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