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