~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/glsl/glcpp/glcpp-parse.c

  • Committer: Package Import Robot
  • Author(s): Bryce Harrington
  • Date: 2012-03-13 14:26:30 UTC
  • Revision ID: package-import@ubuntu.com-20120313142630-8600y32xskf42sou
Tags: 8.0.1-0ubuntu4
Add 117_i965_only_set_last_render_target_last.patch: Fix GPU lockups
on Intel when playing certain games (Ski Challenge 2012, OilRush,
Trine, and possibly others).  These games use MRT (multiple render
targets), and mesa was not setting the Last Render Target Select
properly.  Cherrypick from upstream, will be included in the upcoming
8.0.2 release.
(LP: #899159)

Show diffs side-by-side

added added

removed removed

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