GDB (xrefs)

/tmp/gdb-8.1/gdb/rust-exp.c
Go to the documentation of this file.
1 /* A Bison parser, made by GNU Bison 3.0.4. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
29
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
42
43 /* Identify Bison output. */
44 #define YYBISON 1
45
46 /* Bison version. */
47 #define YYBISON_VERSION "3.0.4"
48
49 /* Skeleton name. */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers. */
53 #define YYPURE 0
54
55 /* Push parsers. */
56 #define YYPUSH 0
57
58 /* Pull parsers. */
59 #define YYPULL 1
60
61
62
63
64 /* Copy the first part of user declarations. */
65 #line 22 "rust-exp.y" /* yacc.c:339 */
66
67
68 #include "defs.h"
69
70 #include "block.h"
71 #include "charset.h"
72 #include "cp-support.h"
73 #include "gdb_obstack.h"
74 #include "gdb_regex.h"
75 #include "rust-lang.h"
76 #include "parser-defs.h"
77 #include "selftest.h"
78 #include "value.h"
79 #include "vec.h"
80
81 #define GDB_YY_REMAP_PREFIX rust
82 #include "yy-remap.h"
83
84 #define RUSTSTYPE YYSTYPE
85
86 struct rust_op;
87 typedef std::vector<const struct rust_op *> rust_op_vector;
88
89 /* A typed integer constant. */
90
91 struct typed_val_int
92 {
93 LONGEST val;
94 struct type *type;
95 };
96
97 /* A typed floating point constant. */
98
99 struct typed_val_float
100 {
101 gdb_byte val[16];
102 struct type *type;
103 };
104
105 /* An identifier and an expression. This is used to represent one
106 element of a struct initializer. */
107
108 struct set_field
109 {
110 struct stoken name;
111 const struct rust_op *init;
112 };
113
114 typedef std::vector<set_field> rust_set_vector;
115
116 static int rustyylex (void);
117 static void rust_push_back (char c);
118 static const char *rust_copy_name (const char *, int);
119 static struct stoken rust_concat3 (const char *, const char *, const char *);
120 static struct stoken make_stoken (const char *);
121 static struct block_symbol rust_lookup_symbol (const char *name,
122 const struct block *block,
123 const domain_enum domain);
124 static struct type *rust_lookup_type (const char *name,
125 const struct block *block);
126 static struct type *rust_type (const char *name);
127
128 static const struct rust_op *crate_name (const struct rust_op *name);
129 static const struct rust_op *super_name (const struct rust_op *name,
130 unsigned int n_supers);
131
132 static const struct rust_op *ast_operation (enum exp_opcode opcode,
133 const struct rust_op *left,
134 const struct rust_op *right);
135 static const struct rust_op *ast_compound_assignment
136 (enum exp_opcode opcode, const struct rust_op *left,
137 const struct rust_op *rust_op);
138 static const struct rust_op *ast_literal (struct typed_val_int val);
139 static const struct rust_op *ast_dliteral (struct typed_val_float val);
140 static const struct rust_op *ast_structop (const struct rust_op *left,
141 const char *name,
142 int completing);
143 static const struct rust_op *ast_structop_anonymous
144 (const struct rust_op *left, struct typed_val_int number);
145 static const struct rust_op *ast_unary (enum exp_opcode opcode,
146 const struct rust_op *expr);
147 static const struct rust_op *ast_cast (const struct rust_op *expr,
148 const struct rust_op *type);
149 static const struct rust_op *ast_call_ish (enum exp_opcode opcode,
150 const struct rust_op *expr,
151 rust_op_vector *params);
152 static const struct rust_op *ast_path (struct stoken name,
153 rust_op_vector *params);
154 static const struct rust_op *ast_string (struct stoken str);
155 static const struct rust_op *ast_struct (const struct rust_op *name,
156 rust_set_vector *fields);
157 static const struct rust_op *ast_range (const struct rust_op *lhs,
158 const struct rust_op *rhs);
159 static const struct rust_op *ast_array_type (const struct rust_op *lhs,
160 struct typed_val_int val);
161 static const struct rust_op *ast_slice_type (const struct rust_op *type);
162 static const struct rust_op *ast_reference_type (const struct rust_op *type);
163 static const struct rust_op *ast_pointer_type (const struct rust_op *type,
164 int is_mut);
165 static const struct rust_op *ast_function_type (const struct rust_op *result,
166 rust_op_vector *params);
167 static const struct rust_op *ast_tuple_type (rust_op_vector *params);
168
169 /* The current rust parser. */
170
171 struct rust_parser;
172 static rust_parser *current_parser;
173
174 /* A regular expression for matching Rust numbers. This is split up
175 since it is very long and this gives us a way to comment the
176 sections. */
177
178 static const char *number_regex_text =
179 /* subexpression 1: allows use of alternation, otherwise uninteresting */
180 "^("
181 /* First comes floating point. */
182 /* Recognize number after the decimal point, with optional
183 exponent and optional type suffix.
184 subexpression 2: allows "?", otherwise uninteresting
185 subexpression 3: if present, type suffix
186 */
187 "[0-9][0-9_]*\\.[0-9][0-9_]*([eE][-+]?[0-9][0-9_]*)?(f32|f64)?"
188 #define FLOAT_TYPE1 3
189 "|"
190 /* Recognize exponent without decimal point, with optional type
191 suffix.
192 subexpression 4: if present, type suffix
193 */
194 #define FLOAT_TYPE2 4
195 "[0-9][0-9_]*[eE][-+]?[0-9][0-9_]*(f32|f64)?"
196 "|"
197 /* "23." is a valid floating point number, but "23.e5" and
198 "23.f32" are not. So, handle the trailing-. case
199 separately. */
200 "[0-9][0-9_]*\\."
201 "|"
202 /* Finally come integers.
203 subexpression 5: text of integer
204 subexpression 6: if present, type suffix
205 subexpression 7: allows use of alternation, otherwise uninteresting
206 */
207 #define INT_TEXT 5
208 #define INT_TYPE 6
209 "(0x[a-fA-F0-9_]+|0o[0-7_]+|0b[01_]+|[0-9][0-9_]*)"
210 "([iu](size|8|16|32|64))?"
211 ")";
212 /* The number of subexpressions to allocate space for, including the
213 "0th" whole match subexpression. */
214 #define NUM_SUBEXPRESSIONS 8
215
216 /* The compiled number-matching regex. */
217
218 static regex_t number_regex;
219
220 /* Obstack for data temporarily allocated during parsing. Points to
221 the obstack in the rust_parser, or to a temporary obstack during
222 unit testing. */
223
224 static auto_obstack *work_obstack;
225
226 /* An instance of this is created before parsing, and destroyed when
227 parsing is finished. */
228
229 struct rust_parser
230 {
231 rust_parser (struct parser_state *state)
232 : rust_ast (nullptr),
233 pstate (state)
234 {
235 gdb_assert (current_parser == nullptr);
236 current_parser = this;
237 work_obstack = &obstack;
238 }
239
240 ~rust_parser ()
241 {
242 /* Clean up the globals we set. */
243 current_parser = nullptr;
244 work_obstack = nullptr;
245 }
246
247 /* Create a new rust_set_vector. The storage for the new vector is
248 managed by this class. */
249 rust_set_vector *new_set_vector ()
250 {
251 rust_set_vector *result = new rust_set_vector;
252 set_vectors.push_back (std::unique_ptr<rust_set_vector> (result));
253 return result;
254 }
255
256 /* Create a new rust_ops_vector. The storage for the new vector is
257 managed by this class. */
258 rust_op_vector *new_op_vector ()
259 {
260 rust_op_vector *result = new rust_op_vector;
261 op_vectors.push_back (std::unique_ptr<rust_op_vector> (result));
262 return result;
263 }
264
265 /* Return the parser's language. */
266 const struct language_defn *language () const
267 {
268 return parse_language (pstate);
269 }
270
271 /* Return the parser's gdbarch. */
272 struct gdbarch *arch () const
273 {
274 return parse_gdbarch (pstate);
275 }
276
277 /* A pointer to this is installed globally. */
278 auto_obstack obstack;
279
280 /* Result of parsing. Points into obstack. */
281 const struct rust_op *rust_ast;
282
283 /* This keeps track of the various vectors we allocate. */
284 std::vector<std::unique_ptr<rust_set_vector>> set_vectors;
285 std::vector<std::unique_ptr<rust_op_vector>> op_vectors;
286
287 /* The parser state gdb gave us. */
288 struct parser_state *pstate;
289 };
290
291
292 #line 293 "rust-exp.c" /* yacc.c:339 */
293
294 # ifndef YY_NULLPTRPTR
295 # if defined __cplusplus && 201103L <= __cplusplus
296 # define YY_NULLPTRPTR nullptr
297 # else
298 # define YY_NULLPTRPTR 0
299 # endif
300 # endif
301
302 /* Enabling verbose error messages. */
303 #ifdef YYERROR_VERBOSE
304 # undef YYERROR_VERBOSE
305 # define YYERROR_VERBOSE 1
306 #else
307 # define YYERROR_VERBOSE 0
308 #endif
309
310
311 /* Debug traces. */
312 #ifndef YYDEBUG
313 # define YYDEBUG 0
314 #endif
315 #if YYDEBUG
316 extern int yydebug;
317 #endif
318
319 /* Token type. */
320 #ifndef YYTOKENTYPE
321 # define YYTOKENTYPE
322 enum yytokentype
323 {
324 GDBVAR = 258,
325 IDENT = 259,
326 COMPLETE = 260,
327 INTEGER = 261,
328 DECIMAL_INTEGER = 262,
329 STRING = 263,
330 BYTESTRING = 264,
331 FLOAT = 265,
332 COMPOUND_ASSIGN = 266,
333 KW_AS = 267,
334 KW_IF = 268,
335 KW_TRUE = 269,
336 KW_FALSE = 270,
337 KW_SUPER = 271,
338 KW_SELF = 272,
339 KW_MUT = 273,
340 KW_EXTERN = 274,
341 KW_CONST = 275,
342 KW_FN = 276,
343 KW_SIZEOF = 277,
344 DOTDOT = 278,
345 OROR = 279,
346 ANDAND = 280,
347 EQEQ = 281,
348 NOTEQ = 282,
349 LTEQ = 283,
350 GTEQ = 284,
351 LSH = 285,
352 RSH = 286,
353 COLONCOLON = 287,
354 ARROW = 288,
355 UNARY = 289
356 };
357 #endif
358 /* Tokens. */
359 #define GDBVAR 258
360 #define IDENT 259
361 #define COMPLETE 260
362 #define INTEGER 261
363 #define DECIMAL_INTEGER 262
364 #define STRING 263
365 #define BYTESTRING 264
366 #define FLOAT 265
367 #define COMPOUND_ASSIGN 266
368 #define KW_AS 267
369 #define KW_IF 268
370 #define KW_TRUE 269
371 #define KW_FALSE 270
372 #define KW_SUPER 271
373 #define KW_SELF 272
374 #define KW_MUT 273
375 #define KW_EXTERN 274
376 #define KW_CONST 275
377 #define KW_FN 276
378 #define KW_SIZEOF 277
379 #define DOTDOT 278
380 #define OROR 279
381 #define ANDAND 280
382 #define EQEQ 281
383 #define NOTEQ 282
384 #define LTEQ 283
385 #define GTEQ 284
386 #define LSH 285
387 #define RSH 286
388 #define COLONCOLON 287
389 #define ARROW 288
390 #define UNARY 289
391
392 /* Value type. */
393 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
394
395 union YYSTYPE
396 {
397 #line 250 "rust-exp.y" /* yacc.c:355 */
398
399 /* A typed integer constant. */
400 struct typed_val_int typed_val_int;
401
402 /* A typed floating point constant. */
403 struct typed_val_float typed_val_float;
404
405 /* An identifier or string. */
406 struct stoken sval;
407
408 /* A token representing an opcode, like "==". */
409 enum exp_opcode opcode;
410
411 /* A list of expressions; for example, the arguments to a function
412 call. */
413 rust_op_vector *params;
414
415 /* A list of field initializers. */
416 rust_set_vector *field_inits;
417
418 /* A single field initializer. */
419 struct set_field one_field_init;
420
421 /* An expression. */
422 const struct rust_op *op;
423
424 /* A plain integer, for example used to count the number of
425 "super::" prefixes on a path. */
426 unsigned int depth;
427
428 #line 429 "rust-exp.c" /* yacc.c:355 */
429 };
430
431 typedef union YYSTYPE YYSTYPE;
432 # define YYSTYPE_IS_TRIVIAL 1
433 # define YYSTYPE_IS_DECLARED 1
434 #endif
435
436
437 extern YYSTYPE yylval;
438
439 int yyparse (void);
440
441
442
443 /* Copy the second part of user declarations. */
444 #line 281 "rust-exp.y" /* yacc.c:358 */
445
446
447 /* Rust AST operations. We build a tree of these; then lower them
448 to gdb expressions when parsing has completed. */
449
450 struct rust_op
451 {
452 /* The opcode. */
453 enum exp_opcode opcode;
454 /* If OPCODE is OP_TYPE, then this holds information about what type
455 is described by this node. */
456 enum type_code typecode;
457 /* Indicates whether OPCODE actually represents a compound
458 assignment. For example, if OPCODE is GTGT and this is false,
459 then this rust_op represents an ordinary ">>"; but if this is
460 true, then this rust_op represents ">>=". Unused in other
461 cases. */
462 unsigned int compound_assignment : 1;
463 /* Only used by a field expression; if set, indicates that the field
464 name occurred at the end of the expression and is eligible for
465 completion. */
466 unsigned int completing : 1;
467 /* Operands of expression. Which one is used and how depends on the
468 particular opcode. */
469 RUSTSTYPE left;
470 RUSTSTYPE right;
471 };
472
473
474 #line 475 "rust-exp.c" /* yacc.c:358 */
475
476 #ifdef short
477 # undef short
478 #endif
479
480 #ifdef YYTYPE_UINT8
481 typedef YYTYPE_UINT8 yytype_uint8;
482 #else
483 typedef unsigned char yytype_uint8;
484 #endif
485
486 #ifdef YYTYPE_INT8
487 typedef YYTYPE_INT8 yytype_int8;
488 #else
489 typedef signed char yytype_int8;
490 #endif
491
492 #ifdef YYTYPE_UINT16
493 typedef YYTYPE_UINT16 yytype_uint16;
494 #else
495 typedef unsigned short int yytype_uint16;
496 #endif
497
498 #ifdef YYTYPE_INT16
499 typedef YYTYPE_INT16 yytype_int16;
500 #else
501 typedef short int yytype_int16;
502 #endif
503
504 #ifndef YYSIZE_T
505 # ifdef __SIZE_TYPE__
506 # define YYSIZE_T __SIZE_TYPE__
507 # elif defined size_t
508 # define YYSIZE_T size_t
509 # elif ! defined YYSIZE_T
510 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
511 # define YYSIZE_T size_t
512 # else
513 # define YYSIZE_T unsigned int
514 # endif
515 #endif
516
517 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
518
519 #ifndef YY_
520 # if defined YYENABLE_NLS && YYENABLE_NLS
521 # if ENABLE_NLS
522 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
523 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
524 # endif
525 # endif
526 # ifndef YY_
527 # define YY_(Msgid) Msgid
528 # endif
529 #endif
530
531 #ifndef YY_ATTRIBUTE
532 # if (defined __GNUC__ \
533 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
534 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
535 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
536 # else
537 # define YY_ATTRIBUTE(Spec) /* empty */
538 # endif
539 #endif
540
541 #ifndef YY_ATTRIBUTE_PURE
542 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
543 #endif
544
545 #ifndef YY_ATTRIBUTE_UNUSED
546 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
547 #endif
548
549 #if !defined _Noreturn \
550 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
551 # if defined _MSC_VER && 1200 <= _MSC_VER
552 # define _Noreturn __declspec (noreturn)
553 # else
554 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
555 # endif
556 #endif
557
558 /* Suppress unused-variable warnings by "using" E. */
559 #if ! defined lint || defined __GNUC__
560 # define YYUSE(E) ((void) (E))
561 #else
562 # define YYUSE(E) /* empty */
563 #endif
564
565 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
566 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
567 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
568 _Pragma ("GCC diagnostic push") \
569 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
570 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
571 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
572 _Pragma ("GCC diagnostic pop")
573 #else
574 # define YY_INITIAL_VALUE(Value) Value
575 #endif
576 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
577 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
578 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
579 #endif
580 #ifndef YY_INITIAL_VALUE
581 # define YY_INITIAL_VALUE(Value) /* Nothing. */
582 #endif
583
584
585 #if ! defined yyoverflow || YYERROR_VERBOSE
586
587 /* The parser invokes alloca or xmalloc; define the necessary symbols. */
588
589 # ifdef YYSTACK_USE_ALLOCA
590 # if YYSTACK_USE_ALLOCA
591 # ifdef __GNUC__
592 # define YYSTACK_ALLOC __builtin_alloca
593 # elif defined __BUILTIN_VA_ARG_INCR
594 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
595 # elif defined _AIX
596 # define YYSTACK_ALLOC __alloca
597 # elif defined _MSC_VER
598 # define alloca _alloca
599 # else
600 # define YYSTACK_ALLOC alloca
601 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
602 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
603 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
604 # ifndef EXIT_SUCCESS
605 # define EXIT_SUCCESS 0
606 # endif
607 # endif
608 # endif
609 # endif
610 # endif
611
612 # ifdef YYSTACK_ALLOC
613 /* Pacify GCC's 'empty if-body' warning. */
614 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
615 # ifndef YYSTACK_ALLOC_MAXIMUM
616 /* The OS might guarantee only one guard page at the bottom of the stack,
617 and a page size can be as small as 4096 bytes. So we cannot safely
618 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
619 to allow for a few compiler-allocated temporary stack slots. */
620 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
621 # endif
622 # else
623 # define YYSTACK_ALLOC YYMALLOC
624 # define YYSTACK_FREE YYFREE
625 # ifndef YYSTACK_ALLOC_MAXIMUM
626 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
627 # endif
628 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
629 && ! ((defined YYMALLOC || defined xmalloc) \
630 && (defined YYFREE || defined xfree)))
631 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
632 # ifndef EXIT_SUCCESS
633 # define EXIT_SUCCESS 0
634 # endif
635 # endif
636 # ifndef YYMALLOC
637 # define YYMALLOC xmalloc
638 # if ! defined xmalloc && ! defined EXIT_SUCCESS
639 void *xmalloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
640 # endif
641 # endif
642 # ifndef YYFREE
643 # define YYFREE xfree
644 # if ! defined xfree && ! defined EXIT_SUCCESS
645 void xfree (void *); /* INFRINGES ON USER NAME SPACE */
646 # endif
647 # endif
648 # endif
649 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
650
651
652 #if (! defined yyoverflow \
653 && (! defined __cplusplus \
654 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
655
656 /* A type that is properly aligned for any stack member. */
657 union yyalloc
658 {
659 yytype_int16 yyss_alloc;
660 YYSTYPE yyvs_alloc;
661 };
662
663 /* The size of the maximum gap between one aligned stack and the next. */
664 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
665
666 /* The size of an array large to enough to hold all stacks, each with
667 N elements. */
668 # define YYSTACK_BYTES(N) \
669 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
670 + YYSTACK_GAP_MAXIMUM)
671
672 # define YYCOPY_NEEDED 1
673
674 /* Relocate STACK from its old location to the new one. The
675 local variables YYSIZE and YYSTACKSIZE give the old and new number of
676 elements in the stack, and YYPTR gives the new location of the
677 stack. Advance YYPTR to a properly aligned location for the next
678 stack. */
679 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
680 do \
681 { \
682 YYSIZE_T yynewbytes; \
683 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
684 Stack = &yyptr->Stack_alloc; \
685 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
686 yyptr += yynewbytes / sizeof (*yyptr); \
687 } \
688 while (0)
689
690 #endif
691
692 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
693 /* Copy COUNT objects from SRC to DST. The source and destination do
694 not overlap. */
695 # ifndef YYCOPY
696 # if defined __GNUC__ && 1 < __GNUC__
697 # define YYCOPY(Dst, Src, Count) \
698 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
699 # else
700 # define YYCOPY(Dst, Src, Count) \
701 do \
702 { \
703 YYSIZE_T yyi; \
704 for (yyi = 0; yyi < (Count); yyi++) \
705 (Dst)[yyi] = (Src)[yyi]; \
706 } \
707 while (0)
708 # endif
709 # endif
710 #endif /* !YYCOPY_NEEDED */
711
712 /* YYFINAL -- State number of the termination state. */
713 #define YYFINAL 60
714 /* YYLAST -- Last index in YYTABLE. */
715 #define YYLAST 1031
716
717 /* YYNTOKENS -- Number of terminals. */
718 #define YYNTOKENS 58
719 /* YYNNTS -- Number of nonterminals. */
720 #define YYNNTS 35
721 /* YYNRULES -- Number of rules. */
722 #define YYNRULES 121
723 /* YYNSTATES -- Number of states. */
724 #define YYNSTATES 213
725
726 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
727 by yylex, with out-of-bounds checking. */
728 #define YYUNDEFTOK 2
729 #define YYMAXUTOK 289
730
731 #define YYTRANSLATE(YYX) \
732 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
733
734 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
735 as returned by yylex, without out-of-bounds checking. */
736 static const yytype_uint8 yytranslate[] =
737 {
738 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
739 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
740 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
741 2, 2, 2, 57, 2, 2, 2, 45, 39, 2,
742 49, 51, 43, 41, 50, 42, 48, 44, 2, 2,
743 2, 2, 2, 2, 2, 2, 2, 2, 54, 56,
744 35, 34, 36, 2, 40, 2, 2, 2, 2, 2,
745 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
746 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
747 2, 47, 2, 55, 38, 2, 2, 2, 2, 2,
748 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
749 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
750 2, 2, 2, 52, 37, 53, 2, 2, 2, 2,
751 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
752 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
753 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
754 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
755 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
756 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
757 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
758 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
759 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
760 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
761 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
762 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
763 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
764 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
765 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
766 25, 26, 27, 28, 29, 30, 31, 32, 33, 46
767 };
768
769 #if YYDEBUG
770 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
771 static const yytype_uint16 yyrline[] =
772 {
773 0, 406, 406, 419, 420, 421, 422, 423, 424, 425,
774 426, 427, 428, 429, 430, 431, 435, 443, 460, 465,
775 475, 487, 490, 496, 508, 510, 512, 514, 519, 521,
776 523, 525, 530, 532, 534, 536, 563, 565, 574, 586,
777 588, 593, 598, 603, 606, 609, 618, 621, 624, 626,
778 631, 632, 633, 634, 638, 641, 644, 647, 650, 653,
779 656, 659, 662, 665, 668, 671, 674, 677, 680, 683,
780 686, 689, 692, 697, 702, 707, 713, 718, 723, 732,
781 736, 741, 748, 752, 754, 758, 760, 765, 767, 769,
782 774, 775, 777, 779, 781, 793, 795, 801, 803, 811,
783 812, 814, 816, 818, 830, 832, 841, 842, 844, 852,
784 853, 855, 857, 859, 861, 863, 865, 867, 873, 874,
785 879, 885
786 };
787 #endif
788
789 #if YYDEBUG || YYERROR_VERBOSE || 0
790 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
791 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
792 static const char *const yytname[] =
793 {
794 "$end", "error", "$undefined", "GDBVAR", "IDENT", "COMPLETE", "INTEGER",
795 "DECIMAL_INTEGER", "STRING", "BYTESTRING", "FLOAT", "COMPOUND_ASSIGN",
796 "KW_AS", "KW_IF", "KW_TRUE", "KW_FALSE", "KW_SUPER", "KW_SELF", "KW_MUT",
797 "KW_EXTERN", "KW_CONST", "KW_FN", "KW_SIZEOF", "DOTDOT", "OROR",
798 "ANDAND", "EQEQ", "NOTEQ", "LTEQ", "GTEQ", "LSH", "RSH", "COLONCOLON",
799 "ARROW", "'='", "'<'", "'>'", "'|'", "'^'", "'&'", "'@'", "'+'", "'-'",
800 "'*'", "'/'", "'%'", "UNARY", "'['", "'.'", "'('", "','", "')'", "'{'",
801 "'}'", "':'", "']'", "';'", "'!'", "$accept", "start", "expr",
802 "tuple_expr", "unit_expr", "struct_expr", "struct_expr_tail",
803 "struct_expr_list", "array_expr", "range_expr", "literal", "field_expr",
804 "idx_expr", "unop_expr", "binop_expr", "binop_expr_expr",
805 "type_cast_expr", "assignment_expr", "compound_assignment_expr",
806 "paren_expr", "expr_list", "maybe_expr_list", "paren_expr_list",
807 "call_expr", "maybe_self_path", "super_path", "path_expr",
808 "path_for_expr", "identifier_path_for_expr", "path_for_type",
809 "just_identifiers_for_type", "identifier_path_for_type", "type",
810 "maybe_type_list", "type_list", YY_NULLPTRPTR
811 };
812 #endif
813
814 # ifdef YYPRINT
815 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
816 (internal) symbol number NUM (which must be that of a token). */
817 static const yytype_uint16 yytoknum[] =
818 {
819 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
820 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
821 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
822 285, 286, 287, 288, 61, 60, 62, 124, 94, 38,
823 64, 43, 45, 42, 47, 37, 289, 91, 46, 40,
824 44, 41, 123, 125, 58, 93, 59, 33
825 };
826 # endif
827
828 #define YYPACT_NINF -151
829
830 #define yypact_value_is_default(Yystate) \
831 (!!((Yystate) == (-151)))
832
833 #define YYTABLE_NINF -119
834
835 #define yytable_value_is_error(Yytable_value) \
836 (!!((Yytable_value) == (-119)))
837
838 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
839 STATE-NUM. */
840 static const yytype_int16 yypact[] =
841 {
842 384, -151, -151, -151, -151, -151, -151, -151, -151, -151,
843 -20, 41, -2, 119, 41, 176, 384, 384, 384, 228,
844 280, 384, 56, 742, -151, -151, -151, -151, -151, -151,
845 -151, -151, -151, -151, -151, -151, -151, -151, -151, -151,
846 42, -151, 8, 30, 41, 30, 384, 781, 30, 384,
847 68, 68, 68, 68, 384, 425, -28, -151, 620, 68,
848 -151, 384, 209, 119, 384, 384, 384, 384, 384, 384,
849 384, 384, 384, 384, 384, 384, 384, 384, 384, 384,
850 384, 384, 384, 384, 384, 96, 332, -151, 53, 10,
851 6, 5, 30, 661, 68, 464, 2, 384, 384, -151,
852 332, -151, 820, -151, 78, 109, 71, 109, 261, 15,
853 209, 396, 42, -151, 73, -151, -151, 781, 854, 888,
854 922, 922, 922, 922, 162, 162, 820, 922, 922, 942,
855 962, 982, 47, 313, 313, -11, -11, -11, 503, -151,
856 -151, -151, 742, 74, 70, -151, 98, 30, 77, 384,
857 -151, 86, -151, 209, -151, 384, -151, 542, 742, 89,
858 109, -151, 396, -151, 209, -151, 209, 209, 87, -151,
859 93, 95, 27, 142, 209, -151, -151, -151, 384, 742,
860 -151, -8, 581, -151, -151, -151, 99, -50, -151, -151,
861 112, -151, 209, -151, -151, -6, 702, -151, -151, -151,
862 114, -151, 97, 101, -151, -151, -151, 6, 209, -151,
863 -151, -151, -151
864 };
865
866 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
867 Performed when YYTABLE does not specify something else to do. Zero
868 means the default is an error. */
869 static const yytype_uint8 yydefact[] =
870 {
871 83, 88, 95, 32, 33, 35, 36, 34, 37, 38,
872 89, 0, 0, 31, 0, 83, 83, 83, 83, 83,
873 83, 83, 0, 2, 5, 6, 7, 9, 11, 3,
874 8, 10, 12, 13, 50, 51, 52, 53, 14, 15,
875 0, 4, 87, 90, 84, 94, 83, 30, 93, 83,
876 47, 43, 44, 46, 83, 77, 0, 17, 0, 45,
877 1, 83, 83, 28, 83, 83, 83, 83, 83, 83,
878 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
879 83, 83, 83, 83, 83, 0, 79, 82, 0, 0,
880 21, 0, 91, 0, 48, 77, 0, 83, 83, 25,
881 79, 76, 75, 104, 0, 0, 0, 0, 83, 0,
882 83, 83, 0, 109, 106, 99, 73, 29, 65, 66,
883 67, 68, 69, 70, 71, 72, 74, 58, 59, 61,
884 62, 60, 55, 63, 64, 54, 56, 57, 0, 39,
885 40, 41, 77, 80, 0, 85, 0, 92, 0, 83,
886 22, 0, 96, 83, 49, 83, 24, 0, 78, 0,
887 84, 103, 83, 102, 83, 113, 83, 83, 0, 120,
888 0, 119, 0, 0, 83, 42, 81, 86, 83, 19,
889 18, 0, 0, 27, 16, 100, 0, 0, 114, 115,
890 0, 117, 83, 101, 105, 0, 20, 98, 97, 26,
891 0, 112, 0, 0, 121, 108, 107, 21, 83, 110,
892 111, 23, 116
893 };
894
895 /* YYPGOTO[NTERM-NUM]. */
896 static const yytype_int16 yypgoto[] =
897 {
898 -151, -151, 0, -151, -151, -151, -151, -53, -151, -151,
899 -151, -151, -151, -151, -151, -151, -151, -151, -151, -151,
900 -15, 57, -151, -151, -60, 51, -151, -151, -3, -151,
901 -151, -73, -55, 3, -150
902 };
903
904 /* YYDEFGOTO[NTERM-NUM]. */
905 static const yytype_int16 yydefgoto[] =
906 {
907 -1, 22, 142, 24, 25, 26, 150, 151, 27, 28,
908 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
909 143, 144, 87, 39, 40, 89, 41, 42, 43, 113,
910 114, 115, 169, 170, 171
911 };
912
913 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
914 positive, shift that token. If negative, reduce the rule whose
915 number is the opposite. If YYTABLE_NINF, syntax error. */
916 static const yytype_int16 yytable[] =
917 {
918 23, 62, 112, 181, 56, 201, 190, 116, 45, 152,
919 148, 48, 44, 47, 2, 50, 51, 52, 53, 55,
920 58, 59, 98, 197, 195, 205, 146, 99, 198, 149,
921 206, 103, 161, 166, 163, 167, 84, 85, 86, 96,
922 153, 92, 192, 146, 192, 2, 93, 46, 112, 94,
923 112, 112, 98, 165, 95, 168, 60, 156, 88, 62,
924 90, 102, 91, 117, 118, 119, 120, 121, 122, 123,
925 124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
926 134, 135, 136, 137, 138, 145, 147, 185, 79, 80,
927 81, 82, 83, 112, 84, 85, 86, 157, 158, 193,
928 139, 140, 112, 141, 112, 173, 112, 112, 174, 187,
929 160, 188, 189, 103, 112, 84, 85, 86, 202, 203,
930 162, 176, 1, 2, 98, 3, 4, 5, 6, 7,
931 177, 178, 112, 8, 9, -83, 10, 204, 11, 180,
932 184, 12, -119, 190, 191, 192, 194, 208, 112, 179,
933 200, 14, 209, 212, 211, 182, 210, 159, 15, 0,
934 16, 17, 18, 172, 0, 186, 19, 0, 20, 0,
935 0, 0, 0, 0, 62, 0, 21, 0, 196, 1,
936 2, 0, 3, 4, 5, 6, 7, 0, 0, 0,
937 8, 9, 0, 10, 49, 11, 0, 0, 12, 13,
938 0, 0, 78, 79, 80, 81, 82, 83, 14, 84,
939 85, 86, 0, 103, 0, 15, 0, 16, 17, 18,
940 0, 0, 0, 19, 0, 20, 104, 0, 105, 0,
941 106, 1, 2, 21, 3, 4, 5, 6, 7, 0,
942 0, 107, 8, 9, 0, 10, 54, 11, 108, 0,
943 12, 13, 109, 0, 0, 0, 110, 0, 111, 0,
944 14, 0, 0, 0, 0, 103, 0, 15, 0, 16,
945 17, 18, 0, 0, 0, 19, 0, 20, 104, 0,
946 105, 0, 106, 1, 2, 21, 3, 4, 5, 6,
947 7, 0, 0, 107, 8, 9, 0, 10, 0, 11,
948 108, 0, 12, 13, 109, 0, 0, 0, 164, 0,
949 111, 0, 14, 0, 0, 0, 0, 0, 0, 15,
950 0, 16, 17, 18, 0, 62, 0, 19, 0, 20,
951 0, 57, 0, 0, 0, 1, 2, 21, 3, 4,
952 5, 6, 7, 0, 0, 0, 8, 9, -83, 10,
953 0, 11, 0, 0, 12, 13, 81, 82, 83, 0,
954 84, 85, 86, 0, 14, 0, 0, 0, 0, 0,
955 0, 15, 0, 16, 17, 18, 0, 0, 0, 19,
956 0, 20, 0, 0, 0, 0, 0, 1, 2, 21,
957 3, 4, 5, 6, 7, 0, 0, 0, 8, 9,
958 103, 10, 0, 11, 0, 0, 12, 13, 0, 0,
959 0, 0, 0, 104, 0, 105, 14, 106, 0, 0,
960 0, 0, 0, 15, 0, 16, 17, 18, 107, 0,
961 0, 19, 0, 20, 0, 108, 61, 62, 0, 109,
962 0, 21, 0, 110, 0, 111, 0, -118, 63, 64,
963 65, 66, 67, 68, 69, 70, 71, 0, 0, 72,
964 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
965 83, 0, 84, 85, 86, 61, 62, 0, 0, 0,
966 0, 97, 0, 0, 0, 0, 0, 63, 64, 65,
967 66, 67, 68, 69, 70, 71, 0, 0, 72, 73,
968 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
969 0, 84, 85, 86, 61, 62, 0, 0, 0, 0,
970 155, 0, 0, 0, 0, 0, 63, 64, 65, 66,
971 67, 68, 69, 70, 71, 0, 0, 72, 73, 74,
972 75, 76, 77, 78, 79, 80, 81, 82, 83, 0,
973 84, 85, 86, 61, 62, 0, 0, 0, 175, 0,
974 0, 0, 0, 0, 0, 63, 64, 65, 66, 67,
975 68, 69, 70, 71, 0, 0, 72, 73, 74, 75,
976 76, 77, 78, 79, 80, 81, 82, 83, 0, 84,
977 85, 86, 61, 62, 0, 0, 0, 183, 0, 0,
978 0, 0, 0, 0, 63, 64, 65, 66, 67, 68,
979 69, 70, 71, 0, 0, 72, 73, 74, 75, 76,
980 77, 78, 79, 80, 81, 82, 83, 0, 84, 85,
981 86, 61, 62, 0, 0, 0, 199, 0, 0, 0,
982 0, 0, 0, 63, 64, 65, 66, 67, 68, 69,
983 70, 71, 0, 0, 72, 73, 74, 75, 76, 77,
984 78, 79, 80, 81, 82, 83, 0, 84, 85, 86,
985 100, 101, 61, 62, 0, 0, 0, 0, 0, 0,
986 0, 0, 0, 0, 63, 64, 65, 66, 67, 68,
987 69, 70, 71, 0, 0, 72, 73, 74, 75, 76,
988 77, 78, 79, 80, 81, 82, 83, 0, 84, 85,
989 86, 0, 154, 61, 62, 0, 0, 0, 0, 0,
990 0, 0, 0, 0, 0, 63, 64, 65, 66, 67,
991 68, 69, 70, 71, 0, 0, 72, 73, 74, 75,
992 76, 77, 78, 79, 80, 81, 82, 83, 0, 84,
993 85, 86, 207, 61, 62, 0, 0, 0, 0, 0,
994 0, 0, 0, 0, 0, 63, 64, 65, 66, 67,
995 68, 69, 70, 71, 0, 0, 72, 73, 74, 75,
996 76, 77, 78, 79, 80, 81, 82, 83, 0, 84,
997 85, 86, 61, 62, 0, 0, 0, 0, 0, 0,
998 0, 0, 0, 0, -119, 64, 65, 66, 67, 68,
999 69, 70, 71, 0, 0, 72, 73, 74, 75, 76,
1000 77, 78, 79, 80, 81, 82, 83, 0, 84, 85,
1001 86, 61, 62, 0, 0, 0, 0, 0, 0, 0,
1002 0, 0, 0, 0, 64, 65, 66, 67, 68, 69,
1003 70, 71, 0, 0, 72, 73, 74, 75, 76, 77,
1004 78, 79, 80, 81, 82, 83, 62, 84, 85, 86,
1005 0, 0, 0, 0, 0, 0, 0, 0, 0, 65,
1006 66, 67, 68, 69, 70, 71, 0, 0, 0, 73,
1007 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
1008 62, 84, 85, 86, 0, 0, 0, 0, 0, 0,
1009 0, 0, 0, 0, 66, 67, 68, 69, 70, 71,
1010 0, 0, 0, 73, 74, 75, 76, 77, 78, 79,
1011 80, 81, 82, 83, 62, 84, 85, 86, 0, 0,
1012 0, 0, 0, 0, 0, 0, 0, 0, -119, -119,
1013 -119, -119, 70, 71, 62, 0, 0, -119, -119, 75,
1014 76, 77, 78, 79, 80, 81, 82, 83, 0, 84,
1015 85, 86, 70, 71, 62, 0, 0, 0, 0, 0,
1016 76, 77, 78, 79, 80, 81, 82, 83, 0, 84,
1017 85, 86, 70, 71, 62, 0, 0, 0, 0, 0,
1018 0, 77, 78, 79, 80, 81, 82, 83, 0, 84,
1019 85, 86, 70, 71, 0, 0, 0, 0, 0, 0,
1020 0, 0, 78, 79, 80, 81, 82, 83, 0, 84,
1021 85, 86
1022 };
1023
1024 static const yytype_int16 yycheck[] =
1025 {
1026 0, 12, 62, 153, 19, 55, 56, 62, 11, 4,
1027 4, 14, 32, 13, 4, 15, 16, 17, 18, 19,
1028 20, 21, 50, 31, 174, 31, 16, 55, 36, 23,
1029 36, 4, 105, 18, 107, 20, 47, 48, 49, 54,
1030 35, 44, 50, 16, 50, 4, 46, 49, 108, 49,
1031 110, 111, 50, 108, 54, 110, 0, 55, 16, 12,
1032 52, 61, 32, 63, 64, 65, 66, 67, 68, 69,
1033 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
1034 80, 81, 82, 83, 84, 32, 89, 160, 41, 42,
1035 43, 44, 45, 153, 47, 48, 49, 97, 98, 172,
1036 4, 5, 162, 7, 164, 32, 166, 167, 35, 164,
1037 32, 166, 167, 4, 174, 47, 48, 49, 6, 7,
1038 49, 51, 3, 4, 50, 6, 7, 8, 9, 10,
1039 32, 54, 192, 14, 15, 16, 17, 192, 19, 53,
1040 51, 22, 23, 56, 51, 50, 4, 33, 208, 149,
1041 51, 32, 55, 208, 207, 155, 55, 100, 39, -1,
1042 41, 42, 43, 112, -1, 162, 47, -1, 49, -1,
1043 -1, -1, -1, -1, 12, -1, 57, -1, 178, 3,
1044 4, -1, 6, 7, 8, 9, 10, -1, -1, -1,
1045 14, 15, -1, 17, 18, 19, -1, -1, 22, 23,
1046 -1, -1, 40, 41, 42, 43, 44, 45, 32, 47,
1047 48, 49, -1, 4, -1, 39, -1, 41, 42, 43,
1048 -1, -1, -1, 47, -1, 49, 17, -1, 19, -1,
1049 21, 3, 4, 57, 6, 7, 8, 9, 10, -1,
1050 -1, 32, 14, 15, -1, 17, 18, 19, 39, -1,
1051 22, 23, 43, -1, -1, -1, 47, -1, 49, -1,
1052 32, -1, -1, -1, -1, 4, -1, 39, -1, 41,
1053 42, 43, -1, -1, -1, 47, -1, 49, 17, -1,
1054 19, -1, 21, 3, 4, 57, 6, 7, 8, 9,
1055 10, -1, -1, 32, 14, 15, -1, 17, -1, 19,
1056 39, -1, 22, 23, 43, -1, -1, -1, 47, -1,
1057 49, -1, 32, -1, -1, -1, -1, -1, -1, 39,
1058 -1, 41, 42, 43, -1, 12, -1, 47, -1, 49,
1059 -1, 51, -1, -1, -1, 3, 4, 57, 6, 7,
1060 8, 9, 10, -1, -1, -1, 14, 15, 16, 17,
1061 -1, 19, -1, -1, 22, 23, 43, 44, 45, -1,
1062 47, 48, 49, -1, 32, -1, -1, -1, -1, -1,
1063 -1, 39, -1, 41, 42, 43, -1, -1, -1, 47,
1064 -1, 49, -1, -1, -1, -1, -1, 3, 4, 57,
1065 6, 7, 8, 9, 10, -1, -1, -1, 14, 15,
1066 4, 17, -1, 19, -1, -1, 22, 23, -1, -1,
1067 -1, -1, -1, 17, -1, 19, 32, 21, -1, -1,
1068 -1, -1, -1, 39, -1, 41, 42, 43, 32, -1,
1069 -1, 47, -1, 49, -1, 39, 11, 12, -1, 43,
1070 -1, 57, -1, 47, -1, 49, -1, 51, 23, 24,
1071 25, 26, 27, 28, 29, 30, 31, -1, -1, 34,
1072 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
1073 45, -1, 47, 48, 49, 11, 12, -1, -1, -1,
1074 -1, 56, -1, -1, -1, -1, -1, 23, 24, 25,
1075 26, 27, 28, 29, 30, 31, -1, -1, 34, 35,
1076 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
1077 -1, 47, 48, 49, 11, 12, -1, -1, -1, -1,
1078 56, -1, -1, -1, -1, -1, 23, 24, 25, 26,
1079 27, 28, 29, 30, 31, -1, -1, 34, 35, 36,
1080 37, 38, 39, 40, 41, 42, 43, 44, 45, -1,
1081 47, 48, 49, 11, 12, -1, -1, -1, 55, -1,
1082 -1, -1, -1, -1, -1, 23, 24, 25, 26, 27,
1083 28, 29, 30, 31, -1, -1, 34, 35, 36, 37,
1084 38, 39, 40, 41, 42, 43, 44, 45, -1, 47,
1085 48, 49, 11, 12, -1, -1, -1, 55, -1, -1,
1086 -1, -1, -1, -1, 23, 24, 25, 26, 27, 28,
1087 29, 30, 31, -1, -1, 34, 35, 36, 37, 38,
1088 39, 40, 41, 42, 43, 44, 45, -1, 47, 48,
1089 49, 11, 12, -1, -1, -1, 55, -1, -1, -1,
1090 -1, -1, -1, 23, 24, 25, 26, 27, 28, 29,
1091 30, 31, -1, -1, 34, 35, 36, 37, 38, 39,
1092 40, 41, 42, 43, 44, 45, -1, 47, 48, 49,
1093 50, 51, 11, 12, -1, -1, -1, -1, -1, -1,
1094 -1, -1, -1, -1, 23, 24, 25, 26, 27, 28,
1095 29, 30, 31, -1, -1, 34, 35, 36, 37, 38,
1096 39, 40, 41, 42, 43, 44, 45, -1, 47, 48,
1097 49, -1, 51, 11, 12, -1, -1, -1, -1, -1,
1098 -1, -1, -1, -1, -1, 23, 24, 25, 26, 27,
1099 28, 29, 30, 31, -1, -1, 34, 35, 36, 37,
1100 38, 39, 40, 41, 42, 43, 44, 45, -1, 47,
1101 48, 49, 50, 11, 12, -1, -1, -1, -1, -1,
1102 -1, -1, -1, -1, -1, 23, 24, 25, 26, 27,
1103 28, 29, 30, 31, -1, -1, 34, 35, 36, 37,
1104 38, 39, 40, 41, 42, 43, 44, 45, -1, 47,
1105 48, 49, 11, 12, -1, -1, -1, -1, -1, -1,
1106 -1, -1, -1, -1, 23, 24, 25, 26, 27, 28,
1107 29, 30, 31, -1, -1, 34, 35, 36, 37, 38,
1108 39, 40, 41, 42, 43, 44, 45, -1, 47, 48,
1109 49, 11, 12, -1, -1, -1, -1, -1, -1, -1,
1110 -1, -1, -1, -1, 24, 25, 26, 27, 28, 29,
1111 30, 31, -1, -1, 34, 35, 36, 37, 38, 39,
1112 40, 41, 42, 43, 44, 45, 12, 47, 48, 49,
1113 -1, -1, -1, -1, -1, -1, -1, -1, -1, 25,
1114 26, 27, 28, 29, 30, 31, -1, -1, -1, 35,
1115 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
1116 12, 47, 48, 49, -1, -1, -1, -1, -1, -1,
1117 -1, -1, -1, -1, 26, 27, 28, 29, 30, 31,
1118 -1, -1, -1, 35, 36, 37, 38, 39, 40, 41,
1119 42, 43, 44, 45, 12, 47, 48, 49, -1, -1,
1120 -1, -1, -1, -1, -1, -1, -1, -1, 26, 27,
1121 28, 29, 30, 31, 12, -1, -1, 35, 36, 37,
1122 38, 39, 40, 41, 42, 43, 44, 45, -1, 47,
1123 48, 49, 30, 31, 12, -1, -1, -1, -1, -1,
1124 38, 39, 40, 41, 42, 43, 44, 45, -1, 47,
1125 48, 49, 30, 31, 12, -1, -1, -1, -1, -1,
1126 -1, 39, 40, 41, 42, 43, 44, 45, -1, 47,
1127 48, 49, 30, 31, -1, -1, -1, -1, -1, -1,
1128 -1, -1, 40, 41, 42, 43, 44, 45, -1, 47,
1129 48, 49
1130 };
1131
1132 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1133 symbol of state STATE-NUM. */
1134 static const yytype_uint8 yystos[] =
1135 {
1136 0, 3, 4, 6, 7, 8, 9, 10, 14, 15,
1137 17, 19, 22, 23, 32, 39, 41, 42, 43, 47,
1138 49, 57, 59, 60, 61, 62, 63, 66, 67, 68,
1139 69, 70, 71, 72, 73, 74, 75, 76, 77, 81,
1140 82, 84, 85, 86, 32, 86, 49, 60, 86, 18,
1141 60, 60, 60, 60, 18, 60, 78, 51, 60, 60,
1142 0, 11, 12, 23, 24, 25, 26, 27, 28, 29,
1143 30, 31, 34, 35, 36, 37, 38, 39, 40, 41,
1144 42, 43, 44, 45, 47, 48, 49, 80, 16, 83,
1145 52, 32, 86, 60, 60, 60, 78, 56, 50, 55,
1146 50, 51, 60, 4, 17, 19, 21, 32, 39, 43,
1147 47, 49, 82, 87, 88, 89, 90, 60, 60, 60,
1148 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
1149 60, 60, 60, 60, 60, 60, 60, 60, 60, 4,
1150 5, 7, 60, 78, 79, 32, 16, 86, 4, 23,
1151 64, 65, 4, 35, 51, 56, 55, 60, 60, 79,
1152 32, 89, 49, 89, 47, 90, 18, 20, 90, 90,
1153 91, 92, 83, 32, 35, 55, 51, 32, 54, 60,
1154 53, 92, 60, 55, 51, 89, 91, 90, 90, 90,
1155 56, 51, 50, 89, 4, 92, 60, 31, 36, 55,
1156 51, 55, 6, 7, 90, 31, 36, 50, 33, 55,
1157 55, 65, 90
1158 };
1159
1160 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1161 static const yytype_uint8 yyr1[] =
1162 {
1163 0, 58, 59, 60, 60, 60, 60, 60, 60, 60,
1164 60, 60, 60, 60, 60, 60, 61, 62, 63, 64,
1165 64, 65, 65, 65, 66, 66, 66, 66, 67, 67,
1166 67, 67, 68, 68, 68, 68, 68, 68, 68, 69,
1167 69, 69, 70, 71, 71, 71, 71, 71, 71, 71,
1168 72, 72, 72, 72, 73, 73, 73, 73, 73, 73,
1169 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
1170 73, 73, 73, 74, 75, 76, 77, 78, 78, 79,
1171 79, 80, 81, 82, 82, 83, 83, 84, 84, 84,
1172 85, 85, 85, 85, 85, 86, 86, 86, 86, 87,
1173 87, 87, 87, 87, 88, 88, 89, 89, 89, 90,
1174 90, 90, 90, 90, 90, 90, 90, 90, 91, 91,
1175 92, 92
1176 };
1177
1178 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
1179 static const yytype_uint8 yyr2[] =
1180 {
1181 0, 2, 1, 1, 1, 1, 1, 1, 1, 1,
1182 1, 1, 1, 1, 1, 1, 5, 2, 4, 2,
1183 3, 0, 1, 5, 4, 3, 6, 5, 2, 3,
1184 2, 1, 1, 1, 1, 1, 1, 1, 1, 3,
1185 3, 3, 4, 2, 2, 2, 2, 2, 3, 4,
1186 1, 1, 1, 1, 3, 3, 3, 3, 3, 3,
1187 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1188 3, 3, 3, 3, 3, 3, 3, 1, 3, 0,
1189 1, 3, 2, 0, 2, 2, 3, 1, 1, 1,
1190 1, 3, 3, 2, 2, 1, 3, 5, 5, 1,
1191 3, 3, 2, 2, 1, 3, 1, 4, 4, 1,
1192 5, 5, 4, 2, 3, 3, 6, 3, 0, 1,
1193 1, 3
1194 };
1195
1196
1197 #define yyerrok (yyerrstatus = 0)
1198 #define yyclearin (yychar = YYEMPTY)
1199 #define YYEMPTY (-2)
1200 #define YYEOF 0
1201
1202 #define YYACCEPT goto yyacceptlab
1203 #define YYABORT goto yyabortlab
1204 #define YYERROR goto yyerrorlab
1205
1206
1207 #define YYRECOVERING() (!!yyerrstatus)
1208
1209 #define YYBACKUP(Token, Value) \
1210 do \
1211 if (yychar == YYEMPTY) \
1212 { \
1213 yychar = (Token); \
1214 yylval = (Value); \
1215 YYPOPSTACK (yylen); \
1216 yystate = *yyssp; \
1217 goto yybackup; \
1218 } \
1219 else \
1220 { \
1221 yyerror (YY_("syntax error: cannot back up")); \
1222 YYERROR; \
1223 } \
1224 while (0)
1225
1226 /* Error token number */
1227 #define YYTERROR 1
1228 #define YYERRCODE 256
1229
1230
1231
1232 /* Enable debugging if requested. */
1233 #if YYDEBUG
1234
1235 # ifndef YYFPRINTF
1236 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1237 # define YYFPRINTF fprintf
1238 # endif
1239
1240 # define YYDPRINTF(Args) \
1241 do { \
1242 if (yydebug) \
1243 YYFPRINTF Args; \
1244 } while (0)
1245
1246 /* This macro is provided for backward compatibility. */
1247 #ifndef YY_LOCATION_PRINT
1248 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1249 #endif
1250
1251
1252 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1253 do { \
1254 if (yydebug) \
1255 { \
1256 YYFPRINTF (stderr, "%s ", Title); \
1257 yy_symbol_print (stderr, \
1258 Type, Value); \
1259 YYFPRINTF (stderr, "\n"); \
1260 } \
1261 } while (0)
1262
1263
1264 /*----------------------------------------.
1265 | Print this symbol's value on YYOUTPUT. |
1266 `----------------------------------------*/
1267
1268 static void
1269 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1270 {
1271 FILE *yyo = yyoutput;
1272 YYUSE (yyo);
1273 if (!yyvaluep)
1274 return;
1275 # ifdef YYPRINT
1276 if (yytype < YYNTOKENS)
1277 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1278 # endif
1279 YYUSE (yytype);
1280 }
1281
1282
1283 /*--------------------------------.
1284 | Print this symbol on YYOUTPUT. |
1285 `--------------------------------*/
1286
1287 static void
1288 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1289 {
1290 YYFPRINTF (yyoutput, "%s %s (",
1291 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1292
1293 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1294 YYFPRINTF (yyoutput, ")");
1295 }
1296
1297 /*------------------------------------------------------------------.
1298 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1299 | TOP (included). |
1300 `------------------------------------------------------------------*/
1301
1302 static void
1303 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1304 {
1305 YYFPRINTF (stderr, "Stack now");
1306 for (; yybottom <= yytop; yybottom++)
1307 {
1308 int yybot = *yybottom;
1309 YYFPRINTF (stderr, " %d", yybot);
1310 }
1311 YYFPRINTF (stderr, "\n");
1312 }
1313
1314 # define YY_STACK_PRINT(Bottom, Top) \
1315 do { \
1316 if (yydebug) \
1317 yy_stack_print ((Bottom), (Top)); \
1318 } while (0)
1319
1320
1321 /*------------------------------------------------.
1322 | Report that the YYRULE is going to be reduced. |
1323 `------------------------------------------------*/
1324
1325 static void
1326 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
1327 {
1328 unsigned long int yylno = yyrline[yyrule];
1329 int yynrhs = yyr2[yyrule];
1330 int yyi;
1331 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1332 yyrule - 1, yylno);
1333 /* The symbols being reduced. */
1334 for (yyi = 0; yyi < yynrhs; yyi++)
1335 {
1336 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1337 yy_symbol_print (stderr,
1338 yystos[yyssp[yyi + 1 - yynrhs]],
1339 &(yyvsp[(yyi + 1) - (yynrhs)])
1340 );
1341 YYFPRINTF (stderr, "\n");
1342 }
1343 }
1344
1345 # define YY_REDUCE_PRINT(Rule) \
1346 do { \
1347 if (yydebug) \
1348 yy_reduce_print (yyssp, yyvsp, Rule); \
1349 } while (0)
1350
1351 /* Nonzero means print parse trace. It is left uninitialized so that
1352 multiple parsers can coexist. */
1353 int yydebug;
1354 #else /* !YYDEBUG */
1355 # define YYDPRINTF(Args)
1356 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1357 # define YY_STACK_PRINT(Bottom, Top)
1358 # define YY_REDUCE_PRINT(Rule)
1359 #endif /* !YYDEBUG */
1360
1361
1362 /* YYINITDEPTH -- initial size of the parser's stacks. */
1363 #ifndef YYINITDEPTH
1364 # define YYINITDEPTH 200
1365 #endif
1366
1367 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1368 if the built-in stack extension method is used).
1369
1370 Do not make this value too large; the results are undefined if
1371 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1372 evaluated with infinite-precision integer arithmetic. */
1373
1374 #ifndef YYMAXDEPTH
1375 # define YYMAXDEPTH 10000
1376 #endif
1377
1378
1379 #if YYERROR_VERBOSE
1380
1381 # ifndef yystrlen
1382 # if defined __GLIBC__ && defined _STRING_H
1383 # define yystrlen strlen
1384 # else
1385 /* Return the length of YYSTR. */
1386 static YYSIZE_T
1387 yystrlen (const char *yystr)
1388 {
1389 YYSIZE_T yylen;
1390 for (yylen = 0; yystr[yylen]; yylen++)
1391 continue;
1392 return yylen;
1393 }
1394 # endif
1395 # endif
1396
1397 # ifndef yystpcpy
1398 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1399 # define yystpcpy stpcpy
1400 # else
1401 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1402 YYDEST. */
1403 static char *
1404 yystpcpy (char *yydest, const char *yysrc)
1405 {
1406 char *yyd = yydest;
1407 const char *yys = yysrc;
1408
1409 while ((*yyd++ = *yys++) != '\0')
1410 continue;
1411
1412 return yyd - 1;
1413 }
1414 # endif
1415 # endif
1416
1417 # ifndef yytnamerr
1418 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1419 quotes and backslashes, so that it's suitable for yyerror. The
1420 heuristic is that double-quoting is unnecessary unless the string
1421 contains an apostrophe, a comma, or backslash (other than
1422 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1423 null, do not copy; instead, return the length of what the result
1424 would have been. */
1425 static YYSIZE_T
1426 yytnamerr (char *yyres, const char *yystr)
1427 {
1428 if (*yystr == '"')
1429 {
1430 YYSIZE_T yyn = 0;
1431 char const *yyp = yystr;
1432
1433 for (;;)
1434 switch (*++yyp)
1435 {
1436 case '\'':
1437 case ',':
1438 goto do_not_strip_quotes;
1439
1440 case '\\':
1441 if (*++yyp != '\\')
1442 goto do_not_strip_quotes;
1443 /* Fall through. */
1444 default:
1445 if (yyres)
1446 yyres[yyn] = *yyp;
1447 yyn++;
1448 break;
1449
1450 case '"':
1451 if (yyres)
1452 yyres[yyn] = '\0';
1453 return yyn;
1454 }
1455 do_not_strip_quotes: ;
1456 }
1457
1458 if (! yyres)
1459 return yystrlen (yystr);
1460
1461 return yystpcpy (yyres, yystr) - yyres;
1462 }
1463 # endif
1464
1465 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1466 about the unexpected token YYTOKEN for the state stack whose top is
1467 YYSSP.
1468
1469 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1470 not large enough to hold the message. In that case, also set
1471 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1472 required number of bytes is too large to store. */
1473 static int
1474 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1475 yytype_int16 *yyssp, int yytoken)
1476 {
1477 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTRPTR, yytname[yytoken]);
1478 YYSIZE_T yysize = yysize0;
1479 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1480 /* Internationalized format string. */
1481 const char *yyformat = YY_NULLPTRPTR;
1482 /* Arguments of yyformat. */
1483 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1484 /* Number of reported tokens (one for the "unexpected", one per
1485 "expected"). */
1486 int yycount = 0;
1487
1488 /* There are many possibilities here to consider:
1489 - If this state is a consistent state with a default action, then
1490 the only way this function was invoked is if the default action
1491 is an error action. In that case, don't check for expected
1492 tokens because there are none.
1493 - The only way there can be no lookahead present (in yychar) is if
1494 this state is a consistent state with a default action. Thus,
1495 detecting the absence of a lookahead is sufficient to determine
1496 that there is no unexpected or expected token to report. In that
1497 case, just report a simple "syntax error".
1498 - Don't assume there isn't a lookahead just because this state is a
1499 consistent state with a default action. There might have been a
1500 previous inconsistent state, consistent state with a non-default
1501 action, or user semantic action that manipulated yychar.
1502 - Of course, the expected token list depends on states to have
1503 correct lookahead information, and it depends on the parser not
1504 to perform extra reductions after fetching a lookahead from the
1505 scanner and before detecting a syntax error. Thus, state merging
1506 (from LALR or IELR) and default reductions corrupt the expected
1507 token list. However, the list is correct for canonical LR with
1508 one exception: it will still contain any token that will not be
1509 accepted due to an error action in a later state.
1510 */
1511 if (yytoken != YYEMPTY)
1512 {
1513 int yyn = yypact[*yyssp];
1514 yyarg[yycount++] = yytname[yytoken];
1515 if (!yypact_value_is_default (yyn))
1516 {
1517 /* Start YYX at -YYN if negative to avoid negative indexes in
1518 YYCHECK. In other words, skip the first -YYN actions for
1519 this state because they are default actions. */
1520 int yyxbegin = yyn < 0 ? -yyn : 0;
1521 /* Stay within bounds of both yycheck and yytname. */
1522 int yychecklim = YYLAST - yyn + 1;
1523 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1524 int yyx;
1525
1526 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1527 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1528 && !yytable_value_is_error (yytable[yyx + yyn]))
1529 {
1530 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1531 {
1532 yycount = 1;
1533 yysize = yysize0;
1534 break;
1535 }
1536 yyarg[yycount++] = yytname[yyx];
1537 {
1538 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTRPTR, yytname[yyx]);
1539 if (! (yysize <= yysize1
1540 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1541 return 2;
1542 yysize = yysize1;
1543 }
1544 }
1545 }
1546 }
1547
1548 switch (yycount)
1549 {
1550 # define YYCASE_(N, S) \
1551 case N: \
1552 yyformat = S; \
1553 break
1554 YYCASE_(0, YY_("syntax error"));
1555 YYCASE_(1, YY_("syntax error, unexpected %s"));
1556 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1557 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1558 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1559 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1560 # undef YYCASE_
1561 }
1562
1563 {
1564 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1565 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1566 return 2;
1567 yysize = yysize1;
1568 }
1569
1570 if (*yymsg_alloc < yysize)
1571 {
1572 *yymsg_alloc = 2 * yysize;
1573 if (! (yysize <= *yymsg_alloc
1574 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1575 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1576 return 1;
1577 }
1578
1579 /* Avoid sprintf, as that infringes on the user's name space.
1580 Don't have undefined behavior even if the translation
1581 produced a string with the wrong number of "%s"s. */
1582 {
1583 char *yyp = *yymsg;
1584 int yyi = 0;
1585 while ((*yyp = *yyformat) != '\0')
1586 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1587 {
1588 yyp += yytnamerr (yyp, yyarg[yyi++]);
1589 yyformat += 2;
1590 }
1591 else
1592 {
1593 yyp++;
1594 yyformat++;
1595 }
1596 }
1597 return 0;
1598 }
1599 #endif /* YYERROR_VERBOSE */
1600
1601 /*-----------------------------------------------.
1602 | Release the memory associated to this symbol. |
1603 `-----------------------------------------------*/
1604
1605 static void
1606 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1607 {
1608 YYUSE (yyvaluep);
1609 if (!yymsg)
1610 yymsg = "Deleting";
1611 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1612
1613 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1614 YYUSE (yytype);
1615 YY_IGNORE_MAYBE_UNINITIALIZED_END
1616 }
1617
1618
1619
1620
1621 /* The lookahead symbol. */
1622 int yychar;
1623
1624 /* The semantic value of the lookahead symbol. */
1625 YYSTYPE yylval;
1626 /* Number of syntax errors so far. */
1627 int yynerrs;
1628
1629
1630 /*----------.
1631 | yyparse. |
1632 `----------*/
1633
1634 int
1635 yyparse (void)
1636 {
1637 int yystate;
1638 /* Number of tokens to shift before error messages enabled. */
1639 int yyerrstatus;
1640
1641 /* The stacks and their tools:
1642 'yyss': related to states.
1643 'yyvs': related to semantic values.
1644
1645 Refer to the stacks through separate pointers, to allow yyoverflow
1646 to xreallocate them elsewhere. */
1647
1648 /* The state stack. */
1649 yytype_int16 yyssa[YYINITDEPTH];
1650 yytype_int16 *yyss;
1651 yytype_int16 *yyssp;
1652
1653 /* The semantic value stack. */
1654 YYSTYPE yyvsa[YYINITDEPTH];
1655 YYSTYPE *yyvs;
1656 YYSTYPE *yyvsp;
1657
1658 YYSIZE_T yystacksize;
1659
1660 int yyn;
1661 int yyresult;
1662 /* Lookahead token as an internal (translated) token number. */
1663 int yytoken = 0;
1664 /* The variables used to return semantic value and location from the
1665 action routines. */
1666 YYSTYPE yyval;
1667
1668 #if YYERROR_VERBOSE
1669 /* Buffer for error messages, and its allocated size. */
1670 char yymsgbuf[128];
1671 char *yymsg = yymsgbuf;
1672 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1673 #endif
1674
1675 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1676
1677 /* The number of symbols on the RHS of the reduced rule.
1678 Keep to zero when no symbol should be popped. */
1679 int yylen = 0;
1680
1681 yyssp = yyss = yyssa;
1682 yyvsp = yyvs = yyvsa;
1683 yystacksize = YYINITDEPTH;
1684
1685 YYDPRINTF ((stderr, "Starting parse\n"));
1686
1687 yystate = 0;
1688 yyerrstatus = 0;
1689 yynerrs = 0;
1690 yychar = YYEMPTY; /* Cause a token to be read. */
1691 goto yysetstate;
1692
1693 /*------------------------------------------------------------.
1694 | yynewstate -- Push a new state, which is found in yystate. |
1695 `------------------------------------------------------------*/
1696 yynewstate:
1697 /* In all cases, when you get here, the value and location stacks
1698 have just been pushed. So pushing a state here evens the stacks. */
1699 yyssp++;
1700
1701 yysetstate:
1702 *yyssp = yystate;
1703
1704 if (yyss + yystacksize - 1 <= yyssp)
1705 {
1706 /* Get the current used size of the three stacks, in elements. */
1707 YYSIZE_T yysize = yyssp - yyss + 1;
1708
1709 #ifdef yyoverflow
1710 {
1711 /* Give user a chance to xreallocate the stack. Use copies of
1712 these so that the &'s don't force the real ones into
1713 memory. */
1714 YYSTYPE *yyvs1 = yyvs;
1715 yytype_int16 *yyss1 = yyss;
1716
1717 /* Each stack pointer address is followed by the size of the
1718 data in use in that stack, in bytes. This used to be a
1719 conditional around just the two extra args, but that might
1720 be undefined if yyoverflow is a macro. */
1721 yyoverflow (YY_("memory exhausted"),
1722 &yyss1, yysize * sizeof (*yyssp),
1723 &yyvs1, yysize * sizeof (*yyvsp),
1724 &yystacksize);
1725
1726 yyss = yyss1;
1727 yyvs = yyvs1;
1728 }
1729 #else /* no yyoverflow */
1730 # ifndef YYSTACK_RELOCATE
1731 goto yyexhaustedlab;
1732 # else
1733 /* Extend the stack our own way. */
1734 if (YYMAXDEPTH <= yystacksize)
1735 goto yyexhaustedlab;
1736 yystacksize *= 2;
1737 if (YYMAXDEPTH < yystacksize)
1738 yystacksize = YYMAXDEPTH;
1739
1740 {
1741 yytype_int16 *yyss1 = yyss;
1742 union yyalloc *yyptr =
1743 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1744 if (! yyptr)
1745 goto yyexhaustedlab;
1746 YYSTACK_RELOCATE (yyss_alloc, yyss);
1747 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1748 # undef YYSTACK_RELOCATE
1749 if (yyss1 != yyssa)
1750 YYSTACK_FREE (yyss1);
1751 }
1752 # endif
1753 #endif /* no yyoverflow */
1754
1755 yyssp = yyss + yysize - 1;
1756 yyvsp = yyvs + yysize - 1;
1757
1758 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1759 (unsigned long int) yystacksize));
1760
1761 if (yyss + yystacksize - 1 <= yyssp)
1762 YYABORT;
1763 }
1764
1765 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1766
1767 if (yystate == YYFINAL)
1768 YYACCEPT;
1769
1770 goto yybackup;
1771
1772 /*-----------.
1773 | yybackup. |
1774 `-----------*/
1775 yybackup:
1776
1777 /* Do appropriate processing given the current state. Read a
1778 lookahead token if we need one and don't already have one. */
1779
1780 /* First try to decide what to do without reference to lookahead token. */
1781 yyn = yypact[yystate];
1782 if (yypact_value_is_default (yyn))
1783 goto yydefault;
1784
1785 /* Not known => get a lookahead token if don't already have one. */
1786
1787 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1788 if (yychar == YYEMPTY)
1789 {
1790 YYDPRINTF ((stderr, "Reading a token: "));
1791 yychar = yylex ();
1792 }
1793
1794 if (yychar <= YYEOF)
1795 {
1796 yychar = yytoken = YYEOF;
1797 YYDPRINTF ((stderr, "Now at end of input.\n"));
1798 }
1799 else
1800 {
1801 yytoken = YYTRANSLATE (yychar);
1802 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1803 }
1804
1805 /* If the proper action on seeing token YYTOKEN is to reduce or to
1806 detect an error, take that action. */
1807 yyn += yytoken;
1808 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1809 goto yydefault;
1810 yyn = yytable[yyn];
1811 if (yyn <= 0)
1812 {
1813 if (yytable_value_is_error (yyn))
1814 goto yyerrlab;
1815 yyn = -yyn;
1816 goto yyreduce;
1817 }
1818
1819 /* Count tokens shifted since error; after three, turn off error
1820 status. */
1821 if (yyerrstatus)
1822 yyerrstatus--;
1823
1824 /* Shift the lookahead token. */
1825 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1826
1827 /* Discard the shifted token. */
1828 yychar = YYEMPTY;
1829
1830 yystate = yyn;
1831 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1832 *++yyvsp = yylval;
1833 YY_IGNORE_MAYBE_UNINITIALIZED_END
1834
1835 goto yynewstate;
1836
1837
1838 /*-----------------------------------------------------------.
1839 | yydefault -- do the default action for the current state. |
1840 `-----------------------------------------------------------*/
1841 yydefault:
1842 yyn = yydefact[yystate];
1843 if (yyn == 0)
1844 goto yyerrlab;
1845 goto yyreduce;
1846
1847
1848 /*-----------------------------.
1849 | yyreduce -- Do a reduction. |
1850 `-----------------------------*/
1851 yyreduce:
1852 /* yyn is the number of a rule to reduce with. */
1853 yylen = yyr2[yyn];
1854
1855 /* If YYLEN is nonzero, implement the default value of the action:
1856 '$$ = $1'.
1857
1858 Otherwise, the following line sets YYVAL to garbage.
1859 This behavior is undocumented and Bison
1860 users should not rely upon it. Assigning to YYVAL
1861 unconditionally makes the parser a bit smaller, and it avoids a
1862 GCC warning that YYVAL may be used uninitialized. */
1863 yyval = yyvsp[1-yylen];
1864
1865
1866 YY_REDUCE_PRINT (yyn);
1867 switch (yyn)
1868 {
1869 case 2:
1870 #line 407 "rust-exp.y" /* yacc.c:1646 */
1871 {
1872 /* If we are completing and see a valid parse,
1873 rust_ast will already have been set. */
1874 if (current_parser->rust_ast == NULL)
1875 current_parser->rust_ast = (yyvsp[0].op);
1876 }
1877 #line 1879 "rust-exp.c" /* yacc.c:1646 */
1878 break;
1879
1880 case 16:
1881 #line 436 "rust-exp.y" /* yacc.c:1646 */
1882 {
1883 (yyvsp[-1].params)->push_back ((yyvsp[-3].op));
1884 error (_("Tuple expressions not supported yet"));
1885 }
1886 #line 1888 "rust-exp.c" /* yacc.c:1646 */
1887 break;
1888
1889 case 17:
1890 #line 444 "rust-exp.y" /* yacc.c:1646 */
1891 {
1892 struct typed_val_int val;
1893
1894 val.type
1895 = language_lookup_primitive_type (current_parser->language (),
1896 current_parser->arch (),
1897 "()");
1898 val.val = 0;
1899 (yyval.op) = ast_literal (val);
1900 }
1901 #line 1903 "rust-exp.c" /* yacc.c:1646 */
1902 break;
1903
1904 case 18:
1905 #line 461 "rust-exp.y" /* yacc.c:1646 */
1906 { (yyval.op) = ast_struct ((yyvsp[-3].op), (yyvsp[-1].field_inits)); }
1907 #line 1909 "rust-exp.c" /* yacc.c:1646 */
1908 break;
1909
1910 case 19:
1911 #line 466 "rust-exp.y" /* yacc.c:1646 */
1912 {
1913 struct set_field sf;
1914
1915 sf.name.ptr = NULL;
1916 sf.name.length = 0;
1917 sf.init = (yyvsp[0].op);
1918
1919 (yyval.one_field_init) = sf;
1920 }
1921 #line 1923 "rust-exp.c" /* yacc.c:1646 */
1922 break;
1923
1924 case 20:
1925 #line 476 "rust-exp.y" /* yacc.c:1646 */
1926 {
1927 struct set_field sf;
1928
1929 sf.name = (yyvsp[-2].sval);
1930 sf.init = (yyvsp[0].op);
1931 (yyval.one_field_init) = sf;
1932 }
1933 #line 1935 "rust-exp.c" /* yacc.c:1646 */
1934 break;
1935
1936 case 21:
1937 #line 487 "rust-exp.y" /* yacc.c:1646 */
1938 {
1939 (yyval.field_inits) = current_parser->new_set_vector ();
1940 }
1941 #line 1943 "rust-exp.c" /* yacc.c:1646 */
1942 break;
1943
1944 case 22:
1945 #line 491 "rust-exp.y" /* yacc.c:1646 */
1946 {
1947 rust_set_vector *result = current_parser->new_set_vector ();
1948 result->push_back ((yyvsp[0].one_field_init));
1949 (yyval.field_inits) = result;
1950 }
1951 #line 1953 "rust-exp.c" /* yacc.c:1646 */
1952 break;
1953
1954 case 23:
1955 #line 497 "rust-exp.y" /* yacc.c:1646 */
1956 {
1957 struct set_field sf;
1958
1959 sf.name = (yyvsp[-4].sval);
1960 sf.init = (yyvsp[-2].op);
1961 (yyvsp[0].field_inits)->push_back (sf);
1962 (yyval.field_inits) = (yyvsp[0].field_inits);
1963 }
1964 #line 1966 "rust-exp.c" /* yacc.c:1646 */
1965 break;
1966
1967 case 24:
1968 #line 509 "rust-exp.y" /* yacc.c:1646 */
1969 { (yyval.op) = ast_call_ish (OP_ARRAY, NULL, (yyvsp[-1].params)); }
1970 #line 1972 "rust-exp.c" /* yacc.c:1646 */
1971 break;
1972
1973 case 25:
1974 #line 511 "rust-exp.y" /* yacc.c:1646 */
1975 { (yyval.op) = ast_call_ish (OP_ARRAY, NULL, (yyvsp[-1].params)); }
1976 #line 1978 "rust-exp.c" /* yacc.c:1646 */
1977 break;
1978
1979 case 26:
1980 #line 513 "rust-exp.y" /* yacc.c:1646 */
1981 { (yyval.op) = ast_operation (OP_RUST_ARRAY, (yyvsp[-3].op), (yyvsp[-1].op)); }
1982 #line 1984 "rust-exp.c" /* yacc.c:1646 */
1983 break;
1984
1985 case 27:
1986 #line 515 "rust-exp.y" /* yacc.c:1646 */
1987 { (yyval.op) = ast_operation (OP_RUST_ARRAY, (yyvsp[-3].op), (yyvsp[-1].op)); }
1988 #line 1990 "rust-exp.c" /* yacc.c:1646 */
1989 break;
1990
1991 case 28:
1992 #line 520 "rust-exp.y" /* yacc.c:1646 */
1993 { (yyval.op) = ast_range ((yyvsp[-1].op), NULL); }
1994 #line 1996 "rust-exp.c" /* yacc.c:1646 */
1995 break;
1996
1997 case 29:
1998 #line 522 "rust-exp.y" /* yacc.c:1646 */
1999 { (yyval.op) = ast_range ((yyvsp[-2].op), (yyvsp[0].op)); }
2000 #line 2002 "rust-exp.c" /* yacc.c:1646 */
2001 break;
2002
2003 case 30:
2004 #line 524 "rust-exp.y" /* yacc.c:1646 */
2005 { (yyval.op) = ast_range (NULL, (yyvsp[0].op)); }
2006 #line 2008 "rust-exp.c" /* yacc.c:1646 */
2007 break;
2008
2009 case 31:
2010 #line 526 "rust-exp.y" /* yacc.c:1646 */
2011 { (yyval.op) = ast_range (NULL, NULL); }
2012 #line 2014 "rust-exp.c" /* yacc.c:1646 */
2013 break;
2014
2015 case 32:
2016 #line 531 "rust-exp.y" /* yacc.c:1646 */
2017 { (yyval.op) = ast_literal ((yyvsp[0].typed_val_int)); }
2018 #line 2020 "rust-exp.c" /* yacc.c:1646 */
2019 break;
2020
2021 case 33:
2022 #line 533 "rust-exp.y" /* yacc.c:1646 */
2023 { (yyval.op) = ast_literal ((yyvsp[0].typed_val_int)); }
2024 #line 2026 "rust-exp.c" /* yacc.c:1646 */
2025 break;
2026
2027 case 34:
2028 #line 535 "rust-exp.y" /* yacc.c:1646 */
2029 { (yyval.op) = ast_dliteral ((yyvsp[0].typed_val_float)); }
2030 #line 2032 "rust-exp.c" /* yacc.c:1646 */
2031 break;
2032
2033 case 35:
2034 #line 537 "rust-exp.y" /* yacc.c:1646 */
2035 {
2036 const struct rust_op *str = ast_string ((yyvsp[0].sval));
2037 struct set_field field;
2038 struct typed_val_int val;
2039 struct stoken token;
2040
2041 rust_set_vector *fields = current_parser->new_set_vector ();
2042
2043 /* Wrap the raw string in the &str struct. */
2044 field.name.ptr = "data_ptr";
2045 field.name.length = strlen (field.name.ptr);
2046 field.init = ast_unary (UNOP_ADDR, ast_string ((yyvsp[0].sval)));
2047 fields->push_back (field);
2048
2049 val.type = rust_type ("usize");
2050 val.val = (yyvsp[0].sval).length;
2051
2052 field.name.ptr = "length";
2053 field.name.length = strlen (field.name.ptr);
2054 field.init = ast_literal (val);
2055 fields->push_back (field);
2056
2057 token.ptr = "&str";
2058 token.length = strlen (token.ptr);
2059 (yyval.op) = ast_struct (ast_path (token, NULL), fields);
2060 }
2061 #line 2063 "rust-exp.c" /* yacc.c:1646 */
2062 break;
2063
2064 case 36:
2065 #line 564 "rust-exp.y" /* yacc.c:1646 */
2066 { (yyval.op) = ast_string ((yyvsp[0].sval)); }
2067 #line 2069 "rust-exp.c" /* yacc.c:1646 */
2068 break;
2069
2070 case 37:
2071 #line 566 "rust-exp.y" /* yacc.c:1646 */
2072 {
2073 struct typed_val_int val;
2074
2075 val.type = language_bool_type (current_parser->language (),
2076 current_parser->arch ());
2077 val.val = 1;
2078 (yyval.op) = ast_literal (val);
2079 }
2080 #line 2082 "rust-exp.c" /* yacc.c:1646 */
2081 break;
2082
2083 case 38:
2084 #line 575 "rust-exp.y" /* yacc.c:1646 */
2085 {
2086 struct typed_val_int val;
2087
2088 val.type = language_bool_type (current_parser->language (),
2089 current_parser->arch ());
2090 val.val = 0;
2091 (yyval.op) = ast_literal (val);
2092 }
2093 #line 2095 "rust-exp.c" /* yacc.c:1646 */
2094 break;
2095
2096 case 39:
2097 #line 587 "rust-exp.y" /* yacc.c:1646 */
2098 { (yyval.op) = ast_structop ((yyvsp[-2].op), (yyvsp[0].sval).ptr, 0); }
2099 #line 2101 "rust-exp.c" /* yacc.c:1646 */
2100 break;
2101
2102 case 40:
2103 #line 589 "rust-exp.y" /* yacc.c:1646 */
2104 {
2105 (yyval.op) = ast_structop ((yyvsp[-2].op), (yyvsp[0].sval).ptr, 1);
2106 current_parser->rust_ast = (yyval.op);
2107 }
2108 #line 2110 "rust-exp.c" /* yacc.c:1646 */
2109 break;
2110
2111 case 41:
2112 #line 594 "rust-exp.y" /* yacc.c:1646 */
2113 { (yyval.op) = ast_structop_anonymous ((yyvsp[-2].op), (yyvsp[0].typed_val_int)); }
2114 #line 2116 "rust-exp.c" /* yacc.c:1646 */
2115 break;
2116
2117 case 42:
2118 #line 599 "rust-exp.y" /* yacc.c:1646 */
2119 { (yyval.op) = ast_operation (BINOP_SUBSCRIPT, (yyvsp[-3].op), (yyvsp[-1].op)); }
2120 #line 2122 "rust-exp.c" /* yacc.c:1646 */
2121 break;
2122
2123 case 43:
2124 #line 604 "rust-exp.y" /* yacc.c:1646 */
2125 { (yyval.op) = ast_unary (UNOP_PLUS, (yyvsp[0].op)); }
2126 #line 2128 "rust-exp.c" /* yacc.c:1646 */
2127 break;
2128
2129 case 44:
2130 #line 607 "rust-exp.y" /* yacc.c:1646 */
2131 { (yyval.op) = ast_unary (UNOP_NEG, (yyvsp[0].op)); }
2132 #line 2134 "rust-exp.c" /* yacc.c:1646 */
2133 break;
2134
2135 case 45:
2136 #line 610 "rust-exp.y" /* yacc.c:1646 */
2137 {
2138 /* Note that we provide a Rust-specific evaluator
2139 override for UNOP_COMPLEMENT, so it can do the
2140 right thing for both bool and integral
2141 values. */
2142 (yyval.op) = ast_unary (UNOP_COMPLEMENT, (yyvsp[0].op));
2143 }
2144 #line 2146 "rust-exp.c" /* yacc.c:1646 */
2145 break;
2146
2147 case 46:
2148 #line 619 "rust-exp.y" /* yacc.c:1646 */
2149 { (yyval.op) = ast_unary (UNOP_IND, (yyvsp[0].op)); }
2150 #line 2152 "rust-exp.c" /* yacc.c:1646 */
2151 break;
2152
2153 case 47:
2154 #line 622 "rust-exp.y" /* yacc.c:1646 */
2155 { (yyval.op) = ast_unary (UNOP_ADDR, (yyvsp[0].op)); }
2156 #line 2158 "rust-exp.c" /* yacc.c:1646 */
2157 break;
2158
2159 case 48:
2160 #line 625 "rust-exp.y" /* yacc.c:1646 */
2161 { (yyval.op) = ast_unary (UNOP_ADDR, (yyvsp[0].op)); }
2162 #line 2164 "rust-exp.c" /* yacc.c:1646 */
2163 break;
2164
2165 case 49:
2166 #line 627 "rust-exp.y" /* yacc.c:1646 */
2167 { (yyval.op) = ast_unary (UNOP_SIZEOF, (yyvsp[-1].op)); }
2168 #line 2170 "rust-exp.c" /* yacc.c:1646 */
2169 break;
2170
2171 case 54:
2172 #line 639 "rust-exp.y" /* yacc.c:1646 */
2173 { (yyval.op) = ast_operation (BINOP_MUL, (yyvsp[-2].op), (yyvsp[0].op)); }
2174 #line 2176 "rust-exp.c" /* yacc.c:1646 */
2175 break;
2176
2177 case 55:
2178 #line 642 "rust-exp.y" /* yacc.c:1646 */
2179 { (yyval.op) = ast_operation (BINOP_REPEAT, (yyvsp[-2].op), (yyvsp[0].op)); }
2180 #line 2182 "rust-exp.c" /* yacc.c:1646 */
2181 break;
2182
2183 case 56:
2184 #line 645 "rust-exp.y" /* yacc.c:1646 */
2185 { (yyval.op) = ast_operation (BINOP_DIV, (yyvsp[-2].op), (yyvsp[0].op)); }
2186 #line 2188 "rust-exp.c" /* yacc.c:1646 */
2187 break;
2188
2189 case 57:
2190 #line 648 "rust-exp.y" /* yacc.c:1646 */
2191 { (yyval.op) = ast_operation (BINOP_REM, (yyvsp[-2].op), (yyvsp[0].op)); }
2192 #line 2194 "rust-exp.c" /* yacc.c:1646 */
2193 break;
2194
2195 case 58:
2196 #line 651 "rust-exp.y" /* yacc.c:1646 */
2197 { (yyval.op) = ast_operation (BINOP_LESS, (yyvsp[-2].op), (yyvsp[0].op)); }
2198 #line 2200 "rust-exp.c" /* yacc.c:1646 */
2199 break;
2200
2201 case 59:
2202 #line 654 "rust-exp.y" /* yacc.c:1646 */
2203 { (yyval.op) = ast_operation (BINOP_GTR, (yyvsp[-2].op), (yyvsp[0].op)); }
2204 #line 2206 "rust-exp.c" /* yacc.c:1646 */
2205 break;
2206
2207 case 60:
2208 #line 657 "rust-exp.y" /* yacc.c:1646 */
2209 { (yyval.op) = ast_operation (BINOP_BITWISE_AND, (yyvsp[-2].op), (yyvsp[0].op)); }
2210 #line 2212 "rust-exp.c" /* yacc.c:1646 */
2211 break;
2212
2213 case 61:
2214 #line 660 "rust-exp.y" /* yacc.c:1646 */
2215 { (yyval.op) = ast_operation (BINOP_BITWISE_IOR, (yyvsp[-2].op), (yyvsp[0].op)); }
2216 #line 2218 "rust-exp.c" /* yacc.c:1646 */
2217 break;
2218
2219 case 62:
2220 #line 663 "rust-exp.y" /* yacc.c:1646 */
2221 { (yyval.op) = ast_operation (BINOP_BITWISE_XOR, (yyvsp[-2].op), (yyvsp[0].op)); }
2222 #line 2224 "rust-exp.c" /* yacc.c:1646 */
2223 break;
2224
2225 case 63:
2226 #line 666 "rust-exp.y" /* yacc.c:1646 */
2227 { (yyval.op) = ast_operation (BINOP_ADD, (yyvsp[-2].op), (yyvsp[0].op)); }
2228 #line 2230 "rust-exp.c" /* yacc.c:1646 */
2229 break;
2230
2231 case 64:
2232 #line 669 "rust-exp.y" /* yacc.c:1646 */
2233 { (yyval.op) = ast_operation (BINOP_SUB, (yyvsp[-2].op), (yyvsp[0].op)); }
2234 #line 2236 "rust-exp.c" /* yacc.c:1646 */
2235 break;
2236
2237 case 65:
2238 #line 672 "rust-exp.y" /* yacc.c:1646 */
2239 { (yyval.op) = ast_operation (BINOP_LOGICAL_OR, (yyvsp[-2].op), (yyvsp[0].op)); }
2240 #line 2242 "rust-exp.c" /* yacc.c:1646 */
2241 break;
2242
2243 case 66:
2244 #line 675 "rust-exp.y" /* yacc.c:1646 */
2245 { (yyval.op) = ast_operation (BINOP_LOGICAL_AND, (yyvsp[-2].op), (yyvsp[0].op)); }
2246 #line 2248 "rust-exp.c" /* yacc.c:1646 */
2247 break;
2248
2249 case 67:
2250 #line 678 "rust-exp.y" /* yacc.c:1646 */
2251 { (yyval.op) = ast_operation (BINOP_EQUAL, (yyvsp[-2].op), (yyvsp[0].op)); }
2252 #line 2254 "rust-exp.c" /* yacc.c:1646 */
2253 break;
2254
2255 case 68:
2256 #line 681 "rust-exp.y" /* yacc.c:1646 */
2257 { (yyval.op) = ast_operation (BINOP_NOTEQUAL, (yyvsp[-2].op), (yyvsp[0].op)); }
2258 #line 2260 "rust-exp.c" /* yacc.c:1646 */
2259 break;
2260
2261 case 69:
2262 #line 684 "rust-exp.y" /* yacc.c:1646 */
2263 { (yyval.op) = ast_operation (BINOP_LEQ, (yyvsp[-2].op), (yyvsp[0].op)); }
2264 #line 2266 "rust-exp.c" /* yacc.c:1646 */
2265 break;
2266
2267 case 70:
2268 #line 687 "rust-exp.y" /* yacc.c:1646 */
2269 { (yyval.op) = ast_operation (BINOP_GEQ, (yyvsp[-2].op), (yyvsp[0].op)); }
2270 #line 2272 "rust-exp.c" /* yacc.c:1646 */
2271 break;
2272
2273 case 71:
2274 #line 690 "rust-exp.y" /* yacc.c:1646 */
2275 { (yyval.op) = ast_operation (BINOP_LSH, (yyvsp[-2].op), (yyvsp[0].op)); }
2276 #line 2278 "rust-exp.c" /* yacc.c:1646 */
2277 break;
2278
2279 case 72:
2280 #line 693 "rust-exp.y" /* yacc.c:1646 */
2281 { (yyval.op) = ast_operation (BINOP_RSH, (yyvsp[-2].op), (yyvsp[0].op)); }
2282 #line 2284 "rust-exp.c" /* yacc.c:1646 */
2283 break;
2284
2285 case 73:
2286 #line 698 "rust-exp.y" /* yacc.c:1646 */
2287 { (yyval.op) = ast_cast ((yyvsp[-2].op), (yyvsp[0].op)); }
2288 #line 2290 "rust-exp.c" /* yacc.c:1646 */
2289 break;
2290
2291 case 74:
2292 #line 703 "rust-exp.y" /* yacc.c:1646 */
2293 { (yyval.op) = ast_operation (BINOP_ASSIGN, (yyvsp[-2].op), (yyvsp[0].op)); }
2294 #line 2296 "rust-exp.c" /* yacc.c:1646 */
2295 break;
2296
2297 case 75:
2298 #line 708 "rust-exp.y" /* yacc.c:1646 */
2299 { (yyval.op) = ast_compound_assignment ((yyvsp[-1].opcode), (yyvsp[-2].op), (yyvsp[0].op)); }
2300 #line 2302 "rust-exp.c" /* yacc.c:1646 */
2301 break;
2302
2303 case 76:
2304 #line 714 "rust-exp.y" /* yacc.c:1646 */
2305 { (yyval.op) = (yyvsp[-1].op); }
2306 #line 2308 "rust-exp.c" /* yacc.c:1646 */
2307 break;
2308
2309 case 77:
2310 #line 719 "rust-exp.y" /* yacc.c:1646 */
2311 {
2312 (yyval.params) = current_parser->new_op_vector ();
2313 (yyval.params)->push_back ((yyvsp[0].op));
2314 }
2315 #line 2317 "rust-exp.c" /* yacc.c:1646 */
2316 break;
2317
2318 case 78:
2319 #line 724 "rust-exp.y" /* yacc.c:1646 */
2320 {
2321 (yyvsp[-2].params)->push_back ((yyvsp[0].op));
2322 (yyval.params) = (yyvsp[-2].params);
2323 }
2324 #line 2326 "rust-exp.c" /* yacc.c:1646 */
2325 break;
2326
2327 case 79:
2328 #line 732 "rust-exp.y" /* yacc.c:1646 */
2329 {
2330 /* The result can't be NULL. */
2331 (yyval.params) = current_parser->new_op_vector ();
2332 }
2333 #line 2335 "rust-exp.c" /* yacc.c:1646 */
2334 break;
2335
2336 case 80:
2337 #line 737 "rust-exp.y" /* yacc.c:1646 */
2338 { (yyval.params) = (yyvsp[0].params); }
2339 #line 2341 "rust-exp.c" /* yacc.c:1646 */
2340 break;
2341
2342 case 81:
2343 #line 744 "rust-exp.y" /* yacc.c:1646 */
2344 { (yyval.params) = (yyvsp[-1].params); }
2345 #line 2347 "rust-exp.c" /* yacc.c:1646 */
2346 break;
2347
2348 case 82:
2349 #line 749 "rust-exp.y" /* yacc.c:1646 */
2350 { (yyval.op) = ast_call_ish (OP_FUNCALL, (yyvsp[-1].op), (yyvsp[0].params)); }
2351 #line 2353 "rust-exp.c" /* yacc.c:1646 */
2352 break;
2353
2354 case 85:
2355 #line 759 "rust-exp.y" /* yacc.c:1646 */
2356 { (yyval.depth) = 1; }
2357 #line 2359 "rust-exp.c" /* yacc.c:1646 */
2358 break;
2359
2360 case 86:
2361 #line 761 "rust-exp.y" /* yacc.c:1646 */
2362 { (yyval.depth) = (yyvsp[-2].depth) + 1; }
2363 #line 2365 "rust-exp.c" /* yacc.c:1646 */
2364 break;
2365
2366 case 87:
2367 #line 766 "rust-exp.y" /* yacc.c:1646 */
2368 { (yyval.op) = (yyvsp[0].op); }
2369 #line 2371 "rust-exp.c" /* yacc.c:1646 */
2370 break;
2371
2372 case 88:
2373 #line 768 "rust-exp.y" /* yacc.c:1646 */
2374 { (yyval.op) = ast_path ((yyvsp[0].sval), NULL); }
2375 #line 2377 "rust-exp.c" /* yacc.c:1646 */
2376 break;
2377
2378 case 89:
2379 #line 770 "rust-exp.y" /* yacc.c:1646 */
2380 { (yyval.op) = ast_path (make_stoken ("self"), NULL); }
2381 #line 2383 "rust-exp.c" /* yacc.c:1646 */
2382 break;
2383
2384 case 91:
2385 #line 776 "rust-exp.y" /* yacc.c:1646 */
2386 { (yyval.op) = super_name ((yyvsp[0].op), 0); }
2387 #line 2389 "rust-exp.c" /* yacc.c:1646 */
2388 break;
2389
2390 case 92:
2391 #line 778 "rust-exp.y" /* yacc.c:1646 */
2392 { (yyval.op) = super_name ((yyvsp[0].op), (yyvsp[-1].depth)); }
2393 #line 2395 "rust-exp.c" /* yacc.c:1646 */
2394 break;
2395
2396 case 93:
2397 #line 780 "rust-exp.y" /* yacc.c:1646 */
2398 { (yyval.op) = crate_name ((yyvsp[0].op)); }
2399 #line 2401 "rust-exp.c" /* yacc.c:1646 */
2400 break;
2401
2402 case 94:
2403 #line 782 "rust-exp.y" /* yacc.c:1646 */
2404 {
2405 /* This is a gdb extension to make it possible to
2406 refer to items in other crates. It just bypasses
2407 adding the current crate to the front of the
2408 name. */
2409 (yyval.op) = ast_path (rust_concat3 ("::", (yyvsp[0].op)->left.sval.ptr, NULL),
2410 (yyvsp[0].op)->right.params);
2411 }
2412 #line 2414 "rust-exp.c" /* yacc.c:1646 */
2413 break;
2414
2415 case 95:
2416 #line 794 "rust-exp.y" /* yacc.c:1646 */
2417 { (yyval.op) = ast_path ((yyvsp[0].sval), NULL); }
2418 #line 2420 "rust-exp.c" /* yacc.c:1646 */
2419 break;
2420
2421 case 96:
2422 #line 796 "rust-exp.y" /* yacc.c:1646 */
2423 {
2424 (yyval.op) = ast_path (rust_concat3 ((yyvsp[-2].op)->left.sval.ptr, "::",
2425 (yyvsp[0].sval).ptr),
2426 NULL);
2427 }
2428 #line 2430 "rust-exp.c" /* yacc.c:1646 */
2429 break;
2430
2431 case 97:
2432 #line 802 "rust-exp.y" /* yacc.c:1646 */
2433 { (yyval.op) = ast_path ((yyvsp[-4].op)->left.sval, (yyvsp[-1].params)); }
2434 #line 2436 "rust-exp.c" /* yacc.c:1646 */
2435 break;
2436
2437 case 98:
2438 #line 804 "rust-exp.y" /* yacc.c:1646 */
2439 {
2440 (yyval.op) = ast_path ((yyvsp[-4].op)->left.sval, (yyvsp[-1].params));
2441 rust_push_back ('>');
2442 }
2443 #line 2445 "rust-exp.c" /* yacc.c:1646 */
2444 break;
2445
2446 case 100:
2447 #line 813 "rust-exp.y" /* yacc.c:1646 */
2448 { (yyval.op) = super_name ((yyvsp[0].op), 0); }
2449 #line 2451 "rust-exp.c" /* yacc.c:1646 */
2450 break;
2451
2452 case 101:
2453 #line 815 "rust-exp.y" /* yacc.c:1646 */
2454 { (yyval.op) = super_name ((yyvsp[0].op), (yyvsp[-1].depth)); }
2455 #line 2457 "rust-exp.c" /* yacc.c:1646 */
2456 break;
2457
2458 case 102:
2459 #line 817 "rust-exp.y" /* yacc.c:1646 */
2460 { (yyval.op) = crate_name ((yyvsp[0].op)); }
2461 #line 2463 "rust-exp.c" /* yacc.c:1646 */
2462 break;
2463
2464 case 103:
2465 #line 819 "rust-exp.y" /* yacc.c:1646 */
2466 {
2467 /* This is a gdb extension to make it possible to
2468 refer to items in other crates. It just bypasses
2469 adding the current crate to the front of the
2470 name. */
2471 (yyval.op) = ast_path (rust_concat3 ("::", (yyvsp[0].op)->left.sval.ptr, NULL),
2472 (yyvsp[0].op)->right.params);
2473 }
2474 #line 2476 "rust-exp.c" /* yacc.c:1646 */
2475 break;
2476
2477 case 104:
2478 #line 831 "rust-exp.y" /* yacc.c:1646 */
2479 { (yyval.op) = ast_path ((yyvsp[0].sval), NULL); }
2480 #line 2482 "rust-exp.c" /* yacc.c:1646 */
2481 break;
2482
2483 case 105:
2484 #line 833 "rust-exp.y" /* yacc.c:1646 */
2485 {
2486 (yyval.op) = ast_path (rust_concat3 ((yyvsp[-2].op)->left.sval.ptr, "::",
2487 (yyvsp[0].sval).ptr),
2488 NULL);
2489 }
2490 #line 2492 "rust-exp.c" /* yacc.c:1646 */
2491 break;
2492
2493 case 107:
2494 #line 843 "rust-exp.y" /* yacc.c:1646 */
2495 { (yyval.op) = ast_path ((yyvsp[-3].op)->left.sval, (yyvsp[-1].params)); }
2496 #line 2498 "rust-exp.c" /* yacc.c:1646 */
2497 break;
2498
2499 case 108:
2500 #line 845 "rust-exp.y" /* yacc.c:1646 */
2501 {
2502 (yyval.op) = ast_path ((yyvsp[-3].op)->left.sval, (yyvsp[-1].params));
2503 rust_push_back ('>');
2504 }
2505 #line 2507 "rust-exp.c" /* yacc.c:1646 */
2506 break;
2507
2508 case 110:
2509 #line 854 "rust-exp.y" /* yacc.c:1646 */
2510 { (yyval.op) = ast_array_type ((yyvsp[-3].op), (yyvsp[-1].typed_val_int)); }
2511 #line 2513 "rust-exp.c" /* yacc.c:1646 */
2512 break;
2513
2514 case 111:
2515 #line 856 "rust-exp.y" /* yacc.c:1646 */
2516 { (yyval.op) = ast_array_type ((yyvsp[-3].op), (yyvsp[-1].typed_val_int)); }
2517 #line 2519 "rust-exp.c" /* yacc.c:1646 */
2518 break;
2519
2520 case 112:
2521 #line 858 "rust-exp.y" /* yacc.c:1646 */
2522 { (yyval.op) = ast_slice_type ((yyvsp[-1].op)); }
2523 #line 2525 "rust-exp.c" /* yacc.c:1646 */
2524 break;
2525
2526 case 113:
2527 #line 860 "rust-exp.y" /* yacc.c:1646 */
2528 { (yyval.op) = ast_reference_type ((yyvsp[0].op)); }
2529 #line 2531 "rust-exp.c" /* yacc.c:1646 */
2530 break;
2531
2532 case 114:
2533 #line 862 "rust-exp.y" /* yacc.c:1646 */
2534 { (yyval.op) = ast_pointer_type ((yyvsp[0].op), 1); }
2535 #line 2537 "rust-exp.c" /* yacc.c:1646 */
2536 break;
2537
2538 case 115:
2539 #line 864 "rust-exp.y" /* yacc.c:1646 */
2540 { (yyval.op) = ast_pointer_type ((yyvsp[0].op), 0); }
2541 #line 2543 "rust-exp.c" /* yacc.c:1646 */
2542 break;
2543
2544 case 116:
2545 #line 866 "rust-exp.y" /* yacc.c:1646 */
2546 { (yyval.op) = ast_function_type ((yyvsp[0].op), (yyvsp[-3].params)); }
2547 #line 2549 "rust-exp.c" /* yacc.c:1646 */
2548 break;
2549
2550 case 117:
2551 #line 868 "rust-exp.y" /* yacc.c:1646 */
2552 { (yyval.op) = ast_tuple_type ((yyvsp[-1].params)); }
2553 #line 2555 "rust-exp.c" /* yacc.c:1646 */
2554 break;
2555
2556 case 118:
2557 #line 873 "rust-exp.y" /* yacc.c:1646 */
2558 { (yyval.params) = NULL; }
2559 #line 2561 "rust-exp.c" /* yacc.c:1646 */
2560 break;
2561
2562 case 119:
2563 #line 875 "rust-exp.y" /* yacc.c:1646 */
2564 { (yyval.params) = (yyvsp[0].params); }
2565 #line 2567 "rust-exp.c" /* yacc.c:1646 */
2566 break;
2567
2568 case 120:
2569 #line 880 "rust-exp.y" /* yacc.c:1646 */
2570 {
2571 rust_op_vector *result = current_parser->new_op_vector ();
2572 result->push_back ((yyvsp[0].op));
2573 (yyval.params) = result;
2574 }
2575 #line 2577 "rust-exp.c" /* yacc.c:1646 */
2576 break;
2577
2578 case 121:
2579 #line 886 "rust-exp.y" /* yacc.c:1646 */
2580 {
2581 (yyvsp[-2].params)->push_back ((yyvsp[0].op));
2582 (yyval.params) = (yyvsp[-2].params);
2583 }
2584 #line 2586 "rust-exp.c" /* yacc.c:1646 */
2585 break;
2586
2587
2588 #line 2590 "rust-exp.c" /* yacc.c:1646 */
2589 default: break;
2590 }
2591 /* User semantic actions sometimes alter yychar, and that requires
2592 that yytoken be updated with the new translation. We take the
2593 approach of translating immediately before every use of yytoken.
2594 One alternative is translating here after every semantic action,
2595 but that translation would be missed if the semantic action invokes
2596 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2597 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2598 incorrect destructor might then be invoked immediately. In the
2599 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2600 to an incorrect destructor call or verbose syntax error message
2601 before the lookahead is translated. */
2602 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2603
2604 YYPOPSTACK (yylen);
2605 yylen = 0;
2606 YY_STACK_PRINT (yyss, yyssp);
2607
2608 *++yyvsp = yyval;
2609
2610 /* Now 'shift' the result of the reduction. Determine what state
2611 that goes to, based on the state we popped back to and the rule
2612 number reduced by. */
2613
2614 yyn = yyr1[yyn];
2615
2616 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2617 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2618 yystate = yytable[yystate];
2619 else
2620 yystate = yydefgoto[yyn - YYNTOKENS];
2621
2622 goto yynewstate;
2623
2624
2625 /*--------------------------------------.
2626 | yyerrlab -- here on detecting error. |
2627 `--------------------------------------*/
2628 yyerrlab:
2629 /* Make sure we have latest lookahead translation. See comments at
2630 user semantic actions for why this is necessary. */
2631 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2632
2633 /* If not already recovering from an error, report this error. */
2634 if (!yyerrstatus)
2635 {
2636 ++yynerrs;
2637 #if ! YYERROR_VERBOSE
2638 yyerror (YY_("syntax error"));
2639 #else
2640 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2641 yyssp, yytoken)
2642 {
2643 char const *yymsgp = YY_("syntax error");
2644 int yysyntax_error_status;
2645 yysyntax_error_status = YYSYNTAX_ERROR;
2646 if (yysyntax_error_status == 0)
2647 yymsgp = yymsg;
2648 else if (yysyntax_error_status == 1)
2649 {
2650 if (yymsg != yymsgbuf)
2651 YYSTACK_FREE (yymsg);
2652 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2653 if (!yymsg)
2654 {
2655 yymsg = yymsgbuf;
2656 yymsg_alloc = sizeof yymsgbuf;
2657 yysyntax_error_status = 2;
2658 }
2659 else
2660 {
2661 yysyntax_error_status = YYSYNTAX_ERROR;
2662 yymsgp = yymsg;
2663 }
2664 }
2665 yyerror (yymsgp);
2666 if (yysyntax_error_status == 2)
2667 goto yyexhaustedlab;
2668 }
2669 # undef YYSYNTAX_ERROR
2670 #endif
2671 }
2672
2673
2674
2675 if (yyerrstatus == 3)
2676 {
2677 /* If just tried and failed to reuse lookahead token after an
2678 error, discard it. */
2679
2680 if (yychar <= YYEOF)
2681 {
2682 /* Return failure if at end of input. */
2683 if (yychar == YYEOF)
2684 YYABORT;
2685 }
2686 else
2687 {
2688 yydestruct ("Error: discarding",
2689 yytoken, &yylval);
2690 yychar = YYEMPTY;
2691 }
2692 }
2693
2694 /* Else will try to reuse lookahead token after shifting the error
2695 token. */
2696 goto yyerrlab1;
2697
2698
2699 /*---------------------------------------------------.
2700 | yyerrorlab -- error raised explicitly by YYERROR. |
2701 `---------------------------------------------------*/
2702 yyerrorlab:
2703
2704 /* Pacify compilers like GCC when the user code never invokes
2705 YYERROR and the label yyerrorlab therefore never appears in user
2706 code. */
2707 if (/*CONSTCOND*/ 0)
2708 goto yyerrorlab;
2709
2710 /* Do not reclaim the symbols of the rule whose action triggered
2711 this YYERROR. */
2712 YYPOPSTACK (yylen);
2713 yylen = 0;
2714 YY_STACK_PRINT (yyss, yyssp);
2715 yystate = *yyssp;
2716 goto yyerrlab1;
2717
2718
2719 /*-------------------------------------------------------------.
2720 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2721 `-------------------------------------------------------------*/
2722 yyerrlab1:
2723 yyerrstatus = 3; /* Each real token shifted decrements this. */
2724
2725 for (;;)
2726 {
2727 yyn = yypact[yystate];
2728 if (!yypact_value_is_default (yyn))
2729 {
2730 yyn += YYTERROR;
2731 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2732 {
2733 yyn = yytable[yyn];
2734 if (0 < yyn)
2735 break;
2736 }
2737 }
2738
2739 /* Pop the current state because it cannot handle the error token. */
2740 if (yyssp == yyss)
2741 YYABORT;
2742
2743
2744 yydestruct ("Error: popping",
2745 yystos[yystate], yyvsp);
2746 YYPOPSTACK (1);
2747 yystate = *yyssp;
2748 YY_STACK_PRINT (yyss, yyssp);
2749 }
2750
2751 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2752 *++yyvsp = yylval;
2753 YY_IGNORE_MAYBE_UNINITIALIZED_END
2754
2755
2756 /* Shift the error token. */
2757 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2758
2759 yystate = yyn;
2760 goto yynewstate;
2761
2762
2763 /*-------------------------------------.
2764 | yyacceptlab -- YYACCEPT comes here. |
2765 `-------------------------------------*/
2766 yyacceptlab:
2767 yyresult = 0;
2768 goto yyreturn;
2769
2770 /*-----------------------------------.
2771 | yyabortlab -- YYABORT comes here. |
2772 `-----------------------------------*/
2773 yyabortlab:
2774 yyresult = 1;
2775 goto yyreturn;
2776
2777 #if !defined yyoverflow || YYERROR_VERBOSE
2778 /*-------------------------------------------------.
2779 | yyexhaustedlab -- memory exhaustion comes here. |
2780 `-------------------------------------------------*/
2781 yyexhaustedlab:
2782 yyerror (YY_("memory exhausted"));
2783 yyresult = 2;
2784 /* Fall through. */
2785 #endif
2786
2787 yyreturn:
2788 if (yychar != YYEMPTY)
2789 {
2790 /* Make sure we have latest lookahead translation. See comments at
2791 user semantic actions for why this is necessary. */
2792 yytoken = YYTRANSLATE (yychar);
2793 yydestruct ("Cleanup: discarding lookahead",
2794 yytoken, &yylval);
2795 }
2796 /* Do not reclaim the symbols of the rule whose action triggered
2797 this YYABORT or YYACCEPT. */
2798 YYPOPSTACK (yylen);
2799 YY_STACK_PRINT (yyss, yyssp);
2800 while (yyssp != yyss)
2801 {
2802 yydestruct ("Cleanup: popping",
2803 yystos[*yyssp], yyvsp);
2804 YYPOPSTACK (1);
2805 }
2806 #ifndef yyoverflow
2807 if (yyss != yyssa)
2808 YYSTACK_FREE (yyss);
2809 #endif
2810 #if YYERROR_VERBOSE
2811 if (yymsg != yymsgbuf)
2812 YYSTACK_FREE (yymsg);
2813 #endif
2814 return yyresult;
2815 }
2816 #line 892 "rust-exp.y" /* yacc.c:1906 */
2817
2818
2819 /* A struct of this type is used to describe a token. */
2820
2821 struct token_info
2822 {
2823 const char *name;
2824 int value;
2825 enum exp_opcode opcode;
2826 };
2827
2828 /* Identifier tokens. */
2829
2830 static const struct token_info identifier_tokens[] =
2831 {
2832 { "as", KW_AS, OP_NULL },
2833 { "false", KW_FALSE, OP_NULL },
2834 { "if", 0, OP_NULL },
2835 { "mut", KW_MUT, OP_NULL },
2836 { "const", KW_CONST, OP_NULL },
2837 { "self", KW_SELF, OP_NULL },
2838 { "super", KW_SUPER, OP_NULL },
2839 { "true", KW_TRUE, OP_NULL },
2840 { "extern", KW_EXTERN, OP_NULL },
2841 { "fn", KW_FN, OP_NULL },
2842 { "sizeof", KW_SIZEOF, OP_NULL },
2843 };
2844
2845 /* Operator tokens, sorted longest first. */
2846
2847 static const struct token_info operator_tokens[] =
2848 {
2849 { ">>=", COMPOUND_ASSIGN, BINOP_RSH },
2850 { "<<=", COMPOUND_ASSIGN, BINOP_LSH },
2851
2852 { "<<", LSH, OP_NULL },
2853 { ">>", RSH, OP_NULL },
2854 { "&&", ANDAND, OP_NULL },
2855 { "||", OROR, OP_NULL },
2856 { "==", EQEQ, OP_NULL },
2857 { "!=", NOTEQ, OP_NULL },
2858 { "<=", LTEQ, OP_NULL },
2859 { ">=", GTEQ, OP_NULL },
2860 { "+=", COMPOUND_ASSIGN, BINOP_ADD },
2861 { "-=", COMPOUND_ASSIGN, BINOP_SUB },
2862 { "*=", COMPOUND_ASSIGN, BINOP_MUL },
2863 { "/=", COMPOUND_ASSIGN, BINOP_DIV },
2864 { "%=", COMPOUND_ASSIGN, BINOP_REM },
2865 { "&=", COMPOUND_ASSIGN, BINOP_BITWISE_AND },
2866 { "|=", COMPOUND_ASSIGN, BINOP_BITWISE_IOR },
2867 { "^=", COMPOUND_ASSIGN, BINOP_BITWISE_XOR },
2868
2869 { "::", COLONCOLON, OP_NULL },
2870 { "..", DOTDOT, OP_NULL },
2871 { "->", ARROW, OP_NULL }
2872 };
2873
2874 /* Helper function to copy to the name obstack. */
2875
2876 static const char *
2877 rust_copy_name (const char *name, int len)
2878 {
2879 return (const char *) obstack_copy0 (work_obstack, name, len);
2880 }
2881
2882 /* Helper function to make an stoken from a C string. */
2883
2884 static struct stoken
2885 make_stoken (const char *p)
2886 {
2887 struct stoken result;
2888
2889 result.ptr = p;
2890 result.length = strlen (result.ptr);
2891 return result;
2892 }
2893
2894 /* Helper function to concatenate three strings on the name
2895 obstack. */
2896
2897 static struct stoken
2898 rust_concat3 (const char *s1, const char *s2, const char *s3)
2899 {
2900 return make_stoken (obconcat (work_obstack, s1, s2, s3, (char *) NULL));
2901 }
2902
2903 /* Return an AST node referring to NAME, but relative to the crate's
2904 name. */
2905
2906 static const struct rust_op *
2907 crate_name (const struct rust_op *name)
2908 {
2909 std::string crate = rust_crate_for_block (expression_context_block);
2910 struct stoken result;
2911
2912 gdb_assert (name->opcode == OP_VAR_VALUE);
2913
2914 if (crate.empty ())
2915 error (_("Could not find crate for current location"));
2916 result = make_stoken (obconcat (work_obstack, "::", crate.c_str (), "::",
2917 name->left.sval.ptr, (char *) NULL));
2918
2919 return ast_path (result, name->right.params);
2920 }
2921
2922 /* Create an AST node referring to a "super::" qualified name. IDENT
2923 is the base name and N_SUPERS is how many "super::"s were
2924 provided. N_SUPERS can be zero. */
2925
2926 static const struct rust_op *
2927 super_name (const struct rust_op *ident, unsigned int n_supers)
2928 {
2929 const char *scope = block_scope (expression_context_block);
2930 int offset;
2931
2932 gdb_assert (ident->opcode == OP_VAR_VALUE);
2933
2934 if (scope[0] == '\0')
2935 error (_("Couldn't find namespace scope for self::"));
2936
2937 if (n_supers > 0)
2938 {
2939 int len;
2940 std::vector<int> offsets;
2941 unsigned int current_len;
2942
2943 current_len = cp_find_first_component (scope);
2944 while (scope[current_len] != '\0')
2945 {
2946 offsets.push_back (current_len);
2947 gdb_assert (scope[current_len] == ':');
2948 /* The "::". */
2949 current_len += 2;
2950 current_len += cp_find_first_component (scope
2951 + current_len);
2952 }
2953
2954 len = offsets.size ();
2955 if (n_supers >= len)
2956 error (_("Too many super:: uses from '%s'"), scope);
2957
2958 offset = offsets[len - n_supers];
2959 }
2960 else
2961 offset = strlen (scope);
2962
2963 obstack_grow (work_obstack, "::", 2);
2964 obstack_grow (work_obstack, scope, offset);
2965 obstack_grow (work_obstack, "::", 2);
2966 obstack_grow0 (work_obstack, ident->left.sval.ptr, ident->left.sval.length);
2967
2968 return ast_path (make_stoken ((const char *) obstack_finish (work_obstack)),
2969 ident->right.params);
2970 }
2971
2972 /* A helper that updates innermost_block as appropriate. */
2973
2974 static void
2975 update_innermost_block (struct block_symbol sym)
2976 {
2977 if (symbol_read_needs_frame (sym.symbol)
2978 && (innermost_block == NULL
2979 || contained_in (sym.block, innermost_block)))
2980 innermost_block = sym.block;
2981 }
2982
2983 /* A helper to look up a Rust type, or fail. This only works for
2984 types defined by rust_language_arch_info. */
2985
2986 static struct type *
2987 rust_type (const char *name)
2988 {
2989 struct type *type;
2990
2991 type = language_lookup_primitive_type (current_parser->language (),
2992 current_parser->arch (),
2993 name);
2994 if (type == NULL)
2995 error (_("Could not find Rust type %s"), name);
2996 return type;
2997 }
2998
2999 /* Lex a hex number with at least MIN digits and at most MAX
3000 digits. */
3001
3002 static uint32_t
3003 lex_hex (int min, int max)
3004 {
3005 uint32_t result = 0;
3006 int len = 0;
3007 /* We only want to stop at MAX if we're lexing a byte escape. */
3008 int check_max = min == max;
3009
3010 while ((check_max ? len <= max : 1)
3011 && ((lexptr[0] >= 'a' && lexptr[0] <= 'f')
3012 || (lexptr[0] >= 'A' && lexptr[0] <= 'F')
3013 || (lexptr[0] >= '0' && lexptr[0] <= '9')))
3014 {
3015 result *= 16;
3016 if (lexptr[0] >= 'a' && lexptr[0] <= 'f')
3017 result = result + 10 + lexptr[0] - 'a';
3018 else if (lexptr[0] >= 'A' && lexptr[0] <= 'F')
3019 result = result + 10 + lexptr[0] - 'A';
3020 else
3021 result = result + lexptr[0] - '0';
3022 ++lexptr;
3023 ++len;
3024 }
3025
3026 if (len < min)
3027 error (_("Not enough hex digits seen"));
3028 if (len > max)
3029 {
3030 gdb_assert (min != max);
3031 error (_("Overlong hex escape"));
3032 }
3033
3034 return result;
3035 }
3036
3037 /* Lex an escape. IS_BYTE is true if we're lexing a byte escape;
3038 otherwise we're lexing a character escape. */
3039
3040 static uint32_t
3041 lex_escape (int is_byte)
3042 {
3043 uint32_t result;
3044
3045 gdb_assert (lexptr[0] == '\\');
3046 ++lexptr;
3047 switch (lexptr[0])
3048 {
3049 case 'x':
3050 ++lexptr;
3051 result = lex_hex (2, 2);
3052 break;
3053
3054 case 'u':
3055 if (is_byte)
3056 error (_("Unicode escape in byte literal"));
3057 ++lexptr;
3058 if (lexptr[0] != '{')
3059 error (_("Missing '{' in Unicode escape"));
3060 ++lexptr;
3061 result = lex_hex (1, 6);
3062 /* Could do range checks here. */
3063 if (lexptr[0] != '}')
3064 error (_("Missing '}' in Unicode escape"));
3065 ++lexptr;
3066 break;
3067
3068 case 'n':
3069 result = '\n';
3070 ++lexptr;
3071 break;
3072 case 'r':
3073 result = '\r';
3074 ++lexptr;
3075 break;
3076 case 't':
3077 result = '\t';
3078 ++lexptr;
3079 break;
3080 case '\\':
3081 result = '\\';
3082 ++lexptr;
3083 break;
3084 case '0':
3085 result = '\0';
3086 ++lexptr;
3087 break;
3088 case '\'':
3089 result = '\'';
3090 ++lexptr;
3091 break;
3092 case '"':
3093 result = '"';
3094 ++lexptr;
3095 break;
3096
3097 default:
3098 error (_("Invalid escape \\%c in literal"), lexptr[0]);
3099 }
3100
3101 return result;
3102 }
3103
3104 /* Lex a character constant. */
3105
3106 static int
3107 lex_character (void)
3108 {
3109 int is_byte = 0;
3110 uint32_t value;
3111
3112 if (lexptr[0] == 'b')
3113 {
3114 is_byte = 1;
3115 ++lexptr;
3116 }
3117 gdb_assert (lexptr[0] == '\'');
3118 ++lexptr;
3119 /* This should handle UTF-8 here. */
3120 if (lexptr[0] == '\\')
3121 value = lex_escape (is_byte);
3122 else
3123 {
3124 value = lexptr[0] & 0xff;
3125 ++lexptr;
3126 }
3127
3128 if (lexptr[0] != '\'')
3129 error (_("Unterminated character literal"));
3130 ++lexptr;
3131
3132 rustyylval.typed_val_int.val = value;
3133 rustyylval.typed_val_int.type = rust_type (is_byte ? "u8" : "char");
3134
3135 return INTEGER;
3136 }
3137
3138 /* Return the offset of the double quote if STR looks like the start
3139 of a raw string, or 0 if STR does not start a raw string. */
3140
3141 static int
3142 starts_raw_string (const char *str)
3143 {
3144 const char *save = str;
3145
3146 if (str[0] != 'r')
3147 return 0;
3148 ++str;
3149 while (str[0] == '#')
3150 ++str;
3151 if (str[0] == '"')
3152 return str - save;
3153 return 0;
3154 }
3155
3156 /* Return true if STR looks like the end of a raw string that had N
3157 hashes at the start. */
3158
3159 static bool
3160 ends_raw_string (const char *str, int n)
3161 {
3162 int i;
3163
3164 gdb_assert (str[0] == '"');
3165 for (i = 0; i < n; ++i)
3166 if (str[i + 1] != '#')
3167 return false;
3168 return true;
3169 }
3170
3171 /* Lex a string constant. */
3172
3173 static int
3174 lex_string (void)
3175 {
3176 int is_byte = lexptr[0] == 'b';
3177 int raw_length;
3178
3179 if (is_byte)
3180 ++lexptr;
3181 raw_length = starts_raw_string (lexptr);
3182 lexptr += raw_length;
3183 gdb_assert (lexptr[0] == '"');
3184 ++lexptr;
3185
3186 while (1)
3187 {
3188 uint32_t value;
3189
3190 if (raw_length > 0)
3191 {
3192 if (lexptr[0] == '"' && ends_raw_string (lexptr, raw_length - 1))
3193 {
3194 /* Exit with lexptr pointing after the final "#". */
3195 lexptr += raw_length;
3196 break;
3197 }
3198 else if (lexptr[0] == '\0')
3199 error (_("Unexpected EOF in string"));
3200
3201 value = lexptr[0] & 0xff;
3202 if (is_byte && value > 127)
3203 error (_("Non-ASCII value in raw byte string"));
3204 obstack_1grow (work_obstack, value);
3205
3206 ++lexptr;
3207 }
3208 else if (lexptr[0] == '"')
3209 {
3210 /* Make sure to skip the quote. */
3211 ++lexptr;
3212 break;
3213 }
3214 else if (lexptr[0] == '\\')
3215 {
3216 value = lex_escape (is_byte);
3217
3218 if (is_byte)
3219 obstack_1grow (work_obstack, value);
3220 else
3221 convert_between_encodings ("UTF-32", "UTF-8", (gdb_byte *) &value,
3222 sizeof (value), sizeof (value),
3223 work_obstack, translit_none);
3224 }
3225 else if (lexptr[0] == '\0')
3226 error (_("Unexpected EOF in string"));
3227 else
3228 {
3229 value = lexptr[0] & 0xff;
3230 if (is_byte && value > 127)
3231 error (_("Non-ASCII value in byte string"));
3232 obstack_1grow (work_obstack, value);
3233 ++lexptr;
3234 }
3235 }
3236
3237 rustyylval.sval.length = obstack_object_size (work_obstack);
3238 rustyylval.sval.ptr = (const char *) obstack_finish (work_obstack);
3239 return is_byte ? BYTESTRING : STRING;
3240 }
3241
3242 /* Return true if STRING starts with whitespace followed by a digit. */
3243
3244 static bool
3245 space_then_number (const char *string)
3246 {
3247 const char *p = string;
3248
3249 while (p[0] == ' ' || p[0] == '\t')
3250 ++p;
3251 if (p == string)
3252 return false;
3253
3254 return *p >= '0' && *p <= '9';
3255 }
3256
3257 /* Return true if C can start an identifier. */
3258
3259 static bool
3260 rust_identifier_start_p (char c)
3261 {
3262 return ((c >= 'a' && c <= 'z')
3263 || (c >= 'A' && c <= 'Z')
3264 || c == '_'
3265 || c == '$');
3266 }
3267
3268 /* Lex an identifier. */
3269
3270 static int
3271 lex_identifier (void)
3272 {
3273 const char *start = lexptr;
3274 unsigned int length;
3275 const struct token_info *token;
3276 int i;
3277 int is_gdb_var = lexptr[0] == '$';
3278
3279 gdb_assert (rust_identifier_start_p (lexptr[0]));
3280
3281 ++lexptr;
3282
3283 /* For the time being this doesn't handle Unicode rules. Non-ASCII
3284 identifiers are gated anyway. */
3285 while ((lexptr[0] >= 'a' && lexptr[0] <= 'z')
3286 || (lexptr[0] >= 'A' && lexptr[0] <= 'Z')
3287 || lexptr[0] == '_'
3288 || (is_gdb_var && lexptr[0] == '$')
3289 || (lexptr[0] >= '0' && lexptr[0] <= '9'))
3290 ++lexptr;
3291
3292
3293 length = lexptr - start;
3294 token = NULL;
3295 for (i = 0; i < ARRAY_SIZE (identifier_tokens); ++i)
3296 {
3297 if (length == strlen (identifier_tokens[i].name)
3298 && strncmp (identifier_tokens[i].name, start, length) == 0)
3299 {
3300 token = &identifier_tokens[i];
3301 break;
3302 }
3303 }
3304
3305 if (token != NULL)
3306 {
3307 if (token->value == 0)
3308 {
3309 /* Leave the terminating token alone. */
3310 lexptr = start;
3311 return 0;
3312 }
3313 }
3314 else if (token == NULL
3315 && (strncmp (start, "thread", length) == 0
3316 || strncmp (start, "task", length) == 0)
3317 && space_then_number (lexptr))
3318 {
3319 /* "task" or "thread" followed by a number terminates the
3320 parse, per gdb rules. */
3321 lexptr = start;
3322 return 0;
3323 }
3324
3325 if (token == NULL || (parse_completion && lexptr[0] == '\0'))
3326 rustyylval.sval = make_stoken (rust_copy_name (start, length));
3327
3328 if (parse_completion && lexptr[0] == '\0')
3329 {
3330 /* Prevent rustyylex from returning two COMPLETE tokens. */
3331 prev_lexptr = lexptr;
3332 return COMPLETE;
3333 }
3334
3335 if (token != NULL)
3336 return token->value;
3337 if (is_gdb_var)
3338 return GDBVAR;
3339 return IDENT;
3340 }
3341
3342 /* Lex an operator. */
3343
3344 static int
3345 lex_operator (void)
3346 {
3347 const struct token_info *token = NULL;
3348 int i;
3349
3350 for (i = 0; i < ARRAY_SIZE (operator_tokens); ++i)
3351 {
3352 if (strncmp (operator_tokens[i].name, lexptr,
3353 strlen (operator_tokens[i].name)) == 0)
3354 {
3355 lexptr += strlen (operator_tokens[i].name);
3356 token = &operator_tokens[i];
3357 break;
3358 }
3359 }
3360
3361 if (token != NULL)
3362 {
3363 rustyylval.opcode = token->opcode;
3364 return token->value;
3365 }
3366
3367 return *lexptr++;
3368 }
3369
3370 /* Lex a number. */
3371
3372 static int
3373 lex_number (void)
3374 {
3375 regmatch_t subexps[NUM_SUBEXPRESSIONS];
3376 int match;
3377 int is_integer = 0;
3378 int could_be_decimal = 1;
3379 int implicit_i32 = 0;
3380 const char *type_name = NULL;
3381 struct type *type;
3382 int end_index;
3383 int type_index = -1;
3384 int i;
3385
3386 match = regexec (&number_regex, lexptr, ARRAY_SIZE (subexps), subexps, 0);
3387 /* Failure means the regexp is broken. */
3388 gdb_assert (match == 0);
3389
3390 if (subexps[INT_TEXT].rm_so != -1)
3391 {
3392 /* Integer part matched. */
3393 is_integer = 1;
3394 end_index = subexps[INT_TEXT].rm_eo;
3395 if (subexps[INT_TYPE].rm_so == -1)
3396 {
3397 type_name = "i32";
3398 implicit_i32 = 1;
3399 }
3400 else
3401 {
3402 type_index = INT_TYPE;
3403 could_be_decimal = 0;
3404 }
3405 }
3406 else if (subexps[FLOAT_TYPE1].rm_so != -1)
3407 {
3408 /* Found floating point type suffix. */
3409 end_index = subexps[FLOAT_TYPE1].rm_so;
3410 type_index = FLOAT_TYPE1;
3411 }
3412 else if (subexps[FLOAT_TYPE2].rm_so != -1)
3413 {
3414 /* Found floating point type suffix. */
3415 end_index = subexps[FLOAT_TYPE2].rm_so;
3416 type_index = FLOAT_TYPE2;
3417 }
3418 else
3419 {
3420 /* Any other floating point match. */
3421 end_index = subexps[0].rm_eo;
3422 type_name = "f64";
3423 }
3424
3425 /* We need a special case if the final character is ".". In this
3426 case we might need to parse an integer. For example, "23.f()" is
3427 a request for a trait method call, not a syntax error involving
3428 the floating point number "23.". */
3429 gdb_assert (subexps[0].rm_eo > 0);
3430 if (lexptr[subexps[0].rm_eo - 1] == '.')
3431 {
3432 const char *next = skip_spaces (&lexptr[subexps[0].rm_eo]);
3433
3434 if (rust_identifier_start_p (*next) || *next == '.')
3435 {
3436 --subexps[0].rm_eo;
3437 is_integer = 1;
3438 end_index = subexps[0].rm_eo;
3439 type_name = "i32";
3440 could_be_decimal = 1;
3441 implicit_i32 = 1;
3442 }
3443 }
3444
3445 /* Compute the type name if we haven't already. */
3446 std::string type_name_holder;
3447 if (type_name == NULL)
3448 {
3449 gdb_assert (type_index != -1);
3450 type_name_holder = std::string (lexptr + subexps[type_index].rm_so,
3451 (subexps[type_index].rm_eo
3452 - subexps[type_index].rm_so));
3453 type_name = type_name_holder.c_str ();
3454 }
3455
3456 /* Look up the type. */
3457 type = rust_type (type_name);
3458
3459 /* Copy the text of the number and remove the "_"s. */
3460 std::string number;
3461 for (i = 0; i < end_index && lexptr[i]; ++i)
3462 {
3463 if (lexptr[i] == '_')
3464 could_be_decimal = 0;
3465 else
3466 number.push_back (lexptr[i]);
3467 }
3468
3469 /* Advance past the match. */
3470 lexptr += subexps[0].rm_eo;
3471
3472 /* Parse the number. */
3473 if (is_integer)
3474 {
3475 uint64_t value;
3476 int radix = 10;
3477 int offset = 0;
3478
3479 if (number[0] == '0')
3480 {
3481 if (number[1] == 'x')
3482 radix = 16;
3483 else if (number[1] == 'o')
3484 radix = 8;
3485 else if (number[1] == 'b')
3486 radix = 2;
3487 if (radix != 10)
3488 {
3489 offset = 2;
3490 could_be_decimal = 0;
3491 }
3492 }
3493
3494 value = strtoul (number.c_str () + offset, NULL, radix);
3495 if (implicit_i32 && value >= ((uint64_t) 1) << 31)
3496 type = rust_type ("i64");
3497
3498 rustyylval.typed_val_int.val = value;
3499 rustyylval.typed_val_int.type = type;
3500 }
3501 else
3502 {
3503 rustyylval.typed_val_float.type = type;
3504 bool parsed = parse_float (number.c_str (), number.length (),
3505 rustyylval.typed_val_float.type,
3506 rustyylval.typed_val_float.val);
3507 gdb_assert (parsed);
3508 }
3509
3510 return is_integer ? (could_be_decimal ? DECIMAL_INTEGER : INTEGER) : FLOAT;
3511 }
3512
3513 /* The lexer. */
3514
3515 static int
3516 rustyylex (void)
3517 {
3518 /* Skip all leading whitespace. */
3519 while (lexptr[0] == ' ' || lexptr[0] == '\t' || lexptr[0] == '\r'
3520 || lexptr[0] == '\n')
3521 ++lexptr;
3522
3523 /* If we hit EOF and we're completing, then return COMPLETE -- maybe
3524 we're completing an empty string at the end of a field_expr.
3525 But, we don't want to return two COMPLETE tokens in a row. */
3526 if (lexptr[0] == '\0' && lexptr == prev_lexptr)
3527 return 0;
3528 prev_lexptr = lexptr;
3529 if (lexptr[0] == '\0')
3530 {
3531 if (parse_completion)
3532 {
3533 rustyylval.sval = make_stoken ("");
3534 return COMPLETE;
3535 }
3536 return 0;
3537 }
3538
3539 if (lexptr[0] >= '0' && lexptr[0] <= '9')
3540 return lex_number ();
3541 else if (lexptr[0] == 'b' && lexptr[1] == '\'')
3542 return lex_character ();
3543 else if (lexptr[0] == 'b' && lexptr[1] == '"')
3544 return lex_string ();
3545 else if (lexptr[0] == 'b' && starts_raw_string (lexptr + 1))
3546 return lex_string ();
3547 else if (starts_raw_string (lexptr))
3548 return lex_string ();
3549 else if (rust_identifier_start_p (lexptr[0]))
3550 return lex_identifier ();
3551 else if (lexptr[0] == '"')
3552 return lex_string ();
3553 else if (lexptr[0] == '\'')
3554 return lex_character ();
3555 else if (lexptr[0] == '}' || lexptr[0] == ']')
3556 {
3557 /* Falls through to lex_operator. */
3558 --paren_depth;
3559 }
3560 else if (lexptr[0] == '(' || lexptr[0] == '{')
3561 {
3562 /* Falls through to lex_operator. */
3563 ++paren_depth;
3564 }
3565 else if (lexptr[0] == ',' && comma_terminates && paren_depth == 0)
3566 return 0;
3567
3568 return lex_operator ();
3569 }
3570
3571 /* Push back a single character to be re-lexed. */
3572
3573 static void
3574 rust_push_back (char c)
3575 {
3576 /* Can't be called before any lexing. */
3577 gdb_assert (prev_lexptr != NULL);
3578
3579 --lexptr;
3580 gdb_assert (*lexptr == c);
3581 }
3582
3583
3584
3585 /* Make an arbitrary operation and fill in the fields. */
3586
3587 static const struct rust_op *
3588 ast_operation (enum exp_opcode opcode, const struct rust_op *left,
3589 const struct rust_op *right)
3590 {
3591 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3592
3593 result->opcode = opcode;
3594 result->left.op = left;
3595 result->right.op = right;
3596
3597 return result;
3598 }
3599
3600 /* Make a compound assignment operation. */
3601
3602 static const struct rust_op *
3603 ast_compound_assignment (enum exp_opcode opcode, const struct rust_op *left,
3604 const struct rust_op *right)
3605 {
3606 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3607
3608 result->opcode = opcode;
3609 result->compound_assignment = 1;
3610 result->left.op = left;
3611 result->right.op = right;
3612
3613 return result;
3614 }
3615
3616 /* Make a typed integer literal operation. */
3617
3618 static const struct rust_op *
3619 ast_literal (struct typed_val_int val)
3620 {
3621 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3622
3623 result->opcode = OP_LONG;
3624 result->left.typed_val_int = val;
3625
3626 return result;
3627 }
3628
3629 /* Make a typed floating point literal operation. */
3630
3631 static const struct rust_op *
3632 ast_dliteral (struct typed_val_float val)
3633 {
3634 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3635
3636 result->opcode = OP_FLOAT;
3637 result->left.typed_val_float = val;
3638
3639 return result;
3640 }
3641
3642 /* Make a unary operation. */
3643
3644 static const struct rust_op *
3645 ast_unary (enum exp_opcode opcode, const struct rust_op *expr)
3646 {
3647 return ast_operation (opcode, expr, NULL);
3648 }
3649
3650 /* Make a cast operation. */
3651
3652 static const struct rust_op *
3653 ast_cast (const struct rust_op *expr, const struct rust_op *type)
3654 {
3655 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3656
3657 result->opcode = UNOP_CAST;
3658 result->left.op = expr;
3659 result->right.op = type;
3660
3661 return result;
3662 }
3663
3664 /* Make a call-like operation. This is nominally a function call, but
3665 when lowering we may discover that it actually represents the
3666 creation of a tuple struct. */
3667
3668 static const struct rust_op *
3669 ast_call_ish (enum exp_opcode opcode, const struct rust_op *expr,
3670 rust_op_vector *params)
3671 {
3672 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3673
3674 result->opcode = opcode;
3675 result->left.op = expr;
3676 result->right.params = params;
3677
3678 return result;
3679 }
3680
3681 /* Make a structure creation operation. */
3682
3683 static const struct rust_op *
3684 ast_struct (const struct rust_op *name, rust_set_vector *fields)
3685 {
3686 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3687
3688 result->opcode = OP_AGGREGATE;
3689 result->left.op = name;
3690 result->right.field_inits = fields;
3691
3692 return result;
3693 }
3694
3695 /* Make an identifier path. */
3696
3697 static const struct rust_op *
3698 ast_path (struct stoken path, rust_op_vector *params)
3699 {
3700 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3701
3702 result->opcode = OP_VAR_VALUE;
3703 result->left.sval = path;
3704 result->right.params = params;
3705
3706 return result;
3707 }
3708
3709 /* Make a string constant operation. */
3710
3711 static const struct rust_op *
3712 ast_string (struct stoken str)
3713 {
3714 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3715
3716 result->opcode = OP_STRING;
3717 result->left.sval = str;
3718
3719 return result;
3720 }
3721
3722 /* Make a field expression. */
3723
3724 static const struct rust_op *
3725 ast_structop (const struct rust_op *left, const char *name, int completing)
3726 {
3727 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3728
3729 result->opcode = STRUCTOP_STRUCT;
3730 result->completing = completing;
3731 result->left.op = left;
3732 result->right.sval = make_stoken (name);
3733
3734 return result;
3735 }
3736
3737 /* Make an anonymous struct operation, like 'x.0'. */
3738
3739 static const struct rust_op *
3740 ast_structop_anonymous (const struct rust_op *left,
3741 struct typed_val_int number)
3742 {
3743 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3744
3745 result->opcode = STRUCTOP_ANONYMOUS;
3746 result->left.op = left;
3747 result->right.typed_val_int = number;
3748
3749 return result;
3750 }
3751
3752 /* Make a range operation. */
3753
3754 static const struct rust_op *
3755 ast_range (const struct rust_op *lhs, const struct rust_op *rhs)
3756 {
3757 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3758
3759 result->opcode = OP_RANGE;
3760 result->left.op = lhs;
3761 result->right.op = rhs;
3762
3763 return result;
3764 }
3765
3766 /* A helper function to make a type-related AST node. */
3767
3768 static struct rust_op *
3769 ast_basic_type (enum type_code typecode)
3770 {
3771 struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
3772
3773 result->opcode = OP_TYPE;
3774 result->typecode = typecode;
3775 return result;
3776 }
3777
3778 /* Create an AST node describing an array type. */
3779
3780 static const struct rust_op *
3781 ast_array_type (const struct rust_op *lhs, struct typed_val_int val)
3782 {
3783 struct rust_op *result = ast_basic_type (TYPE_CODE_ARRAY);
3784
3785 result->left.op = lhs;
3786 result->right.typed_val_int = val;
3787 return result;
3788 }
3789
3790 /* Create an AST node describing a reference type. */
3791
3792 static const struct rust_op *
3793 ast_slice_type (const struct rust_op *type)
3794 {
3795 /* Use TYPE_CODE_COMPLEX just because it is handy. */
3796 struct rust_op *result = ast_basic_type (TYPE_CODE_COMPLEX);
3797
3798 result->left.op = type;
3799 return result;
3800 }
3801
3802 /* Create an AST node describing a reference type. */
3803
3804 static const struct rust_op *
3805 ast_reference_type (const struct rust_op *type)
3806 {
3807 struct rust_op *result = ast_basic_type (TYPE_CODE_REF);
3808
3809 result->left.op = type;
3810 return result;
3811 }
3812
3813 /* Create an AST node describing a pointer type. */
3814
3815 static const struct rust_op *
3816 ast_pointer_type (const struct rust_op *type, int is_mut)
3817 {
3818 struct rust_op *result = ast_basic_type (TYPE_CODE_PTR);
3819
3820 result->left.op = type;
3821 /* For the time being we ignore is_mut. */
3822 return result;
3823 }
3824
3825 /* Create an AST node describing a function type. */
3826
3827 static const struct rust_op *
3828 ast_function_type (const struct rust_op *rtype, rust_op_vector *params)
3829 {
3830 struct rust_op *result = ast_basic_type (TYPE_CODE_FUNC);
3831
3832 result->left.op = rtype;
3833 result->right.params = params;
3834 return result;
3835 }
3836
3837 /* Create an AST node describing a tuple type. */
3838
3839 static const struct rust_op *
3840 ast_tuple_type (rust_op_vector *params)
3841 {
3842 struct rust_op *result = ast_basic_type (TYPE_CODE_STRUCT);
3843
3844 result->left.params = params;
3845 return result;
3846 }
3847
3848 /* A helper to appropriately munge NAME and BLOCK depending on the
3849 presence of a leading "::". */
3850
3851 static void
3852 munge_name_and_block (const char **name, const struct block **block)
3853 {
3854 /* If it is a global reference, skip the current block in favor of
3855 the static block. */
3856 if (strncmp (*name, "::", 2) == 0)
3857 {
3858 *name += 2;
3859 *block = block_static_block (*block);
3860 }
3861 }
3862
3863 /* Like lookup_symbol, but handles Rust namespace conventions, and
3864 doesn't require field_of_this_result. */
3865
3866 static struct block_symbol
3867 rust_lookup_symbol (const char *name, const struct block *block,
3868 const domain_enum domain)
3869 {
3870 struct block_symbol result;
3871
3872 munge_name_and_block (&name, &block);
3873
3874 result = lookup_symbol (name, block, domain, NULL);
3875 if (result.symbol != NULL)
3876 update_innermost_block (result);
3877 return result;
3878 }
3879
3880 /* Look up a type, following Rust namespace conventions. */
3881
3882 static struct type *
3883 rust_lookup_type (const char *name, const struct block *block)
3884 {
3885 struct block_symbol result;
3886 struct type *type;
3887
3888 munge_name_and_block (&name, &block);
3889
3890 result = lookup_symbol (name, block, STRUCT_DOMAIN, NULL);
3891 if (result.symbol != NULL)
3892 {
3893 update_innermost_block (result);
3894 return SYMBOL_TYPE (result.symbol);
3895 }
3896
3897 type = lookup_typename (current_parser->language (), current_parser->arch (),
3898 name, NULL, 1);
3899 if (type != NULL)
3900 return type;
3901
3902 /* Last chance, try a built-in type. */
3903 return language_lookup_primitive_type (current_parser->language (),
3904 current_parser->arch (),
3905 name);
3906 }
3907
3908 static struct type *convert_ast_to_type (struct parser_state *state,
3909 const struct rust_op *operation);
3910 static const char *convert_name (struct parser_state *state,
3911 const struct rust_op *operation);
3912
3913 /* Convert a vector of rust_ops representing types to a vector of
3914 types. */
3915
3916 static std::vector<struct type *>
3917 convert_params_to_types (struct parser_state *state, rust_op_vector *params)
3918 {
3919 std::vector<struct type *> result;
3920
3921 for (const rust_op *op : *params)
3922 result.push_back (convert_ast_to_type (state, op));
3923
3924 return result;
3925 }
3926
3927 /* Convert a rust_op representing a type to a struct type *. */
3928
3929 static struct type *
3930 convert_ast_to_type (struct parser_state *state,
3931 const struct rust_op *operation)
3932 {
3933 struct type *type, *result = NULL;
3934
3935 if (operation->opcode == OP_VAR_VALUE)
3936 {
3937 const char *varname = convert_name (state, operation);
3938
3939 result = rust_lookup_type (varname, expression_context_block);
3940 if (result == NULL)
3941 error (_("No typed name '%s' in current context"), varname);
3942 return result;
3943 }
3944
3945 gdb_assert (operation->opcode == OP_TYPE);
3946
3947 switch (operation->typecode)
3948 {
3949 case TYPE_CODE_ARRAY:
3950 type = convert_ast_to_type (state, operation->left.op);
3951 if (operation->right.typed_val_int.val < 0)
3952 error (_("Negative array length"));
3953 result = lookup_array_range_type (type, 0,
3954 operation->right.typed_val_int.val - 1);
3955 break;
3956
3957 case TYPE_CODE_COMPLEX:
3958 {
3959 struct type *usize = rust_type ("usize");
3960
3961 type = convert_ast_to_type (state, operation->left.op);
3962 result = rust_slice_type ("&[*gdb*]", type, usize);
3963 }
3964 break;
3965
3966 case TYPE_CODE_REF:
3967 case TYPE_CODE_PTR:
3968 /* For now we treat &x and *x identically. */
3969 type = convert_ast_to_type (state, operation->left.op);
3970 result = lookup_pointer_type (type);
3971 break;
3972
3973 case TYPE_CODE_FUNC:
3974 {
3975 std::vector<struct type *> args
3976 (convert_params_to_types (state, operation->right.params));
3977 struct type **argtypes = NULL;
3978
3979 type = convert_ast_to_type (state, operation->left.op);
3980 if (!args.empty ())
3981 argtypes = args.data ();
3982
3983 result
3984 = lookup_function_type_with_arguments (type, args.size (),
3985 argtypes);
3986 result = lookup_pointer_type (result);
3987 }
3988 break;
3989
3990 case TYPE_CODE_STRUCT:
3991 {
3992 std::vector<struct type *> args
3993 (convert_params_to_types (state, operation->left.params));
3994 int i;
3995 const char *name;
3996
3997 obstack_1grow (work_obstack, '(');
3998 for (i = 0; i < args.size (); ++i)
3999 {
4000 std::string type_name = type_to_string (args[i]);
4001
4002 if (i > 0)
4003 obstack_1grow (work_obstack, ',');
4004 obstack_grow_str (work_obstack, type_name.c_str ());
4005 }
4006
4007 obstack_grow_str0 (work_obstack, ")");
4008 name = (const char *) obstack_finish (work_obstack);
4009
4010 /* We don't allow creating new tuple types (yet), but we do
4011 allow looking up existing tuple types. */
4012 result = rust_lookup_type (name, expression_context_block);
4013 if (result == NULL)
4014 error (_("could not find tuple type '%s'"), name);
4015 }
4016 break;
4017
4018 default:
4019 gdb_assert_not_reached ("unhandled opcode in convert_ast_to_type");
4020 }
4021
4022 gdb_assert (result != NULL);
4023 return result;
4024 }
4025
4026 /* A helper function to turn a rust_op representing a name into a full
4027 name. This applies generic arguments as needed. The returned name
4028 is allocated on the work obstack. */
4029
4030 static const char *
4031 convert_name (struct parser_state *state, const struct rust_op *operation)
4032 {
4033 int i;
4034
4035 gdb_assert (operation->opcode == OP_VAR_VALUE);
4036
4037 if (operation->right.params == NULL)
4038 return operation->left.sval.ptr;
4039
4040 std::vector<struct type *> types
4041 (convert_params_to_types (state, operation->right.params));
4042
4043 obstack_grow_str (work_obstack, operation->left.sval.ptr);
4044 obstack_1grow (work_obstack, '<');
4045 for (i = 0; i < types.size (); ++i)
4046 {
4047 std::string type_name = type_to_string (types[i]);
4048
4049 if (i > 0)
4050 obstack_1grow (work_obstack, ',');
4051
4052 obstack_grow_str (work_obstack, type_name.c_str ());
4053 }
4054 obstack_grow_str0 (work_obstack, ">");
4055
4056 return (const char *) obstack_finish (work_obstack);
4057 }
4058
4059 static void convert_ast_to_expression (struct parser_state *state,
4060 const struct rust_op *operation,
4061 const struct rust_op *top,
4062 bool want_type = false);
4063
4064 /* A helper function that converts a vec of rust_ops to a gdb
4065 expression. */
4066
4067 static void
4068 convert_params_to_expression (struct parser_state *state,
4069 rust_op_vector *params,
4070 const struct rust_op *top)
4071 {
4072 for (const rust_op *elem : *params)
4073 convert_ast_to_expression (state, elem, top);
4074 }
4075
4076 /* Lower a rust_op to a gdb expression. STATE is the parser state.
4077 OPERATION is the operation to lower. TOP is a pointer to the
4078 top-most operation; it is used to handle the special case where the
4079 top-most expression is an identifier and can be optionally lowered
4080 to OP_TYPE. WANT_TYPE is a flag indicating that, if the expression
4081 is the name of a type, then emit an OP_TYPE for it (rather than
4082 erroring). If WANT_TYPE is set, then the similar TOP handling is
4083 not done. */
4084
4085 static void
4086 convert_ast_to_expression (struct parser_state *state,
4087 const struct rust_op *operation,
4088 const struct rust_op *top,
4089 bool want_type)
4090 {
4091 switch (operation->opcode)
4092 {
4093 case OP_LONG:
4094 write_exp_elt_opcode (state, OP_LONG);
4095 write_exp_elt_type (state, operation->left.typed_val_int.type);
4096 write_exp_elt_longcst (state, operation->left.typed_val_int.val);
4097 write_exp_elt_opcode (state, OP_LONG);
4098 break;
4099
4100 case OP_FLOAT:
4101 write_exp_elt_opcode (state, OP_FLOAT);
4102 write_exp_elt_type (state, operation->left.typed_val_float.type);
4103 write_exp_elt_floatcst (state, operation->left.typed_val_float.val);
4104 write_exp_elt_opcode (state, OP_FLOAT);
4105 break;
4106
4107 case STRUCTOP_STRUCT:
4108 {
4109 convert_ast_to_expression (state, operation->left.op, top);
4110
4111 if (operation->completing)
4112 mark_struct_expression (state);
4113 write_exp_elt_opcode (state, STRUCTOP_STRUCT);
4114 write_exp_string (state, operation->right.sval);
4115 write_exp_elt_opcode (state, STRUCTOP_STRUCT);
4116 }
4117 break;
4118
4119 case STRUCTOP_ANONYMOUS:
4120 {
4121 convert_ast_to_expression (state, operation->left.op, top);
4122
4123 write_exp_elt_opcode (state, STRUCTOP_ANONYMOUS);
4124 write_exp_elt_longcst (state, operation->right.typed_val_int.val);
4125 write_exp_elt_opcode (state, STRUCTOP_ANONYMOUS);
4126 }
4127 break;
4128
4129 case UNOP_SIZEOF:
4130 convert_ast_to_expression (state, operation->left.op, top, true);
4131 write_exp_elt_opcode (state, UNOP_SIZEOF);
4132 break;
4133
4134 case UNOP_PLUS:
4135 case UNOP_NEG:
4136 case UNOP_COMPLEMENT:
4137 case UNOP_IND:
4138 case UNOP_ADDR:
4139 convert_ast_to_expression (state, operation->left.op, top);
4140 write_exp_elt_opcode (state, operation->opcode);
4141 break;
4142
4143 case BINOP_SUBSCRIPT:
4144 case BINOP_MUL:
4145 case BINOP_REPEAT:
4146 case BINOP_DIV:
4147 case BINOP_REM:
4148 case BINOP_LESS:
4149 case BINOP_GTR:
4150 case BINOP_BITWISE_AND:
4151 case BINOP_BITWISE_IOR:
4152 case BINOP_BITWISE_XOR:
4153 case BINOP_ADD:
4154 case BINOP_SUB:
4155 case BINOP_LOGICAL_OR:
4156 case BINOP_LOGICAL_AND:
4157 case BINOP_EQUAL:
4158 case BINOP_NOTEQUAL:
4159 case BINOP_LEQ:
4160 case BINOP_GEQ:
4161 case BINOP_LSH:
4162 case BINOP_RSH:
4163 case BINOP_ASSIGN:
4164 case OP_RUST_ARRAY:
4165 convert_ast_to_expression (state, operation->left.op, top);
4166 convert_ast_to_expression (state, operation->right.op, top);
4167 if (operation->compound_assignment)
4168 {
4169 write_exp_elt_opcode (state, BINOP_ASSIGN_MODIFY);
4170 write_exp_elt_opcode (state, operation->opcode);
4171 write_exp_elt_opcode (state, BINOP_ASSIGN_MODIFY);
4172 }
4173 else
4174 write_exp_elt_opcode (state, operation->opcode);
4175
4176 if (operation->compound_assignment
4177 || operation->opcode == BINOP_ASSIGN)
4178 {
4179 struct type *type;
4180
4181 type = language_lookup_primitive_type (parse_language (state),
4182 parse_gdbarch (state),
4183 "()");
4184
4185 write_exp_elt_opcode (state, OP_LONG);
4186 write_exp_elt_type (state, type);
4187 write_exp_elt_longcst (state, 0);
4188 write_exp_elt_opcode (state, OP_LONG);
4189
4190 write_exp_elt_opcode (state, BINOP_COMMA);
4191 }
4192 break;
4193
4194 case UNOP_CAST:
4195 {
4196 struct type *type = convert_ast_to_type (state, operation->right.op);
4197
4198 convert_ast_to_expression (state, operation->left.op, top);
4199 write_exp_elt_opcode (state, UNOP_CAST);
4200 write_exp_elt_type (state, type);
4201 write_exp_elt_opcode (state, UNOP_CAST);
4202 }
4203 break;
4204
4205 case OP_FUNCALL:
4206 {
4207 if (operation->left.op->opcode == OP_VAR_VALUE)
4208 {
4209 struct type *type;
4210 const char *varname = convert_name (state, operation->left.op);
4211
4212 type = rust_lookup_type (varname, expression_context_block);
4213 if (type != NULL)
4214 {
4215 /* This is actually a tuple struct expression, not a
4216 call expression. */
4217 rust_op_vector *params = operation->right.params;
4218
4219 if (TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
4220 {
4221 if (!rust_tuple_struct_type_p (type))
4222 error (_("Type %s is not a tuple struct"), varname);
4223
4224 for (int i = 0; i < params->size (); ++i)
4225 {
4226 char *cell = get_print_cell ();
4227
4228 xsnprintf (cell, PRINT_CELL_SIZE, "__%d", i);
4229 write_exp_elt_opcode (state, OP_NAME);
4230 write_exp_string (state, make_stoken (cell));
4231 write_exp_elt_opcode (state, OP_NAME);
4232
4233 convert_ast_to_expression (state, (*params)[i], top);
4234 }
4235
4236 write_exp_elt_opcode (state, OP_AGGREGATE);
4237 write_exp_elt_type (state, type);
4238 write_exp_elt_longcst (state, 2 * params->size ());
4239 write_exp_elt_opcode (state, OP_AGGREGATE);
4240 break;
4241 }
4242 }
4243 }
4244 convert_ast_to_expression (state, operation->left.op, top);
4245 convert_params_to_expression (state, operation->right.params, top);
4246 write_exp_elt_opcode (state, OP_FUNCALL);
4247 write_exp_elt_longcst (state, operation->right.params->size ());
4248 write_exp_elt_longcst (state, OP_FUNCALL);
4249 }
4250 break;
4251
4252 case OP_ARRAY:
4253 gdb_assert (operation->left.op == NULL);
4254 convert_params_to_expression (state, operation->right.params, top);
4255 write_exp_elt_opcode (state, OP_ARRAY);
4256 write_exp_elt_longcst (state, 0);
4257 write_exp_elt_longcst (state, operation->right.params->size () - 1);
4258 write_exp_elt_longcst (state, OP_ARRAY);
4259 break;
4260
4261 case OP_VAR_VALUE:
4262 {
4263 struct block_symbol sym;
4264 const char *varname;
4265
4266 if (operation->left.sval.ptr[0] == '$')
4267 {
4268 write_dollar_variable (state, operation->left.sval);
4269 break;
4270 }
4271
4272 varname = convert_name (state, operation);
4273 sym = rust_lookup_symbol (varname, expression_context_block,
4274 VAR_DOMAIN);
4275 if (sym.symbol != NULL && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
4276 {
4277 write_exp_elt_opcode (state, OP_VAR_VALUE);
4278 write_exp_elt_block (state, sym.block);
4279 write_exp_elt_sym (state, sym.symbol);
4280 write_exp_elt_opcode (state, OP_VAR_VALUE);
4281 }
4282 else
4283 {
4284 struct type *type = NULL;
4285
4286 if (sym.symbol != NULL)
4287 {
4288 gdb_assert (SYMBOL_CLASS (sym.symbol) == LOC_TYPEDEF);
4289 type = SYMBOL_TYPE (sym.symbol);
4290 }
4291 if (type == NULL)
4292 type = rust_lookup_type (varname, expression_context_block);
4293 if (type == NULL)
4294 error (_("No symbol '%s' in current context"), varname);
4295
4296 if (!want_type
4297 && TYPE_CODE (type) == TYPE_CODE_STRUCT
4298 && TYPE_NFIELDS (type) == 0)
4299 {
4300 /* A unit-like struct. */
4301 write_exp_elt_opcode (state, OP_AGGREGATE);
4302 write_exp_elt_type (state, type);
4303 write_exp_elt_longcst (state, 0);
4304 write_exp_elt_opcode (state, OP_AGGREGATE);
4305 }
4306 else if (want_type || operation == top)
4307 {
4308 write_exp_elt_opcode (state, OP_TYPE);
4309 write_exp_elt_type (state, type);
4310 write_exp_elt_opcode (state, OP_TYPE);
4311 }
4312 else
4313 error (_("Found type '%s', which can't be "
4314 "evaluated in this context"),
4315 varname);
4316 }
4317 }
4318 break;
4319
4320 case OP_AGGREGATE:
4321 {
4322 int length;
4323 rust_set_vector *fields = operation->right.field_inits;
4324 struct type *type;
4325 const char *name;
4326
4327 length = 0;
4328 for (const set_field &init : *fields)
4329 {
4330 if (init.name.ptr != NULL)
4331 {
4332 write_exp_elt_opcode (state, OP_NAME);
4333 write_exp_string (state, init.name);
4334 write_exp_elt_opcode (state, OP_NAME);
4335 ++length;
4336 }
4337
4338 convert_ast_to_expression (state, init.init, top);
4339 ++length;
4340
4341 if (init.name.ptr == NULL)
4342 {
4343 /* This is handled differently from Ada in our
4344 evaluator. */
4345 write_exp_elt_opcode (state, OP_OTHERS);
4346 }
4347 }
4348
4349 name = convert_name (state, operation->left.op);
4350 type = rust_lookup_type (name, expression_context_block);
4351 if (type == NULL)
4352 error (_("Could not find type '%s'"), operation->left.sval.ptr);
4353
4354 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
4355 || rust_tuple_type_p (type)
4356 || rust_tuple_struct_type_p (type))
4357 error (_("Struct expression applied to non-struct type"));
4358
4359 write_exp_elt_opcode (state, OP_AGGREGATE);
4360 write_exp_elt_type (state, type);
4361 write_exp_elt_longcst (state, length);
4362 write_exp_elt_opcode (state, OP_AGGREGATE);
4363 }
4364 break;
4365
4366 case OP_STRING:
4367 {
4368 write_exp_elt_opcode (state, OP_STRING);
4369 write_exp_string (state, operation->left.sval);
4370 write_exp_elt_opcode (state, OP_STRING);
4371 }
4372 break;
4373
4374 case OP_RANGE:
4375 {
4376 enum range_type kind = BOTH_BOUND_DEFAULT;
4377
4378 if (operation->left.op != NULL)
4379 {
4380 convert_ast_to_expression (state, operation->left.op, top);
4381 kind = HIGH_BOUND_DEFAULT;
4382 }
4383 if (operation->right.op != NULL)
4384 {
4385 convert_ast_to_expression (state, operation->right.op, top);
4386 if (kind == BOTH_BOUND_DEFAULT)
4387 kind = LOW_BOUND_DEFAULT;
4388 else
4389 {
4390 gdb_assert (kind == HIGH_BOUND_DEFAULT);
4391 kind = NONE_BOUND_DEFAULT;
4392 }
4393 }
4394 write_exp_elt_opcode (state, OP_RANGE);
4395 write_exp_elt_longcst (state, kind);
4396 write_exp_elt_opcode (state, OP_RANGE);
4397 }
4398 break;
4399
4400 default:
4401 gdb_assert_not_reached ("unhandled opcode in convert_ast_to_expression");
4402 }
4403 }
4404
4405
4406
4407 /* The parser as exposed to gdb. */
4408
4409 int
4410 rust_parse (struct parser_state *state)
4411 {
4412 int result;
4413
4414 /* This sets various globals and also clears them on
4415 destruction. */
4416 rust_parser parser (state);
4417
4418 result = rustyyparse ();
4419
4420 if (!result || (parse_completion && parser.rust_ast != NULL))
4421 convert_ast_to_expression (state, parser.rust_ast, parser.rust_ast);
4422
4423 return result;
4424 }
4425
4426 /* The parser error handler. */
4427
4428 void
4429 rustyyerror (const char *msg)
4430 {
4431 const char *where = prev_lexptr ? prev_lexptr : lexptr;
4432 error (_("%s in expression, near `%s'."), (msg ? msg : "Error"), where);
4433 }
4434
4435
4436
4437 #if GDB_SELF_TEST
4438
4439 /* Initialize the lexer for testing. */
4440
4441 static void
4442 rust_lex_test_init (const char *input)
4443 {
4444 prev_lexptr = NULL;
4445 lexptr = input;
4446 paren_depth = 0;
4447 }
4448
4449 /* A test helper that lexes a string, expecting a single token. It
4450 returns the lexer data for this token. */
4451
4452 static RUSTSTYPE
4453 rust_lex_test_one (const char *input, int expected)
4454 {
4455 int token;
4456 RUSTSTYPE result;
4457
4458 rust_lex_test_init (input);
4459
4460 token = rustyylex ();
4461 SELF_CHECK (token == expected);
4462 result = rustyylval;
4463
4464 if (token)
4465 {
4466 token = rustyylex ();
4467 SELF_CHECK (token == 0);
4468 }
4469
4470 return result;
4471 }
4472
4473 /* Test that INPUT lexes as the integer VALUE. */
4474
4475 static void
4476 rust_lex_int_test (const char *input, int value, int kind)
4477 {
4478 RUSTSTYPE result = rust_lex_test_one (input, kind);
4479 SELF_CHECK (result.typed_val_int.val == value);
4480 }
4481
4482 /* Test that INPUT throws an exception with text ERR. */
4483
4484 static void
4485 rust_lex_exception_test (const char *input, const char *err)
4486 {
4487 TRY
4488 {
4489 /* The "kind" doesn't matter. */
4490 rust_lex_test_one (input, DECIMAL_INTEGER);
4491 SELF_CHECK (0);
4492 }
4493 CATCH (except, RETURN_MASK_ERROR)
4494 {
4495 SELF_CHECK (strcmp (except.message, err) == 0);
4496 }
4497 END_CATCH
4498 }
4499
4500 /* Test that INPUT lexes as the identifier, string, or byte-string
4501 VALUE. KIND holds the expected token kind. */
4502
4503 static void
4504 rust_lex_stringish_test (const char *input, const char *value, int kind)
4505 {
4506 RUSTSTYPE result = rust_lex_test_one (input, kind);
4507 SELF_CHECK (result.sval.length == strlen (value));
4508 SELF_CHECK (strncmp (result.sval.ptr, value, result.sval.length) == 0);
4509 }
4510
4511 /* Helper to test that a string parses as a given token sequence. */
4512
4513 static void
4514 rust_lex_test_sequence (const char *input, int len, const int expected[])
4515 {
4516 int i;
4517
4518 lexptr = input;
4519 paren_depth = 0;
4520
4521 for (i = 0; i < len; ++i)
4522 {
4523 int token = rustyylex ();
4524
4525 SELF_CHECK (token == expected[i]);
4526 }
4527 }
4528
4529 /* Tests for an integer-parsing corner case. */
4530
4531 static void
4532 rust_lex_test_trailing_dot (void)
4533 {
4534 const int expected1[] = { DECIMAL_INTEGER, '.', IDENT, '(', ')', 0 };
4535 const int expected2[] = { INTEGER, '.', IDENT, '(', ')', 0 };
4536 const int expected3[] = { FLOAT, EQEQ, '(', ')', 0 };
4537 const int expected4[] = { DECIMAL_INTEGER, DOTDOT, DECIMAL_INTEGER, 0 };
4538
4539 rust_lex_test_sequence ("23.g()", ARRAY_SIZE (expected1), expected1);
4540 rust_lex_test_sequence ("23_0.g()", ARRAY_SIZE (expected2), expected2);
4541 rust_lex_test_sequence ("23.==()", ARRAY_SIZE (expected3), expected3);
4542 rust_lex_test_sequence ("23..25", ARRAY_SIZE (expected4), expected4);
4543 }
4544
4545 /* Tests of completion. */
4546
4547 static void
4548 rust_lex_test_completion (void)
4549 {
4550 const int expected[] = { IDENT, '.', COMPLETE, 0 };
4551
4552 parse_completion = 1;
4553
4554 rust_lex_test_sequence ("something.wha", ARRAY_SIZE (expected), expected);
4555 rust_lex_test_sequence ("something.", ARRAY_SIZE (expected), expected);
4556
4557 parse_completion = 0;
4558 }
4559
4560 /* Test pushback. */
4561
4562 static void
4563 rust_lex_test_push_back (void)
4564 {
4565 int token;
4566
4567 rust_lex_test_init (">>=");
4568
4569 token = rustyylex ();
4570 SELF_CHECK (token == COMPOUND_ASSIGN);
4571 SELF_CHECK (rustyylval.opcode == BINOP_RSH);
4572
4573 rust_push_back ('=');
4574
4575 token = rustyylex ();
4576 SELF_CHECK (token == '=');
4577
4578 token = rustyylex ();
4579 SELF_CHECK (token == 0);
4580 }
4581
4582 /* Unit test the lexer. */
4583
4584 static void
4585 rust_lex_tests (void)
4586 {
4587 int i;
4588
4589 auto_obstack test_obstack;
4590 scoped_restore obstack_holder = make_scoped_restore (&work_obstack,
4591 &test_obstack);
4592
4593 // Set up dummy "parser", so that rust_type works.
4594 struct parser_state ps (0, &rust_language_defn, target_gdbarch ());
4595 rust_parser parser (&ps);
4596
4597 rust_lex_test_one ("", 0);
4598 rust_lex_test_one (" \t \n \r ", 0);
4599 rust_lex_test_one ("thread 23", 0);
4600 rust_lex_test_one ("task 23", 0);
4601 rust_lex_test_one ("th 104", 0);
4602 rust_lex_test_one ("ta 97", 0);
4603
4604 rust_lex_int_test ("'z'", 'z', INTEGER);
4605 rust_lex_int_test ("'\\xff'", 0xff, INTEGER);
4606 rust_lex_int_test ("'\\u{1016f}'", 0x1016f, INTEGER);
4607 rust_lex_int_test ("b'z'", 'z', INTEGER);
4608 rust_lex_int_test ("b'\\xfe'", 0xfe, INTEGER);
4609 rust_lex_int_test ("b'\\xFE'", 0xfe, INTEGER);
4610 rust_lex_int_test ("b'\\xfE'", 0xfe, INTEGER);
4611
4612 /* Test all escapes in both modes. */
4613 rust_lex_int_test ("'\\n'", '\n', INTEGER);
4614 rust_lex_int_test ("'\\r'", '\r', INTEGER);
4615 rust_lex_int_test ("'\\t'", '\t', INTEGER);
4616 rust_lex_int_test ("'\\\\'", '\\', INTEGER);
4617 rust_lex_int_test ("'\\0'", '\0', INTEGER);
4618 rust_lex_int_test ("'\\''", '\'', INTEGER);
4619 rust_lex_int_test ("'\\\"'", '"', INTEGER);
4620
4621 rust_lex_int_test ("b'\\n'", '\n', INTEGER);
4622 rust_lex_int_test ("b'\\r'", '\r', INTEGER);
4623 rust_lex_int_test ("b'\\t'", '\t', INTEGER);
4624 rust_lex_int_test ("b'\\\\'", '\\', INTEGER);
4625 rust_lex_int_test ("b'\\0'", '\0', INTEGER);
4626 rust_lex_int_test ("b'\\''", '\'', INTEGER);
4627 rust_lex_int_test ("b'\\\"'", '"', INTEGER);
4628
4629 rust_lex_exception_test ("'z", "Unterminated character literal");
4630 rust_lex_exception_test ("b'\\x0'", "Not enough hex digits seen");
4631 rust_lex_exception_test ("b'\\u{0}'", "Unicode escape in byte literal");
4632 rust_lex_exception_test ("'\\x0'", "Not enough hex digits seen");
4633 rust_lex_exception_test ("'\\u0'", "Missing '{' in Unicode escape");
4634 rust_lex_exception_test ("'\\u{0", "Missing '}' in Unicode escape");
4635 rust_lex_exception_test ("'\\u{0000007}", "Overlong hex escape");
4636 rust_lex_exception_test ("'\\u{}", "Not enough hex digits seen");
4637 rust_lex_exception_test ("'\\Q'", "Invalid escape \\Q in literal");
4638 rust_lex_exception_test ("b'\\Q'", "Invalid escape \\Q in literal");
4639
4640 rust_lex_int_test ("23", 23, DECIMAL_INTEGER);
4641 rust_lex_int_test ("2_344__29", 234429, INTEGER);
4642 rust_lex_int_test ("0x1f", 0x1f, INTEGER);
4643 rust_lex_int_test ("23usize", 23, INTEGER);
4644 rust_lex_int_test ("23i32", 23, INTEGER);
4645 rust_lex_int_test ("0x1_f", 0x1f, INTEGER);
4646 rust_lex_int_test ("0b1_101011__", 0x6b, INTEGER);
4647 rust_lex_int_test ("0o001177i64", 639, INTEGER);
4648
4649 rust_lex_test_trailing_dot ();
4650
4651 rust_lex_test_one ("23.", FLOAT);
4652 rust_lex_test_one ("23.99f32", FLOAT);
4653 rust_lex_test_one ("23e7", FLOAT);
4654 rust_lex_test_one ("23E-7", FLOAT);
4655 rust_lex_test_one ("23e+7", FLOAT);
4656 rust_lex_test_one ("23.99e+7f64", FLOAT);
4657 rust_lex_test_one ("23.82f32", FLOAT);
4658
4659 rust_lex_stringish_test ("hibob", "hibob", IDENT);
4660 rust_lex_stringish_test ("hibob__93", "hibob__93", IDENT);
4661 rust_lex_stringish_test ("thread", "thread", IDENT);
4662
4663 rust_lex_stringish_test ("\"string\"", "string", STRING);
4664 rust_lex_stringish_test ("\"str\\ting\"", "str\ting", STRING);
4665 rust_lex_stringish_test ("\"str\\\"ing\"", "str\"ing", STRING);
4666 rust_lex_stringish_test ("r\"str\\ing\"", "str\\ing", STRING);
4667 rust_lex_stringish_test ("r#\"str\\ting\"#", "str\\ting", STRING);
4668 rust_lex_stringish_test ("r###\"str\\\"ing\"###", "str\\\"ing", STRING);
4669
4670 rust_lex_stringish_test ("b\"string\"", "string", BYTESTRING);
4671 rust_lex_stringish_test ("b\"\x73tring\"", "string", BYTESTRING);
4672 rust_lex_stringish_test ("b\"str\\\"ing\"", "str\"ing", BYTESTRING);
4673 rust_lex_stringish_test ("br####\"\\x73tring\"####", "\\x73tring",
4674 BYTESTRING);
4675
4676 for (i = 0; i < ARRAY_SIZE (identifier_tokens); ++i)
4677 rust_lex_test_one (identifier_tokens[i].name, identifier_tokens[i].value);
4678
4679 for (i = 0; i < ARRAY_SIZE (operator_tokens); ++i)
4680 rust_lex_test_one (operator_tokens[i].name, operator_tokens[i].value);
4681
4682 rust_lex_test_completion ();
4683 rust_lex_test_push_back ();
4684 }
4685
4686 #endif /* GDB_SELF_TEST */
4687
4688 void
4689 _initialize_rust_exp (void)
4690 {
4691 int code = regcomp (&number_regex, number_regex_text, REG_EXTENDED);
4692 /* If the regular expression was incorrect, it was a programming
4693 error. */
4694 gdb_assert (code == 0);
4695
4696 #if GDB_SELF_TEST
4697 selftests::register_test ("rust-lex", rust_lex_tests);
4698 #endif
4699 }
TYPE_CODE_NAMESPACE
Definition: gdbtypes.h:171
target_gdbarch
struct gdbarch * target_gdbarch(void)
Definition: gdbarch.c:5467
err
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition: gnu-nat.c:1822
gdbarch
Definition: gdbarch.c:127
typed_val_float::val
gdb_byte val[16]
Definition: rust-exp.c:101
type::length
unsigned int length
Definition: gdbtypes.h:803
string
const char * string
Definition: signals.c:50
YYSTACK_FREE
#define YYSTACK_FREE
Definition: rust-exp.c:624
rust_language_defn
const struct language_defn rust_language_defn
KW_FN
#define KW_FN
Definition: rust-exp.c:377
crate_name
static const struct rust_op * crate_name(const struct rust_op *name)
Definition: rust-exp.c:2907
yylex
#define yylex
Definition: cp-name-parser.c:165
yydefact
static const yytype_uint8 yydefact[]
Definition: rust-exp.c:869
type_code
type_code
Definition: gdbtypes.h:80
rust_tuple_type_p
bool rust_tuple_type_p(struct type *type)
Definition: rust-lang.c:274
TYPE_CODE_ARRAY
Definition: gdbtypes.h:104
COMPOUND_ASSIGN
#define COMPOUND_ASSIGN
Definition: rust-exp.c:367
YY_
#define YY_(Msgid)
Definition: rust-exp.c:527
YYFPRINTF
#define YYFPRINTF
Definition: yy-remap.h:92
yylen
#define yylen
Definition: cp-name-parser.c:195
lookup_array_range_type
struct type * lookup_array_range_type(struct type *element_type, LONGEST low_bound, LONGEST high_bound)
Definition: gdbtypes.c:1232
rust_parser::pstate
struct parser_state * pstate
Definition: rust-exp.c:288
FLOAT_TYPE1
#define FLOAT_TYPE1
ast_struct
static const struct rust_op * ast_struct(const struct rust_op *name, rust_set_vector *fields)
Definition: rust-exp.c:3684
INT_TYPE
#define INT_TYPE
gdb_obstack.h
yy_symbol_value_print
static void yy_symbol_value_print(FILE *yyoutput, int yytype, YYSTYPE const *const yyvaluep)
Definition: rust-exp.c:1269
munge_name_and_block
static void munge_name_and_block(const char **name, const struct block **block)
Definition: rust-exp.c:3852
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Definition: rust-exp.c:577
ast_cast
static const struct rust_op * ast_cast(const struct rust_op *expr, const struct rust_op *type)
Definition: rust-exp.c:3653
write_exp_elt_sym
void write_exp_elt_sym(struct parser_state *ps, struct symbol *expelt)
Definition: parse.c:215
parse_language
#define parse_language(ps)
Definition: parser-defs.h:36
token_info::name
const char * name
Definition: rust-exp.c:2823
parse_gdbarch
#define parse_gdbarch(ps)
Definition: parser-defs.h:35
value::type
struct type * type
Definition: value.c:266
rust_parse
int rust_parse(struct parser_state *state)
Definition: rust-exp.c:4410
parse_float
bool parse_float(const char *p, int len, const struct type *type, gdb_byte *data)
Definition: parse.c:1331
yyvs
#define yyvs
Definition: cp-name-parser.c:207
rust_parser::obstack
auto_obstack obstack
Definition: rust-exp.c:278
yylloc
#define yylloc
Definition: cp-name-parser.c:189
stoken::ptr
const char * ptr
Definition: parser-defs.h:91
FLOAT
#define FLOAT
Definition: rust-exp.c:366
KW_IF
#define KW_IF
Definition: rust-exp.c:369
yyssp
#define yyssp
Definition: cp-name-parser.c:205
rust_parser::arch
struct gdbarch * arch() const
Definition: rust-exp.c:272
update_innermost_block
static void update_innermost_block(struct block_symbol sym)
Definition: rust-exp.c:2975
LTEQ
#define LTEQ
Definition: rust-exp.c:384
comma_terminates
int comma_terminates
Definition: parse.c:77
_initialize_rust_exp
void _initialize_rust_exp(void)
Definition: rust-exp.c:4689
rust_parser::~rust_parser
~rust_parser()
Definition: rust-exp.c:240
gdb_regex.h
ast_structop_anonymous
static const struct rust_op * ast_structop_anonymous(const struct rust_op *left, struct typed_val_int number)
Definition: rust-exp.c:3740
ast_literal
static const struct rust_op * ast_literal(struct typed_val_int val)
Definition: rust-exp.c:3619
yyparse
int yyparse(void)
Definition: rust-exp.c:1635
parse_completion
int parse_completion
Definition: parse.c:80
lex_operator
static int lex_operator(void)
Definition: rust-exp.c:3345
convert_ast_to_expression
static void convert_ast_to_expression(struct parser_state *state, const struct rust_op *operation, const struct rust_op *top, bool want_type=false)
Definition: rust-exp.c:4086
rust_type
static struct type * rust_type(const char *name)
Definition: rust-exp.c:2987
lex_hex
static uint32_t lex_hex(int min, int max)
Definition: rust-exp.c:3003
lex_number
static int lex_number(void)
Definition: rust-exp.c:3373
number_regex_text
static const char * number_regex_text
Definition: rust-exp.c:178
yyerror
#define yyerror
Definition: cp-name-parser.c:166
ANDAND
#define ANDAND
Definition: rust-exp.c:381
NUM_SUBEXPRESSIONS
#define NUM_SUBEXPRESSIONS
Definition: rust-exp.c:214
rust_lookup_type
static struct type * rust_lookup_type(const char *name, const struct block *block)
Definition: rust-exp.c:3883
rust_identifier_start_p
static bool rust_identifier_start_p(char c)
Definition: rust-exp.c:3260
KW_TRUE
#define KW_TRUE
Definition: rust-exp.c:370
convert_params_to_types
static std::vector< struct type * > convert_params_to_types(struct parser_state *state, rust_op_vector *params)
Definition: rust-exp.c:3917
yyvsp
#define yyvsp
Definition: cp-name-parser.c:208
domain_enum
enum domain_enum_tag domain_enum
lex_escape
static uint32_t lex_escape(int is_byte)
Definition: rust-exp.c:3041
charset.h
RETURN_MASK_ERROR
Definition: common-exceptions.h:43
SYMBOL_CLASS
#define SYMBOL_CLASS(symbol)
Definition: symtab.h:1155
FLOAT_TYPE2
#define FLOAT_TYPE2
work_obstack
static auto_obstack * work_obstack
Definition: rust-exp.c:224
convert_params_to_expression
static void convert_params_to_expression(struct parser_state *state, rust_op_vector *params, const struct rust_op *top)
Definition: rust-exp.c:4068
rust_concat3
static struct stoken rust_concat3(const char *, const char *, const char *)
Definition: rust-exp.c:2898
ast_dliteral
static const struct rust_op * ast_dliteral(struct typed_val_float val)
Definition: rust-exp.c:3632
yylval
YYSTYPE yylval
Definition: rust-exp.c:1625
get_print_cell
char * get_print_cell(void)
Definition: print-utils.c:30
innermost_block
const struct block * innermost_block
Definition: parse.c:71
STRING
#define STRING
Definition: rust-exp.c:364
rust_crate_for_block
std::string rust_crate_for_block(const struct block *block)
Definition: rust-lang.c:56
cp-support.h
INTEGER
#define INTEGER
Definition: rust-exp.c:362
LOC_TYPEDEF
Definition: symtab.h:844
token
Definition: c-exp.c:4864
ast_slice_type
static const struct rust_op * ast_slice_type(const struct rust_op *type)
Definition: rust-exp.c:3793
ast_function_type
static const struct rust_op * ast_function_type(const struct rust_op *result, rust_op_vector *params)
Definition: rust-exp.c:3828
ast_array_type
static const struct rust_op * ast_array_type(const struct rust_op *lhs, struct typed_val_int val)
Definition: rust-exp.c:3781
YYSTYPE::depth
unsigned int depth
Definition: rust-exp.c:426
lookup_symbol
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
Definition: symtab.c:1893
rust_op::completing
unsigned int completing
Definition: rust-exp.c:466
skip_spaces
char * skip_spaces(char *chp)
Definition: common-utils.c:337
STRUCT_DOMAIN
Definition: symtab.h:745
_
#define _(String)
Definition: gdb_locale.h:35
ast_compound_assignment
static const struct rust_op * ast_compound_assignment(enum exp_opcode opcode, const struct rust_op *left, const struct rust_op *rust_op)
Definition: rust-exp.c:3603
YYNTOKENS
#define YYNTOKENS
Definition: rust-exp.c:718
rust-lang.h
defs.h
YYSTACK_BYTES
#define YYSTACK_BYTES(N)
Definition: rust-exp.c:668
YYPRINT
#define YYPRINT(FILE, TYPE, VALUE)
Definition: c-exp.c:328
convert_ast_to_type
static struct type * convert_ast_to_type(struct parser_state *state, const struct rust_op *operation)
Definition: rust-exp.c:3930
KW_CONST
#define KW_CONST
Definition: rust-exp.c:376
rust_lookup_symbol
static struct block_symbol rust_lookup_symbol(const char *name, const struct block *block, const domain_enum domain)
Definition: rust-exp.c:3867
END_CATCH
#define END_CATCH
Definition: common-exceptions.h:259
yytable_value_is_error
#define yytable_value_is_error(Yytable_value)
Definition: rust-exp.c:835
typed_val_int::type
struct type * type
Definition: rust-exp.c:94
cleanup_check.ps
ps
Definition: cleanup_check.py:333
typed_val_float
Definition: rust-exp.c:99
YYEMPTY
#define YYEMPTY
Definition: rust-exp.c:1199
ast_pointer_type
static const struct rust_op * ast_pointer_type(const struct rust_op *type, int is_mut)
Definition: rust-exp.c:3816
ARROW
#define ARROW
Definition: rust-exp.c:389
yytname
static const char *const yytname[]
Definition: rust-exp.c:792
yyrline
static const yytype_uint16 yyrline[]
Definition: rust-exp.c:771
language_defn
Definition: language.h:132
LOW_BOUND_DEFAULT
Definition: expression.h:164
token_info::value
int value
Definition: rust-exp.c:2824
make_scoped_restore
scoped_restore_tmpl< T > make_scoped_restore(T *var)
Definition: scoped_restore.h:105
parser-defs.h
yydebug
int yydebug
Definition: rust-exp.c:1353
TRY
#define TRY
Definition: common-exceptions.h:246
YYSTACK_ALLOC
#define YYSTACK_ALLOC
Definition: rust-exp.c:623
DOTDOT
#define DOTDOT
Definition: rust-exp.c:379
lookup_typename
struct type * lookup_typename(const struct language_defn *language, struct gdbarch *gdbarch, const char *name, const struct block *block, int noerr)
Definition: gdbtypes.c:1509
name
const char *const name
Definition: aarch64-tdep.c:76
write_exp_elt_block
void write_exp_elt_block(struct parser_state *ps, const struct block *b)
Definition: parse.c:235
write_exp_elt_longcst
void write_exp_elt_longcst(struct parser_state *ps, LONGEST expelt)
Definition: parse.c:255
IDENT
#define IDENT
Definition: rust-exp.c:360
UNARY
#define UNARY
Definition: rust-exp.c:390
YYLAST
#define YYLAST
Definition: rust-exp.c:715
YYTRANSLATE
#define YYTRANSLATE(YYX)
Definition: rust-exp.c:731
YYACCEPT
#define YYACCEPT
Definition: rust-exp.c:1202
CATCH
#define CATCH(EXCEPTION, MASK)
Definition: common-exceptions.h:254
convert_between_encodings
void convert_between_encodings(const char *from, const char *to, const gdb_byte *bytes, unsigned int num_bytes, int width, struct obstack *output, enum transliterations translit)
Definition: charset.c:512
ast_operation
static const struct rust_op * ast_operation(enum exp_opcode opcode, const struct rust_op *left, const struct rust_op *right)
Definition: rust-exp.c:3588
contained_in
int contained_in(const struct block *a, const struct block *b)
Definition: block.c:73
YYSTYPE::params
rust_op_vector * params
Definition: rust-exp.c:413
yyr1
static const yytype_uint8 yyr1[]
Definition: rust-exp.c:1161
COLONCOLON
#define COLONCOLON
Definition: rust-exp.c:388
yystos
static const yytype_uint8 yystos[]
Definition: rust-exp.c:1134
yyss
#define yyss
Definition: cp-name-parser.c:203
cp_find_first_component
unsigned int cp_find_first_component(const char *name)
Definition: cp-support.c:970
GTEQ
#define GTEQ
Definition: rust-exp.c:385
block_symbol::block
const struct block * block
Definition: symtab.h:1140
KW_EXTERN
#define KW_EXTERN
Definition: rust-exp.c:375
current_parser
static rust_parser * current_parser
Definition: rust-exp.c:171
yy-remap.h
YY_SYMBOL_PRINT
#define YY_SYMBOL_PRINT(Title, Type, Value, Location)
Definition: rust-exp.c:1252
rust_parser::rust_ast
const struct rust_op * rust_ast
Definition: rust-exp.c:281
yycheck
static const yytype_int16 yycheck[]
Definition: rust-exp.c:1024
symbol_read_needs_frame
int symbol_read_needs_frame(struct symbol *sym)
Definition: findvar.c:392
translit_none
Definition: charset.h:46
rust_copy_name
static const char * rust_copy_name(const char *, int)
Definition: rust-exp.c:2877
obconcat
char * obconcat(struct obstack *obstackp,...)
Definition: gdb_obstack.c:29
block_symbol
Definition: symtab.h:1133
HIGH_BOUND_DEFAULT
Definition: expression.h:165
ast_unary
static const struct rust_op * ast_unary(enum exp_opcode opcode, const struct rust_op *expr)
Definition: rust-exp.c:3645
gdb_assert_not_reached
#define gdb_assert_not_reached(message)
Definition: gdb_assert.h:55
rust_op
Definition: rust-exp.c:450
ast_tuple_type
static const struct rust_op * ast_tuple_type(rust_op_vector *params)
Definition: rust-exp.c:3840
yytable
static const yytype_int16 yytable[]
Definition: rust-exp.c:916
convert_name
static const char * convert_name(struct parser_state *state, const struct rust_op *operation)
Definition: rust-exp.c:4031
operator_tokens
static const struct token_info operator_tokens[]
Definition: rust-exp.c:2847
YY_STACK_PRINT
#define YY_STACK_PRINT(Bottom, Top)
Definition: rust-exp.c:1314
yyalloc::yyss_alloc
yytype_int16 yyss_alloc
Definition: ada-exp.c:500
rust_parser::language
const struct language_defn * language() const
Definition: rust-exp.c:266
rust_tuple_struct_type_p
bool rust_tuple_struct_type_p(struct type *type)
Definition: rust-lang.c:320
scoped_restore_base
Definition: scoped_restore.h:24
type
Definition: gdbtypes.h:749
KW_AS
#define KW_AS
Definition: rust-exp.c:368
set_field::name
struct stoken name
Definition: rust-exp.c:110
rustyyerror
void rustyyerror(const char *msg)
Definition: rust-exp.c:4429
yytokentype
yytokentype
Definition: ada-exp.c:178
yytoknum
static const yytype_uint16 yytoknum[]
Definition: c-exp.c:699
write_dollar_variable
void write_dollar_variable(struct parser_state *ps, struct stoken str)
Definition: parse.c:594
RSH
#define RSH
Definition: rust-exp.c:387
EQEQ
#define EQEQ
Definition: rust-exp.c:382
type
static const char * type
Definition: language.c:113
language_bool_type
struct type * language_bool_type(const struct language_defn *la, struct gdbarch *gdbarch)
Definition: language.c:982
mark_struct_expression
void mark_struct_expression(struct parser_state *ps)
Definition: parse.c:544
field
Definition: gdbtypes.h:517
lex_character
static int lex_character(void)
Definition: rust-exp.c:3107
make_stoken
static struct stoken make_stoken(const char *)
Definition: rust-exp.c:2885
YYABORT
#define YYABORT
Definition: rust-exp.c:1203
yytype_int16
short int yytype_int16
Definition: rust-exp.c:501
YYSTACK_RELOCATE
#define YYSTACK_RELOCATE(Stack_alloc, Stack)
Definition: rust-exp.c:679
yyalloc::yyvs_alloc
YYSTYPE yyvs_alloc
Definition: ada-exp.c:501
yyrule
#define yyrule
Definition: cp-name-parser.c:193
YYTERROR
#define YYTERROR
Definition: rust-exp.c:1227
yytype_uint16
unsigned short int yytype_uint16
Definition: ada-exp.c:336
token
int token
Definition: m2-exp.c:2527
yytype_uint8
unsigned char yytype_uint8
Definition: rust-exp.c:483
parser_state
Definition: parser-defs.h:38
rust_set_vector
std::vector< set_field > rust_set_vector
Definition: rust-exp.c:114
DECIMAL_INTEGER
#define DECIMAL_INTEGER
Definition: rust-exp.c:363
yy_symbol_print
static void yy_symbol_print(FILE *yyoutput, int yytype, YYSTYPE const *const yyvaluep)
Definition: rust-exp.c:1288
KW_SELF
#define KW_SELF
Definition: rust-exp.c:373
rust_slice_type
struct type * rust_slice_type(const char *name, struct type *elt_type, struct type *usize_type)
Definition: rust-lang.c:1195
LSH
#define LSH
Definition: rust-exp.c:386
rust_parser::set_vectors
std::vector< std::unique_ptr< rust_set_vector > > set_vectors
Definition: rust-exp.c:284
YYSIZE_T
#define YYSIZE_T
Definition: rust-exp.c:511
TYPE_CODE_STRUCT
Definition: gdbtypes.h:106
YYFINAL
#define YYFINAL
Definition: rust-exp.c:713
TYPE_CODE_REF
Definition: gdbtypes.h:156
paren_depth
int paren_depth
Definition: parse.c:76
TYPE_CODE_FUNC
Definition: gdbtypes.h:110
set_field::init
const struct rust_op * init
Definition: rust-exp.c:111
YY_NULLPTRPTR
#define YY_NULLPTRPTR
Definition: rust-exp.c:298
block_symbol::symbol
struct symbol * symbol
Definition: symtab.h:1136
gdb_assert
#define gdb_assert(expr)
Definition: gdb_assert.h:32
block
Definition: block.h:60
value
Definition: value.c:169
INT_TEXT
#define INT_TEXT
identifier_tokens
static const struct token_info identifier_tokens[]
Definition: rust-exp.c:2830
rust_push_back
static void rust_push_back(char c)
Definition: rust-exp.c:3574
typed_val_float::type
struct type * type
Definition: rust-exp.c:102
ast_string
static const struct rust_op * ast_string(struct stoken str)
Definition: rust-exp.c:3712
rust_op::opcode
enum exp_opcode opcode
Definition: rust-exp.c:453
xfree
void xfree(void *)
space_then_number
static bool space_then_number(const char *string)
Definition: rust-exp.c:3245
write_exp_elt_opcode
void write_exp_elt_opcode(struct parser_state *ps, enum exp_opcode expelt)
Definition: parse.c:205
TYPE_CODE_PTR
Definition: gdbtypes.h:84
typed_val_int
Definition: rust-exp.c:91
rust_parser::new_op_vector
rust_op_vector * new_op_vector()
Definition: rust-exp.c:258
lexptr
static const char * lexptr
Definition: cp-name-parser.c:84
yyalloc
Definition: ada-exp.c:498
rust_parser
Definition: rust-exp.c:229
YY_REDUCE_PRINT
#define YY_REDUCE_PRINT(Rule)
Definition: rust-exp.c:1345
typed_val_int::val
LONGEST val
Definition: rust-exp.c:93
yytype_int8
signed char yytype_int8
Definition: rust-exp.c:489
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
rust_op::left
RUSTSTYPE left
Definition: rust-exp.c:469
COMPLETE
#define COMPLETE
Definition: rust-exp.c:361
set_field
Definition: rust-exp.c:108
starts_raw_string
static int starts_raw_string(const char *str)
Definition: rust-exp.c:3142
yynerrs
int yynerrs
Definition: rust-exp.c:1627
yytype_uint8
unsigned char yytype_uint8
Definition: ada-exp.c:324
xmalloc
void * xmalloc(YYSIZE_T)
YYSTACK_ALLOC_MAXIMUM
#define YYSTACK_ALLOC_MAXIMUM
Definition: rust-exp.c:626
yypact_value_is_default
#define yypact_value_is_default(Yystate)
Definition: rust-exp.c:830
ast_reference_type
static const struct rust_op * ast_reference_type(const struct rust_op *type)
Definition: rust-exp.c:3805
yys
#define yys
Definition: cp-name-parser.c:182
yy_reduce_print
static void yy_reduce_print(yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
Definition: rust-exp.c:1326
xsnprintf
int xsnprintf(char *str, size_t size, const char *format,...)
Definition: common-utils.c:134
super_name
static const struct rust_op * super_name(const struct rust_op *name, unsigned int n_supers)
Definition: rust-exp.c:2927
TYPE_CODE
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1238
block_static_block
const struct block * block_static_block(const struct block *block)
Definition: block.c:364
yytranslate
static const yytype_uint8 yytranslate[]
Definition: rust-exp.c:736
YYUSE
#define YYUSE(E)
Definition: rust-exp.c:560
field::name
const char * name
Definition: gdbtypes.h:550
OROR
#define OROR
Definition: rust-exp.c:380
token_info::opcode
enum exp_opcode opcode
Definition: rust-exp.c:2825
ast_basic_type
static struct rust_op * ast_basic_type(enum type_code typecode)
Definition: rust-exp.c:3769
offset
int offset
Definition: agent.c:65
YYSTYPE
Definition: ada-exp.c:279
yychar
int yychar
Definition: rust-exp.c:1622
code
int code
Definition: ser-unix.c:239
TYPE_NFIELDS
#define TYPE_NFIELDS(thistype)
Definition: gdbtypes.h:1239
yystate
#define yystate
Definition: cp-name-parser.c:184
exp_opcode
exp_opcode
Definition: expression.h:42
YYSTYPE::opcode
enum exp_opcode opcode
Definition: c-exp.c:290
obstack_grow_str
#define obstack_grow_str(OBSTACK, STRING)
Definition: gdb_obstack.h:46
VAR_DOMAIN
Definition: symtab.h:739
value.h
YYMAXDEPTH
#define YYMAXDEPTH
Definition: rust-exp.c:1375
BYTESTRING
#define BYTESTRING
Definition: rust-exp.c:365
yypact
static const yytype_int16 yypact[]
Definition: rust-exp.c:840
number_regex
static regex_t number_regex
Definition: rust-exp.c:218
expression_context_block
const struct block * expression_context_block
Definition: parse.c:69
rust_parser::rust_parser
rust_parser(struct parser_state *state)
Definition: rust-exp.c:231
KW_SIZEOF
#define KW_SIZEOF
Definition: rust-exp.c:378
YYSTYPE::field_inits
rust_set_vector * field_inits
Definition: rust-exp.c:416
yydestruct
static void yydestruct(const char *yymsg, int yytype, YYSTYPE *yyvaluep)
Definition: rust-exp.c:1606
PRINT_CELL_SIZE
#define PRINT_CELL_SIZE
Definition: print-utils.h:25
YYEOF
#define YYEOF
Definition: rust-exp.c:1200
obstack_grow_str0
#define obstack_grow_str0(OBSTACK, STRING)
Definition: gdb_obstack.h:48
lookup_function_type_with_arguments
struct type * lookup_function_type_with_arguments(struct type *type, int nparams, struct type **param_types)
Definition: gdbtypes.c:529
YY_IGNORE_MAYBE_UNINITIALIZED_END
#define YY_IGNORE_MAYBE_UNINITIALIZED_END
Definition: rust-exp.c:578
range_type
range_type
Definition: expression.h:161
SYMBOL_TYPE
#define SYMBOL_TYPE(symbol)
Definition: symtab.h:1161
YYSTYPE::op
const struct rust_op * op
Definition: rust-exp.c:422
yyval
#define yyval
Definition: cp-name-parser.c:188
selftest.h
yypgoto
static const yytype_int16 yypgoto[]
Definition: rust-exp.c:896
RUSTSTYPE
#define RUSTSTYPE
Definition: rust-exp.c:84
token_info
Definition: rust-exp.c:2821
BOTH_BOUND_DEFAULT
Definition: expression.h:163
lex_string
static int lex_string(void)
Definition: rust-exp.c:3174
OBSTACK_ZALLOC
#define OBSTACK_ZALLOC(OBSTACK, TYPE)
Definition: gdb_obstack.h:27
GDBVAR
#define GDBVAR
Definition: rust-exp.c:359
yytype_int16
short int yytype_int16
Definition: ada-exp.c:342
language_lookup_primitive_type
struct type * language_lookup_primitive_type(const struct language_defn *la, struct gdbarch *gdbarch, const char *name)
Definition: language.c:1025
YYSTYPE::one_field_init
struct set_field one_field_init
Definition: rust-exp.c:419
NOTEQ
#define NOTEQ
Definition: rust-exp.c:383
type_to_string
std::string type_to_string(struct type *type)
Definition: typeprint.c:368
yyr2
static const yytype_uint8 yyr2[]
Definition: rust-exp.c:1179
ast_structop
static const struct rust_op * ast_structop(const struct rust_op *left, const char *name, int completing)
Definition: rust-exp.c:3725
NONE_BOUND_DEFAULT
Definition: expression.h:166
YYPOPSTACK
#define YYPOPSTACK(N)
auto_obstack
Definition: gdb_obstack.h:67
ast_range
static const struct rust_op * ast_range(const struct rust_op *lhs, const struct rust_op *rhs)
Definition: rust-exp.c:3755
YYSTYPE::sval
struct stoken sval
Definition: ada-exp.c:293
KW_FALSE
#define KW_FALSE
Definition: rust-exp.c:371
rust_op::compound_assignment
unsigned int compound_assignment
Definition: rust-exp.c:462
rust_parser::new_set_vector
rust_set_vector * new_set_vector()
Definition: rust-exp.c:249
prev_lexptr
static const char * prev_lexptr
Definition: cp-name-parser.c:84
write_exp_elt_floatcst
void write_exp_elt_floatcst(struct parser_state *ps, const gdb_byte expelt[16])
Definition: parse.c:265
stoken
Definition: parser-defs.h:88
write_exp_string
void write_exp_string(struct parser_state *ps, struct stoken str)
Definition: parse.c:318
yy_stack_print
static void yy_stack_print(yytype_int16 *yybottom, yytype_int16 *yytop)
Definition: rust-exp.c:1303
write_exp_elt_type
void write_exp_elt_type(struct parser_state *ps, struct type *expelt)
Definition: parse.c:277
lex_identifier
static int lex_identifier(void)
Definition: rust-exp.c:3271
selftests::register_test
void register_test(const std::string &name, selftest *test)
Definition: selftest.c:52
YYDPRINTF
#define YYDPRINTF(Args)
Definition: rust-exp.c:1240
yystacksize
#define yystacksize
Definition: cp-name-parser.c:206
yytype_uint16
unsigned short int yytype_uint16
Definition: rust-exp.c:495
error
void error(const char *fmt,...)
Definition: errors.c:38
KW_MUT
#define KW_MUT
Definition: rust-exp.c:374
YYINITDEPTH
#define YYINITDEPTH
Definition: rust-exp.c:1364
block_scope
const char * block_scope(const struct block *block)
Definition: block.c:295
ast_path
static const struct rust_op * ast_path(struct stoken name, rust_op_vector *params)
Definition: rust-exp.c:3698
yydefgoto
static const yytype_int16 yydefgoto[]
Definition: rust-exp.c:905
lookup_pointer_type
struct type * lookup_pointer_type(struct type *type)
Definition: gdbtypes.c:381
rust_op::typecode
enum type_code typecode
Definition: rust-exp.c:456
rust_parser::op_vectors
std::vector< std::unique_ptr< rust_op_vector > > op_vectors
Definition: rust-exp.c:285
ast_call_ish
static const struct rust_op * ast_call_ish(enum exp_opcode opcode, const struct rust_op *expr, rust_op_vector *params)
Definition: rust-exp.c:3669
block.h
LONGEST
long long LONGEST
Definition: common-types.h:52
rustyylex
static int rustyylex(void)
Definition: rust-exp.c:3516
SELF_CHECK
#define SELF_CHECK(VALUE)
Definition: selftest.h:67
stoken::length
int length
Definition: parser-defs.h:93
rust_op::right
RUSTSTYPE right
Definition: rust-exp.c:470
KW_SUPER
#define KW_SUPER
Definition: rust-exp.c:372
ends_raw_string
static bool ends_raw_string(const char *str, int n)
Definition: rust-exp.c:3160
vec.h
TYPE_CODE_COMPLEX
Definition: gdbtypes.h:167
rust_op_vector
std::vector< const struct rust_op * > rust_op_vector
Definition: rust-exp.c:86
token::opcode
enum exp_opcode opcode
Definition: c-exp.c:4868