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