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