Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

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