1 /* A Bison parser, made by GNU Bison 3.5.1. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
6 Inc.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
30
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
33
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
36
37 /* All symbols defined below should begin with yy or YY, to avoid
38 infringing on user name space. This should be done even for local
39 variables, as they might otherwise be expanded by user macros.
40 There are some unavoidable exceptions within include files to
41 define necessary library symbols; they are noted "INFRINGES ON
42 USER NAME SPACE" below. */
43
44 /* Undocumented macros, especially those whose name start with YY_,
45 are private implementation details. Do not rely on them. */
46
47 /* Identify Bison output. */
48 #define YYBISON 1
49
50 /* Bison version. */
51 #define YYBISON_VERSION "3.5.1"
52
53 /* Skeleton name. */
54 #define YYSKELETON_NAME "yacc.c"
55
56 /* Pure parsers. */
57 #define YYPURE 0
58
59 /* Push parsers. */
60 #define YYPUSH 0
61
62 /* Pull parsers. */
63 #define YYPULL 1
64
65
66
67
68 /* First part of user prologue. */
69 #line 52 "go-exp.y"
70
71
72 #include "defs.h"
73 #include <ctype.h>
74 #include "expression.h"
75 #include "value.h"
76 #include "parser-defs.h"
77 #include "language.h"
78 #include "c-lang.h"
79 #include "go-lang.h"
80 #include "bfd.h" /* Required by objfiles.h. */
81 #include "symfile.h" /* Required by objfiles.h. */
82 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
83 #include "charset.h"
84 #include "block.h"
85 #include "expop.h"
86
87 #define parse_type(ps) builtin_type (ps->gdbarch ())
88
89 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
90 etc). */
91 #define GDB_YY_REMAP_PREFIX go_
92 #include "yy-remap.h"
93
94 /* The state of the parser, used internally when we are parsing the
95 expression. */
96
97 static struct parser_state *pstate = NULL;
98
99 int yyparse (void);
100
101 static int yylex (void);
102
103 static void yyerror (const char *);
104
105
106 #line 107 "go-exp.c.tmp"
107
108 # ifndef YY_CAST
109 # ifdef __cplusplus
110 # define YY_CAST(Type, Val) static_cast<Type> (Val)
111 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
112 # else
113 # define YY_CAST(Type, Val) ((Type) (Val))
114 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
115 # endif
116 # endif
117 # ifndef YY_NULLPTRPTR
118 # if defined __cplusplus
119 # if 201103L <= __cplusplus
120 # define YY_NULLPTRPTR nullptr
121 # else
122 # define YY_NULLPTRPTR 0
123 # endif
124 # else
125 # define YY_NULLPTRPTR ((void*)0)
126 # endif
127 # endif
128
129 /* Enabling verbose error messages. */
130 #ifdef YYERROR_VERBOSE
131 # undef YYERROR_VERBOSE
132 # define YYERROR_VERBOSE 1
133 #else
134 # define YYERROR_VERBOSE 0
135 #endif
136
137
138 /* Debug traces. */
139 #ifndef YYDEBUG
140 # define YYDEBUG 0
141 #endif
142 #if YYDEBUG
143 extern int yydebug;
144 #endif
145
146 /* Token type. */
147 #ifndef YYTOKENTYPE
148 # define YYTOKENTYPE
149 enum yytokentype
150 {
151 INT = 258,
152 FLOAT = 259,
153 RAW_STRING = 260,
154 STRING = 261,
155 CHAR = 262,
156 NAME = 263,
157 TYPENAME = 264,
158 COMPLETE = 265,
159 NAME_OR_INT = 266,
160 TRUE_KEYWORD = 267,
161 FALSE_KEYWORD = 268,
162 STRUCT_KEYWORD = 269,
163 INTERFACE_KEYWORD = 270,
164 TYPE_KEYWORD = 271,
165 CHAN_KEYWORD = 272,
166 SIZEOF_KEYWORD = 273,
167 LEN_KEYWORD = 274,
168 CAP_KEYWORD = 275,
169 NEW_KEYWORD = 276,
170 IOTA_KEYWORD = 277,
171 NIL_KEYWORD = 278,
172 CONST_KEYWORD = 279,
173 DOTDOTDOT = 280,
174 ENTRY = 281,
175 ERROR = 282,
176 BYTE_KEYWORD = 283,
177 DOLLAR_VARIABLE = 284,
178 ASSIGN_MODIFY = 285,
179 ABOVE_COMMA = 286,
180 OROR = 287,
181 ANDAND = 288,
182 ANDNOT = 289,
183 EQUAL = 290,
184 NOTEQUAL = 291,
185 LEQ = 292,
186 GEQ = 293,
187 LSH = 294,
188 RSH = 295,
189 UNARY = 296,
190 INCREMENT = 297,
191 DECREMENT = 298,
192 LEFT_ARROW = 299
193 };
194 #endif
195 /* Tokens. */
196 #define INT 258
197 #define FLOAT 259
198 #define RAW_STRING 260
199 #define STRING 261
200 #define CHAR 262
201 #define NAME 263
202 #define TYPENAME 264
203 #define COMPLETE 265
204 #define NAME_OR_INT 266
205 #define TRUE_KEYWORD 267
206 #define FALSE_KEYWORD 268
207 #define STRUCT_KEYWORD 269
208 #define INTERFACE_KEYWORD 270
209 #define TYPE_KEYWORD 271
210 #define CHAN_KEYWORD 272
211 #define SIZEOF_KEYWORD 273
212 #define LEN_KEYWORD 274
213 #define CAP_KEYWORD 275
214 #define NEW_KEYWORD 276
215 #define IOTA_KEYWORD 277
216 #define NIL_KEYWORD 278
217 #define CONST_KEYWORD 279
218 #define DOTDOTDOT 280
219 #define ENTRY 281
220 #define ERROR 282
221 #define BYTE_KEYWORD 283
222 #define DOLLAR_VARIABLE 284
223 #define ASSIGN_MODIFY 285
224 #define ABOVE_COMMA 286
225 #define OROR 287
226 #define ANDAND 288
227 #define ANDNOT 289
228 #define EQUAL 290
229 #define NOTEQUAL 291
230 #define LEQ 292
231 #define GEQ 293
232 #define LSH 294
233 #define RSH 295
234 #define UNARY 296
235 #define INCREMENT 297
236 #define DECREMENT 298
237 #define LEFT_ARROW 299
238
239 /* Value type. */
240 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
241 union YYSTYPE
242 {
243 #line 94 "go-exp.y"
244
245 LONGEST lval;
246 struct {
247 LONGEST val;
248 struct type *type;
249 } typed_val_int;
250 struct {
251 gdb_byte val[16];
252 struct type *type;
253 } typed_val_float;
254 struct stoken sval;
255 struct symtoken ssym;
256 struct type *tval;
257 struct typed_stoken tsval;
258 struct ttype tsym;
259 int voidval;
260 enum exp_opcode opcode;
261 struct internalvar *ivar;
262 struct stoken_vector svec;
263
264
265 #line 266 "go-exp.c.tmp"
266
267 };
268 typedef union YYSTYPE YYSTYPE;
269 # define YYSTYPE_IS_TRIVIAL 1
270 # define YYSTYPE_IS_DECLARED 1
271 #endif
272
273
274 extern YYSTYPE yylval;
275
276 int yyparse (void);
277
278
279
280 /* Second part of user prologue. */
281 #line 115 "go-exp.y"
282
283 /* YYSTYPE gets defined by %union. */
284 static int parse_number (struct parser_state *,
285 const char *, int, int, YYSTYPE *);
286
287 using namespace expr;
288
289 #line 290 "go-exp.c.tmp"
290
291
292 #ifdef short
293 # undef short
294 #endif
295
296 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
297 <limits.h> and (if available) <stdint.h> are included
298 so that the code can choose integer types of a good width. */
299
300 #ifndef __PTRDIFF_MAX__
301 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
302 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
303 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
304 # define YY_STDINT_H
305 # endif
306 #endif
307
308 /* Narrow types that promote to a signed type and that can represent a
309 signed or unsigned integer of at least N bits. In tables they can
310 save space and decrease cache pressure. Promoting to a signed type
311 helps avoid bugs in integer arithmetic. */
312
313 #ifdef __INT_LEAST8_MAX__
314 typedef __INT_LEAST8_TYPE__ yytype_int8;
315 #elif defined YY_STDINT_H
316 typedef int_least8_t yytype_int8;
317 #else
318 typedef signed char yytype_int8;
319 #endif
320
321 #ifdef __INT_LEAST16_MAX__
322 typedef __INT_LEAST16_TYPE__ yytype_int16;
323 #elif defined YY_STDINT_H
324 typedef int_least16_t yytype_int16;
325 #else
326 typedef short yytype_int16;
327 #endif
328
329 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
330 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
331 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
332 && UINT_LEAST8_MAX <= INT_MAX)
333 typedef uint_least8_t yytype_uint8;
334 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
335 typedef unsigned char yytype_uint8;
336 #else
337 typedef short yytype_uint8;
338 #endif
339
340 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
341 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
342 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
343 && UINT_LEAST16_MAX <= INT_MAX)
344 typedef uint_least16_t yytype_uint16;
345 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
346 typedef unsigned short yytype_uint16;
347 #else
348 typedef int yytype_uint16;
349 #endif
350
351 #ifndef YYPTRDIFF_T
352 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
353 # define YYPTRDIFF_T __PTRDIFF_TYPE__
354 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
355 # elif defined PTRDIFF_MAX
356 # ifndef ptrdiff_t
357 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
358 # endif
359 # define YYPTRDIFF_T ptrdiff_t
360 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
361 # else
362 # define YYPTRDIFF_T long
363 # define YYPTRDIFF_MAXIMUM LONG_MAX
364 # endif
365 #endif
366
367 #ifndef YYSIZE_T
368 # ifdef __SIZE_TYPE__
369 # define YYSIZE_T __SIZE_TYPE__
370 # elif defined size_t
371 # define YYSIZE_T size_t
372 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
373 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
374 # define YYSIZE_T size_t
375 # else
376 # define YYSIZE_T unsigned
377 # endif
378 #endif
379
380 #define YYSIZE_MAXIMUM \
381 YY_CAST (YYPTRDIFF_T, \
382 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
383 ? YYPTRDIFF_MAXIMUM \
384 : YY_CAST (YYSIZE_T, -1)))
385
386 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
387
388 /* Stored state numbers (used for stacks). */
389 typedef yytype_int8 yy_state_t;
390
391 /* State numbers in computations. */
392 typedef int yy_state_fast_t;
393
394 #ifndef YY_
395 # if defined YYENABLE_NLS && YYENABLE_NLS
396 # if ENABLE_NLS
397 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
398 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
399 # endif
400 # endif
401 # ifndef YY_
402 # define YY_(Msgid) Msgid
403 # endif
404 #endif
405
406 #ifndef YY_ATTRIBUTE_PURE
407 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
408 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
409 # else
410 # define YY_ATTRIBUTE_PURE
411 # endif
412 #endif
413
414 #ifndef YY_ATTRIBUTE_UNUSED
415 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
416 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
417 # else
418 # define YY_ATTRIBUTE_UNUSED
419 # endif
420 #endif
421
422 /* Suppress unused-variable warnings by "using" E. */
423 #if ! defined lint || defined __GNUC__
424 # define YYUSE(E) ((void) (E))
425 #else
426 # define YYUSE(E) /* empty */
427 #endif
428
429 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
430 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
431 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
432 _Pragma ("GCC diagnostic push") \
433 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
434 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
435 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
436 _Pragma ("GCC diagnostic pop")
437 #else
438 # define YY_INITIAL_VALUE(Value) Value
439 #endif
440 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
441 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
442 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
443 #endif
444 #ifndef YY_INITIAL_VALUE
445 # define YY_INITIAL_VALUE(Value) /* Nothing. */
446 #endif
447
448 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
449 # define YY_IGNORE_USELESS_CAST_BEGIN \
450 _Pragma ("GCC diagnostic push") \
451 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
452 # define YY_IGNORE_USELESS_CAST_END \
453 _Pragma ("GCC diagnostic pop")
454 #endif
455 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
456 # define YY_IGNORE_USELESS_CAST_BEGIN
457 # define YY_IGNORE_USELESS_CAST_END
458 #endif
459
460
461 #define YY_ASSERT(E) ((void) (0 && (E)))
462
463 #if ! defined yyoverflow || YYERROR_VERBOSE
464
465 /* The parser invokes alloca or xmalloc; define the necessary symbols. */
466
467 # ifdef YYSTACK_USE_ALLOCA
468 # if YYSTACK_USE_ALLOCA
469 # ifdef __GNUC__
470 # define YYSTACK_ALLOC __builtin_alloca
471 # elif defined __BUILTIN_VA_ARG_INCR
472 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
473 # elif defined _AIX
474 # define YYSTACK_ALLOC __alloca
475 # elif defined _MSC_VER
476 # define alloca _alloca
477 # else
478 # define YYSTACK_ALLOC alloca
479 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
480 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
481 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
482 # ifndef EXIT_SUCCESS
483 # define EXIT_SUCCESS 0
484 # endif
485 # endif
486 # endif
487 # endif
488 # endif
489
490 # ifdef YYSTACK_ALLOC
491 /* Pacify GCC's 'empty if-body' warning. */
492 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
493 # ifndef YYSTACK_ALLOC_MAXIMUM
494 /* The OS might guarantee only one guard page at the bottom of the stack,
495 and a page size can be as small as 4096 bytes. So we cannot safely
496 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
497 to allow for a few compiler-allocated temporary stack slots. */
498 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
499 # endif
500 # else
501 # define YYSTACK_ALLOC YYMALLOC
502 # define YYSTACK_FREE YYFREE
503 # ifndef YYSTACK_ALLOC_MAXIMUM
504 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
505 # endif
506 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
507 && ! ((defined YYMALLOC || defined xmalloc) \
508 && (defined YYFREE || defined xfree)))
509 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
510 # ifndef EXIT_SUCCESS
511 # define EXIT_SUCCESS 0
512 # endif
513 # endif
514 # ifndef YYMALLOC
515 # define YYMALLOC xmalloc
516 # if ! defined xmalloc && ! defined EXIT_SUCCESS
517 void *xmalloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
518 # endif
519 # endif
520 # ifndef YYFREE
521 # define YYFREE xfree
522 # if ! defined xfree && ! defined EXIT_SUCCESS
523 void xfree (void *); /* INFRINGES ON USER NAME SPACE */
524 # endif
525 # endif
526 # endif
527 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
528
529
530 #if (! defined yyoverflow \
531 && (! defined __cplusplus \
532 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
533
534 /* A type that is properly aligned for any stack member. */
535 union yyalloc
536 {
537 yy_state_t yyss_alloc;
538 YYSTYPE yyvs_alloc;
539 };
540
541 /* The size of the maximum gap between one aligned stack and the next. */
542 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
543
544 /* The size of an array large to enough to hold all stacks, each with
545 N elements. */
546 # define YYSTACK_BYTES(N) \
547 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
548 + YYSTACK_GAP_MAXIMUM)
549
550 # define YYCOPY_NEEDED 1
551
552 /* Relocate STACK from its old location to the new one. The
553 local variables YYSIZE and YYSTACKSIZE give the old and new number of
554 elements in the stack, and YYPTR gives the new location of the
555 stack. Advance YYPTR to a properly aligned location for the next
556 stack. */
557 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
558 do \
559 { \
560 YYPTRDIFF_T yynewbytes; \
561 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
562 Stack = &yyptr->Stack_alloc; \
563 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
564 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
565 } \
566 while (0)
567
568 #endif
569
570 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
571 /* Copy COUNT objects from SRC to DST. The source and destination do
572 not overlap. */
573 # ifndef YYCOPY
574 # if defined __GNUC__ && 1 < __GNUC__
575 # define YYCOPY(Dst, Src, Count) \
576 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
577 # else
578 # define YYCOPY(Dst, Src, Count) \
579 do \
580 { \
581 YYPTRDIFF_T yyi; \
582 for (yyi = 0; yyi < (Count); yyi++) \
583 (Dst)[yyi] = (Src)[yyi]; \
584 } \
585 while (0)
586 # endif
587 # endif
588 #endif /* !YYCOPY_NEEDED */
589
590 /* YYFINAL -- State number of the termination state. */
591 #define YYFINAL 40
592 /* YYLAST -- Last index in YYTABLE. */
593 #define YYLAST 451
594
595 /* YYNTOKENS -- Number of terminals. */
596 #define YYNTOKENS 68
597 /* YYNNTS -- Number of nonterminals. */
598 #define YYNNTS 13
599 /* YYNRULES -- Number of rules. */
600 #define YYNRULES 69
601 /* YYNSTATES -- Number of states. */
602 #define YYNSTATES 122
603
604 #define YYUNDEFTOK 2
605 #define YYMAXUTOK 299
606
607
608 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
609 as returned by yylex, with out-of-bounds checking. */
610 #define YYTRANSLATE(YYX) \
611 (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
612
613 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
614 as returned by yylex. */
615 static const yytype_int8 yytranslate[] =
616 {
617 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
618 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
619 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
620 2, 2, 2, 62, 2, 2, 2, 54, 39, 2,
621 61, 64, 52, 50, 31, 51, 59, 53, 2, 2,
622 2, 2, 2, 2, 2, 2, 2, 2, 67, 2,
623 43, 33, 44, 34, 49, 2, 2, 2, 2, 2,
624 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
625 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
626 2, 60, 2, 63, 38, 2, 2, 2, 2, 2,
627 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
628 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
629 2, 2, 2, 65, 37, 66, 2, 2, 2, 2,
630 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
631 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
632 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
633 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
634 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
635 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
636 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
637 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
638 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
639 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
640 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
641 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
642 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
643 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
644 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
645 25, 26, 27, 28, 29, 30, 32, 35, 36, 40,
646 41, 42, 45, 46, 47, 48, 55, 56, 57, 58
647 };
648
649 #if YYDEBUG
650 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
651 static const yytype_int16 yyrline[] =
652 {
653 0, 194, 194, 195, 198, 203, 204, 209, 213, 217,
654 221, 225, 229, 233, 237, 243, 250, 260, 269, 276,
655 273, 286, 290, 293, 297, 301, 305, 312, 319, 325,
656 329, 333, 337, 341, 345, 349, 353, 357, 361, 365,
657 369, 373, 377, 381, 385, 389, 393, 397, 401, 412,
658 416, 425, 432, 441, 452, 461, 464, 470, 482, 489,
659 506, 524, 536, 540, 544, 558, 603, 605, 612, 625
660 };
661 #endif
662
663 #if YYDEBUG || YYERROR_VERBOSE || 0
664 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
665 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
666 static const char *const yytname[] =
667 {
668 "$end", "error", "$undefined", "INT", "FLOAT", "RAW_STRING", "STRING",
669 "CHAR", "NAME", "TYPENAME", "COMPLETE", "NAME_OR_INT", "TRUE_KEYWORD",
670 "FALSE_KEYWORD", "STRUCT_KEYWORD", "INTERFACE_KEYWORD", "TYPE_KEYWORD",
671 "CHAN_KEYWORD", "SIZEOF_KEYWORD", "LEN_KEYWORD", "CAP_KEYWORD",
672 "NEW_KEYWORD", "IOTA_KEYWORD", "NIL_KEYWORD", "CONST_KEYWORD",
673 "DOTDOTDOT", "ENTRY", "ERROR", "BYTE_KEYWORD", "DOLLAR_VARIABLE",
674 "ASSIGN_MODIFY", "','", "ABOVE_COMMA", "'='", "'?'", "OROR", "ANDAND",
675 "'|'", "'^'", "'&'", "ANDNOT", "EQUAL", "NOTEQUAL", "'<'", "'>'", "LEQ",
676 "GEQ", "LSH", "RSH", "'@'", "'+'", "'-'", "'*'", "'/'", "'%'", "UNARY",
677 "INCREMENT", "DECREMENT", "LEFT_ARROW", "'.'", "'['", "'('", "'!'",
678 "']'", "')'", "'{'", "'}'", "':'", "$accept", "start", "type_exp",
679 "exp1", "exp", "$@1", "lcurly", "arglist", "rcurly", "string_exp",
680 "variable", "type", "name_not_typename", YY_NULLPTRPTR
681 };
682 #endif
683
684 # ifdef YYPRINT
685 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
686 (internal) symbol number NUM (which must be that of a token). */
687 static const yytype_int16 yytoknum[] =
688 {
689 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
690 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
691 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
692 285, 44, 286, 61, 63, 287, 288, 124, 94, 38,
693 289, 290, 291, 60, 62, 292, 293, 294, 295, 64,
694 43, 45, 42, 47, 37, 296, 297, 298, 299, 46,
695 91, 40, 33, 93, 41, 123, 125, 58
696 };
697 # endif
698
699 #define YYPACT_NINF (-42)
700
701 #define yypact_value_is_default(Yyn) \
702 ((Yyn) == YYPACT_NINF)
703
704 #define YYTABLE_NINF (-1)
705
706 #define yytable_value_is_error(Yyn) \
707 0
708
709 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
710 STATE-NUM. */
711 static const yytype_int16 yypact[] =
712 {
713 49, -42, -42, -42, -42, -42, -42, -42, -42, -42,
714 -38, -42, -42, 49, 49, 49, 49, 49, 49, 49,
715 -42, 27, -42, 34, 187, 45, 16, -42, 11, 53,
716 49, -35, 11, -35, -35, -35, -35, 11, 38, -35,
717 -42, 49, 49, 49, 49, 49, 49, 49, 49, 49,
718 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
719 49, 49, 49, 49, -42, -42, -3, 49, -42, 45,
720 9, 74, 49, -42, 123, 10, -42, 187, 187, 187,
721 88, 241, 266, 290, 313, 334, 353, 353, 368, 368,
722 368, 368, -41, -41, 380, 390, 390, -35, -35, -35,
723 -42, 72, 33, 49, -42, -42, 49, -42, 155, -42,
724 -42, 49, -42, -42, 187, 39, -35, -42, 215, 49,
725 -42, 187
726 };
727
728 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
729 Performed when YYTABLE does not specify something else to do. Zero
730 means the default is an error. */
731 static const yytype_int8 yydefact[] =
732 {
733 0, 51, 54, 59, 52, 69, 67, 53, 62, 63,
734 0, 68, 56, 0, 0, 0, 0, 0, 0, 0,
735 21, 0, 3, 2, 5, 0, 61, 55, 4, 65,
736 0, 12, 0, 8, 10, 9, 7, 66, 0, 11,
737 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
738 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
739 0, 0, 0, 0, 13, 14, 0, 0, 19, 0,
740 0, 0, 0, 64, 0, 0, 28, 6, 50, 49,
741 0, 47, 46, 45, 44, 43, 37, 38, 41, 42,
742 39, 40, 35, 36, 29, 33, 34, 30, 31, 32,
743 17, 15, 0, 22, 66, 25, 0, 60, 0, 58,
744 57, 0, 16, 18, 23, 0, 26, 27, 48, 0,
745 20, 24
746 };
747
748 /* YYPGOTO[NTERM-NUM]. */
749 static const yytype_int8 yypgoto[] =
750 {
751 -42, -42, -42, -4, -13, -42, -42, -42, -42, -42,
752 -42, 51, 17
753 };
754
755 /* YYDEFGOTO[NTERM-NUM]. */
756 static const yytype_int8 yydefgoto[] =
757 {
758 -1, 21, 22, 23, 24, 103, 25, 115, 106, 26,
759 27, 32, 29
760 };
761
762 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
763 positive, shift that token. If negative, reduce the rule whose
764 number is the opposite. If YYTABLE_NINF, syntax error. */
765 static const yytype_int8 yytable[] =
766 {
767 31, 33, 34, 35, 36, 5, 39, 100, 58, 59,
768 60, 61, 62, 63, 38, 64, 65, 74, 66, 67,
769 68, 64, 65, 30, 66, 67, 68, 40, 77, 78,
770 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
771 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
772 99, 28, 1, 2, 6, 3, 4, 5, 6, 108,
773 7, 8, 9, 102, 41, 41, 71, 10, 37, 41,
774 119, 72, 72, 11, 110, 105, 70, 11, 12, 73,
775 107, 75, 112, 101, 0, 0, 0, 13, 14, 0,
776 114, 0, 0, 116, 0, 0, 113, 69, 118, 15,
777 16, 17, 76, 120, 0, 0, 121, 0, 0, 0,
778 18, 19, 0, 0, 20, 0, 0, 0, 42, 0,
779 104, 43, 44, 45, 46, 47, 48, 49, 0, 50,
780 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
781 61, 62, 63, 0, 64, 65, 0, 66, 67, 68,
782 0, 0, 0, 42, 0, 111, 43, 44, 45, 46,
783 47, 48, 49, 0, 50, 51, 52, 53, 54, 55,
784 56, 57, 58, 59, 60, 61, 62, 63, 0, 64,
785 65, 0, 66, 67, 68, 42, 0, 109, 43, 44,
786 45, 46, 47, 48, 49, 0, 50, 51, 52, 53,
787 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
788 0, 64, 65, 0, 66, 67, 68, 42, 0, 117,
789 43, 44, 45, 46, 47, 48, 49, 0, 50, 51,
790 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
791 62, 63, 0, 64, 65, 0, 66, 67, 68, 44,
792 45, 46, 47, 48, 49, 0, 50, 51, 52, 53,
793 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
794 0, 64, 65, 0, 66, 67, 68, 46, 47, 48,
795 49, 0, 50, 51, 52, 53, 54, 55, 56, 57,
796 58, 59, 60, 61, 62, 63, 0, 64, 65, 0,
797 66, 67, 68, 47, 48, 49, 0, 50, 51, 52,
798 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
799 63, 0, 64, 65, 0, 66, 67, 68, 48, 49,
800 0, 50, 51, 52, 53, 54, 55, 56, 57, 58,
801 59, 60, 61, 62, 63, 0, 64, 65, 0, 66,
802 67, 68, 49, 0, 50, 51, 52, 53, 54, 55,
803 56, 57, 58, 59, 60, 61, 62, 63, 0, 64,
804 65, 0, 66, 67, 68, 50, 51, 52, 53, 54,
805 55, 56, 57, 58, 59, 60, 61, 62, 63, 0,
806 64, 65, 0, 66, 67, 68, 52, 53, 54, 55,
807 56, 57, 58, 59, 60, 61, 62, 63, 0, 64,
808 65, 0, 66, 67, 68, 56, 57, 58, 59, 60,
809 61, 62, 63, 0, 64, 65, 0, 66, 67, 68,
810 59, 60, 61, 62, 63, 0, 64, 65, 0, 66,
811 67, 68, 61, 62, 63, 0, 64, 65, 0, 66,
812 67, 68
813 };
814
815 static const yytype_int8 yycheck[] =
816 {
817 13, 14, 15, 16, 17, 8, 19, 10, 49, 50,
818 51, 52, 53, 54, 18, 56, 57, 30, 59, 60,
819 61, 56, 57, 61, 59, 60, 61, 0, 41, 42,
820 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
821 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
822 63, 0, 3, 4, 9, 6, 7, 8, 9, 72,
823 11, 12, 13, 67, 31, 31, 50, 18, 17, 31,
824 31, 61, 61, 28, 64, 66, 25, 28, 29, 26,
825 6, 30, 10, 66, -1, -1, -1, 38, 39, -1,
826 103, -1, -1, 106, -1, -1, 63, 52, 111, 50,
827 51, 52, 64, 64, -1, -1, 119, -1, -1, -1,
828 61, 62, -1, -1, 65, -1, -1, -1, 30, -1,
829 69, 33, 34, 35, 36, 37, 38, 39, -1, 41,
830 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
831 52, 53, 54, -1, 56, 57, -1, 59, 60, 61,
832 -1, -1, -1, 30, -1, 67, 33, 34, 35, 36,
833 37, 38, 39, -1, 41, 42, 43, 44, 45, 46,
834 47, 48, 49, 50, 51, 52, 53, 54, -1, 56,
835 57, -1, 59, 60, 61, 30, -1, 64, 33, 34,
836 35, 36, 37, 38, 39, -1, 41, 42, 43, 44,
837 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
838 -1, 56, 57, -1, 59, 60, 61, 30, -1, 64,
839 33, 34, 35, 36, 37, 38, 39, -1, 41, 42,
840 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
841 53, 54, -1, 56, 57, -1, 59, 60, 61, 34,
842 35, 36, 37, 38, 39, -1, 41, 42, 43, 44,
843 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
844 -1, 56, 57, -1, 59, 60, 61, 36, 37, 38,
845 39, -1, 41, 42, 43, 44, 45, 46, 47, 48,
846 49, 50, 51, 52, 53, 54, -1, 56, 57, -1,
847 59, 60, 61, 37, 38, 39, -1, 41, 42, 43,
848 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
849 54, -1, 56, 57, -1, 59, 60, 61, 38, 39,
850 -1, 41, 42, 43, 44, 45, 46, 47, 48, 49,
851 50, 51, 52, 53, 54, -1, 56, 57, -1, 59,
852 60, 61, 39, -1, 41, 42, 43, 44, 45, 46,
853 47, 48, 49, 50, 51, 52, 53, 54, -1, 56,
854 57, -1, 59, 60, 61, 41, 42, 43, 44, 45,
855 46, 47, 48, 49, 50, 51, 52, 53, 54, -1,
856 56, 57, -1, 59, 60, 61, 43, 44, 45, 46,
857 47, 48, 49, 50, 51, 52, 53, 54, -1, 56,
858 57, -1, 59, 60, 61, 47, 48, 49, 50, 51,
859 52, 53, 54, -1, 56, 57, -1, 59, 60, 61,
860 50, 51, 52, 53, 54, -1, 56, 57, -1, 59,
861 60, 61, 52, 53, 54, -1, 56, 57, -1, 59,
862 60, 61
863 };
864
865 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
866 symbol of state STATE-NUM. */
867 static const yytype_int8 yystos[] =
868 {
869 0, 3, 4, 6, 7, 8, 9, 11, 12, 13,
870 18, 28, 29, 38, 39, 50, 51, 52, 61, 62,
871 65, 69, 70, 71, 72, 74, 77, 78, 79, 80,
872 61, 72, 79, 72, 72, 72, 72, 79, 71, 72,
873 0, 31, 30, 33, 34, 35, 36, 37, 38, 39,
874 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
875 51, 52, 53, 54, 56, 57, 59, 60, 61, 52,
876 79, 50, 61, 26, 72, 79, 64, 72, 72, 72,
877 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
878 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
879 10, 80, 71, 73, 79, 66, 76, 6, 72, 64,
880 64, 67, 10, 63, 72, 75, 72, 64, 72, 31,
881 64, 72
882 };
883
884 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
885 static const yytype_int8 yyr1[] =
886 {
887 0, 68, 69, 69, 70, 71, 71, 72, 72, 72,
888 72, 72, 72, 72, 72, 72, 72, 72, 72, 73,
889 72, 74, 75, 75, 75, 76, 72, 72, 72, 72,
890 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
891 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
892 72, 72, 72, 72, 72, 72, 72, 72, 72, 77,
893 77, 72, 72, 72, 78, 78, 79, 79, 79, 80
894 };
895
896 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
897 static const yytype_int8 yyr2[] =
898 {
899 0, 2, 1, 1, 1, 1, 3, 2, 2, 2,
900 2, 2, 2, 2, 2, 3, 4, 3, 4, 0,
901 5, 1, 0, 1, 3, 1, 4, 4, 3, 3,
902 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
903 3, 3, 3, 3, 3, 3, 3, 3, 5, 3,
904 3, 1, 1, 1, 1, 1, 1, 4, 4, 1,
905 3, 1, 1, 1, 2, 1, 2, 1, 1, 1
906 };
907
908
909 #define yyerrok (yyerrstatus = 0)
910 #define yyclearin (yychar = YYEMPTY)
911 #define YYEMPTY (-2)
912 #define YYEOF 0
913
914 #define YYACCEPT goto yyacceptlab
915 #define YYABORT goto yyabortlab
916 #define YYERROR goto yyerrorlab
917
918
919 #define YYRECOVERING() (!!yyerrstatus)
920
921 #define YYBACKUP(Token, Value) \
922 do \
923 if (yychar == YYEMPTY) \
924 { \
925 yychar = (Token); \
926 yylval = (Value); \
927 YYPOPSTACK (yylen); \
928 yystate = *yyssp; \
929 goto yybackup; \
930 } \
931 else \
932 { \
933 yyerror (YY_("syntax error: cannot back up")); \
934 YYERROR; \
935 } \
936 while (0)
937
938 /* Error token number */
939 #define YYTERROR 1
940 #define YYERRCODE 256
941
942
943
944 /* Enable debugging if requested. */
945 #if YYDEBUG
946
947 # ifndef YYFPRINTF
948 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
949 # define YYFPRINTF fprintf
950 # endif
951
952 # define YYDPRINTF(Args) \
953 do { \
954 if (yydebug) \
955 YYFPRINTF Args; \
956 } while (0)
957
958 /* This macro is provided for backward compatibility. */
959 #ifndef YY_LOCATION_PRINT
960 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
961 #endif
962
963
964 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
965 do { \
966 if (yydebug) \
967 { \
968 YYFPRINTF (stderr, "%s ", Title); \
969 yy_symbol_print (stderr, \
970 Type, Value); \
971 YYFPRINTF (stderr, "\n"); \
972 } \
973 } while (0)
974
975
976 /*-----------------------------------.
977 | Print this symbol's value on YYO. |
978 `-----------------------------------*/
979
980 static void
yy_symbol_value_print(FILE * yyo,int yytype,YYSTYPE const * const yyvaluep)981 yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
982 {
983 FILE *yyoutput = yyo;
984 YYUSE (yyoutput);
985 if (!yyvaluep)
986 return;
987 # ifdef YYPRINT
988 if (yytype < YYNTOKENS)
989 YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
990 # endif
991 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
992 YYUSE (yytype);
993 YY_IGNORE_MAYBE_UNINITIALIZED_END
994 }
995
996
997 /*---------------------------.
998 | Print this symbol on YYO. |
999 `---------------------------*/
1000
1001 static void
yy_symbol_print(FILE * yyo,int yytype,YYSTYPE const * const yyvaluep)1002 yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
1003 {
1004 YYFPRINTF (yyo, "%s %s (",
1005 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1006
1007 yy_symbol_value_print (yyo, yytype, yyvaluep);
1008 YYFPRINTF (yyo, ")");
1009 }
1010
1011 /*------------------------------------------------------------------.
1012 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1013 | TOP (included). |
1014 `------------------------------------------------------------------*/
1015
1016 static void
yy_stack_print(yy_state_t * yybottom,yy_state_t * yytop)1017 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
1018 {
1019 YYFPRINTF (stderr, "Stack now");
1020 for (; yybottom <= yytop; yybottom++)
1021 {
1022 int yybot = *yybottom;
1023 YYFPRINTF (stderr, " %d", yybot);
1024 }
1025 YYFPRINTF (stderr, "\n");
1026 }
1027
1028 # define YY_STACK_PRINT(Bottom, Top) \
1029 do { \
1030 if (yydebug) \
1031 yy_stack_print ((Bottom), (Top)); \
1032 } while (0)
1033
1034
1035 /*------------------------------------------------.
1036 | Report that the YYRULE is going to be reduced. |
1037 `------------------------------------------------*/
1038
1039 static void
yy_reduce_print(yy_state_t * yyssp,YYSTYPE * yyvsp,int yyrule)1040 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule)
1041 {
1042 int yylno = yyrline[yyrule];
1043 int yynrhs = yyr2[yyrule];
1044 int yyi;
1045 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
1046 yyrule - 1, yylno);
1047 /* The symbols being reduced. */
1048 for (yyi = 0; yyi < yynrhs; yyi++)
1049 {
1050 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1051 yy_symbol_print (stderr,
1052 yystos[+yyssp[yyi + 1 - yynrhs]],
1053 &yyvsp[(yyi + 1) - (yynrhs)]
1054 );
1055 YYFPRINTF (stderr, "\n");
1056 }
1057 }
1058
1059 # define YY_REDUCE_PRINT(Rule) \
1060 do { \
1061 if (yydebug) \
1062 yy_reduce_print (yyssp, yyvsp, Rule); \
1063 } while (0)
1064
1065 /* Nonzero means print parse trace. It is left uninitialized so that
1066 multiple parsers can coexist. */
1067 int yydebug;
1068 #else /* !YYDEBUG */
1069 # define YYDPRINTF(Args)
1070 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1071 # define YY_STACK_PRINT(Bottom, Top)
1072 # define YY_REDUCE_PRINT(Rule)
1073 #endif /* !YYDEBUG */
1074
1075
1076 /* YYINITDEPTH -- initial size of the parser's stacks. */
1077 #ifndef YYINITDEPTH
1078 # define YYINITDEPTH 200
1079 #endif
1080
1081 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1082 if the built-in stack extension method is used).
1083
1084 Do not make this value too large; the results are undefined if
1085 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1086 evaluated with infinite-precision integer arithmetic. */
1087
1088 #ifndef YYMAXDEPTH
1089 # define YYMAXDEPTH 10000
1090 #endif
1091
1092
1093 #if YYERROR_VERBOSE
1094
1095 # ifndef yystrlen
1096 # if defined __GLIBC__ && defined _STRING_H
1097 # define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
1098 # else
1099 /* Return the length of YYSTR. */
1100 static YYPTRDIFF_T
yystrlen(const char * yystr)1101 yystrlen (const char *yystr)
1102 {
1103 YYPTRDIFF_T yylen;
1104 for (yylen = 0; yystr[yylen]; yylen++)
1105 continue;
1106 return yylen;
1107 }
1108 # endif
1109 # endif
1110
1111 # ifndef yystpcpy
1112 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1113 # define yystpcpy stpcpy
1114 # else
1115 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1116 YYDEST. */
1117 static char *
yystpcpy(char * yydest,const char * yysrc)1118 yystpcpy (char *yydest, const char *yysrc)
1119 {
1120 char *yyd = yydest;
1121 const char *yys = yysrc;
1122
1123 while ((*yyd++ = *yys++) != '\0')
1124 continue;
1125
1126 return yyd - 1;
1127 }
1128 # endif
1129 # endif
1130
1131 # ifndef yytnamerr
1132 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1133 quotes and backslashes, so that it's suitable for yyerror. The
1134 heuristic is that double-quoting is unnecessary unless the string
1135 contains an apostrophe, a comma, or backslash (other than
1136 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1137 null, do not copy; instead, return the length of what the result
1138 would have been. */
1139 static YYPTRDIFF_T
yytnamerr(char * yyres,const char * yystr)1140 yytnamerr (char *yyres, const char *yystr)
1141 {
1142 if (*yystr == '"')
1143 {
1144 YYPTRDIFF_T yyn = 0;
1145 char const *yyp = yystr;
1146
1147 for (;;)
1148 switch (*++yyp)
1149 {
1150 case '\'':
1151 case ',':
1152 goto do_not_strip_quotes;
1153
1154 case '\\':
1155 if (*++yyp != '\\')
1156 goto do_not_strip_quotes;
1157 else
1158 goto append;
1159
1160 append:
1161 default:
1162 if (yyres)
1163 yyres[yyn] = *yyp;
1164 yyn++;
1165 break;
1166
1167 case '"':
1168 if (yyres)
1169 yyres[yyn] = '\0';
1170 return yyn;
1171 }
1172 do_not_strip_quotes: ;
1173 }
1174
1175 if (yyres)
1176 return yystpcpy (yyres, yystr) - yyres;
1177 else
1178 return yystrlen (yystr);
1179 }
1180 # endif
1181
1182 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1183 about the unexpected token YYTOKEN for the state stack whose top is
1184 YYSSP.
1185
1186 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1187 not large enough to hold the message. In that case, also set
1188 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1189 required number of bytes is too large to store. */
1190 static int
yysyntax_error(YYPTRDIFF_T * yymsg_alloc,char ** yymsg,yy_state_t * yyssp,int yytoken)1191 yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
1192 yy_state_t *yyssp, int yytoken)
1193 {
1194 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1195 /* Internationalized format string. */
1196 const char *yyformat = YY_NULLPTRPTR;
1197 /* Arguments of yyformat: reported tokens (one for the "unexpected",
1198 one per "expected"). */
1199 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1200 /* Actual size of YYARG. */
1201 int yycount = 0;
1202 /* Cumulated lengths of YYARG. */
1203 YYPTRDIFF_T yysize = 0;
1204
1205 /* There are many possibilities here to consider:
1206 - If this state is a consistent state with a default action, then
1207 the only way this function was invoked is if the default action
1208 is an error action. In that case, don't check for expected
1209 tokens because there are none.
1210 - The only way there can be no lookahead present (in yychar) is if
1211 this state is a consistent state with a default action. Thus,
1212 detecting the absence of a lookahead is sufficient to determine
1213 that there is no unexpected or expected token to report. In that
1214 case, just report a simple "syntax error".
1215 - Don't assume there isn't a lookahead just because this state is a
1216 consistent state with a default action. There might have been a
1217 previous inconsistent state, consistent state with a non-default
1218 action, or user semantic action that manipulated yychar.
1219 - Of course, the expected token list depends on states to have
1220 correct lookahead information, and it depends on the parser not
1221 to perform extra reductions after fetching a lookahead from the
1222 scanner and before detecting a syntax error. Thus, state merging
1223 (from LALR or IELR) and default reductions corrupt the expected
1224 token list. However, the list is correct for canonical LR with
1225 one exception: it will still contain any token that will not be
1226 accepted due to an error action in a later state.
1227 */
1228 if (yytoken != YYEMPTY)
1229 {
1230 int yyn = yypact[+*yyssp];
1231 YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTRPTR, yytname[yytoken]);
1232 yysize = yysize0;
1233 yyarg[yycount++] = yytname[yytoken];
1234 if (!yypact_value_is_default (yyn))
1235 {
1236 /* Start YYX at -YYN if negative to avoid negative indexes in
1237 YYCHECK. In other words, skip the first -YYN actions for
1238 this state because they are default actions. */
1239 int yyxbegin = yyn < 0 ? -yyn : 0;
1240 /* Stay within bounds of both yycheck and yytname. */
1241 int yychecklim = YYLAST - yyn + 1;
1242 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1243 int yyx;
1244
1245 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1246 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1247 && !yytable_value_is_error (yytable[yyx + yyn]))
1248 {
1249 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1250 {
1251 yycount = 1;
1252 yysize = yysize0;
1253 break;
1254 }
1255 yyarg[yycount++] = yytname[yyx];
1256 {
1257 YYPTRDIFF_T yysize1
1258 = yysize + yytnamerr (YY_NULLPTRPTR, yytname[yyx]);
1259 if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
1260 yysize = yysize1;
1261 else
1262 return 2;
1263 }
1264 }
1265 }
1266 }
1267
1268 switch (yycount)
1269 {
1270 # define YYCASE_(N, S) \
1271 case N: \
1272 yyformat = S; \
1273 break
1274 default: /* Avoid compiler warnings. */
1275 YYCASE_(0, YY_("syntax error"));
1276 YYCASE_(1, YY_("syntax error, unexpected %s"));
1277 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1278 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1279 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1280 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1281 # undef YYCASE_
1282 }
1283
1284 {
1285 /* Don't count the "%s"s in the final size, but reserve room for
1286 the terminator. */
1287 YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1;
1288 if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
1289 yysize = yysize1;
1290 else
1291 return 2;
1292 }
1293
1294 if (*yymsg_alloc < yysize)
1295 {
1296 *yymsg_alloc = 2 * yysize;
1297 if (! (yysize <= *yymsg_alloc
1298 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1299 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1300 return 1;
1301 }
1302
1303 /* Avoid sprintf, as that infringes on the user's name space.
1304 Don't have undefined behavior even if the translation
1305 produced a string with the wrong number of "%s"s. */
1306 {
1307 char *yyp = *yymsg;
1308 int yyi = 0;
1309 while ((*yyp = *yyformat) != '\0')
1310 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1311 {
1312 yyp += yytnamerr (yyp, yyarg[yyi++]);
1313 yyformat += 2;
1314 }
1315 else
1316 {
1317 ++yyp;
1318 ++yyformat;
1319 }
1320 }
1321 return 0;
1322 }
1323 #endif /* YYERROR_VERBOSE */
1324
1325 /*-----------------------------------------------.
1326 | Release the memory associated to this symbol. |
1327 `-----------------------------------------------*/
1328
1329 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep)1330 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1331 {
1332 YYUSE (yyvaluep);
1333 if (!yymsg)
1334 yymsg = "Deleting";
1335 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1336
1337 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1338 YYUSE (yytype);
1339 YY_IGNORE_MAYBE_UNINITIALIZED_END
1340 }
1341
1342
1343
1344
1345 /* The lookahead symbol. */
1346 int yychar;
1347
1348 /* The semantic value of the lookahead symbol. */
1349 YYSTYPE yylval;
1350 /* Number of syntax errors so far. */
1351 int yynerrs;
1352
1353
1354 /*----------.
1355 | yyparse. |
1356 `----------*/
1357
1358 int
yyparse(void)1359 yyparse (void)
1360 {
1361 yy_state_fast_t yystate;
1362 /* Number of tokens to shift before error messages enabled. */
1363 int yyerrstatus;
1364
1365 /* The stacks and their tools:
1366 'yyss': related to states.
1367 'yyvs': related to semantic values.
1368
1369 Refer to the stacks through separate pointers, to allow yyoverflow
1370 to xreallocate them elsewhere. */
1371
1372 /* The state stack. */
1373 yy_state_t yyssa[YYINITDEPTH];
1374 yy_state_t *yyss;
1375 yy_state_t *yyssp;
1376
1377 /* The semantic value stack. */
1378 YYSTYPE yyvsa[YYINITDEPTH];
1379 YYSTYPE *yyvs;
1380 YYSTYPE *yyvsp;
1381
1382 YYPTRDIFF_T yystacksize;
1383
1384 int yyn;
1385 int yyresult;
1386 /* Lookahead token as an internal (translated) token number. */
1387 int yytoken = 0;
1388 /* The variables used to return semantic value and location from the
1389 action routines. */
1390 YYSTYPE yyval;
1391
1392 #if YYERROR_VERBOSE
1393 /* Buffer for error messages, and its allocated size. */
1394 char yymsgbuf[128];
1395 char *yymsg = yymsgbuf;
1396 YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
1397 #endif
1398
1399 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1400
1401 /* The number of symbols on the RHS of the reduced rule.
1402 Keep to zero when no symbol should be popped. */
1403 int yylen = 0;
1404
1405 yyssp = yyss = yyssa;
1406 yyvsp = yyvs = yyvsa;
1407 yystacksize = YYINITDEPTH;
1408
1409 YYDPRINTF ((stderr, "Starting parse\n"));
1410
1411 yystate = 0;
1412 yyerrstatus = 0;
1413 yynerrs = 0;
1414 yychar = YYEMPTY; /* Cause a token to be read. */
1415 goto yysetstate;
1416
1417
1418 /*------------------------------------------------------------.
1419 | yynewstate -- push a new state, which is found in yystate. |
1420 `------------------------------------------------------------*/
1421 yynewstate:
1422 /* In all cases, when you get here, the value and location stacks
1423 have just been pushed. So pushing a state here evens the stacks. */
1424 yyssp++;
1425
1426
1427 /*--------------------------------------------------------------------.
1428 | yysetstate -- set current state (the top of the stack) to yystate. |
1429 `--------------------------------------------------------------------*/
1430 yysetstate:
1431 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1432 YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1433 YY_IGNORE_USELESS_CAST_BEGIN
1434 *yyssp = YY_CAST (yy_state_t, yystate);
1435 YY_IGNORE_USELESS_CAST_END
1436
1437 if (yyss + yystacksize - 1 <= yyssp)
1438 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1439 goto yyexhaustedlab;
1440 #else
1441 {
1442 /* Get the current used size of the three stacks, in elements. */
1443 YYPTRDIFF_T yysize = yyssp - yyss + 1;
1444
1445 # if defined yyoverflow
1446 {
1447 /* Give user a chance to xreallocate the stack. Use copies of
1448 these so that the &'s don't force the real ones into
1449 memory. */
1450 yy_state_t *yyss1 = yyss;
1451 YYSTYPE *yyvs1 = yyvs;
1452
1453 /* Each stack pointer address is followed by the size of the
1454 data in use in that stack, in bytes. This used to be a
1455 conditional around just the two extra args, but that might
1456 be undefined if yyoverflow is a macro. */
1457 yyoverflow (YY_("memory exhausted"),
1458 &yyss1, yysize * YYSIZEOF (*yyssp),
1459 &yyvs1, yysize * YYSIZEOF (*yyvsp),
1460 &yystacksize);
1461 yyss = yyss1;
1462 yyvs = yyvs1;
1463 }
1464 # else /* defined YYSTACK_RELOCATE */
1465 /* Extend the stack our own way. */
1466 if (YYMAXDEPTH <= yystacksize)
1467 goto yyexhaustedlab;
1468 yystacksize *= 2;
1469 if (YYMAXDEPTH < yystacksize)
1470 yystacksize = YYMAXDEPTH;
1471
1472 {
1473 yy_state_t *yyss1 = yyss;
1474 union yyalloc *yyptr =
1475 YY_CAST (union yyalloc *,
1476 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1477 if (! yyptr)
1478 goto yyexhaustedlab;
1479 YYSTACK_RELOCATE (yyss_alloc, yyss);
1480 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1481 # undef YYSTACK_RELOCATE
1482 if (yyss1 != yyssa)
1483 YYSTACK_FREE (yyss1);
1484 }
1485 # endif
1486
1487 yyssp = yyss + yysize - 1;
1488 yyvsp = yyvs + yysize - 1;
1489
1490 YY_IGNORE_USELESS_CAST_BEGIN
1491 YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1492 YY_CAST (long, yystacksize)));
1493 YY_IGNORE_USELESS_CAST_END
1494
1495 if (yyss + yystacksize - 1 <= yyssp)
1496 YYABORT;
1497 }
1498 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1499
1500 if (yystate == YYFINAL)
1501 YYACCEPT;
1502
1503 goto yybackup;
1504
1505
1506 /*-----------.
1507 | yybackup. |
1508 `-----------*/
1509 yybackup:
1510 /* Do appropriate processing given the current state. Read a
1511 lookahead token if we need one and don't already have one. */
1512
1513 /* First try to decide what to do without reference to lookahead token. */
1514 yyn = yypact[yystate];
1515 if (yypact_value_is_default (yyn))
1516 goto yydefault;
1517
1518 /* Not known => get a lookahead token if don't already have one. */
1519
1520 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1521 if (yychar == YYEMPTY)
1522 {
1523 YYDPRINTF ((stderr, "Reading a token: "));
1524 yychar = yylex ();
1525 }
1526
1527 if (yychar <= YYEOF)
1528 {
1529 yychar = yytoken = YYEOF;
1530 YYDPRINTF ((stderr, "Now at end of input.\n"));
1531 }
1532 else
1533 {
1534 yytoken = YYTRANSLATE (yychar);
1535 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1536 }
1537
1538 /* If the proper action on seeing token YYTOKEN is to reduce or to
1539 detect an error, take that action. */
1540 yyn += yytoken;
1541 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1542 goto yydefault;
1543 yyn = yytable[yyn];
1544 if (yyn <= 0)
1545 {
1546 if (yytable_value_is_error (yyn))
1547 goto yyerrlab;
1548 yyn = -yyn;
1549 goto yyreduce;
1550 }
1551
1552 /* Count tokens shifted since error; after three, turn off error
1553 status. */
1554 if (yyerrstatus)
1555 yyerrstatus--;
1556
1557 /* Shift the lookahead token. */
1558 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1559 yystate = yyn;
1560 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1561 *++yyvsp = yylval;
1562 YY_IGNORE_MAYBE_UNINITIALIZED_END
1563
1564 /* Discard the shifted token. */
1565 yychar = YYEMPTY;
1566 goto yynewstate;
1567
1568
1569 /*-----------------------------------------------------------.
1570 | yydefault -- do the default action for the current state. |
1571 `-----------------------------------------------------------*/
1572 yydefault:
1573 yyn = yydefact[yystate];
1574 if (yyn == 0)
1575 goto yyerrlab;
1576 goto yyreduce;
1577
1578
1579 /*-----------------------------.
1580 | yyreduce -- do a reduction. |
1581 `-----------------------------*/
1582 yyreduce:
1583 /* yyn is the number of a rule to reduce with. */
1584 yylen = yyr2[yyn];
1585
1586 /* If YYLEN is nonzero, implement the default value of the action:
1587 '$$ = $1'.
1588
1589 Otherwise, the following line sets YYVAL to garbage.
1590 This behavior is undocumented and Bison
1591 users should not rely upon it. Assigning to YYVAL
1592 unconditionally makes the parser a bit smaller, and it avoids a
1593 GCC warning that YYVAL may be used uninitialized. */
1594 yyval = yyvsp[1-yylen];
1595
1596
1597 YY_REDUCE_PRINT (yyn);
1598 switch (yyn)
1599 {
1600 case 4:
1601 #line 199 "go-exp.y"
1602 { pstate->push_new<type_operation> ((yyvsp[0].tval)); }
1603 #line 1605 "go-exp.c.tmp"
1604 break;
1605
1606 case 6:
1607 #line 205 "go-exp.y"
1608 { pstate->wrap2<comma_operation> (); }
1609 #line 1611 "go-exp.c.tmp"
1610 break;
1611
1612 case 7:
1613 #line 210 "go-exp.y"
1614 { pstate->wrap<unop_ind_operation> (); }
1615 #line 1617 "go-exp.c.tmp"
1616 break;
1617
1618 case 8:
1619 #line 214 "go-exp.y"
1620 { pstate->wrap<unop_addr_operation> (); }
1621 #line 1623 "go-exp.c.tmp"
1622 break;
1623
1624 case 9:
1625 #line 218 "go-exp.y"
1626 { pstate->wrap<unary_neg_operation> (); }
1627 #line 1629 "go-exp.c.tmp"
1628 break;
1629
1630 case 10:
1631 #line 222 "go-exp.y"
1632 { pstate->wrap<unary_plus_operation> (); }
1633 #line 1635 "go-exp.c.tmp"
1634 break;
1635
1636 case 11:
1637 #line 226 "go-exp.y"
1638 { pstate->wrap<unary_logical_not_operation> (); }
1639 #line 1641 "go-exp.c.tmp"
1640 break;
1641
1642 case 12:
1643 #line 230 "go-exp.y"
1644 { pstate->wrap<unary_complement_operation> (); }
1645 #line 1647 "go-exp.c.tmp"
1646 break;
1647
1648 case 13:
1649 #line 234 "go-exp.y"
1650 { pstate->wrap<postinc_operation> (); }
1651 #line 1653 "go-exp.c.tmp"
1652 break;
1653
1654 case 14:
1655 #line 238 "go-exp.y"
1656 { pstate->wrap<postdec_operation> (); }
1657 #line 1659 "go-exp.c.tmp"
1658 break;
1659
1660 case 15:
1661 #line 244 "go-exp.y"
1662 {
1663 pstate->push_new<structop_operation>
1664 (pstate->pop (), copy_name ((yyvsp[0].ssym).stoken));
1665 }
1666 #line 1668 "go-exp.c.tmp"
1667 break;
1668
1669 case 16:
1670 #line 251 "go-exp.y"
1671 {
1672 structop_base_operation *op
1673 = new structop_operation (pstate->pop (),
1674 copy_name ((yyvsp[-1].ssym).stoken));
1675 pstate->mark_struct_expression (op);
1676 pstate->push (operation_up (op));
1677 }
1678 #line 1680 "go-exp.c.tmp"
1679 break;
1680
1681 case 17:
1682 #line 261 "go-exp.y"
1683 {
1684 structop_base_operation *op
1685 = new structop_operation (pstate->pop (), "");
1686 pstate->mark_struct_expression (op);
1687 pstate->push (operation_up (op));
1688 }
1689 #line 1691 "go-exp.c.tmp"
1690 break;
1691
1692 case 18:
1693 #line 270 "go-exp.y"
1694 { pstate->wrap2<subscript_operation> (); }
1695 #line 1697 "go-exp.c.tmp"
1696 break;
1697
1698 case 19:
1699 #line 276 "go-exp.y"
1700 { pstate->start_arglist (); }
1701 #line 1703 "go-exp.c.tmp"
1702 break;
1703
1704 case 20:
1705 #line 278 "go-exp.y"
1706 {
1707 std::vector<operation_up> args
1708 = pstate->pop_vector (pstate->end_arglist ());
1709 pstate->push_new<funcall_operation>
1710 (pstate->pop (), std::move (args));
1711 }
1712 #line 1714 "go-exp.c.tmp"
1713 break;
1714
1715 case 21:
1716 #line 287 "go-exp.y"
1717 { pstate->start_arglist (); }
1718 #line 1720 "go-exp.c.tmp"
1719 break;
1720
1721 case 23:
1722 #line 294 "go-exp.y"
1723 { pstate->arglist_len = 1; }
1724 #line 1726 "go-exp.c.tmp"
1725 break;
1726
1727 case 24:
1728 #line 298 "go-exp.y"
1729 { pstate->arglist_len++; }
1730 #line 1732 "go-exp.c.tmp"
1731 break;
1732
1733 case 25:
1734 #line 302 "go-exp.y"
1735 { (yyval.lval) = pstate->end_arglist () - 1; }
1736 #line 1738 "go-exp.c.tmp"
1737 break;
1738
1739 case 26:
1740 #line 306 "go-exp.y"
1741 {
1742 pstate->push_new<unop_memval_operation>
1743 (pstate->pop (), (yyvsp[-2].tval));
1744 }
1745 #line 1747 "go-exp.c.tmp"
1746 break;
1747
1748 case 27:
1749 #line 313 "go-exp.y"
1750 {
1751 pstate->push_new<unop_cast_operation>
1752 (pstate->pop (), (yyvsp[-3].tval));
1753 }
1754 #line 1756 "go-exp.c.tmp"
1755 break;
1756
1757 case 28:
1758 #line 320 "go-exp.y"
1759 { }
1760 #line 1762 "go-exp.c.tmp"
1761 break;
1762
1763 case 29:
1764 #line 326 "go-exp.y"
1765 { pstate->wrap2<repeat_operation> (); }
1766 #line 1768 "go-exp.c.tmp"
1767 break;
1768
1769 case 30:
1770 #line 330 "go-exp.y"
1771 { pstate->wrap2<mul_operation> (); }
1772 #line 1774 "go-exp.c.tmp"
1773 break;
1774
1775 case 31:
1776 #line 334 "go-exp.y"
1777 { pstate->wrap2<div_operation> (); }
1778 #line 1780 "go-exp.c.tmp"
1779 break;
1780
1781 case 32:
1782 #line 338 "go-exp.y"
1783 { pstate->wrap2<rem_operation> (); }
1784 #line 1786 "go-exp.c.tmp"
1785 break;
1786
1787 case 33:
1788 #line 342 "go-exp.y"
1789 { pstate->wrap2<add_operation> (); }
1790 #line 1792 "go-exp.c.tmp"
1791 break;
1792
1793 case 34:
1794 #line 346 "go-exp.y"
1795 { pstate->wrap2<sub_operation> (); }
1796 #line 1798 "go-exp.c.tmp"
1797 break;
1798
1799 case 35:
1800 #line 350 "go-exp.y"
1801 { pstate->wrap2<lsh_operation> (); }
1802 #line 1804 "go-exp.c.tmp"
1803 break;
1804
1805 case 36:
1806 #line 354 "go-exp.y"
1807 { pstate->wrap2<rsh_operation> (); }
1808 #line 1810 "go-exp.c.tmp"
1809 break;
1810
1811 case 37:
1812 #line 358 "go-exp.y"
1813 { pstate->wrap2<equal_operation> (); }
1814 #line 1816 "go-exp.c.tmp"
1815 break;
1816
1817 case 38:
1818 #line 362 "go-exp.y"
1819 { pstate->wrap2<notequal_operation> (); }
1820 #line 1822 "go-exp.c.tmp"
1821 break;
1822
1823 case 39:
1824 #line 366 "go-exp.y"
1825 { pstate->wrap2<leq_operation> (); }
1826 #line 1828 "go-exp.c.tmp"
1827 break;
1828
1829 case 40:
1830 #line 370 "go-exp.y"
1831 { pstate->wrap2<geq_operation> (); }
1832 #line 1834 "go-exp.c.tmp"
1833 break;
1834
1835 case 41:
1836 #line 374 "go-exp.y"
1837 { pstate->wrap2<less_operation> (); }
1838 #line 1840 "go-exp.c.tmp"
1839 break;
1840
1841 case 42:
1842 #line 378 "go-exp.y"
1843 { pstate->wrap2<gtr_operation> (); }
1844 #line 1846 "go-exp.c.tmp"
1845 break;
1846
1847 case 43:
1848 #line 382 "go-exp.y"
1849 { pstate->wrap2<bitwise_and_operation> (); }
1850 #line 1852 "go-exp.c.tmp"
1851 break;
1852
1853 case 44:
1854 #line 386 "go-exp.y"
1855 { pstate->wrap2<bitwise_xor_operation> (); }
1856 #line 1858 "go-exp.c.tmp"
1857 break;
1858
1859 case 45:
1860 #line 390 "go-exp.y"
1861 { pstate->wrap2<bitwise_ior_operation> (); }
1862 #line 1864 "go-exp.c.tmp"
1863 break;
1864
1865 case 46:
1866 #line 394 "go-exp.y"
1867 { pstate->wrap2<logical_and_operation> (); }
1868 #line 1870 "go-exp.c.tmp"
1869 break;
1870
1871 case 47:
1872 #line 398 "go-exp.y"
1873 { pstate->wrap2<logical_or_operation> (); }
1874 #line 1876 "go-exp.c.tmp"
1875 break;
1876
1877 case 48:
1878 #line 402 "go-exp.y"
1879 {
1880 operation_up last = pstate->pop ();
1881 operation_up mid = pstate->pop ();
1882 operation_up first = pstate->pop ();
1883 pstate->push_new<ternop_cond_operation>
1884 (std::move (first), std::move (mid),
1885 std::move (last));
1886 }
1887 #line 1889 "go-exp.c.tmp"
1888 break;
1889
1890 case 49:
1891 #line 413 "go-exp.y"
1892 { pstate->wrap2<assign_operation> (); }
1893 #line 1895 "go-exp.c.tmp"
1894 break;
1895
1896 case 50:
1897 #line 417 "go-exp.y"
1898 {
1899 operation_up rhs = pstate->pop ();
1900 operation_up lhs = pstate->pop ();
1901 pstate->push_new<assign_modify_operation>
1902 ((yyvsp[-1].opcode), std::move (lhs), std::move (rhs));
1903 }
1904 #line 1906 "go-exp.c.tmp"
1905 break;
1906
1907 case 51:
1908 #line 426 "go-exp.y"
1909 {
1910 pstate->push_new<long_const_operation>
1911 ((yyvsp[0].typed_val_int).type, (yyvsp[0].typed_val_int).val);
1912 }
1913 #line 1915 "go-exp.c.tmp"
1914 break;
1915
1916 case 52:
1917 #line 433 "go-exp.y"
1918 {
1919 struct stoken_vector vec;
1920 vec.len = 1;
1921 vec.tokens = &(yyvsp[0].tsval);
1922 pstate->push_c_string ((yyvsp[0].tsval).type, &vec);
1923 }
1924 #line 1926 "go-exp.c.tmp"
1925 break;
1926
1927 case 53:
1928 #line 442 "go-exp.y"
1929 { YYSTYPE val;
1930 parse_number (pstate, (yyvsp[0].ssym).stoken.ptr,
1931 (yyvsp[0].ssym).stoken.length, 0, &val);
1932 pstate->push_new<long_const_operation>
1933 (val.typed_val_int.type,
1934 val.typed_val_int.val);
1935 }
1936 #line 1938 "go-exp.c.tmp"
1937 break;
1938
1939 case 54:
1940 #line 453 "go-exp.y"
1941 {
1942 float_data data;
1943 std::copy (std::begin ((yyvsp[0].typed_val_float).val), std::end ((yyvsp[0].typed_val_float).val),
1944 std::begin (data));
1945 pstate->push_new<float_const_operation> ((yyvsp[0].typed_val_float).type, data);
1946 }
1947 #line 1949 "go-exp.c.tmp"
1948 break;
1949
1950 case 56:
1951 #line 465 "go-exp.y"
1952 {
1953 pstate->push_dollar ((yyvsp[0].sval));
1954 }
1955 #line 1957 "go-exp.c.tmp"
1956 break;
1957
1958 case 57:
1959 #line 471 "go-exp.y"
1960 {
1961 /* TODO(dje): Go objects in structs. */
1962 /* TODO(dje): What's the right type here? */
1963 struct type *size_type
1964 = parse_type (pstate)->builtin_unsigned_int;
1965 (yyvsp[-1].tval) = check_typedef ((yyvsp[-1].tval));
1966 pstate->push_new<long_const_operation>
1967 (size_type, (LONGEST) TYPE_LENGTH ((yyvsp[-1].tval)));
1968 }
1969 #line 1971 "go-exp.c.tmp"
1970 break;
1971
1972 case 58:
1973 #line 483 "go-exp.y"
1974 {
1975 /* TODO(dje): Go objects in structs. */
1976 pstate->wrap<unop_sizeof_operation> ();
1977 }
1978 #line 1980 "go-exp.c.tmp"
1979 break;
1980
1981 case 59:
1982 #line 490 "go-exp.y"
1983 {
1984 /* We copy the string here, and not in the
1985 lexer, to guarantee that we do not leak a
1986 string. */
1987 /* Note that we NUL-terminate here, but just
1988 for convenience. */
1989 struct typed_stoken *vec = XNEW (struct typed_stoken);
1990 (yyval.svec).len = 1;
1991 (yyval.svec).tokens = vec;
1992
1993 vec->type = (yyvsp[0].tsval).type;
1994 vec->length = (yyvsp[0].tsval).length;
1995 vec->ptr = (char *) xmalloc ((yyvsp[0].tsval).length + 1);
1996 memcpy (vec->ptr, (yyvsp[0].tsval).ptr, (yyvsp[0].tsval).length + 1);
1997 }
1998 #line 2000 "go-exp.c.tmp"
1999 break;
2000
2001 case 60:
2002 #line 507 "go-exp.y"
2003 {
2004 /* Note that we NUL-terminate here, but just
2005 for convenience. */
2006 char *p;
2007 ++(yyval.svec).len;
2008 (yyval.svec).tokens = XRESIZEVEC (struct typed_stoken,
2009 (yyval.svec).tokens, (yyval.svec).len);
2010
2011 p = (char *) xmalloc ((yyvsp[0].tsval).length + 1);
2012 memcpy (p, (yyvsp[0].tsval).ptr, (yyvsp[0].tsval).length + 1);
2013
2014 (yyval.svec).tokens[(yyval.svec).len - 1].type = (yyvsp[0].tsval).type;
2015 (yyval.svec).tokens[(yyval.svec).len - 1].length = (yyvsp[0].tsval).length;
2016 (yyval.svec).tokens[(yyval.svec).len - 1].ptr = p;
2017 }
2018 #line 2020 "go-exp.c.tmp"
2019 break;
2020
2021 case 61:
2022 #line 525 "go-exp.y"
2023 {
2024 int i;
2025
2026 /* Always utf8. */
2027 pstate->push_c_string (0, &(yyvsp[0].svec));
2028 for (i = 0; i < (yyvsp[0].svec).len; ++i)
2029 xfree ((yyvsp[0].svec).tokens[i].ptr);
2030 xfree ((yyvsp[0].svec).tokens);
2031 }
2032 #line 2034 "go-exp.c.tmp"
2033 break;
2034
2035 case 62:
2036 #line 537 "go-exp.y"
2037 { pstate->push_new<bool_operation> ((yyvsp[0].lval)); }
2038 #line 2040 "go-exp.c.tmp"
2039 break;
2040
2041 case 63:
2042 #line 541 "go-exp.y"
2043 { pstate->push_new<bool_operation> ((yyvsp[0].lval)); }
2044 #line 2046 "go-exp.c.tmp"
2045 break;
2046
2047 case 64:
2048 #line 545 "go-exp.y"
2049 { struct symbol *sym = (yyvsp[-1].ssym).sym.symbol;
2050
2051 if (sym == NULL
2052 || !SYMBOL_IS_ARGUMENT (sym)
2053 || !symbol_read_needs_frame (sym))
2054 error (_("@entry can be used only for function "
2055 "parameters, not for \"%s\""),
2056 copy_name ((yyvsp[-1].ssym).stoken).c_str ());
2057
2058 pstate->push_new<var_entry_value_operation> (sym);
2059 }
2060 #line 2062 "go-exp.c.tmp"
2061 break;
2062
2063 case 65:
2064 #line 559 "go-exp.y"
2065 { struct block_symbol sym = (yyvsp[0].ssym).sym;
2066
2067 if (sym.symbol)
2068 {
2069 if (symbol_read_needs_frame (sym.symbol))
2070 pstate->block_tracker->update (sym);
2071
2072 pstate->push_new<var_value_operation> (sym);
2073 }
2074 else if ((yyvsp[0].ssym).is_a_field_of_this)
2075 {
2076 /* TODO(dje): Can we get here?
2077 E.g., via a mix of c++ and go? */
2078 gdb_assert_not_reached ("go with `this' field");
2079 }
2080 else
2081 {
2082 struct bound_minimal_symbol msymbol;
2083 std::string arg = copy_name ((yyvsp[0].ssym).stoken);
2084
2085 msymbol =
2086 lookup_bound_minimal_symbol (arg.c_str ());
2087 if (msymbol.minsym != NULL)
2088 pstate->push_new<var_msym_value_operation>
2089 (msymbol);
2090 else if (!have_full_symbols ()
2091 && !have_partial_symbols ())
2092 error (_("No symbol table is loaded. "
2093 "Use the \"file\" command."));
2094 else
2095 error (_("No symbol \"%s\" in current context."),
2096 arg.c_str ());
2097 }
2098 }
2099 #line 2101 "go-exp.c.tmp"
2100 break;
2101
2102 case 66:
2103 #line 604 "go-exp.y"
2104 { (yyval.tval) = lookup_pointer_type ((yyvsp[0].tval)); }
2105 #line 2107 "go-exp.c.tmp"
2106 break;
2107
2108 case 67:
2109 #line 606 "go-exp.y"
2110 { (yyval.tval) = (yyvsp[0].tsym).type; }
2111 #line 2113 "go-exp.c.tmp"
2112 break;
2113
2114 case 68:
2115 #line 613 "go-exp.y"
2116 { (yyval.tval) = builtin_go_type (pstate->gdbarch ())
2117 ->builtin_uint8; }
2118 #line 2120 "go-exp.c.tmp"
2119 break;
2120
2121
2122 #line 2124 "go-exp.c.tmp"
2123
2124 default: break;
2125 }
2126 /* User semantic actions sometimes alter yychar, and that requires
2127 that yytoken be updated with the new translation. We take the
2128 approach of translating immediately before every use of yytoken.
2129 One alternative is translating here after every semantic action,
2130 but that translation would be missed if the semantic action invokes
2131 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2132 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2133 incorrect destructor might then be invoked immediately. In the
2134 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2135 to an incorrect destructor call or verbose syntax error message
2136 before the lookahead is translated. */
2137 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2138
2139 YYPOPSTACK (yylen);
2140 yylen = 0;
2141 YY_STACK_PRINT (yyss, yyssp);
2142
2143 *++yyvsp = yyval;
2144
2145 /* Now 'shift' the result of the reduction. Determine what state
2146 that goes to, based on the state we popped back to and the rule
2147 number reduced by. */
2148 {
2149 const int yylhs = yyr1[yyn] - YYNTOKENS;
2150 const int yyi = yypgoto[yylhs] + *yyssp;
2151 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
2152 ? yytable[yyi]
2153 : yydefgoto[yylhs]);
2154 }
2155
2156 goto yynewstate;
2157
2158
2159 /*--------------------------------------.
2160 | yyerrlab -- here on detecting error. |
2161 `--------------------------------------*/
2162 yyerrlab:
2163 /* Make sure we have latest lookahead translation. See comments at
2164 user semantic actions for why this is necessary. */
2165 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2166
2167 /* If not already recovering from an error, report this error. */
2168 if (!yyerrstatus)
2169 {
2170 ++yynerrs;
2171 #if ! YYERROR_VERBOSE
2172 yyerror (YY_("syntax error"));
2173 #else
2174 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2175 yyssp, yytoken)
2176 {
2177 char const *yymsgp = YY_("syntax error");
2178 int yysyntax_error_status;
2179 yysyntax_error_status = YYSYNTAX_ERROR;
2180 if (yysyntax_error_status == 0)
2181 yymsgp = yymsg;
2182 else if (yysyntax_error_status == 1)
2183 {
2184 if (yymsg != yymsgbuf)
2185 YYSTACK_FREE (yymsg);
2186 yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
2187 if (!yymsg)
2188 {
2189 yymsg = yymsgbuf;
2190 yymsg_alloc = sizeof yymsgbuf;
2191 yysyntax_error_status = 2;
2192 }
2193 else
2194 {
2195 yysyntax_error_status = YYSYNTAX_ERROR;
2196 yymsgp = yymsg;
2197 }
2198 }
2199 yyerror (yymsgp);
2200 if (yysyntax_error_status == 2)
2201 goto yyexhaustedlab;
2202 }
2203 # undef YYSYNTAX_ERROR
2204 #endif
2205 }
2206
2207
2208
2209 if (yyerrstatus == 3)
2210 {
2211 /* If just tried and failed to reuse lookahead token after an
2212 error, discard it. */
2213
2214 if (yychar <= YYEOF)
2215 {
2216 /* Return failure if at end of input. */
2217 if (yychar == YYEOF)
2218 YYABORT;
2219 }
2220 else
2221 {
2222 yydestruct ("Error: discarding",
2223 yytoken, &yylval);
2224 yychar = YYEMPTY;
2225 }
2226 }
2227
2228 /* Else will try to reuse lookahead token after shifting the error
2229 token. */
2230 goto yyerrlab1;
2231
2232
2233 /*---------------------------------------------------.
2234 | yyerrorlab -- error raised explicitly by YYERROR. |
2235 `---------------------------------------------------*/
2236 yyerrorlab:
2237 /* Pacify compilers when the user code never invokes YYERROR and the
2238 label yyerrorlab therefore never appears in user code. */
2239 if (0)
2240 YYERROR;
2241
2242 /* Do not reclaim the symbols of the rule whose action triggered
2243 this YYERROR. */
2244 YYPOPSTACK (yylen);
2245 yylen = 0;
2246 YY_STACK_PRINT (yyss, yyssp);
2247 yystate = *yyssp;
2248 goto yyerrlab1;
2249
2250
2251 /*-------------------------------------------------------------.
2252 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2253 `-------------------------------------------------------------*/
2254 yyerrlab1:
2255 yyerrstatus = 3; /* Each real token shifted decrements this. */
2256
2257 for (;;)
2258 {
2259 yyn = yypact[yystate];
2260 if (!yypact_value_is_default (yyn))
2261 {
2262 yyn += YYTERROR;
2263 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2264 {
2265 yyn = yytable[yyn];
2266 if (0 < yyn)
2267 break;
2268 }
2269 }
2270
2271 /* Pop the current state because it cannot handle the error token. */
2272 if (yyssp == yyss)
2273 YYABORT;
2274
2275
2276 yydestruct ("Error: popping",
2277 yystos[yystate], yyvsp);
2278 YYPOPSTACK (1);
2279 yystate = *yyssp;
2280 YY_STACK_PRINT (yyss, yyssp);
2281 }
2282
2283 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2284 *++yyvsp = yylval;
2285 YY_IGNORE_MAYBE_UNINITIALIZED_END
2286
2287
2288 /* Shift the error token. */
2289 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2290
2291 yystate = yyn;
2292 goto yynewstate;
2293
2294
2295 /*-------------------------------------.
2296 | yyacceptlab -- YYACCEPT comes here. |
2297 `-------------------------------------*/
2298 yyacceptlab:
2299 yyresult = 0;
2300 goto yyreturn;
2301
2302
2303 /*-----------------------------------.
2304 | yyabortlab -- YYABORT comes here. |
2305 `-----------------------------------*/
2306 yyabortlab:
2307 yyresult = 1;
2308 goto yyreturn;
2309
2310
2311 #if !defined yyoverflow || YYERROR_VERBOSE
2312 /*-------------------------------------------------.
2313 | yyexhaustedlab -- memory exhaustion comes here. |
2314 `-------------------------------------------------*/
2315 yyexhaustedlab:
2316 yyerror (YY_("memory exhausted"));
2317 yyresult = 2;
2318 /* Fall through. */
2319 #endif
2320
2321
2322 /*-----------------------------------------------------.
2323 | yyreturn -- parsing is finished, return the result. |
2324 `-----------------------------------------------------*/
2325 yyreturn:
2326 if (yychar != YYEMPTY)
2327 {
2328 /* Make sure we have latest lookahead translation. See comments at
2329 user semantic actions for why this is necessary. */
2330 yytoken = YYTRANSLATE (yychar);
2331 yydestruct ("Cleanup: discarding lookahead",
2332 yytoken, &yylval);
2333 }
2334 /* Do not reclaim the symbols of the rule whose action triggered
2335 this YYABORT or YYACCEPT. */
2336 YYPOPSTACK (yylen);
2337 YY_STACK_PRINT (yyss, yyssp);
2338 while (yyssp != yyss)
2339 {
2340 yydestruct ("Cleanup: popping",
2341 yystos[+*yyssp], yyvsp);
2342 YYPOPSTACK (1);
2343 }
2344 #ifndef yyoverflow
2345 if (yyss != yyssa)
2346 YYSTACK_FREE (yyss);
2347 #endif
2348 #if YYERROR_VERBOSE
2349 if (yymsg != yymsgbuf)
2350 YYSTACK_FREE (yymsg);
2351 #endif
2352 return yyresult;
2353 }
2354 #line 635 "go-exp.y"
2355
2356
2357 /* Take care of parsing a number (anything that starts with a digit).
2358 Set yylval and return the token type; update lexptr.
2359 LEN is the number of characters in it. */
2360
2361 /* FIXME: Needs some error checking for the float case. */
2362 /* FIXME(dje): IWBN to use c-exp.y's parse_number if we could.
2363 That will require moving the guts into a function that we both call
2364 as our YYSTYPE is different than c-exp.y's */
2365
2366 static int
parse_number(struct parser_state * par_state,const char * p,int len,int parsed_float,YYSTYPE * putithere)2367 parse_number (struct parser_state *par_state,
2368 const char *p, int len, int parsed_float, YYSTYPE *putithere)
2369 {
2370 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
2371 here, and we do kind of silly things like cast to unsigned. */
2372 LONGEST n = 0;
2373 LONGEST prevn = 0;
2374 ULONGEST un;
2375
2376 int i = 0;
2377 int c;
2378 int base = input_radix;
2379 int unsigned_p = 0;
2380
2381 /* Number of "L" suffixes encountered. */
2382 int long_p = 0;
2383
2384 /* We have found a "L" or "U" suffix. */
2385 int found_suffix = 0;
2386
2387 ULONGEST high_bit;
2388 struct type *signed_type;
2389 struct type *unsigned_type;
2390
2391 if (parsed_float)
2392 {
2393 const struct builtin_go_type *builtin_go_types
2394 = builtin_go_type (par_state->gdbarch ());
2395
2396 /* Handle suffixes: 'f' for float32, 'l' for long double.
2397 FIXME: This appears to be an extension -- do we want this? */
2398 if (len >= 1 && tolower (p[len - 1]) == 'f')
2399 {
2400 putithere->typed_val_float.type
2401 = builtin_go_types->builtin_float32;
2402 len--;
2403 }
2404 else if (len >= 1 && tolower (p[len - 1]) == 'l')
2405 {
2406 putithere->typed_val_float.type
2407 = parse_type (par_state)->builtin_long_double;
2408 len--;
2409 }
2410 /* Default type for floating-point literals is float64. */
2411 else
2412 {
2413 putithere->typed_val_float.type
2414 = builtin_go_types->builtin_float64;
2415 }
2416
2417 if (!parse_float (p, len,
2418 putithere->typed_val_float.type,
2419 putithere->typed_val_float.val))
2420 return ERROR;
2421 return FLOAT;
2422 }
2423
2424 /* Handle base-switching prefixes 0x, 0t, 0d, 0. */
2425 if (p[0] == '0')
2426 switch (p[1])
2427 {
2428 case 'x':
2429 case 'X':
2430 if (len >= 3)
2431 {
2432 p += 2;
2433 base = 16;
2434 len -= 2;
2435 }
2436 break;
2437
2438 case 'b':
2439 case 'B':
2440 if (len >= 3)
2441 {
2442 p += 2;
2443 base = 2;
2444 len -= 2;
2445 }
2446 break;
2447
2448 case 't':
2449 case 'T':
2450 case 'd':
2451 case 'D':
2452 if (len >= 3)
2453 {
2454 p += 2;
2455 base = 10;
2456 len -= 2;
2457 }
2458 break;
2459
2460 default:
2461 base = 8;
2462 break;
2463 }
2464
2465 while (len-- > 0)
2466 {
2467 c = *p++;
2468 if (c >= 'A' && c <= 'Z')
2469 c += 'a' - 'A';
2470 if (c != 'l' && c != 'u')
2471 n *= base;
2472 if (c >= '0' && c <= '9')
2473 {
2474 if (found_suffix)
2475 return ERROR;
2476 n += i = c - '0';
2477 }
2478 else
2479 {
2480 if (base > 10 && c >= 'a' && c <= 'f')
2481 {
2482 if (found_suffix)
2483 return ERROR;
2484 n += i = c - 'a' + 10;
2485 }
2486 else if (c == 'l')
2487 {
2488 ++long_p;
2489 found_suffix = 1;
2490 }
2491 else if (c == 'u')
2492 {
2493 unsigned_p = 1;
2494 found_suffix = 1;
2495 }
2496 else
2497 return ERROR; /* Char not a digit */
2498 }
2499 if (i >= base)
2500 return ERROR; /* Invalid digit in this base. */
2501
2502 /* Portably test for overflow (only works for nonzero values, so make
2503 a second check for zero). FIXME: Can't we just make n and prevn
2504 unsigned and avoid this? */
2505 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
2506 unsigned_p = 1; /* Try something unsigned. */
2507
2508 /* Portably test for unsigned overflow.
2509 FIXME: This check is wrong; for example it doesn't find overflow
2510 on 0x123456789 when LONGEST is 32 bits. */
2511 if (c != 'l' && c != 'u' && n != 0)
2512 {
2513 if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
2514 error (_("Numeric constant too large."));
2515 }
2516 prevn = n;
2517 }
2518
2519 /* An integer constant is an int, a long, or a long long. An L
2520 suffix forces it to be long; an LL suffix forces it to be long
2521 long. If not forced to a larger size, it gets the first type of
2522 the above that it fits in. To figure out whether it fits, we
2523 shift it right and see whether anything remains. Note that we
2524 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
2525 operation, because many compilers will warn about such a shift
2526 (which always produces a zero result). Sometimes gdbarch_int_bit
2527 or gdbarch_long_bit will be that big, sometimes not. To deal with
2528 the case where it is we just always shift the value more than
2529 once, with fewer bits each time. */
2530
2531 un = (ULONGEST)n >> 2;
2532 if (long_p == 0
2533 && (un >> (gdbarch_int_bit (par_state->gdbarch ()) - 2)) == 0)
2534 {
2535 high_bit
2536 = ((ULONGEST)1) << (gdbarch_int_bit (par_state->gdbarch ()) - 1);
2537
2538 /* A large decimal (not hex or octal) constant (between INT_MAX
2539 and UINT_MAX) is a long or unsigned long, according to ANSI,
2540 never an unsigned int, but this code treats it as unsigned
2541 int. This probably should be fixed. GCC gives a warning on
2542 such constants. */
2543
2544 unsigned_type = parse_type (par_state)->builtin_unsigned_int;
2545 signed_type = parse_type (par_state)->builtin_int;
2546 }
2547 else if (long_p <= 1
2548 && (un >> (gdbarch_long_bit (par_state->gdbarch ()) - 2)) == 0)
2549 {
2550 high_bit
2551 = ((ULONGEST)1) << (gdbarch_long_bit (par_state->gdbarch ()) - 1);
2552 unsigned_type = parse_type (par_state)->builtin_unsigned_long;
2553 signed_type = parse_type (par_state)->builtin_long;
2554 }
2555 else
2556 {
2557 int shift;
2558 if (sizeof (ULONGEST) * HOST_CHAR_BIT
2559 < gdbarch_long_long_bit (par_state->gdbarch ()))
2560 /* A long long does not fit in a LONGEST. */
2561 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
2562 else
2563 shift = (gdbarch_long_long_bit (par_state->gdbarch ()) - 1);
2564 high_bit = (ULONGEST) 1 << shift;
2565 unsigned_type = parse_type (par_state)->builtin_unsigned_long_long;
2566 signed_type = parse_type (par_state)->builtin_long_long;
2567 }
2568
2569 putithere->typed_val_int.val = n;
2570
2571 /* If the high bit of the worked out type is set then this number
2572 has to be unsigned. */
2573
2574 if (unsigned_p || (n & high_bit))
2575 {
2576 putithere->typed_val_int.type = unsigned_type;
2577 }
2578 else
2579 {
2580 putithere->typed_val_int.type = signed_type;
2581 }
2582
2583 return INT;
2584 }
2585
2586 /* Temporary obstack used for holding strings. */
2587 static struct obstack tempbuf;
2588 static int tempbuf_init;
2589
2590 /* Parse a string or character literal from TOKPTR. The string or
2591 character may be wide or unicode. *OUTPTR is set to just after the
2592 end of the literal in the input string. The resulting token is
2593 stored in VALUE. This returns a token value, either STRING or
2594 CHAR, depending on what was parsed. *HOST_CHARS is set to the
2595 number of host characters in the literal. */
2596
2597 static int
parse_string_or_char(const char * tokptr,const char ** outptr,struct typed_stoken * value,int * host_chars)2598 parse_string_or_char (const char *tokptr, const char **outptr,
2599 struct typed_stoken *value, int *host_chars)
2600 {
2601 int quote;
2602
2603 /* Build the gdb internal form of the input string in tempbuf. Note
2604 that the buffer is null byte terminated *only* for the
2605 convenience of debugging gdb itself and printing the buffer
2606 contents when the buffer contains no embedded nulls. Gdb does
2607 not depend upon the buffer being null byte terminated, it uses
2608 the length string instead. This allows gdb to handle C strings
2609 (as well as strings in other languages) with embedded null
2610 bytes */
2611
2612 if (!tempbuf_init)
2613 tempbuf_init = 1;
2614 else
2615 obstack_free (&tempbuf, NULL);
2616 obstack_init (&tempbuf);
2617
2618 /* Skip the quote. */
2619 quote = *tokptr;
2620 ++tokptr;
2621
2622 *host_chars = 0;
2623
2624 while (*tokptr)
2625 {
2626 char c = *tokptr;
2627 if (c == '\\')
2628 {
2629 ++tokptr;
2630 *host_chars += c_parse_escape (&tokptr, &tempbuf);
2631 }
2632 else if (c == quote)
2633 break;
2634 else
2635 {
2636 obstack_1grow (&tempbuf, c);
2637 ++tokptr;
2638 /* FIXME: this does the wrong thing with multi-byte host
2639 characters. We could use mbrlen here, but that would
2640 make "set host-charset" a bit less useful. */
2641 ++*host_chars;
2642 }
2643 }
2644
2645 if (*tokptr != quote)
2646 {
2647 if (quote == '"')
2648 error (_("Unterminated string in expression."));
2649 else
2650 error (_("Unmatched single quote."));
2651 }
2652 ++tokptr;
2653
2654 value->type = (int) C_STRING | (quote == '\'' ? C_CHAR : 0); /*FIXME*/
2655 value->ptr = (char *) obstack_base (&tempbuf);
2656 value->length = obstack_object_size (&tempbuf);
2657
2658 *outptr = tokptr;
2659
2660 return quote == '\'' ? CHAR : STRING;
2661 }
2662
2663 struct token
2664 {
2665 const char *oper;
2666 int token;
2667 enum exp_opcode opcode;
2668 };
2669
2670 static const struct token tokentab3[] =
2671 {
2672 {">>=", ASSIGN_MODIFY, BINOP_RSH},
2673 {"<<=", ASSIGN_MODIFY, BINOP_LSH},
2674 /*{"&^=", ASSIGN_MODIFY, BINOP_BITWISE_ANDNOT}, TODO */
2675 {"...", DOTDOTDOT, OP_NULL},
2676 };
2677
2678 static const struct token tokentab2[] =
2679 {
2680 {"+=", ASSIGN_MODIFY, BINOP_ADD},
2681 {"-=", ASSIGN_MODIFY, BINOP_SUB},
2682 {"*=", ASSIGN_MODIFY, BINOP_MUL},
2683 {"/=", ASSIGN_MODIFY, BINOP_DIV},
2684 {"%=", ASSIGN_MODIFY, BINOP_REM},
2685 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR},
2686 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND},
2687 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR},
2688 {"++", INCREMENT, OP_NULL},
2689 {"--", DECREMENT, OP_NULL},
2690 /*{"->", RIGHT_ARROW, OP_NULL}, Doesn't exist in Go. */
2691 {"<-", LEFT_ARROW, OP_NULL},
2692 {"&&", ANDAND, OP_NULL},
2693 {"||", OROR, OP_NULL},
2694 {"<<", LSH, OP_NULL},
2695 {">>", RSH, OP_NULL},
2696 {"==", EQUAL, OP_NULL},
2697 {"!=", NOTEQUAL, OP_NULL},
2698 {"<=", LEQ, OP_NULL},
2699 {">=", GEQ, OP_NULL},
2700 /*{"&^", ANDNOT, OP_NULL}, TODO */
2701 };
2702
2703 /* Identifier-like tokens. */
2704 static const struct token ident_tokens[] =
2705 {
2706 {"true", TRUE_KEYWORD, OP_NULL},
2707 {"false", FALSE_KEYWORD, OP_NULL},
2708 {"nil", NIL_KEYWORD, OP_NULL},
2709 {"const", CONST_KEYWORD, OP_NULL},
2710 {"struct", STRUCT_KEYWORD, OP_NULL},
2711 {"type", TYPE_KEYWORD, OP_NULL},
2712 {"interface", INTERFACE_KEYWORD, OP_NULL},
2713 {"chan", CHAN_KEYWORD, OP_NULL},
2714 {"byte", BYTE_KEYWORD, OP_NULL}, /* An alias of uint8. */
2715 {"len", LEN_KEYWORD, OP_NULL},
2716 {"cap", CAP_KEYWORD, OP_NULL},
2717 {"new", NEW_KEYWORD, OP_NULL},
2718 {"iota", IOTA_KEYWORD, OP_NULL},
2719 };
2720
2721 /* This is set if a NAME token appeared at the very end of the input
2722 string, with no whitespace separating the name from the EOF. This
2723 is used only when parsing to do field name completion. */
2724 static int saw_name_at_eof;
2725
2726 /* This is set if the previously-returned token was a structure
2727 operator -- either '.' or ARROW. This is used only when parsing to
2728 do field name completion. */
2729 static int last_was_structop;
2730
2731 /* Depth of parentheses. */
2732 static int paren_depth;
2733
2734 /* Read one token, getting characters through lexptr. */
2735
2736 static int
lex_one_token(struct parser_state * par_state)2737 lex_one_token (struct parser_state *par_state)
2738 {
2739 int c;
2740 int namelen;
2741 unsigned int i;
2742 const char *tokstart;
2743 int saw_structop = last_was_structop;
2744
2745 last_was_structop = 0;
2746
2747 retry:
2748
2749 par_state->prev_lexptr = par_state->lexptr;
2750
2751 tokstart = par_state->lexptr;
2752 /* See if it is a special token of length 3. */
2753 for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
2754 if (strncmp (tokstart, tokentab3[i].oper, 3) == 0)
2755 {
2756 par_state->lexptr += 3;
2757 yylval.opcode = tokentab3[i].opcode;
2758 return tokentab3[i].token;
2759 }
2760
2761 /* See if it is a special token of length 2. */
2762 for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
2763 if (strncmp (tokstart, tokentab2[i].oper, 2) == 0)
2764 {
2765 par_state->lexptr += 2;
2766 yylval.opcode = tokentab2[i].opcode;
2767 /* NOTE: -> doesn't exist in Go, so we don't need to watch for
2768 setting last_was_structop here. */
2769 return tokentab2[i].token;
2770 }
2771
2772 switch (c = *tokstart)
2773 {
2774 case 0:
2775 if (saw_name_at_eof)
2776 {
2777 saw_name_at_eof = 0;
2778 return COMPLETE;
2779 }
2780 else if (saw_structop)
2781 return COMPLETE;
2782 else
2783 return 0;
2784
2785 case ' ':
2786 case '\t':
2787 case '\n':
2788 par_state->lexptr++;
2789 goto retry;
2790
2791 case '[':
2792 case '(':
2793 paren_depth++;
2794 par_state->lexptr++;
2795 return c;
2796
2797 case ']':
2798 case ')':
2799 if (paren_depth == 0)
2800 return 0;
2801 paren_depth--;
2802 par_state->lexptr++;
2803 return c;
2804
2805 case ',':
2806 if (pstate->comma_terminates
2807 && paren_depth == 0)
2808 return 0;
2809 par_state->lexptr++;
2810 return c;
2811
2812 case '.':
2813 /* Might be a floating point number. */
2814 if (par_state->lexptr[1] < '0' || par_state->lexptr[1] > '9')
2815 {
2816 if (pstate->parse_completion)
2817 last_was_structop = 1;
2818 goto symbol; /* Nope, must be a symbol. */
2819 }
2820 /* FALL THRU. */
2821
2822 case '0':
2823 case '1':
2824 case '2':
2825 case '3':
2826 case '4':
2827 case '5':
2828 case '6':
2829 case '7':
2830 case '8':
2831 case '9':
2832 {
2833 /* It's a number. */
2834 int got_dot = 0, got_e = 0, toktype;
2835 const char *p = tokstart;
2836 int hex = input_radix > 10;
2837
2838 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
2839 {
2840 p += 2;
2841 hex = 1;
2842 }
2843
2844 for (;; ++p)
2845 {
2846 /* This test includes !hex because 'e' is a valid hex digit
2847 and thus does not indicate a floating point number when
2848 the radix is hex. */
2849 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2850 got_dot = got_e = 1;
2851 /* This test does not include !hex, because a '.' always indicates
2852 a decimal floating point number regardless of the radix. */
2853 else if (!got_dot && *p == '.')
2854 got_dot = 1;
2855 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2856 && (*p == '-' || *p == '+'))
2857 /* This is the sign of the exponent, not the end of the
2858 number. */
2859 continue;
2860 /* We will take any letters or digits. parse_number will
2861 complain if past the radix, or if L or U are not final. */
2862 else if ((*p < '0' || *p > '9')
2863 && ((*p < 'a' || *p > 'z')
2864 && (*p < 'A' || *p > 'Z')))
2865 break;
2866 }
2867 toktype = parse_number (par_state, tokstart, p - tokstart,
2868 got_dot|got_e, &yylval);
2869 if (toktype == ERROR)
2870 {
2871 char *err_copy = (char *) alloca (p - tokstart + 1);
2872
2873 memcpy (err_copy, tokstart, p - tokstart);
2874 err_copy[p - tokstart] = 0;
2875 error (_("Invalid number \"%s\"."), err_copy);
2876 }
2877 par_state->lexptr = p;
2878 return toktype;
2879 }
2880
2881 case '@':
2882 {
2883 const char *p = &tokstart[1];
2884 size_t len = strlen ("entry");
2885
2886 while (isspace (*p))
2887 p++;
2888 if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
2889 && p[len] != '_')
2890 {
2891 par_state->lexptr = &p[len];
2892 return ENTRY;
2893 }
2894 }
2895 /* FALLTHRU */
2896 case '+':
2897 case '-':
2898 case '*':
2899 case '/':
2900 case '%':
2901 case '|':
2902 case '&':
2903 case '^':
2904 case '~':
2905 case '!':
2906 case '<':
2907 case '>':
2908 case '?':
2909 case ':':
2910 case '=':
2911 case '{':
2912 case '}':
2913 symbol:
2914 par_state->lexptr++;
2915 return c;
2916
2917 case '\'':
2918 case '"':
2919 case '`':
2920 {
2921 int host_len;
2922 int result = parse_string_or_char (tokstart, &par_state->lexptr,
2923 &yylval.tsval, &host_len);
2924 if (result == CHAR)
2925 {
2926 if (host_len == 0)
2927 error (_("Empty character constant."));
2928 else if (host_len > 2 && c == '\'')
2929 {
2930 ++tokstart;
2931 namelen = par_state->lexptr - tokstart - 1;
2932 goto tryname;
2933 }
2934 else if (host_len > 1)
2935 error (_("Invalid character constant."));
2936 }
2937 return result;
2938 }
2939 }
2940
2941 if (!(c == '_' || c == '$'
2942 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2943 /* We must have come across a bad character (e.g. ';'). */
2944 error (_("Invalid character '%c' in expression."), c);
2945
2946 /* It's a name. See how long it is. */
2947 namelen = 0;
2948 for (c = tokstart[namelen];
2949 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2950 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));)
2951 {
2952 c = tokstart[++namelen];
2953 }
2954
2955 /* The token "if" terminates the expression and is NOT removed from
2956 the input stream. It doesn't count if it appears in the
2957 expansion of a macro. */
2958 if (namelen == 2
2959 && tokstart[0] == 'i'
2960 && tokstart[1] == 'f')
2961 {
2962 return 0;
2963 }
2964
2965 /* For the same reason (breakpoint conditions), "thread N"
2966 terminates the expression. "thread" could be an identifier, but
2967 an identifier is never followed by a number without intervening
2968 punctuation.
2969 Handle abbreviations of these, similarly to
2970 breakpoint.c:find_condition_and_thread.
2971 TODO: Watch for "goroutine" here? */
2972 if (namelen >= 1
2973 && strncmp (tokstart, "thread", namelen) == 0
2974 && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t'))
2975 {
2976 const char *p = tokstart + namelen + 1;
2977
2978 while (*p == ' ' || *p == '\t')
2979 p++;
2980 if (*p >= '0' && *p <= '9')
2981 return 0;
2982 }
2983
2984 par_state->lexptr += namelen;
2985
2986 tryname:
2987
2988 yylval.sval.ptr = tokstart;
2989 yylval.sval.length = namelen;
2990
2991 /* Catch specific keywords. */
2992 std::string copy = copy_name (yylval.sval);
2993 for (i = 0; i < sizeof (ident_tokens) / sizeof (ident_tokens[0]); i++)
2994 if (copy == ident_tokens[i].oper)
2995 {
2996 /* It is ok to always set this, even though we don't always
2997 strictly need to. */
2998 yylval.opcode = ident_tokens[i].opcode;
2999 return ident_tokens[i].token;
3000 }
3001
3002 if (*tokstart == '$')
3003 return DOLLAR_VARIABLE;
3004
3005 if (pstate->parse_completion && *par_state->lexptr == '\0')
3006 saw_name_at_eof = 1;
3007 return NAME;
3008 }
3009
3010 /* An object of this type is pushed on a FIFO by the "outer" lexer. */
3011 struct token_and_value
3012 {
3013 int token;
3014 YYSTYPE value;
3015 };
3016
3017 /* A FIFO of tokens that have been read but not yet returned to the
3018 parser. */
3019 static std::vector<token_and_value> token_fifo;
3020
3021 /* Non-zero if the lexer should return tokens from the FIFO. */
3022 static int popping;
3023
3024 /* Temporary storage for yylex; this holds symbol names as they are
3025 built up. */
3026 static auto_obstack name_obstack;
3027
3028 /* Build "package.name" in name_obstack.
3029 For convenience of the caller, the name is NUL-terminated,
3030 but the NUL is not included in the recorded length. */
3031
3032 static struct stoken
build_packaged_name(const char * package,int package_len,const char * name,int name_len)3033 build_packaged_name (const char *package, int package_len,
3034 const char *name, int name_len)
3035 {
3036 struct stoken result;
3037
3038 name_obstack.clear ();
3039 obstack_grow (&name_obstack, package, package_len);
3040 obstack_grow_str (&name_obstack, ".");
3041 obstack_grow (&name_obstack, name, name_len);
3042 obstack_grow (&name_obstack, "", 1);
3043 result.ptr = (char *) obstack_base (&name_obstack);
3044 result.length = obstack_object_size (&name_obstack) - 1;
3045
3046 return result;
3047 }
3048
3049 /* Return non-zero if NAME is a package name.
3050 BLOCK is the scope in which to interpret NAME; this can be NULL
3051 to mean the global scope. */
3052
3053 static int
package_name_p(const char * name,const struct block * block)3054 package_name_p (const char *name, const struct block *block)
3055 {
3056 struct symbol *sym;
3057 struct field_of_this_result is_a_field_of_this;
3058
3059 sym = lookup_symbol (name, block, STRUCT_DOMAIN, &is_a_field_of_this).symbol;
3060
3061 if (sym
3062 && SYMBOL_CLASS (sym) == LOC_TYPEDEF
3063 && SYMBOL_TYPE (sym)->code () == TYPE_CODE_MODULE)
3064 return 1;
3065
3066 return 0;
3067 }
3068
3069 /* Classify a (potential) function in the "unsafe" package.
3070 We fold these into "keywords" to keep things simple, at least until
3071 something more complex is warranted. */
3072
3073 static int
classify_unsafe_function(struct stoken function_name)3074 classify_unsafe_function (struct stoken function_name)
3075 {
3076 std::string copy = copy_name (function_name);
3077
3078 if (copy == "Sizeof")
3079 {
3080 yylval.sval = function_name;
3081 return SIZEOF_KEYWORD;
3082 }
3083
3084 error (_("Unknown function in `unsafe' package: %s"), copy.c_str ());
3085 }
3086
3087 /* Classify token(s) "name1.name2" where name1 is known to be a package.
3088 The contents of the token are in `yylval'.
3089 Updates yylval and returns the new token type.
3090
3091 The result is one of NAME, NAME_OR_INT, or TYPENAME. */
3092
3093 static int
classify_packaged_name(const struct block * block)3094 classify_packaged_name (const struct block *block)
3095 {
3096 struct block_symbol sym;
3097 struct field_of_this_result is_a_field_of_this;
3098
3099 std::string copy = copy_name (yylval.sval);
3100
3101 sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
3102
3103 if (sym.symbol)
3104 {
3105 yylval.ssym.sym = sym;
3106 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
3107 }
3108
3109 return NAME;
3110 }
3111
3112 /* Classify a NAME token.
3113 The contents of the token are in `yylval'.
3114 Updates yylval and returns the new token type.
3115 BLOCK is the block in which lookups start; this can be NULL
3116 to mean the global scope.
3117
3118 The result is one of NAME, NAME_OR_INT, or TYPENAME. */
3119
3120 static int
classify_name(struct parser_state * par_state,const struct block * block)3121 classify_name (struct parser_state *par_state, const struct block *block)
3122 {
3123 struct type *type;
3124 struct block_symbol sym;
3125 struct field_of_this_result is_a_field_of_this;
3126
3127 std::string copy = copy_name (yylval.sval);
3128
3129 /* Try primitive types first so they win over bad/weird debug info. */
3130 type = language_lookup_primitive_type (par_state->language (),
3131 par_state->gdbarch (),
3132 copy.c_str ());
3133 if (type != NULL)
3134 {
3135 /* NOTE: We take advantage of the fact that yylval coming in was a
3136 NAME, and that struct ttype is a compatible extension of struct
3137 stoken, so yylval.tsym.stoken is already filled in. */
3138 yylval.tsym.type = type;
3139 return TYPENAME;
3140 }
3141
3142 /* TODO: What about other types? */
3143
3144 sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
3145
3146 if (sym.symbol)
3147 {
3148 yylval.ssym.sym = sym;
3149 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
3150 return NAME;
3151 }
3152
3153 /* If we didn't find a symbol, look again in the current package.
3154 This is to, e.g., make "p global_var" work without having to specify
3155 the package name. We intentionally only looks for objects in the
3156 current package. */
3157
3158 {
3159 char *current_package_name = go_block_package_name (block);
3160
3161 if (current_package_name != NULL)
3162 {
3163 struct stoken sval =
3164 build_packaged_name (current_package_name,
3165 strlen (current_package_name),
3166 copy.c_str (), copy.size ());
3167
3168 xfree (current_package_name);
3169 sym = lookup_symbol (sval.ptr, block, VAR_DOMAIN,
3170 &is_a_field_of_this);
3171 if (sym.symbol)
3172 {
3173 yylval.ssym.stoken = sval;
3174 yylval.ssym.sym = sym;
3175 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
3176 return NAME;
3177 }
3178 }
3179 }
3180
3181 /* Input names that aren't symbols but ARE valid hex numbers, when
3182 the input radix permits them, can be names or numbers depending
3183 on the parse. Note we support radixes > 16 here. */
3184 if ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
3185 || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10))
3186 {
3187 YYSTYPE newlval; /* Its value is ignored. */
3188 int hextype = parse_number (par_state, copy.c_str (),
3189 yylval.sval.length, 0, &newlval);
3190 if (hextype == INT)
3191 {
3192 yylval.ssym.sym.symbol = NULL;
3193 yylval.ssym.sym.block = NULL;
3194 yylval.ssym.is_a_field_of_this = 0;
3195 return NAME_OR_INT;
3196 }
3197 }
3198
3199 yylval.ssym.sym.symbol = NULL;
3200 yylval.ssym.sym.block = NULL;
3201 yylval.ssym.is_a_field_of_this = 0;
3202 return NAME;
3203 }
3204
3205 /* This is taken from c-exp.y mostly to get something working.
3206 The basic structure has been kept because we may yet need some of it. */
3207
3208 static int
yylex(void)3209 yylex (void)
3210 {
3211 token_and_value current, next;
3212
3213 if (popping && !token_fifo.empty ())
3214 {
3215 token_and_value tv = token_fifo[0];
3216 token_fifo.erase (token_fifo.begin ());
3217 yylval = tv.value;
3218 /* There's no need to fall through to handle package.name
3219 as that can never happen here. In theory. */
3220 return tv.token;
3221 }
3222 popping = 0;
3223
3224 current.token = lex_one_token (pstate);
3225
3226 /* TODO: Need a way to force specifying name1 as a package.
3227 .name1.name2 ? */
3228
3229 if (current.token != NAME)
3230 return current.token;
3231
3232 /* See if we have "name1 . name2". */
3233
3234 current.value = yylval;
3235 next.token = lex_one_token (pstate);
3236 next.value = yylval;
3237
3238 if (next.token == '.')
3239 {
3240 token_and_value name2;
3241
3242 name2.token = lex_one_token (pstate);
3243 name2.value = yylval;
3244
3245 if (name2.token == NAME)
3246 {
3247 /* Ok, we have "name1 . name2". */
3248 std::string copy = copy_name (current.value.sval);
3249
3250 if (copy == "unsafe")
3251 {
3252 popping = 1;
3253 return classify_unsafe_function (name2.value.sval);
3254 }
3255
3256 if (package_name_p (copy.c_str (), pstate->expression_context_block))
3257 {
3258 popping = 1;
3259 yylval.sval = build_packaged_name (current.value.sval.ptr,
3260 current.value.sval.length,
3261 name2.value.sval.ptr,
3262 name2.value.sval.length);
3263 return classify_packaged_name (pstate->expression_context_block);
3264 }
3265 }
3266
3267 token_fifo.push_back (next);
3268 token_fifo.push_back (name2);
3269 }
3270 else
3271 token_fifo.push_back (next);
3272
3273 /* If we arrive here we don't have a package-qualified name. */
3274
3275 popping = 1;
3276 yylval = current.value;
3277 return classify_name (pstate, pstate->expression_context_block);
3278 }
3279
3280 /* See language.h. */
3281
3282 int
parser(struct parser_state * par_state)3283 go_language::parser (struct parser_state *par_state) const
3284 {
3285 /* Setting up the parser state. */
3286 scoped_restore pstate_restore = make_scoped_restore (&pstate);
3287 gdb_assert (par_state != NULL);
3288 pstate = par_state;
3289
3290 scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
3291 parser_debug);
3292
3293 /* Initialize some state used by the lexer. */
3294 last_was_structop = 0;
3295 saw_name_at_eof = 0;
3296 paren_depth = 0;
3297
3298 token_fifo.clear ();
3299 popping = 0;
3300 name_obstack.clear ();
3301
3302 int result = yyparse ();
3303 if (!result)
3304 pstate->set_operation (pstate->pop ());
3305 return result;
3306 }
3307
3308 static void
yyerror(const char * msg)3309 yyerror (const char *msg)
3310 {
3311 if (pstate->prev_lexptr)
3312 pstate->lexptr = pstate->prev_lexptr;
3313
3314 error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
3315 }
3316