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