1 /* A Bison parser, made by GNU Bison 3.8.2. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 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 <https://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 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38 especially those whose name start with YY_ or yy_. They are
39 private implementation details that can be changed or removed. */
40
41 /* All symbols defined below should begin with yy or YY, to avoid
42 infringing on user name space. This should be done even for local
43 variables, as they might otherwise be expanded by user macros.
44 There are some unavoidable exceptions within include files to
45 define necessary library symbols; they are noted "INFRINGES ON
46 USER NAME SPACE" below. */
47
48 /* Identify Bison output, and Bison version. */
49 #define YYBISON 30802
50
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.8.2"
53
54 /* Skeleton name. */
55 #define YYSKELETON_NAME "yacc.c"
56
57 /* Pure parsers. */
58 #define YYPURE 1
59
60 /* Push parsers. */
61 #define YYPUSH 0
62
63 /* Pull parsers. */
64 #define YYPULL 1
65
66 /* Substitute the type names. */
67 #define YYSTYPE PPSTYPE
68 /* Substitute the variable and function names. */
69 #define yyparse ppparse
70 #define yylex pplex
71 #define yyerror pperror
72 #define yydebug ppdebug
73 #define yynerrs ppnerrs
74
75 /* First part of user prologue. */
76
77 // GENERATED FILE - DO NOT EDIT.
78 // Generated by generate_parser.py from preprocessor.y
79 //
80 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
81 // Use of this source code is governed by a BSD-style license that can be
82 // found in the LICENSE file.
83 //
84 // preprocessor.y:
85 // Parser for the OpenGL shading language preprocessor.
86
87 #if defined(__GNUC__)
88 // Triggered by the auto-generated pplval variable.
89 # if !defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
90 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
91 # else
92 # pragma GCC diagnostic ignored "-Wuninitialized"
93 # endif
94 #elif defined(_MSC_VER)
95 # pragma warning(disable : 4065 4244 4701 4702)
96 #endif
97 #if defined(__clang__)
98 # pragma clang diagnostic ignored "-Wunreachable-code"
99 # pragma clang diagnostic ignored "-Wunused-but-set-variable"
100 #endif
101
102 #include "ExpressionParser.h"
103
104 #if defined(_MSC_VER)
105 # include <malloc.h>
106 #else
107 # include <stdlib.h>
108 #endif
109
110 #include <stdint.h>
111 #include <cassert>
112 #include <sstream>
113
114 #include "DiagnosticsBase.h"
115 #include "Lexer.h"
116 #include "Token.h"
117 #include "common/mathutil.h"
118
119 typedef int32_t YYSTYPE;
120 typedef uint32_t UNSIGNED_TYPE;
121
122 #define YYENABLE_NLS 0
123 #define YYLTYPE_IS_TRIVIAL 1
124 #define YYSTYPE_IS_TRIVIAL 1
125 #define YYSTYPE_IS_DECLARED 1
126
127 namespace
128 {
129 struct Context
130 {
131 angle::pp::Diagnostics *diagnostics;
132 angle::pp::Lexer *lexer;
133 angle::pp::Token *token;
134 int *result;
135 bool parsePresetToken;
136
137 angle::pp::ExpressionParser::ErrorSettings errorSettings;
138 bool *valid;
139
startIgnoreErrors__anond3770b340111::Context140 void startIgnoreErrors() { ++ignoreErrors; }
endIgnoreErrors__anond3770b340111::Context141 void endIgnoreErrors() { --ignoreErrors; }
142
isIgnoringErrors__anond3770b340111::Context143 bool isIgnoringErrors() { return ignoreErrors > 0; }
144
145 int ignoreErrors;
146 };
147 } // namespace
148
149 static int yylex(YYSTYPE *lvalp, Context *context);
150 static void yyerror(Context *context, const char *reason);
151
152 #ifndef YY_CAST
153 # ifdef __cplusplus
154 # define YY_CAST(Type, Val) static_cast<Type>(Val)
155 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type>(Val)
156 # else
157 # define YY_CAST(Type, Val) ((Type)(Val))
158 # define YY_REINTERPRET_CAST(Type, Val) ((Type)(Val))
159 # endif
160 #endif
161 #ifndef YY_NULLPTR
162 # if defined __cplusplus
163 # if 201103L <= __cplusplus
164 # define YY_NULLPTR nullptr
165 # else
166 # define YY_NULLPTR 0
167 # endif
168 # else
169 # define YY_NULLPTR ((void *)0)
170 # endif
171 #endif
172
173 /* Debug traces. */
174 #ifndef PPDEBUG
175 # if defined YYDEBUG
176 # if YYDEBUG
177 # define PPDEBUG 1
178 # else
179 # define PPDEBUG 0
180 # endif
181 # else /* ! defined YYDEBUG */
182 # define PPDEBUG 0
183 # endif /* ! defined YYDEBUG */
184 #endif /* ! defined PPDEBUG */
185 #if PPDEBUG
186 extern int ppdebug;
187 #endif
188
189 /* Token kinds. */
190 #ifndef PPTOKENTYPE
191 # define PPTOKENTYPE
192 enum pptokentype
193 {
194 PPEMPTY = -2,
195 PPEOF = 0, /* "end of file" */
196 PPerror = 256, /* error */
197 PPUNDEF = 257, /* "invalid token" */
198 TOK_CONST_INT = 258, /* TOK_CONST_INT */
199 TOK_IDENTIFIER = 259, /* TOK_IDENTIFIER */
200 TOK_OP_OR = 260, /* TOK_OP_OR */
201 TOK_OP_AND = 261, /* TOK_OP_AND */
202 TOK_OP_EQ = 262, /* TOK_OP_EQ */
203 TOK_OP_NE = 263, /* TOK_OP_NE */
204 TOK_OP_LE = 264, /* TOK_OP_LE */
205 TOK_OP_GE = 265, /* TOK_OP_GE */
206 TOK_OP_LEFT = 266, /* TOK_OP_LEFT */
207 TOK_OP_RIGHT = 267, /* TOK_OP_RIGHT */
208 TOK_UNARY = 268 /* TOK_UNARY */
209 };
210 typedef enum pptokentype pptoken_kind_t;
211 #endif
212
213 /* Value type. */
214 #if !defined PPSTYPE && !defined PPSTYPE_IS_DECLARED
215 typedef int PPSTYPE;
216 # define PPSTYPE_IS_TRIVIAL 1
217 # define PPSTYPE_IS_DECLARED 1
218 #endif
219
220 int ppparse(Context *context);
221
222 /* Symbol kind. */
223 enum yysymbol_kind_t
224 {
225 YYSYMBOL_YYEMPTY = -2,
226 YYSYMBOL_YYEOF = 0, /* "end of file" */
227 YYSYMBOL_YYerror = 1, /* error */
228 YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
229 YYSYMBOL_TOK_CONST_INT = 3, /* TOK_CONST_INT */
230 YYSYMBOL_TOK_IDENTIFIER = 4, /* TOK_IDENTIFIER */
231 YYSYMBOL_TOK_OP_OR = 5, /* TOK_OP_OR */
232 YYSYMBOL_TOK_OP_AND = 6, /* TOK_OP_AND */
233 YYSYMBOL_7_ = 7, /* '|' */
234 YYSYMBOL_8_ = 8, /* '^' */
235 YYSYMBOL_9_ = 9, /* '&' */
236 YYSYMBOL_TOK_OP_EQ = 10, /* TOK_OP_EQ */
237 YYSYMBOL_TOK_OP_NE = 11, /* TOK_OP_NE */
238 YYSYMBOL_12_ = 12, /* '<' */
239 YYSYMBOL_13_ = 13, /* '>' */
240 YYSYMBOL_TOK_OP_LE = 14, /* TOK_OP_LE */
241 YYSYMBOL_TOK_OP_GE = 15, /* TOK_OP_GE */
242 YYSYMBOL_TOK_OP_LEFT = 16, /* TOK_OP_LEFT */
243 YYSYMBOL_TOK_OP_RIGHT = 17, /* TOK_OP_RIGHT */
244 YYSYMBOL_18_ = 18, /* '+' */
245 YYSYMBOL_19_ = 19, /* '-' */
246 YYSYMBOL_20_ = 20, /* '*' */
247 YYSYMBOL_21_ = 21, /* '/' */
248 YYSYMBOL_22_ = 22, /* '%' */
249 YYSYMBOL_TOK_UNARY = 23, /* TOK_UNARY */
250 YYSYMBOL_24_ = 24, /* '!' */
251 YYSYMBOL_25_ = 25, /* '~' */
252 YYSYMBOL_26_ = 26, /* '(' */
253 YYSYMBOL_27_ = 27, /* ')' */
254 YYSYMBOL_YYACCEPT = 28, /* $accept */
255 YYSYMBOL_input = 29, /* input */
256 YYSYMBOL_expression = 30, /* expression */
257 YYSYMBOL_31_1 = 31, /* $@1 */
258 YYSYMBOL_32_2 = 32 /* $@2 */
259 };
260 typedef enum yysymbol_kind_t yysymbol_kind_t;
261
262 #ifdef short
263 # undef short
264 #endif
265
266 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
267 <limits.h> and (if available) <stdint.h> are included
268 so that the code can choose integer types of a good width. */
269
270 #ifndef __PTRDIFF_MAX__
271 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
272 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
273 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
274 # define YY_STDINT_H
275 # endif
276 #endif
277
278 /* Narrow types that promote to a signed type and that can represent a
279 signed or unsigned integer of at least N bits. In tables they can
280 save space and decrease cache pressure. Promoting to a signed type
281 helps avoid bugs in integer arithmetic. */
282
283 #ifdef __INT_LEAST8_MAX__
284 typedef __INT_LEAST8_TYPE__ yytype_int8;
285 #elif defined YY_STDINT_H
286 typedef int_least8_t yytype_int8;
287 #else
288 typedef signed char yytype_int8;
289 #endif
290
291 #ifdef __INT_LEAST16_MAX__
292 typedef __INT_LEAST16_TYPE__ yytype_int16;
293 #elif defined YY_STDINT_H
294 typedef int_least16_t yytype_int16;
295 #else
296 typedef short yytype_int16;
297 #endif
298
299 /* Work around bug in HP-UX 11.23, which defines these macros
300 incorrectly for preprocessor constants. This workaround can likely
301 be removed in 2023, as HPE has promised support for HP-UX 11.23
302 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
303 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
304 #ifdef __hpux
305 # undef UINT_LEAST8_MAX
306 # undef UINT_LEAST16_MAX
307 # define UINT_LEAST8_MAX 255
308 # define UINT_LEAST16_MAX 65535
309 #endif
310
311 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
312 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
313 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H && UINT_LEAST8_MAX <= INT_MAX)
314 typedef uint_least8_t yytype_uint8;
315 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
316 typedef unsigned char yytype_uint8;
317 #else
318 typedef short yytype_uint8;
319 #endif
320
321 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
322 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
323 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H && UINT_LEAST16_MAX <= INT_MAX)
324 typedef uint_least16_t yytype_uint16;
325 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
326 typedef unsigned short yytype_uint16;
327 #else
328 typedef int yytype_uint16;
329 #endif
330
331 #ifndef YYPTRDIFF_T
332 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
333 # define YYPTRDIFF_T __PTRDIFF_TYPE__
334 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
335 # elif defined PTRDIFF_MAX
336 # ifndef ptrdiff_t
337 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
338 # endif
339 # define YYPTRDIFF_T ptrdiff_t
340 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
341 # else
342 # define YYPTRDIFF_T long
343 # define YYPTRDIFF_MAXIMUM LONG_MAX
344 # endif
345 #endif
346
347 #ifndef YYSIZE_T
348 # ifdef __SIZE_TYPE__
349 # define YYSIZE_T __SIZE_TYPE__
350 # elif defined size_t
351 # define YYSIZE_T size_t
352 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
353 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
354 # define YYSIZE_T size_t
355 # else
356 # define YYSIZE_T unsigned
357 # endif
358 #endif
359
360 #define YYSIZE_MAXIMUM \
361 YY_CAST(YYPTRDIFF_T, (YYPTRDIFF_MAXIMUM < YY_CAST(YYSIZE_T, -1) ? YYPTRDIFF_MAXIMUM \
362 : YY_CAST(YYSIZE_T, -1)))
363
364 #define YYSIZEOF(X) YY_CAST(YYPTRDIFF_T, sizeof(X))
365
366 /* Stored state numbers (used for stacks). */
367 typedef yytype_int8 yy_state_t;
368
369 /* State numbers in computations. */
370 typedef int yy_state_fast_t;
371
372 #ifndef YY_
373 # if defined YYENABLE_NLS && YYENABLE_NLS
374 # if ENABLE_NLS
375 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
376 # define YY_(Msgid) dgettext("bison-runtime", Msgid)
377 # endif
378 # endif
379 # ifndef YY_
380 # define YY_(Msgid) Msgid
381 # endif
382 #endif
383
384 #ifndef YY_ATTRIBUTE_PURE
385 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
386 # define YY_ATTRIBUTE_PURE __attribute__((__pure__))
387 # else
388 # define YY_ATTRIBUTE_PURE
389 # endif
390 #endif
391
392 #ifndef YY_ATTRIBUTE_UNUSED
393 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
394 # define YY_ATTRIBUTE_UNUSED __attribute__((__unused__))
395 # else
396 # define YY_ATTRIBUTE_UNUSED
397 # endif
398 #endif
399
400 /* Suppress unused-variable warnings by "using" E. */
401 #if !defined lint || defined __GNUC__
402 # define YY_USE(E) ((void)(E))
403 #else
404 # define YY_USE(E) /* empty */
405 #endif
406
407 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
408 #if defined __GNUC__ && !defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
409 # if __GNUC__ * 100 + __GNUC_MINOR__ < 407
410 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
411 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuninitialized\"")
412 # else
413 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
414 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \
415 _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
416 # endif
417 # define YY_IGNORE_MAYBE_UNINITIALIZED_END _Pragma("GCC diagnostic pop")
418 #else
419 # define YY_INITIAL_VALUE(Value) Value
420 #endif
421 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
422 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
423 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
424 #endif
425 #ifndef YY_INITIAL_VALUE
426 # define YY_INITIAL_VALUE(Value) /* Nothing. */
427 #endif
428
429 #if defined __cplusplus && defined __GNUC__ && !defined __ICC && 6 <= __GNUC__
430 # define YY_IGNORE_USELESS_CAST_BEGIN \
431 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuseless-cast\"")
432 # define YY_IGNORE_USELESS_CAST_END _Pragma("GCC diagnostic pop")
433 #endif
434 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
435 # define YY_IGNORE_USELESS_CAST_BEGIN
436 # define YY_IGNORE_USELESS_CAST_END
437 #endif
438
439 #define YY_ASSERT(E) ((void)(0 && (E)))
440
441 #if !defined yyoverflow
442
443 /* The parser invokes alloca or malloc; define the necessary symbols. */
444
445 # ifdef YYSTACK_USE_ALLOCA
446 # if YYSTACK_USE_ALLOCA
447 # ifdef __GNUC__
448 # define YYSTACK_ALLOC __builtin_alloca
449 # elif defined __BUILTIN_VA_ARG_INCR
450 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
451 # elif defined _AIX
452 # define YYSTACK_ALLOC __alloca
453 # elif defined _MSC_VER
454 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
455 # define alloca _alloca
456 # else
457 # define YYSTACK_ALLOC alloca
458 # if !defined _ALLOCA_H && !defined EXIT_SUCCESS
459 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
460 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
461 # ifndef EXIT_SUCCESS
462 # define EXIT_SUCCESS 0
463 # endif
464 # endif
465 # endif
466 # endif
467 # endif
468
469 # ifdef YYSTACK_ALLOC
470 /* Pacify GCC's 'empty if-body' warning. */
471 # define YYSTACK_FREE(Ptr) \
472 do \
473 { /* empty */ \
474 ; \
475 } while (0)
476 # ifndef YYSTACK_ALLOC_MAXIMUM
477 /* The OS might guarantee only one guard page at the bottom of the stack,
478 and a page size can be as small as 4096 bytes. So we cannot safely
479 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
480 to allow for a few compiler-allocated temporary stack slots. */
481 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
482 # endif
483 # else
484 # define YYSTACK_ALLOC YYMALLOC
485 # define YYSTACK_FREE YYFREE
486 # ifndef YYSTACK_ALLOC_MAXIMUM
487 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
488 # endif
489 # if (defined __cplusplus && !defined EXIT_SUCCESS && \
490 !((defined YYMALLOC || defined malloc) && (defined YYFREE || defined free)))
491 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
492 # ifndef EXIT_SUCCESS
493 # define EXIT_SUCCESS 0
494 # endif
495 # endif
496 # ifndef YYMALLOC
497 # define YYMALLOC malloc
498 # if !defined malloc && !defined EXIT_SUCCESS
499 void *malloc(YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
500 # endif
501 # endif
502 # ifndef YYFREE
503 # define YYFREE free
504 # if !defined free && !defined EXIT_SUCCESS
505 void free(void *); /* INFRINGES ON USER NAME SPACE */
506 # endif
507 # endif
508 # endif
509 #endif /* !defined yyoverflow */
510
511 #if (!defined yyoverflow && \
512 (!defined __cplusplus || (defined PPSTYPE_IS_TRIVIAL && PPSTYPE_IS_TRIVIAL)))
513
514 /* A type that is properly aligned for any stack member. */
515 union yyalloc
516 {
517 yy_state_t yyss_alloc;
518 YYSTYPE yyvs_alloc;
519 };
520
521 /* The size of the maximum gap between one aligned stack and the next. */
522 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF(union yyalloc) - 1)
523
524 /* The size of an array large to enough to hold all stacks, each with
525 N elements. */
526 # define YYSTACK_BYTES(N) \
527 ((N) * (YYSIZEOF(yy_state_t) + YYSIZEOF(YYSTYPE)) + YYSTACK_GAP_MAXIMUM)
528
529 # define YYCOPY_NEEDED 1
530
531 /* Relocate STACK from its old location to the new one. The
532 local variables YYSIZE and YYSTACKSIZE give the old and new number of
533 elements in the stack, and YYPTR gives the new location of the
534 stack. Advance YYPTR to a properly aligned location for the next
535 stack. */
536 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
537 do \
538 { \
539 YYPTRDIFF_T yynewbytes; \
540 YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \
541 Stack = &yyptr->Stack_alloc; \
542 yynewbytes = yystacksize * YYSIZEOF(*Stack) + YYSTACK_GAP_MAXIMUM; \
543 yyptr += yynewbytes / YYSIZEOF(*yyptr); \
544 } while (0)
545
546 #endif
547
548 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
549 /* Copy COUNT objects from SRC to DST. The source and destination do
550 not overlap. */
551 # ifndef YYCOPY
552 # if defined __GNUC__ && 1 < __GNUC__
553 # define YYCOPY(Dst, Src, Count) \
554 __builtin_memcpy(Dst, Src, YY_CAST(YYSIZE_T, (Count)) * sizeof(*(Src)))
555 # else
556 # define YYCOPY(Dst, Src, Count) \
557 do \
558 { \
559 YYPTRDIFF_T yyi; \
560 for (yyi = 0; yyi < (Count); yyi++) \
561 (Dst)[yyi] = (Src)[yyi]; \
562 } while (0)
563 # endif
564 # endif
565 #endif /* !YYCOPY_NEEDED */
566
567 /* YYFINAL -- State number of the termination state. */
568 #define YYFINAL 15
569 /* YYLAST -- Last index in YYTABLE. */
570 #define YYLAST 176
571
572 /* YYNTOKENS -- Number of terminals. */
573 #define YYNTOKENS 28
574 /* YYNNTS -- Number of nonterminals. */
575 #define YYNNTS 5
576 /* YYNRULES -- Number of rules. */
577 #define YYNRULES 29
578 /* YYNSTATES -- Number of states. */
579 #define YYNSTATES 55
580
581 /* YYMAXUTOK -- Last valid token kind. */
582 #define YYMAXUTOK 268
583
584 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
585 as returned by yylex, with out-of-bounds checking. */
586 #define YYTRANSLATE(YYX) \
587 (0 <= (YYX) && (YYX) <= YYMAXUTOK ? YY_CAST(yysymbol_kind_t, yytranslate[YYX]) \
588 : YYSYMBOL_YYUNDEF)
589
590 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
591 as returned by yylex. */
592 static const yytype_int8 yytranslate[] = {
593 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
594 2, 2, 2, 2, 2, 2, 24, 2, 2, 2, 22, 9, 2, 26, 27, 20, 18, 2, 19, 2, 21, 2, 2, 2, 2, 2, 2,
595 2, 2, 2, 2, 2, 2, 12, 2, 13, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
596 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
597 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 7, 2, 25, 2, 2, 2, 2, 2, 2, 2, 2,
598 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
599 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
600 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
601 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
602 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 10, 11, 14, 15, 16, 17, 23};
603
604 #if PPDEBUG
605 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
606 static const yytype_int16 yyrline[] = {0, 114, 114, 121, 122, 133, 133, 154, 154, 175,
607 178, 181, 184, 187, 190, 193, 196, 199, 202, 227,
608 249, 252, 255, 281, 308, 311, 314, 317, 329, 332};
609 #endif
610
611 /** Accessing symbol of state STATE. */
612 #define YY_ACCESSING_SYMBOL(State) YY_CAST(yysymbol_kind_t, yystos[State])
613
614 #if PPDEBUG || 0
615 /* The user-facing name of the symbol whose (internal) number is
616 YYSYMBOL. No bounds checking. */
617 static const char *yysymbol_name(yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
618
619 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
620 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
621 static const char *const yytname[] = {"\"end of file\"",
622 "error",
623 "\"invalid token\"",
624 "TOK_CONST_INT",
625 "TOK_IDENTIFIER",
626 "TOK_OP_OR",
627 "TOK_OP_AND",
628 "'|'",
629 "'^'",
630 "'&'",
631 "TOK_OP_EQ",
632 "TOK_OP_NE",
633 "'<'",
634 "'>'",
635 "TOK_OP_LE",
636 "TOK_OP_GE",
637 "TOK_OP_LEFT",
638 "TOK_OP_RIGHT",
639 "'+'",
640 "'-'",
641 "'*'",
642 "'/'",
643 "'%'",
644 "TOK_UNARY",
645 "'!'",
646 "'~'",
647 "'('",
648 "')'",
649 "$accept",
650 "input",
651 "expression",
652 "$@1",
653 "$@2",
654 YY_NULLPTR};
655
yysymbol_name(yysymbol_kind_t yysymbol)656 static const char *yysymbol_name(yysymbol_kind_t yysymbol)
657 {
658 return yytname[yysymbol];
659 }
660 #endif
661
662 #define YYPACT_NINF (-12)
663
664 #define yypact_value_is_default(Yyn) ((Yyn) == YYPACT_NINF)
665
666 #define YYTABLE_NINF (-1)
667
668 #define yytable_value_is_error(Yyn) 0
669
670 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
671 STATE-NUM. */
672 static const yytype_int16 yypact[] = {
673 31, -12, -12, 31, 31, 31, 31, 31, 51, 76, -12, -12, -12, -12, 53, -12, -12, -12, 31,
674 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, -12, 31, 31, 124,
675 138, 26, 149, 149, -11, -11, -11, -11, 154, 154, -8, -8, -12, -12, -12, 93, 109};
676
677 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
678 Performed when YYTABLE does not specify something else to do. Zero
679 means the default is an error. */
680 static const yytype_int8 yydefact[] = {0, 3, 4, 0, 0, 0, 0, 0, 0, 2, 28, 27, 25, 26,
681 0, 1, 5, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
682 0, 0, 0, 0, 0, 0, 29, 0, 0, 9, 10, 11, 13, 12,
683 17, 16, 15, 14, 19, 18, 21, 20, 24, 23, 22, 6, 8};
684
685 /* YYPGOTO[NTERM-NUM]. */
686 static const yytype_int8 yypgoto[] = {-12, -12, -3, -12, -12};
687
688 /* YYDEFGOTO[NTERM-NUM]. */
689 static const yytype_int8 yydefgoto[] = {0, 8, 9, 35, 36};
690
691 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
692 positive, shift that token. If negative, reduce the rule whose
693 number is the opposite. If YYTABLE_NINF, syntax error. */
694 static const yytype_int8 yytable[] = {
695 10, 11, 12, 13, 14, 27, 28, 29, 30, 31, 32, 33, 31, 32, 33, 37, 38, 39, 40, 41, 42, 43, 44,
696 45, 46, 47, 48, 49, 50, 51, 52, 0, 53, 54, 1, 2, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
697 31, 32, 33, 3, 4, 15, 0, 0, 0, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
698 27, 28, 29, 30, 31, 32, 33, 0, 0, 0, 0, 34, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
699 27, 28, 29, 30, 31, 32, 33, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
700 33, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 19, 20, 21, 22, 23, 24,
701 25, 26, 27, 28, 29, 30, 31, 32, 33, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
702 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 29, 30, 31, 32, 33};
703
704 static const yytype_int8 yycheck[] = {
705 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 20, 21, 22, 18, 19, 20, 21, 22, 23, 24, 25,
706 26, 27, 28, 29, 30, 31, 32, 33, -1, 35, 36, 3, 4, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
707 20, 21, 22, 18, 19, 0, -1, -1, -1, 24, 25, 26, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
708 16, 17, 18, 19, 20, 21, 22, -1, -1, -1, -1, 27, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
709 16, 17, 18, 19, 20, 21, 22, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
710 22, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 8, 9, 10, 11, 12, 13,
711 14, 15, 16, 17, 18, 19, 20, 21, 22, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
712 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 18, 19, 20, 21, 22};
713
714 /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
715 state STATE-NUM. */
716 static const yytype_int8 yystos[] = {0, 3, 4, 18, 19, 24, 25, 26, 29, 30, 30, 30, 30, 30,
717 30, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
718 17, 18, 19, 20, 21, 22, 27, 31, 32, 30, 30, 30, 30, 30,
719 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30};
720
721 /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
722 static const yytype_int8 yyr1[] = {0, 28, 29, 30, 30, 31, 30, 32, 30, 30, 30, 30, 30, 30, 30,
723 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30};
724
725 /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
726 static const yytype_int8 yyr2[] = {0, 2, 1, 1, 1, 0, 4, 0, 4, 3, 3, 3, 3, 3, 3,
727 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3};
728
729 enum
730 {
731 YYENOMEM = -2
732 };
733
734 #define yyerrok (yyerrstatus = 0)
735 #define yyclearin (yychar = PPEMPTY)
736
737 #define YYACCEPT goto yyacceptlab
738 #define YYABORT goto yyabortlab
739 #define YYERROR goto yyerrorlab
740 #define YYNOMEM goto yyexhaustedlab
741
742 #define YYRECOVERING() (!!yyerrstatus)
743
744 #define YYBACKUP(Token, Value) \
745 do \
746 if (yychar == PPEMPTY) \
747 { \
748 yychar = (Token); \
749 yylval = (Value); \
750 YYPOPSTACK(yylen); \
751 yystate = *yyssp; \
752 goto yybackup; \
753 } \
754 else \
755 { \
756 yyerror(context, YY_("syntax error: cannot back up")); \
757 YYERROR; \
758 } \
759 while (0)
760
761 /* Backward compatibility with an undocumented macro.
762 Use PPerror or PPUNDEF. */
763 #define YYERRCODE PPUNDEF
764
765 /* Enable debugging if requested. */
766 #if PPDEBUG
767
768 # ifndef YYFPRINTF
769 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
770 # define YYFPRINTF fprintf
771 # endif
772
773 # define YYDPRINTF(Args) \
774 do \
775 { \
776 if (yydebug) \
777 YYFPRINTF Args; \
778 } while (0)
779
780 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
781 do \
782 { \
783 if (yydebug) \
784 { \
785 YYFPRINTF(stderr, "%s ", Title); \
786 yy_symbol_print(stderr, Kind, Value, context); \
787 YYFPRINTF(stderr, "\n"); \
788 } \
789 } while (0)
790
791 /*-----------------------------------.
792 | Print this symbol's value on YYO. |
793 `-----------------------------------*/
794
yy_symbol_value_print(FILE * yyo,yysymbol_kind_t yykind,YYSTYPE const * const yyvaluep,Context * context)795 static void yy_symbol_value_print(FILE *yyo,
796 yysymbol_kind_t yykind,
797 YYSTYPE const *const yyvaluep,
798 Context *context)
799 {
800 FILE *yyoutput = yyo;
801 YY_USE(yyoutput);
802 YY_USE(context);
803 if (!yyvaluep)
804 return;
805 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
806 YY_USE(yykind);
807 YY_IGNORE_MAYBE_UNINITIALIZED_END
808 }
809
810 /*---------------------------.
811 | Print this symbol on YYO. |
812 `---------------------------*/
813
yy_symbol_print(FILE * yyo,yysymbol_kind_t yykind,YYSTYPE const * const yyvaluep,Context * context)814 static void yy_symbol_print(FILE *yyo,
815 yysymbol_kind_t yykind,
816 YYSTYPE const *const yyvaluep,
817 Context *context)
818 {
819 YYFPRINTF(yyo, "%s %s (", yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name(yykind));
820
821 yy_symbol_value_print(yyo, yykind, yyvaluep, context);
822 YYFPRINTF(yyo, ")");
823 }
824
825 /*------------------------------------------------------------------.
826 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
827 | TOP (included). |
828 `------------------------------------------------------------------*/
829
yy_stack_print(yy_state_t * yybottom,yy_state_t * yytop)830 static void yy_stack_print(yy_state_t *yybottom, yy_state_t *yytop)
831 {
832 YYFPRINTF(stderr, "Stack now");
833 for (; yybottom <= yytop; yybottom++)
834 {
835 int yybot = *yybottom;
836 YYFPRINTF(stderr, " %d", yybot);
837 }
838 YYFPRINTF(stderr, "\n");
839 }
840
841 # define YY_STACK_PRINT(Bottom, Top) \
842 do \
843 { \
844 if (yydebug) \
845 yy_stack_print((Bottom), (Top)); \
846 } while (0)
847
848 /*------------------------------------------------.
849 | Report that the YYRULE is going to be reduced. |
850 `------------------------------------------------*/
851
yy_reduce_print(yy_state_t * yyssp,YYSTYPE * yyvsp,int yyrule,Context * context)852 static void yy_reduce_print(yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule, Context *context)
853 {
854 int yylno = yyrline[yyrule];
855 int yynrhs = yyr2[yyrule];
856 int yyi;
857 YYFPRINTF(stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno);
858 /* The symbols being reduced. */
859 for (yyi = 0; yyi < yynrhs; yyi++)
860 {
861 YYFPRINTF(stderr, " $%d = ", yyi + 1);
862 yy_symbol_print(stderr, YY_ACCESSING_SYMBOL(+yyssp[yyi + 1 - yynrhs]),
863 &yyvsp[(yyi + 1) - (yynrhs)], context);
864 YYFPRINTF(stderr, "\n");
865 }
866 }
867
868 # define YY_REDUCE_PRINT(Rule) \
869 do \
870 { \
871 if (yydebug) \
872 yy_reduce_print(yyssp, yyvsp, Rule, context); \
873 } while (0)
874
875 /* Nonzero means print parse trace. It is left uninitialized so that
876 multiple parsers can coexist. */
877 int yydebug;
878 #else /* !PPDEBUG */
879 # define YYDPRINTF(Args) ((void)0)
880 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
881 # define YY_STACK_PRINT(Bottom, Top)
882 # define YY_REDUCE_PRINT(Rule)
883 #endif /* !PPDEBUG */
884
885 /* YYINITDEPTH -- initial size of the parser's stacks. */
886 #ifndef YYINITDEPTH
887 # define YYINITDEPTH 200
888 #endif
889
890 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
891 if the built-in stack extension method is used).
892
893 Do not make this value too large; the results are undefined if
894 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
895 evaluated with infinite-precision integer arithmetic. */
896
897 #ifndef YYMAXDEPTH
898 # define YYMAXDEPTH 10000
899 #endif
900
901 /*-----------------------------------------------.
902 | Release the memory associated to this symbol. |
903 `-----------------------------------------------*/
904
yydestruct(const char * yymsg,yysymbol_kind_t yykind,YYSTYPE * yyvaluep,Context * context)905 static void yydestruct(const char *yymsg,
906 yysymbol_kind_t yykind,
907 YYSTYPE *yyvaluep,
908 Context *context)
909 {
910 YY_USE(yyvaluep);
911 YY_USE(context);
912 if (!yymsg)
913 yymsg = "Deleting";
914 YY_SYMBOL_PRINT(yymsg, yykind, yyvaluep, yylocationp);
915
916 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
917 YY_USE(yykind);
918 YY_IGNORE_MAYBE_UNINITIALIZED_END
919 }
920
921 /*----------.
922 | yyparse. |
923 `----------*/
924
yyparse(Context * context)925 int yyparse(Context *context)
926 {
927 /* Lookahead token kind. */
928 int yychar;
929
930 /* The semantic value of the lookahead symbol. */
931 /* Default value used for initialization, for pacifying older GCCs
932 or non-GCC compilers. */
933 YY_INITIAL_VALUE(static YYSTYPE yyval_default;)
934 YYSTYPE yylval YY_INITIAL_VALUE(= yyval_default);
935
936 /* Number of syntax errors so far. */
937 int yynerrs = 0;
938
939 yy_state_fast_t yystate = 0;
940 /* Number of tokens to shift before error messages enabled. */
941 int yyerrstatus = 0;
942
943 /* Refer to the stacks through separate pointers, to allow yyoverflow
944 to reallocate them elsewhere. */
945
946 /* Their size. */
947 YYPTRDIFF_T yystacksize = YYINITDEPTH;
948
949 /* The state stack: array, bottom, top. */
950 yy_state_t yyssa[YYINITDEPTH];
951 yy_state_t *yyss = yyssa;
952 yy_state_t *yyssp = yyss;
953
954 /* The semantic value stack: array, bottom, top. */
955 YYSTYPE yyvsa[YYINITDEPTH];
956 YYSTYPE *yyvs = yyvsa;
957 YYSTYPE *yyvsp = yyvs;
958
959 int yyn;
960 /* The return value of yyparse. */
961 int yyresult;
962 /* Lookahead symbol kind. */
963 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
964 /* The variables used to return semantic value and location from the
965 action routines. */
966 YYSTYPE yyval;
967
968 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
969
970 /* The number of symbols on the RHS of the reduced rule.
971 Keep to zero when no symbol should be popped. */
972 int yylen = 0;
973
974 YYDPRINTF((stderr, "Starting parse\n"));
975
976 yychar = PPEMPTY; /* Cause a token to be read. */
977
978 goto yysetstate;
979
980 /*------------------------------------------------------------.
981 | yynewstate -- push a new state, which is found in yystate. |
982 `------------------------------------------------------------*/
983 yynewstate:
984 /* In all cases, when you get here, the value and location stacks
985 have just been pushed. So pushing a state here evens the stacks. */
986 yyssp++;
987
988 /*--------------------------------------------------------------------.
989 | yysetstate -- set current state (the top of the stack) to yystate. |
990 `--------------------------------------------------------------------*/
991 yysetstate:
992 YYDPRINTF((stderr, "Entering state %d\n", yystate));
993 YY_ASSERT(0 <= yystate && yystate < YYNSTATES);
994 YY_IGNORE_USELESS_CAST_BEGIN
995 *yyssp = YY_CAST(yy_state_t, yystate);
996 YY_IGNORE_USELESS_CAST_END
997 YY_STACK_PRINT(yyss, yyssp);
998
999 if (yyss + yystacksize - 1 <= yyssp)
1000 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1001 YYNOMEM;
1002 #else
1003 {
1004 /* Get the current used size of the three stacks, in elements. */
1005 YYPTRDIFF_T yysize = yyssp - yyss + 1;
1006
1007 # if defined yyoverflow
1008 {
1009 /* Give user a chance to reallocate the stack. Use copies of
1010 these so that the &'s don't force the real ones into
1011 memory. */
1012 yy_state_t *yyss1 = yyss;
1013 YYSTYPE *yyvs1 = yyvs;
1014
1015 /* Each stack pointer address is followed by the size of the
1016 data in use in that stack, in bytes. This used to be a
1017 conditional around just the two extra args, but that might
1018 be undefined if yyoverflow is a macro. */
1019 yyoverflow(YY_("memory exhausted"), &yyss1, yysize * YYSIZEOF(*yyssp), &yyvs1,
1020 yysize * YYSIZEOF(*yyvsp), &yystacksize);
1021 yyss = yyss1;
1022 yyvs = yyvs1;
1023 }
1024 # else /* defined YYSTACK_RELOCATE */
1025 /* Extend the stack our own way. */
1026 if (YYMAXDEPTH <= yystacksize)
1027 YYNOMEM;
1028 yystacksize *= 2;
1029 if (YYMAXDEPTH < yystacksize)
1030 yystacksize = YYMAXDEPTH;
1031
1032 {
1033 yy_state_t *yyss1 = yyss;
1034 union yyalloc *yyptr = YY_CAST(
1035 union yyalloc *, YYSTACK_ALLOC(YY_CAST(YYSIZE_T, YYSTACK_BYTES(yystacksize))));
1036 if (!yyptr)
1037 YYNOMEM;
1038 YYSTACK_RELOCATE(yyss_alloc, yyss);
1039 YYSTACK_RELOCATE(yyvs_alloc, yyvs);
1040 # undef YYSTACK_RELOCATE
1041 if (yyss1 != yyssa)
1042 YYSTACK_FREE(yyss1);
1043 }
1044 # endif
1045
1046 yyssp = yyss + yysize - 1;
1047 yyvsp = yyvs + yysize - 1;
1048
1049 YY_IGNORE_USELESS_CAST_BEGIN
1050 YYDPRINTF((stderr, "Stack size increased to %ld\n", YY_CAST(long, yystacksize)));
1051 YY_IGNORE_USELESS_CAST_END
1052
1053 if (yyss + yystacksize - 1 <= yyssp)
1054 YYABORT;
1055 }
1056 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1057
1058 if (yystate == YYFINAL)
1059 YYACCEPT;
1060
1061 goto yybackup;
1062
1063 /*-----------.
1064 | yybackup. |
1065 `-----------*/
1066 yybackup:
1067 /* Do appropriate processing given the current state. Read a
1068 lookahead token if we need one and don't already have one. */
1069
1070 /* First try to decide what to do without reference to lookahead token. */
1071 yyn = yypact[yystate];
1072 if (yypact_value_is_default(yyn))
1073 goto yydefault;
1074
1075 /* Not known => get a lookahead token if don't already have one. */
1076
1077 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1078 if (yychar == PPEMPTY)
1079 {
1080 YYDPRINTF((stderr, "Reading a token\n"));
1081 yychar = yylex(&yylval, context);
1082 }
1083
1084 if (yychar <= PPEOF)
1085 {
1086 yychar = PPEOF;
1087 yytoken = YYSYMBOL_YYEOF;
1088 YYDPRINTF((stderr, "Now at end of input.\n"));
1089 }
1090 else if (yychar == PPerror)
1091 {
1092 /* The scanner already issued an error message, process directly
1093 to error recovery. But do not keep the error token as
1094 lookahead, it is too special and may lead us to an endless
1095 loop in error recovery. */
1096 yychar = PPUNDEF;
1097 yytoken = YYSYMBOL_YYerror;
1098 goto yyerrlab1;
1099 }
1100 else
1101 {
1102 yytoken = YYTRANSLATE(yychar);
1103 YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc);
1104 }
1105
1106 /* If the proper action on seeing token YYTOKEN is to reduce or to
1107 detect an error, take that action. */
1108 yyn += yytoken;
1109 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1110 goto yydefault;
1111 yyn = yytable[yyn];
1112 if (yyn <= 0)
1113 {
1114 if (yytable_value_is_error(yyn))
1115 goto yyerrlab;
1116 yyn = -yyn;
1117 goto yyreduce;
1118 }
1119
1120 /* Count tokens shifted since error; after three, turn off error
1121 status. */
1122 if (yyerrstatus)
1123 yyerrstatus--;
1124
1125 /* Shift the lookahead token. */
1126 YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc);
1127 yystate = yyn;
1128 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1129 *++yyvsp = yylval;
1130 YY_IGNORE_MAYBE_UNINITIALIZED_END
1131
1132 /* Discard the shifted token. */
1133 yychar = PPEMPTY;
1134 goto yynewstate;
1135
1136 /*-----------------------------------------------------------.
1137 | yydefault -- do the default action for the current state. |
1138 `-----------------------------------------------------------*/
1139 yydefault:
1140 yyn = yydefact[yystate];
1141 if (yyn == 0)
1142 goto yyerrlab;
1143 goto yyreduce;
1144
1145 /*-----------------------------.
1146 | yyreduce -- do a reduction. |
1147 `-----------------------------*/
1148 yyreduce:
1149 /* yyn is the number of a rule to reduce with. */
1150 yylen = yyr2[yyn];
1151
1152 /* If YYLEN is nonzero, implement the default value of the action:
1153 '$$ = $1'.
1154
1155 Otherwise, the following line sets YYVAL to garbage.
1156 This behavior is undocumented and Bison
1157 users should not rely upon it. Assigning to YYVAL
1158 unconditionally makes the parser a bit smaller, and it avoids a
1159 GCC warning that YYVAL may be used uninitialized. */
1160 yyval = yyvsp[1 - yylen];
1161
1162 YY_REDUCE_PRINT(yyn);
1163 switch (yyn)
1164 {
1165 case 2: /* input: expression */
1166 {
1167 *(context->result) = static_cast<int>(yyvsp[0]);
1168 YYACCEPT;
1169 }
1170 break;
1171
1172 case 4: /* expression: TOK_IDENTIFIER */
1173 {
1174 if (!context->isIgnoringErrors())
1175 {
1176 // This rule should be applied right after the token is lexed, so we can
1177 // refer to context->token in the error message.
1178 context->diagnostics->report(context->errorSettings.unexpectedIdentifier,
1179 context->token->location, context->token->text);
1180 *(context->valid) = false;
1181 }
1182 yyval = yyvsp[0];
1183 }
1184 break;
1185
1186 case 5: /* $@1: %empty */
1187 {
1188 if (yyvsp[-1] != 0)
1189 {
1190 // Ignore errors in the short-circuited part of the expression.
1191 // ESSL3.00 section 3.4:
1192 // If an operand is not evaluated, the presence of undefined identifiers
1193 // in the operand will not cause an error.
1194 // Unevaluated division by zero should not cause an error either.
1195 context->startIgnoreErrors();
1196 }
1197 }
1198 break;
1199
1200 case 6: /* expression: expression TOK_OP_OR $@1 expression */
1201 {
1202 if (yyvsp[-3] != 0)
1203 {
1204 context->endIgnoreErrors();
1205 yyval = static_cast<YYSTYPE>(1);
1206 }
1207 else
1208 {
1209 yyval = yyvsp[-3] || yyvsp[0];
1210 }
1211 }
1212 break;
1213
1214 case 7: /* $@2: %empty */
1215 {
1216 if (yyvsp[-1] == 0)
1217 {
1218 // Ignore errors in the short-circuited part of the expression.
1219 // ESSL3.00 section 3.4:
1220 // If an operand is not evaluated, the presence of undefined identifiers
1221 // in the operand will not cause an error.
1222 // Unevaluated division by zero should not cause an error either.
1223 context->startIgnoreErrors();
1224 }
1225 }
1226 break;
1227
1228 case 8: /* expression: expression TOK_OP_AND $@2 expression */
1229 {
1230 if (yyvsp[-3] == 0)
1231 {
1232 context->endIgnoreErrors();
1233 yyval = static_cast<YYSTYPE>(0);
1234 }
1235 else
1236 {
1237 yyval = yyvsp[-3] && yyvsp[0];
1238 }
1239 }
1240 break;
1241
1242 case 9: /* expression: expression '|' expression */
1243 {
1244 yyval = yyvsp[-2] | yyvsp[0];
1245 }
1246 break;
1247
1248 case 10: /* expression: expression '^' expression */
1249 {
1250 yyval = yyvsp[-2] ^ yyvsp[0];
1251 }
1252 break;
1253
1254 case 11: /* expression: expression '&' expression */
1255 {
1256 yyval = yyvsp[-2] & yyvsp[0];
1257 }
1258 break;
1259
1260 case 12: /* expression: expression TOK_OP_NE expression */
1261 {
1262 yyval = yyvsp[-2] != yyvsp[0];
1263 }
1264 break;
1265
1266 case 13: /* expression: expression TOK_OP_EQ expression */
1267 {
1268 yyval = yyvsp[-2] == yyvsp[0];
1269 }
1270 break;
1271
1272 case 14: /* expression: expression TOK_OP_GE expression */
1273 {
1274 yyval = yyvsp[-2] >= yyvsp[0];
1275 }
1276 break;
1277
1278 case 15: /* expression: expression TOK_OP_LE expression */
1279 {
1280 yyval = yyvsp[-2] <= yyvsp[0];
1281 }
1282 break;
1283
1284 case 16: /* expression: expression '>' expression */
1285 {
1286 yyval = yyvsp[-2] > yyvsp[0];
1287 }
1288 break;
1289
1290 case 17: /* expression: expression '<' expression */
1291 {
1292 yyval = yyvsp[-2] < yyvsp[0];
1293 }
1294 break;
1295
1296 case 18: /* expression: expression TOK_OP_RIGHT expression */
1297 {
1298 if (yyvsp[0] < 0 || yyvsp[0] > 31)
1299 {
1300 if (!context->isIgnoringErrors())
1301 {
1302 std::ostringstream stream;
1303 stream << yyvsp[-2] << " >> " << yyvsp[0];
1304 std::string text = stream.str();
1305 context->diagnostics->report(angle::pp::Diagnostics::PP_UNDEFINED_SHIFT,
1306 context->token->location, text.c_str());
1307 *(context->valid) = false;
1308 }
1309 yyval = static_cast<YYSTYPE>(0);
1310 }
1311 else if (yyvsp[-2] < 0)
1312 {
1313 // Logical shift right.
1314 yyval = static_cast<YYSTYPE>(static_cast<UNSIGNED_TYPE>(yyvsp[-2]) >> yyvsp[0]);
1315 }
1316 else
1317 {
1318 yyval = yyvsp[-2] >> yyvsp[0];
1319 }
1320 }
1321 break;
1322
1323 case 19: /* expression: expression TOK_OP_LEFT expression */
1324 {
1325 if (yyvsp[0] < 0 || yyvsp[0] > 31)
1326 {
1327 if (!context->isIgnoringErrors())
1328 {
1329 std::ostringstream stream;
1330 stream << yyvsp[-2] << " << " << yyvsp[0];
1331 std::string text = stream.str();
1332 context->diagnostics->report(angle::pp::Diagnostics::PP_UNDEFINED_SHIFT,
1333 context->token->location, text.c_str());
1334 *(context->valid) = false;
1335 }
1336 yyval = static_cast<YYSTYPE>(0);
1337 }
1338 else
1339 {
1340 // Logical shift left. Casting to unsigned is needed to ensure there's no signed
1341 // integer overflow, which some tools treat as an error.
1342 yyval = static_cast<YYSTYPE>(static_cast<UNSIGNED_TYPE>(yyvsp[-2]) << yyvsp[0]);
1343 }
1344 }
1345 break;
1346
1347 case 20: /* expression: expression '-' expression */
1348 {
1349 yyval = gl::WrappingDiff<YYSTYPE>(yyvsp[-2], yyvsp[0]);
1350 }
1351 break;
1352
1353 case 21: /* expression: expression '+' expression */
1354 {
1355 yyval = gl::WrappingSum<YYSTYPE>(yyvsp[-2], yyvsp[0]);
1356 }
1357 break;
1358
1359 case 22: /* expression: expression '%' expression */
1360 {
1361 if (yyvsp[0] == 0)
1362 {
1363 if (!context->isIgnoringErrors())
1364 {
1365 std::ostringstream stream;
1366 stream << yyvsp[-2] << " % " << yyvsp[0];
1367 std::string text = stream.str();
1368 context->diagnostics->report(angle::pp::Diagnostics::PP_DIVISION_BY_ZERO,
1369 context->token->location, text.c_str());
1370 *(context->valid) = false;
1371 }
1372 yyval = static_cast<YYSTYPE>(0);
1373 }
1374 else if ((yyvsp[-2] == std::numeric_limits<YYSTYPE>::min()) && (yyvsp[0] == -1))
1375 {
1376 // Check for the special case where the minimum representable number is
1377 // divided by -1. If left alone this has undefined results.
1378 yyval = 0;
1379 }
1380 else
1381 {
1382 yyval = yyvsp[-2] % yyvsp[0];
1383 }
1384 }
1385 break;
1386
1387 case 23: /* expression: expression '/' expression */
1388 {
1389 if (yyvsp[0] == 0)
1390 {
1391 if (!context->isIgnoringErrors())
1392 {
1393 std::ostringstream stream;
1394 stream << yyvsp[-2] << " / " << yyvsp[0];
1395 std::string text = stream.str();
1396 context->diagnostics->report(angle::pp::Diagnostics::PP_DIVISION_BY_ZERO,
1397 context->token->location, text.c_str());
1398 *(context->valid) = false;
1399 }
1400 yyval = static_cast<YYSTYPE>(0);
1401 }
1402 else if ((yyvsp[-2] == std::numeric_limits<YYSTYPE>::min()) && (yyvsp[0] == -1))
1403 {
1404 // Check for the special case where the minimum representable number is
1405 // divided by -1. If left alone this leads to integer overflow in C++, which
1406 // has undefined results.
1407 yyval = std::numeric_limits<YYSTYPE>::max();
1408 }
1409 else
1410 {
1411 yyval = yyvsp[-2] / yyvsp[0];
1412 }
1413 }
1414 break;
1415
1416 case 24: /* expression: expression '*' expression */
1417 {
1418 yyval = gl::WrappingMul(yyvsp[-2], yyvsp[0]);
1419 }
1420 break;
1421
1422 case 25: /* expression: '!' expression */
1423 {
1424 yyval = !yyvsp[0];
1425 }
1426 break;
1427
1428 case 26: /* expression: '~' expression */
1429 {
1430 yyval = ~yyvsp[0];
1431 }
1432 break;
1433
1434 case 27: /* expression: '-' expression */
1435 {
1436 // Check for negation of minimum representable integer to prevent undefined signed int
1437 // overflow.
1438 if (yyvsp[0] == std::numeric_limits<YYSTYPE>::min())
1439 {
1440 yyval = std::numeric_limits<YYSTYPE>::min();
1441 }
1442 else
1443 {
1444 yyval = -yyvsp[0];
1445 }
1446 }
1447 break;
1448
1449 case 28: /* expression: '+' expression */
1450 {
1451 yyval = +yyvsp[0];
1452 }
1453 break;
1454
1455 case 29: /* expression: '(' expression ')' */
1456 {
1457 yyval = yyvsp[-1];
1458 }
1459 break;
1460
1461 default:
1462 break;
1463 }
1464 /* User semantic actions sometimes alter yychar, and that requires
1465 that yytoken be updated with the new translation. We take the
1466 approach of translating immediately before every use of yytoken.
1467 One alternative is translating here after every semantic action,
1468 but that translation would be missed if the semantic action invokes
1469 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1470 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1471 incorrect destructor might then be invoked immediately. In the
1472 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1473 to an incorrect destructor call or verbose syntax error message
1474 before the lookahead is translated. */
1475 YY_SYMBOL_PRINT("-> $$ =", YY_CAST(yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
1476
1477 YYPOPSTACK(yylen);
1478 yylen = 0;
1479
1480 *++yyvsp = yyval;
1481
1482 /* Now 'shift' the result of the reduction. Determine what state
1483 that goes to, based on the state we popped back to and the rule
1484 number reduced by. */
1485 {
1486 const int yylhs = yyr1[yyn] - YYNTOKENS;
1487 const int yyi = yypgoto[yylhs] + *yyssp;
1488 yystate =
1489 (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp ? yytable[yyi] : yydefgoto[yylhs]);
1490 }
1491
1492 goto yynewstate;
1493
1494 /*--------------------------------------.
1495 | yyerrlab -- here on detecting error. |
1496 `--------------------------------------*/
1497 yyerrlab:
1498 /* Make sure we have latest lookahead translation. See comments at
1499 user semantic actions for why this is necessary. */
1500 yytoken = yychar == PPEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE(yychar);
1501 /* If not already recovering from an error, report this error. */
1502 if (!yyerrstatus)
1503 {
1504 ++yynerrs;
1505 yyerror(context, YY_("syntax error"));
1506 }
1507
1508 if (yyerrstatus == 3)
1509 {
1510 /* If just tried and failed to reuse lookahead token after an
1511 error, discard it. */
1512
1513 if (yychar <= PPEOF)
1514 {
1515 /* Return failure if at end of input. */
1516 if (yychar == PPEOF)
1517 YYABORT;
1518 }
1519 else
1520 {
1521 yydestruct("Error: discarding", yytoken, &yylval, context);
1522 yychar = PPEMPTY;
1523 }
1524 }
1525
1526 /* Else will try to reuse lookahead token after shifting the error
1527 token. */
1528 goto yyerrlab1;
1529
1530 /*---------------------------------------------------.
1531 | yyerrorlab -- error raised explicitly by YYERROR. |
1532 `---------------------------------------------------*/
1533 yyerrorlab:
1534 /* Pacify compilers when the user code never invokes YYERROR and the
1535 label yyerrorlab therefore never appears in user code. */
1536 if (0)
1537 YYERROR;
1538 ++yynerrs;
1539
1540 /* Do not reclaim the symbols of the rule whose action triggered
1541 this YYERROR. */
1542 YYPOPSTACK(yylen);
1543 yylen = 0;
1544 YY_STACK_PRINT(yyss, yyssp);
1545 yystate = *yyssp;
1546 goto yyerrlab1;
1547
1548 /*-------------------------------------------------------------.
1549 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1550 `-------------------------------------------------------------*/
1551 yyerrlab1:
1552 yyerrstatus = 3; /* Each real token shifted decrements this. */
1553
1554 /* Pop stack until we find a state that shifts the error token. */
1555 for (;;)
1556 {
1557 yyn = yypact[yystate];
1558 if (!yypact_value_is_default(yyn))
1559 {
1560 yyn += YYSYMBOL_YYerror;
1561 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
1562 {
1563 yyn = yytable[yyn];
1564 if (0 < yyn)
1565 break;
1566 }
1567 }
1568
1569 /* Pop the current state because it cannot handle the error token. */
1570 if (yyssp == yyss)
1571 YYABORT;
1572
1573 yydestruct("Error: popping", YY_ACCESSING_SYMBOL(yystate), yyvsp, context);
1574 YYPOPSTACK(1);
1575 yystate = *yyssp;
1576 YY_STACK_PRINT(yyss, yyssp);
1577 }
1578
1579 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1580 *++yyvsp = yylval;
1581 YY_IGNORE_MAYBE_UNINITIALIZED_END
1582
1583 /* Shift the error token. */
1584 YY_SYMBOL_PRINT("Shifting", YY_ACCESSING_SYMBOL(yyn), yyvsp, yylsp);
1585
1586 yystate = yyn;
1587 goto yynewstate;
1588
1589 /*-------------------------------------.
1590 | yyacceptlab -- YYACCEPT comes here. |
1591 `-------------------------------------*/
1592 yyacceptlab:
1593 yyresult = 0;
1594 goto yyreturnlab;
1595
1596 /*-----------------------------------.
1597 | yyabortlab -- YYABORT comes here. |
1598 `-----------------------------------*/
1599 yyabortlab:
1600 yyresult = 1;
1601 goto yyreturnlab;
1602
1603 /*-----------------------------------------------------------.
1604 | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
1605 `-----------------------------------------------------------*/
1606 yyexhaustedlab:
1607 yyerror(context, YY_("memory exhausted"));
1608 yyresult = 2;
1609 goto yyreturnlab;
1610
1611 /*----------------------------------------------------------.
1612 | yyreturnlab -- parsing is finished, clean up and return. |
1613 `----------------------------------------------------------*/
1614 yyreturnlab:
1615 if (yychar != PPEMPTY)
1616 {
1617 /* Make sure we have latest lookahead translation. See comments at
1618 user semantic actions for why this is necessary. */
1619 yytoken = YYTRANSLATE(yychar);
1620 yydestruct("Cleanup: discarding lookahead", yytoken, &yylval, context);
1621 }
1622 /* Do not reclaim the symbols of the rule whose action triggered
1623 this YYABORT or YYACCEPT. */
1624 YYPOPSTACK(yylen);
1625 YY_STACK_PRINT(yyss, yyssp);
1626 while (yyssp != yyss)
1627 {
1628 yydestruct("Cleanup: popping", YY_ACCESSING_SYMBOL(+*yyssp), yyvsp, context);
1629 YYPOPSTACK(1);
1630 }
1631 #ifndef yyoverflow
1632 if (yyss != yyssa)
1633 YYSTACK_FREE(yyss);
1634 #endif
1635
1636 return yyresult;
1637 }
1638
yylex(YYSTYPE * lvalp,Context * context)1639 int yylex(YYSTYPE *lvalp, Context *context)
1640 {
1641 angle::pp::Token *token = context->token;
1642 if (!context->parsePresetToken)
1643 {
1644 context->lexer->lex(token);
1645 }
1646 context->parsePresetToken = false;
1647
1648 int type = 0;
1649
1650 switch (token->type)
1651 {
1652 case angle::pp::Token::CONST_INT:
1653 {
1654 unsigned int val = 0;
1655 int testVal = 0;
1656 if (!token->uValue(&val) ||
1657 (!token->iValue(&testVal) &&
1658 context->errorSettings.integerLiteralsMustFit32BitSignedRange))
1659 {
1660 context->diagnostics->report(angle::pp::Diagnostics::PP_INTEGER_OVERFLOW,
1661 token->location, token->text);
1662 *(context->valid) = false;
1663 }
1664 *lvalp = static_cast<YYSTYPE>(val);
1665 type = TOK_CONST_INT;
1666 break;
1667 }
1668 case angle::pp::Token::IDENTIFIER:
1669 *lvalp = static_cast<YYSTYPE>(-1);
1670 type = TOK_IDENTIFIER;
1671 break;
1672 case angle::pp::Token::OP_OR:
1673 type = TOK_OP_OR;
1674 break;
1675 case angle::pp::Token::OP_AND:
1676 type = TOK_OP_AND;
1677 break;
1678 case angle::pp::Token::OP_NE:
1679 type = TOK_OP_NE;
1680 break;
1681 case angle::pp::Token::OP_EQ:
1682 type = TOK_OP_EQ;
1683 break;
1684 case angle::pp::Token::OP_GE:
1685 type = TOK_OP_GE;
1686 break;
1687 case angle::pp::Token::OP_LE:
1688 type = TOK_OP_LE;
1689 break;
1690 case angle::pp::Token::OP_RIGHT:
1691 type = TOK_OP_RIGHT;
1692 break;
1693 case angle::pp::Token::OP_LEFT:
1694 type = TOK_OP_LEFT;
1695 break;
1696 case '|':
1697 case '^':
1698 case '&':
1699 case '>':
1700 case '<':
1701 case '-':
1702 case '+':
1703 case '%':
1704 case '/':
1705 case '*':
1706 case '!':
1707 case '~':
1708 case '(':
1709 case ')':
1710 type = token->type;
1711 break;
1712
1713 default:
1714 break;
1715 }
1716
1717 return type;
1718 }
1719
yyerror(Context * context,const char * reason)1720 void yyerror(Context *context, const char *reason)
1721 {
1722 context->diagnostics->report(angle::pp::Diagnostics::PP_INVALID_EXPRESSION,
1723 context->token->location, reason);
1724 }
1725
1726 namespace angle
1727 {
1728
1729 namespace pp
1730 {
1731
ExpressionParser(Lexer * lexer,Diagnostics * diagnostics)1732 ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)
1733 : mLexer(lexer), mDiagnostics(diagnostics)
1734 {}
1735
parse(Token * token,int * result,bool parsePresetToken,const ErrorSettings & errorSettings,bool * valid)1736 bool ExpressionParser::parse(Token *token,
1737 int *result,
1738 bool parsePresetToken,
1739 const ErrorSettings &errorSettings,
1740 bool *valid)
1741 {
1742 Context context;
1743 context.diagnostics = mDiagnostics;
1744 context.lexer = mLexer;
1745 context.token = token;
1746 context.result = result;
1747 context.ignoreErrors = 0;
1748 context.parsePresetToken = parsePresetToken;
1749 context.errorSettings = errorSettings;
1750 context.valid = valid;
1751 int ret = yyparse(&context);
1752 switch (ret)
1753 {
1754 case 0:
1755 case 1:
1756 break;
1757
1758 case 2:
1759 mDiagnostics->report(Diagnostics::PP_OUT_OF_MEMORY, token->location, "");
1760 break;
1761
1762 default:
1763 assert(false);
1764 mDiagnostics->report(Diagnostics::PP_INTERNAL_ERROR, token->location, "");
1765 break;
1766 }
1767
1768 return ret == 0;
1769 }
1770
1771 } // namespace pp
1772
1773 } // namespace angle
1774