1 /* A Bison parser, made by GNU Bison 3.5.  */
2 
3 /* Bison implementation for Yacc-like parsers in C
4 
5    Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 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"
52 
53 /* Skeleton name.  */
54 #define YYSKELETON_NAME "yacc.c"
55 
56 /* Pure parsers.  */
57 #define YYPURE 1
58 
59 /* Push parsers.  */
60 #define YYPUSH 0
61 
62 /* Pull parsers.  */
63 #define YYPULL 1
64 
65 
66 /* Substitute the variable and function names.  */
67 #define yyparse         glcpp_parser_parse
68 #define yylex           glcpp_parser_lex
69 #define yyerror         glcpp_parser_error
70 #define yydebug         glcpp_parser_debug
71 #define yynerrs         glcpp_parser_nerrs
72 
73 /* First part of user prologue.  */
74 #line 1 "src/compiler/glsl/glcpp/glcpp-parse.y"
75 
76 /*
77  * Copyright © 2010 Intel Corporation
78  *
79  * Permission is hereby granted, free of charge, to any person obtaining a
80  * copy of this software and associated documentation files (the "Software"),
81  * to deal in the Software without restriction, including without limitation
82  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
83  * and/or sell copies of the Software, and to permit persons to whom the
84  * Software is furnished to do so, subject to the following conditions:
85  *
86  * The above copyright notice and this permission notice (including the next
87  * paragraph) shall be included in all copies or substantial portions of the
88  * Software.
89  *
90  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
91  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
92  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
93  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
94  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
95  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
96  * DEALINGS IN THE SOFTWARE.
97  */
98 
99 #include <stdio.h>
100 #include <stdlib.h>
101 #include <string.h>
102 #include <assert.h>
103 #include <inttypes.h>
104 
105 #include "glcpp.h"
106 #include "main/mtypes.h"
107 #include "util/strndup.h"
108 
109 const char *
110 _mesa_lookup_shader_include(struct gl_context *ctx, char *path,
111                             bool error_check);
112 
113 size_t
114 _mesa_get_shader_include_cursor(struct gl_shared_state *shared);
115 
116 void
117 _mesa_set_shader_include_cursor(struct gl_shared_state *shared, size_t cursor);
118 
119 static void
120 yyerror(YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
121 
122 static void
123 _define_object_macro(glcpp_parser_t *parser,
124                      YYLTYPE *loc,
125                      const char *macro,
126                      token_list_t *replacements);
127 
128 static void
129 _define_function_macro(glcpp_parser_t *parser,
130                        YYLTYPE *loc,
131                        const char *macro,
132                        string_list_t *parameters,
133                        token_list_t *replacements);
134 
135 static string_list_t *
136 _string_list_create(glcpp_parser_t *parser);
137 
138 static void
139 _string_list_append_item(glcpp_parser_t *parser, string_list_t *list,
140                          const char *str);
141 
142 static int
143 _string_list_contains(string_list_t *list, const char *member, int *index);
144 
145 static const char *
146 _string_list_has_duplicate(string_list_t *list);
147 
148 static int
149 _string_list_length(string_list_t *list);
150 
151 static int
152 _string_list_equal(string_list_t *a, string_list_t *b);
153 
154 static argument_list_t *
155 _argument_list_create(glcpp_parser_t *parser);
156 
157 static void
158 _argument_list_append(glcpp_parser_t *parser, argument_list_t *list,
159                       token_list_t *argument);
160 
161 static int
162 _argument_list_length(argument_list_t *list);
163 
164 static token_list_t *
165 _argument_list_member_at(argument_list_t *list, int index);
166 
167 static token_t *
168 _token_create_str(glcpp_parser_t *parser, int type, char *str);
169 
170 static token_t *
171 _token_create_ival(glcpp_parser_t *parser, int type, int ival);
172 
173 static token_list_t *
174 _token_list_create(glcpp_parser_t *parser);
175 
176 static void
177 _token_list_append(glcpp_parser_t *parser, token_list_t *list, token_t *token);
178 
179 static void
180 _token_list_append_list(token_list_t *list, token_list_t *tail);
181 
182 static int
183 _token_list_equal_ignoring_space(token_list_t *a, token_list_t *b);
184 
185 static void
186 _parser_active_list_push(glcpp_parser_t *parser, const char *identifier,
187                          token_node_t *marker);
188 
189 static void
190 _parser_active_list_pop(glcpp_parser_t *parser);
191 
192 static int
193 _parser_active_list_contains(glcpp_parser_t *parser, const char *identifier);
194 
195 typedef enum {
196    EXPANSION_MODE_IGNORE_DEFINED,
197    EXPANSION_MODE_EVALUATE_DEFINED
198 } expansion_mode_t;
199 
200 /* Expand list, and begin lexing from the result (after first
201  * prefixing a token of type 'head_token_type').
202  */
203 static void
204 _glcpp_parser_expand_and_lex_from(glcpp_parser_t *parser, int head_token_type,
205                                   token_list_t *list, expansion_mode_t mode);
206 
207 /* Perform macro expansion in-place on the given list. */
208 static void
209 _glcpp_parser_expand_token_list(glcpp_parser_t *parser, token_list_t *list,
210                                 expansion_mode_t mode);
211 
212 static void
213 _glcpp_parser_print_expanded_token_list(glcpp_parser_t *parser,
214                                         token_list_t *list);
215 
216 static void
217 _glcpp_parser_skip_stack_push_if(glcpp_parser_t *parser, YYLTYPE *loc,
218                                  int condition);
219 
220 static void
221 _glcpp_parser_skip_stack_change_if(glcpp_parser_t *parser, YYLTYPE *loc,
222                                    const char *type, int condition);
223 
224 static void
225 _glcpp_parser_skip_stack_pop(glcpp_parser_t *parser, YYLTYPE *loc);
226 
227 static void
228 _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t version,
229                                          const char *ident, bool explicitly_set);
230 
231 static int
232 glcpp_parser_lex(YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
233 
234 static void
235 glcpp_parser_lex_from(glcpp_parser_t *parser, token_list_t *list);
236 
237 struct define_include {
238    glcpp_parser_t *parser;
239    YYLTYPE *loc;
240 };
241 
242 static void
243 glcpp_parser_copy_defines(const void *key, void *data, void *closure);
244 
245 static void
246 add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
247 
248 
249 #line 250 "src/compiler/glsl/glcpp/glcpp-parse.c"
250 
251 # ifndef YY_CAST
252 #  ifdef __cplusplus
253 #   define YY_CAST(Type, Val) static_cast<Type> (Val)
254 #   define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
255 #  else
256 #   define YY_CAST(Type, Val) ((Type) (Val))
257 #   define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
258 #  endif
259 # endif
260 # ifndef YY_NULLPTR
261 #  if defined __cplusplus
262 #   if 201103L <= __cplusplus
263 #    define YY_NULLPTR nullptr
264 #   else
265 #    define YY_NULLPTR 0
266 #   endif
267 #  else
268 #   define YY_NULLPTR ((void*)0)
269 #  endif
270 # endif
271 
272 /* Enabling verbose error messages.  */
273 #ifdef YYERROR_VERBOSE
274 # undef YYERROR_VERBOSE
275 # define YYERROR_VERBOSE 1
276 #else
277 # define YYERROR_VERBOSE 1
278 #endif
279 
280 /* Use api.header.include to #include this header
281    instead of duplicating it here.  */
282 #ifndef YY_GLCPP_PARSER_SRC_COMPILER_GLSL_GLCPP_GLCPP_PARSE_H_INCLUDED
283 # define YY_GLCPP_PARSER_SRC_COMPILER_GLSL_GLCPP_GLCPP_PARSE_H_INCLUDED
284 /* Debug traces.  */
285 #ifndef YYDEBUG
286 # define YYDEBUG 1
287 #endif
288 #if YYDEBUG
289 extern int glcpp_parser_debug;
290 #endif
291 
292 /* Token type.  */
293 #ifndef YYTOKENTYPE
294 # define YYTOKENTYPE
295   enum yytokentype
296   {
297     DEFINED = 258,
298     ELIF_EXPANDED = 259,
299     HASH_TOKEN = 260,
300     DEFINE_TOKEN = 261,
301     FUNC_IDENTIFIER = 262,
302     OBJ_IDENTIFIER = 263,
303     ELIF = 264,
304     ELSE = 265,
305     ENDIF = 266,
306     ERROR_TOKEN = 267,
307     IF = 268,
308     IFDEF = 269,
309     IFNDEF = 270,
310     LINE = 271,
311     PRAGMA = 272,
312     UNDEF = 273,
313     VERSION_TOKEN = 274,
314     GARBAGE = 275,
315     IDENTIFIER = 276,
316     IF_EXPANDED = 277,
317     INTEGER = 278,
318     INTEGER_STRING = 279,
319     LINE_EXPANDED = 280,
320     NEWLINE = 281,
321     OTHER = 282,
322     PLACEHOLDER = 283,
323     SPACE = 284,
324     PLUS_PLUS = 285,
325     MINUS_MINUS = 286,
326     PATH = 287,
327     INCLUDE = 288,
328     PASTE = 289,
329     OR = 290,
330     AND = 291,
331     EQUAL = 292,
332     NOT_EQUAL = 293,
333     LESS_OR_EQUAL = 294,
334     GREATER_OR_EQUAL = 295,
335     LEFT_SHIFT = 296,
336     RIGHT_SHIFT = 297,
337     UNARY = 298
338   };
339 #endif
340 
341 /* Value type.  */
342 
343 /* Location type.  */
344 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
345 typedef struct YYLTYPE YYLTYPE;
346 struct YYLTYPE
347 {
348   int first_line;
349   int first_column;
350   int last_line;
351   int last_column;
352 };
353 # define YYLTYPE_IS_DECLARED 1
354 # define YYLTYPE_IS_TRIVIAL 1
355 #endif
356 
357 
358 
359 int glcpp_parser_parse (glcpp_parser_t *parser);
360 
361 #endif /* !YY_GLCPP_PARSER_SRC_COMPILER_GLSL_GLCPP_GLCPP_PARSE_H_INCLUDED  */
362 
363 
364 
365 #ifdef short
366 # undef short
367 #endif
368 
369 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
370    <limits.h> and (if available) <stdint.h> are included
371    so that the code can choose integer types of a good width.  */
372 
373 #ifndef __PTRDIFF_MAX__
374 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
375 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
376 #  include <stdint.h> /* INFRINGES ON USER NAME SPACE */
377 #  define YY_STDINT_H
378 # endif
379 #endif
380 
381 /* Narrow types that promote to a signed type and that can represent a
382    signed or unsigned integer of at least N bits.  In tables they can
383    save space and decrease cache pressure.  Promoting to a signed type
384    helps avoid bugs in integer arithmetic.  */
385 
386 #ifdef __INT_LEAST8_MAX__
387 typedef __INT_LEAST8_TYPE__ yytype_int8;
388 #elif defined YY_STDINT_H
389 typedef int_least8_t yytype_int8;
390 #else
391 typedef signed char yytype_int8;
392 #endif
393 
394 #ifdef __INT_LEAST16_MAX__
395 typedef __INT_LEAST16_TYPE__ yytype_int16;
396 #elif defined YY_STDINT_H
397 typedef int_least16_t yytype_int16;
398 #else
399 typedef short yytype_int16;
400 #endif
401 
402 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
403 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
404 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
405        && UINT_LEAST8_MAX <= INT_MAX)
406 typedef uint_least8_t yytype_uint8;
407 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
408 typedef unsigned char yytype_uint8;
409 #else
410 typedef short yytype_uint8;
411 #endif
412 
413 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
414 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
415 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
416        && UINT_LEAST16_MAX <= INT_MAX)
417 typedef uint_least16_t yytype_uint16;
418 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
419 typedef unsigned short yytype_uint16;
420 #else
421 typedef int yytype_uint16;
422 #endif
423 
424 #ifndef YYPTRDIFF_T
425 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
426 #  define YYPTRDIFF_T __PTRDIFF_TYPE__
427 #  define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
428 # elif defined PTRDIFF_MAX
429 #  ifndef ptrdiff_t
430 #   include <stddef.h> /* INFRINGES ON USER NAME SPACE */
431 #  endif
432 #  define YYPTRDIFF_T ptrdiff_t
433 #  define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
434 # else
435 #  define YYPTRDIFF_T long
436 #  define YYPTRDIFF_MAXIMUM LONG_MAX
437 # endif
438 #endif
439 
440 #ifndef YYSIZE_T
441 # ifdef __SIZE_TYPE__
442 #  define YYSIZE_T __SIZE_TYPE__
443 # elif defined size_t
444 #  define YYSIZE_T size_t
445 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
446 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
447 #  define YYSIZE_T size_t
448 # else
449 #  define YYSIZE_T unsigned
450 # endif
451 #endif
452 
453 #define YYSIZE_MAXIMUM                                  \
454   YY_CAST (YYPTRDIFF_T,                                 \
455            (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1)  \
456             ? YYPTRDIFF_MAXIMUM                         \
457             : YY_CAST (YYSIZE_T, -1)))
458 
459 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
460 
461 /* Stored state numbers (used for stacks). */
462 typedef yytype_uint8 yy_state_t;
463 
464 /* State numbers in computations.  */
465 typedef int yy_state_fast_t;
466 
467 #ifndef YY_
468 # if defined YYENABLE_NLS && YYENABLE_NLS
469 #  if ENABLE_NLS
470 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
471 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
472 #  endif
473 # endif
474 # ifndef YY_
475 #  define YY_(Msgid) Msgid
476 # endif
477 #endif
478 
479 #ifndef YY_ATTRIBUTE_PURE
480 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
481 #  define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
482 # else
483 #  define YY_ATTRIBUTE_PURE
484 # endif
485 #endif
486 
487 #ifndef YY_ATTRIBUTE_UNUSED
488 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
489 #  define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
490 # else
491 #  define YY_ATTRIBUTE_UNUSED
492 # endif
493 #endif
494 
495 /* Suppress unused-variable warnings by "using" E.  */
496 #if ! defined lint || defined __GNUC__
497 # define YYUSE(E) ((void) (E))
498 #else
499 # define YYUSE(E) /* empty */
500 #endif
501 
502 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
503 /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
504 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                            \
505     _Pragma ("GCC diagnostic push")                                     \
506     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")              \
507     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
508 # define YY_IGNORE_MAYBE_UNINITIALIZED_END      \
509     _Pragma ("GCC diagnostic pop")
510 #else
511 # define YY_INITIAL_VALUE(Value) Value
512 #endif
513 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
514 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
515 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
516 #endif
517 #ifndef YY_INITIAL_VALUE
518 # define YY_INITIAL_VALUE(Value) /* Nothing. */
519 #endif
520 
521 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
522 # define YY_IGNORE_USELESS_CAST_BEGIN                          \
523     _Pragma ("GCC diagnostic push")                            \
524     _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
525 # define YY_IGNORE_USELESS_CAST_END            \
526     _Pragma ("GCC diagnostic pop")
527 #endif
528 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
529 # define YY_IGNORE_USELESS_CAST_BEGIN
530 # define YY_IGNORE_USELESS_CAST_END
531 #endif
532 
533 
534 #define YY_ASSERT(E) ((void) (0 && (E)))
535 
536 #if ! defined yyoverflow || YYERROR_VERBOSE
537 
538 /* The parser invokes alloca or malloc; define the necessary symbols.  */
539 
540 # ifdef YYSTACK_USE_ALLOCA
541 #  if YYSTACK_USE_ALLOCA
542 #   ifdef __GNUC__
543 #    define YYSTACK_ALLOC __builtin_alloca
544 #   elif defined __BUILTIN_VA_ARG_INCR
545 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
546 #   elif defined _AIX
547 #    define YYSTACK_ALLOC __alloca
548 #   elif defined _MSC_VER
549 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
550 #    define alloca _alloca
551 #   else
552 #    define YYSTACK_ALLOC alloca
553 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
554 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
555       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
556 #     ifndef EXIT_SUCCESS
557 #      define EXIT_SUCCESS 0
558 #     endif
559 #    endif
560 #   endif
561 #  endif
562 # endif
563 
564 # ifdef YYSTACK_ALLOC
565    /* Pacify GCC's 'empty if-body' warning.  */
566 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
567 #  ifndef YYSTACK_ALLOC_MAXIMUM
568     /* The OS might guarantee only one guard page at the bottom of the stack,
569        and a page size can be as small as 4096 bytes.  So we cannot safely
570        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
571        to allow for a few compiler-allocated temporary stack slots.  */
572 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
573 #  endif
574 # else
575 #  define YYSTACK_ALLOC YYMALLOC
576 #  define YYSTACK_FREE YYFREE
577 #  ifndef YYSTACK_ALLOC_MAXIMUM
578 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
579 #  endif
580 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
581        && ! ((defined YYMALLOC || defined malloc) \
582              && (defined YYFREE || defined free)))
583 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
584 #   ifndef EXIT_SUCCESS
585 #    define EXIT_SUCCESS 0
586 #   endif
587 #  endif
588 #  ifndef YYMALLOC
589 #   define YYMALLOC malloc
590 #   if ! defined malloc && ! defined EXIT_SUCCESS
591 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
592 #   endif
593 #  endif
594 #  ifndef YYFREE
595 #   define YYFREE free
596 #   if ! defined free && ! defined EXIT_SUCCESS
597 void free (void *); /* INFRINGES ON USER NAME SPACE */
598 #   endif
599 #  endif
600 # endif
601 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
602 
603 
604 #if (! defined yyoverflow \
605      && (! defined __cplusplus \
606          || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
607              && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
608 
609 /* A type that is properly aligned for any stack member.  */
610 union yyalloc
611 {
612   yy_state_t yyss_alloc;
613   YYSTYPE yyvs_alloc;
614   YYLTYPE yyls_alloc;
615 };
616 
617 /* The size of the maximum gap between one aligned stack and the next.  */
618 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
619 
620 /* The size of an array large to enough to hold all stacks, each with
621    N elements.  */
622 # define YYSTACK_BYTES(N) \
623      ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \
624              + YYSIZEOF (YYLTYPE)) \
625       + 2 * YYSTACK_GAP_MAXIMUM)
626 
627 # define YYCOPY_NEEDED 1
628 
629 /* Relocate STACK from its old location to the new one.  The
630    local variables YYSIZE and YYSTACKSIZE give the old and new number of
631    elements in the stack, and YYPTR gives the new location of the
632    stack.  Advance YYPTR to a properly aligned location for the next
633    stack.  */
634 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
635     do                                                                  \
636       {                                                                 \
637         YYPTRDIFF_T yynewbytes;                                         \
638         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
639         Stack = &yyptr->Stack_alloc;                                    \
640         yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
641         yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
642       }                                                                 \
643     while (0)
644 
645 #endif
646 
647 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
648 /* Copy COUNT objects from SRC to DST.  The source and destination do
649    not overlap.  */
650 # ifndef YYCOPY
651 #  if defined __GNUC__ && 1 < __GNUC__
652 #   define YYCOPY(Dst, Src, Count) \
653       __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
654 #  else
655 #   define YYCOPY(Dst, Src, Count)              \
656       do                                        \
657         {                                       \
658           YYPTRDIFF_T yyi;                      \
659           for (yyi = 0; yyi < (Count); yyi++)   \
660             (Dst)[yyi] = (Src)[yyi];            \
661         }                                       \
662       while (0)
663 #  endif
664 # endif
665 #endif /* !YYCOPY_NEEDED */
666 
667 /* YYFINAL -- State number of the termination state.  */
668 #define YYFINAL  2
669 /* YYLAST -- Last index in YYTABLE.  */
670 #define YYLAST   731
671 
672 /* YYNTOKENS -- Number of terminals.  */
673 #define YYNTOKENS  66
674 /* YYNNTS -- Number of nonterminals.  */
675 #define YYNNTS  20
676 /* YYNRULES -- Number of rules.  */
677 #define YYNRULES  116
678 /* YYNSTATES -- Number of states.  */
679 #define YYNSTATES  185
680 
681 #define YYUNDEFTOK  2
682 #define YYMAXUTOK   298
683 
684 
685 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
686    as returned by yylex, with out-of-bounds checking.  */
687 #define YYTRANSLATE(YYX)                                                \
688   (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
689 
690 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
691    as returned by yylex.  */
692 static const yytype_int8 yytranslate[] =
693 {
694        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
695        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
696        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
697        2,     2,     2,    56,     2,     2,     2,    52,    39,     2,
698       54,    55,    50,    48,    58,    49,    63,    51,     2,     2,
699        2,     2,     2,     2,     2,     2,     2,     2,     2,    64,
700       42,    65,    43,     2,     2,     2,     2,     2,     2,     2,
701        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
702        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
703        2,    59,     2,    60,    38,     2,     2,     2,     2,     2,
704        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
705        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
706        2,     2,     2,    61,    37,    62,    57,     2,     2,     2,
707        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
708        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
709        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
710        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
711        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
712        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
713        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
714        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
715        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
716        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
717        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
718        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
719        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
720        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
721       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
722       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
723       35,    36,    40,    41,    44,    45,    46,    47,    53
724 };
725 
726 #if YYDEBUG
727   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
728 static const yytype_int16 yyrline[] =
729 {
730        0,   220,   220,   222,   226,   227,   228,   232,   236,   241,
731      246,   251,   260,   270,   273,   276,   282,   285,   286,   299,
732      300,   352,   426,   447,   457,   463,   469,   495,   515,   515,
733      528,   528,   531,   537,   543,   546,   552,   555,   558,   564,
734      568,   573,   584,   588,   595,   606,   617,   624,   631,   638,
735      645,   652,   659,   666,   673,   680,   687,   694,   701,   708,
736      720,   732,   739,   743,   747,   751,   755,   761,   765,   772,
737      773,   777,   778,   781,   783,   789,   794,   801,   805,   809,
738      813,   817,   821,   825,   832,   833,   834,   835,   836,   837,
739      838,   839,   840,   841,   842,   843,   844,   845,   846,   847,
740      848,   849,   850,   851,   852,   853,   854,   855,   856,   857,
741      858,   859,   860,   861,   862,   863,   864
742 };
743 #endif
744 
745 #if YYDEBUG || YYERROR_VERBOSE || 1
746 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
747    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
748 static const char *const yytname[] =
749 {
750   "$end", "error", "$undefined", "DEFINED", "ELIF_EXPANDED", "HASH_TOKEN",
751   "DEFINE_TOKEN", "FUNC_IDENTIFIER", "OBJ_IDENTIFIER", "ELIF", "ELSE",
752   "ENDIF", "ERROR_TOKEN", "IF", "IFDEF", "IFNDEF", "LINE", "PRAGMA",
753   "UNDEF", "VERSION_TOKEN", "GARBAGE", "IDENTIFIER", "IF_EXPANDED",
754   "INTEGER", "INTEGER_STRING", "LINE_EXPANDED", "NEWLINE", "OTHER",
755   "PLACEHOLDER", "SPACE", "PLUS_PLUS", "MINUS_MINUS", "PATH", "INCLUDE",
756   "PASTE", "OR", "AND", "'|'", "'^'", "'&'", "EQUAL", "NOT_EQUAL", "'<'",
757   "'>'", "LESS_OR_EQUAL", "GREATER_OR_EQUAL", "LEFT_SHIFT", "RIGHT_SHIFT",
758   "'+'", "'-'", "'*'", "'/'", "'%'", "UNARY", "'('", "')'", "'!'", "'~'",
759   "','", "'['", "']'", "'{'", "'}'", "'.'", "';'", "'='", "$accept",
760   "input", "line", "expanded_line", "define", "control_line",
761   "control_line_success", "$@1", "$@2", "control_line_error",
762   "integer_constant", "version_constant", "expression", "identifier_list",
763   "text_line", "replacement_list", "junk", "pp_tokens",
764   "preprocessing_token", "operator", YY_NULLPTR
765 };
766 #endif
767 
768 # ifdef YYPRINT
769 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
770    (internal) symbol number NUM (which must be that of a token).  */
771 static const yytype_int16 yytoknum[] =
772 {
773        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
774      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
775      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
776      285,   286,   287,   288,   289,   290,   291,   124,    94,    38,
777      292,   293,    60,    62,   294,   295,   296,   297,    43,    45,
778       42,    47,    37,   298,    40,    41,    33,   126,    44,    91,
779       93,   123,   125,    46,    59,    61
780 };
781 # endif
782 
783 #define YYPACT_NINF (-145)
784 
785 #define yypact_value_is_default(Yyn) \
786   ((Yyn) == YYPACT_NINF)
787 
788 #define YYTABLE_NINF (-1)
789 
790 #define yytable_value_is_error(Yyn) \
791   0
792 
793   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
794      STATE-NUM.  */
795 static const yytype_int16 yypact[] =
796 {
797     -145,   105,  -145,  -145,   -15,     4,  -145,   -15,  -145,    45,
798     -145,  -145,    -2,  -145,  -145,  -145,  -145,  -145,  -145,  -145,
799     -145,  -145,  -145,  -145,  -145,  -145,  -145,  -145,  -145,  -145,
800     -145,  -145,  -145,  -145,  -145,  -145,  -145,  -145,  -145,  -145,
801     -145,  -145,  -145,  -145,  -145,  -145,  -145,  -145,  -145,  -145,
802     -145,  -145,  -145,   155,  -145,  -145,  -145,  -145,  -145,   -15,
803      -15,   -15,   -15,   -15,  -145,   545,    18,   205,  -145,  -145,
804        1,   255,   -10,    10,   505,    12,    19,    24,   505,  -145,
805       17,   572,    26,  -145,  -145,  -145,  -145,  -145,  -145,   590,
806     -145,  -145,  -145,   -15,   -15,   -15,   -15,   -15,   -15,   -15,
807      -15,   -15,   -15,   -15,   -15,   -15,   -15,   -15,   -15,   -15,
808      -15,    -3,   505,  -145,  -145,  -145,   305,    48,    50,  -145,
809     -145,   355,   505,   505,   405,  -145,    53,  -145,   -14,   455,
810     -145,  -145,  -145,    60,    80,  -145,   610,   626,   641,   655,
811      668,   679,   679,    13,    13,    13,    13,    33,    33,    -5,
812       -5,  -145,  -145,  -145,   -19,    85,   505,  -145,  -145,  -145,
813     -145,    86,   505,    88,  -145,  -145,    89,  -145,  -145,  -145,
814     -145,  -145,   505,   -26,  -145,  -145,  -145,  -145,    90,   505,
815       96,  -145,    92,  -145,  -145
816 };
817 
818   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
819      Performed when YYTABLE does not specify something else to do.  Zero
820      means the default is an error.  */
821 static const yytype_int8 yydefact[] =
822 {
823        2,     0,     1,    81,     0,     0,    77,     0,    78,     0,
824       69,    82,    83,   115,   116,    79,   114,   110,   109,   108,
825      107,    91,   105,   106,   101,   102,   103,   104,    99,   100,
826       93,    94,    92,    97,    98,    86,    87,    96,    95,   112,
827       84,    85,    88,    89,    90,   111,   113,     3,     7,     4,
828       16,    17,     6,     0,    75,    80,    43,    40,    39,     0,
829        0,     0,     0,     0,    42,     0,     0,     0,    28,    30,
830        0,     0,     0,     0,     0,     0,     0,     0,     0,    34,
831        0,     0,     0,     5,    70,    83,    76,    65,    64,     0,
832       62,    63,     9,     0,     0,     0,     0,     0,     0,     0,
833        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
834        0,     0,    71,    37,    19,    27,     0,     0,     0,    36,
835       23,     0,    73,    73,     0,    35,     0,    41,     0,     0,
836       21,     8,    10,     0,     0,    66,    44,    45,    46,    47,
837       48,    50,    49,    54,    53,    52,    51,    56,    55,    58,
838       57,    61,    60,    59,     0,     0,    72,    26,    29,    31,
839       22,     0,    74,     0,    18,    20,     0,    32,    38,    12,
840       11,    67,    71,     0,    13,    24,    25,    33,     0,    71,
841        0,    14,     0,    68,    15
842 };
843 
844   /* YYPGOTO[NTERM-NUM].  */
845 static const yytype_int16 yypgoto[] =
846 {
847     -145,  -145,  -145,  -145,  -145,    59,  -145,  -145,  -145,  -145,
848       -4,  -145,    -6,  -145,  -145,  -144,     0,    -1,   -49,  -145
849 };
850 
851   /* YYDEFGOTO[NTERM-NUM].  */
852 static const yytype_int16 yydefgoto[] =
853 {
854       -1,     1,    47,    48,   114,    49,    50,   117,   118,    51,
855       64,   128,    65,   173,    52,   155,   161,   156,    54,    55
856 };
857 
858   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
859      positive, shift that token.  If negative, reduce the rule whose
860      number is the opposite.  If YYTABLE_NINF, syntax error.  */
861 static const yytype_uint8 yytable[] =
862 {
863       53,    81,   171,     5,    86,    82,    56,   166,    57,    58,
864       66,   122,   167,    67,    68,    69,    70,    71,    72,    73,
865       74,    75,    76,    77,    78,   111,   112,   119,   178,   179,
866       79,   123,   180,    59,    60,   182,   172,    80,   125,    61,
867      126,    62,    63,   130,   113,   108,   109,   110,   127,    57,
868       58,   154,   132,    87,    88,    89,    90,    91,   133,   104,
869      105,   106,   107,   108,   109,   110,   116,    86,    57,    58,
870      121,    83,    86,   124,   158,    86,   159,   129,   134,   165,
871       86,   106,   107,   108,   109,   110,   169,   136,   137,   138,
872      139,   140,   141,   142,   143,   144,   145,   146,   147,   148,
873      149,   150,   151,   152,   153,     2,   170,    86,     3,     4,
874        5,   174,   175,    86,   176,   177,   181,   183,   184,     0,
875        0,   162,   162,   163,     0,     0,     6,     7,     0,     8,
876        9,    10,    11,     0,    12,    13,    14,    15,     0,    16,
877       17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
878       27,    28,    29,    30,    31,    32,    33,    34,     3,    35,
879       36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
880       46,     0,     0,     0,     0,     0,     6,     0,     0,     8,
881        0,    84,    11,     0,    85,    13,    14,    15,     0,    16,
882       17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
883       27,    28,    29,    30,    31,    32,    33,    34,     3,    35,
884       36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
885       46,     0,     0,     0,     0,     0,     6,     0,     0,     8,
886        0,   115,    11,     0,    85,    13,    14,    15,     0,    16,
887       17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
888       27,    28,    29,    30,    31,    32,    33,    34,     3,    35,
889       36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
890       46,     0,     0,     0,     0,     0,     6,     0,     0,     8,
891        0,   120,    11,     0,    85,    13,    14,    15,     0,    16,
892       17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
893       27,    28,    29,    30,    31,    32,    33,    34,     3,    35,
894       36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
895       46,     0,     0,     0,     0,     0,     6,     0,     0,     8,
896        0,   157,    11,     0,    85,    13,    14,    15,     0,    16,
897       17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
898       27,    28,    29,    30,    31,    32,    33,    34,     3,    35,
899       36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
900       46,     0,     0,     0,     0,     0,     6,     0,     0,     8,
901        0,   160,    11,     0,    85,    13,    14,    15,     0,    16,
902       17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
903       27,    28,    29,    30,    31,    32,    33,    34,     3,    35,
904       36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
905       46,     0,     0,     0,     0,     0,     6,     0,     0,     8,
906        0,   164,    11,     0,    85,    13,    14,    15,     0,    16,
907       17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
908       27,    28,    29,    30,    31,    32,    33,    34,     3,    35,
909       36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
910       46,     0,     0,     0,     0,     0,     6,     0,     0,     8,
911        0,   168,    11,     0,    85,    13,    14,    15,     0,    16,
912       17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
913       27,    28,    29,    30,    31,    32,    33,    34,     3,    35,
914       36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
915       46,     0,     0,     0,     0,     0,     6,     0,     0,     8,
916        0,     0,    11,     0,    85,    13,    14,    15,     0,    16,
917       17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
918       27,    28,    29,    30,    31,    32,    33,    34,     0,    35,
919       36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
920       46,    92,     0,     0,     0,     0,     0,     0,     0,     0,
921       93,    94,    95,    96,    97,    98,    99,   100,   101,   102,
922      103,   104,   105,   106,   107,   108,   109,   110,   131,     0,
923        0,     0,     0,     0,     0,     0,     0,    93,    94,    95,
924       96,    97,    98,    99,   100,   101,   102,   103,   104,   105,
925      106,   107,   108,   109,   110,    93,    94,    95,    96,    97,
926       98,    99,   100,   101,   102,   103,   104,   105,   106,   107,
927      108,   109,   110,     0,     0,   135,    94,    95,    96,    97,
928       98,    99,   100,   101,   102,   103,   104,   105,   106,   107,
929      108,   109,   110,    95,    96,    97,    98,    99,   100,   101,
930      102,   103,   104,   105,   106,   107,   108,   109,   110,    96,
931       97,    98,    99,   100,   101,   102,   103,   104,   105,   106,
932      107,   108,   109,   110,    97,    98,    99,   100,   101,   102,
933      103,   104,   105,   106,   107,   108,   109,   110,    98,    99,
934      100,   101,   102,   103,   104,   105,   106,   107,   108,   109,
935      110,   100,   101,   102,   103,   104,   105,   106,   107,   108,
936      109,   110
937 };
938 
939 static const yytype_int16 yycheck[] =
940 {
941        1,     7,    21,     5,    53,     9,    21,    21,    23,    24,
942        6,    21,    26,     9,    10,    11,    12,    13,    14,    15,
943       16,    17,    18,    19,    20,     7,     8,    26,   172,    55,
944       26,    21,    58,    48,    49,   179,    55,    33,    26,    54,
945       21,    56,    57,    26,    26,    50,    51,    52,    24,    23,
946       24,    54,    26,    59,    60,    61,    62,    63,    32,    46,
947       47,    48,    49,    50,    51,    52,    67,   116,    23,    24,
948       71,    12,   121,    74,    26,   124,    26,    78,    82,    26,
949      129,    48,    49,    50,    51,    52,    26,    93,    94,    95,
950       96,    97,    98,    99,   100,   101,   102,   103,   104,   105,
951      106,   107,   108,   109,   110,     0,    26,   156,     3,     4,
952        5,    26,    26,   162,    26,    26,    26,    21,    26,    -1,
953       -1,   122,   123,   123,    -1,    -1,    21,    22,    -1,    24,
954       25,    26,    27,    -1,    29,    30,    31,    32,    -1,    34,
955       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
956       45,    46,    47,    48,    49,    50,    51,    52,     3,    54,
957       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
958       65,    -1,    -1,    -1,    -1,    -1,    21,    -1,    -1,    24,
959       -1,    26,    27,    -1,    29,    30,    31,    32,    -1,    34,
960       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
961       45,    46,    47,    48,    49,    50,    51,    52,     3,    54,
962       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
963       65,    -1,    -1,    -1,    -1,    -1,    21,    -1,    -1,    24,
964       -1,    26,    27,    -1,    29,    30,    31,    32,    -1,    34,
965       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
966       45,    46,    47,    48,    49,    50,    51,    52,     3,    54,
967       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
968       65,    -1,    -1,    -1,    -1,    -1,    21,    -1,    -1,    24,
969       -1,    26,    27,    -1,    29,    30,    31,    32,    -1,    34,
970       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
971       45,    46,    47,    48,    49,    50,    51,    52,     3,    54,
972       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
973       65,    -1,    -1,    -1,    -1,    -1,    21,    -1,    -1,    24,
974       -1,    26,    27,    -1,    29,    30,    31,    32,    -1,    34,
975       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
976       45,    46,    47,    48,    49,    50,    51,    52,     3,    54,
977       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
978       65,    -1,    -1,    -1,    -1,    -1,    21,    -1,    -1,    24,
979       -1,    26,    27,    -1,    29,    30,    31,    32,    -1,    34,
980       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
981       45,    46,    47,    48,    49,    50,    51,    52,     3,    54,
982       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
983       65,    -1,    -1,    -1,    -1,    -1,    21,    -1,    -1,    24,
984       -1,    26,    27,    -1,    29,    30,    31,    32,    -1,    34,
985       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
986       45,    46,    47,    48,    49,    50,    51,    52,     3,    54,
987       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
988       65,    -1,    -1,    -1,    -1,    -1,    21,    -1,    -1,    24,
989       -1,    26,    27,    -1,    29,    30,    31,    32,    -1,    34,
990       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
991       45,    46,    47,    48,    49,    50,    51,    52,     3,    54,
992       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
993       65,    -1,    -1,    -1,    -1,    -1,    21,    -1,    -1,    24,
994       -1,    -1,    27,    -1,    29,    30,    31,    32,    -1,    34,
995       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
996       45,    46,    47,    48,    49,    50,    51,    52,    -1,    54,
997       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
998       65,    26,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
999       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
1000       45,    46,    47,    48,    49,    50,    51,    52,    26,    -1,
1001       -1,    -1,    -1,    -1,    -1,    -1,    -1,    35,    36,    37,
1002       38,    39,    40,    41,    42,    43,    44,    45,    46,    47,
1003       48,    49,    50,    51,    52,    35,    36,    37,    38,    39,
1004       40,    41,    42,    43,    44,    45,    46,    47,    48,    49,
1005       50,    51,    52,    -1,    -1,    55,    36,    37,    38,    39,
1006       40,    41,    42,    43,    44,    45,    46,    47,    48,    49,
1007       50,    51,    52,    37,    38,    39,    40,    41,    42,    43,
1008       44,    45,    46,    47,    48,    49,    50,    51,    52,    38,
1009       39,    40,    41,    42,    43,    44,    45,    46,    47,    48,
1010       49,    50,    51,    52,    39,    40,    41,    42,    43,    44,
1011       45,    46,    47,    48,    49,    50,    51,    52,    40,    41,
1012       42,    43,    44,    45,    46,    47,    48,    49,    50,    51,
1013       52,    42,    43,    44,    45,    46,    47,    48,    49,    50,
1014       51,    52
1015 };
1016 
1017   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1018      symbol of state STATE-NUM.  */
1019 static const yytype_int8 yystos[] =
1020 {
1021        0,    67,     0,     3,     4,     5,    21,    22,    24,    25,
1022       26,    27,    29,    30,    31,    32,    34,    35,    36,    37,
1023       38,    39,    40,    41,    42,    43,    44,    45,    46,    47,
1024       48,    49,    50,    51,    52,    54,    55,    56,    57,    58,
1025       59,    60,    61,    62,    63,    64,    65,    68,    69,    71,
1026       72,    75,    80,    83,    84,    85,    21,    23,    24,    48,
1027       49,    54,    56,    57,    76,    78,     6,     9,    10,    11,
1028       12,    13,    14,    15,    16,    17,    18,    19,    20,    26,
1029       33,    78,    76,    71,    26,    29,    84,    78,    78,    78,
1030       78,    78,    26,    35,    36,    37,    38,    39,    40,    41,
1031       42,    43,    44,    45,    46,    47,    48,    49,    50,    51,
1032       52,     7,     8,    26,    70,    26,    83,    73,    74,    26,
1033       26,    83,    21,    21,    83,    26,    21,    24,    77,    83,
1034       26,    26,    26,    32,    76,    55,    78,    78,    78,    78,
1035       78,    78,    78,    78,    78,    78,    78,    78,    78,    78,
1036       78,    78,    78,    78,    54,    81,    83,    26,    26,    26,
1037       26,    82,    83,    82,    26,    26,    21,    26,    26,    26,
1038       26,    21,    55,    79,    26,    26,    26,    26,    81,    55,
1039       58,    26,    81,    21,    26
1040 };
1041 
1042   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
1043 static const yytype_int8 yyr1[] =
1044 {
1045        0,    66,    67,    67,    68,    68,    68,    68,    69,    69,
1046       69,    69,    69,    70,    70,    70,    71,    71,    71,    72,
1047       72,    72,    72,    72,    72,    72,    72,    72,    73,    72,
1048       74,    72,    72,    72,    72,    72,    75,    75,    75,    76,
1049       76,    77,    78,    78,    78,    78,    78,    78,    78,    78,
1050       78,    78,    78,    78,    78,    78,    78,    78,    78,    78,
1051       78,    78,    78,    78,    78,    78,    78,    79,    79,    80,
1052       80,    81,    81,    82,    82,    83,    83,    84,    84,    84,
1053       84,    84,    84,    84,    85,    85,    85,    85,    85,    85,
1054       85,    85,    85,    85,    85,    85,    85,    85,    85,    85,
1055       85,    85,    85,    85,    85,    85,    85,    85,    85,    85,
1056       85,    85,    85,    85,    85,    85,    85
1057 };
1058 
1059   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
1060 static const yytype_int8 yyr2[] =
1061 {
1062        0,     2,     0,     2,     1,     2,     1,     1,     3,     3,
1063        3,     4,     4,     3,     5,     6,     1,     1,     4,     3,
1064        4,     3,     4,     3,     5,     5,     4,     3,     0,     4,
1065        0,     4,     4,     5,     2,     3,     3,     3,     4,     1,
1066        1,     1,     1,     1,     3,     3,     3,     3,     3,     3,
1067        3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
1068        3,     3,     2,     2,     2,     2,     3,     1,     3,     1,
1069        2,     0,     1,     0,     1,     1,     2,     1,     1,     1,
1070        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
1071        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
1072        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
1073        1,     1,     1,     1,     1,     1,     1
1074 };
1075 
1076 
1077 #define yyerrok         (yyerrstatus = 0)
1078 #define yyclearin       (yychar = YYEMPTY)
1079 #define YYEMPTY         (-2)
1080 #define YYEOF           0
1081 
1082 #define YYACCEPT        goto yyacceptlab
1083 #define YYABORT         goto yyabortlab
1084 #define YYERROR         goto yyerrorlab
1085 
1086 
1087 #define YYRECOVERING()  (!!yyerrstatus)
1088 
1089 #define YYBACKUP(Token, Value)                                    \
1090   do                                                              \
1091     if (yychar == YYEMPTY)                                        \
1092       {                                                           \
1093         yychar = (Token);                                         \
1094         yylval = (Value);                                         \
1095         YYPOPSTACK (yylen);                                       \
1096         yystate = *yyssp;                                         \
1097         goto yybackup;                                            \
1098       }                                                           \
1099     else                                                          \
1100       {                                                           \
1101         yyerror (&yylloc, parser, YY_("syntax error: cannot back up")); \
1102         YYERROR;                                                  \
1103       }                                                           \
1104   while (0)
1105 
1106 /* Error token number */
1107 #define YYTERROR        1
1108 #define YYERRCODE       256
1109 
1110 
1111 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1112    If N is 0, then set CURRENT to the empty location which ends
1113    the previous symbol: RHS[0] (always defined).  */
1114 
1115 #ifndef YYLLOC_DEFAULT
1116 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
1117     do                                                                  \
1118       if (N)                                                            \
1119         {                                                               \
1120           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
1121           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
1122           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
1123           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
1124         }                                                               \
1125       else                                                              \
1126         {                                                               \
1127           (Current).first_line   = (Current).last_line   =              \
1128             YYRHSLOC (Rhs, 0).last_line;                                \
1129           (Current).first_column = (Current).last_column =              \
1130             YYRHSLOC (Rhs, 0).last_column;                              \
1131         }                                                               \
1132     while (0)
1133 #endif
1134 
1135 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1136 
1137 
1138 /* Enable debugging if requested.  */
1139 #if YYDEBUG
1140 
1141 # ifndef YYFPRINTF
1142 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1143 #  define YYFPRINTF fprintf
1144 # endif
1145 
1146 # define YYDPRINTF(Args)                        \
1147 do {                                            \
1148   if (yydebug)                                  \
1149     YYFPRINTF Args;                             \
1150 } while (0)
1151 
1152 
1153 /* YY_LOCATION_PRINT -- Print the location on the stream.
1154    This macro was not mandated originally: define only if we know
1155    we won't break user code: when these are the locations we know.  */
1156 
1157 #ifndef YY_LOCATION_PRINT
1158 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1159 
1160 /* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
1161 
1162 YY_ATTRIBUTE_UNUSED
1163 static int
yy_location_print_(FILE * yyo,YYLTYPE const * const yylocp)1164 yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
1165 {
1166   int res = 0;
1167   int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
1168   if (0 <= yylocp->first_line)
1169     {
1170       res += YYFPRINTF (yyo, "%d", yylocp->first_line);
1171       if (0 <= yylocp->first_column)
1172         res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
1173     }
1174   if (0 <= yylocp->last_line)
1175     {
1176       if (yylocp->first_line < yylocp->last_line)
1177         {
1178           res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
1179           if (0 <= end_col)
1180             res += YYFPRINTF (yyo, ".%d", end_col);
1181         }
1182       else if (0 <= end_col && yylocp->first_column < end_col)
1183         res += YYFPRINTF (yyo, "-%d", end_col);
1184     }
1185   return res;
1186  }
1187 
1188 #  define YY_LOCATION_PRINT(File, Loc)          \
1189   yy_location_print_ (File, &(Loc))
1190 
1191 # else
1192 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1193 # endif
1194 #endif
1195 
1196 
1197 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
1198 do {                                                                      \
1199   if (yydebug)                                                            \
1200     {                                                                     \
1201       YYFPRINTF (stderr, "%s ", Title);                                   \
1202       yy_symbol_print (stderr,                                            \
1203                   Type, Value, Location, parser); \
1204       YYFPRINTF (stderr, "\n");                                           \
1205     }                                                                     \
1206 } while (0)
1207 
1208 
1209 /*-----------------------------------.
1210 | Print this symbol's value on YYO.  |
1211 `-----------------------------------*/
1212 
1213 static void
yy_symbol_value_print(FILE * yyo,int yytype,YYSTYPE const * const yyvaluep,YYLTYPE const * const yylocationp,glcpp_parser_t * parser)1214 yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
1215 {
1216   FILE *yyoutput = yyo;
1217   YYUSE (yyoutput);
1218   YYUSE (yylocationp);
1219   YYUSE (parser);
1220   if (!yyvaluep)
1221     return;
1222 # ifdef YYPRINT
1223   if (yytype < YYNTOKENS)
1224     YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
1225 # endif
1226   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1227   YYUSE (yytype);
1228   YY_IGNORE_MAYBE_UNINITIALIZED_END
1229 }
1230 
1231 
1232 /*---------------------------.
1233 | Print this symbol on YYO.  |
1234 `---------------------------*/
1235 
1236 static void
yy_symbol_print(FILE * yyo,int yytype,YYSTYPE const * const yyvaluep,YYLTYPE const * const yylocationp,glcpp_parser_t * parser)1237 yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
1238 {
1239   YYFPRINTF (yyo, "%s %s (",
1240              yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1241 
1242   YY_LOCATION_PRINT (yyo, *yylocationp);
1243   YYFPRINTF (yyo, ": ");
1244   yy_symbol_value_print (yyo, yytype, yyvaluep, yylocationp, parser);
1245   YYFPRINTF (yyo, ")");
1246 }
1247 
1248 /*------------------------------------------------------------------.
1249 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1250 | TOP (included).                                                   |
1251 `------------------------------------------------------------------*/
1252 
1253 static void
yy_stack_print(yy_state_t * yybottom,yy_state_t * yytop)1254 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
1255 {
1256   YYFPRINTF (stderr, "Stack now");
1257   for (; yybottom <= yytop; yybottom++)
1258     {
1259       int yybot = *yybottom;
1260       YYFPRINTF (stderr, " %d", yybot);
1261     }
1262   YYFPRINTF (stderr, "\n");
1263 }
1264 
1265 # define YY_STACK_PRINT(Bottom, Top)                            \
1266 do {                                                            \
1267   if (yydebug)                                                  \
1268     yy_stack_print ((Bottom), (Top));                           \
1269 } while (0)
1270 
1271 
1272 /*------------------------------------------------.
1273 | Report that the YYRULE is going to be reduced.  |
1274 `------------------------------------------------*/
1275 
1276 static void
yy_reduce_print(yy_state_t * yyssp,YYSTYPE * yyvsp,YYLTYPE * yylsp,int yyrule,glcpp_parser_t * parser)1277 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, glcpp_parser_t *parser)
1278 {
1279   int yylno = yyrline[yyrule];
1280   int yynrhs = yyr2[yyrule];
1281   int yyi;
1282   YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
1283              yyrule - 1, yylno);
1284   /* The symbols being reduced.  */
1285   for (yyi = 0; yyi < yynrhs; yyi++)
1286     {
1287       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
1288       yy_symbol_print (stderr,
1289                        yystos[yyssp[yyi + 1 - yynrhs]],
1290                        &yyvsp[(yyi + 1) - (yynrhs)]
1291                        , &(yylsp[(yyi + 1) - (yynrhs)])                       , parser);
1292       YYFPRINTF (stderr, "\n");
1293     }
1294 }
1295 
1296 # define YY_REDUCE_PRINT(Rule)          \
1297 do {                                    \
1298   if (yydebug)                          \
1299     yy_reduce_print (yyssp, yyvsp, yylsp, Rule, parser); \
1300 } while (0)
1301 
1302 /* Nonzero means print parse trace.  It is left uninitialized so that
1303    multiple parsers can coexist.  */
1304 int yydebug;
1305 #else /* !YYDEBUG */
1306 # define YYDPRINTF(Args)
1307 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1308 # define YY_STACK_PRINT(Bottom, Top)
1309 # define YY_REDUCE_PRINT(Rule)
1310 #endif /* !YYDEBUG */
1311 
1312 
1313 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1314 #ifndef YYINITDEPTH
1315 # define YYINITDEPTH 200
1316 #endif
1317 
1318 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1319    if the built-in stack extension method is used).
1320 
1321    Do not make this value too large; the results are undefined if
1322    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1323    evaluated with infinite-precision integer arithmetic.  */
1324 
1325 #ifndef YYMAXDEPTH
1326 # define YYMAXDEPTH 10000
1327 #endif
1328 
1329 
1330 #if YYERROR_VERBOSE
1331 
1332 # ifndef yystrlen
1333 #  if defined __GLIBC__ && defined _STRING_H
1334 #   define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
1335 #  else
1336 /* Return the length of YYSTR.  */
1337 static YYPTRDIFF_T
yystrlen(const char * yystr)1338 yystrlen (const char *yystr)
1339 {
1340   YYPTRDIFF_T yylen;
1341   for (yylen = 0; yystr[yylen]; yylen++)
1342     continue;
1343   return yylen;
1344 }
1345 #  endif
1346 # endif
1347 
1348 # ifndef yystpcpy
1349 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1350 #   define yystpcpy stpcpy
1351 #  else
1352 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1353    YYDEST.  */
1354 static char *
yystpcpy(char * yydest,const char * yysrc)1355 yystpcpy (char *yydest, const char *yysrc)
1356 {
1357   char *yyd = yydest;
1358   const char *yys = yysrc;
1359 
1360   while ((*yyd++ = *yys++) != '\0')
1361     continue;
1362 
1363   return yyd - 1;
1364 }
1365 #  endif
1366 # endif
1367 
1368 # ifndef yytnamerr
1369 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1370    quotes and backslashes, so that it's suitable for yyerror.  The
1371    heuristic is that double-quoting is unnecessary unless the string
1372    contains an apostrophe, a comma, or backslash (other than
1373    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1374    null, do not copy; instead, return the length of what the result
1375    would have been.  */
1376 static YYPTRDIFF_T
yytnamerr(char * yyres,const char * yystr)1377 yytnamerr (char *yyres, const char *yystr)
1378 {
1379   if (*yystr == '"')
1380     {
1381       YYPTRDIFF_T yyn = 0;
1382       char const *yyp = yystr;
1383 
1384       for (;;)
1385         switch (*++yyp)
1386           {
1387           case '\'':
1388           case ',':
1389             goto do_not_strip_quotes;
1390 
1391           case '\\':
1392             if (*++yyp != '\\')
1393               goto do_not_strip_quotes;
1394             else
1395               goto append;
1396 
1397           append:
1398           default:
1399             if (yyres)
1400               yyres[yyn] = *yyp;
1401             yyn++;
1402             break;
1403 
1404           case '"':
1405             if (yyres)
1406               yyres[yyn] = '\0';
1407             return yyn;
1408           }
1409     do_not_strip_quotes: ;
1410     }
1411 
1412   if (yyres)
1413     return yystpcpy (yyres, yystr) - yyres;
1414   else
1415     return yystrlen (yystr);
1416 }
1417 # endif
1418 
1419 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1420    about the unexpected token YYTOKEN for the state stack whose top is
1421    YYSSP.
1422 
1423    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1424    not large enough to hold the message.  In that case, also set
1425    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1426    required number of bytes is too large to store.  */
1427 static int
yysyntax_error(YYPTRDIFF_T * yymsg_alloc,char ** yymsg,yy_state_t * yyssp,int yytoken)1428 yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
1429                 yy_state_t *yyssp, int yytoken)
1430 {
1431   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1432   /* Internationalized format string. */
1433   const char *yyformat = YY_NULLPTR;
1434   /* Arguments of yyformat: reported tokens (one for the "unexpected",
1435      one per "expected"). */
1436   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1437   /* Actual size of YYARG. */
1438   int yycount = 0;
1439   /* Cumulated lengths of YYARG.  */
1440   YYPTRDIFF_T yysize = 0;
1441 
1442   /* There are many possibilities here to consider:
1443      - If this state is a consistent state with a default action, then
1444        the only way this function was invoked is if the default action
1445        is an error action.  In that case, don't check for expected
1446        tokens because there are none.
1447      - The only way there can be no lookahead present (in yychar) is if
1448        this state is a consistent state with a default action.  Thus,
1449        detecting the absence of a lookahead is sufficient to determine
1450        that there is no unexpected or expected token to report.  In that
1451        case, just report a simple "syntax error".
1452      - Don't assume there isn't a lookahead just because this state is a
1453        consistent state with a default action.  There might have been a
1454        previous inconsistent state, consistent state with a non-default
1455        action, or user semantic action that manipulated yychar.
1456      - Of course, the expected token list depends on states to have
1457        correct lookahead information, and it depends on the parser not
1458        to perform extra reductions after fetching a lookahead from the
1459        scanner and before detecting a syntax error.  Thus, state merging
1460        (from LALR or IELR) and default reductions corrupt the expected
1461        token list.  However, the list is correct for canonical LR with
1462        one exception: it will still contain any token that will not be
1463        accepted due to an error action in a later state.
1464   */
1465   if (yytoken != YYEMPTY)
1466     {
1467       int yyn = yypact[*yyssp];
1468       YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1469       yysize = yysize0;
1470       yyarg[yycount++] = yytname[yytoken];
1471       if (!yypact_value_is_default (yyn))
1472         {
1473           /* Start YYX at -YYN if negative to avoid negative indexes in
1474              YYCHECK.  In other words, skip the first -YYN actions for
1475              this state because they are default actions.  */
1476           int yyxbegin = yyn < 0 ? -yyn : 0;
1477           /* Stay within bounds of both yycheck and yytname.  */
1478           int yychecklim = YYLAST - yyn + 1;
1479           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1480           int yyx;
1481 
1482           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1483             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1484                 && !yytable_value_is_error (yytable[yyx + yyn]))
1485               {
1486                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1487                   {
1488                     yycount = 1;
1489                     yysize = yysize0;
1490                     break;
1491                   }
1492                 yyarg[yycount++] = yytname[yyx];
1493                 {
1494                   YYPTRDIFF_T yysize1
1495                     = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1496                   if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
1497                     yysize = yysize1;
1498                   else
1499                     return 2;
1500                 }
1501               }
1502         }
1503     }
1504 
1505   switch (yycount)
1506     {
1507 # define YYCASE_(N, S)                      \
1508       case N:                               \
1509         yyformat = S;                       \
1510       break
1511     default: /* Avoid compiler warnings. */
1512       YYCASE_(0, YY_("syntax error"));
1513       YYCASE_(1, YY_("syntax error, unexpected %s"));
1514       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1515       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1516       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1517       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1518 # undef YYCASE_
1519     }
1520 
1521   {
1522     /* Don't count the "%s"s in the final size, but reserve room for
1523        the terminator.  */
1524     YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1;
1525     if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
1526       yysize = yysize1;
1527     else
1528       return 2;
1529   }
1530 
1531   if (*yymsg_alloc < yysize)
1532     {
1533       *yymsg_alloc = 2 * yysize;
1534       if (! (yysize <= *yymsg_alloc
1535              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1536         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1537       return 1;
1538     }
1539 
1540   /* Avoid sprintf, as that infringes on the user's name space.
1541      Don't have undefined behavior even if the translation
1542      produced a string with the wrong number of "%s"s.  */
1543   {
1544     char *yyp = *yymsg;
1545     int yyi = 0;
1546     while ((*yyp = *yyformat) != '\0')
1547       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1548         {
1549           yyp += yytnamerr (yyp, yyarg[yyi++]);
1550           yyformat += 2;
1551         }
1552       else
1553         {
1554           ++yyp;
1555           ++yyformat;
1556         }
1557   }
1558   return 0;
1559 }
1560 #endif /* YYERROR_VERBOSE */
1561 
1562 /*-----------------------------------------------.
1563 | Release the memory associated to this symbol.  |
1564 `-----------------------------------------------*/
1565 
1566 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep,YYLTYPE * yylocationp,glcpp_parser_t * parser)1567 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, glcpp_parser_t *parser)
1568 {
1569   YYUSE (yyvaluep);
1570   YYUSE (yylocationp);
1571   YYUSE (parser);
1572   if (!yymsg)
1573     yymsg = "Deleting";
1574   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1575 
1576   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1577   YYUSE (yytype);
1578   YY_IGNORE_MAYBE_UNINITIALIZED_END
1579 }
1580 
1581 
1582 
1583 
1584 /*----------.
1585 | yyparse.  |
1586 `----------*/
1587 
1588 int
yyparse(glcpp_parser_t * parser)1589 yyparse (glcpp_parser_t *parser)
1590 {
1591 /* The lookahead symbol.  */
1592 int yychar;
1593 
1594 
1595 /* The semantic value of the lookahead symbol.  */
1596 /* Default value used for initialization, for pacifying older GCCs
1597    or non-GCC compilers.  */
1598 YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1599 YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1600 
1601 /* Location data for the lookahead symbol.  */
1602 static YYLTYPE yyloc_default
1603 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1604   = { 1, 1, 1, 1 }
1605 # endif
1606 ;
1607 YYLTYPE yylloc = yyloc_default;
1608 
1609     /* Number of syntax errors so far.  */
1610     int yynerrs;
1611 
1612     yy_state_fast_t yystate;
1613     /* Number of tokens to shift before error messages enabled.  */
1614     int yyerrstatus;
1615 
1616     /* The stacks and their tools:
1617        'yyss': related to states.
1618        'yyvs': related to semantic values.
1619        'yyls': related to locations.
1620 
1621        Refer to the stacks through separate pointers, to allow yyoverflow
1622        to reallocate them elsewhere.  */
1623 
1624     /* The state stack.  */
1625     yy_state_t yyssa[YYINITDEPTH];
1626     yy_state_t *yyss;
1627     yy_state_t *yyssp;
1628 
1629     /* The semantic value stack.  */
1630     YYSTYPE yyvsa[YYINITDEPTH];
1631     YYSTYPE *yyvs;
1632     YYSTYPE *yyvsp;
1633 
1634     /* The location stack.  */
1635     YYLTYPE yylsa[YYINITDEPTH];
1636     YYLTYPE *yyls;
1637     YYLTYPE *yylsp;
1638 
1639     /* The locations where the error started and ended.  */
1640     YYLTYPE yyerror_range[3];
1641 
1642     YYPTRDIFF_T yystacksize;
1643 
1644   int yyn;
1645   int yyresult;
1646   /* Lookahead token as an internal (translated) token number.  */
1647   int yytoken = 0;
1648   /* The variables used to return semantic value and location from the
1649      action routines.  */
1650   YYSTYPE yyval;
1651   YYLTYPE yyloc;
1652 
1653 #if YYERROR_VERBOSE
1654   /* Buffer for error messages, and its allocated size.  */
1655   char yymsgbuf[128];
1656   char *yymsg = yymsgbuf;
1657   YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
1658 #endif
1659 
1660 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1661 
1662   /* The number of symbols on the RHS of the reduced rule.
1663      Keep to zero when no symbol should be popped.  */
1664   int yylen = 0;
1665 
1666   yyssp = yyss = yyssa;
1667   yyvsp = yyvs = yyvsa;
1668   yylsp = yyls = yylsa;
1669   yystacksize = YYINITDEPTH;
1670 
1671   YYDPRINTF ((stderr, "Starting parse\n"));
1672 
1673   yystate = 0;
1674   yyerrstatus = 0;
1675   yynerrs = 0;
1676   yychar = YYEMPTY; /* Cause a token to be read.  */
1677 
1678 /* User initialization code.  */
1679 #line 180 "src/compiler/glsl/glcpp/glcpp-parse.y"
1680 {
1681    yylloc.first_line = 1;
1682    yylloc.first_column = 1;
1683    yylloc.last_line = 1;
1684    yylloc.last_column = 1;
1685    yylloc.source = 0;
1686 }
1687 
1688 #line 1689 "src/compiler/glsl/glcpp/glcpp-parse.c"
1689 
1690   yylsp[0] = yylloc;
1691   goto yysetstate;
1692 
1693 
1694 /*------------------------------------------------------------.
1695 | yynewstate -- push a new state, which is found in yystate.  |
1696 `------------------------------------------------------------*/
1697 yynewstate:
1698   /* In all cases, when you get here, the value and location stacks
1699      have just been pushed.  So pushing a state here evens the stacks.  */
1700   yyssp++;
1701 
1702 
1703 /*--------------------------------------------------------------------.
1704 | yysetstate -- set current state (the top of the stack) to yystate.  |
1705 `--------------------------------------------------------------------*/
1706 yysetstate:
1707   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1708   YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1709   YY_IGNORE_USELESS_CAST_BEGIN
1710   *yyssp = YY_CAST (yy_state_t, yystate);
1711   YY_IGNORE_USELESS_CAST_END
1712 
1713   if (yyss + yystacksize - 1 <= yyssp)
1714 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1715     goto yyexhaustedlab;
1716 #else
1717     {
1718       /* Get the current used size of the three stacks, in elements.  */
1719       YYPTRDIFF_T yysize = yyssp - yyss + 1;
1720 
1721 # if defined yyoverflow
1722       {
1723         /* Give user a chance to reallocate the stack.  Use copies of
1724            these so that the &'s don't force the real ones into
1725            memory.  */
1726         yy_state_t *yyss1 = yyss;
1727         YYSTYPE *yyvs1 = yyvs;
1728         YYLTYPE *yyls1 = yyls;
1729 
1730         /* Each stack pointer address is followed by the size of the
1731            data in use in that stack, in bytes.  This used to be a
1732            conditional around just the two extra args, but that might
1733            be undefined if yyoverflow is a macro.  */
1734         yyoverflow (YY_("memory exhausted"),
1735                     &yyss1, yysize * YYSIZEOF (*yyssp),
1736                     &yyvs1, yysize * YYSIZEOF (*yyvsp),
1737                     &yyls1, yysize * YYSIZEOF (*yylsp),
1738                     &yystacksize);
1739         yyss = yyss1;
1740         yyvs = yyvs1;
1741         yyls = yyls1;
1742       }
1743 # else /* defined YYSTACK_RELOCATE */
1744       /* Extend the stack our own way.  */
1745       if (YYMAXDEPTH <= yystacksize)
1746         goto yyexhaustedlab;
1747       yystacksize *= 2;
1748       if (YYMAXDEPTH < yystacksize)
1749         yystacksize = YYMAXDEPTH;
1750 
1751       {
1752         yy_state_t *yyss1 = yyss;
1753         union yyalloc *yyptr =
1754           YY_CAST (union yyalloc *,
1755                    YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1756         if (! yyptr)
1757           goto yyexhaustedlab;
1758         YYSTACK_RELOCATE (yyss_alloc, yyss);
1759         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1760         YYSTACK_RELOCATE (yyls_alloc, yyls);
1761 # undef YYSTACK_RELOCATE
1762         if (yyss1 != yyssa)
1763           YYSTACK_FREE (yyss1);
1764       }
1765 # endif
1766 
1767       yyssp = yyss + yysize - 1;
1768       yyvsp = yyvs + yysize - 1;
1769       yylsp = yyls + yysize - 1;
1770 
1771       YY_IGNORE_USELESS_CAST_BEGIN
1772       YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1773                   YY_CAST (long, yystacksize)));
1774       YY_IGNORE_USELESS_CAST_END
1775 
1776       if (yyss + yystacksize - 1 <= yyssp)
1777         YYABORT;
1778     }
1779 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1780 
1781   if (yystate == YYFINAL)
1782     YYACCEPT;
1783 
1784   goto yybackup;
1785 
1786 
1787 /*-----------.
1788 | yybackup.  |
1789 `-----------*/
1790 yybackup:
1791   /* Do appropriate processing given the current state.  Read a
1792      lookahead token if we need one and don't already have one.  */
1793 
1794   /* First try to decide what to do without reference to lookahead token.  */
1795   yyn = yypact[yystate];
1796   if (yypact_value_is_default (yyn))
1797     goto yydefault;
1798 
1799   /* Not known => get a lookahead token if don't already have one.  */
1800 
1801   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1802   if (yychar == YYEMPTY)
1803     {
1804       YYDPRINTF ((stderr, "Reading a token: "));
1805       yychar = yylex (&yylval, &yylloc, parser);
1806     }
1807 
1808   if (yychar <= YYEOF)
1809     {
1810       yychar = yytoken = YYEOF;
1811       YYDPRINTF ((stderr, "Now at end of input.\n"));
1812     }
1813   else
1814     {
1815       yytoken = YYTRANSLATE (yychar);
1816       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1817     }
1818 
1819   /* If the proper action on seeing token YYTOKEN is to reduce or to
1820      detect an error, take that action.  */
1821   yyn += yytoken;
1822   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1823     goto yydefault;
1824   yyn = yytable[yyn];
1825   if (yyn <= 0)
1826     {
1827       if (yytable_value_is_error (yyn))
1828         goto yyerrlab;
1829       yyn = -yyn;
1830       goto yyreduce;
1831     }
1832 
1833   /* Count tokens shifted since error; after three, turn off error
1834      status.  */
1835   if (yyerrstatus)
1836     yyerrstatus--;
1837 
1838   /* Shift the lookahead token.  */
1839   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1840   yystate = yyn;
1841   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1842   *++yyvsp = yylval;
1843   YY_IGNORE_MAYBE_UNINITIALIZED_END
1844   *++yylsp = yylloc;
1845 
1846   /* Discard the shifted token.  */
1847   yychar = YYEMPTY;
1848   goto yynewstate;
1849 
1850 
1851 /*-----------------------------------------------------------.
1852 | yydefault -- do the default action for the current state.  |
1853 `-----------------------------------------------------------*/
1854 yydefault:
1855   yyn = yydefact[yystate];
1856   if (yyn == 0)
1857     goto yyerrlab;
1858   goto yyreduce;
1859 
1860 
1861 /*-----------------------------.
1862 | yyreduce -- do a reduction.  |
1863 `-----------------------------*/
1864 yyreduce:
1865   /* yyn is the number of a rule to reduce with.  */
1866   yylen = yyr2[yyn];
1867 
1868   /* If YYLEN is nonzero, implement the default value of the action:
1869      '$$ = $1'.
1870 
1871      Otherwise, the following line sets YYVAL to garbage.
1872      This behavior is undocumented and Bison
1873      users should not rely upon it.  Assigning to YYVAL
1874      unconditionally makes the parser a bit smaller, and it avoids a
1875      GCC warning that YYVAL may be used uninitialized.  */
1876   yyval = yyvsp[1-yylen];
1877 
1878   /* Default location. */
1879   YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1880   yyerror_range[1] = yyloc;
1881   YY_REDUCE_PRINT (yyn);
1882   switch (yyn)
1883     {
1884   case 6:
1885 #line 228 "src/compiler/glsl/glcpp/glcpp-parse.y"
1886                   {
1887 		_glcpp_parser_print_expanded_token_list (parser, (yyvsp[0].token_list));
1888 		_mesa_string_buffer_append_char(parser->output, '\n');
1889 	}
1890 #line 1891 "src/compiler/glsl/glcpp/glcpp-parse.c"
1891     break;
1892 
1893   case 8:
1894 #line 236 "src/compiler/glsl/glcpp/glcpp-parse.y"
1895                                        {
1896 		if (parser->is_gles && (yyvsp[-1].expression_value).undefined_macro)
1897 			glcpp_error(& (yylsp[-2]), parser, "undefined macro %s in expression (illegal in GLES)", (yyvsp[-1].expression_value).undefined_macro);
1898 		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[-2]), (yyvsp[-1].expression_value).value);
1899 	}
1900 #line 1901 "src/compiler/glsl/glcpp/glcpp-parse.c"
1901     break;
1902 
1903   case 9:
1904 #line 241 "src/compiler/glsl/glcpp/glcpp-parse.y"
1905                                          {
1906 		if (parser->is_gles && (yyvsp[-1].expression_value).undefined_macro)
1907 			glcpp_error(& (yylsp[-2]), parser, "undefined macro %s in expression (illegal in GLES)", (yyvsp[-1].expression_value).undefined_macro);
1908 		_glcpp_parser_skip_stack_change_if (parser, & (yylsp[-2]), "elif", (yyvsp[-1].expression_value).value);
1909 	}
1910 #line 1911 "src/compiler/glsl/glcpp/glcpp-parse.c"
1911     break;
1912 
1913   case 10:
1914 #line 246 "src/compiler/glsl/glcpp/glcpp-parse.y"
1915                                                {
1916 		parser->has_new_line_number = 1;
1917 		parser->new_line_number = (yyvsp[-1].ival);
1918 		_mesa_string_buffer_printf(parser->output, "#line %" PRIiMAX "\n", (yyvsp[-1].ival));
1919 	}
1920 #line 1921 "src/compiler/glsl/glcpp/glcpp-parse.c"
1921     break;
1922 
1923   case 11:
1924 #line 251 "src/compiler/glsl/glcpp/glcpp-parse.y"
1925                                                                 {
1926 		parser->has_new_line_number = 1;
1927 		parser->new_line_number = (yyvsp[-2].ival);
1928 		parser->has_new_source_number = 1;
1929 		parser->new_source_number = (yyvsp[-1].ival);
1930 		_mesa_string_buffer_printf(parser->output,
1931 					   "#line %" PRIiMAX " %" PRIiMAX "\n",
1932 					    (yyvsp[-2].ival), (yyvsp[-1].ival));
1933 	}
1934 #line 1935 "src/compiler/glsl/glcpp/glcpp-parse.c"
1935     break;
1936 
1937   case 12:
1938 #line 260 "src/compiler/glsl/glcpp/glcpp-parse.y"
1939                                                     {
1940 		parser->has_new_line_number = 1;
1941 		parser->new_line_number = (yyvsp[-2].ival);
1942 		_mesa_string_buffer_printf(parser->output,
1943 					   "#line %" PRIiMAX " %s\n",
1944 					    (yyvsp[-2].ival), (yyvsp[-1].str));
1945 	}
1946 #line 1947 "src/compiler/glsl/glcpp/glcpp-parse.c"
1947     break;
1948 
1949   case 13:
1950 #line 270 "src/compiler/glsl/glcpp/glcpp-parse.y"
1951                                                 {
1952 		_define_object_macro (parser, & (yylsp[-2]), (yyvsp[-2].str), (yyvsp[-1].token_list));
1953 	}
1954 #line 1955 "src/compiler/glsl/glcpp/glcpp-parse.c"
1955     break;
1956 
1957   case 14:
1958 #line 273 "src/compiler/glsl/glcpp/glcpp-parse.y"
1959                                                          {
1960 		_define_function_macro (parser, & (yylsp[-4]), (yyvsp[-4].str), NULL, (yyvsp[-1].token_list));
1961 	}
1962 #line 1963 "src/compiler/glsl/glcpp/glcpp-parse.c"
1963     break;
1964 
1965   case 15:
1966 #line 276 "src/compiler/glsl/glcpp/glcpp-parse.y"
1967                                                                          {
1968 		_define_function_macro (parser, & (yylsp[-5]), (yyvsp[-5].str), (yyvsp[-3].string_list), (yyvsp[-1].token_list));
1969 	}
1970 #line 1971 "src/compiler/glsl/glcpp/glcpp-parse.c"
1971     break;
1972 
1973   case 16:
1974 #line 282 "src/compiler/glsl/glcpp/glcpp-parse.y"
1975                              {
1976 		_mesa_string_buffer_append_char(parser->output, '\n');
1977 	}
1978 #line 1979 "src/compiler/glsl/glcpp/glcpp-parse.c"
1979     break;
1980 
1981   case 18:
1982 #line 286 "src/compiler/glsl/glcpp/glcpp-parse.y"
1983                                           {
1984 
1985 		if (parser->skip_stack == NULL ||
1986 		    parser->skip_stack->type == SKIP_NO_SKIP)
1987 		{
1988 			_glcpp_parser_expand_and_lex_from (parser,
1989 							   LINE_EXPANDED, (yyvsp[-1].token_list),
1990 							   EXPANSION_MODE_IGNORE_DEFINED);
1991 		}
1992 	}
1993 #line 1994 "src/compiler/glsl/glcpp/glcpp-parse.c"
1994     break;
1995 
1996   case 20:
1997 #line 300 "src/compiler/glsl/glcpp/glcpp-parse.y"
1998                                             {
1999 		struct hash_entry *entry;
2000 
2001                 /* Section 3.4 (Preprocessor) of the GLSL ES 3.00 spec says:
2002                  *
2003                  *    It is an error to undefine or to redefine a built-in
2004                  *    (pre-defined) macro name.
2005                  *
2006                  * The GLSL ES 1.00 spec does not contain this text, but
2007                  * dEQP's preprocess test in GLES2 checks for it.
2008                  *
2009                  * Section 3.3 (Preprocessor) revision 7, of the GLSL 4.50
2010                  * spec says:
2011                  *
2012                  *    By convention, all macro names containing two consecutive
2013                  *    underscores ( __ ) are reserved for use by underlying
2014                  *    software layers. Defining or undefining such a name
2015                  *    in a shader does not itself result in an error, but may
2016                  *    result in unintended behaviors that stem from having
2017                  *    multiple definitions of the same name. All macro names
2018                  *    prefixed with "GL_" (...) are also reseved, and defining
2019                  *    such a name results in a compile-time error.
2020                  *
2021                  * The code below implements the same checks as GLSLang.
2022                  */
2023 		if (strncmp("GL_", (yyvsp[-1].str), 3) == 0)
2024 			glcpp_error(& (yylsp[-3]), parser, "Built-in (pre-defined)"
2025 				    " names beginning with GL_ cannot be undefined.");
2026 		else if (strstr((yyvsp[-1].str), "__") != NULL) {
2027 			if (parser->is_gles
2028 			    && parser->version >= 300
2029 			    && (strcmp("__LINE__", (yyvsp[-1].str)) == 0
2030 				|| strcmp("__FILE__", (yyvsp[-1].str)) == 0
2031 				|| strcmp("__VERSION__", (yyvsp[-1].str)) == 0)) {
2032 				glcpp_error(& (yylsp[-3]), parser, "Built-in (pre-defined)"
2033 					    " names cannot be undefined.");
2034 			} else if (parser->is_gles && parser->version <= 300) {
2035 				glcpp_error(& (yylsp[-3]), parser,
2036 					    " names containing consecutive underscores"
2037 					    " are reserved.");
2038 			} else {
2039 				glcpp_warning(& (yylsp[-3]), parser,
2040 					      " names containing consecutive underscores"
2041 					      " are reserved.");
2042 			}
2043 		}
2044 
2045 		entry = _mesa_hash_table_search (parser->defines, (yyvsp[-1].str));
2046 		if (entry) {
2047 			_mesa_hash_table_remove (parser->defines, entry);
2048 		}
2049 	}
2050 #line 2051 "src/compiler/glsl/glcpp/glcpp-parse.c"
2051     break;
2052 
2053   case 21:
2054 #line 352 "src/compiler/glsl/glcpp/glcpp-parse.y"
2055                                    {
2056 		size_t include_cursor = _mesa_get_shader_include_cursor(parser->gl_ctx->Shared);
2057 
2058 		/* Remove leading and trailing "" or <> */
2059 		char *start = strchr((yyvsp[-1].str), '"');
2060 		if (!start) {
2061 			_mesa_set_shader_include_cursor(parser->gl_ctx->Shared, 0);
2062 			start = strchr((yyvsp[-1].str), '<');
2063 		}
2064 		char *path = strndup(start + 1, strlen(start + 1) - 1);
2065 
2066 		const char *shader =
2067 			_mesa_lookup_shader_include(parser->gl_ctx, path, false);
2068 		free(path);
2069 
2070 		if (!shader)
2071 			glcpp_error(&(yylsp[-2]), parser, "%s not found", (yyvsp[-1].str));
2072 		else {
2073 			/* Create a temporary parser with the same settings */
2074 			glcpp_parser_t *tmp_parser =
2075 				glcpp_parser_create(parser->gl_ctx, parser->extensions, parser->state);
2076 			tmp_parser->version_set = true;
2077 			tmp_parser->version = parser->version;
2078 
2079 			/* Set the shader source and run the lexer */
2080 			glcpp_lex_set_source_string(tmp_parser, shader);
2081 
2082 			/* Copy any existing define macros to the temporary
2083 			 * shade include parser.
2084 			 */
2085 			struct define_include di;
2086 			di.parser = tmp_parser;
2087 			di.loc = &(yylsp[-2]);
2088 
2089 			hash_table_call_foreach(parser->defines,
2090 						glcpp_parser_copy_defines,
2091 						&di);
2092 
2093 			/* Print out '#include' to the glsl parser. We do this
2094 			 * so that it can do the error checking require to
2095 			 * make sure the ARB_shading_language_include
2096 			 * extension is enabled.
2097 			 */
2098 			_mesa_string_buffer_printf(parser->output, "#include\n");
2099 
2100 			/* Parse the include string before adding to the
2101 			 * preprocessor output.
2102 			 */
2103 			glcpp_parser_parse(tmp_parser);
2104 			_mesa_string_buffer_printf(parser->info_log, "%s",
2105 						   tmp_parser->info_log->buf);
2106 			_mesa_string_buffer_printf(parser->output, "%s",
2107 						   tmp_parser->output->buf);
2108 
2109 			/* Copy any new define macros to the parent parser
2110 			 * and steal the memory of our temp parser so we don't
2111 			 * free these new defines before they are no longer
2112 			 * needed.
2113 			 */
2114 			di.parser = parser;
2115 			di.loc = &(yylsp[-2]);
2116 			ralloc_steal(parser, tmp_parser);
2117 
2118 			hash_table_call_foreach(tmp_parser->defines,
2119 						glcpp_parser_copy_defines,
2120 						&di);
2121 
2122 			/* Destroy tmp parser memory we no longer need */
2123 			glcpp_lex_destroy(tmp_parser->scanner);
2124 			_mesa_hash_table_destroy(tmp_parser->defines, NULL);
2125 		}
2126 
2127 		_mesa_set_shader_include_cursor(parser->gl_ctx->Shared, include_cursor);
2128 	}
2129 #line 2130 "src/compiler/glsl/glcpp/glcpp-parse.c"
2130     break;
2131 
2132   case 22:
2133 #line 426 "src/compiler/glsl/glcpp/glcpp-parse.y"
2134                                         {
2135 		/* Be careful to only evaluate the 'if' expression if
2136 		 * we are not skipping. When we are skipping, we
2137 		 * simply push a new 0-valued 'if' onto the skip
2138 		 * stack.
2139 		 *
2140 		 * This avoids generating diagnostics for invalid
2141 		 * expressions that are being skipped. */
2142 		if (parser->skip_stack == NULL ||
2143 		    parser->skip_stack->type == SKIP_NO_SKIP)
2144 		{
2145 			_glcpp_parser_expand_and_lex_from (parser,
2146 							   IF_EXPANDED, (yyvsp[-1].token_list),
2147 							   EXPANSION_MODE_EVALUATE_DEFINED);
2148 		}
2149 		else
2150 		{
2151 			_glcpp_parser_skip_stack_push_if (parser, & (yylsp[-3]), 0);
2152 			parser->skip_stack->type = SKIP_TO_ENDIF;
2153 		}
2154 	}
2155 #line 2156 "src/compiler/glsl/glcpp/glcpp-parse.c"
2156     break;
2157 
2158   case 23:
2159 #line 447 "src/compiler/glsl/glcpp/glcpp-parse.y"
2160                               {
2161 		/* #if without an expression is only an error if we
2162 		 *  are not skipping */
2163 		if (parser->skip_stack == NULL ||
2164 		    parser->skip_stack->type == SKIP_NO_SKIP)
2165 		{
2166 			glcpp_error(& (yylsp[-2]), parser, "#if with no expression");
2167 		}
2168 		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[-2]), 0);
2169 	}
2170 #line 2171 "src/compiler/glsl/glcpp/glcpp-parse.c"
2171     break;
2172 
2173   case 24:
2174 #line 457 "src/compiler/glsl/glcpp/glcpp-parse.y"
2175                                                  {
2176 		struct hash_entry *entry =
2177 				_mesa_hash_table_search(parser->defines, (yyvsp[-2].str));
2178 		macro_t *macro = entry ? entry->data : NULL;
2179 		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[-4]), macro != NULL);
2180 	}
2181 #line 2182 "src/compiler/glsl/glcpp/glcpp-parse.c"
2182     break;
2183 
2184   case 25:
2185 #line 463 "src/compiler/glsl/glcpp/glcpp-parse.y"
2186                                                   {
2187 		struct hash_entry *entry =
2188 				_mesa_hash_table_search(parser->defines, (yyvsp[-2].str));
2189 		macro_t *macro = entry ? entry->data : NULL;
2190 		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[-2]), macro == NULL);
2191 	}
2192 #line 2193 "src/compiler/glsl/glcpp/glcpp-parse.c"
2193     break;
2194 
2195   case 26:
2196 #line 469 "src/compiler/glsl/glcpp/glcpp-parse.y"
2197                                           {
2198 		/* Be careful to only evaluate the 'elif' expression
2199 		 * if we are not skipping. When we are skipping, we
2200 		 * simply change to a 0-valued 'elif' on the skip
2201 		 * stack.
2202 		 *
2203 		 * This avoids generating diagnostics for invalid
2204 		 * expressions that are being skipped. */
2205 		if (parser->skip_stack &&
2206 		    parser->skip_stack->type == SKIP_TO_ELSE)
2207 		{
2208 			_glcpp_parser_expand_and_lex_from (parser,
2209 							   ELIF_EXPANDED, (yyvsp[-1].token_list),
2210 							   EXPANSION_MODE_EVALUATE_DEFINED);
2211 		}
2212 		else if (parser->skip_stack &&
2213 		    parser->skip_stack->has_else)
2214 		{
2215 			glcpp_error(& (yylsp[-3]), parser, "#elif after #else");
2216 		}
2217 		else
2218 		{
2219 			_glcpp_parser_skip_stack_change_if (parser, & (yylsp[-3]),
2220 							    "elif", 0);
2221 		}
2222 	}
2223 #line 2224 "src/compiler/glsl/glcpp/glcpp-parse.c"
2224     break;
2225 
2226   case 27:
2227 #line 495 "src/compiler/glsl/glcpp/glcpp-parse.y"
2228                                 {
2229 		/* #elif without an expression is an error unless we
2230 		 * are skipping. */
2231 		if (parser->skip_stack &&
2232 		    parser->skip_stack->type == SKIP_TO_ELSE)
2233 		{
2234 			glcpp_error(& (yylsp[-2]), parser, "#elif with no expression");
2235 		}
2236 		else if (parser->skip_stack &&
2237 		    parser->skip_stack->has_else)
2238 		{
2239 			glcpp_error(& (yylsp[-2]), parser, "#elif after #else");
2240 		}
2241 		else
2242 		{
2243 			_glcpp_parser_skip_stack_change_if (parser, & (yylsp[-2]),
2244 							    "elif", 0);
2245 			glcpp_warning(& (yylsp[-2]), parser, "ignoring illegal #elif without expression");
2246 		}
2247 	}
2248 #line 2249 "src/compiler/glsl/glcpp/glcpp-parse.c"
2249     break;
2250 
2251   case 28:
2252 #line 515 "src/compiler/glsl/glcpp/glcpp-parse.y"
2253                         { parser->lexing_directive = 1; }
2254 #line 2255 "src/compiler/glsl/glcpp/glcpp-parse.c"
2255     break;
2256 
2257   case 29:
2258 #line 515 "src/compiler/glsl/glcpp/glcpp-parse.y"
2259                                                                   {
2260 		if (parser->skip_stack &&
2261 		    parser->skip_stack->has_else)
2262 		{
2263 			glcpp_error(& (yylsp[-3]), parser, "multiple #else");
2264 		}
2265 		else
2266 		{
2267 			_glcpp_parser_skip_stack_change_if (parser, & (yylsp[-3]), "else", 1);
2268 			if (parser->skip_stack)
2269 				parser->skip_stack->has_else = true;
2270 		}
2271 	}
2272 #line 2273 "src/compiler/glsl/glcpp/glcpp-parse.c"
2273     break;
2274 
2275   case 30:
2276 #line 528 "src/compiler/glsl/glcpp/glcpp-parse.y"
2277                          {
2278 		_glcpp_parser_skip_stack_pop (parser, & (yylsp[-1]));
2279 	}
2280 #line 2281 "src/compiler/glsl/glcpp/glcpp-parse.c"
2281     break;
2282 
2283   case 32:
2284 #line 531 "src/compiler/glsl/glcpp/glcpp-parse.y"
2285                                                           {
2286 		if (parser->version_set) {
2287 			glcpp_error(& (yylsp[-3]), parser, "#version must appear on the first line");
2288 		}
2289 		_glcpp_parser_handle_version_declaration(parser, (yyvsp[-1].ival), NULL, true);
2290 	}
2291 #line 2292 "src/compiler/glsl/glcpp/glcpp-parse.c"
2292     break;
2293 
2294   case 33:
2295 #line 537 "src/compiler/glsl/glcpp/glcpp-parse.y"
2296                                                                      {
2297 		if (parser->version_set) {
2298 			glcpp_error(& (yylsp[-4]), parser, "#version must appear on the first line");
2299 		}
2300 		_glcpp_parser_handle_version_declaration(parser, (yyvsp[-2].ival), (yyvsp[-1].str), true);
2301 	}
2302 #line 2303 "src/compiler/glsl/glcpp/glcpp-parse.c"
2303     break;
2304 
2305   case 34:
2306 #line 543 "src/compiler/glsl/glcpp/glcpp-parse.y"
2307                            {
2308 		glcpp_parser_resolve_implicit_version(parser);
2309 	}
2310 #line 2311 "src/compiler/glsl/glcpp/glcpp-parse.c"
2311     break;
2312 
2313   case 35:
2314 #line 546 "src/compiler/glsl/glcpp/glcpp-parse.y"
2315                                   {
2316 		_mesa_string_buffer_printf(parser->output, "#%s", (yyvsp[-1].str));
2317 	}
2318 #line 2319 "src/compiler/glsl/glcpp/glcpp-parse.c"
2319     break;
2320 
2321   case 36:
2322 #line 552 "src/compiler/glsl/glcpp/glcpp-parse.y"
2323                                        {
2324 		glcpp_error(& (yylsp[-2]), parser, "#%s", (yyvsp[-1].str));
2325 	}
2326 #line 2327 "src/compiler/glsl/glcpp/glcpp-parse.c"
2327     break;
2328 
2329   case 37:
2330 #line 555 "src/compiler/glsl/glcpp/glcpp-parse.y"
2331                                         {
2332 		glcpp_error (& (yylsp[-2]), parser, "#define without macro name");
2333 	}
2334 #line 2335 "src/compiler/glsl/glcpp/glcpp-parse.c"
2335     break;
2336 
2337   case 38:
2338 #line 558 "src/compiler/glsl/glcpp/glcpp-parse.y"
2339                                               {
2340 		glcpp_error (& (yylsp[-3]), parser, "Illegal non-directive after #");
2341 	}
2342 #line 2343 "src/compiler/glsl/glcpp/glcpp-parse.c"
2343     break;
2344 
2345   case 39:
2346 #line 564 "src/compiler/glsl/glcpp/glcpp-parse.y"
2347                        {
2348 		/* let strtoll detect the base */
2349 		(yyval.ival) = strtoll ((yyvsp[0].str), NULL, 0);
2350 	}
2351 #line 2352 "src/compiler/glsl/glcpp/glcpp-parse.c"
2352     break;
2353 
2354   case 40:
2355 #line 568 "src/compiler/glsl/glcpp/glcpp-parse.y"
2356                 {
2357 		(yyval.ival) = (yyvsp[0].ival);
2358 	}
2359 #line 2360 "src/compiler/glsl/glcpp/glcpp-parse.c"
2360     break;
2361 
2362   case 41:
2363 #line 573 "src/compiler/glsl/glcpp/glcpp-parse.y"
2364                        {
2365 	   /* Both octal and hexadecimal constants begin with 0. */
2366 	   if ((yyvsp[0].str)[0] == '0' && (yyvsp[0].str)[1] != '\0') {
2367 		glcpp_error(&(yylsp[0]), parser, "invalid #version \"%s\" (not a decimal constant)", (yyvsp[0].str));
2368 		(yyval.ival) = 0;
2369 	   } else {
2370 		(yyval.ival) = strtoll((yyvsp[0].str), NULL, 10);
2371 	   }
2372 	}
2373 #line 2374 "src/compiler/glsl/glcpp/glcpp-parse.c"
2374     break;
2375 
2376   case 42:
2377 #line 584 "src/compiler/glsl/glcpp/glcpp-parse.y"
2378                          {
2379 		(yyval.expression_value).value = (yyvsp[0].ival);
2380 		(yyval.expression_value).undefined_macro = NULL;
2381 	}
2382 #line 2383 "src/compiler/glsl/glcpp/glcpp-parse.c"
2383     break;
2384 
2385   case 43:
2386 #line 588 "src/compiler/glsl/glcpp/glcpp-parse.y"
2387                    {
2388 		(yyval.expression_value).value = 0;
2389 		if (parser->is_gles)
2390 			(yyval.expression_value).undefined_macro = linear_strdup(parser->linalloc, (yyvsp[0].str));
2391 		else
2392 			(yyval.expression_value).undefined_macro = NULL;
2393 	}
2394 #line 2395 "src/compiler/glsl/glcpp/glcpp-parse.c"
2395     break;
2396 
2397   case 44:
2398 #line 595 "src/compiler/glsl/glcpp/glcpp-parse.y"
2399                                  {
2400 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value || (yyvsp[0].expression_value).value;
2401 
2402 		/* Short-circuit: Only flag undefined from right side
2403 		 * if left side evaluates to false.
2404 		 */
2405 		if ((yyvsp[-2].expression_value).undefined_macro)
2406 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2407                 else if (! (yyvsp[-2].expression_value).value)
2408 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2409 	}
2410 #line 2411 "src/compiler/glsl/glcpp/glcpp-parse.c"
2411     break;
2412 
2413   case 45:
2414 #line 606 "src/compiler/glsl/glcpp/glcpp-parse.y"
2415                                   {
2416 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value && (yyvsp[0].expression_value).value;
2417 
2418 		/* Short-circuit: Only flag undefined from right-side
2419 		 * if left side evaluates to true.
2420 		 */
2421 		if ((yyvsp[-2].expression_value).undefined_macro)
2422 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2423                 else if ((yyvsp[-2].expression_value).value)
2424 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2425 	}
2426 #line 2427 "src/compiler/glsl/glcpp/glcpp-parse.c"
2427     break;
2428 
2429   case 46:
2430 #line 617 "src/compiler/glsl/glcpp/glcpp-parse.y"
2431                                   {
2432 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value | (yyvsp[0].expression_value).value;
2433 		if ((yyvsp[-2].expression_value).undefined_macro)
2434 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2435                 else
2436 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2437 	}
2438 #line 2439 "src/compiler/glsl/glcpp/glcpp-parse.c"
2439     break;
2440 
2441   case 47:
2442 #line 624 "src/compiler/glsl/glcpp/glcpp-parse.y"
2443                                   {
2444 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value ^ (yyvsp[0].expression_value).value;
2445 		if ((yyvsp[-2].expression_value).undefined_macro)
2446 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2447                 else
2448 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2449 	}
2450 #line 2451 "src/compiler/glsl/glcpp/glcpp-parse.c"
2451     break;
2452 
2453   case 48:
2454 #line 631 "src/compiler/glsl/glcpp/glcpp-parse.y"
2455                                   {
2456 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value & (yyvsp[0].expression_value).value;
2457 		if ((yyvsp[-2].expression_value).undefined_macro)
2458 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2459                 else
2460 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2461 	}
2462 #line 2463 "src/compiler/glsl/glcpp/glcpp-parse.c"
2463     break;
2464 
2465   case 49:
2466 #line 638 "src/compiler/glsl/glcpp/glcpp-parse.y"
2467                                         {
2468 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value != (yyvsp[0].expression_value).value;
2469 		if ((yyvsp[-2].expression_value).undefined_macro)
2470 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2471                 else
2472 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2473 	}
2474 #line 2475 "src/compiler/glsl/glcpp/glcpp-parse.c"
2475     break;
2476 
2477   case 50:
2478 #line 645 "src/compiler/glsl/glcpp/glcpp-parse.y"
2479                                     {
2480 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value == (yyvsp[0].expression_value).value;
2481 		if ((yyvsp[-2].expression_value).undefined_macro)
2482 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2483                 else
2484 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2485 	}
2486 #line 2487 "src/compiler/glsl/glcpp/glcpp-parse.c"
2487     break;
2488 
2489   case 51:
2490 #line 652 "src/compiler/glsl/glcpp/glcpp-parse.y"
2491                                                {
2492 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value >= (yyvsp[0].expression_value).value;
2493 		if ((yyvsp[-2].expression_value).undefined_macro)
2494 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2495                 else
2496 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2497 	}
2498 #line 2499 "src/compiler/glsl/glcpp/glcpp-parse.c"
2499     break;
2500 
2501   case 52:
2502 #line 659 "src/compiler/glsl/glcpp/glcpp-parse.y"
2503                                             {
2504 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value <= (yyvsp[0].expression_value).value;
2505 		if ((yyvsp[-2].expression_value).undefined_macro)
2506 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2507                 else
2508 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2509 	}
2510 #line 2511 "src/compiler/glsl/glcpp/glcpp-parse.c"
2511     break;
2512 
2513   case 53:
2514 #line 666 "src/compiler/glsl/glcpp/glcpp-parse.y"
2515                                   {
2516 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value > (yyvsp[0].expression_value).value;
2517 		if ((yyvsp[-2].expression_value).undefined_macro)
2518 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2519                 else
2520 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2521 	}
2522 #line 2523 "src/compiler/glsl/glcpp/glcpp-parse.c"
2523     break;
2524 
2525   case 54:
2526 #line 673 "src/compiler/glsl/glcpp/glcpp-parse.y"
2527                                   {
2528 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value < (yyvsp[0].expression_value).value;
2529 		if ((yyvsp[-2].expression_value).undefined_macro)
2530 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2531                 else
2532 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2533 	}
2534 #line 2535 "src/compiler/glsl/glcpp/glcpp-parse.c"
2535     break;
2536 
2537   case 55:
2538 #line 680 "src/compiler/glsl/glcpp/glcpp-parse.y"
2539                                           {
2540 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value >> (yyvsp[0].expression_value).value;
2541 		if ((yyvsp[-2].expression_value).undefined_macro)
2542 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2543                 else
2544 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2545 	}
2546 #line 2547 "src/compiler/glsl/glcpp/glcpp-parse.c"
2547     break;
2548 
2549   case 56:
2550 #line 687 "src/compiler/glsl/glcpp/glcpp-parse.y"
2551                                          {
2552 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value << (yyvsp[0].expression_value).value;
2553 		if ((yyvsp[-2].expression_value).undefined_macro)
2554 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2555                 else
2556 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2557 	}
2558 #line 2559 "src/compiler/glsl/glcpp/glcpp-parse.c"
2559     break;
2560 
2561   case 57:
2562 #line 694 "src/compiler/glsl/glcpp/glcpp-parse.y"
2563                                   {
2564 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value - (yyvsp[0].expression_value).value;
2565 		if ((yyvsp[-2].expression_value).undefined_macro)
2566 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2567                 else
2568 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2569 	}
2570 #line 2571 "src/compiler/glsl/glcpp/glcpp-parse.c"
2571     break;
2572 
2573   case 58:
2574 #line 701 "src/compiler/glsl/glcpp/glcpp-parse.y"
2575                                   {
2576 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value + (yyvsp[0].expression_value).value;
2577 		if ((yyvsp[-2].expression_value).undefined_macro)
2578 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2579                 else
2580 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2581 	}
2582 #line 2583 "src/compiler/glsl/glcpp/glcpp-parse.c"
2583     break;
2584 
2585   case 59:
2586 #line 708 "src/compiler/glsl/glcpp/glcpp-parse.y"
2587                                   {
2588 		if ((yyvsp[0].expression_value).value == 0) {
2589 			yyerror (& (yylsp[-2]), parser,
2590 				 "zero modulus in preprocessor directive");
2591 		} else {
2592 			(yyval.expression_value).value = (yyvsp[-2].expression_value).value % (yyvsp[0].expression_value).value;
2593 		}
2594 		if ((yyvsp[-2].expression_value).undefined_macro)
2595 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2596                 else
2597 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2598 	}
2599 #line 2600 "src/compiler/glsl/glcpp/glcpp-parse.c"
2600     break;
2601 
2602   case 60:
2603 #line 720 "src/compiler/glsl/glcpp/glcpp-parse.y"
2604                                   {
2605 		if ((yyvsp[0].expression_value).value == 0) {
2606 			yyerror (& (yylsp[-2]), parser,
2607 				 "division by 0 in preprocessor directive");
2608 		} else {
2609 			(yyval.expression_value).value = (yyvsp[-2].expression_value).value / (yyvsp[0].expression_value).value;
2610 		}
2611 		if ((yyvsp[-2].expression_value).undefined_macro)
2612 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2613                 else
2614 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2615 	}
2616 #line 2617 "src/compiler/glsl/glcpp/glcpp-parse.c"
2617     break;
2618 
2619   case 61:
2620 #line 732 "src/compiler/glsl/glcpp/glcpp-parse.y"
2621                                   {
2622 		(yyval.expression_value).value = (yyvsp[-2].expression_value).value * (yyvsp[0].expression_value).value;
2623 		if ((yyvsp[-2].expression_value).undefined_macro)
2624 			(yyval.expression_value).undefined_macro = (yyvsp[-2].expression_value).undefined_macro;
2625                 else
2626 			(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2627 	}
2628 #line 2629 "src/compiler/glsl/glcpp/glcpp-parse.c"
2629     break;
2630 
2631   case 62:
2632 #line 739 "src/compiler/glsl/glcpp/glcpp-parse.y"
2633                                    {
2634 		(yyval.expression_value).value = ! (yyvsp[0].expression_value).value;
2635 		(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2636 	}
2637 #line 2638 "src/compiler/glsl/glcpp/glcpp-parse.c"
2638     break;
2639 
2640   case 63:
2641 #line 743 "src/compiler/glsl/glcpp/glcpp-parse.y"
2642                                    {
2643 		(yyval.expression_value).value = ~ (yyvsp[0].expression_value).value;
2644 		(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2645 	}
2646 #line 2647 "src/compiler/glsl/glcpp/glcpp-parse.c"
2647     break;
2648 
2649   case 64:
2650 #line 747 "src/compiler/glsl/glcpp/glcpp-parse.y"
2651                                    {
2652 		(yyval.expression_value).value = - (yyvsp[0].expression_value).value;
2653 		(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2654 	}
2655 #line 2656 "src/compiler/glsl/glcpp/glcpp-parse.c"
2656     break;
2657 
2658   case 65:
2659 #line 751 "src/compiler/glsl/glcpp/glcpp-parse.y"
2660                                    {
2661 		(yyval.expression_value).value = + (yyvsp[0].expression_value).value;
2662 		(yyval.expression_value).undefined_macro = (yyvsp[0].expression_value).undefined_macro;
2663 	}
2664 #line 2665 "src/compiler/glsl/glcpp/glcpp-parse.c"
2665     break;
2666 
2667   case 66:
2668 #line 755 "src/compiler/glsl/glcpp/glcpp-parse.y"
2669                            {
2670 		(yyval.expression_value) = (yyvsp[-1].expression_value);
2671 	}
2672 #line 2673 "src/compiler/glsl/glcpp/glcpp-parse.c"
2673     break;
2674 
2675   case 67:
2676 #line 761 "src/compiler/glsl/glcpp/glcpp-parse.y"
2677                    {
2678 		(yyval.string_list) = _string_list_create (parser);
2679 		_string_list_append_item (parser, (yyval.string_list), (yyvsp[0].str));
2680 	}
2681 #line 2682 "src/compiler/glsl/glcpp/glcpp-parse.c"
2682     break;
2683 
2684   case 68:
2685 #line 765 "src/compiler/glsl/glcpp/glcpp-parse.y"
2686                                        {
2687 		(yyval.string_list) = (yyvsp[-2].string_list);
2688 		_string_list_append_item (parser, (yyval.string_list), (yyvsp[0].str));
2689 	}
2690 #line 2691 "src/compiler/glsl/glcpp/glcpp-parse.c"
2691     break;
2692 
2693   case 69:
2694 #line 772 "src/compiler/glsl/glcpp/glcpp-parse.y"
2695                 { (yyval.token_list) = NULL; }
2696 #line 2697 "src/compiler/glsl/glcpp/glcpp-parse.c"
2697     break;
2698 
2699   case 71:
2700 #line 777 "src/compiler/glsl/glcpp/glcpp-parse.y"
2701                     { (yyval.token_list) = NULL; }
2702 #line 2703 "src/compiler/glsl/glcpp/glcpp-parse.c"
2703     break;
2704 
2705   case 74:
2706 #line 783 "src/compiler/glsl/glcpp/glcpp-parse.y"
2707                   {
2708 		glcpp_error(&(yylsp[0]), parser, "extra tokens at end of directive");
2709 	}
2710 #line 2711 "src/compiler/glsl/glcpp/glcpp-parse.c"
2711     break;
2712 
2713   case 75:
2714 #line 789 "src/compiler/glsl/glcpp/glcpp-parse.y"
2715                             {
2716 		parser->space_tokens = 1;
2717 		(yyval.token_list) = _token_list_create (parser);
2718 		_token_list_append (parser, (yyval.token_list), (yyvsp[0].token));
2719 	}
2720 #line 2721 "src/compiler/glsl/glcpp/glcpp-parse.c"
2721     break;
2722 
2723   case 76:
2724 #line 794 "src/compiler/glsl/glcpp/glcpp-parse.y"
2725                                       {
2726 		(yyval.token_list) = (yyvsp[-1].token_list);
2727 		_token_list_append (parser, (yyval.token_list), (yyvsp[0].token));
2728 	}
2729 #line 2730 "src/compiler/glsl/glcpp/glcpp-parse.c"
2730     break;
2731 
2732   case 77:
2733 #line 801 "src/compiler/glsl/glcpp/glcpp-parse.y"
2734                    {
2735 		(yyval.token) = _token_create_str (parser, IDENTIFIER, (yyvsp[0].str));
2736 		(yyval.token)->location = yylloc;
2737 	}
2738 #line 2739 "src/compiler/glsl/glcpp/glcpp-parse.c"
2739     break;
2740 
2741   case 78:
2742 #line 805 "src/compiler/glsl/glcpp/glcpp-parse.y"
2743                        {
2744 		(yyval.token) = _token_create_str (parser, INTEGER_STRING, (yyvsp[0].str));
2745 		(yyval.token)->location = yylloc;
2746 	}
2747 #line 2748 "src/compiler/glsl/glcpp/glcpp-parse.c"
2748     break;
2749 
2750   case 79:
2751 #line 809 "src/compiler/glsl/glcpp/glcpp-parse.y"
2752              {
2753 		(yyval.token) = _token_create_str (parser, PATH, (yyvsp[0].str));
2754 		(yyval.token)->location = yylloc;
2755 	}
2756 #line 2757 "src/compiler/glsl/glcpp/glcpp-parse.c"
2757     break;
2758 
2759   case 80:
2760 #line 813 "src/compiler/glsl/glcpp/glcpp-parse.y"
2761                  {
2762 		(yyval.token) = _token_create_ival (parser, (yyvsp[0].ival), (yyvsp[0].ival));
2763 		(yyval.token)->location = yylloc;
2764 	}
2765 #line 2766 "src/compiler/glsl/glcpp/glcpp-parse.c"
2766     break;
2767 
2768   case 81:
2769 #line 817 "src/compiler/glsl/glcpp/glcpp-parse.y"
2770                 {
2771 		(yyval.token) = _token_create_ival (parser, DEFINED, DEFINED);
2772 		(yyval.token)->location = yylloc;
2773 	}
2774 #line 2775 "src/compiler/glsl/glcpp/glcpp-parse.c"
2775     break;
2776 
2777   case 82:
2778 #line 821 "src/compiler/glsl/glcpp/glcpp-parse.y"
2779               {
2780 		(yyval.token) = _token_create_str (parser, OTHER, (yyvsp[0].str));
2781 		(yyval.token)->location = yylloc;
2782 	}
2783 #line 2784 "src/compiler/glsl/glcpp/glcpp-parse.c"
2784     break;
2785 
2786   case 83:
2787 #line 825 "src/compiler/glsl/glcpp/glcpp-parse.y"
2788               {
2789 		(yyval.token) = _token_create_ival (parser, SPACE, SPACE);
2790 		(yyval.token)->location = yylloc;
2791 	}
2792 #line 2793 "src/compiler/glsl/glcpp/glcpp-parse.c"
2793     break;
2794 
2795   case 84:
2796 #line 832 "src/compiler/glsl/glcpp/glcpp-parse.y"
2797                                 { (yyval.ival) = '['; }
2798 #line 2799 "src/compiler/glsl/glcpp/glcpp-parse.c"
2799     break;
2800 
2801   case 85:
2802 #line 833 "src/compiler/glsl/glcpp/glcpp-parse.y"
2803                                 { (yyval.ival) = ']'; }
2804 #line 2805 "src/compiler/glsl/glcpp/glcpp-parse.c"
2805     break;
2806 
2807   case 86:
2808 #line 834 "src/compiler/glsl/glcpp/glcpp-parse.y"
2809                                 { (yyval.ival) = '('; }
2810 #line 2811 "src/compiler/glsl/glcpp/glcpp-parse.c"
2811     break;
2812 
2813   case 87:
2814 #line 835 "src/compiler/glsl/glcpp/glcpp-parse.y"
2815                                 { (yyval.ival) = ')'; }
2816 #line 2817 "src/compiler/glsl/glcpp/glcpp-parse.c"
2817     break;
2818 
2819   case 88:
2820 #line 836 "src/compiler/glsl/glcpp/glcpp-parse.y"
2821                                 { (yyval.ival) = '{'; }
2822 #line 2823 "src/compiler/glsl/glcpp/glcpp-parse.c"
2823     break;
2824 
2825   case 89:
2826 #line 837 "src/compiler/glsl/glcpp/glcpp-parse.y"
2827                                 { (yyval.ival) = '}'; }
2828 #line 2829 "src/compiler/glsl/glcpp/glcpp-parse.c"
2829     break;
2830 
2831   case 90:
2832 #line 838 "src/compiler/glsl/glcpp/glcpp-parse.y"
2833                                 { (yyval.ival) = '.'; }
2834 #line 2835 "src/compiler/glsl/glcpp/glcpp-parse.c"
2835     break;
2836 
2837   case 91:
2838 #line 839 "src/compiler/glsl/glcpp/glcpp-parse.y"
2839                                 { (yyval.ival) = '&'; }
2840 #line 2841 "src/compiler/glsl/glcpp/glcpp-parse.c"
2841     break;
2842 
2843   case 92:
2844 #line 840 "src/compiler/glsl/glcpp/glcpp-parse.y"
2845                                 { (yyval.ival) = '*'; }
2846 #line 2847 "src/compiler/glsl/glcpp/glcpp-parse.c"
2847     break;
2848 
2849   case 93:
2850 #line 841 "src/compiler/glsl/glcpp/glcpp-parse.y"
2851                                 { (yyval.ival) = '+'; }
2852 #line 2853 "src/compiler/glsl/glcpp/glcpp-parse.c"
2853     break;
2854 
2855   case 94:
2856 #line 842 "src/compiler/glsl/glcpp/glcpp-parse.y"
2857                                 { (yyval.ival) = '-'; }
2858 #line 2859 "src/compiler/glsl/glcpp/glcpp-parse.c"
2859     break;
2860 
2861   case 95:
2862 #line 843 "src/compiler/glsl/glcpp/glcpp-parse.y"
2863                                 { (yyval.ival) = '~'; }
2864 #line 2865 "src/compiler/glsl/glcpp/glcpp-parse.c"
2865     break;
2866 
2867   case 96:
2868 #line 844 "src/compiler/glsl/glcpp/glcpp-parse.y"
2869                                 { (yyval.ival) = '!'; }
2870 #line 2871 "src/compiler/glsl/glcpp/glcpp-parse.c"
2871     break;
2872 
2873   case 97:
2874 #line 845 "src/compiler/glsl/glcpp/glcpp-parse.y"
2875                                 { (yyval.ival) = '/'; }
2876 #line 2877 "src/compiler/glsl/glcpp/glcpp-parse.c"
2877     break;
2878 
2879   case 98:
2880 #line 846 "src/compiler/glsl/glcpp/glcpp-parse.y"
2881                                 { (yyval.ival) = '%'; }
2882 #line 2883 "src/compiler/glsl/glcpp/glcpp-parse.c"
2883     break;
2884 
2885   case 99:
2886 #line 847 "src/compiler/glsl/glcpp/glcpp-parse.y"
2887                                 { (yyval.ival) = LEFT_SHIFT; }
2888 #line 2889 "src/compiler/glsl/glcpp/glcpp-parse.c"
2889     break;
2890 
2891   case 100:
2892 #line 848 "src/compiler/glsl/glcpp/glcpp-parse.y"
2893                                 { (yyval.ival) = RIGHT_SHIFT; }
2894 #line 2895 "src/compiler/glsl/glcpp/glcpp-parse.c"
2895     break;
2896 
2897   case 101:
2898 #line 849 "src/compiler/glsl/glcpp/glcpp-parse.y"
2899                                 { (yyval.ival) = '<'; }
2900 #line 2901 "src/compiler/glsl/glcpp/glcpp-parse.c"
2901     break;
2902 
2903   case 102:
2904 #line 850 "src/compiler/glsl/glcpp/glcpp-parse.y"
2905                                 { (yyval.ival) = '>'; }
2906 #line 2907 "src/compiler/glsl/glcpp/glcpp-parse.c"
2907     break;
2908 
2909   case 103:
2910 #line 851 "src/compiler/glsl/glcpp/glcpp-parse.y"
2911                                 { (yyval.ival) = LESS_OR_EQUAL; }
2912 #line 2913 "src/compiler/glsl/glcpp/glcpp-parse.c"
2913     break;
2914 
2915   case 104:
2916 #line 852 "src/compiler/glsl/glcpp/glcpp-parse.y"
2917                                 { (yyval.ival) = GREATER_OR_EQUAL; }
2918 #line 2919 "src/compiler/glsl/glcpp/glcpp-parse.c"
2919     break;
2920 
2921   case 105:
2922 #line 853 "src/compiler/glsl/glcpp/glcpp-parse.y"
2923                                 { (yyval.ival) = EQUAL; }
2924 #line 2925 "src/compiler/glsl/glcpp/glcpp-parse.c"
2925     break;
2926 
2927   case 106:
2928 #line 854 "src/compiler/glsl/glcpp/glcpp-parse.y"
2929                                 { (yyval.ival) = NOT_EQUAL; }
2930 #line 2931 "src/compiler/glsl/glcpp/glcpp-parse.c"
2931     break;
2932 
2933   case 107:
2934 #line 855 "src/compiler/glsl/glcpp/glcpp-parse.y"
2935                                 { (yyval.ival) = '^'; }
2936 #line 2937 "src/compiler/glsl/glcpp/glcpp-parse.c"
2937     break;
2938 
2939   case 108:
2940 #line 856 "src/compiler/glsl/glcpp/glcpp-parse.y"
2941                                 { (yyval.ival) = '|'; }
2942 #line 2943 "src/compiler/glsl/glcpp/glcpp-parse.c"
2943     break;
2944 
2945   case 109:
2946 #line 857 "src/compiler/glsl/glcpp/glcpp-parse.y"
2947                                 { (yyval.ival) = AND; }
2948 #line 2949 "src/compiler/glsl/glcpp/glcpp-parse.c"
2949     break;
2950 
2951   case 110:
2952 #line 858 "src/compiler/glsl/glcpp/glcpp-parse.y"
2953                                 { (yyval.ival) = OR; }
2954 #line 2955 "src/compiler/glsl/glcpp/glcpp-parse.c"
2955     break;
2956 
2957   case 111:
2958 #line 859 "src/compiler/glsl/glcpp/glcpp-parse.y"
2959                                 { (yyval.ival) = ';'; }
2960 #line 2961 "src/compiler/glsl/glcpp/glcpp-parse.c"
2961     break;
2962 
2963   case 112:
2964 #line 860 "src/compiler/glsl/glcpp/glcpp-parse.y"
2965                                 { (yyval.ival) = ','; }
2966 #line 2967 "src/compiler/glsl/glcpp/glcpp-parse.c"
2967     break;
2968 
2969   case 113:
2970 #line 861 "src/compiler/glsl/glcpp/glcpp-parse.y"
2971                                 { (yyval.ival) = '='; }
2972 #line 2973 "src/compiler/glsl/glcpp/glcpp-parse.c"
2973     break;
2974 
2975   case 114:
2976 #line 862 "src/compiler/glsl/glcpp/glcpp-parse.y"
2977                                 { (yyval.ival) = PASTE; }
2978 #line 2979 "src/compiler/glsl/glcpp/glcpp-parse.c"
2979     break;
2980 
2981   case 115:
2982 #line 863 "src/compiler/glsl/glcpp/glcpp-parse.y"
2983                                 { (yyval.ival) = PLUS_PLUS; }
2984 #line 2985 "src/compiler/glsl/glcpp/glcpp-parse.c"
2985     break;
2986 
2987   case 116:
2988 #line 864 "src/compiler/glsl/glcpp/glcpp-parse.y"
2989                                 { (yyval.ival) = MINUS_MINUS; }
2990 #line 2991 "src/compiler/glsl/glcpp/glcpp-parse.c"
2991     break;
2992 
2993 
2994 #line 2995 "src/compiler/glsl/glcpp/glcpp-parse.c"
2995 
2996       default: break;
2997     }
2998   /* User semantic actions sometimes alter yychar, and that requires
2999      that yytoken be updated with the new translation.  We take the
3000      approach of translating immediately before every use of yytoken.
3001      One alternative is translating here after every semantic action,
3002      but that translation would be missed if the semantic action invokes
3003      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
3004      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
3005      incorrect destructor might then be invoked immediately.  In the
3006      case of YYERROR or YYBACKUP, subsequent parser actions might lead
3007      to an incorrect destructor call or verbose syntax error message
3008      before the lookahead is translated.  */
3009   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3010 
3011   YYPOPSTACK (yylen);
3012   yylen = 0;
3013   YY_STACK_PRINT (yyss, yyssp);
3014 
3015   *++yyvsp = yyval;
3016   *++yylsp = yyloc;
3017 
3018   /* Now 'shift' the result of the reduction.  Determine what state
3019      that goes to, based on the state we popped back to and the rule
3020      number reduced by.  */
3021   {
3022     const int yylhs = yyr1[yyn] - YYNTOKENS;
3023     const int yyi = yypgoto[yylhs] + *yyssp;
3024     yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
3025                ? yytable[yyi]
3026                : yydefgoto[yylhs]);
3027   }
3028 
3029   goto yynewstate;
3030 
3031 
3032 /*--------------------------------------.
3033 | yyerrlab -- here on detecting error.  |
3034 `--------------------------------------*/
3035 yyerrlab:
3036   /* Make sure we have latest lookahead translation.  See comments at
3037      user semantic actions for why this is necessary.  */
3038   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
3039 
3040   /* If not already recovering from an error, report this error.  */
3041   if (!yyerrstatus)
3042     {
3043       ++yynerrs;
3044 #if ! YYERROR_VERBOSE
3045       yyerror (&yylloc, parser, YY_("syntax error"));
3046 #else
3047 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
3048                                         yyssp, yytoken)
3049       {
3050         char const *yymsgp = YY_("syntax error");
3051         int yysyntax_error_status;
3052         yysyntax_error_status = YYSYNTAX_ERROR;
3053         if (yysyntax_error_status == 0)
3054           yymsgp = yymsg;
3055         else if (yysyntax_error_status == 1)
3056           {
3057             if (yymsg != yymsgbuf)
3058               YYSTACK_FREE (yymsg);
3059             yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
3060             if (!yymsg)
3061               {
3062                 yymsg = yymsgbuf;
3063                 yymsg_alloc = sizeof yymsgbuf;
3064                 yysyntax_error_status = 2;
3065               }
3066             else
3067               {
3068                 yysyntax_error_status = YYSYNTAX_ERROR;
3069                 yymsgp = yymsg;
3070               }
3071           }
3072         yyerror (&yylloc, parser, yymsgp);
3073         if (yysyntax_error_status == 2)
3074           goto yyexhaustedlab;
3075       }
3076 # undef YYSYNTAX_ERROR
3077 #endif
3078     }
3079 
3080   yyerror_range[1] = yylloc;
3081 
3082   if (yyerrstatus == 3)
3083     {
3084       /* If just tried and failed to reuse lookahead token after an
3085          error, discard it.  */
3086 
3087       if (yychar <= YYEOF)
3088         {
3089           /* Return failure if at end of input.  */
3090           if (yychar == YYEOF)
3091             YYABORT;
3092         }
3093       else
3094         {
3095           yydestruct ("Error: discarding",
3096                       yytoken, &yylval, &yylloc, parser);
3097           yychar = YYEMPTY;
3098         }
3099     }
3100 
3101   /* Else will try to reuse lookahead token after shifting the error
3102      token.  */
3103   goto yyerrlab1;
3104 
3105 
3106 /*---------------------------------------------------.
3107 | yyerrorlab -- error raised explicitly by YYERROR.  |
3108 `---------------------------------------------------*/
3109 yyerrorlab:
3110   /* Pacify compilers when the user code never invokes YYERROR and the
3111      label yyerrorlab therefore never appears in user code.  */
3112   if (0)
3113     YYERROR;
3114 
3115   /* Do not reclaim the symbols of the rule whose action triggered
3116      this YYERROR.  */
3117   YYPOPSTACK (yylen);
3118   yylen = 0;
3119   YY_STACK_PRINT (yyss, yyssp);
3120   yystate = *yyssp;
3121   goto yyerrlab1;
3122 
3123 
3124 /*-------------------------------------------------------------.
3125 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
3126 `-------------------------------------------------------------*/
3127 yyerrlab1:
3128   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
3129 
3130   for (;;)
3131     {
3132       yyn = yypact[yystate];
3133       if (!yypact_value_is_default (yyn))
3134         {
3135           yyn += YYTERROR;
3136           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
3137             {
3138               yyn = yytable[yyn];
3139               if (0 < yyn)
3140                 break;
3141             }
3142         }
3143 
3144       /* Pop the current state because it cannot handle the error token.  */
3145       if (yyssp == yyss)
3146         YYABORT;
3147 
3148       yyerror_range[1] = *yylsp;
3149       yydestruct ("Error: popping",
3150                   yystos[yystate], yyvsp, yylsp, parser);
3151       YYPOPSTACK (1);
3152       yystate = *yyssp;
3153       YY_STACK_PRINT (yyss, yyssp);
3154     }
3155 
3156   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3157   *++yyvsp = yylval;
3158   YY_IGNORE_MAYBE_UNINITIALIZED_END
3159 
3160   yyerror_range[2] = yylloc;
3161   /* Using YYLLOC is tempting, but would change the location of
3162      the lookahead.  YYLOC is available though.  */
3163   YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
3164   *++yylsp = yyloc;
3165 
3166   /* Shift the error token.  */
3167   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
3168 
3169   yystate = yyn;
3170   goto yynewstate;
3171 
3172 
3173 /*-------------------------------------.
3174 | yyacceptlab -- YYACCEPT comes here.  |
3175 `-------------------------------------*/
3176 yyacceptlab:
3177   yyresult = 0;
3178   goto yyreturn;
3179 
3180 
3181 /*-----------------------------------.
3182 | yyabortlab -- YYABORT comes here.  |
3183 `-----------------------------------*/
3184 yyabortlab:
3185   yyresult = 1;
3186   goto yyreturn;
3187 
3188 
3189 #if !defined yyoverflow || YYERROR_VERBOSE
3190 /*-------------------------------------------------.
3191 | yyexhaustedlab -- memory exhaustion comes here.  |
3192 `-------------------------------------------------*/
3193 yyexhaustedlab:
3194   yyerror (&yylloc, parser, YY_("memory exhausted"));
3195   yyresult = 2;
3196   /* Fall through.  */
3197 #endif
3198 
3199 
3200 /*-----------------------------------------------------.
3201 | yyreturn -- parsing is finished, return the result.  |
3202 `-----------------------------------------------------*/
3203 yyreturn:
3204   if (yychar != YYEMPTY)
3205     {
3206       /* Make sure we have latest lookahead translation.  See comments at
3207          user semantic actions for why this is necessary.  */
3208       yytoken = YYTRANSLATE (yychar);
3209       yydestruct ("Cleanup: discarding lookahead",
3210                   yytoken, &yylval, &yylloc, parser);
3211     }
3212   /* Do not reclaim the symbols of the rule whose action triggered
3213      this YYABORT or YYACCEPT.  */
3214   YYPOPSTACK (yylen);
3215   YY_STACK_PRINT (yyss, yyssp);
3216   while (yyssp != yyss)
3217     {
3218       yydestruct ("Cleanup: popping",
3219                   yystos[*yyssp], yyvsp, yylsp, parser);
3220       YYPOPSTACK (1);
3221     }
3222 #ifndef yyoverflow
3223   if (yyss != yyssa)
3224     YYSTACK_FREE (yyss);
3225 #endif
3226 #if YYERROR_VERBOSE
3227   if (yymsg != yymsgbuf)
3228     YYSTACK_FREE (yymsg);
3229 #endif
3230   return yyresult;
3231 }
3232 #line 867 "src/compiler/glsl/glcpp/glcpp-parse.y"
3233 
3234 
3235 string_list_t *
_string_list_create(glcpp_parser_t * parser)3236 _string_list_create(glcpp_parser_t *parser)
3237 {
3238    string_list_t *list;
3239 
3240    list = linear_alloc_child(parser->linalloc, sizeof(string_list_t));
3241    list->head = NULL;
3242    list->tail = NULL;
3243 
3244    return list;
3245 }
3246 
3247 void
_string_list_append_item(glcpp_parser_t * parser,string_list_t * list,const char * str)3248 _string_list_append_item(glcpp_parser_t *parser, string_list_t *list,
3249                          const char *str)
3250 {
3251    string_node_t *node;
3252 
3253    node = linear_alloc_child(parser->linalloc, sizeof(string_node_t));
3254    node->str = linear_strdup(parser->linalloc, str);
3255 
3256    node->next = NULL;
3257 
3258    if (list->head == NULL) {
3259       list->head = node;
3260    } else {
3261       list->tail->next = node;
3262    }
3263 
3264    list->tail = node;
3265 }
3266 
3267 int
_string_list_contains(string_list_t * list,const char * member,int * index)3268 _string_list_contains(string_list_t *list, const char *member, int *index)
3269 {
3270    string_node_t *node;
3271    int i;
3272 
3273    if (list == NULL)
3274       return 0;
3275 
3276    for (i = 0, node = list->head; node; i++, node = node->next) {
3277       if (strcmp (node->str, member) == 0) {
3278          if (index)
3279             *index = i;
3280          return 1;
3281       }
3282    }
3283 
3284    return 0;
3285 }
3286 
3287 /* Return duplicate string in list (if any), NULL otherwise. */
3288 const char *
_string_list_has_duplicate(string_list_t * list)3289 _string_list_has_duplicate(string_list_t *list)
3290 {
3291    string_node_t *node, *dup;
3292 
3293    if (list == NULL)
3294       return NULL;
3295 
3296    for (node = list->head; node; node = node->next) {
3297       for (dup = node->next; dup; dup = dup->next) {
3298          if (strcmp (node->str, dup->str) == 0)
3299             return node->str;
3300       }
3301    }
3302 
3303    return NULL;
3304 }
3305 
3306 int
_string_list_length(string_list_t * list)3307 _string_list_length(string_list_t *list)
3308 {
3309    int length = 0;
3310    string_node_t *node;
3311 
3312    if (list == NULL)
3313       return 0;
3314 
3315    for (node = list->head; node; node = node->next)
3316       length++;
3317 
3318    return length;
3319 }
3320 
3321 int
_string_list_equal(string_list_t * a,string_list_t * b)3322 _string_list_equal(string_list_t *a, string_list_t *b)
3323 {
3324    string_node_t *node_a, *node_b;
3325 
3326    if (a == NULL && b == NULL)
3327       return 1;
3328 
3329    if (a == NULL || b == NULL)
3330       return 0;
3331 
3332    for (node_a = a->head, node_b = b->head;
3333         node_a && node_b;
3334         node_a = node_a->next, node_b = node_b->next)
3335    {
3336       if (strcmp (node_a->str, node_b->str))
3337          return 0;
3338    }
3339 
3340    /* Catch the case of lists being different lengths, (which
3341     * would cause the loop above to terminate after the shorter
3342     * list). */
3343    return node_a == node_b;
3344 }
3345 
3346 argument_list_t *
_argument_list_create(glcpp_parser_t * parser)3347 _argument_list_create(glcpp_parser_t *parser)
3348 {
3349    argument_list_t *list;
3350 
3351    list = linear_alloc_child(parser->linalloc, sizeof(argument_list_t));
3352    list->head = NULL;
3353    list->tail = NULL;
3354 
3355    return list;
3356 }
3357 
3358 void
_argument_list_append(glcpp_parser_t * parser,argument_list_t * list,token_list_t * argument)3359 _argument_list_append(glcpp_parser_t *parser,
3360                       argument_list_t *list, token_list_t *argument)
3361 {
3362    argument_node_t *node;
3363 
3364    node = linear_alloc_child(parser->linalloc, sizeof(argument_node_t));
3365    node->argument = argument;
3366 
3367    node->next = NULL;
3368 
3369    if (list->head == NULL) {
3370       list->head = node;
3371    } else {
3372       list->tail->next = node;
3373    }
3374 
3375    list->tail = node;
3376 }
3377 
3378 int
_argument_list_length(argument_list_t * list)3379 _argument_list_length(argument_list_t *list)
3380 {
3381    int length = 0;
3382    argument_node_t *node;
3383 
3384    if (list == NULL)
3385       return 0;
3386 
3387    for (node = list->head; node; node = node->next)
3388       length++;
3389 
3390    return length;
3391 }
3392 
3393 token_list_t *
_argument_list_member_at(argument_list_t * list,int index)3394 _argument_list_member_at(argument_list_t *list, int index)
3395 {
3396    argument_node_t *node;
3397    int i;
3398 
3399    if (list == NULL)
3400       return NULL;
3401 
3402    node = list->head;
3403    for (i = 0; i < index; i++) {
3404       node = node->next;
3405       if (node == NULL)
3406          break;
3407    }
3408 
3409    if (node)
3410       return node->argument;
3411 
3412    return NULL;
3413 }
3414 
3415 token_t *
_token_create_str(glcpp_parser_t * parser,int type,char * str)3416 _token_create_str(glcpp_parser_t *parser, int type, char *str)
3417 {
3418    token_t *token;
3419 
3420    token = linear_alloc_child(parser->linalloc, sizeof(token_t));
3421    token->type = type;
3422    token->value.str = str;
3423 
3424    return token;
3425 }
3426 
3427 token_t *
_token_create_ival(glcpp_parser_t * parser,int type,int ival)3428 _token_create_ival(glcpp_parser_t *parser, int type, int ival)
3429 {
3430    token_t *token;
3431 
3432    token = linear_alloc_child(parser->linalloc, sizeof(token_t));
3433    token->type = type;
3434    token->value.ival = ival;
3435 
3436    return token;
3437 }
3438 
3439 token_list_t *
_token_list_create(glcpp_parser_t * parser)3440 _token_list_create(glcpp_parser_t *parser)
3441 {
3442    token_list_t *list;
3443 
3444    list = linear_alloc_child(parser->linalloc, sizeof(token_list_t));
3445    list->head = NULL;
3446    list->tail = NULL;
3447    list->non_space_tail = NULL;
3448 
3449    return list;
3450 }
3451 
3452 void
_token_list_append(glcpp_parser_t * parser,token_list_t * list,token_t * token)3453 _token_list_append(glcpp_parser_t *parser, token_list_t *list, token_t *token)
3454 {
3455    token_node_t *node;
3456 
3457    node = linear_alloc_child(parser->linalloc, sizeof(token_node_t));
3458    node->token = token;
3459    node->next = NULL;
3460 
3461    if (list->head == NULL) {
3462       list->head = node;
3463    } else {
3464       list->tail->next = node;
3465    }
3466 
3467    list->tail = node;
3468    if (token->type != SPACE)
3469       list->non_space_tail = node;
3470 }
3471 
3472 void
_token_list_append_list(token_list_t * list,token_list_t * tail)3473 _token_list_append_list(token_list_t *list, token_list_t *tail)
3474 {
3475    if (tail == NULL || tail->head == NULL)
3476       return;
3477 
3478    if (list->head == NULL) {
3479       list->head = tail->head;
3480    } else {
3481       list->tail->next = tail->head;
3482    }
3483 
3484    list->tail = tail->tail;
3485    list->non_space_tail = tail->non_space_tail;
3486 }
3487 
3488 static token_list_t *
_token_list_copy(glcpp_parser_t * parser,token_list_t * other)3489 _token_list_copy(glcpp_parser_t *parser, token_list_t *other)
3490 {
3491    token_list_t *copy;
3492    token_node_t *node;
3493 
3494    if (other == NULL)
3495       return NULL;
3496 
3497    copy = _token_list_create (parser);
3498    for (node = other->head; node; node = node->next) {
3499       token_t *new_token = linear_alloc_child(parser->linalloc, sizeof(token_t));
3500       *new_token = *node->token;
3501       _token_list_append (parser, copy, new_token);
3502    }
3503 
3504    return copy;
3505 }
3506 
3507 static void
_token_list_trim_trailing_space(token_list_t * list)3508 _token_list_trim_trailing_space(token_list_t *list)
3509 {
3510    if (list->non_space_tail) {
3511       list->non_space_tail->next = NULL;
3512       list->tail = list->non_space_tail;
3513    }
3514 }
3515 
3516 static int
_token_list_is_empty_ignoring_space(token_list_t * l)3517 _token_list_is_empty_ignoring_space(token_list_t *l)
3518 {
3519    token_node_t *n;
3520 
3521    if (l == NULL)
3522       return 1;
3523 
3524    n = l->head;
3525    while (n != NULL && n->token->type == SPACE)
3526       n = n->next;
3527 
3528    return n == NULL;
3529 }
3530 
3531 int
_token_list_equal_ignoring_space(token_list_t * a,token_list_t * b)3532 _token_list_equal_ignoring_space(token_list_t *a, token_list_t *b)
3533 {
3534    token_node_t *node_a, *node_b;
3535 
3536    if (a == NULL || b == NULL) {
3537       int a_empty = _token_list_is_empty_ignoring_space(a);
3538       int b_empty = _token_list_is_empty_ignoring_space(b);
3539       return a_empty == b_empty;
3540    }
3541 
3542    node_a = a->head;
3543    node_b = b->head;
3544 
3545    while (1)
3546    {
3547       if (node_a == NULL && node_b == NULL)
3548          break;
3549 
3550       /* Ignore trailing whitespace */
3551       if (node_a == NULL && node_b->token->type == SPACE) {
3552          while (node_b && node_b->token->type == SPACE)
3553             node_b = node_b->next;
3554       }
3555 
3556       if (node_a == NULL && node_b == NULL)
3557          break;
3558 
3559       if (node_b == NULL && node_a->token->type == SPACE) {
3560          while (node_a && node_a->token->type == SPACE)
3561             node_a = node_a->next;
3562       }
3563 
3564       if (node_a == NULL && node_b == NULL)
3565          break;
3566 
3567       if (node_a == NULL || node_b == NULL)
3568          return 0;
3569       /* Make sure whitespace appears in the same places in both.
3570        * It need not be exactly the same amount of whitespace,
3571        * though.
3572        */
3573       if (node_a->token->type == SPACE && node_b->token->type == SPACE) {
3574          while (node_a && node_a->token->type == SPACE)
3575             node_a = node_a->next;
3576          while (node_b && node_b->token->type == SPACE)
3577             node_b = node_b->next;
3578          continue;
3579       }
3580 
3581       if (node_a->token->type != node_b->token->type)
3582          return 0;
3583 
3584       switch (node_a->token->type) {
3585       case INTEGER:
3586          if (node_a->token->value.ival !=  node_b->token->value.ival) {
3587             return 0;
3588          }
3589          break;
3590       case IDENTIFIER:
3591       case INTEGER_STRING:
3592       case OTHER:
3593          if (strcmp(node_a->token->value.str, node_b->token->value.str)) {
3594             return 0;
3595          }
3596          break;
3597       }
3598 
3599       node_a = node_a->next;
3600       node_b = node_b->next;
3601    }
3602 
3603    return 1;
3604 }
3605 
3606 static void
_token_print(struct _mesa_string_buffer * out,token_t * token)3607 _token_print(struct _mesa_string_buffer *out, token_t *token)
3608 {
3609    if (token->type < 256) {
3610       _mesa_string_buffer_append_char(out, token->type);
3611       return;
3612    }
3613 
3614    switch (token->type) {
3615    case INTEGER:
3616       _mesa_string_buffer_printf(out, "%" PRIiMAX, token->value.ival);
3617       break;
3618    case IDENTIFIER:
3619    case INTEGER_STRING:
3620    case PATH:
3621    case OTHER:
3622       _mesa_string_buffer_append(out, token->value.str);
3623       break;
3624    case SPACE:
3625       _mesa_string_buffer_append_char(out, ' ');
3626       break;
3627    case LEFT_SHIFT:
3628       _mesa_string_buffer_append(out, "<<");
3629       break;
3630    case RIGHT_SHIFT:
3631       _mesa_string_buffer_append(out, ">>");
3632       break;
3633    case LESS_OR_EQUAL:
3634       _mesa_string_buffer_append(out, "<=");
3635       break;
3636    case GREATER_OR_EQUAL:
3637       _mesa_string_buffer_append(out, ">=");
3638       break;
3639    case EQUAL:
3640       _mesa_string_buffer_append(out, "==");
3641       break;
3642    case NOT_EQUAL:
3643       _mesa_string_buffer_append(out, "!=");
3644       break;
3645    case AND:
3646       _mesa_string_buffer_append(out, "&&");
3647       break;
3648    case OR:
3649       _mesa_string_buffer_append(out, "||");
3650       break;
3651    case PASTE:
3652       _mesa_string_buffer_append(out, "##");
3653       break;
3654    case PLUS_PLUS:
3655       _mesa_string_buffer_append(out, "++");
3656       break;
3657    case MINUS_MINUS:
3658       _mesa_string_buffer_append(out, "--");
3659       break;
3660    case DEFINED:
3661       _mesa_string_buffer_append(out, "defined");
3662       break;
3663    case PLACEHOLDER:
3664       /* Nothing to print. */
3665       break;
3666    default:
3667       assert(!"Error: Don't know how to print token.");
3668 
3669       break;
3670    }
3671 }
3672 
3673 /* Return a new token formed by pasting 'token' and 'other'. Note that this
3674  * function may return 'token' or 'other' directly rather than allocating
3675  * anything new.
3676  *
3677  * Caution: Only very cursory error-checking is performed to see if
3678  * the final result is a valid single token. */
3679 static token_t *
_token_paste(glcpp_parser_t * parser,token_t * token,token_t * other)3680 _token_paste(glcpp_parser_t *parser, token_t *token, token_t *other)
3681 {
3682    token_t *combined = NULL;
3683 
3684    /* Pasting a placeholder onto anything makes no change. */
3685    if (other->type == PLACEHOLDER)
3686       return token;
3687 
3688    /* When 'token' is a placeholder, just return 'other'. */
3689    if (token->type == PLACEHOLDER)
3690       return other;
3691 
3692    /* A very few single-character punctuators can be combined
3693     * with another to form a multi-character punctuator. */
3694    switch (token->type) {
3695    case '<':
3696       if (other->type == '<')
3697          combined = _token_create_ival (parser, LEFT_SHIFT, LEFT_SHIFT);
3698       else if (other->type == '=')
3699          combined = _token_create_ival (parser, LESS_OR_EQUAL, LESS_OR_EQUAL);
3700       break;
3701    case '>':
3702       if (other->type == '>')
3703          combined = _token_create_ival (parser, RIGHT_SHIFT, RIGHT_SHIFT);
3704       else if (other->type == '=')
3705          combined = _token_create_ival (parser, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
3706       break;
3707    case '=':
3708       if (other->type == '=')
3709          combined = _token_create_ival (parser, EQUAL, EQUAL);
3710       break;
3711    case '!':
3712       if (other->type == '=')
3713          combined = _token_create_ival (parser, NOT_EQUAL, NOT_EQUAL);
3714       break;
3715    case '&':
3716       if (other->type == '&')
3717          combined = _token_create_ival (parser, AND, AND);
3718       break;
3719    case '|':
3720       if (other->type == '|')
3721          combined = _token_create_ival (parser, OR, OR);
3722       break;
3723    }
3724 
3725    if (combined != NULL) {
3726       /* Inherit the location from the first token */
3727       combined->location = token->location;
3728       return combined;
3729    }
3730 
3731    /* Two string-valued (or integer) tokens can usually just be
3732     * mashed together. (We also handle a string followed by an
3733     * integer here as well.)
3734     *
3735     * There are some exceptions here. Notably, if the first token
3736     * is an integer (or a string representing an integer), then
3737     * the second token must also be an integer or must be a
3738     * string representing an integer that begins with a digit.
3739     */
3740    if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING || token->type == INTEGER) &&
3741        (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING || other->type == INTEGER))
3742    {
3743       char *str;
3744       int combined_type;
3745 
3746       /* Check that pasting onto an integer doesn't create a
3747        * non-integer, (that is, only digits can be
3748        * pasted. */
3749       if (token->type == INTEGER_STRING || token->type == INTEGER) {
3750          switch (other->type) {
3751          case INTEGER_STRING:
3752             if (other->value.str[0] < '0' || other->value.str[0] > '9')
3753                goto FAIL;
3754             break;
3755          case INTEGER:
3756             if (other->value.ival < 0)
3757                goto FAIL;
3758             break;
3759          default:
3760             goto FAIL;
3761          }
3762       }
3763 
3764       if (token->type == INTEGER)
3765          str = linear_asprintf(parser->linalloc, "%" PRIiMAX, token->value.ival);
3766       else
3767          str = linear_strdup(parser->linalloc, token->value.str);
3768 
3769       if (other->type == INTEGER)
3770          linear_asprintf_append(parser->linalloc, &str, "%" PRIiMAX, other->value.ival);
3771       else
3772          linear_strcat(parser->linalloc, &str, other->value.str);
3773 
3774       /* New token is same type as original token, unless we
3775        * started with an integer, in which case we will be
3776        * creating an integer-string. */
3777       combined_type = token->type;
3778       if (combined_type == INTEGER)
3779          combined_type = INTEGER_STRING;
3780 
3781       combined = _token_create_str (parser, combined_type, str);
3782       combined->location = token->location;
3783       return combined;
3784    }
3785 
3786     FAIL:
3787    glcpp_error (&token->location, parser, "");
3788    _mesa_string_buffer_append(parser->info_log, "Pasting \"");
3789    _token_print(parser->info_log, token);
3790    _mesa_string_buffer_append(parser->info_log, "\" and \"");
3791    _token_print(parser->info_log, other);
3792    _mesa_string_buffer_append(parser->info_log, "\" does not give a valid preprocessing token.\n");
3793 
3794    return token;
3795 }
3796 
3797 static void
_token_list_print(glcpp_parser_t * parser,token_list_t * list)3798 _token_list_print(glcpp_parser_t *parser, token_list_t *list)
3799 {
3800    token_node_t *node;
3801 
3802    if (list == NULL)
3803       return;
3804 
3805    for (node = list->head; node; node = node->next)
3806       _token_print(parser->output, node->token);
3807 }
3808 
3809 void
yyerror(YYLTYPE * locp,glcpp_parser_t * parser,const char * error)3810 yyerror(YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
3811 {
3812    glcpp_error(locp, parser, "%s", error);
3813 }
3814 
3815 static void
add_builtin_define(glcpp_parser_t * parser,const char * name,int value)3816 add_builtin_define(glcpp_parser_t *parser, const char *name, int value)
3817 {
3818    token_t *tok;
3819    token_list_t *list;
3820 
3821    tok = _token_create_ival (parser, INTEGER, value);
3822 
3823    list = _token_list_create(parser);
3824    _token_list_append(parser, list, tok);
3825    _define_object_macro(parser, NULL, name, list);
3826 }
3827 
3828 /* Initial output buffer size, 4096 minus ralloc() overhead. It was selected
3829  * to minimize total amount of allocated memory during shader-db run.
3830  */
3831 #define INITIAL_PP_OUTPUT_BUF_SIZE 4048
3832 
3833 glcpp_parser_t *
glcpp_parser_create(struct gl_context * gl_ctx,glcpp_extension_iterator extensions,void * state)3834 glcpp_parser_create(struct gl_context *gl_ctx,
3835                     glcpp_extension_iterator extensions, void *state)
3836 {
3837    glcpp_parser_t *parser;
3838 
3839    parser = ralloc (NULL, glcpp_parser_t);
3840 
3841    glcpp_lex_init_extra (parser, &parser->scanner);
3842    parser->defines = _mesa_hash_table_create(NULL, _mesa_hash_string,
3843                                              _mesa_key_string_equal);
3844    parser->linalloc = linear_alloc_parent(parser, 0);
3845    parser->active = NULL;
3846    parser->lexing_directive = 0;
3847    parser->lexing_version_directive = 0;
3848    parser->space_tokens = 1;
3849    parser->last_token_was_newline = 0;
3850    parser->last_token_was_space = 0;
3851    parser->first_non_space_token_this_line = 1;
3852    parser->newline_as_space = 0;
3853    parser->in_control_line = 0;
3854    parser->paren_count = 0;
3855    parser->commented_newlines = 0;
3856 
3857    parser->skip_stack = NULL;
3858    parser->skipping = 0;
3859 
3860    parser->lex_from_list = NULL;
3861    parser->lex_from_node = NULL;
3862 
3863    parser->output = _mesa_string_buffer_create(parser,
3864                                                INITIAL_PP_OUTPUT_BUF_SIZE);
3865    parser->info_log = _mesa_string_buffer_create(parser,
3866                                                  INITIAL_PP_OUTPUT_BUF_SIZE);
3867    parser->error = 0;
3868 
3869    parser->gl_ctx = gl_ctx;
3870    parser->extensions = extensions;
3871    parser->extension_list = &gl_ctx->Extensions;
3872    parser->state = state;
3873    parser->api = gl_ctx->API;
3874    parser->version = 0;
3875    parser->version_set = false;
3876 
3877    parser->has_new_line_number = 0;
3878    parser->new_line_number = 1;
3879    parser->has_new_source_number = 0;
3880    parser->new_source_number = 0;
3881 
3882    parser->is_gles = false;
3883 
3884    return parser;
3885 }
3886 
3887 void
glcpp_parser_destroy(glcpp_parser_t * parser)3888 glcpp_parser_destroy(glcpp_parser_t *parser)
3889 {
3890    glcpp_lex_destroy (parser->scanner);
3891    _mesa_hash_table_destroy(parser->defines, NULL);
3892    ralloc_free (parser);
3893 }
3894 
3895 typedef enum function_status
3896 {
3897    FUNCTION_STATUS_SUCCESS,
3898    FUNCTION_NOT_A_FUNCTION,
3899    FUNCTION_UNBALANCED_PARENTHESES
3900 } function_status_t;
3901 
3902 /* Find a set of function-like macro arguments by looking for a
3903  * balanced set of parentheses.
3904  *
3905  * When called, 'node' should be the opening-parenthesis token, (or
3906  * perhaps preceeding SPACE tokens). Upon successful return *last will
3907  * be the last consumed node, (corresponding to the closing right
3908  * parenthesis).
3909  *
3910  * Return values:
3911  *
3912  *   FUNCTION_STATUS_SUCCESS:
3913  *
3914  *      Successfully parsed a set of function arguments.
3915  *
3916  *   FUNCTION_NOT_A_FUNCTION:
3917  *
3918  *      Macro name not followed by a '('. This is not an error, but
3919  *      simply that the macro name should be treated as a non-macro.
3920  *
3921  *   FUNCTION_UNBALANCED_PARENTHESES
3922  *
3923  *      Macro name is not followed by a balanced set of parentheses.
3924  */
3925 static function_status_t
_arguments_parse(glcpp_parser_t * parser,argument_list_t * arguments,token_node_t * node,token_node_t ** last)3926 _arguments_parse(glcpp_parser_t *parser,
3927                  argument_list_t *arguments, token_node_t *node,
3928                  token_node_t **last)
3929 {
3930    token_list_t *argument;
3931    int paren_count;
3932 
3933    node = node->next;
3934 
3935    /* Ignore whitespace before first parenthesis. */
3936    while (node && node->token->type == SPACE)
3937       node = node->next;
3938 
3939    if (node == NULL || node->token->type != '(')
3940       return FUNCTION_NOT_A_FUNCTION;
3941 
3942    node = node->next;
3943 
3944    argument = _token_list_create (parser);
3945    _argument_list_append (parser, arguments, argument);
3946 
3947    for (paren_count = 1; node; node = node->next) {
3948       if (node->token->type == '(') {
3949          paren_count++;
3950       } else if (node->token->type == ')') {
3951          paren_count--;
3952          if (paren_count == 0)
3953             break;
3954       }
3955 
3956       if (node->token->type == ',' && paren_count == 1) {
3957          _token_list_trim_trailing_space (argument);
3958          argument = _token_list_create (parser);
3959          _argument_list_append (parser, arguments, argument);
3960       } else {
3961          if (argument->head == NULL) {
3962             /* Don't treat initial whitespace as part of the argument. */
3963             if (node->token->type == SPACE)
3964                continue;
3965          }
3966          _token_list_append(parser, argument, node->token);
3967       }
3968    }
3969 
3970    if (paren_count)
3971       return FUNCTION_UNBALANCED_PARENTHESES;
3972 
3973    *last = node;
3974 
3975    return FUNCTION_STATUS_SUCCESS;
3976 }
3977 
3978 static token_list_t *
_token_list_create_with_one_ival(glcpp_parser_t * parser,int type,int ival)3979 _token_list_create_with_one_ival(glcpp_parser_t *parser, int type, int ival)
3980 {
3981    token_list_t *list;
3982    token_t *node;
3983 
3984    list = _token_list_create(parser);
3985    node = _token_create_ival(parser, type, ival);
3986    _token_list_append(parser, list, node);
3987 
3988    return list;
3989 }
3990 
3991 static token_list_t *
_token_list_create_with_one_space(glcpp_parser_t * parser)3992 _token_list_create_with_one_space(glcpp_parser_t *parser)
3993 {
3994    return _token_list_create_with_one_ival(parser, SPACE, SPACE);
3995 }
3996 
3997 static token_list_t *
_token_list_create_with_one_integer(glcpp_parser_t * parser,int ival)3998 _token_list_create_with_one_integer(glcpp_parser_t *parser, int ival)
3999 {
4000    return _token_list_create_with_one_ival(parser, INTEGER, ival);
4001 }
4002 
4003 /* Evaluate a DEFINED token node (based on subsequent tokens in the list).
4004  *
4005  * Note: This function must only be called when "node" is a DEFINED token,
4006  * (and will abort with an assertion failure otherwise).
4007  *
4008  * If "node" is followed, (ignoring any SPACE tokens), by an IDENTIFIER token
4009  * (optionally preceded and followed by '(' and ')' tokens) then the following
4010  * occurs:
4011  *
4012  *   If the identifier is a defined macro, this function returns 1.
4013  *
4014  *   If the identifier is not a defined macro, this function returns 0.
4015  *
4016  *   In either case, *last will be updated to the last node in the list
4017  *   consumed by the evaluation, (either the token of the identifier or the
4018  *   token of the closing parenthesis).
4019  *
4020  * In all other cases, (such as "node is the final node of the list", or
4021  * "missing closing parenthesis", etc.), this function generates a
4022  * preprocessor error, returns -1 and *last will not be set.
4023  */
4024 static int
_glcpp_parser_evaluate_defined(glcpp_parser_t * parser,token_node_t * node,token_node_t ** last)4025 _glcpp_parser_evaluate_defined(glcpp_parser_t *parser, token_node_t *node,
4026                                token_node_t **last)
4027 {
4028    token_node_t *argument, *defined = node;
4029 
4030    assert(node->token->type == DEFINED);
4031 
4032    node = node->next;
4033 
4034    /* Ignore whitespace after DEFINED token. */
4035    while (node && node->token->type == SPACE)
4036       node = node->next;
4037 
4038    if (node == NULL)
4039       goto FAIL;
4040 
4041    if (node->token->type == IDENTIFIER || node->token->type == OTHER) {
4042       argument = node;
4043    } else if (node->token->type == '(') {
4044       node = node->next;
4045 
4046       /* Ignore whitespace after '(' token. */
4047       while (node && node->token->type == SPACE)
4048          node = node->next;
4049 
4050       if (node == NULL || (node->token->type != IDENTIFIER &&
4051                            node->token->type != OTHER)) {
4052          goto FAIL;
4053       }
4054 
4055       argument = node;
4056 
4057       node = node->next;
4058 
4059       /* Ignore whitespace after identifier, before ')' token. */
4060       while (node && node->token->type == SPACE)
4061          node = node->next;
4062 
4063       if (node == NULL || node->token->type != ')')
4064          goto FAIL;
4065    } else {
4066       goto FAIL;
4067    }
4068 
4069    *last = node;
4070 
4071    return _mesa_hash_table_search(parser->defines,
4072                                   argument->token->value.str) ? 1 : 0;
4073 
4074 FAIL:
4075    glcpp_error (&defined->token->location, parser,
4076                 "\"defined\" not followed by an identifier");
4077    return -1;
4078 }
4079 
4080 /* Evaluate all DEFINED nodes in a given list, modifying the list in place.
4081  */
4082 static void
_glcpp_parser_evaluate_defined_in_list(glcpp_parser_t * parser,token_list_t * list)4083 _glcpp_parser_evaluate_defined_in_list(glcpp_parser_t *parser,
4084                                        token_list_t *list)
4085 {
4086    token_node_t *node, *node_prev, *replacement, *last = NULL;
4087    int value;
4088 
4089    if (list == NULL)
4090       return;
4091 
4092    node_prev = NULL;
4093    node = list->head;
4094 
4095    while (node) {
4096 
4097       if (node->token->type != DEFINED)
4098          goto NEXT;
4099 
4100       value = _glcpp_parser_evaluate_defined (parser, node, &last);
4101       if (value == -1)
4102          goto NEXT;
4103 
4104       replacement = linear_alloc_child(parser->linalloc, sizeof(token_node_t));
4105       replacement->token = _token_create_ival (parser, INTEGER, value);
4106 
4107       /* Splice replacement node into list, replacing from "node"
4108        * through "last". */
4109       if (node_prev)
4110          node_prev->next = replacement;
4111       else
4112          list->head = replacement;
4113       replacement->next = last->next;
4114       if (last == list->tail)
4115          list->tail = replacement;
4116 
4117       node = replacement;
4118 
4119    NEXT:
4120       node_prev = node;
4121       node = node->next;
4122    }
4123 }
4124 
4125 /* Perform macro expansion on 'list', placing the resulting tokens
4126  * into a new list which is initialized with a first token of type
4127  * 'head_token_type'. Then begin lexing from the resulting list,
4128  * (return to the current lexing source when this list is exhausted).
4129  *
4130  * See the documentation of _glcpp_parser_expand_token_list for a description
4131  * of the "mode" parameter.
4132  */
4133 static void
_glcpp_parser_expand_and_lex_from(glcpp_parser_t * parser,int head_token_type,token_list_t * list,expansion_mode_t mode)4134 _glcpp_parser_expand_and_lex_from(glcpp_parser_t *parser, int head_token_type,
4135                                   token_list_t *list, expansion_mode_t mode)
4136 {
4137    token_list_t *expanded;
4138    token_t *token;
4139 
4140    expanded = _token_list_create (parser);
4141    token = _token_create_ival (parser, head_token_type, head_token_type);
4142    _token_list_append (parser, expanded, token);
4143    _glcpp_parser_expand_token_list (parser, list, mode);
4144    _token_list_append_list (expanded, list);
4145    glcpp_parser_lex_from (parser, expanded);
4146 }
4147 
4148 static void
_glcpp_parser_apply_pastes(glcpp_parser_t * parser,token_list_t * list)4149 _glcpp_parser_apply_pastes(glcpp_parser_t *parser, token_list_t *list)
4150 {
4151    token_node_t *node;
4152 
4153    node = list->head;
4154    while (node) {
4155       token_node_t *next_non_space;
4156 
4157       /* Look ahead for a PASTE token, skipping space. */
4158       next_non_space = node->next;
4159       while (next_non_space && next_non_space->token->type == SPACE)
4160          next_non_space = next_non_space->next;
4161 
4162       if (next_non_space == NULL)
4163          break;
4164 
4165       if (next_non_space->token->type != PASTE) {
4166          node = next_non_space;
4167          continue;
4168       }
4169 
4170       /* Now find the next non-space token after the PASTE. */
4171       next_non_space = next_non_space->next;
4172       while (next_non_space && next_non_space->token->type == SPACE)
4173          next_non_space = next_non_space->next;
4174 
4175       if (next_non_space == NULL) {
4176          yyerror(&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
4177          return;
4178       }
4179 
4180       node->token = _token_paste(parser, node->token, next_non_space->token);
4181       node->next = next_non_space->next;
4182       if (next_non_space == list->tail)
4183          list->tail = node;
4184    }
4185 
4186    list->non_space_tail = list->tail;
4187 }
4188 
4189 /* This is a helper function that's essentially part of the
4190  * implementation of _glcpp_parser_expand_node. It shouldn't be called
4191  * except for by that function.
4192  *
4193  * Returns NULL if node is a simple token with no expansion, (that is,
4194  * although 'node' corresponds to an identifier defined as a
4195  * function-like macro, it is not followed with a parenthesized
4196  * argument list).
4197  *
4198  * Compute the complete expansion of node (which is a function-like
4199  * macro) and subsequent nodes which are arguments.
4200  *
4201  * Returns the token list that results from the expansion and sets
4202  * *last to the last node in the list that was consumed by the
4203  * expansion. Specifically, *last will be set as follows: as the
4204  * token of the closing right parenthesis.
4205  *
4206  * See the documentation of _glcpp_parser_expand_token_list for a description
4207  * of the "mode" parameter.
4208  */
4209 static token_list_t *
_glcpp_parser_expand_function(glcpp_parser_t * parser,token_node_t * node,token_node_t ** last,expansion_mode_t mode)4210 _glcpp_parser_expand_function(glcpp_parser_t *parser, token_node_t *node,
4211                               token_node_t **last, expansion_mode_t mode)
4212 {
4213    struct hash_entry *entry;
4214    macro_t *macro;
4215    const char *identifier;
4216    argument_list_t *arguments;
4217    function_status_t status;
4218    token_list_t *substituted;
4219    int parameter_index;
4220 
4221    identifier = node->token->value.str;
4222 
4223    entry = _mesa_hash_table_search(parser->defines, identifier);
4224    macro = entry ? entry->data : NULL;
4225 
4226    assert(macro->is_function);
4227 
4228    arguments = _argument_list_create(parser);
4229    status = _arguments_parse(parser, arguments, node, last);
4230 
4231    switch (status) {
4232    case FUNCTION_STATUS_SUCCESS:
4233       break;
4234    case FUNCTION_NOT_A_FUNCTION:
4235       return NULL;
4236    case FUNCTION_UNBALANCED_PARENTHESES:
4237       glcpp_error(&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
4238       return NULL;
4239    }
4240 
4241    /* Replace a macro defined as empty with a SPACE token. */
4242    if (macro->replacements == NULL) {
4243       return _token_list_create_with_one_space(parser);
4244    }
4245 
4246    if (!((_argument_list_length (arguments) ==
4247           _string_list_length (macro->parameters)) ||
4248          (_string_list_length (macro->parameters) == 0 &&
4249           _argument_list_length (arguments) == 1 &&
4250           arguments->head->argument->head == NULL))) {
4251       glcpp_error(&node->token->location, parser,
4252                   "Error: macro %s invoked with %d arguments (expected %d)\n",
4253                   identifier, _argument_list_length (arguments),
4254                   _string_list_length(macro->parameters));
4255       return NULL;
4256    }
4257 
4258    /* Perform argument substitution on the replacement list. */
4259    substituted = _token_list_create(parser);
4260 
4261    for (node = macro->replacements->head; node; node = node->next) {
4262       if (node->token->type == IDENTIFIER &&
4263           _string_list_contains(macro->parameters, node->token->value.str,
4264                                 &parameter_index)) {
4265          token_list_t *argument;
4266          argument = _argument_list_member_at(arguments, parameter_index);
4267          /* Before substituting, we expand the argument tokens, or append a
4268           * placeholder token for an empty argument. */
4269          if (argument->head) {
4270             token_list_t *expanded_argument;
4271             expanded_argument = _token_list_copy(parser, argument);
4272             _glcpp_parser_expand_token_list(parser, expanded_argument, mode);
4273             _token_list_append_list(substituted, expanded_argument);
4274          } else {
4275             token_t *new_token;
4276 
4277             new_token = _token_create_ival(parser, PLACEHOLDER,
4278                                            PLACEHOLDER);
4279             _token_list_append(parser, substituted, new_token);
4280          }
4281       } else {
4282          _token_list_append(parser, substituted, node->token);
4283       }
4284    }
4285 
4286    /* After argument substitution, and before further expansion
4287     * below, implement token pasting. */
4288 
4289    _token_list_trim_trailing_space(substituted);
4290 
4291    _glcpp_parser_apply_pastes(parser, substituted);
4292 
4293    return substituted;
4294 }
4295 
4296 /* Compute the complete expansion of node, (and subsequent nodes after
4297  * 'node' in the case that 'node' is a function-like macro and
4298  * subsequent nodes are arguments).
4299  *
4300  * Returns NULL if node is a simple token with no expansion.
4301  *
4302  * Otherwise, returns the token list that results from the expansion
4303  * and sets *last to the last node in the list that was consumed by
4304  * the expansion. Specifically, *last will be set as follows:
4305  *
4306  *   As 'node' in the case of object-like macro expansion.
4307  *
4308  *   As the token of the closing right parenthesis in the case of
4309  *   function-like macro expansion.
4310  *
4311  * See the documentation of _glcpp_parser_expand_token_list for a description
4312  * of the "mode" parameter.
4313  */
4314 static token_list_t *
_glcpp_parser_expand_node(glcpp_parser_t * parser,token_node_t * node,token_node_t ** last,expansion_mode_t mode,int line)4315 _glcpp_parser_expand_node(glcpp_parser_t *parser, token_node_t *node,
4316                           token_node_t **last, expansion_mode_t mode,
4317                           int line)
4318 {
4319    token_t *token = node->token;
4320    const char *identifier;
4321    struct hash_entry *entry;
4322    macro_t *macro;
4323 
4324    /* We only expand identifiers */
4325    if (token->type != IDENTIFIER) {
4326       return NULL;
4327    }
4328 
4329    *last = node;
4330    identifier = token->value.str;
4331 
4332    /* Special handling for __LINE__ and __FILE__, (not through
4333     * the hash table). */
4334    if (*identifier == '_') {
4335       if (strcmp(identifier, "__LINE__") == 0)
4336          return _token_list_create_with_one_integer(parser, line);
4337 
4338       if (strcmp(identifier, "__FILE__") == 0)
4339          return _token_list_create_with_one_integer(parser,
4340                                                     node->token->location.source);
4341    }
4342 
4343    /* Look up this identifier in the hash table. */
4344    entry = _mesa_hash_table_search(parser->defines, identifier);
4345    macro = entry ? entry->data : NULL;
4346 
4347    /* Not a macro, so no expansion needed. */
4348    if (macro == NULL)
4349       return NULL;
4350 
4351    /* Finally, don't expand this macro if we're already actively
4352     * expanding it, (to avoid infinite recursion). */
4353    if (_parser_active_list_contains (parser, identifier)) {
4354       /* We change the token type here from IDENTIFIER to OTHER to prevent any
4355        * future expansion of this unexpanded token. */
4356       char *str;
4357       token_list_t *expansion;
4358       token_t *final;
4359 
4360       str = linear_strdup(parser->linalloc, token->value.str);
4361       final = _token_create_str(parser, OTHER, str);
4362       expansion = _token_list_create(parser);
4363       _token_list_append(parser, expansion, final);
4364       return expansion;
4365    }
4366 
4367    if (! macro->is_function) {
4368       token_list_t *replacement;
4369 
4370       /* Replace a macro defined as empty with a SPACE token. */
4371       if (macro->replacements == NULL)
4372          return _token_list_create_with_one_space(parser);
4373 
4374       replacement = _token_list_copy(parser, macro->replacements);
4375       _glcpp_parser_apply_pastes(parser, replacement);
4376       return replacement;
4377    }
4378 
4379    return _glcpp_parser_expand_function(parser, node, last, mode);
4380 }
4381 
4382 /* Push a new identifier onto the parser's active list.
4383  *
4384  * Here, 'marker' is the token node that appears in the list after the
4385  * expansion of 'identifier'. That is, when the list iterator begins
4386  * examining 'marker', then it is time to pop this node from the
4387  * active stack.
4388  */
4389 static void
_parser_active_list_push(glcpp_parser_t * parser,const char * identifier,token_node_t * marker)4390 _parser_active_list_push(glcpp_parser_t *parser, const char *identifier,
4391                          token_node_t *marker)
4392 {
4393    active_list_t *node;
4394 
4395    node = linear_alloc_child(parser->linalloc, sizeof(active_list_t));
4396    node->identifier = linear_strdup(parser->linalloc, identifier);
4397    node->marker = marker;
4398    node->next = parser->active;
4399 
4400    parser->active = node;
4401 }
4402 
4403 static void
_parser_active_list_pop(glcpp_parser_t * parser)4404 _parser_active_list_pop(glcpp_parser_t *parser)
4405 {
4406    active_list_t *node = parser->active;
4407 
4408    if (node == NULL) {
4409       parser->active = NULL;
4410       return;
4411    }
4412 
4413    node = parser->active->next;
4414    parser->active = node;
4415 }
4416 
4417 static int
_parser_active_list_contains(glcpp_parser_t * parser,const char * identifier)4418 _parser_active_list_contains(glcpp_parser_t *parser, const char *identifier)
4419 {
4420    active_list_t *node;
4421 
4422    if (parser->active == NULL)
4423       return 0;
4424 
4425    for (node = parser->active; node; node = node->next)
4426       if (strcmp(node->identifier, identifier) == 0)
4427          return 1;
4428 
4429    return 0;
4430 }
4431 
4432 /* Walk over the token list replacing nodes with their expansion.
4433  * Whenever nodes are expanded the walking will walk over the new
4434  * nodes, continuing to expand as necessary. The results are placed in
4435  * 'list' itself.
4436  *
4437  * The "mode" argument controls the handling of any DEFINED tokens that
4438  * result from expansion as follows:
4439  *
4440  *   EXPANSION_MODE_IGNORE_DEFINED: Any resulting DEFINED tokens will be
4441  *      left in the final list, unevaluated. This is the correct mode
4442  *      for expanding any list in any context other than a
4443  *      preprocessor conditional, (#if or #elif).
4444  *
4445  *   EXPANSION_MODE_EVALUATE_DEFINED: Any resulting DEFINED tokens will be
4446  *      evaluated to 0 or 1 tokens depending on whether the following
4447  *      token is the name of a defined macro. If the DEFINED token is
4448  *      not followed by an (optionally parenthesized) identifier, then
4449  *      an error will be generated. This the correct mode for
4450  *      expanding any list in the context of a preprocessor
4451  *      conditional, (#if or #elif).
4452  */
4453 static void
_glcpp_parser_expand_token_list(glcpp_parser_t * parser,token_list_t * list,expansion_mode_t mode)4454 _glcpp_parser_expand_token_list(glcpp_parser_t *parser, token_list_t *list,
4455                                 expansion_mode_t mode)
4456 {
4457    token_node_t *node_prev;
4458    token_node_t *node, *last = NULL;
4459    token_list_t *expansion;
4460    active_list_t *active_initial = parser->active;
4461    int line;
4462 
4463    if (list == NULL)
4464       return;
4465 
4466    _token_list_trim_trailing_space (list);
4467 
4468    line = list->tail->token->location.last_line;
4469 
4470    node_prev = NULL;
4471    node = list->head;
4472 
4473    if (mode == EXPANSION_MODE_EVALUATE_DEFINED)
4474       _glcpp_parser_evaluate_defined_in_list (parser, list);
4475 
4476    while (node) {
4477 
4478       while (parser->active && parser->active->marker == node)
4479          _parser_active_list_pop (parser);
4480 
4481       expansion = _glcpp_parser_expand_node (parser, node, &last, mode, line);
4482       if (expansion) {
4483          token_node_t *n;
4484 
4485          if (mode == EXPANSION_MODE_EVALUATE_DEFINED) {
4486             _glcpp_parser_evaluate_defined_in_list (parser, expansion);
4487          }
4488 
4489          for (n = node; n != last->next; n = n->next)
4490             while (parser->active && parser->active->marker == n) {
4491                _parser_active_list_pop (parser);
4492             }
4493 
4494          _parser_active_list_push(parser, node->token->value.str, last->next);
4495 
4496          /* Splice expansion into list, supporting a simple deletion if the
4497           * expansion is empty.
4498           */
4499          if (expansion->head) {
4500             if (node_prev)
4501                node_prev->next = expansion->head;
4502             else
4503                list->head = expansion->head;
4504             expansion->tail->next = last->next;
4505             if (last == list->tail)
4506                list->tail = expansion->tail;
4507          } else {
4508             if (node_prev)
4509                node_prev->next = last->next;
4510             else
4511                list->head = last->next;
4512             if (last == list->tail)
4513                list->tail = NULL;
4514          }
4515       } else {
4516          node_prev = node;
4517       }
4518       node = node_prev ? node_prev->next : list->head;
4519    }
4520 
4521    /* Remove any lingering effects of this invocation on the
4522     * active list. That is, pop until the list looks like it did
4523     * at the beginning of this function. */
4524    while (parser->active && parser->active != active_initial)
4525       _parser_active_list_pop (parser);
4526 
4527    list->non_space_tail = list->tail;
4528 }
4529 
4530 void
_glcpp_parser_print_expanded_token_list(glcpp_parser_t * parser,token_list_t * list)4531 _glcpp_parser_print_expanded_token_list(glcpp_parser_t *parser,
4532                                         token_list_t *list)
4533 {
4534    if (list == NULL)
4535       return;
4536 
4537    _glcpp_parser_expand_token_list (parser, list, EXPANSION_MODE_IGNORE_DEFINED);
4538 
4539    _token_list_trim_trailing_space (list);
4540 
4541    _token_list_print (parser, list);
4542 }
4543 
4544 static void
_check_for_reserved_macro_name(glcpp_parser_t * parser,YYLTYPE * loc,const char * identifier)4545 _check_for_reserved_macro_name(glcpp_parser_t *parser, YYLTYPE *loc,
4546                                const char *identifier)
4547 {
4548    /* Section 3.3 (Preprocessor) of the GLSL 1.30 spec (and later) and
4549     * the GLSL ES spec (all versions) say:
4550     *
4551     *     "All macro names containing two consecutive underscores ( __ )
4552     *     are reserved for future use as predefined macro names. All
4553     *     macro names prefixed with "GL_" ("GL" followed by a single
4554     *     underscore) are also reserved."
4555     *
4556     * The intention is that names containing __ are reserved for internal
4557     * use by the implementation, and names prefixed with GL_ are reserved
4558     * for use by Khronos.  Since every extension adds a name prefixed
4559     * with GL_ (i.e., the name of the extension), that should be an
4560     * error.  Names simply containing __ are dangerous to use, but should
4561     * be allowed.
4562     *
4563     * A future version of the GLSL specification will clarify this.
4564     */
4565    if (strstr(identifier, "__")) {
4566       glcpp_warning(loc, parser, "Macro names containing \"__\" are reserved "
4567                     "for use by the implementation.\n");
4568    }
4569    if (strncmp(identifier, "GL_", 3) == 0) {
4570       glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
4571    }
4572    if (strcmp(identifier, "defined") == 0) {
4573       glcpp_error (loc, parser, "\"defined\" cannot be used as a macro name");
4574    }
4575 }
4576 
4577 static int
_macro_equal(macro_t * a,macro_t * b)4578 _macro_equal(macro_t *a, macro_t *b)
4579 {
4580    if (a->is_function != b->is_function)
4581       return 0;
4582 
4583    if (a->is_function) {
4584       if (! _string_list_equal (a->parameters, b->parameters))
4585          return 0;
4586    }
4587 
4588    return _token_list_equal_ignoring_space(a->replacements, b->replacements);
4589 }
4590 
4591 void
_define_object_macro(glcpp_parser_t * parser,YYLTYPE * loc,const char * identifier,token_list_t * replacements)4592 _define_object_macro(glcpp_parser_t *parser, YYLTYPE *loc,
4593                      const char *identifier, token_list_t *replacements)
4594 {
4595    macro_t *macro, *previous;
4596    struct hash_entry *entry;
4597 
4598    /* We define pre-defined macros before we've started parsing the actual
4599     * file. So if there's no location defined yet, that's what were doing and
4600     * we don't want to generate an error for using the reserved names. */
4601    if (loc != NULL)
4602       _check_for_reserved_macro_name(parser, loc, identifier);
4603 
4604    macro = linear_alloc_child(parser->linalloc, sizeof(macro_t));
4605 
4606    macro->is_function = 0;
4607    macro->parameters = NULL;
4608    macro->identifier = linear_strdup(parser->linalloc, identifier);
4609    macro->replacements = replacements;
4610 
4611    entry = _mesa_hash_table_search(parser->defines, identifier);
4612    previous = entry ? entry->data : NULL;
4613    if (previous) {
4614       if (_macro_equal (macro, previous)) {
4615          return;
4616       }
4617       glcpp_error (loc, parser, "Redefinition of macro %s\n",  identifier);
4618    }
4619 
4620    _mesa_hash_table_insert (parser->defines, identifier, macro);
4621 }
4622 
4623 void
_define_function_macro(glcpp_parser_t * parser,YYLTYPE * loc,const char * identifier,string_list_t * parameters,token_list_t * replacements)4624 _define_function_macro(glcpp_parser_t *parser, YYLTYPE *loc,
4625                        const char *identifier, string_list_t *parameters,
4626                        token_list_t *replacements)
4627 {
4628    macro_t *macro, *previous;
4629    struct hash_entry *entry;
4630    const char *dup;
4631 
4632    _check_for_reserved_macro_name(parser, loc, identifier);
4633 
4634         /* Check for any duplicate parameter names. */
4635    if ((dup = _string_list_has_duplicate (parameters)) != NULL) {
4636       glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"", dup);
4637    }
4638 
4639    macro = linear_alloc_child(parser->linalloc, sizeof(macro_t));
4640 
4641    macro->is_function = 1;
4642    macro->parameters = parameters;
4643    macro->identifier = linear_strdup(parser->linalloc, identifier);
4644    macro->replacements = replacements;
4645 
4646    entry = _mesa_hash_table_search(parser->defines, identifier);
4647    previous = entry ? entry->data : NULL;
4648    if (previous) {
4649       if (_macro_equal (macro, previous)) {
4650          return;
4651       }
4652       glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
4653    }
4654 
4655    _mesa_hash_table_insert(parser->defines, identifier, macro);
4656 }
4657 
4658 static int
glcpp_parser_lex(YYSTYPE * yylval,YYLTYPE * yylloc,glcpp_parser_t * parser)4659 glcpp_parser_lex(YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
4660 {
4661    token_node_t *node;
4662    int ret;
4663 
4664    if (parser->lex_from_list == NULL) {
4665       ret = glcpp_lex(yylval, yylloc, parser->scanner);
4666 
4667       /* XXX: This ugly block of code exists for the sole
4668        * purpose of converting a NEWLINE token into a SPACE
4669        * token, but only in the case where we have seen a
4670        * function-like macro name, but have not yet seen its
4671        * closing parenthesis.
4672        *
4673        * There's perhaps a more compact way to do this with
4674        * mid-rule actions in the grammar.
4675        *
4676        * I'm definitely not pleased with the complexity of
4677        * this code here.
4678        */
4679       if (parser->newline_as_space) {
4680          if (ret == '(') {
4681             parser->paren_count++;
4682          } else if (ret == ')') {
4683             parser->paren_count--;
4684             if (parser->paren_count == 0)
4685                parser->newline_as_space = 0;
4686          } else if (ret == NEWLINE) {
4687             ret = SPACE;
4688          } else if (ret != SPACE) {
4689             if (parser->paren_count == 0)
4690                parser->newline_as_space = 0;
4691          }
4692       } else if (parser->in_control_line) {
4693          if (ret == NEWLINE)
4694             parser->in_control_line = 0;
4695       }
4696       else if (ret == DEFINE_TOKEN || ret == UNDEF || ret == IF ||
4697                ret == IFDEF || ret == IFNDEF || ret == ELIF || ret == ELSE ||
4698                ret == ENDIF || ret == HASH_TOKEN) {
4699          parser->in_control_line = 1;
4700       } else if (ret == IDENTIFIER) {
4701          struct hash_entry *entry = _mesa_hash_table_search(parser->defines,
4702                                                             yylval->str);
4703          macro_t *macro = entry ? entry->data : NULL;
4704          if (macro && macro->is_function) {
4705             parser->newline_as_space = 1;
4706             parser->paren_count = 0;
4707          }
4708       }
4709 
4710       return ret;
4711    }
4712 
4713    node = parser->lex_from_node;
4714 
4715    if (node == NULL) {
4716       parser->lex_from_list = NULL;
4717       return NEWLINE;
4718    }
4719 
4720    *yylval = node->token->value;
4721    ret = node->token->type;
4722 
4723    parser->lex_from_node = node->next;
4724 
4725    return ret;
4726 }
4727 
4728 static void
glcpp_parser_lex_from(glcpp_parser_t * parser,token_list_t * list)4729 glcpp_parser_lex_from(glcpp_parser_t *parser, token_list_t *list)
4730 {
4731    token_node_t *node;
4732 
4733    assert (parser->lex_from_list == NULL);
4734 
4735    /* Copy list, eliminating any space tokens. */
4736    parser->lex_from_list = _token_list_create (parser);
4737 
4738    for (node = list->head; node; node = node->next) {
4739       if (node->token->type == SPACE)
4740          continue;
4741       _token_list_append (parser,  parser->lex_from_list, node->token);
4742    }
4743 
4744    parser->lex_from_node = parser->lex_from_list->head;
4745 
4746    /* It's possible the list consisted of nothing but whitespace. */
4747    if (parser->lex_from_node == NULL) {
4748       parser->lex_from_list = NULL;
4749    }
4750 }
4751 
4752 static void
_glcpp_parser_skip_stack_push_if(glcpp_parser_t * parser,YYLTYPE * loc,int condition)4753 _glcpp_parser_skip_stack_push_if(glcpp_parser_t *parser, YYLTYPE *loc,
4754                                  int condition)
4755 {
4756    skip_type_t current = SKIP_NO_SKIP;
4757    skip_node_t *node;
4758 
4759    if (parser->skip_stack)
4760       current = parser->skip_stack->type;
4761 
4762    node = linear_alloc_child(parser->linalloc, sizeof(skip_node_t));
4763    node->loc = *loc;
4764 
4765    if (current == SKIP_NO_SKIP) {
4766       if (condition)
4767          node->type = SKIP_NO_SKIP;
4768       else
4769          node->type = SKIP_TO_ELSE;
4770    } else {
4771       node->type = SKIP_TO_ENDIF;
4772    }
4773 
4774    node->has_else = false;
4775    node->next = parser->skip_stack;
4776    parser->skip_stack = node;
4777 }
4778 
4779 static void
_glcpp_parser_skip_stack_change_if(glcpp_parser_t * parser,YYLTYPE * loc,const char * type,int condition)4780 _glcpp_parser_skip_stack_change_if(glcpp_parser_t *parser, YYLTYPE *loc,
4781                                    const char *type, int condition)
4782 {
4783    if (parser->skip_stack == NULL) {
4784       glcpp_error (loc, parser, "#%s without #if\n", type);
4785       return;
4786    }
4787 
4788    if (parser->skip_stack->type == SKIP_TO_ELSE) {
4789       if (condition)
4790          parser->skip_stack->type = SKIP_NO_SKIP;
4791    } else {
4792       parser->skip_stack->type = SKIP_TO_ENDIF;
4793    }
4794 }
4795 
4796 static void
_glcpp_parser_skip_stack_pop(glcpp_parser_t * parser,YYLTYPE * loc)4797 _glcpp_parser_skip_stack_pop(glcpp_parser_t *parser, YYLTYPE *loc)
4798 {
4799    skip_node_t *node;
4800 
4801    if (parser->skip_stack == NULL) {
4802       glcpp_error (loc, parser, "#endif without #if\n");
4803       return;
4804    }
4805 
4806    node = parser->skip_stack;
4807    parser->skip_stack = node->next;
4808 }
4809 
4810 static void
_glcpp_parser_handle_version_declaration(glcpp_parser_t * parser,intmax_t version,const char * identifier,bool explicitly_set)4811 _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t version,
4812                                          const char *identifier,
4813                                          bool explicitly_set)
4814 {
4815    if (parser->version_set)
4816       return;
4817 
4818    parser->version = version;
4819    parser->version_set = true;
4820 
4821    add_builtin_define (parser, "__VERSION__", version);
4822 
4823    parser->is_gles = (version == 100) ||
4824                      (identifier && (strcmp(identifier, "es") == 0));
4825    bool is_compat = version >= 150 && identifier &&
4826                     strcmp(identifier, "compatibility") == 0;
4827 
4828    /* Add pre-defined macros. */
4829    if (parser->is_gles)
4830       add_builtin_define(parser, "GL_ES", 1);
4831    else if (is_compat)
4832       add_builtin_define(parser, "GL_compatibility_profile", 1);
4833    else if (version >= 150)
4834       add_builtin_define(parser, "GL_core_profile", 1);
4835 
4836    /* Currently, all ES2/ES3 implementations support highp in the
4837     * fragment shader, so we always define this macro in ES2/ES3.
4838     * If we ever get a driver that doesn't support highp, we'll
4839     * need to add a flag to the gl_context and check that here.
4840     */
4841    if (version >= 130 || parser->is_gles)
4842       add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
4843 
4844    /* Add all the extension macros available in this context */
4845    if (parser->extensions)
4846       parser->extensions(parser->state, add_builtin_define, parser,
4847                          version, parser->is_gles);
4848 
4849    if (parser->extension_list) {
4850       /* If MESA_shader_integer_functions is supported, then the building
4851        * blocks required for the 64x64 => 64 multiply exist.  Add defines for
4852        * those functions so that they can be tested.
4853        */
4854       if (parser->extension_list->MESA_shader_integer_functions) {
4855          add_builtin_define(parser, "__have_builtin_builtin_sign64", 1);
4856          add_builtin_define(parser, "__have_builtin_builtin_umul64", 1);
4857          add_builtin_define(parser, "__have_builtin_builtin_udiv64", 1);
4858          add_builtin_define(parser, "__have_builtin_builtin_umod64", 1);
4859          add_builtin_define(parser, "__have_builtin_builtin_idiv64", 1);
4860          add_builtin_define(parser, "__have_builtin_builtin_imod64", 1);
4861       }
4862    }
4863 
4864    if (explicitly_set) {
4865       _mesa_string_buffer_printf(parser->output,
4866                                  "#version %" PRIiMAX "%s%s", version,
4867                                  identifier ? " " : "",
4868                                  identifier ? identifier : "");
4869    }
4870 }
4871 
4872 /* GLSL version if no version is explicitly specified. */
4873 #define IMPLICIT_GLSL_VERSION 110
4874 
4875 /* GLSL ES version if no version is explicitly specified. */
4876 #define IMPLICIT_GLSL_ES_VERSION 100
4877 
4878 void
glcpp_parser_resolve_implicit_version(glcpp_parser_t * parser)4879 glcpp_parser_resolve_implicit_version(glcpp_parser_t *parser)
4880 {
4881    int language_version = parser->api == API_OPENGLES2 ?
4882                           IMPLICIT_GLSL_ES_VERSION : IMPLICIT_GLSL_VERSION;
4883 
4884    _glcpp_parser_handle_version_declaration(parser, language_version,
4885                                             NULL, false);
4886 }
4887 
4888 static void
glcpp_parser_copy_defines(const void * key,void * data,void * closure)4889 glcpp_parser_copy_defines(const void *key, void *data, void *closure)
4890 {
4891    struct define_include *di = (struct define_include *) closure;
4892    macro_t *macro = (macro_t *) data;
4893 
4894    /* If we hit an error on a previous pass, just return */
4895    if (di->parser->error)
4896       return;
4897 
4898    const char *identifier =  macro->identifier;
4899    struct hash_entry *entry = _mesa_hash_table_search(di->parser->defines,
4900                                                       identifier);
4901 
4902    macro_t *previous = entry ? entry->data : NULL;
4903    if (previous) {
4904       if (_macro_equal(macro, previous)) {
4905          return;
4906       }
4907       glcpp_error(di->loc, di->parser, "Redefinition of macro %s\n",
4908                   identifier);
4909    }
4910 
4911    _mesa_hash_table_insert(di->parser->defines, identifier, macro);
4912 }
4913