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