Commit | Line | Data |
---|---|---|
c906108c | 1 | /* YACC parser for C expressions, for GDB. |
42a4f53d | 2 | Copyright (C) 1986-2019 Free Software Foundation, Inc. |
c906108c | 3 | |
5b1ba0e5 | 4 | This file is part of GDB. |
c906108c | 5 | |
5b1ba0e5 NS |
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 3 of the License, or | |
9 | (at your option) any later version. | |
c906108c | 10 | |
5b1ba0e5 NS |
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. | |
c906108c | 15 | |
5b1ba0e5 NS |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
c906108c SS |
18 | |
19 | /* Parse a C expression from text in a string, | |
20 | and return the result as a struct expression pointer. | |
21 | That structure contains arithmetic operations in reverse polish, | |
22 | with constants represented by operations that are followed by special data. | |
23 | See expression.h for the details of the format. | |
24 | What is important here is that it can be built up sequentially | |
25 | during the process of parsing; the lower levels of the tree always | |
26 | come first in the result. | |
27 | ||
28 | Note that malloc's and realloc's in this file are transformed to | |
29 | xmalloc and xrealloc respectively by the same sed command in the | |
30 | makefile that remaps any other malloc/realloc inserted by the parser | |
31 | generator. Doing this with #defines and trying to control the interaction | |
32 | with include files (<malloc.h> and <stdlib.h> for example) just became | |
33 | too messy, particularly when such includes can be inserted at random | |
34 | times by the parser generator. */ | |
4d29c0a8 | 35 | |
c906108c SS |
36 | %{ |
37 | ||
38 | #include "defs.h" | |
c906108c SS |
39 | #include <ctype.h> |
40 | #include "expression.h" | |
41 | #include "value.h" | |
42 | #include "parser-defs.h" | |
43 | #include "language.h" | |
44 | #include "c-lang.h" | |
b1b60145 | 45 | #include "c-support.h" |
c906108c SS |
46 | #include "bfd.h" /* Required by objfiles.h. */ |
47 | #include "symfile.h" /* Required by objfiles.h. */ | |
48 | #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ | |
234b45d4 | 49 | #include "charset.h" |
fe898f56 | 50 | #include "block.h" |
79c2c32d | 51 | #include "cp-support.h" |
7c8adf68 | 52 | #include "macroscope.h" |
f2e8016f | 53 | #include "objc-lang.h" |
79d43c61 | 54 | #include "typeprint.h" |
6592e36f | 55 | #include "cp-abi.h" |
dac43e32 | 56 | #include "type-stack.h" |
c906108c | 57 | |
fa9f5be6 | 58 | #define parse_type(ps) builtin_type (ps->gdbarch ()) |
3e79cecf | 59 | |
b3f11165 PA |
60 | /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, |
61 | etc). */ | |
62 | #define GDB_YY_REMAP_PREFIX c_ | |
63 | #include "yy-remap.h" | |
f461f5cf | 64 | |
410a0ff2 SDJ |
65 | /* The state of the parser, used internally when we are parsing the |
66 | expression. */ | |
67 | ||
68 | static struct parser_state *pstate = NULL; | |
69 | ||
02e12e38 TT |
70 | /* Data that must be held for the duration of a parse. */ |
71 | ||
72 | struct c_parse_state | |
73 | { | |
74 | /* These are used to hold type lists and type stacks that are | |
75 | allocated during the parse. */ | |
76 | std::vector<std::unique_ptr<std::vector<struct type *>>> type_lists; | |
77 | std::vector<std::unique_ptr<struct type_stack>> type_stacks; | |
c65bac38 TT |
78 | |
79 | /* Storage for some strings allocated during the parse. */ | |
80 | std::vector<gdb::unique_xmalloc_ptr<char>> strings; | |
9d30e1fd TT |
81 | |
82 | /* When we find that lexptr (the global var defined in parse.c) is | |
83 | pointing at a macro invocation, we expand the invocation, and call | |
84 | scan_macro_expansion to save the old lexptr here and point lexptr | |
85 | into the expanded text. When we reach the end of that, we call | |
86 | end_macro_expansion to pop back to the value we saved here. The | |
87 | macro expansion code promises to return only fully-expanded text, | |
88 | so we don't need to "push" more than one level. | |
89 | ||
90 | This is disgusting, of course. It would be cleaner to do all macro | |
91 | expansion beforehand, and then hand that to lexptr. But we don't | |
92 | really know where the expression ends. Remember, in a command like | |
93 | ||
94 | (gdb) break *ADDRESS if CONDITION | |
95 | ||
96 | we evaluate ADDRESS in the scope of the current frame, but we | |
97 | evaluate CONDITION in the scope of the breakpoint's location. So | |
98 | it's simply wrong to try to macro-expand the whole thing at once. */ | |
99 | const char *macro_original_text = nullptr; | |
100 | ||
101 | /* We save all intermediate macro expansions on this obstack for the | |
102 | duration of a single parse. The expansion text may sometimes have | |
103 | to live past the end of the expansion, due to yacc lookahead. | |
104 | Rather than try to be clever about saving the data for a single | |
105 | token, we simply keep it all and delete it after parsing has | |
106 | completed. */ | |
107 | auto_obstack expansion_obstack; | |
dac43e32 TT |
108 | |
109 | /* The type stack. */ | |
110 | struct type_stack type_stack; | |
02e12e38 TT |
111 | }; |
112 | ||
113 | /* This is set and cleared in c_parse. */ | |
114 | ||
115 | static struct c_parse_state *cpstate; | |
116 | ||
a14ed312 | 117 | int yyparse (void); |
c906108c | 118 | |
a14ed312 | 119 | static int yylex (void); |
c906108c | 120 | |
69d340c6 | 121 | static void yyerror (const char *); |
c906108c | 122 | |
3d567982 TT |
123 | static int type_aggregate_p (struct type *); |
124 | ||
c906108c SS |
125 | %} |
126 | ||
127 | /* Although the yacc "value" of an expression is not used, | |
128 | since the result is stored in the structure being created, | |
129 | other node types do have values. */ | |
130 | ||
131 | %union | |
132 | { | |
133 | LONGEST lval; | |
134 | struct { | |
135 | LONGEST val; | |
136 | struct type *type; | |
137 | } typed_val_int; | |
27bc4d80 TJB |
138 | struct { |
139 | gdb_byte val[16]; | |
140 | struct type *type; | |
edd079d9 | 141 | } typed_val_float; |
c906108c SS |
142 | struct type *tval; |
143 | struct stoken sval; | |
6c7a06a3 | 144 | struct typed_stoken tsval; |
c906108c SS |
145 | struct ttype tsym; |
146 | struct symtoken ssym; | |
147 | int voidval; | |
3977b71f | 148 | const struct block *bval; |
c906108c | 149 | enum exp_opcode opcode; |
c906108c | 150 | |
6c7a06a3 | 151 | struct stoken_vector svec; |
02e12e38 | 152 | std::vector<struct type *> *tvec; |
fcde5961 TT |
153 | |
154 | struct type_stack *type_stack; | |
f2e8016f | 155 | |
fe978cb0 | 156 | struct objc_class_str theclass; |
c906108c SS |
157 | } |
158 | ||
159 | %{ | |
160 | /* YYSTYPE gets defined by %union */ | |
410a0ff2 SDJ |
161 | static int parse_number (struct parser_state *par_state, |
162 | const char *, int, int, YYSTYPE *); | |
66c53f2b | 163 | static struct stoken operator_stoken (const char *); |
6f0ffe50 | 164 | static struct stoken typename_stoken (const char *); |
02e12e38 | 165 | static void check_parameter_typelist (std::vector<struct type *> *); |
410a0ff2 SDJ |
166 | static void write_destructor_name (struct parser_state *par_state, |
167 | struct stoken); | |
9507860e | 168 | |
12c5175d | 169 | #ifdef YYBISON |
9507860e TT |
170 | static void c_print_token (FILE *file, int type, YYSTYPE value); |
171 | #define YYPRINT(FILE, TYPE, VALUE) c_print_token (FILE, TYPE, VALUE) | |
12c5175d | 172 | #endif |
c906108c SS |
173 | %} |
174 | ||
858be34c | 175 | %type <voidval> exp exp1 type_exp start variable qualified_name lcurly function_method |
c906108c | 176 | %type <lval> rcurly |
48e32051 | 177 | %type <tval> type typebase |
a6fb9c08 | 178 | %type <tvec> nonempty_typelist func_mod parameter_typelist |
c906108c SS |
179 | /* %type <bval> block */ |
180 | ||
181 | /* Fancy type parsing. */ | |
c906108c SS |
182 | %type <tval> ptype |
183 | %type <lval> array_mod | |
95c391b6 | 184 | %type <tval> conversion_type_id |
c906108c | 185 | |
fcde5961 TT |
186 | %type <type_stack> ptr_operator_ts abs_decl direct_abs_decl |
187 | ||
c906108c SS |
188 | %token <typed_val_int> INT |
189 | %token <typed_val_float> FLOAT | |
190 | ||
191 | /* Both NAME and TYPENAME tokens represent symbols in the input, | |
192 | and both convey their data as strings. | |
193 | But a TYPENAME is a string that happens to be defined as a typedef | |
194 | or builtin type name (such as int or char) | |
195 | and a NAME is any other symbol. | |
196 | Contexts where this distinction is not important can use the | |
197 | nonterminal "name", which matches either NAME or TYPENAME. */ | |
198 | ||
6c7a06a3 | 199 | %token <tsval> STRING |
f2e8016f TT |
200 | %token <sval> NSSTRING /* ObjC Foundation "NSString" literal */ |
201 | %token SELECTOR /* ObjC "@selector" pseudo-operator */ | |
6c7a06a3 | 202 | %token <tsval> CHAR |
c906108c | 203 | %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */ |
7322dca9 | 204 | %token <ssym> UNKNOWN_CPP_NAME |
65d12d83 | 205 | %token <voidval> COMPLETE |
c906108c | 206 | %token <tsym> TYPENAME |
fe978cb0 | 207 | %token <theclass> CLASSNAME /* ObjC Class name */ |
0f5d3f63 | 208 | %type <sval> name field_name |
6c7a06a3 | 209 | %type <svec> string_exp |
c906108c | 210 | %type <ssym> name_not_typename |
fe978cb0 | 211 | %type <tsym> type_name |
c906108c | 212 | |
f2e8016f TT |
213 | /* This is like a '[' token, but is only generated when parsing |
214 | Objective C. This lets us reuse the same parser without | |
215 | erroneously parsing ObjC-specific expressions in C. */ | |
216 | %token OBJC_LBRAC | |
217 | ||
c906108c SS |
218 | /* A NAME_OR_INT is a symbol which is not known in the symbol table, |
219 | but which would parse as a valid number in the current input radix. | |
220 | E.g. "c" when input_radix==16. Depending on the parse, it will be | |
221 | turned into a name or into a number. */ | |
222 | ||
4d29c0a8 | 223 | %token <ssym> NAME_OR_INT |
c906108c | 224 | |
66c53f2b | 225 | %token OPERATOR |
007e1530 | 226 | %token STRUCT CLASS UNION ENUM SIZEOF ALIGNOF UNSIGNED COLONCOLON |
c906108c SS |
227 | %token TEMPLATE |
228 | %token ERROR | |
66c53f2b | 229 | %token NEW DELETE |
fe978cb0 | 230 | %type <sval> oper |
4e8f195d | 231 | %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST |
941b2081 | 232 | %token ENTRY |
608b4967 TT |
233 | %token TYPEOF |
234 | %token DECLTYPE | |
6e72ca20 | 235 | %token TYPEID |
c906108c SS |
236 | |
237 | /* Special type cases, put in to allow the parser to distinguish different | |
238 | legal basetypes. */ | |
239 | %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD | |
240 | ||
cfeadda5 | 241 | %token <sval> DOLLAR_VARIABLE |
c906108c SS |
242 | |
243 | %token <opcode> ASSIGN_MODIFY | |
244 | ||
245 | /* C++ */ | |
c906108c SS |
246 | %token TRUEKEYWORD |
247 | %token FALSEKEYWORD | |
248 | ||
249 | ||
250 | %left ',' | |
251 | %left ABOVE_COMMA | |
252 | %right '=' ASSIGN_MODIFY | |
253 | %right '?' | |
254 | %left OROR | |
255 | %left ANDAND | |
256 | %left '|' | |
257 | %left '^' | |
258 | %left '&' | |
259 | %left EQUAL NOTEQUAL | |
260 | %left '<' '>' LEQ GEQ | |
261 | %left LSH RSH | |
262 | %left '@' | |
263 | %left '+' '-' | |
264 | %left '*' '/' '%' | |
265 | %right UNARY INCREMENT DECREMENT | |
f2e8016f | 266 | %right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '(' |
4d29c0a8 | 267 | %token <ssym> BLOCKNAME |
c906108c SS |
268 | %token <bval> FILENAME |
269 | %type <bval> block | |
270 | %left COLONCOLON | |
271 | ||
a6fb9c08 TT |
272 | %token DOTDOTDOT |
273 | ||
c906108c SS |
274 | \f |
275 | %% | |
276 | ||
277 | start : exp1 | |
278 | | type_exp | |
279 | ; | |
280 | ||
281 | type_exp: type | |
410a0ff2 SDJ |
282 | { write_exp_elt_opcode(pstate, OP_TYPE); |
283 | write_exp_elt_type(pstate, $1); | |
284 | write_exp_elt_opcode(pstate, OP_TYPE);} | |
608b4967 TT |
285 | | TYPEOF '(' exp ')' |
286 | { | |
410a0ff2 | 287 | write_exp_elt_opcode (pstate, OP_TYPEOF); |
608b4967 TT |
288 | } |
289 | | TYPEOF '(' type ')' | |
290 | { | |
410a0ff2 SDJ |
291 | write_exp_elt_opcode (pstate, OP_TYPE); |
292 | write_exp_elt_type (pstate, $3); | |
293 | write_exp_elt_opcode (pstate, OP_TYPE); | |
608b4967 TT |
294 | } |
295 | | DECLTYPE '(' exp ')' | |
296 | { | |
410a0ff2 | 297 | write_exp_elt_opcode (pstate, OP_DECLTYPE); |
608b4967 | 298 | } |
c906108c SS |
299 | ; |
300 | ||
301 | /* Expressions, including the comma operator. */ | |
302 | exp1 : exp | |
303 | | exp1 ',' exp | |
410a0ff2 | 304 | { write_exp_elt_opcode (pstate, BINOP_COMMA); } |
c906108c SS |
305 | ; |
306 | ||
307 | /* Expressions, not including the comma operator. */ | |
308 | exp : '*' exp %prec UNARY | |
410a0ff2 | 309 | { write_exp_elt_opcode (pstate, UNOP_IND); } |
ef944135 | 310 | ; |
c906108c SS |
311 | |
312 | exp : '&' exp %prec UNARY | |
410a0ff2 | 313 | { write_exp_elt_opcode (pstate, UNOP_ADDR); } |
ef944135 | 314 | ; |
c906108c SS |
315 | |
316 | exp : '-' exp %prec UNARY | |
410a0ff2 | 317 | { write_exp_elt_opcode (pstate, UNOP_NEG); } |
c906108c SS |
318 | ; |
319 | ||
36e9969c | 320 | exp : '+' exp %prec UNARY |
410a0ff2 | 321 | { write_exp_elt_opcode (pstate, UNOP_PLUS); } |
36e9969c NS |
322 | ; |
323 | ||
c906108c | 324 | exp : '!' exp %prec UNARY |
410a0ff2 | 325 | { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } |
c906108c SS |
326 | ; |
327 | ||
328 | exp : '~' exp %prec UNARY | |
410a0ff2 | 329 | { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); } |
c906108c SS |
330 | ; |
331 | ||
332 | exp : INCREMENT exp %prec UNARY | |
410a0ff2 | 333 | { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); } |
c906108c SS |
334 | ; |
335 | ||
336 | exp : DECREMENT exp %prec UNARY | |
410a0ff2 | 337 | { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); } |
c906108c SS |
338 | ; |
339 | ||
340 | exp : exp INCREMENT %prec UNARY | |
410a0ff2 | 341 | { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); } |
c906108c SS |
342 | ; |
343 | ||
344 | exp : exp DECREMENT %prec UNARY | |
410a0ff2 | 345 | { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); } |
c906108c SS |
346 | ; |
347 | ||
6e72ca20 | 348 | exp : TYPEID '(' exp ')' %prec UNARY |
410a0ff2 | 349 | { write_exp_elt_opcode (pstate, OP_TYPEID); } |
6e72ca20 TT |
350 | ; |
351 | ||
352 | exp : TYPEID '(' type_exp ')' %prec UNARY | |
410a0ff2 | 353 | { write_exp_elt_opcode (pstate, OP_TYPEID); } |
6e72ca20 TT |
354 | ; |
355 | ||
c906108c | 356 | exp : SIZEOF exp %prec UNARY |
410a0ff2 | 357 | { write_exp_elt_opcode (pstate, UNOP_SIZEOF); } |
c906108c SS |
358 | ; |
359 | ||
007e1530 TT |
360 | exp : ALIGNOF '(' type_exp ')' %prec UNARY |
361 | { write_exp_elt_opcode (pstate, UNOP_ALIGNOF); } | |
362 | ; | |
363 | ||
0f5d3f63 | 364 | exp : exp ARROW field_name |
410a0ff2 SDJ |
365 | { write_exp_elt_opcode (pstate, STRUCTOP_PTR); |
366 | write_exp_string (pstate, $3); | |
367 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); } | |
c906108c SS |
368 | ; |
369 | ||
0f5d3f63 | 370 | exp : exp ARROW field_name COMPLETE |
2a612529 | 371 | { pstate->mark_struct_expression (); |
410a0ff2 SDJ |
372 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); |
373 | write_exp_string (pstate, $3); | |
374 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); } | |
65d12d83 TT |
375 | ; |
376 | ||
377 | exp : exp ARROW COMPLETE | |
378 | { struct stoken s; | |
2a612529 | 379 | pstate->mark_struct_expression (); |
410a0ff2 | 380 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); |
65d12d83 TT |
381 | s.ptr = ""; |
382 | s.length = 0; | |
410a0ff2 SDJ |
383 | write_exp_string (pstate, s); |
384 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); } | |
65d12d83 TT |
385 | ; |
386 | ||
24955f63 | 387 | exp : exp ARROW '~' name |
410a0ff2 SDJ |
388 | { write_exp_elt_opcode (pstate, STRUCTOP_PTR); |
389 | write_destructor_name (pstate, $4); | |
390 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); } | |
24955f63 TT |
391 | ; |
392 | ||
393 | exp : exp ARROW '~' name COMPLETE | |
2a612529 | 394 | { pstate->mark_struct_expression (); |
410a0ff2 SDJ |
395 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); |
396 | write_destructor_name (pstate, $4); | |
397 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); } | |
24955f63 TT |
398 | ; |
399 | ||
c906108c SS |
400 | exp : exp ARROW qualified_name |
401 | { /* exp->type::name becomes exp->*(&type::name) */ | |
402 | /* Note: this doesn't work if name is a | |
403 | static member! FIXME */ | |
410a0ff2 SDJ |
404 | write_exp_elt_opcode (pstate, UNOP_ADDR); |
405 | write_exp_elt_opcode (pstate, STRUCTOP_MPTR); } | |
c906108c SS |
406 | ; |
407 | ||
c1af96a0 | 408 | exp : exp ARROW_STAR exp |
410a0ff2 | 409 | { write_exp_elt_opcode (pstate, STRUCTOP_MPTR); } |
c906108c SS |
410 | ; |
411 | ||
0f5d3f63 | 412 | exp : exp '.' field_name |
410a0ff2 SDJ |
413 | { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); |
414 | write_exp_string (pstate, $3); | |
415 | write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } | |
c906108c SS |
416 | ; |
417 | ||
0f5d3f63 | 418 | exp : exp '.' field_name COMPLETE |
2a612529 | 419 | { pstate->mark_struct_expression (); |
410a0ff2 SDJ |
420 | write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); |
421 | write_exp_string (pstate, $3); | |
422 | write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } | |
65d12d83 TT |
423 | ; |
424 | ||
425 | exp : exp '.' COMPLETE | |
426 | { struct stoken s; | |
2a612529 | 427 | pstate->mark_struct_expression (); |
410a0ff2 | 428 | write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); |
65d12d83 TT |
429 | s.ptr = ""; |
430 | s.length = 0; | |
410a0ff2 SDJ |
431 | write_exp_string (pstate, s); |
432 | write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } | |
65d12d83 TT |
433 | ; |
434 | ||
24955f63 | 435 | exp : exp '.' '~' name |
410a0ff2 SDJ |
436 | { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); |
437 | write_destructor_name (pstate, $4); | |
438 | write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } | |
24955f63 TT |
439 | ; |
440 | ||
441 | exp : exp '.' '~' name COMPLETE | |
2a612529 | 442 | { pstate->mark_struct_expression (); |
410a0ff2 SDJ |
443 | write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); |
444 | write_destructor_name (pstate, $4); | |
445 | write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } | |
24955f63 TT |
446 | ; |
447 | ||
c906108c SS |
448 | exp : exp '.' qualified_name |
449 | { /* exp.type::name becomes exp.*(&type::name) */ | |
450 | /* Note: this doesn't work if name is a | |
451 | static member! FIXME */ | |
410a0ff2 SDJ |
452 | write_exp_elt_opcode (pstate, UNOP_ADDR); |
453 | write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); } | |
c906108c SS |
454 | ; |
455 | ||
c1af96a0 | 456 | exp : exp DOT_STAR exp |
410a0ff2 | 457 | { write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); } |
c906108c SS |
458 | ; |
459 | ||
460 | exp : exp '[' exp1 ']' | |
410a0ff2 | 461 | { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } |
c906108c SS |
462 | ; |
463 | ||
f2e8016f | 464 | exp : exp OBJC_LBRAC exp1 ']' |
410a0ff2 | 465 | { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } |
f2e8016f TT |
466 | ; |
467 | ||
468 | /* | |
469 | * The rules below parse ObjC message calls of the form: | |
470 | * '[' target selector {':' argument}* ']' | |
471 | */ | |
472 | ||
473 | exp : OBJC_LBRAC TYPENAME | |
474 | { | |
fe978cb0 | 475 | CORE_ADDR theclass; |
f2e8016f | 476 | |
fa9f5be6 | 477 | theclass = lookup_objc_class (pstate->gdbarch (), |
f2e8016f | 478 | copy_name ($2.stoken)); |
fe978cb0 | 479 | if (theclass == 0) |
f2e8016f TT |
480 | error (_("%s is not an ObjC Class"), |
481 | copy_name ($2.stoken)); | |
410a0ff2 SDJ |
482 | write_exp_elt_opcode (pstate, OP_LONG); |
483 | write_exp_elt_type (pstate, | |
484 | parse_type (pstate)->builtin_int); | |
fe978cb0 | 485 | write_exp_elt_longcst (pstate, (LONGEST) theclass); |
410a0ff2 | 486 | write_exp_elt_opcode (pstate, OP_LONG); |
f2e8016f TT |
487 | start_msglist(); |
488 | } | |
489 | msglist ']' | |
410a0ff2 SDJ |
490 | { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); |
491 | end_msglist (pstate); | |
492 | write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); | |
f2e8016f TT |
493 | } |
494 | ; | |
495 | ||
496 | exp : OBJC_LBRAC CLASSNAME | |
497 | { | |
410a0ff2 SDJ |
498 | write_exp_elt_opcode (pstate, OP_LONG); |
499 | write_exp_elt_type (pstate, | |
500 | parse_type (pstate)->builtin_int); | |
fe978cb0 | 501 | write_exp_elt_longcst (pstate, (LONGEST) $2.theclass); |
410a0ff2 | 502 | write_exp_elt_opcode (pstate, OP_LONG); |
f2e8016f TT |
503 | start_msglist(); |
504 | } | |
505 | msglist ']' | |
410a0ff2 SDJ |
506 | { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); |
507 | end_msglist (pstate); | |
508 | write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); | |
f2e8016f TT |
509 | } |
510 | ; | |
511 | ||
512 | exp : OBJC_LBRAC exp | |
513 | { start_msglist(); } | |
514 | msglist ']' | |
410a0ff2 SDJ |
515 | { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); |
516 | end_msglist (pstate); | |
517 | write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); | |
f2e8016f TT |
518 | } |
519 | ; | |
520 | ||
521 | msglist : name | |
522 | { add_msglist(&$1, 0); } | |
523 | | msgarglist | |
524 | ; | |
525 | ||
526 | msgarglist : msgarg | |
527 | | msgarglist msgarg | |
528 | ; | |
529 | ||
530 | msgarg : name ':' exp | |
531 | { add_msglist(&$1, 1); } | |
532 | | ':' exp /* Unnamed arg. */ | |
533 | { add_msglist(0, 1); } | |
534 | | ',' exp /* Variable number of args. */ | |
535 | { add_msglist(0, 0); } | |
536 | ; | |
537 | ||
4d29c0a8 | 538 | exp : exp '(' |
c906108c SS |
539 | /* This is to save the value of arglist_len |
540 | being accumulated by an outer function call. */ | |
43476f0b | 541 | { pstate->start_arglist (); } |
c906108c | 542 | arglist ')' %prec ARROW |
410a0ff2 SDJ |
543 | { write_exp_elt_opcode (pstate, OP_FUNCALL); |
544 | write_exp_elt_longcst (pstate, | |
43476f0b | 545 | pstate->end_arglist ()); |
410a0ff2 | 546 | write_exp_elt_opcode (pstate, OP_FUNCALL); } |
c906108c SS |
547 | ; |
548 | ||
858be34c PA |
549 | /* This is here to disambiguate with the production for |
550 | "func()::static_var" further below, which uses | |
551 | function_method_void. */ | |
552 | exp : exp '(' ')' %prec ARROW | |
43476f0b | 553 | { pstate->start_arglist (); |
858be34c PA |
554 | write_exp_elt_opcode (pstate, OP_FUNCALL); |
555 | write_exp_elt_longcst (pstate, | |
43476f0b | 556 | pstate->end_arglist ()); |
858be34c PA |
557 | write_exp_elt_opcode (pstate, OP_FUNCALL); } |
558 | ; | |
559 | ||
560 | ||
941b2081 | 561 | exp : UNKNOWN_CPP_NAME '(' |
7322dca9 SW |
562 | { |
563 | /* This could potentially be a an argument defined | |
564 | lookup function (Koenig). */ | |
410a0ff2 | 565 | write_exp_elt_opcode (pstate, OP_ADL_FUNC); |
1e58a4a4 TT |
566 | write_exp_elt_block |
567 | (pstate, pstate->expression_context_block); | |
410a0ff2 SDJ |
568 | write_exp_elt_sym (pstate, |
569 | NULL); /* Placeholder. */ | |
570 | write_exp_string (pstate, $1.stoken); | |
571 | write_exp_elt_opcode (pstate, OP_ADL_FUNC); | |
7322dca9 SW |
572 | |
573 | /* This is to save the value of arglist_len | |
574 | being accumulated by an outer function call. */ | |
575 | ||
43476f0b | 576 | pstate->start_arglist (); |
7322dca9 SW |
577 | } |
578 | arglist ')' %prec ARROW | |
579 | { | |
410a0ff2 SDJ |
580 | write_exp_elt_opcode (pstate, OP_FUNCALL); |
581 | write_exp_elt_longcst (pstate, | |
43476f0b | 582 | pstate->end_arglist ()); |
410a0ff2 | 583 | write_exp_elt_opcode (pstate, OP_FUNCALL); |
7322dca9 SW |
584 | } |
585 | ; | |
586 | ||
c906108c | 587 | lcurly : '{' |
43476f0b | 588 | { pstate->start_arglist (); } |
c906108c SS |
589 | ; |
590 | ||
591 | arglist : | |
592 | ; | |
593 | ||
594 | arglist : exp | |
43476f0b | 595 | { pstate->arglist_len = 1; } |
c906108c SS |
596 | ; |
597 | ||
598 | arglist : arglist ',' exp %prec ABOVE_COMMA | |
43476f0b | 599 | { pstate->arglist_len++; } |
c906108c SS |
600 | ; |
601 | ||
858be34c | 602 | function_method: exp '(' parameter_typelist ')' const_or_volatile |
02e12e38 TT |
603 | { |
604 | std::vector<struct type *> *type_list = $3; | |
605 | LONGEST len = type_list->size (); | |
71918a86 | 606 | |
410a0ff2 | 607 | write_exp_elt_opcode (pstate, TYPE_INSTANCE); |
3693fdb3 PA |
608 | /* Save the const/volatile qualifiers as |
609 | recorded by the const_or_volatile | |
610 | production's actions. */ | |
dac43e32 TT |
611 | write_exp_elt_longcst |
612 | (pstate, | |
613 | (cpstate->type_stack | |
614 | .follow_type_instance_flags ())); | |
410a0ff2 | 615 | write_exp_elt_longcst (pstate, len); |
02e12e38 | 616 | for (type *type_elt : *type_list) |
410a0ff2 SDJ |
617 | write_exp_elt_type (pstate, type_elt); |
618 | write_exp_elt_longcst(pstate, len); | |
619 | write_exp_elt_opcode (pstate, TYPE_INSTANCE); | |
072bba3b KS |
620 | } |
621 | ; | |
622 | ||
858be34c PA |
623 | function_method_void: exp '(' ')' const_or_volatile |
624 | { write_exp_elt_opcode (pstate, TYPE_INSTANCE); | |
3693fdb3 | 625 | /* See above. */ |
dac43e32 TT |
626 | write_exp_elt_longcst |
627 | (pstate, | |
628 | cpstate->type_stack.follow_type_instance_flags ()); | |
858be34c PA |
629 | write_exp_elt_longcst (pstate, 0); |
630 | write_exp_elt_longcst (pstate, 0); | |
631 | write_exp_elt_opcode (pstate, TYPE_INSTANCE); | |
632 | } | |
633 | ; | |
634 | ||
635 | exp : function_method | |
636 | ; | |
637 | ||
638 | /* Normally we must interpret "func()" as a function call, instead of | |
639 | a type. The user needs to write func(void) to disambiguate. | |
640 | However, in the "func()::static_var" case, there's no | |
641 | ambiguity. */ | |
642 | function_method_void_or_typelist: function_method | |
643 | | function_method_void | |
644 | ; | |
645 | ||
646 | exp : function_method_void_or_typelist COLONCOLON name | |
647 | { | |
648 | write_exp_elt_opcode (pstate, OP_FUNC_STATIC_VAR); | |
649 | write_exp_string (pstate, $3); | |
650 | write_exp_elt_opcode (pstate, OP_FUNC_STATIC_VAR); | |
651 | } | |
652 | ; | |
653 | ||
c906108c | 654 | rcurly : '}' |
43476f0b | 655 | { $$ = pstate->end_arglist () - 1; } |
c906108c SS |
656 | ; |
657 | exp : lcurly arglist rcurly %prec ARROW | |
410a0ff2 SDJ |
658 | { write_exp_elt_opcode (pstate, OP_ARRAY); |
659 | write_exp_elt_longcst (pstate, (LONGEST) 0); | |
660 | write_exp_elt_longcst (pstate, (LONGEST) $3); | |
661 | write_exp_elt_opcode (pstate, OP_ARRAY); } | |
c906108c SS |
662 | ; |
663 | ||
9eaf6705 | 664 | exp : lcurly type_exp rcurly exp %prec UNARY |
410a0ff2 | 665 | { write_exp_elt_opcode (pstate, UNOP_MEMVAL_TYPE); } |
c906108c SS |
666 | ; |
667 | ||
9eaf6705 | 668 | exp : '(' type_exp ')' exp %prec UNARY |
410a0ff2 | 669 | { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); } |
c906108c SS |
670 | ; |
671 | ||
672 | exp : '(' exp1 ')' | |
673 | { } | |
674 | ; | |
675 | ||
676 | /* Binary operators in order of decreasing precedence. */ | |
677 | ||
678 | exp : exp '@' exp | |
410a0ff2 | 679 | { write_exp_elt_opcode (pstate, BINOP_REPEAT); } |
c906108c SS |
680 | ; |
681 | ||
682 | exp : exp '*' exp | |
410a0ff2 | 683 | { write_exp_elt_opcode (pstate, BINOP_MUL); } |
c906108c SS |
684 | ; |
685 | ||
686 | exp : exp '/' exp | |
410a0ff2 | 687 | { write_exp_elt_opcode (pstate, BINOP_DIV); } |
c906108c SS |
688 | ; |
689 | ||
690 | exp : exp '%' exp | |
410a0ff2 | 691 | { write_exp_elt_opcode (pstate, BINOP_REM); } |
c906108c SS |
692 | ; |
693 | ||
694 | exp : exp '+' exp | |
410a0ff2 | 695 | { write_exp_elt_opcode (pstate, BINOP_ADD); } |
c906108c SS |
696 | ; |
697 | ||
698 | exp : exp '-' exp | |
410a0ff2 | 699 | { write_exp_elt_opcode (pstate, BINOP_SUB); } |
c906108c SS |
700 | ; |
701 | ||
702 | exp : exp LSH exp | |
410a0ff2 | 703 | { write_exp_elt_opcode (pstate, BINOP_LSH); } |
c906108c SS |
704 | ; |
705 | ||
706 | exp : exp RSH exp | |
410a0ff2 | 707 | { write_exp_elt_opcode (pstate, BINOP_RSH); } |
c906108c SS |
708 | ; |
709 | ||
710 | exp : exp EQUAL exp | |
410a0ff2 | 711 | { write_exp_elt_opcode (pstate, BINOP_EQUAL); } |
c906108c SS |
712 | ; |
713 | ||
714 | exp : exp NOTEQUAL exp | |
410a0ff2 | 715 | { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); } |
c906108c SS |
716 | ; |
717 | ||
718 | exp : exp LEQ exp | |
410a0ff2 | 719 | { write_exp_elt_opcode (pstate, BINOP_LEQ); } |
c906108c SS |
720 | ; |
721 | ||
722 | exp : exp GEQ exp | |
410a0ff2 | 723 | { write_exp_elt_opcode (pstate, BINOP_GEQ); } |
c906108c SS |
724 | ; |
725 | ||
726 | exp : exp '<' exp | |
410a0ff2 | 727 | { write_exp_elt_opcode (pstate, BINOP_LESS); } |
c906108c SS |
728 | ; |
729 | ||
730 | exp : exp '>' exp | |
410a0ff2 | 731 | { write_exp_elt_opcode (pstate, BINOP_GTR); } |
c906108c SS |
732 | ; |
733 | ||
734 | exp : exp '&' exp | |
410a0ff2 | 735 | { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); } |
c906108c SS |
736 | ; |
737 | ||
738 | exp : exp '^' exp | |
410a0ff2 | 739 | { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); } |
c906108c SS |
740 | ; |
741 | ||
742 | exp : exp '|' exp | |
410a0ff2 | 743 | { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); } |
c906108c SS |
744 | ; |
745 | ||
746 | exp : exp ANDAND exp | |
410a0ff2 | 747 | { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); } |
c906108c SS |
748 | ; |
749 | ||
750 | exp : exp OROR exp | |
410a0ff2 | 751 | { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); } |
c906108c SS |
752 | ; |
753 | ||
754 | exp : exp '?' exp ':' exp %prec '?' | |
410a0ff2 | 755 | { write_exp_elt_opcode (pstate, TERNOP_COND); } |
c906108c | 756 | ; |
4d29c0a8 | 757 | |
c906108c | 758 | exp : exp '=' exp |
410a0ff2 | 759 | { write_exp_elt_opcode (pstate, BINOP_ASSIGN); } |
c906108c SS |
760 | ; |
761 | ||
762 | exp : exp ASSIGN_MODIFY exp | |
410a0ff2 SDJ |
763 | { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); |
764 | write_exp_elt_opcode (pstate, $2); | |
765 | write_exp_elt_opcode (pstate, | |
766 | BINOP_ASSIGN_MODIFY); } | |
c906108c SS |
767 | ; |
768 | ||
769 | exp : INT | |
410a0ff2 SDJ |
770 | { write_exp_elt_opcode (pstate, OP_LONG); |
771 | write_exp_elt_type (pstate, $1.type); | |
772 | write_exp_elt_longcst (pstate, (LONGEST) ($1.val)); | |
773 | write_exp_elt_opcode (pstate, OP_LONG); } | |
c906108c SS |
774 | ; |
775 | ||
6c7a06a3 TT |
776 | exp : CHAR |
777 | { | |
778 | struct stoken_vector vec; | |
779 | vec.len = 1; | |
780 | vec.tokens = &$1; | |
410a0ff2 | 781 | write_exp_string_vector (pstate, $1.type, &vec); |
6c7a06a3 TT |
782 | } |
783 | ; | |
784 | ||
c906108c SS |
785 | exp : NAME_OR_INT |
786 | { YYSTYPE val; | |
410a0ff2 SDJ |
787 | parse_number (pstate, $1.stoken.ptr, |
788 | $1.stoken.length, 0, &val); | |
789 | write_exp_elt_opcode (pstate, OP_LONG); | |
790 | write_exp_elt_type (pstate, val.typed_val_int.type); | |
791 | write_exp_elt_longcst (pstate, | |
792 | (LONGEST) val.typed_val_int.val); | |
793 | write_exp_elt_opcode (pstate, OP_LONG); | |
c906108c SS |
794 | } |
795 | ; | |
796 | ||
797 | ||
798 | exp : FLOAT | |
edd079d9 | 799 | { write_exp_elt_opcode (pstate, OP_FLOAT); |
410a0ff2 | 800 | write_exp_elt_type (pstate, $1.type); |
edd079d9 UW |
801 | write_exp_elt_floatcst (pstate, $1.val); |
802 | write_exp_elt_opcode (pstate, OP_FLOAT); } | |
27bc4d80 TJB |
803 | ; |
804 | ||
c906108c SS |
805 | exp : variable |
806 | ; | |
807 | ||
cfeadda5 | 808 | exp : DOLLAR_VARIABLE |
48e32051 | 809 | { |
410a0ff2 | 810 | write_dollar_variable (pstate, $1); |
48e32051 | 811 | } |
c906108c SS |
812 | ; |
813 | ||
f2e8016f TT |
814 | exp : SELECTOR '(' name ')' |
815 | { | |
410a0ff2 SDJ |
816 | write_exp_elt_opcode (pstate, OP_OBJC_SELECTOR); |
817 | write_exp_string (pstate, $3); | |
818 | write_exp_elt_opcode (pstate, OP_OBJC_SELECTOR); } | |
f2e8016f TT |
819 | ; |
820 | ||
c906108c | 821 | exp : SIZEOF '(' type ')' %prec UNARY |
245a5f0b KS |
822 | { struct type *type = $3; |
823 | write_exp_elt_opcode (pstate, OP_LONG); | |
410a0ff2 | 824 | write_exp_elt_type (pstate, lookup_signed_typename |
73923d7e | 825 | (pstate->language (), |
fa9f5be6 | 826 | pstate->gdbarch (), |
f4b8a18d | 827 | "int")); |
f168693b | 828 | type = check_typedef (type); |
245a5f0b KS |
829 | |
830 | /* $5.3.3/2 of the C++ Standard (n3290 draft) | |
831 | says of sizeof: "When applied to a reference | |
832 | or a reference type, the result is the size of | |
833 | the referenced type." */ | |
53cc15f5 | 834 | if (TYPE_IS_REFERENCE (type)) |
245a5f0b | 835 | type = check_typedef (TYPE_TARGET_TYPE (type)); |
410a0ff2 | 836 | write_exp_elt_longcst (pstate, |
245a5f0b | 837 | (LONGEST) TYPE_LENGTH (type)); |
410a0ff2 | 838 | write_exp_elt_opcode (pstate, OP_LONG); } |
c906108c SS |
839 | ; |
840 | ||
9eaf6705 | 841 | exp : REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY |
410a0ff2 SDJ |
842 | { write_exp_elt_opcode (pstate, |
843 | UNOP_REINTERPRET_CAST); } | |
4e8f195d TT |
844 | ; |
845 | ||
9eaf6705 | 846 | exp : STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY |
410a0ff2 | 847 | { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); } |
4e8f195d TT |
848 | ; |
849 | ||
9eaf6705 | 850 | exp : DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY |
410a0ff2 | 851 | { write_exp_elt_opcode (pstate, UNOP_DYNAMIC_CAST); } |
4e8f195d TT |
852 | ; |
853 | ||
9eaf6705 | 854 | exp : CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY |
4e8f195d TT |
855 | { /* We could do more error checking here, but |
856 | it doesn't seem worthwhile. */ | |
410a0ff2 | 857 | write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); } |
4e8f195d TT |
858 | ; |
859 | ||
c209f847 TT |
860 | string_exp: |
861 | STRING | |
862 | { | |
863 | /* We copy the string here, and not in the | |
864 | lexer, to guarantee that we do not leak a | |
865 | string. Note that we follow the | |
866 | NUL-termination convention of the | |
867 | lexer. */ | |
6c7a06a3 TT |
868 | struct typed_stoken *vec = XNEW (struct typed_stoken); |
869 | $$.len = 1; | |
870 | $$.tokens = vec; | |
871 | ||
872 | vec->type = $1.type; | |
873 | vec->length = $1.length; | |
224c3ddb | 874 | vec->ptr = (char *) malloc ($1.length + 1); |
6c7a06a3 | 875 | memcpy (vec->ptr, $1.ptr, $1.length + 1); |
c209f847 TT |
876 | } |
877 | ||
878 | | string_exp STRING | |
879 | { | |
880 | /* Note that we NUL-terminate here, but just | |
881 | for convenience. */ | |
6c7a06a3 TT |
882 | char *p; |
883 | ++$$.len; | |
224c3ddb SM |
884 | $$.tokens = XRESIZEVEC (struct typed_stoken, |
885 | $$.tokens, $$.len); | |
6c7a06a3 | 886 | |
224c3ddb | 887 | p = (char *) malloc ($2.length + 1); |
6c7a06a3 TT |
888 | memcpy (p, $2.ptr, $2.length + 1); |
889 | ||
890 | $$.tokens[$$.len - 1].type = $2.type; | |
891 | $$.tokens[$$.len - 1].length = $2.length; | |
892 | $$.tokens[$$.len - 1].ptr = p; | |
c209f847 TT |
893 | } |
894 | ; | |
895 | ||
896 | exp : string_exp | |
6c7a06a3 TT |
897 | { |
898 | int i; | |
0c801b96 | 899 | c_string_type type = C_STRING; |
6c7a06a3 TT |
900 | |
901 | for (i = 0; i < $1.len; ++i) | |
c906108c | 902 | { |
6c7a06a3 TT |
903 | switch ($1.tokens[i].type) |
904 | { | |
905 | case C_STRING: | |
906 | break; | |
907 | case C_WIDE_STRING: | |
908 | case C_STRING_16: | |
909 | case C_STRING_32: | |
910 | if (type != C_STRING | |
911 | && type != $1.tokens[i].type) | |
001083c6 | 912 | error (_("Undefined string concatenation.")); |
0c801b96 | 913 | type = (enum c_string_type_values) $1.tokens[i].type; |
6c7a06a3 TT |
914 | break; |
915 | default: | |
916 | /* internal error */ | |
917 | internal_error (__FILE__, __LINE__, | |
918 | "unrecognized type in string concatenation"); | |
919 | } | |
c906108c | 920 | } |
6c7a06a3 | 921 | |
410a0ff2 | 922 | write_exp_string_vector (pstate, type, &$1); |
6c7a06a3 TT |
923 | for (i = 0; i < $1.len; ++i) |
924 | free ($1.tokens[i].ptr); | |
925 | free ($1.tokens); | |
c209f847 | 926 | } |
c906108c SS |
927 | ; |
928 | ||
f2e8016f TT |
929 | exp : NSSTRING /* ObjC NextStep NSString constant |
930 | * of the form '@' '"' string '"'. | |
931 | */ | |
410a0ff2 SDJ |
932 | { write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING); |
933 | write_exp_string (pstate, $1); | |
934 | write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING); } | |
f2e8016f TT |
935 | ; |
936 | ||
c906108c | 937 | /* C++. */ |
4d29c0a8 | 938 | exp : TRUEKEYWORD |
410a0ff2 SDJ |
939 | { write_exp_elt_opcode (pstate, OP_LONG); |
940 | write_exp_elt_type (pstate, | |
941 | parse_type (pstate)->builtin_bool); | |
942 | write_exp_elt_longcst (pstate, (LONGEST) 1); | |
943 | write_exp_elt_opcode (pstate, OP_LONG); } | |
c906108c SS |
944 | ; |
945 | ||
4d29c0a8 | 946 | exp : FALSEKEYWORD |
410a0ff2 SDJ |
947 | { write_exp_elt_opcode (pstate, OP_LONG); |
948 | write_exp_elt_type (pstate, | |
949 | parse_type (pstate)->builtin_bool); | |
950 | write_exp_elt_longcst (pstate, (LONGEST) 0); | |
951 | write_exp_elt_opcode (pstate, OP_LONG); } | |
c906108c SS |
952 | ; |
953 | ||
954 | /* end of C++. */ | |
955 | ||
956 | block : BLOCKNAME | |
957 | { | |
d12307c1 PMR |
958 | if ($1.sym.symbol) |
959 | $$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol); | |
c906108c | 960 | else |
001083c6 | 961 | error (_("No file or function \"%s\"."), |
c906108c SS |
962 | copy_name ($1.stoken)); |
963 | } | |
964 | | FILENAME | |
965 | { | |
966 | $$ = $1; | |
967 | } | |
968 | ; | |
969 | ||
970 | block : block COLONCOLON name | |
971 | { struct symbol *tem | |
972 | = lookup_symbol (copy_name ($3), $1, | |
d12307c1 PMR |
973 | VAR_DOMAIN, NULL).symbol; |
974 | ||
c906108c | 975 | if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK) |
001083c6 | 976 | error (_("No function \"%s\" in specified context."), |
c906108c SS |
977 | copy_name ($3)); |
978 | $$ = SYMBOL_BLOCK_VALUE (tem); } | |
979 | ; | |
980 | ||
941b2081 | 981 | variable: name_not_typename ENTRY |
d12307c1 | 982 | { struct symbol *sym = $1.sym.symbol; |
36b11add JK |
983 | |
984 | if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym) | |
985 | || !symbol_read_needs_frame (sym)) | |
986 | error (_("@entry can be used only for function " | |
987 | "parameters, not for \"%s\""), | |
988 | copy_name ($1.stoken)); | |
989 | ||
410a0ff2 SDJ |
990 | write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE); |
991 | write_exp_elt_sym (pstate, sym); | |
992 | write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE); | |
36b11add JK |
993 | } |
994 | ; | |
995 | ||
c906108c | 996 | variable: block COLONCOLON name |
d12307c1 PMR |
997 | { struct block_symbol sym |
998 | = lookup_symbol (copy_name ($3), $1, | |
999 | VAR_DOMAIN, NULL); | |
1000 | ||
1001 | if (sym.symbol == 0) | |
001083c6 | 1002 | error (_("No symbol \"%s\" in specified context."), |
c906108c | 1003 | copy_name ($3)); |
d12307c1 | 1004 | if (symbol_read_needs_frame (sym.symbol)) |
699bd4cf | 1005 | pstate->block_tracker->update (sym); |
c906108c | 1006 | |
410a0ff2 | 1007 | write_exp_elt_opcode (pstate, OP_VAR_VALUE); |
d12307c1 PMR |
1008 | write_exp_elt_block (pstate, sym.block); |
1009 | write_exp_elt_sym (pstate, sym.symbol); | |
410a0ff2 | 1010 | write_exp_elt_opcode (pstate, OP_VAR_VALUE); } |
c906108c SS |
1011 | ; |
1012 | ||
48e32051 | 1013 | qualified_name: TYPENAME COLONCOLON name |
c906108c | 1014 | { |
48e32051 | 1015 | struct type *type = $1.type; |
f168693b | 1016 | type = check_typedef (type); |
3d567982 | 1017 | if (!type_aggregate_p (type)) |
001083c6 | 1018 | error (_("`%s' is not defined as an aggregate type."), |
7fc75ca7 | 1019 | TYPE_SAFE_NAME (type)); |
c906108c | 1020 | |
410a0ff2 SDJ |
1021 | write_exp_elt_opcode (pstate, OP_SCOPE); |
1022 | write_exp_elt_type (pstate, type); | |
1023 | write_exp_string (pstate, $3); | |
1024 | write_exp_elt_opcode (pstate, OP_SCOPE); | |
c906108c | 1025 | } |
48e32051 | 1026 | | TYPENAME COLONCOLON '~' name |
c906108c | 1027 | { |
48e32051 | 1028 | struct type *type = $1.type; |
c906108c | 1029 | struct stoken tmp_token; |
d7561cbb KS |
1030 | char *buf; |
1031 | ||
f168693b | 1032 | type = check_typedef (type); |
3d567982 | 1033 | if (!type_aggregate_p (type)) |
001083c6 | 1034 | error (_("`%s' is not defined as an aggregate type."), |
7fc75ca7 | 1035 | TYPE_SAFE_NAME (type)); |
224c3ddb | 1036 | buf = (char *) alloca ($4.length + 2); |
d7561cbb | 1037 | tmp_token.ptr = buf; |
c906108c | 1038 | tmp_token.length = $4.length + 1; |
d7561cbb KS |
1039 | buf[0] = '~'; |
1040 | memcpy (buf+1, $4.ptr, $4.length); | |
1041 | buf[tmp_token.length] = 0; | |
c906108c SS |
1042 | |
1043 | /* Check for valid destructor name. */ | |
d8228535 | 1044 | destructor_name_p (tmp_token.ptr, $1.type); |
410a0ff2 SDJ |
1045 | write_exp_elt_opcode (pstate, OP_SCOPE); |
1046 | write_exp_elt_type (pstate, type); | |
1047 | write_exp_string (pstate, tmp_token); | |
1048 | write_exp_elt_opcode (pstate, OP_SCOPE); | |
c906108c | 1049 | } |
48e32051 TT |
1050 | | TYPENAME COLONCOLON name COLONCOLON name |
1051 | { | |
1052 | char *copy = copy_name ($3); | |
1053 | error (_("No type \"%s\" within class " | |
1054 | "or namespace \"%s\"."), | |
7fc75ca7 | 1055 | copy, TYPE_SAFE_NAME ($1.type)); |
48e32051 | 1056 | } |
c906108c SS |
1057 | ; |
1058 | ||
1059 | variable: qualified_name | |
48e32051 | 1060 | | COLONCOLON name_not_typename |
c906108c | 1061 | { |
48e32051 | 1062 | char *name = copy_name ($2.stoken); |
c906108c | 1063 | struct symbol *sym; |
7c7b6655 | 1064 | struct bound_minimal_symbol msymbol; |
c906108c | 1065 | |
d12307c1 PMR |
1066 | sym |
1067 | = lookup_symbol (name, (const struct block *) NULL, | |
1068 | VAR_DOMAIN, NULL).symbol; | |
c906108c SS |
1069 | if (sym) |
1070 | { | |
410a0ff2 SDJ |
1071 | write_exp_elt_opcode (pstate, OP_VAR_VALUE); |
1072 | write_exp_elt_block (pstate, NULL); | |
1073 | write_exp_elt_sym (pstate, sym); | |
1074 | write_exp_elt_opcode (pstate, OP_VAR_VALUE); | |
c906108c SS |
1075 | break; |
1076 | } | |
1077 | ||
7c7b6655 TT |
1078 | msymbol = lookup_bound_minimal_symbol (name); |
1079 | if (msymbol.minsym != NULL) | |
410a0ff2 | 1080 | write_exp_msymbol (pstate, msymbol); |
c841afd5 | 1081 | else if (!have_full_symbols () && !have_partial_symbols ()) |
001083c6 | 1082 | error (_("No symbol table is loaded. Use the \"file\" command.")); |
c906108c | 1083 | else |
001083c6 | 1084 | error (_("No symbol \"%s\" in current context."), name); |
c906108c SS |
1085 | } |
1086 | ; | |
1087 | ||
1088 | variable: name_not_typename | |
d12307c1 | 1089 | { struct block_symbol sym = $1.sym; |
c906108c | 1090 | |
d12307c1 | 1091 | if (sym.symbol) |
c906108c | 1092 | { |
d12307c1 | 1093 | if (symbol_read_needs_frame (sym.symbol)) |
699bd4cf | 1094 | pstate->block_tracker->update (sym); |
c906108c | 1095 | |
ca31ab1d PA |
1096 | /* If we found a function, see if it's |
1097 | an ifunc resolver that has the same | |
1098 | address as the ifunc symbol itself. | |
1099 | If so, prefer the ifunc symbol. */ | |
1100 | ||
1101 | bound_minimal_symbol resolver | |
1102 | = find_gnu_ifunc (sym.symbol); | |
1103 | if (resolver.minsym != NULL) | |
1104 | write_exp_msymbol (pstate, resolver); | |
1105 | else | |
1106 | { | |
1107 | write_exp_elt_opcode (pstate, OP_VAR_VALUE); | |
1108 | write_exp_elt_block (pstate, sym.block); | |
1109 | write_exp_elt_sym (pstate, sym.symbol); | |
1110 | write_exp_elt_opcode (pstate, OP_VAR_VALUE); | |
1111 | } | |
c906108c SS |
1112 | } |
1113 | else if ($1.is_a_field_of_this) | |
1114 | { | |
1115 | /* C++: it hangs off of `this'. Must | |
1116 | not inadvertently convert from a method call | |
1117 | to data ref. */ | |
699bd4cf | 1118 | pstate->block_tracker->update (sym); |
410a0ff2 SDJ |
1119 | write_exp_elt_opcode (pstate, OP_THIS); |
1120 | write_exp_elt_opcode (pstate, OP_THIS); | |
1121 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); | |
1122 | write_exp_string (pstate, $1.stoken); | |
1123 | write_exp_elt_opcode (pstate, STRUCTOP_PTR); | |
c906108c SS |
1124 | } |
1125 | else | |
1126 | { | |
710122da | 1127 | char *arg = copy_name ($1.stoken); |
c906108c | 1128 | |
bf223d3e PA |
1129 | bound_minimal_symbol msymbol |
1130 | = lookup_bound_minimal_symbol (arg); | |
1131 | if (msymbol.minsym == NULL) | |
1132 | { | |
1133 | if (!have_full_symbols () && !have_partial_symbols ()) | |
1134 | error (_("No symbol table is loaded. Use the \"file\" command.")); | |
1135 | else | |
1136 | error (_("No symbol \"%s\" in current context."), | |
1137 | copy_name ($1.stoken)); | |
1138 | } | |
1139 | ||
1140 | /* This minsym might be an alias for | |
1141 | another function. See if we can find | |
1142 | the debug symbol for the target, and | |
1143 | if so, use it instead, since it has | |
1144 | return type / prototype info. This | |
1145 | is important for example for "p | |
1146 | *__errno_location()". */ | |
1147 | symbol *alias_target | |
f50776aa PA |
1148 | = ((msymbol.minsym->type != mst_text_gnu_ifunc |
1149 | && msymbol.minsym->type != mst_data_gnu_ifunc) | |
a376e11d PA |
1150 | ? find_function_alias_target (msymbol) |
1151 | : NULL); | |
bf223d3e PA |
1152 | if (alias_target != NULL) |
1153 | { | |
1154 | write_exp_elt_opcode (pstate, OP_VAR_VALUE); | |
1155 | write_exp_elt_block | |
1156 | (pstate, SYMBOL_BLOCK_VALUE (alias_target)); | |
1157 | write_exp_elt_sym (pstate, alias_target); | |
1158 | write_exp_elt_opcode (pstate, OP_VAR_VALUE); | |
1159 | } | |
c906108c | 1160 | else |
bf223d3e | 1161 | write_exp_msymbol (pstate, msymbol); |
c906108c SS |
1162 | } |
1163 | } | |
1164 | ; | |
1165 | ||
47663de5 | 1166 | space_identifier : '@' NAME |
dac43e32 TT |
1167 | { |
1168 | cpstate->type_stack.insert (pstate, copy_name ($2.stoken)); | |
1169 | } | |
47663de5 | 1170 | ; |
c906108c | 1171 | |
47663de5 MS |
1172 | const_or_volatile: const_or_volatile_noopt |
1173 | | | |
c906108c | 1174 | ; |
47663de5 MS |
1175 | |
1176 | cv_with_space_id : const_or_volatile space_identifier const_or_volatile | |
56e2d25a | 1177 | ; |
47663de5 MS |
1178 | |
1179 | const_or_volatile_or_space_identifier_noopt: cv_with_space_id | |
4d29c0a8 | 1180 | | const_or_volatile_noopt |
56e2d25a | 1181 | ; |
47663de5 | 1182 | |
4d29c0a8 | 1183 | const_or_volatile_or_space_identifier: |
47663de5 MS |
1184 | const_or_volatile_or_space_identifier_noopt |
1185 | | | |
56e2d25a | 1186 | ; |
47663de5 | 1187 | |
95c391b6 TT |
1188 | ptr_operator: |
1189 | ptr_operator '*' | |
dac43e32 | 1190 | { cpstate->type_stack.insert (tp_pointer); } |
95c391b6 | 1191 | const_or_volatile_or_space_identifier |
4d29c0a8 | 1192 | | '*' |
dac43e32 | 1193 | { cpstate->type_stack.insert (tp_pointer); } |
95c391b6 | 1194 | const_or_volatile_or_space_identifier |
c906108c | 1195 | | '&' |
dac43e32 | 1196 | { cpstate->type_stack.insert (tp_reference); } |
95c391b6 | 1197 | | '&' ptr_operator |
dac43e32 | 1198 | { cpstate->type_stack.insert (tp_reference); } |
53cc15f5 | 1199 | | ANDAND |
dac43e32 | 1200 | { cpstate->type_stack.insert (tp_rvalue_reference); } |
53cc15f5 | 1201 | | ANDAND ptr_operator |
dac43e32 | 1202 | { cpstate->type_stack.insert (tp_rvalue_reference); } |
95c391b6 TT |
1203 | ; |
1204 | ||
fcde5961 TT |
1205 | ptr_operator_ts: ptr_operator |
1206 | { | |
dac43e32 | 1207 | $$ = cpstate->type_stack.create (); |
02e12e38 | 1208 | cpstate->type_stacks.emplace_back ($$); |
fcde5961 TT |
1209 | } |
1210 | ; | |
1211 | ||
1212 | abs_decl: ptr_operator_ts direct_abs_decl | |
dac43e32 | 1213 | { $$ = $2->append ($1); } |
4d29c0a8 | 1214 | | ptr_operator_ts |
c906108c SS |
1215 | | direct_abs_decl |
1216 | ; | |
1217 | ||
1218 | direct_abs_decl: '(' abs_decl ')' | |
fcde5961 | 1219 | { $$ = $2; } |
c906108c SS |
1220 | | direct_abs_decl array_mod |
1221 | { | |
dac43e32 TT |
1222 | cpstate->type_stack.push ($1); |
1223 | cpstate->type_stack.push ($2); | |
1224 | cpstate->type_stack.push (tp_array); | |
1225 | $$ = cpstate->type_stack.create (); | |
ab759ca8 | 1226 | cpstate->type_stacks.emplace_back ($$); |
c906108c SS |
1227 | } |
1228 | | array_mod | |
1229 | { | |
dac43e32 TT |
1230 | cpstate->type_stack.push ($1); |
1231 | cpstate->type_stack.push (tp_array); | |
1232 | $$ = cpstate->type_stack.create (); | |
ab759ca8 | 1233 | cpstate->type_stacks.emplace_back ($$); |
c906108c SS |
1234 | } |
1235 | ||
1236 | | direct_abs_decl func_mod | |
fcde5961 | 1237 | { |
dac43e32 TT |
1238 | cpstate->type_stack.push ($1); |
1239 | cpstate->type_stack.push ($2); | |
1240 | $$ = cpstate->type_stack.create (); | |
ab759ca8 | 1241 | cpstate->type_stacks.emplace_back ($$); |
fcde5961 | 1242 | } |
c906108c | 1243 | | func_mod |
fcde5961 | 1244 | { |
dac43e32 TT |
1245 | cpstate->type_stack.push ($1); |
1246 | $$ = cpstate->type_stack.create (); | |
ab759ca8 | 1247 | cpstate->type_stacks.emplace_back ($$); |
fcde5961 | 1248 | } |
c906108c SS |
1249 | ; |
1250 | ||
1251 | array_mod: '[' ']' | |
1252 | { $$ = -1; } | |
f2e8016f TT |
1253 | | OBJC_LBRAC ']' |
1254 | { $$ = -1; } | |
c906108c SS |
1255 | | '[' INT ']' |
1256 | { $$ = $2.val; } | |
f2e8016f TT |
1257 | | OBJC_LBRAC INT ']' |
1258 | { $$ = $2.val; } | |
c906108c SS |
1259 | ; |
1260 | ||
1261 | func_mod: '(' ')' | |
02e12e38 TT |
1262 | { |
1263 | $$ = new std::vector<struct type *>; | |
1264 | cpstate->type_lists.emplace_back ($$); | |
1265 | } | |
a6fb9c08 | 1266 | | '(' parameter_typelist ')' |
71918a86 | 1267 | { $$ = $2; } |
c906108c SS |
1268 | ; |
1269 | ||
a22229c4 | 1270 | /* We used to try to recognize pointer to member types here, but |
c906108c SS |
1271 | that didn't work (shift/reduce conflicts meant that these rules never |
1272 | got executed). The problem is that | |
1273 | int (foo::bar::baz::bizzle) | |
1274 | is a function type but | |
1275 | int (foo::bar::baz::bizzle::*) | |
1276 | is a pointer to member type. Stroustrup loses again! */ | |
1277 | ||
1278 | type : ptype | |
c906108c SS |
1279 | ; |
1280 | ||
b6c95c0c AB |
1281 | /* Implements (approximately): (type-qualifier)* type-specifier. |
1282 | ||
1283 | When type-specifier is only ever a single word, like 'float' then these | |
1284 | arrive as pre-built TYPENAME tokens thanks to the classify_name | |
1285 | function. However, when a type-specifier can contain multiple words, | |
1286 | for example 'double' can appear as just 'double' or 'long double', and | |
1287 | similarly 'long' can appear as just 'long' or in 'long double', then | |
1288 | these type-specifiers are parsed into their own tokens in the function | |
1289 | lex_one_token and the ident_tokens array. These separate tokens are all | |
1290 | recognised here. */ | |
1291 | typebase | |
c906108c SS |
1292 | : TYPENAME |
1293 | { $$ = $1.type; } | |
1294 | | INT_KEYWORD | |
73923d7e | 1295 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1296 | pstate->gdbarch (), |
f4b8a18d | 1297 | "int"); } |
c906108c | 1298 | | LONG |
73923d7e | 1299 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1300 | pstate->gdbarch (), |
f4b8a18d | 1301 | "long"); } |
c906108c | 1302 | | SHORT |
73923d7e | 1303 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1304 | pstate->gdbarch (), |
f4b8a18d | 1305 | "short"); } |
c906108c | 1306 | | LONG INT_KEYWORD |
73923d7e | 1307 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1308 | pstate->gdbarch (), |
f4b8a18d | 1309 | "long"); } |
b2c4da81 | 1310 | | LONG SIGNED_KEYWORD INT_KEYWORD |
73923d7e | 1311 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1312 | pstate->gdbarch (), |
f4b8a18d | 1313 | "long"); } |
b2c4da81 | 1314 | | LONG SIGNED_KEYWORD |
73923d7e | 1315 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1316 | pstate->gdbarch (), |
f4b8a18d | 1317 | "long"); } |
b2c4da81 | 1318 | | SIGNED_KEYWORD LONG INT_KEYWORD |
73923d7e | 1319 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1320 | pstate->gdbarch (), |
f4b8a18d | 1321 | "long"); } |
c906108c | 1322 | | UNSIGNED LONG INT_KEYWORD |
73923d7e | 1323 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1324 | pstate->gdbarch (), |
f4b8a18d | 1325 | "long"); } |
b2c4da81 | 1326 | | LONG UNSIGNED INT_KEYWORD |
73923d7e | 1327 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1328 | pstate->gdbarch (), |
f4b8a18d | 1329 | "long"); } |
b2c4da81 | 1330 | | LONG UNSIGNED |
73923d7e | 1331 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1332 | pstate->gdbarch (), |
f4b8a18d | 1333 | "long"); } |
c906108c | 1334 | | LONG LONG |
73923d7e | 1335 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1336 | pstate->gdbarch (), |
f4b8a18d | 1337 | "long long"); } |
c906108c | 1338 | | LONG LONG INT_KEYWORD |
73923d7e | 1339 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1340 | pstate->gdbarch (), |
f4b8a18d | 1341 | "long long"); } |
b2c4da81 | 1342 | | LONG LONG SIGNED_KEYWORD INT_KEYWORD |
73923d7e | 1343 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1344 | pstate->gdbarch (), |
f4b8a18d | 1345 | "long long"); } |
b2c4da81 | 1346 | | LONG LONG SIGNED_KEYWORD |
73923d7e | 1347 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1348 | pstate->gdbarch (), |
f4b8a18d | 1349 | "long long"); } |
b2c4da81 | 1350 | | SIGNED_KEYWORD LONG LONG |
73923d7e | 1351 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1352 | pstate->gdbarch (), |
f4b8a18d | 1353 | "long long"); } |
55baeb84 | 1354 | | SIGNED_KEYWORD LONG LONG INT_KEYWORD |
73923d7e | 1355 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1356 | pstate->gdbarch (), |
f4b8a18d | 1357 | "long long"); } |
c906108c | 1358 | | UNSIGNED LONG LONG |
73923d7e | 1359 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1360 | pstate->gdbarch (), |
f4b8a18d | 1361 | "long long"); } |
c906108c | 1362 | | UNSIGNED LONG LONG INT_KEYWORD |
73923d7e | 1363 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1364 | pstate->gdbarch (), |
f4b8a18d | 1365 | "long long"); } |
b2c4da81 | 1366 | | LONG LONG UNSIGNED |
73923d7e | 1367 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1368 | pstate->gdbarch (), |
f4b8a18d | 1369 | "long long"); } |
b2c4da81 | 1370 | | LONG LONG UNSIGNED INT_KEYWORD |
73923d7e | 1371 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1372 | pstate->gdbarch (), |
f4b8a18d | 1373 | "long long"); } |
c906108c | 1374 | | SHORT INT_KEYWORD |
73923d7e | 1375 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1376 | pstate->gdbarch (), |
f4b8a18d | 1377 | "short"); } |
b2c4da81 | 1378 | | SHORT SIGNED_KEYWORD INT_KEYWORD |
73923d7e | 1379 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1380 | pstate->gdbarch (), |
f4b8a18d | 1381 | "short"); } |
b2c4da81 | 1382 | | SHORT SIGNED_KEYWORD |
73923d7e | 1383 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1384 | pstate->gdbarch (), |
f4b8a18d | 1385 | "short"); } |
c906108c | 1386 | | UNSIGNED SHORT INT_KEYWORD |
73923d7e | 1387 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1388 | pstate->gdbarch (), |
f4b8a18d | 1389 | "short"); } |
4d29c0a8 | 1390 | | SHORT UNSIGNED |
73923d7e | 1391 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1392 | pstate->gdbarch (), |
f4b8a18d | 1393 | "short"); } |
b2c4da81 | 1394 | | SHORT UNSIGNED INT_KEYWORD |
73923d7e | 1395 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1396 | pstate->gdbarch (), |
f4b8a18d | 1397 | "short"); } |
c906108c | 1398 | | DOUBLE_KEYWORD |
73923d7e | 1399 | { $$ = lookup_typename (pstate->language (), |
fa9f5be6 | 1400 | pstate->gdbarch (), |
410a0ff2 | 1401 | "double", |
582942f4 | 1402 | NULL, |
f4b8a18d | 1403 | 0); } |
c906108c | 1404 | | LONG DOUBLE_KEYWORD |
73923d7e | 1405 | { $$ = lookup_typename (pstate->language (), |
fa9f5be6 | 1406 | pstate->gdbarch (), |
f4b8a18d | 1407 | "long double", |
582942f4 | 1408 | NULL, |
410a0ff2 | 1409 | 0); } |
c906108c | 1410 | | STRUCT name |
1e58a4a4 TT |
1411 | { $$ |
1412 | = lookup_struct (copy_name ($2), | |
1413 | pstate->expression_context_block); | |
1414 | } | |
2f68a895 TT |
1415 | | STRUCT COMPLETE |
1416 | { | |
2a612529 TT |
1417 | pstate->mark_completion_tag (TYPE_CODE_STRUCT, |
1418 | "", 0); | |
2f68a895 TT |
1419 | $$ = NULL; |
1420 | } | |
1421 | | STRUCT name COMPLETE | |
1422 | { | |
2a612529 TT |
1423 | pstate->mark_completion_tag (TYPE_CODE_STRUCT, |
1424 | $2.ptr, $2.length); | |
2f68a895 TT |
1425 | $$ = NULL; |
1426 | } | |
c906108c | 1427 | | CLASS name |
1e58a4a4 TT |
1428 | { $$ = lookup_struct |
1429 | (copy_name ($2), pstate->expression_context_block); | |
1430 | } | |
2f68a895 TT |
1431 | | CLASS COMPLETE |
1432 | { | |
2a612529 TT |
1433 | pstate->mark_completion_tag (TYPE_CODE_STRUCT, |
1434 | "", 0); | |
2f68a895 TT |
1435 | $$ = NULL; |
1436 | } | |
1437 | | CLASS name COMPLETE | |
1438 | { | |
2a612529 TT |
1439 | pstate->mark_completion_tag (TYPE_CODE_STRUCT, |
1440 | $2.ptr, $2.length); | |
2f68a895 TT |
1441 | $$ = NULL; |
1442 | } | |
c906108c | 1443 | | UNION name |
1e58a4a4 TT |
1444 | { $$ |
1445 | = lookup_union (copy_name ($2), | |
1446 | pstate->expression_context_block); | |
1447 | } | |
2f68a895 TT |
1448 | | UNION COMPLETE |
1449 | { | |
2a612529 TT |
1450 | pstate->mark_completion_tag (TYPE_CODE_UNION, |
1451 | "", 0); | |
2f68a895 TT |
1452 | $$ = NULL; |
1453 | } | |
1454 | | UNION name COMPLETE | |
1455 | { | |
2a612529 TT |
1456 | pstate->mark_completion_tag (TYPE_CODE_UNION, |
1457 | $2.ptr, $2.length); | |
2f68a895 TT |
1458 | $$ = NULL; |
1459 | } | |
c906108c SS |
1460 | | ENUM name |
1461 | { $$ = lookup_enum (copy_name ($2), | |
1e58a4a4 TT |
1462 | pstate->expression_context_block); |
1463 | } | |
2f68a895 TT |
1464 | | ENUM COMPLETE |
1465 | { | |
2a612529 | 1466 | pstate->mark_completion_tag (TYPE_CODE_ENUM, "", 0); |
2f68a895 TT |
1467 | $$ = NULL; |
1468 | } | |
1469 | | ENUM name COMPLETE | |
1470 | { | |
2a612529 TT |
1471 | pstate->mark_completion_tag (TYPE_CODE_ENUM, $2.ptr, |
1472 | $2.length); | |
2f68a895 TT |
1473 | $$ = NULL; |
1474 | } | |
fe978cb0 | 1475 | | UNSIGNED type_name |
73923d7e | 1476 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1477 | pstate->gdbarch (), |
e6c014f2 | 1478 | TYPE_NAME($2.type)); } |
c906108c | 1479 | | UNSIGNED |
73923d7e | 1480 | { $$ = lookup_unsigned_typename (pstate->language (), |
fa9f5be6 | 1481 | pstate->gdbarch (), |
f4b8a18d | 1482 | "int"); } |
fe978cb0 | 1483 | | SIGNED_KEYWORD type_name |
73923d7e | 1484 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1485 | pstate->gdbarch (), |
e6c014f2 | 1486 | TYPE_NAME($2.type)); } |
c906108c | 1487 | | SIGNED_KEYWORD |
73923d7e | 1488 | { $$ = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1489 | pstate->gdbarch (), |
f4b8a18d | 1490 | "int"); } |
c906108c SS |
1491 | /* It appears that this rule for templates is never |
1492 | reduced; template recognition happens by lookahead | |
4d29c0a8 | 1493 | in the token processing code in yylex. */ |
c906108c | 1494 | | TEMPLATE name '<' type '>' |
1e58a4a4 TT |
1495 | { $$ = lookup_template_type |
1496 | (copy_name($2), $4, | |
1497 | pstate->expression_context_block); | |
c906108c | 1498 | } |
4d29c0a8 | 1499 | | const_or_volatile_or_space_identifier_noopt typebase |
dac43e32 | 1500 | { $$ = cpstate->type_stack.follow_types ($2); } |
4d29c0a8 | 1501 | | typebase const_or_volatile_or_space_identifier_noopt |
dac43e32 | 1502 | { $$ = cpstate->type_stack.follow_types ($1); } |
c906108c SS |
1503 | ; |
1504 | ||
fe978cb0 | 1505 | type_name: TYPENAME |
c906108c SS |
1506 | | INT_KEYWORD |
1507 | { | |
1508 | $$.stoken.ptr = "int"; | |
1509 | $$.stoken.length = 3; | |
73923d7e | 1510 | $$.type = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1511 | pstate->gdbarch (), |
f4b8a18d | 1512 | "int"); |
c906108c SS |
1513 | } |
1514 | | LONG | |
1515 | { | |
1516 | $$.stoken.ptr = "long"; | |
1517 | $$.stoken.length = 4; | |
73923d7e | 1518 | $$.type = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1519 | pstate->gdbarch (), |
f4b8a18d | 1520 | "long"); |
c906108c SS |
1521 | } |
1522 | | SHORT | |
1523 | { | |
1524 | $$.stoken.ptr = "short"; | |
1525 | $$.stoken.length = 5; | |
73923d7e | 1526 | $$.type = lookup_signed_typename (pstate->language (), |
fa9f5be6 | 1527 | pstate->gdbarch (), |
f4b8a18d | 1528 | "short"); |
c906108c SS |
1529 | } |
1530 | ; | |
1531 | ||
a6fb9c08 TT |
1532 | parameter_typelist: |
1533 | nonempty_typelist | |
e314d629 | 1534 | { check_parameter_typelist ($1); } |
a6fb9c08 TT |
1535 | | nonempty_typelist ',' DOTDOTDOT |
1536 | { | |
02e12e38 | 1537 | $1->push_back (NULL); |
e314d629 | 1538 | check_parameter_typelist ($1); |
a6fb9c08 TT |
1539 | $$ = $1; |
1540 | } | |
1541 | ; | |
1542 | ||
c906108c SS |
1543 | nonempty_typelist |
1544 | : type | |
71918a86 | 1545 | { |
02e12e38 TT |
1546 | std::vector<struct type *> *typelist |
1547 | = new std::vector<struct type *>; | |
1548 | cpstate->type_lists.emplace_back (typelist); | |
1549 | ||
1550 | typelist->push_back ($1); | |
71918a86 | 1551 | $$ = typelist; |
c906108c SS |
1552 | } |
1553 | | nonempty_typelist ',' type | |
71918a86 | 1554 | { |
02e12e38 | 1555 | $1->push_back ($3); |
71918a86 | 1556 | $$ = $1; |
c906108c SS |
1557 | } |
1558 | ; | |
1559 | ||
47663de5 | 1560 | ptype : typebase |
95c391b6 | 1561 | | ptype abs_decl |
fcde5961 | 1562 | { |
dac43e32 TT |
1563 | cpstate->type_stack.push ($2); |
1564 | $$ = cpstate->type_stack.follow_types ($1); | |
fcde5961 | 1565 | } |
47663de5 MS |
1566 | ; |
1567 | ||
95c391b6 | 1568 | conversion_type_id: typebase conversion_declarator |
dac43e32 | 1569 | { $$ = cpstate->type_stack.follow_types ($1); } |
95c391b6 TT |
1570 | ; |
1571 | ||
1572 | conversion_declarator: /* Nothing. */ | |
1573 | | ptr_operator conversion_declarator | |
1574 | ; | |
1575 | ||
47663de5 MS |
1576 | const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD |
1577 | | VOLATILE_KEYWORD CONST_KEYWORD | |
1578 | ; | |
1579 | ||
4d29c0a8 | 1580 | const_or_volatile_noopt: const_and_volatile |
dac43e32 TT |
1581 | { cpstate->type_stack.insert (tp_const); |
1582 | cpstate->type_stack.insert (tp_volatile); | |
47663de5 MS |
1583 | } |
1584 | | CONST_KEYWORD | |
dac43e32 | 1585 | { cpstate->type_stack.insert (tp_const); } |
47663de5 | 1586 | | VOLATILE_KEYWORD |
dac43e32 | 1587 | { cpstate->type_stack.insert (tp_volatile); } |
47663de5 MS |
1588 | ; |
1589 | ||
fe978cb0 | 1590 | oper: OPERATOR NEW |
66c53f2b KS |
1591 | { $$ = operator_stoken (" new"); } |
1592 | | OPERATOR DELETE | |
4cd18215 | 1593 | { $$ = operator_stoken (" delete"); } |
66c53f2b KS |
1594 | | OPERATOR NEW '[' ']' |
1595 | { $$ = operator_stoken (" new[]"); } | |
1596 | | OPERATOR DELETE '[' ']' | |
4cd18215 | 1597 | { $$ = operator_stoken (" delete[]"); } |
f2e8016f TT |
1598 | | OPERATOR NEW OBJC_LBRAC ']' |
1599 | { $$ = operator_stoken (" new[]"); } | |
1600 | | OPERATOR DELETE OBJC_LBRAC ']' | |
1601 | { $$ = operator_stoken (" delete[]"); } | |
66c53f2b KS |
1602 | | OPERATOR '+' |
1603 | { $$ = operator_stoken ("+"); } | |
1604 | | OPERATOR '-' | |
1605 | { $$ = operator_stoken ("-"); } | |
1606 | | OPERATOR '*' | |
1607 | { $$ = operator_stoken ("*"); } | |
1608 | | OPERATOR '/' | |
1609 | { $$ = operator_stoken ("/"); } | |
1610 | | OPERATOR '%' | |
1611 | { $$ = operator_stoken ("%"); } | |
1612 | | OPERATOR '^' | |
1613 | { $$ = operator_stoken ("^"); } | |
1614 | | OPERATOR '&' | |
1615 | { $$ = operator_stoken ("&"); } | |
1616 | | OPERATOR '|' | |
1617 | { $$ = operator_stoken ("|"); } | |
1618 | | OPERATOR '~' | |
1619 | { $$ = operator_stoken ("~"); } | |
1620 | | OPERATOR '!' | |
1621 | { $$ = operator_stoken ("!"); } | |
1622 | | OPERATOR '=' | |
1623 | { $$ = operator_stoken ("="); } | |
1624 | | OPERATOR '<' | |
1625 | { $$ = operator_stoken ("<"); } | |
1626 | | OPERATOR '>' | |
1627 | { $$ = operator_stoken (">"); } | |
1628 | | OPERATOR ASSIGN_MODIFY | |
c8ba13ad | 1629 | { const char *op = " unknown"; |
66c53f2b KS |
1630 | switch ($2) |
1631 | { | |
1632 | case BINOP_RSH: | |
1633 | op = ">>="; | |
1634 | break; | |
1635 | case BINOP_LSH: | |
1636 | op = "<<="; | |
1637 | break; | |
1638 | case BINOP_ADD: | |
1639 | op = "+="; | |
1640 | break; | |
1641 | case BINOP_SUB: | |
1642 | op = "-="; | |
1643 | break; | |
1644 | case BINOP_MUL: | |
1645 | op = "*="; | |
1646 | break; | |
1647 | case BINOP_DIV: | |
1648 | op = "/="; | |
1649 | break; | |
1650 | case BINOP_REM: | |
1651 | op = "%="; | |
1652 | break; | |
1653 | case BINOP_BITWISE_IOR: | |
1654 | op = "|="; | |
1655 | break; | |
1656 | case BINOP_BITWISE_AND: | |
1657 | op = "&="; | |
1658 | break; | |
1659 | case BINOP_BITWISE_XOR: | |
1660 | op = "^="; | |
1661 | break; | |
1662 | default: | |
1663 | break; | |
1664 | } | |
1665 | ||
1666 | $$ = operator_stoken (op); | |
1667 | } | |
1668 | | OPERATOR LSH | |
1669 | { $$ = operator_stoken ("<<"); } | |
1670 | | OPERATOR RSH | |
1671 | { $$ = operator_stoken (">>"); } | |
1672 | | OPERATOR EQUAL | |
1673 | { $$ = operator_stoken ("=="); } | |
1674 | | OPERATOR NOTEQUAL | |
1675 | { $$ = operator_stoken ("!="); } | |
1676 | | OPERATOR LEQ | |
1677 | { $$ = operator_stoken ("<="); } | |
1678 | | OPERATOR GEQ | |
1679 | { $$ = operator_stoken (">="); } | |
1680 | | OPERATOR ANDAND | |
1681 | { $$ = operator_stoken ("&&"); } | |
1682 | | OPERATOR OROR | |
1683 | { $$ = operator_stoken ("||"); } | |
1684 | | OPERATOR INCREMENT | |
1685 | { $$ = operator_stoken ("++"); } | |
1686 | | OPERATOR DECREMENT | |
1687 | { $$ = operator_stoken ("--"); } | |
1688 | | OPERATOR ',' | |
1689 | { $$ = operator_stoken (","); } | |
1690 | | OPERATOR ARROW_STAR | |
1691 | { $$ = operator_stoken ("->*"); } | |
1692 | | OPERATOR ARROW | |
1693 | { $$ = operator_stoken ("->"); } | |
1694 | | OPERATOR '(' ')' | |
1695 | { $$ = operator_stoken ("()"); } | |
1696 | | OPERATOR '[' ']' | |
1697 | { $$ = operator_stoken ("[]"); } | |
f2e8016f TT |
1698 | | OPERATOR OBJC_LBRAC ']' |
1699 | { $$ = operator_stoken ("[]"); } | |
95c391b6 | 1700 | | OPERATOR conversion_type_id |
d7e74731 | 1701 | { string_file buf; |
66c53f2b | 1702 | |
d7e74731 | 1703 | c_print_type ($2, NULL, &buf, -1, 0, |
79d43c61 | 1704 | &type_print_raw_options); |
c8ba13ad KS |
1705 | |
1706 | /* This also needs canonicalization. */ | |
1707 | std::string canon | |
1708 | = cp_canonicalize_string (buf.c_str ()); | |
1709 | if (canon.empty ()) | |
1710 | canon = std::move (buf.string ()); | |
1711 | $$ = operator_stoken ((" " + canon).c_str ()); | |
66c53f2b KS |
1712 | } |
1713 | ; | |
1714 | ||
6f0ffe50 AB |
1715 | /* This rule exists in order to allow some tokens that would not normally |
1716 | match the 'name' rule to appear as fields within a struct. The example | |
1717 | that initially motivated this was the RISC-V target which models the | |
1718 | floating point registers as a union with fields called 'float' and | |
1719 | 'double'. The 'float' string becomes a TYPENAME token and can appear | |
1720 | anywhere a 'name' can, however 'double' is its own token, | |
1721 | DOUBLE_KEYWORD, and doesn't match the 'name' rule.*/ | |
0f5d3f63 AB |
1722 | field_name |
1723 | : name | |
6f0ffe50 AB |
1724 | | DOUBLE_KEYWORD { $$ = typename_stoken ("double"); } |
1725 | | INT_KEYWORD { $$ = typename_stoken ("int"); } | |
1726 | | LONG { $$ = typename_stoken ("long"); } | |
1727 | | SHORT { $$ = typename_stoken ("short"); } | |
1728 | | SIGNED_KEYWORD { $$ = typename_stoken ("signed"); } | |
1729 | | UNSIGNED { $$ = typename_stoken ("unsigned"); } | |
0f5d3f63 | 1730 | ; |
66c53f2b | 1731 | |
c906108c SS |
1732 | name : NAME { $$ = $1.stoken; } |
1733 | | BLOCKNAME { $$ = $1.stoken; } | |
1734 | | TYPENAME { $$ = $1.stoken; } | |
1735 | | NAME_OR_INT { $$ = $1.stoken; } | |
7322dca9 | 1736 | | UNKNOWN_CPP_NAME { $$ = $1.stoken; } |
fe978cb0 | 1737 | | oper { $$ = $1; } |
c906108c SS |
1738 | ; |
1739 | ||
1740 | name_not_typename : NAME | |
1741 | | BLOCKNAME | |
1742 | /* These would be useful if name_not_typename was useful, but it is just | |
1743 | a fake for "variable", so these cause reduce/reduce conflicts because | |
1744 | the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable, | |
1745 | =exp) or just an exp. If name_not_typename was ever used in an lvalue | |
1746 | context where only a name could occur, this might be useful. | |
1747 | | NAME_OR_INT | |
1748 | */ | |
fe978cb0 | 1749 | | oper |
6e31430b | 1750 | { |
1993b719 TT |
1751 | struct field_of_this_result is_a_field_of_this; |
1752 | ||
6e31430b | 1753 | $$.stoken = $1; |
1e58a4a4 TT |
1754 | $$.sym |
1755 | = lookup_symbol ($1.ptr, | |
1756 | pstate->expression_context_block, | |
1757 | VAR_DOMAIN, | |
1758 | &is_a_field_of_this); | |
1993b719 TT |
1759 | $$.is_a_field_of_this |
1760 | = is_a_field_of_this.type != NULL; | |
6e31430b | 1761 | } |
7322dca9 | 1762 | | UNKNOWN_CPP_NAME |
c906108c SS |
1763 | ; |
1764 | ||
1765 | %% | |
1766 | ||
24955f63 TT |
1767 | /* Like write_exp_string, but prepends a '~'. */ |
1768 | ||
1769 | static void | |
410a0ff2 | 1770 | write_destructor_name (struct parser_state *par_state, struct stoken token) |
24955f63 | 1771 | { |
224c3ddb | 1772 | char *copy = (char *) alloca (token.length + 1); |
24955f63 TT |
1773 | |
1774 | copy[0] = '~'; | |
1775 | memcpy (©[1], token.ptr, token.length); | |
1776 | ||
1777 | token.ptr = copy; | |
1778 | ++token.length; | |
1779 | ||
410a0ff2 | 1780 | write_exp_string (par_state, token); |
24955f63 TT |
1781 | } |
1782 | ||
66c53f2b | 1783 | /* Returns a stoken of the operator name given by OP (which does not |
4d29c0a8 DE |
1784 | include the string "operator"). */ |
1785 | ||
66c53f2b KS |
1786 | static struct stoken |
1787 | operator_stoken (const char *op) | |
1788 | { | |
66c53f2b | 1789 | struct stoken st = { NULL, 0 }; |
d7561cbb KS |
1790 | char *buf; |
1791 | ||
8090b426 | 1792 | st.length = CP_OPERATOR_LEN + strlen (op); |
224c3ddb | 1793 | buf = (char *) malloc (st.length + 1); |
8090b426 | 1794 | strcpy (buf, CP_OPERATOR_STR); |
d7561cbb KS |
1795 | strcat (buf, op); |
1796 | st.ptr = buf; | |
66c53f2b KS |
1797 | |
1798 | /* The toplevel (c_parse) will free the memory allocated here. */ | |
c65bac38 | 1799 | cpstate->strings.emplace_back (buf); |
66c53f2b KS |
1800 | return st; |
1801 | }; | |
1802 | ||
6f0ffe50 AB |
1803 | /* Returns a stoken of the type named TYPE. */ |
1804 | ||
1805 | static struct stoken | |
1806 | typename_stoken (const char *type) | |
1807 | { | |
1808 | struct stoken st = { type, 0 }; | |
1809 | st.length = strlen (type); | |
1810 | return st; | |
1811 | }; | |
1812 | ||
3d567982 TT |
1813 | /* Return true if the type is aggregate-like. */ |
1814 | ||
1815 | static int | |
1816 | type_aggregate_p (struct type *type) | |
1817 | { | |
1818 | return (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1819 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
1820 | || TYPE_CODE (type) == TYPE_CODE_NAMESPACE | |
1821 | || (TYPE_CODE (type) == TYPE_CODE_ENUM | |
1822 | && TYPE_DECLARED_CLASS (type))); | |
1823 | } | |
1824 | ||
e314d629 TT |
1825 | /* Validate a parameter typelist. */ |
1826 | ||
1827 | static void | |
02e12e38 | 1828 | check_parameter_typelist (std::vector<struct type *> *params) |
e314d629 TT |
1829 | { |
1830 | struct type *type; | |
1831 | int ix; | |
1832 | ||
02e12e38 | 1833 | for (ix = 0; ix < params->size (); ++ix) |
e314d629 | 1834 | { |
02e12e38 | 1835 | type = (*params)[ix]; |
e314d629 TT |
1836 | if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID) |
1837 | { | |
1838 | if (ix == 0) | |
1839 | { | |
02e12e38 | 1840 | if (params->size () == 1) |
e314d629 TT |
1841 | { |
1842 | /* Ok. */ | |
1843 | break; | |
1844 | } | |
e314d629 TT |
1845 | error (_("parameter types following 'void'")); |
1846 | } | |
1847 | else | |
02e12e38 | 1848 | error (_("'void' invalid as parameter type")); |
e314d629 TT |
1849 | } |
1850 | } | |
1851 | } | |
1852 | ||
c906108c SS |
1853 | /* Take care of parsing a number (anything that starts with a digit). |
1854 | Set yylval and return the token type; update lexptr. | |
1855 | LEN is the number of characters in it. */ | |
1856 | ||
1857 | /*** Needs some error checking for the float case ***/ | |
1858 | ||
1859 | static int | |
410a0ff2 SDJ |
1860 | parse_number (struct parser_state *par_state, |
1861 | const char *buf, int len, int parsed_float, YYSTYPE *putithere) | |
c906108c | 1862 | { |
20562150 TT |
1863 | ULONGEST n = 0; |
1864 | ULONGEST prevn = 0; | |
c906108c SS |
1865 | ULONGEST un; |
1866 | ||
710122da DC |
1867 | int i = 0; |
1868 | int c; | |
1869 | int base = input_radix; | |
c906108c SS |
1870 | int unsigned_p = 0; |
1871 | ||
1872 | /* Number of "L" suffixes encountered. */ | |
1873 | int long_p = 0; | |
1874 | ||
1875 | /* We have found a "L" or "U" suffix. */ | |
1876 | int found_suffix = 0; | |
1877 | ||
1878 | ULONGEST high_bit; | |
1879 | struct type *signed_type; | |
1880 | struct type *unsigned_type; | |
d7561cbb KS |
1881 | char *p; |
1882 | ||
224c3ddb | 1883 | p = (char *) alloca (len); |
d7561cbb | 1884 | memcpy (p, buf, len); |
c906108c SS |
1885 | |
1886 | if (parsed_float) | |
1887 | { | |
edd079d9 | 1888 | /* Handle suffixes for decimal floating-point: "df", "dd" or "dl". */ |
fe9441f6 | 1889 | if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f') |
27bc4d80 | 1890 | { |
edd079d9 | 1891 | putithere->typed_val_float.type |
410a0ff2 | 1892 | = parse_type (par_state)->builtin_decfloat; |
edd079d9 | 1893 | len -= 2; |
27bc4d80 | 1894 | } |
edd079d9 | 1895 | else if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd') |
27bc4d80 | 1896 | { |
edd079d9 | 1897 | putithere->typed_val_float.type |
410a0ff2 | 1898 | = parse_type (par_state)->builtin_decdouble; |
edd079d9 | 1899 | len -= 2; |
27bc4d80 | 1900 | } |
edd079d9 | 1901 | else if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l') |
27bc4d80 | 1902 | { |
edd079d9 | 1903 | putithere->typed_val_float.type |
410a0ff2 | 1904 | = parse_type (par_state)->builtin_declong; |
edd079d9 UW |
1905 | len -= 2; |
1906 | } | |
1907 | /* Handle suffixes: 'f' for float, 'l' for long double. */ | |
b1b60145 | 1908 | else if (len >= 1 && TOLOWER (p[len - 1]) == 'f') |
edd079d9 UW |
1909 | { |
1910 | putithere->typed_val_float.type | |
1911 | = parse_type (par_state)->builtin_float; | |
1912 | len -= 1; | |
1913 | } | |
b1b60145 | 1914 | else if (len >= 1 && TOLOWER (p[len - 1]) == 'l') |
edd079d9 UW |
1915 | { |
1916 | putithere->typed_val_float.type | |
1917 | = parse_type (par_state)->builtin_long_double; | |
1918 | len -= 1; | |
1919 | } | |
1920 | /* Default type for floating-point literals is double. */ | |
1921 | else | |
1922 | { | |
1923 | putithere->typed_val_float.type | |
1924 | = parse_type (par_state)->builtin_double; | |
27bc4d80 TJB |
1925 | } |
1926 | ||
edd079d9 UW |
1927 | if (!parse_float (p, len, |
1928 | putithere->typed_val_float.type, | |
1929 | putithere->typed_val_float.val)) | |
1930 | return ERROR; | |
c906108c SS |
1931 | return FLOAT; |
1932 | } | |
1933 | ||
1934 | /* Handle base-switching prefixes 0x, 0t, 0d, 0 */ | |
ebf13736 | 1935 | if (p[0] == '0' && len > 1) |
c906108c SS |
1936 | switch (p[1]) |
1937 | { | |
1938 | case 'x': | |
1939 | case 'X': | |
1940 | if (len >= 3) | |
1941 | { | |
1942 | p += 2; | |
1943 | base = 16; | |
1944 | len -= 2; | |
1945 | } | |
1946 | break; | |
1947 | ||
b5cfddf5 JK |
1948 | case 'b': |
1949 | case 'B': | |
1950 | if (len >= 3) | |
1951 | { | |
1952 | p += 2; | |
1953 | base = 2; | |
1954 | len -= 2; | |
1955 | } | |
1956 | break; | |
1957 | ||
c906108c SS |
1958 | case 't': |
1959 | case 'T': | |
1960 | case 'd': | |
1961 | case 'D': | |
1962 | if (len >= 3) | |
1963 | { | |
1964 | p += 2; | |
1965 | base = 10; | |
1966 | len -= 2; | |
1967 | } | |
1968 | break; | |
1969 | ||
1970 | default: | |
1971 | base = 8; | |
1972 | break; | |
1973 | } | |
1974 | ||
1975 | while (len-- > 0) | |
1976 | { | |
1977 | c = *p++; | |
1978 | if (c >= 'A' && c <= 'Z') | |
1979 | c += 'a' - 'A'; | |
1980 | if (c != 'l' && c != 'u') | |
1981 | n *= base; | |
1982 | if (c >= '0' && c <= '9') | |
1983 | { | |
1984 | if (found_suffix) | |
1985 | return ERROR; | |
1986 | n += i = c - '0'; | |
1987 | } | |
1988 | else | |
1989 | { | |
1990 | if (base > 10 && c >= 'a' && c <= 'f') | |
1991 | { | |
1992 | if (found_suffix) | |
1993 | return ERROR; | |
1994 | n += i = c - 'a' + 10; | |
1995 | } | |
1996 | else if (c == 'l') | |
1997 | { | |
1998 | ++long_p; | |
1999 | found_suffix = 1; | |
2000 | } | |
2001 | else if (c == 'u') | |
2002 | { | |
2003 | unsigned_p = 1; | |
2004 | found_suffix = 1; | |
2005 | } | |
2006 | else | |
2007 | return ERROR; /* Char not a digit */ | |
2008 | } | |
2009 | if (i >= base) | |
2010 | return ERROR; /* Invalid digit in this base */ | |
2011 | ||
2012 | /* Portably test for overflow (only works for nonzero values, so make | |
2013 | a second check for zero). FIXME: Can't we just make n and prevn | |
2014 | unsigned and avoid this? */ | |
2015 | if (c != 'l' && c != 'u' && (prevn >= n) && n != 0) | |
2016 | unsigned_p = 1; /* Try something unsigned */ | |
2017 | ||
2018 | /* Portably test for unsigned overflow. | |
2019 | FIXME: This check is wrong; for example it doesn't find overflow | |
2020 | on 0x123456789 when LONGEST is 32 bits. */ | |
2021 | if (c != 'l' && c != 'u' && n != 0) | |
2022 | { | |
20562150 | 2023 | if (unsigned_p && prevn >= n) |
001083c6 | 2024 | error (_("Numeric constant too large.")); |
c906108c SS |
2025 | } |
2026 | prevn = n; | |
2027 | } | |
2028 | ||
2029 | /* An integer constant is an int, a long, or a long long. An L | |
2030 | suffix forces it to be long; an LL suffix forces it to be long | |
2031 | long. If not forced to a larger size, it gets the first type of | |
2032 | the above that it fits in. To figure out whether it fits, we | |
2033 | shift it right and see whether anything remains. Note that we | |
2034 | can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one | |
2035 | operation, because many compilers will warn about such a shift | |
9a76efb6 UW |
2036 | (which always produces a zero result). Sometimes gdbarch_int_bit |
2037 | or gdbarch_long_bit will be that big, sometimes not. To deal with | |
c906108c SS |
2038 | the case where it is we just always shift the value more than |
2039 | once, with fewer bits each time. */ | |
2040 | ||
20562150 | 2041 | un = n >> 2; |
c906108c | 2042 | if (long_p == 0 |
fa9f5be6 | 2043 | && (un >> (gdbarch_int_bit (par_state->gdbarch ()) - 2)) == 0) |
c906108c | 2044 | { |
410a0ff2 | 2045 | high_bit |
fa9f5be6 | 2046 | = ((ULONGEST)1) << (gdbarch_int_bit (par_state->gdbarch ()) - 1); |
c906108c SS |
2047 | |
2048 | /* A large decimal (not hex or octal) constant (between INT_MAX | |
2049 | and UINT_MAX) is a long or unsigned long, according to ANSI, | |
2050 | never an unsigned int, but this code treats it as unsigned | |
2051 | int. This probably should be fixed. GCC gives a warning on | |
2052 | such constants. */ | |
2053 | ||
410a0ff2 SDJ |
2054 | unsigned_type = parse_type (par_state)->builtin_unsigned_int; |
2055 | signed_type = parse_type (par_state)->builtin_int; | |
c906108c SS |
2056 | } |
2057 | else if (long_p <= 1 | |
fa9f5be6 | 2058 | && (un >> (gdbarch_long_bit (par_state->gdbarch ()) - 2)) == 0) |
c906108c | 2059 | { |
410a0ff2 | 2060 | high_bit |
fa9f5be6 | 2061 | = ((ULONGEST)1) << (gdbarch_long_bit (par_state->gdbarch ()) - 1); |
410a0ff2 SDJ |
2062 | unsigned_type = parse_type (par_state)->builtin_unsigned_long; |
2063 | signed_type = parse_type (par_state)->builtin_long; | |
c906108c SS |
2064 | } |
2065 | else | |
2066 | { | |
2067 | int shift; | |
4d29c0a8 | 2068 | if (sizeof (ULONGEST) * HOST_CHAR_BIT |
fa9f5be6 | 2069 | < gdbarch_long_long_bit (par_state->gdbarch ())) |
c906108c SS |
2070 | /* A long long does not fit in a LONGEST. */ |
2071 | shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1); | |
2072 | else | |
fa9f5be6 | 2073 | shift = (gdbarch_long_long_bit (par_state->gdbarch ()) - 1); |
c906108c | 2074 | high_bit = (ULONGEST) 1 << shift; |
410a0ff2 SDJ |
2075 | unsigned_type = parse_type (par_state)->builtin_unsigned_long_long; |
2076 | signed_type = parse_type (par_state)->builtin_long_long; | |
c906108c SS |
2077 | } |
2078 | ||
2079 | putithere->typed_val_int.val = n; | |
2080 | ||
2081 | /* If the high bit of the worked out type is set then this number | |
2082 | has to be unsigned. */ | |
2083 | ||
4d29c0a8 | 2084 | if (unsigned_p || (n & high_bit)) |
c906108c SS |
2085 | { |
2086 | putithere->typed_val_int.type = unsigned_type; | |
2087 | } | |
4d29c0a8 | 2088 | else |
c906108c SS |
2089 | { |
2090 | putithere->typed_val_int.type = signed_type; | |
2091 | } | |
2092 | ||
2093 | return INT; | |
2094 | } | |
2095 | ||
6c7a06a3 TT |
2096 | /* Temporary obstack used for holding strings. */ |
2097 | static struct obstack tempbuf; | |
2098 | static int tempbuf_init; | |
2099 | ||
2100 | /* Parse a C escape sequence. The initial backslash of the sequence | |
2101 | is at (*PTR)[-1]. *PTR will be updated to point to just after the | |
2102 | last character of the sequence. If OUTPUT is not NULL, the | |
2103 | translated form of the escape sequence will be written there. If | |
2104 | OUTPUT is NULL, no output is written and the call will only affect | |
2105 | *PTR. If an escape sequence is expressed in target bytes, then the | |
2106 | entire sequence will simply be copied to OUTPUT. Return 1 if any | |
2107 | character was emitted, 0 otherwise. */ | |
2108 | ||
2109 | int | |
d7561cbb | 2110 | c_parse_escape (const char **ptr, struct obstack *output) |
6c7a06a3 | 2111 | { |
d7561cbb | 2112 | const char *tokptr = *ptr; |
6c7a06a3 TT |
2113 | int result = 1; |
2114 | ||
2115 | /* Some escape sequences undergo character set conversion. Those we | |
2116 | translate here. */ | |
2117 | switch (*tokptr) | |
2118 | { | |
2119 | /* Hex escapes do not undergo character set conversion, so keep | |
2120 | the escape sequence for later. */ | |
2121 | case 'x': | |
2122 | if (output) | |
2123 | obstack_grow_str (output, "\\x"); | |
2124 | ++tokptr; | |
b1b60145 | 2125 | if (!ISXDIGIT (*tokptr)) |
6c7a06a3 | 2126 | error (_("\\x escape without a following hex digit")); |
b1b60145 | 2127 | while (ISXDIGIT (*tokptr)) |
6c7a06a3 TT |
2128 | { |
2129 | if (output) | |
2130 | obstack_1grow (output, *tokptr); | |
2131 | ++tokptr; | |
2132 | } | |
2133 | break; | |
2134 | ||
2135 | /* Octal escapes do not undergo character set conversion, so | |
2136 | keep the escape sequence for later. */ | |
2137 | case '0': | |
2138 | case '1': | |
2139 | case '2': | |
2140 | case '3': | |
2141 | case '4': | |
2142 | case '5': | |
2143 | case '6': | |
2144 | case '7': | |
30b66ecc TT |
2145 | { |
2146 | int i; | |
2147 | if (output) | |
2148 | obstack_grow_str (output, "\\"); | |
2149 | for (i = 0; | |
b1b60145 | 2150 | i < 3 && ISDIGIT (*tokptr) && *tokptr != '8' && *tokptr != '9'; |
30b66ecc TT |
2151 | ++i) |
2152 | { | |
2153 | if (output) | |
2154 | obstack_1grow (output, *tokptr); | |
2155 | ++tokptr; | |
2156 | } | |
2157 | } | |
6c7a06a3 TT |
2158 | break; |
2159 | ||
2160 | /* We handle UCNs later. We could handle them here, but that | |
2161 | would mean a spurious error in the case where the UCN could | |
2162 | be converted to the target charset but not the host | |
2163 | charset. */ | |
2164 | case 'u': | |
2165 | case 'U': | |
2166 | { | |
2167 | char c = *tokptr; | |
2168 | int i, len = c == 'U' ? 8 : 4; | |
2169 | if (output) | |
2170 | { | |
2171 | obstack_1grow (output, '\\'); | |
2172 | obstack_1grow (output, *tokptr); | |
2173 | } | |
2174 | ++tokptr; | |
b1b60145 | 2175 | if (!ISXDIGIT (*tokptr)) |
6c7a06a3 | 2176 | error (_("\\%c escape without a following hex digit"), c); |
b1b60145 | 2177 | for (i = 0; i < len && ISXDIGIT (*tokptr); ++i) |
6c7a06a3 TT |
2178 | { |
2179 | if (output) | |
2180 | obstack_1grow (output, *tokptr); | |
2181 | ++tokptr; | |
2182 | } | |
2183 | } | |
2184 | break; | |
2185 | ||
2186 | /* We must pass backslash through so that it does not | |
2187 | cause quoting during the second expansion. */ | |
2188 | case '\\': | |
2189 | if (output) | |
2190 | obstack_grow_str (output, "\\\\"); | |
2191 | ++tokptr; | |
2192 | break; | |
2193 | ||
2194 | /* Escapes which undergo conversion. */ | |
2195 | case 'a': | |
2196 | if (output) | |
2197 | obstack_1grow (output, '\a'); | |
2198 | ++tokptr; | |
2199 | break; | |
2200 | case 'b': | |
2201 | if (output) | |
2202 | obstack_1grow (output, '\b'); | |
2203 | ++tokptr; | |
2204 | break; | |
2205 | case 'f': | |
2206 | if (output) | |
2207 | obstack_1grow (output, '\f'); | |
2208 | ++tokptr; | |
2209 | break; | |
2210 | case 'n': | |
2211 | if (output) | |
2212 | obstack_1grow (output, '\n'); | |
2213 | ++tokptr; | |
2214 | break; | |
2215 | case 'r': | |
2216 | if (output) | |
2217 | obstack_1grow (output, '\r'); | |
2218 | ++tokptr; | |
2219 | break; | |
2220 | case 't': | |
2221 | if (output) | |
2222 | obstack_1grow (output, '\t'); | |
2223 | ++tokptr; | |
2224 | break; | |
2225 | case 'v': | |
2226 | if (output) | |
2227 | obstack_1grow (output, '\v'); | |
2228 | ++tokptr; | |
2229 | break; | |
2230 | ||
2231 | /* GCC extension. */ | |
2232 | case 'e': | |
2233 | if (output) | |
2234 | obstack_1grow (output, HOST_ESCAPE_CHAR); | |
2235 | ++tokptr; | |
2236 | break; | |
2237 | ||
2238 | /* Backslash-newline expands to nothing at all. */ | |
2239 | case '\n': | |
2240 | ++tokptr; | |
2241 | result = 0; | |
2242 | break; | |
2243 | ||
2244 | /* A few escapes just expand to the character itself. */ | |
2245 | case '\'': | |
2246 | case '\"': | |
2247 | case '?': | |
2248 | /* GCC extensions. */ | |
2249 | case '(': | |
2250 | case '{': | |
2251 | case '[': | |
2252 | case '%': | |
2253 | /* Unrecognized escapes turn into the character itself. */ | |
2254 | default: | |
2255 | if (output) | |
2256 | obstack_1grow (output, *tokptr); | |
2257 | ++tokptr; | |
2258 | break; | |
2259 | } | |
2260 | *ptr = tokptr; | |
2261 | return result; | |
2262 | } | |
2263 | ||
2264 | /* Parse a string or character literal from TOKPTR. The string or | |
2265 | character may be wide or unicode. *OUTPTR is set to just after the | |
2266 | end of the literal in the input string. The resulting token is | |
2267 | stored in VALUE. This returns a token value, either STRING or | |
2268 | CHAR, depending on what was parsed. *HOST_CHARS is set to the | |
2269 | number of host characters in the literal. */ | |
4d29c0a8 | 2270 | |
6c7a06a3 | 2271 | static int |
d7561cbb KS |
2272 | parse_string_or_char (const char *tokptr, const char **outptr, |
2273 | struct typed_stoken *value, int *host_chars) | |
6c7a06a3 | 2274 | { |
8c5630cb | 2275 | int quote; |
0c801b96 | 2276 | c_string_type type; |
f2e8016f | 2277 | int is_objc = 0; |
6c7a06a3 TT |
2278 | |
2279 | /* Build the gdb internal form of the input string in tempbuf. Note | |
2280 | that the buffer is null byte terminated *only* for the | |
2281 | convenience of debugging gdb itself and printing the buffer | |
2282 | contents when the buffer contains no embedded nulls. Gdb does | |
2283 | not depend upon the buffer being null byte terminated, it uses | |
2284 | the length string instead. This allows gdb to handle C strings | |
2285 | (as well as strings in other languages) with embedded null | |
2286 | bytes */ | |
2287 | ||
2288 | if (!tempbuf_init) | |
2289 | tempbuf_init = 1; | |
2290 | else | |
2291 | obstack_free (&tempbuf, NULL); | |
2292 | obstack_init (&tempbuf); | |
2293 | ||
2294 | /* Record the string type. */ | |
2295 | if (*tokptr == 'L') | |
2296 | { | |
2297 | type = C_WIDE_STRING; | |
2298 | ++tokptr; | |
2299 | } | |
2300 | else if (*tokptr == 'u') | |
2301 | { | |
2302 | type = C_STRING_16; | |
2303 | ++tokptr; | |
2304 | } | |
2305 | else if (*tokptr == 'U') | |
2306 | { | |
2307 | type = C_STRING_32; | |
2308 | ++tokptr; | |
2309 | } | |
f2e8016f TT |
2310 | else if (*tokptr == '@') |
2311 | { | |
2312 | /* An Objective C string. */ | |
2313 | is_objc = 1; | |
2314 | type = C_STRING; | |
2315 | ++tokptr; | |
2316 | } | |
6c7a06a3 TT |
2317 | else |
2318 | type = C_STRING; | |
2319 | ||
2320 | /* Skip the quote. */ | |
2321 | quote = *tokptr; | |
2322 | if (quote == '\'') | |
2323 | type |= C_CHAR; | |
2324 | ++tokptr; | |
2325 | ||
2326 | *host_chars = 0; | |
2327 | ||
2328 | while (*tokptr) | |
2329 | { | |
2330 | char c = *tokptr; | |
2331 | if (c == '\\') | |
2332 | { | |
2333 | ++tokptr; | |
2334 | *host_chars += c_parse_escape (&tokptr, &tempbuf); | |
2335 | } | |
2336 | else if (c == quote) | |
2337 | break; | |
2338 | else | |
2339 | { | |
2340 | obstack_1grow (&tempbuf, c); | |
2341 | ++tokptr; | |
2342 | /* FIXME: this does the wrong thing with multi-byte host | |
2343 | characters. We could use mbrlen here, but that would | |
2344 | make "set host-charset" a bit less useful. */ | |
2345 | ++*host_chars; | |
2346 | } | |
2347 | } | |
2348 | ||
2349 | if (*tokptr != quote) | |
2350 | { | |
2351 | if (quote == '"') | |
001083c6 | 2352 | error (_("Unterminated string in expression.")); |
6c7a06a3 | 2353 | else |
001083c6 | 2354 | error (_("Unmatched single quote.")); |
6c7a06a3 TT |
2355 | } |
2356 | ++tokptr; | |
2357 | ||
2358 | value->type = type; | |
79f33898 | 2359 | value->ptr = (char *) obstack_base (&tempbuf); |
6c7a06a3 TT |
2360 | value->length = obstack_object_size (&tempbuf); |
2361 | ||
2362 | *outptr = tokptr; | |
2363 | ||
f2e8016f | 2364 | return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR; |
6c7a06a3 TT |
2365 | } |
2366 | ||
274b54d7 TT |
2367 | /* This is used to associate some attributes with a token. */ |
2368 | ||
8d297bbf | 2369 | enum token_flag |
274b54d7 TT |
2370 | { |
2371 | /* If this bit is set, the token is C++-only. */ | |
2372 | ||
2373 | FLAG_CXX = 1, | |
2374 | ||
2375 | /* If this bit is set, the token is conditional: if there is a | |
2376 | symbol of the same name, then the token is a symbol; otherwise, | |
2377 | the token is a keyword. */ | |
2378 | ||
2379 | FLAG_SHADOW = 2 | |
2380 | }; | |
8d297bbf | 2381 | DEF_ENUM_FLAGS_TYPE (enum token_flag, token_flags); |
274b54d7 | 2382 | |
c906108c SS |
2383 | struct token |
2384 | { | |
a121b7c1 | 2385 | const char *oper; |
c906108c SS |
2386 | int token; |
2387 | enum exp_opcode opcode; | |
8d297bbf | 2388 | token_flags flags; |
c906108c SS |
2389 | }; |
2390 | ||
2391 | static const struct token tokentab3[] = | |
2392 | { | |
ba163c7e | 2393 | {">>=", ASSIGN_MODIFY, BINOP_RSH, 0}, |
c1af96a0 | 2394 | {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0}, |
274b54d7 | 2395 | {"->*", ARROW_STAR, BINOP_END, FLAG_CXX}, |
a6fb9c08 | 2396 | {"...", DOTDOTDOT, BINOP_END, 0} |
c906108c SS |
2397 | }; |
2398 | ||
2399 | static const struct token tokentab2[] = | |
2400 | { | |
ba163c7e TT |
2401 | {"+=", ASSIGN_MODIFY, BINOP_ADD, 0}, |
2402 | {"-=", ASSIGN_MODIFY, BINOP_SUB, 0}, | |
2403 | {"*=", ASSIGN_MODIFY, BINOP_MUL, 0}, | |
2404 | {"/=", ASSIGN_MODIFY, BINOP_DIV, 0}, | |
2405 | {"%=", ASSIGN_MODIFY, BINOP_REM, 0}, | |
2406 | {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0}, | |
2407 | {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0}, | |
2408 | {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0}, | |
2409 | {"++", INCREMENT, BINOP_END, 0}, | |
2410 | {"--", DECREMENT, BINOP_END, 0}, | |
2411 | {"->", ARROW, BINOP_END, 0}, | |
2412 | {"&&", ANDAND, BINOP_END, 0}, | |
2413 | {"||", OROR, BINOP_END, 0}, | |
ec7f2efe KS |
2414 | /* "::" is *not* only C++: gdb overrides its meaning in several |
2415 | different ways, e.g., 'filename'::func, function::variable. */ | |
ba163c7e TT |
2416 | {"::", COLONCOLON, BINOP_END, 0}, |
2417 | {"<<", LSH, BINOP_END, 0}, | |
2418 | {">>", RSH, BINOP_END, 0}, | |
2419 | {"==", EQUAL, BINOP_END, 0}, | |
2420 | {"!=", NOTEQUAL, BINOP_END, 0}, | |
2421 | {"<=", LEQ, BINOP_END, 0}, | |
c1af96a0 | 2422 | {">=", GEQ, BINOP_END, 0}, |
274b54d7 | 2423 | {".*", DOT_STAR, BINOP_END, FLAG_CXX} |
ba163c7e TT |
2424 | }; |
2425 | ||
b6c95c0c AB |
2426 | /* Identifier-like tokens. Only type-specifiers than can appear in |
2427 | multi-word type names (for example 'double' can appear in 'long | |
2428 | double') need to be listed here. type-specifiers that are only ever | |
2429 | single word (like 'float') are handled by the classify_name function. */ | |
ba163c7e TT |
2430 | static const struct token ident_tokens[] = |
2431 | { | |
2432 | {"unsigned", UNSIGNED, OP_NULL, 0}, | |
274b54d7 | 2433 | {"template", TEMPLATE, OP_NULL, FLAG_CXX}, |
ba163c7e TT |
2434 | {"volatile", VOLATILE_KEYWORD, OP_NULL, 0}, |
2435 | {"struct", STRUCT, OP_NULL, 0}, | |
2436 | {"signed", SIGNED_KEYWORD, OP_NULL, 0}, | |
2437 | {"sizeof", SIZEOF, OP_NULL, 0}, | |
007e1530 TT |
2438 | {"_Alignof", ALIGNOF, OP_NULL, 0}, |
2439 | {"alignof", ALIGNOF, OP_NULL, FLAG_CXX}, | |
ba163c7e | 2440 | {"double", DOUBLE_KEYWORD, OP_NULL, 0}, |
274b54d7 TT |
2441 | {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX}, |
2442 | {"class", CLASS, OP_NULL, FLAG_CXX}, | |
ba163c7e TT |
2443 | {"union", UNION, OP_NULL, 0}, |
2444 | {"short", SHORT, OP_NULL, 0}, | |
2445 | {"const", CONST_KEYWORD, OP_NULL, 0}, | |
2446 | {"enum", ENUM, OP_NULL, 0}, | |
2447 | {"long", LONG, OP_NULL, 0}, | |
274b54d7 | 2448 | {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX}, |
ba163c7e | 2449 | {"int", INT_KEYWORD, OP_NULL, 0}, |
274b54d7 TT |
2450 | {"new", NEW, OP_NULL, FLAG_CXX}, |
2451 | {"delete", DELETE, OP_NULL, FLAG_CXX}, | |
2452 | {"operator", OPERATOR, OP_NULL, FLAG_CXX}, | |
2453 | ||
2454 | {"and", ANDAND, BINOP_END, FLAG_CXX}, | |
2455 | {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX}, | |
2456 | {"bitand", '&', OP_NULL, FLAG_CXX}, | |
2457 | {"bitor", '|', OP_NULL, FLAG_CXX}, | |
2458 | {"compl", '~', OP_NULL, FLAG_CXX}, | |
2459 | {"not", '!', OP_NULL, FLAG_CXX}, | |
2460 | {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX}, | |
2461 | {"or", OROR, BINOP_END, FLAG_CXX}, | |
2462 | {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX}, | |
2463 | {"xor", '^', OP_NULL, FLAG_CXX}, | |
2464 | {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX}, | |
2465 | ||
2466 | {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX }, | |
2467 | {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX }, | |
2468 | {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX }, | |
608b4967 TT |
2469 | {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX }, |
2470 | ||
2471 | {"__typeof__", TYPEOF, OP_TYPEOF, 0 }, | |
2472 | {"__typeof", TYPEOF, OP_TYPEOF, 0 }, | |
2473 | {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW }, | |
2474 | {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX }, | |
6e72ca20 TT |
2475 | {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW }, |
2476 | ||
2477 | {"typeid", TYPEID, OP_TYPEID, FLAG_CXX} | |
c906108c SS |
2478 | }; |
2479 | ||
7c8adf68 TT |
2480 | |
2481 | static void | |
2482 | scan_macro_expansion (char *expansion) | |
2483 | { | |
2484 | char *copy; | |
2485 | ||
2486 | /* We'd better not be trying to push the stack twice. */ | |
9d30e1fd | 2487 | gdb_assert (! cpstate->macro_original_text); |
7c8adf68 TT |
2488 | |
2489 | /* Copy to the obstack, and then free the intermediate | |
2490 | expansion. */ | |
9d30e1fd | 2491 | copy = (char *) obstack_copy0 (&cpstate->expansion_obstack, expansion, |
224c3ddb | 2492 | strlen (expansion)); |
7c8adf68 TT |
2493 | xfree (expansion); |
2494 | ||
2495 | /* Save the old lexptr value, so we can return to it when we're done | |
2496 | parsing the expanded text. */ | |
5776fca3 TT |
2497 | cpstate->macro_original_text = pstate->lexptr; |
2498 | pstate->lexptr = copy; | |
7c8adf68 TT |
2499 | } |
2500 | ||
7c8adf68 TT |
2501 | static int |
2502 | scanning_macro_expansion (void) | |
2503 | { | |
9d30e1fd | 2504 | return cpstate->macro_original_text != 0; |
7c8adf68 TT |
2505 | } |
2506 | ||
4d29c0a8 | 2507 | static void |
7c8adf68 TT |
2508 | finished_macro_expansion (void) |
2509 | { | |
2510 | /* There'd better be something to pop back to. */ | |
9d30e1fd | 2511 | gdb_assert (cpstate->macro_original_text); |
7c8adf68 TT |
2512 | |
2513 | /* Pop back to the original text. */ | |
5776fca3 | 2514 | pstate->lexptr = cpstate->macro_original_text; |
9d30e1fd | 2515 | cpstate->macro_original_text = 0; |
7c8adf68 TT |
2516 | } |
2517 | ||
4e8f195d TT |
2518 | /* Return true iff the token represents a C++ cast operator. */ |
2519 | ||
2520 | static int | |
2521 | is_cast_operator (const char *token, int len) | |
2522 | { | |
2523 | return (! strncmp (token, "dynamic_cast", len) | |
2524 | || ! strncmp (token, "static_cast", len) | |
2525 | || ! strncmp (token, "reinterpret_cast", len) | |
2526 | || ! strncmp (token, "const_cast", len)); | |
2527 | } | |
7c8adf68 TT |
2528 | |
2529 | /* The scope used for macro expansion. */ | |
2530 | static struct macro_scope *expression_macro_scope; | |
2531 | ||
65d12d83 TT |
2532 | /* This is set if a NAME token appeared at the very end of the input |
2533 | string, with no whitespace separating the name from the EOF. This | |
2534 | is used only when parsing to do field name completion. */ | |
2535 | static int saw_name_at_eof; | |
2536 | ||
2537 | /* This is set if the previously-returned token was a structure | |
59498c30 LS |
2538 | operator -- either '.' or ARROW. */ |
2539 | static bool last_was_structop; | |
65d12d83 | 2540 | |
28aaf3fd TT |
2541 | /* Depth of parentheses. */ |
2542 | static int paren_depth; | |
2543 | ||
c906108c SS |
2544 | /* Read one token, getting characters through lexptr. */ |
2545 | ||
2546 | static int | |
59498c30 | 2547 | lex_one_token (struct parser_state *par_state, bool *is_quoted_name) |
c906108c SS |
2548 | { |
2549 | int c; | |
2550 | int namelen; | |
2551 | unsigned int i; | |
d7561cbb | 2552 | const char *tokstart; |
59498c30 | 2553 | bool saw_structop = last_was_structop; |
ba163c7e | 2554 | char *copy; |
65d12d83 | 2555 | |
59498c30 LS |
2556 | last_was_structop = false; |
2557 | *is_quoted_name = false; | |
65d12d83 | 2558 | |
c906108c SS |
2559 | retry: |
2560 | ||
84f0252a JB |
2561 | /* Check if this is a macro invocation that we need to expand. */ |
2562 | if (! scanning_macro_expansion ()) | |
2563 | { | |
5776fca3 | 2564 | char *expanded = macro_expand_next (&pstate->lexptr, |
7c8adf68 TT |
2565 | standard_macro_lookup, |
2566 | expression_macro_scope); | |
84f0252a JB |
2567 | |
2568 | if (expanded) | |
2569 | scan_macro_expansion (expanded); | |
2570 | } | |
2571 | ||
5776fca3 | 2572 | pstate->prev_lexptr = pstate->lexptr; |
c906108c | 2573 | |
5776fca3 | 2574 | tokstart = pstate->lexptr; |
c906108c SS |
2575 | /* See if it is a special token of length 3. */ |
2576 | for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++) | |
fe978cb0 | 2577 | if (strncmp (tokstart, tokentab3[i].oper, 3) == 0) |
c906108c | 2578 | { |
274b54d7 | 2579 | if ((tokentab3[i].flags & FLAG_CXX) != 0 |
73923d7e | 2580 | && par_state->language ()->la_language != language_cplus) |
ec7f2efe KS |
2581 | break; |
2582 | ||
5776fca3 | 2583 | pstate->lexptr += 3; |
c906108c SS |
2584 | yylval.opcode = tokentab3[i].opcode; |
2585 | return tokentab3[i].token; | |
2586 | } | |
2587 | ||
2588 | /* See if it is a special token of length 2. */ | |
2589 | for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++) | |
fe978cb0 | 2590 | if (strncmp (tokstart, tokentab2[i].oper, 2) == 0) |
c906108c | 2591 | { |
274b54d7 | 2592 | if ((tokentab2[i].flags & FLAG_CXX) != 0 |
73923d7e | 2593 | && par_state->language ()->la_language != language_cplus) |
ec7f2efe KS |
2594 | break; |
2595 | ||
5776fca3 | 2596 | pstate->lexptr += 2; |
c906108c | 2597 | yylval.opcode = tokentab2[i].opcode; |
59498c30 | 2598 | if (tokentab2[i].token == ARROW) |
65d12d83 | 2599 | last_was_structop = 1; |
c906108c SS |
2600 | return tokentab2[i].token; |
2601 | } | |
2602 | ||
2603 | switch (c = *tokstart) | |
2604 | { | |
2605 | case 0: | |
84f0252a JB |
2606 | /* If we were just scanning the result of a macro expansion, |
2607 | then we need to resume scanning the original text. | |
65d12d83 TT |
2608 | If we're parsing for field name completion, and the previous |
2609 | token allows such completion, return a COMPLETE token. | |
84f0252a JB |
2610 | Otherwise, we were already scanning the original text, and |
2611 | we're really done. */ | |
2612 | if (scanning_macro_expansion ()) | |
2613 | { | |
2614 | finished_macro_expansion (); | |
2615 | goto retry; | |
2616 | } | |
65d12d83 TT |
2617 | else if (saw_name_at_eof) |
2618 | { | |
2619 | saw_name_at_eof = 0; | |
2620 | return COMPLETE; | |
2621 | } | |
2a612529 | 2622 | else if (par_state->parse_completion && saw_structop) |
65d12d83 | 2623 | return COMPLETE; |
84f0252a JB |
2624 | else |
2625 | return 0; | |
c906108c SS |
2626 | |
2627 | case ' ': | |
2628 | case '\t': | |
2629 | case '\n': | |
5776fca3 | 2630 | pstate->lexptr++; |
c906108c SS |
2631 | goto retry; |
2632 | ||
379a77b5 | 2633 | case '[': |
c906108c SS |
2634 | case '(': |
2635 | paren_depth++; | |
5776fca3 | 2636 | pstate->lexptr++; |
73923d7e | 2637 | if (par_state->language ()->la_language == language_objc |
410a0ff2 | 2638 | && c == '[') |
f2e8016f | 2639 | return OBJC_LBRAC; |
c906108c SS |
2640 | return c; |
2641 | ||
379a77b5 | 2642 | case ']': |
c906108c SS |
2643 | case ')': |
2644 | if (paren_depth == 0) | |
2645 | return 0; | |
2646 | paren_depth--; | |
5776fca3 | 2647 | pstate->lexptr++; |
c906108c SS |
2648 | return c; |
2649 | ||
2650 | case ',': | |
8621b685 | 2651 | if (pstate->comma_terminates |
84f0252a JB |
2652 | && paren_depth == 0 |
2653 | && ! scanning_macro_expansion ()) | |
c906108c | 2654 | return 0; |
5776fca3 | 2655 | pstate->lexptr++; |
c906108c SS |
2656 | return c; |
2657 | ||
2658 | case '.': | |
2659 | /* Might be a floating point number. */ | |
5776fca3 | 2660 | if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9') |
65d12d83 | 2661 | { |
59498c30 | 2662 | last_was_structop = true; |
65d12d83 TT |
2663 | goto symbol; /* Nope, must be a symbol. */ |
2664 | } | |
86a73007 | 2665 | /* FALL THRU. */ |
c906108c SS |
2666 | |
2667 | case '0': | |
2668 | case '1': | |
2669 | case '2': | |
2670 | case '3': | |
2671 | case '4': | |
2672 | case '5': | |
2673 | case '6': | |
2674 | case '7': | |
2675 | case '8': | |
2676 | case '9': | |
2677 | { | |
2678 | /* It's a number. */ | |
2679 | int got_dot = 0, got_e = 0, toktype; | |
d7561cbb | 2680 | const char *p = tokstart; |
c906108c SS |
2681 | int hex = input_radix > 10; |
2682 | ||
2683 | if (c == '0' && (p[1] == 'x' || p[1] == 'X')) | |
2684 | { | |
2685 | p += 2; | |
2686 | hex = 1; | |
2687 | } | |
2688 | else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D')) | |
2689 | { | |
2690 | p += 2; | |
2691 | hex = 0; | |
2692 | } | |
2693 | ||
2694 | for (;; ++p) | |
2695 | { | |
2696 | /* This test includes !hex because 'e' is a valid hex digit | |
2697 | and thus does not indicate a floating point number when | |
2698 | the radix is hex. */ | |
2699 | if (!hex && !got_e && (*p == 'e' || *p == 'E')) | |
2700 | got_dot = got_e = 1; | |
2701 | /* This test does not include !hex, because a '.' always indicates | |
2702 | a decimal floating point number regardless of the radix. */ | |
2703 | else if (!got_dot && *p == '.') | |
2704 | got_dot = 1; | |
2705 | else if (got_e && (p[-1] == 'e' || p[-1] == 'E') | |
2706 | && (*p == '-' || *p == '+')) | |
2707 | /* This is the sign of the exponent, not the end of the | |
2708 | number. */ | |
2709 | continue; | |
2710 | /* We will take any letters or digits. parse_number will | |
2711 | complain if past the radix, or if L or U are not final. */ | |
2712 | else if ((*p < '0' || *p > '9') | |
2713 | && ((*p < 'a' || *p > 'z') | |
2714 | && (*p < 'A' || *p > 'Z'))) | |
2715 | break; | |
2716 | } | |
410a0ff2 SDJ |
2717 | toktype = parse_number (par_state, tokstart, p - tokstart, |
2718 | got_dot|got_e, &yylval); | |
c906108c SS |
2719 | if (toktype == ERROR) |
2720 | { | |
2721 | char *err_copy = (char *) alloca (p - tokstart + 1); | |
2722 | ||
2723 | memcpy (err_copy, tokstart, p - tokstart); | |
2724 | err_copy[p - tokstart] = 0; | |
001083c6 | 2725 | error (_("Invalid number \"%s\"."), err_copy); |
c906108c | 2726 | } |
5776fca3 | 2727 | pstate->lexptr = p; |
c906108c SS |
2728 | return toktype; |
2729 | } | |
2730 | ||
941b2081 JK |
2731 | case '@': |
2732 | { | |
d7561cbb | 2733 | const char *p = &tokstart[1]; |
941b2081 | 2734 | |
73923d7e | 2735 | if (par_state->language ()->la_language == language_objc) |
f2e8016f TT |
2736 | { |
2737 | size_t len = strlen ("selector"); | |
2738 | ||
2739 | if (strncmp (p, "selector", len) == 0 | |
b1b60145 | 2740 | && (p[len] == '\0' || ISSPACE (p[len]))) |
f2e8016f | 2741 | { |
5776fca3 | 2742 | pstate->lexptr = p + len; |
f2e8016f TT |
2743 | return SELECTOR; |
2744 | } | |
2745 | else if (*p == '"') | |
2746 | goto parse_string; | |
2747 | } | |
2748 | ||
b1b60145 | 2749 | while (ISSPACE (*p)) |
941b2081 | 2750 | p++; |
b926417a | 2751 | size_t len = strlen ("entry"); |
b1b60145 | 2752 | if (strncmp (p, "entry", len) == 0 && !c_ident_is_alnum (p[len]) |
941b2081 JK |
2753 | && p[len] != '_') |
2754 | { | |
5776fca3 | 2755 | pstate->lexptr = &p[len]; |
941b2081 JK |
2756 | return ENTRY; |
2757 | } | |
2758 | } | |
2759 | /* FALLTHRU */ | |
c906108c SS |
2760 | case '+': |
2761 | case '-': | |
2762 | case '*': | |
2763 | case '/': | |
2764 | case '%': | |
2765 | case '|': | |
2766 | case '&': | |
2767 | case '^': | |
2768 | case '~': | |
2769 | case '!': | |
c906108c SS |
2770 | case '<': |
2771 | case '>': | |
c906108c SS |
2772 | case '?': |
2773 | case ':': | |
2774 | case '=': | |
2775 | case '{': | |
2776 | case '}': | |
2777 | symbol: | |
5776fca3 | 2778 | pstate->lexptr++; |
c906108c SS |
2779 | return c; |
2780 | ||
6c7a06a3 TT |
2781 | case 'L': |
2782 | case 'u': | |
2783 | case 'U': | |
2784 | if (tokstart[1] != '"' && tokstart[1] != '\'') | |
2785 | break; | |
2786 | /* Fall through. */ | |
2787 | case '\'': | |
c906108c | 2788 | case '"': |
f2e8016f TT |
2789 | |
2790 | parse_string: | |
6c7a06a3 TT |
2791 | { |
2792 | int host_len; | |
5776fca3 TT |
2793 | int result = parse_string_or_char (tokstart, &pstate->lexptr, |
2794 | &yylval.tsval, &host_len); | |
6c7a06a3 | 2795 | if (result == CHAR) |
c906108c | 2796 | { |
6c7a06a3 | 2797 | if (host_len == 0) |
001083c6 | 2798 | error (_("Empty character constant.")); |
6c7a06a3 | 2799 | else if (host_len > 2 && c == '\'') |
c906108c | 2800 | { |
6c7a06a3 | 2801 | ++tokstart; |
5776fca3 | 2802 | namelen = pstate->lexptr - tokstart - 1; |
59498c30 | 2803 | *is_quoted_name = true; |
805e1f19 | 2804 | |
6c7a06a3 | 2805 | goto tryname; |
c906108c | 2806 | } |
6c7a06a3 | 2807 | else if (host_len > 1) |
001083c6 | 2808 | error (_("Invalid character constant.")); |
c906108c | 2809 | } |
6c7a06a3 TT |
2810 | return result; |
2811 | } | |
c906108c SS |
2812 | } |
2813 | ||
b1b60145 | 2814 | if (!(c == '_' || c == '$' || c_ident_is_alpha (c))) |
c906108c | 2815 | /* We must have come across a bad character (e.g. ';'). */ |
001083c6 | 2816 | error (_("Invalid character '%c' in expression."), c); |
c906108c SS |
2817 | |
2818 | /* It's a name. See how long it is. */ | |
2819 | namelen = 0; | |
2820 | for (c = tokstart[namelen]; | |
b1b60145 | 2821 | (c == '_' || c == '$' || c_ident_is_alnum (c) || c == '<');) |
c906108c SS |
2822 | { |
2823 | /* Template parameter lists are part of the name. | |
2824 | FIXME: This mishandles `print $a<4&&$a>3'. */ | |
2825 | ||
2826 | if (c == '<') | |
4e8f195d TT |
2827 | { |
2828 | if (! is_cast_operator (tokstart, namelen)) | |
2829 | { | |
2830 | /* Scan ahead to get rest of the template specification. Note | |
2831 | that we look ahead only when the '<' adjoins non-whitespace | |
2832 | characters; for comparison expressions, e.g. "a < b > c", | |
2833 | there must be spaces before the '<', etc. */ | |
d7561cbb KS |
2834 | const char *p = find_template_name_end (tokstart + namelen); |
2835 | ||
4e8f195d TT |
2836 | if (p) |
2837 | namelen = p - tokstart; | |
2838 | } | |
2839 | break; | |
c906108c SS |
2840 | } |
2841 | c = tokstart[++namelen]; | |
2842 | } | |
2843 | ||
84f0252a JB |
2844 | /* The token "if" terminates the expression and is NOT removed from |
2845 | the input stream. It doesn't count if it appears in the | |
2846 | expansion of a macro. */ | |
2847 | if (namelen == 2 | |
2848 | && tokstart[0] == 'i' | |
2849 | && tokstart[1] == 'f' | |
2850 | && ! scanning_macro_expansion ()) | |
c906108c SS |
2851 | { |
2852 | return 0; | |
2853 | } | |
2854 | ||
b6199126 DJ |
2855 | /* For the same reason (breakpoint conditions), "thread N" |
2856 | terminates the expression. "thread" could be an identifier, but | |
2857 | an identifier is never followed by a number without intervening | |
2858 | punctuation. "task" is similar. Handle abbreviations of these, | |
2859 | similarly to breakpoint.c:find_condition_and_thread. */ | |
2860 | if (namelen >= 1 | |
2861 | && (strncmp (tokstart, "thread", namelen) == 0 | |
2862 | || strncmp (tokstart, "task", namelen) == 0) | |
2863 | && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t') | |
2864 | && ! scanning_macro_expansion ()) | |
2865 | { | |
d7561cbb KS |
2866 | const char *p = tokstart + namelen + 1; |
2867 | ||
b6199126 DJ |
2868 | while (*p == ' ' || *p == '\t') |
2869 | p++; | |
2870 | if (*p >= '0' && *p <= '9') | |
2871 | return 0; | |
2872 | } | |
2873 | ||
5776fca3 | 2874 | pstate->lexptr += namelen; |
c906108c SS |
2875 | |
2876 | tryname: | |
2877 | ||
c906108c SS |
2878 | yylval.sval.ptr = tokstart; |
2879 | yylval.sval.length = namelen; | |
2880 | ||
ba163c7e TT |
2881 | /* Catch specific keywords. */ |
2882 | copy = copy_name (yylval.sval); | |
2883 | for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++) | |
fe978cb0 | 2884 | if (strcmp (copy, ident_tokens[i].oper) == 0) |
ba163c7e | 2885 | { |
274b54d7 | 2886 | if ((ident_tokens[i].flags & FLAG_CXX) != 0 |
73923d7e | 2887 | && par_state->language ()->la_language != language_cplus) |
ba163c7e TT |
2888 | break; |
2889 | ||
274b54d7 TT |
2890 | if ((ident_tokens[i].flags & FLAG_SHADOW) != 0) |
2891 | { | |
1993b719 | 2892 | struct field_of_this_result is_a_field_of_this; |
274b54d7 | 2893 | |
1e58a4a4 TT |
2894 | if (lookup_symbol (copy, |
2895 | pstate->expression_context_block, | |
274b54d7 | 2896 | VAR_DOMAIN, |
73923d7e | 2897 | (par_state->language ()->la_language |
410a0ff2 | 2898 | == language_cplus ? &is_a_field_of_this |
d12307c1 | 2899 | : NULL)).symbol |
274b54d7 TT |
2900 | != NULL) |
2901 | { | |
2902 | /* The keyword is shadowed. */ | |
2903 | break; | |
2904 | } | |
2905 | } | |
2906 | ||
ba163c7e TT |
2907 | /* It is ok to always set this, even though we don't always |
2908 | strictly need to. */ | |
2909 | yylval.opcode = ident_tokens[i].opcode; | |
2910 | return ident_tokens[i].token; | |
2911 | } | |
2912 | ||
c906108c | 2913 | if (*tokstart == '$') |
cfeadda5 | 2914 | return DOLLAR_VARIABLE; |
48e32051 | 2915 | |
2a612529 | 2916 | if (pstate->parse_completion && *pstate->lexptr == '\0') |
48e32051 | 2917 | saw_name_at_eof = 1; |
e234dfaf TT |
2918 | |
2919 | yylval.ssym.stoken = yylval.sval; | |
d12307c1 PMR |
2920 | yylval.ssym.sym.symbol = NULL; |
2921 | yylval.ssym.sym.block = NULL; | |
e234dfaf | 2922 | yylval.ssym.is_a_field_of_this = 0; |
48e32051 TT |
2923 | return NAME; |
2924 | } | |
2925 | ||
2926 | /* An object of this type is pushed on a FIFO by the "outer" lexer. */ | |
5fe3f3e4 | 2927 | struct token_and_value |
48e32051 TT |
2928 | { |
2929 | int token; | |
e707a91d | 2930 | YYSTYPE value; |
5fe3f3e4 | 2931 | }; |
48e32051 TT |
2932 | |
2933 | /* A FIFO of tokens that have been read but not yet returned to the | |
2934 | parser. */ | |
5fe3f3e4 | 2935 | static std::vector<token_and_value> token_fifo; |
48e32051 TT |
2936 | |
2937 | /* Non-zero if the lexer should return tokens from the FIFO. */ | |
2938 | static int popping; | |
2939 | ||
2940 | /* Temporary storage for c_lex; this holds symbol names as they are | |
2941 | built up. */ | |
8268c778 | 2942 | auto_obstack name_obstack; |
48e32051 TT |
2943 | |
2944 | /* Classify a NAME token. The contents of the token are in `yylval'. | |
2945 | Updates yylval and returns the new token type. BLOCK is the block | |
805e1f19 TT |
2946 | in which lookups start; this can be NULL to mean the global scope. |
2947 | IS_QUOTED_NAME is non-zero if the name token was originally quoted | |
59498c30 LS |
2948 | in single quotes. IS_AFTER_STRUCTOP is true if this name follows |
2949 | a structure operator -- either '.' or ARROW */ | |
4d29c0a8 | 2950 | |
48e32051 | 2951 | static int |
410a0ff2 | 2952 | classify_name (struct parser_state *par_state, const struct block *block, |
59498c30 | 2953 | bool is_quoted_name, bool is_after_structop) |
48e32051 | 2954 | { |
d12307c1 | 2955 | struct block_symbol bsym; |
48e32051 | 2956 | char *copy; |
1993b719 | 2957 | struct field_of_this_result is_a_field_of_this; |
48e32051 TT |
2958 | |
2959 | copy = copy_name (yylval.sval); | |
2960 | ||
1993b719 TT |
2961 | /* Initialize this in case we *don't* use it in this call; that way |
2962 | we can refer to it unconditionally below. */ | |
2963 | memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this)); | |
2964 | ||
d12307c1 | 2965 | bsym = lookup_symbol (copy, block, VAR_DOMAIN, |
73923d7e | 2966 | par_state->language ()->la_name_of_this |
d12307c1 | 2967 | ? &is_a_field_of_this : NULL); |
48e32051 | 2968 | |
d12307c1 | 2969 | if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK) |
c906108c | 2970 | { |
d12307c1 | 2971 | yylval.ssym.sym = bsym; |
1993b719 | 2972 | yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; |
48e32051 | 2973 | return BLOCKNAME; |
c906108c | 2974 | } |
d12307c1 | 2975 | else if (!bsym.symbol) |
48e32051 | 2976 | { |
6592e36f TT |
2977 | /* If we found a field of 'this', we might have erroneously |
2978 | found a constructor where we wanted a type name. Handle this | |
2979 | case by noticing that we found a constructor and then look up | |
2980 | the type tag instead. */ | |
2981 | if (is_a_field_of_this.type != NULL | |
2982 | && is_a_field_of_this.fn_field != NULL | |
2983 | && TYPE_FN_FIELD_CONSTRUCTOR (is_a_field_of_this.fn_field->fn_fields, | |
2984 | 0)) | |
2985 | { | |
2986 | struct field_of_this_result inner_is_a_field_of_this; | |
2987 | ||
d12307c1 PMR |
2988 | bsym = lookup_symbol (copy, block, STRUCT_DOMAIN, |
2989 | &inner_is_a_field_of_this); | |
2990 | if (bsym.symbol != NULL) | |
6592e36f | 2991 | { |
d12307c1 | 2992 | yylval.tsym.type = SYMBOL_TYPE (bsym.symbol); |
6592e36f TT |
2993 | return TYPENAME; |
2994 | } | |
2995 | } | |
805e1f19 | 2996 | |
59498c30 LS |
2997 | /* If we found a field on the "this" object, or we are looking |
2998 | up a field on a struct, then we want to prefer it over a | |
805e1f19 TT |
2999 | filename. However, if the name was quoted, then it is better |
3000 | to check for a filename or a block, since this is the only | |
3001 | way the user has of requiring the extension to be used. */ | |
59498c30 LS |
3002 | if ((is_a_field_of_this.type == NULL && !is_after_structop) |
3003 | || is_quoted_name) | |
805e1f19 TT |
3004 | { |
3005 | /* See if it's a file name. */ | |
3006 | struct symtab *symtab; | |
3007 | ||
3008 | symtab = lookup_symtab (copy); | |
3009 | if (symtab) | |
3010 | { | |
439247b6 | 3011 | yylval.bval = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), |
805e1f19 TT |
3012 | STATIC_BLOCK); |
3013 | return FILENAME; | |
3014 | } | |
3015 | } | |
48e32051 | 3016 | } |
c906108c | 3017 | |
d12307c1 | 3018 | if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_TYPEDEF) |
48e32051 | 3019 | { |
d12307c1 | 3020 | yylval.tsym.type = SYMBOL_TYPE (bsym.symbol); |
47663de5 | 3021 | return TYPENAME; |
48e32051 | 3022 | } |
c906108c | 3023 | |
f2e8016f | 3024 | /* See if it's an ObjC classname. */ |
73923d7e | 3025 | if (par_state->language ()->la_language == language_objc && !bsym.symbol) |
f2e8016f | 3026 | { |
fa9f5be6 | 3027 | CORE_ADDR Class = lookup_objc_class (par_state->gdbarch (), copy); |
f2e8016f TT |
3028 | if (Class) |
3029 | { | |
d12307c1 PMR |
3030 | struct symbol *sym; |
3031 | ||
fe978cb0 | 3032 | yylval.theclass.theclass = Class; |
1e58a4a4 TT |
3033 | sym = lookup_struct_typedef (copy, |
3034 | par_state->expression_context_block, 1); | |
826f0041 | 3035 | if (sym) |
fe978cb0 | 3036 | yylval.theclass.type = SYMBOL_TYPE (sym); |
f2e8016f TT |
3037 | return CLASSNAME; |
3038 | } | |
3039 | } | |
3040 | ||
48e32051 TT |
3041 | /* Input names that aren't symbols but ARE valid hex numbers, when |
3042 | the input radix permits them, can be names or numbers depending | |
3043 | on the parse. Note we support radixes > 16 here. */ | |
d12307c1 | 3044 | if (!bsym.symbol |
48e32051 TT |
3045 | && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10) |
3046 | || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10))) | |
3047 | { | |
3048 | YYSTYPE newlval; /* Its value is ignored. */ | |
410a0ff2 SDJ |
3049 | int hextype = parse_number (par_state, copy, yylval.sval.length, |
3050 | 0, &newlval); | |
d12307c1 | 3051 | |
48e32051 TT |
3052 | if (hextype == INT) |
3053 | { | |
d12307c1 | 3054 | yylval.ssym.sym = bsym; |
1993b719 | 3055 | yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; |
48e32051 TT |
3056 | return NAME_OR_INT; |
3057 | } | |
3058 | } | |
3059 | ||
3060 | /* Any other kind of symbol */ | |
d12307c1 | 3061 | yylval.ssym.sym = bsym; |
1993b719 | 3062 | yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; |
7322dca9 | 3063 | |
d12307c1 | 3064 | if (bsym.symbol == NULL |
73923d7e | 3065 | && par_state->language ()->la_language == language_cplus |
1993b719 | 3066 | && is_a_field_of_this.type == NULL |
3b7344d5 | 3067 | && lookup_minimal_symbol (copy, NULL, NULL).minsym == NULL) |
7322dca9 SW |
3068 | return UNKNOWN_CPP_NAME; |
3069 | ||
48e32051 TT |
3070 | return NAME; |
3071 | } | |
c906108c | 3072 | |
48e32051 | 3073 | /* Like classify_name, but used by the inner loop of the lexer, when a |
e234dfaf TT |
3074 | name might have already been seen. CONTEXT is the context type, or |
3075 | NULL if this is the first component of a name. */ | |
50af5481 | 3076 | |
48e32051 | 3077 | static int |
410a0ff2 SDJ |
3078 | classify_inner_name (struct parser_state *par_state, |
3079 | const struct block *block, struct type *context) | |
48e32051 | 3080 | { |
df54f8eb | 3081 | struct type *type; |
48e32051 TT |
3082 | char *copy; |
3083 | ||
e234dfaf | 3084 | if (context == NULL) |
59498c30 | 3085 | return classify_name (par_state, block, false, false); |
48e32051 | 3086 | |
e234dfaf | 3087 | type = check_typedef (context); |
3d567982 | 3088 | if (!type_aggregate_p (type)) |
50af5481 | 3089 | return ERROR; |
48e32051 | 3090 | |
e234dfaf | 3091 | copy = copy_name (yylval.ssym.stoken); |
4dcabcc2 DE |
3092 | /* N.B. We assume the symbol can only be in VAR_DOMAIN. */ |
3093 | yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block, VAR_DOMAIN); | |
f7e3ecae KS |
3094 | |
3095 | /* If no symbol was found, search for a matching base class named | |
3096 | COPY. This will allow users to enter qualified names of class members | |
3097 | relative to the `this' pointer. */ | |
d12307c1 | 3098 | if (yylval.ssym.sym.symbol == NULL) |
f7e3ecae | 3099 | { |
a07e3e18 | 3100 | struct type *base_type = cp_find_type_baseclass_by_name (type, copy); |
f7e3ecae KS |
3101 | |
3102 | if (base_type != NULL) | |
3103 | { | |
3104 | yylval.tsym.type = base_type; | |
3105 | return TYPENAME; | |
3106 | } | |
3107 | ||
3108 | return ERROR; | |
3109 | } | |
50af5481 | 3110 | |
d12307c1 | 3111 | switch (SYMBOL_CLASS (yylval.ssym.sym.symbol)) |
50af5481 JK |
3112 | { |
3113 | case LOC_BLOCK: | |
3114 | case LOC_LABEL: | |
f7e3ecae KS |
3115 | /* cp_lookup_nested_symbol might have accidentally found a constructor |
3116 | named COPY when we really wanted a base class of the same name. | |
3117 | Double-check this case by looking for a base class. */ | |
3118 | { | |
a07e3e18 | 3119 | struct type *base_type = cp_find_type_baseclass_by_name (type, copy); |
f7e3ecae KS |
3120 | |
3121 | if (base_type != NULL) | |
3122 | { | |
3123 | yylval.tsym.type = base_type; | |
3124 | return TYPENAME; | |
3125 | } | |
3126 | } | |
50af5481 | 3127 | return ERROR; |
48e32051 | 3128 | |
50af5481 | 3129 | case LOC_TYPEDEF: |
d12307c1 | 3130 | yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym.symbol); |
50af5481 | 3131 | return TYPENAME; |
48e32051 | 3132 | |
50af5481 | 3133 | default: |
50af5481 JK |
3134 | return NAME; |
3135 | } | |
3136 | internal_error (__FILE__, __LINE__, _("not reached")); | |
48e32051 TT |
3137 | } |
3138 | ||
3139 | /* The outer level of a two-level lexer. This calls the inner lexer | |
3140 | to return tokens. It then either returns these tokens, or | |
3141 | aggregates them into a larger token. This lets us work around a | |
3142 | problem in our parsing approach, where the parser could not | |
3143 | distinguish between qualified names and qualified types at the | |
3144 | right point. | |
4d29c0a8 | 3145 | |
48e32051 TT |
3146 | This approach is still not ideal, because it mishandles template |
3147 | types. See the comment in lex_one_token for an example. However, | |
3148 | this is still an improvement over the earlier approach, and will | |
3149 | suffice until we move to better parsing technology. */ | |
4d29c0a8 | 3150 | |
48e32051 TT |
3151 | static int |
3152 | yylex (void) | |
3153 | { | |
3154 | token_and_value current; | |
b2f83c08 | 3155 | int first_was_coloncolon, last_was_coloncolon; |
e234dfaf | 3156 | struct type *context_type = NULL; |
b2f83c08 TT |
3157 | int last_to_examine, next_to_examine, checkpoint; |
3158 | const struct block *search_block; | |
59498c30 | 3159 | bool is_quoted_name, last_lex_was_structop; |
48e32051 | 3160 | |
5fe3f3e4 | 3161 | if (popping && !token_fifo.empty ()) |
b2f83c08 | 3162 | goto do_pop; |
48e32051 TT |
3163 | popping = 0; |
3164 | ||
59498c30 LS |
3165 | last_lex_was_structop = last_was_structop; |
3166 | ||
b2f83c08 TT |
3167 | /* Read the first token and decide what to do. Most of the |
3168 | subsequent code is C++-only; but also depends on seeing a "::" or | |
3169 | name-like token. */ | |
410a0ff2 | 3170 | current.token = lex_one_token (pstate, &is_quoted_name); |
48e32051 | 3171 | if (current.token == NAME) |
1e58a4a4 | 3172 | current.token = classify_name (pstate, pstate->expression_context_block, |
59498c30 | 3173 | is_quoted_name, last_lex_was_structop); |
73923d7e | 3174 | if (pstate->language ()->la_language != language_cplus |
b2f83c08 TT |
3175 | || (current.token != TYPENAME && current.token != COLONCOLON |
3176 | && current.token != FILENAME)) | |
48e32051 TT |
3177 | return current.token; |
3178 | ||
b2f83c08 TT |
3179 | /* Read any sequence of alternating "::" and name-like tokens into |
3180 | the token FIFO. */ | |
3181 | current.value = yylval; | |
5fe3f3e4 | 3182 | token_fifo.push_back (current); |
b2f83c08 TT |
3183 | last_was_coloncolon = current.token == COLONCOLON; |
3184 | while (1) | |
3185 | { | |
59498c30 | 3186 | bool ignore; |
805e1f19 TT |
3187 | |
3188 | /* We ignore quoted names other than the very first one. | |
3189 | Subsequent ones do not have any special meaning. */ | |
410a0ff2 | 3190 | current.token = lex_one_token (pstate, &ignore); |
b2f83c08 | 3191 | current.value = yylval; |
5fe3f3e4 | 3192 | token_fifo.push_back (current); |
b2f83c08 TT |
3193 | |
3194 | if ((last_was_coloncolon && current.token != NAME) | |
3195 | || (!last_was_coloncolon && current.token != COLONCOLON)) | |
3196 | break; | |
3197 | last_was_coloncolon = !last_was_coloncolon; | |
3198 | } | |
3199 | popping = 1; | |
3200 | ||
3201 | /* We always read one extra token, so compute the number of tokens | |
3202 | to examine accordingly. */ | |
5fe3f3e4 | 3203 | last_to_examine = token_fifo.size () - 2; |
b2f83c08 TT |
3204 | next_to_examine = 0; |
3205 | ||
5fe3f3e4 | 3206 | current = token_fifo[next_to_examine]; |
b2f83c08 TT |
3207 | ++next_to_examine; |
3208 | ||
8268c778 | 3209 | name_obstack.clear (); |
b2f83c08 TT |
3210 | checkpoint = 0; |
3211 | if (current.token == FILENAME) | |
3212 | search_block = current.value.bval; | |
3213 | else if (current.token == COLONCOLON) | |
3214 | search_block = NULL; | |
3215 | else | |
e234dfaf | 3216 | { |
b2f83c08 | 3217 | gdb_assert (current.token == TYPENAME); |
1e58a4a4 | 3218 | search_block = pstate->expression_context_block; |
b2f83c08 TT |
3219 | obstack_grow (&name_obstack, current.value.sval.ptr, |
3220 | current.value.sval.length); | |
3221 | context_type = current.value.tsym.type; | |
3222 | checkpoint = 1; | |
e234dfaf | 3223 | } |
b2f83c08 TT |
3224 | |
3225 | first_was_coloncolon = current.token == COLONCOLON; | |
3226 | last_was_coloncolon = first_was_coloncolon; | |
3227 | ||
3228 | while (next_to_examine <= last_to_examine) | |
48e32051 | 3229 | { |
5fe3f3e4 | 3230 | token_and_value next; |
48e32051 | 3231 | |
5fe3f3e4 | 3232 | next = token_fifo[next_to_examine]; |
b2f83c08 | 3233 | ++next_to_examine; |
48e32051 | 3234 | |
5fe3f3e4 | 3235 | if (next.token == NAME && last_was_coloncolon) |
48e32051 TT |
3236 | { |
3237 | int classification; | |
3238 | ||
5fe3f3e4 | 3239 | yylval = next.value; |
410a0ff2 SDJ |
3240 | classification = classify_inner_name (pstate, search_block, |
3241 | context_type); | |
48e32051 TT |
3242 | /* We keep going until we either run out of names, or until |
3243 | we have a qualified name which is not a type. */ | |
50af5481 | 3244 | if (classification != TYPENAME && classification != NAME) |
b2f83c08 TT |
3245 | break; |
3246 | ||
3247 | /* Accept up to this token. */ | |
3248 | checkpoint = next_to_examine; | |
48e32051 TT |
3249 | |
3250 | /* Update the partial name we are constructing. */ | |
e234dfaf | 3251 | if (context_type != NULL) |
48e32051 TT |
3252 | { |
3253 | /* We don't want to put a leading "::" into the name. */ | |
3254 | obstack_grow_str (&name_obstack, "::"); | |
3255 | } | |
5fe3f3e4 TT |
3256 | obstack_grow (&name_obstack, next.value.sval.ptr, |
3257 | next.value.sval.length); | |
48e32051 | 3258 | |
79f33898 | 3259 | yylval.sval.ptr = (const char *) obstack_base (&name_obstack); |
48e32051 TT |
3260 | yylval.sval.length = obstack_object_size (&name_obstack); |
3261 | current.value = yylval; | |
3262 | current.token = classification; | |
3263 | ||
3264 | last_was_coloncolon = 0; | |
4d29c0a8 | 3265 | |
e234dfaf TT |
3266 | if (classification == NAME) |
3267 | break; | |
3268 | ||
3269 | context_type = yylval.tsym.type; | |
48e32051 | 3270 | } |
5fe3f3e4 | 3271 | else if (next.token == COLONCOLON && !last_was_coloncolon) |
48e32051 TT |
3272 | last_was_coloncolon = 1; |
3273 | else | |
3274 | { | |
3275 | /* We've reached the end of the name. */ | |
48e32051 TT |
3276 | break; |
3277 | } | |
48e32051 TT |
3278 | } |
3279 | ||
b2f83c08 TT |
3280 | /* If we have a replacement token, install it as the first token in |
3281 | the FIFO, and delete the other constituent tokens. */ | |
3282 | if (checkpoint > 0) | |
48e32051 | 3283 | { |
224c3ddb | 3284 | current.value.sval.ptr |
9d30e1fd | 3285 | = (const char *) obstack_copy0 (&cpstate->expansion_obstack, |
224c3ddb SM |
3286 | current.value.sval.ptr, |
3287 | current.value.sval.length); | |
b2f83c08 | 3288 | |
5fe3f3e4 | 3289 | token_fifo[0] = current; |
b2f83c08 | 3290 | if (checkpoint > 1) |
5fe3f3e4 TT |
3291 | token_fifo.erase (token_fifo.begin () + 1, |
3292 | token_fifo.begin () + checkpoint); | |
48e32051 TT |
3293 | } |
3294 | ||
b2f83c08 | 3295 | do_pop: |
5fe3f3e4 TT |
3296 | current = token_fifo[0]; |
3297 | token_fifo.erase (token_fifo.begin ()); | |
48e32051 | 3298 | yylval = current.value; |
48e32051 | 3299 | return current.token; |
c906108c SS |
3300 | } |
3301 | ||
65d12d83 | 3302 | int |
410a0ff2 | 3303 | c_parse (struct parser_state *par_state) |
65d12d83 | 3304 | { |
410a0ff2 | 3305 | /* Setting up the parser state. */ |
eae49211 | 3306 | scoped_restore pstate_restore = make_scoped_restore (&pstate); |
410a0ff2 SDJ |
3307 | gdb_assert (par_state != NULL); |
3308 | pstate = par_state; | |
3309 | ||
02e12e38 TT |
3310 | c_parse_state cstate; |
3311 | scoped_restore cstate_restore = make_scoped_restore (&cpstate, &cstate); | |
3312 | ||
f6c2623e | 3313 | gdb::unique_xmalloc_ptr<struct macro_scope> macro_scope; |
7c8adf68 | 3314 | |
1e58a4a4 TT |
3315 | if (par_state->expression_context_block) |
3316 | macro_scope | |
3317 | = sal_macro_scope (find_pc_line (par_state->expression_context_pc, 0)); | |
7c8adf68 | 3318 | else |
f6c2623e TT |
3319 | macro_scope = default_macro_scope (); |
3320 | if (! macro_scope) | |
3321 | macro_scope = user_macro_scope (); | |
3322 | ||
3323 | scoped_restore restore_macro_scope | |
3324 | = make_scoped_restore (&expression_macro_scope, macro_scope.get ()); | |
7c8adf68 | 3325 | |
156d9eab TT |
3326 | scoped_restore restore_yydebug = make_scoped_restore (&yydebug, |
3327 | parser_debug); | |
92981e24 | 3328 | |
7c8adf68 | 3329 | /* Initialize some state used by the lexer. */ |
59498c30 | 3330 | last_was_structop = false; |
65d12d83 | 3331 | saw_name_at_eof = 0; |
28aaf3fd | 3332 | paren_depth = 0; |
7c8adf68 | 3333 | |
5fe3f3e4 | 3334 | token_fifo.clear (); |
48e32051 | 3335 | popping = 0; |
8268c778 | 3336 | name_obstack.clear (); |
48e32051 | 3337 | |
9d30e1fd | 3338 | return yyparse (); |
65d12d83 TT |
3339 | } |
3340 | ||
12c5175d MK |
3341 | #ifdef YYBISON |
3342 | ||
9507860e TT |
3343 | /* This is called via the YYPRINT macro when parser debugging is |
3344 | enabled. It prints a token's value. */ | |
3345 | ||
3346 | static void | |
3347 | c_print_token (FILE *file, int type, YYSTYPE value) | |
3348 | { | |
3349 | switch (type) | |
3350 | { | |
3351 | case INT: | |
66be918f PA |
3352 | parser_fprintf (file, "typed_val_int<%s, %s>", |
3353 | TYPE_SAFE_NAME (value.typed_val_int.type), | |
3354 | pulongest (value.typed_val_int.val)); | |
9507860e TT |
3355 | break; |
3356 | ||
3357 | case CHAR: | |
3358 | case STRING: | |
3359 | { | |
224c3ddb | 3360 | char *copy = (char *) alloca (value.tsval.length + 1); |
9507860e TT |
3361 | |
3362 | memcpy (copy, value.tsval.ptr, value.tsval.length); | |
3363 | copy[value.tsval.length] = '\0'; | |
3364 | ||
66be918f | 3365 | parser_fprintf (file, "tsval<type=%d, %s>", value.tsval.type, copy); |
9507860e TT |
3366 | } |
3367 | break; | |
3368 | ||
3369 | case NSSTRING: | |
cfeadda5 | 3370 | case DOLLAR_VARIABLE: |
66be918f | 3371 | parser_fprintf (file, "sval<%s>", copy_name (value.sval)); |
9507860e TT |
3372 | break; |
3373 | ||
3374 | case TYPENAME: | |
66be918f PA |
3375 | parser_fprintf (file, "tsym<type=%s, name=%s>", |
3376 | TYPE_SAFE_NAME (value.tsym.type), | |
3377 | copy_name (value.tsym.stoken)); | |
9507860e TT |
3378 | break; |
3379 | ||
3380 | case NAME: | |
3381 | case UNKNOWN_CPP_NAME: | |
3382 | case NAME_OR_INT: | |
3383 | case BLOCKNAME: | |
66be918f PA |
3384 | parser_fprintf (file, "ssym<name=%s, sym=%s, field_of_this=%d>", |
3385 | copy_name (value.ssym.stoken), | |
3386 | (value.ssym.sym.symbol == NULL | |
3387 | ? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym.symbol)), | |
3388 | value.ssym.is_a_field_of_this); | |
9507860e TT |
3389 | break; |
3390 | ||
3391 | case FILENAME: | |
66be918f | 3392 | parser_fprintf (file, "bval<%s>", host_address_to_string (value.bval)); |
9507860e TT |
3393 | break; |
3394 | } | |
3395 | } | |
7c8adf68 | 3396 | |
12c5175d MK |
3397 | #endif |
3398 | ||
69d340c6 | 3399 | static void |
a121b7c1 | 3400 | yyerror (const char *msg) |
c906108c | 3401 | { |
5776fca3 TT |
3402 | if (pstate->prev_lexptr) |
3403 | pstate->lexptr = pstate->prev_lexptr; | |
665132f9 | 3404 | |
5776fca3 | 3405 | error (_("A %s in expression, near `%s'."), msg, pstate->lexptr); |
c906108c | 3406 | } |