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