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