glsl2: Add missing include of string.h
[mesa/nouveau-pmpeg.git] / src / glsl / glcpp / glcpp-parse.c
bloba4d46042fffe8574e0c9d063b3c74cd2837988de
2 /* A Bison parser, made by GNU Bison 2.4.1. */
4 /* Skeleton implementation for Bison's Yacc-like parsers in C
6 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
7 Free Software Foundation, Inc.
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.
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.
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/>. */
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.
32 This special exception was added by the Free Software Foundation in
33 version 2.2 of Bison. */
35 /* C LALR(1) parser skeleton written by Richard Stallman, by
36 simplifying the original so-called "semantic" parser. */
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. */
45 /* Identify Bison output. */
46 #define YYBISON 1
48 /* Bison version. */
49 #define YYBISON_VERSION "2.4.1"
51 /* Skeleton name. */
52 #define YYSKELETON_NAME "yacc.c"
54 /* Pure parsers. */
55 #define YYPURE 1
57 /* Push parsers. */
58 #define YYPUSH 0
60 /* Pull parsers. */
61 #define YYPULL 1
63 /* Using locations. */
64 #define YYLSP_NEEDED 1
68 /* Copy the first part of user declarations. */
70 /* Line 189 of yacc.c */
71 #line 1 "glcpp/glcpp-parse.y"
74 * Copyright © 2010 Intel Corporation
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:
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.
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.
96 #include <stdio.h>
97 #include <stdlib.h>
98 #include <string.h>
99 #include <assert.h>
100 #include <inttypes.h>
102 #include "glcpp.h"
103 #include "main/mtypes.h"
105 #define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str)
106 #define glcpp_printf(stream, fmt, args...) \
107 stream = talloc_asprintf_append(stream, fmt, args)
109 static void
110 yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
112 static void
113 _define_object_macro (glcpp_parser_t *parser,
114 YYLTYPE *loc,
115 const char *macro,
116 token_list_t *replacements);
118 static void
119 _define_function_macro (glcpp_parser_t *parser,
120 YYLTYPE *loc,
121 const char *macro,
122 string_list_t *parameters,
123 token_list_t *replacements);
125 static string_list_t *
126 _string_list_create (void *ctx);
128 static void
129 _string_list_append_item (string_list_t *list, const char *str);
131 static int
132 _string_list_contains (string_list_t *list, const char *member, int *index);
134 static int
135 _string_list_length (string_list_t *list);
137 static argument_list_t *
138 _argument_list_create (void *ctx);
140 static void
141 _argument_list_append (argument_list_t *list, token_list_t *argument);
143 static int
144 _argument_list_length (argument_list_t *list);
146 static token_list_t *
147 _argument_list_member_at (argument_list_t *list, int index);
149 /* Note: This function talloc_steal()s the str pointer. */
150 static token_t *
151 _token_create_str (void *ctx, int type, char *str);
153 static token_t *
154 _token_create_ival (void *ctx, int type, int ival);
156 static token_list_t *
157 _token_list_create (void *ctx);
159 /* Note: This function adds a talloc_reference() to token.
161 * You may want to talloc_unlink any current reference if you no
162 * longer need it. */
163 static void
164 _token_list_append (token_list_t *list, token_t *token);
166 static void
167 _token_list_append_list (token_list_t *list, token_list_t *tail);
169 static active_list_t *
170 _active_list_push (active_list_t *list,
171 const char *identifier,
172 token_node_t *marker);
174 static active_list_t *
175 _active_list_pop (active_list_t *list);
178 _active_list_contains (active_list_t *list, const char *identifier);
180 static void
181 _glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
183 static void
184 _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
185 token_list_t *list);
187 static void
188 _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
189 token_list_t *list);
191 static void
192 _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
193 int condition);
195 static void
196 _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
197 const char *type, int condition);
199 static void
200 _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc);
202 #define yylex glcpp_parser_lex
204 static int
205 glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
207 static void
208 glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
210 static void
211 add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
215 /* Line 189 of yacc.c */
216 #line 217 "glcpp/glcpp-parse.c"
218 /* Enabling traces. */
219 #ifndef YYDEBUG
220 # define YYDEBUG 0
221 #endif
223 /* Enabling verbose error messages. */
224 #ifdef YYERROR_VERBOSE
225 # undef YYERROR_VERBOSE
226 # define YYERROR_VERBOSE 1
227 #else
228 # define YYERROR_VERBOSE 1
229 #endif
231 /* Enabling the token table. */
232 #ifndef YYTOKEN_TABLE
233 # define YYTOKEN_TABLE 0
234 #endif
237 /* Tokens. */
238 #ifndef YYTOKENTYPE
239 # define YYTOKENTYPE
240 /* Put the tokens into the symbol table, so that GDB and other debuggers
241 know about them. */
242 enum yytokentype {
243 COMMA_FINAL = 258,
244 DEFINED = 259,
245 ELIF_EXPANDED = 260,
246 HASH = 261,
247 HASH_DEFINE_FUNC = 262,
248 HASH_DEFINE_OBJ = 263,
249 HASH_ELIF = 264,
250 HASH_ELSE = 265,
251 HASH_ENDIF = 266,
252 HASH_IF = 267,
253 HASH_IFDEF = 268,
254 HASH_IFNDEF = 269,
255 HASH_UNDEF = 270,
256 HASH_VERSION = 271,
257 IDENTIFIER = 272,
258 IF_EXPANDED = 273,
259 INTEGER = 274,
260 INTEGER_STRING = 275,
261 NEWLINE = 276,
262 OTHER = 277,
263 PLACEHOLDER = 278,
264 SPACE = 279,
265 PASTE = 280,
266 OR = 281,
267 AND = 282,
268 NOT_EQUAL = 283,
269 EQUAL = 284,
270 GREATER_OR_EQUAL = 285,
271 LESS_OR_EQUAL = 286,
272 RIGHT_SHIFT = 287,
273 LEFT_SHIFT = 288,
274 UNARY = 289
276 #endif
280 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
282 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
283 # define YYSTYPE_IS_DECLARED 1
284 #endif
286 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
287 typedef struct YYLTYPE
289 int first_line;
290 int first_column;
291 int last_line;
292 int last_column;
293 } YYLTYPE;
294 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
295 # define YYLTYPE_IS_DECLARED 1
296 # define YYLTYPE_IS_TRIVIAL 1
297 #endif
300 /* Copy the second part of user declarations. */
303 /* Line 264 of yacc.c */
304 #line 305 "glcpp/glcpp-parse.c"
306 #ifdef short
307 # undef short
308 #endif
310 #ifdef YYTYPE_UINT8
311 typedef YYTYPE_UINT8 yytype_uint8;
312 #else
313 typedef unsigned char yytype_uint8;
314 #endif
316 #ifdef YYTYPE_INT8
317 typedef YYTYPE_INT8 yytype_int8;
318 #elif (defined __STDC__ || defined __C99__FUNC__ \
319 || defined __cplusplus || defined _MSC_VER)
320 typedef signed char yytype_int8;
321 #else
322 typedef short int yytype_int8;
323 #endif
325 #ifdef YYTYPE_UINT16
326 typedef YYTYPE_UINT16 yytype_uint16;
327 #else
328 typedef unsigned short int yytype_uint16;
329 #endif
331 #ifdef YYTYPE_INT16
332 typedef YYTYPE_INT16 yytype_int16;
333 #else
334 typedef short int yytype_int16;
335 #endif
337 #ifndef YYSIZE_T
338 # ifdef __SIZE_TYPE__
339 # define YYSIZE_T __SIZE_TYPE__
340 # elif defined size_t
341 # define YYSIZE_T size_t
342 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
343 || defined __cplusplus || defined _MSC_VER)
344 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
345 # define YYSIZE_T size_t
346 # else
347 # define YYSIZE_T unsigned int
348 # endif
349 #endif
351 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
353 #ifndef YY_
354 # if YYENABLE_NLS
355 # if ENABLE_NLS
356 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
357 # define YY_(msgid) dgettext ("bison-runtime", msgid)
358 # endif
359 # endif
360 # ifndef YY_
361 # define YY_(msgid) msgid
362 # endif
363 #endif
365 /* Suppress unused-variable warnings by "using" E. */
366 #if ! defined lint || defined __GNUC__
367 # define YYUSE(e) ((void) (e))
368 #else
369 # define YYUSE(e) /* empty */
370 #endif
372 /* Identity function, used to suppress warnings about constant conditions. */
373 #ifndef lint
374 # define YYID(n) (n)
375 #else
376 #if (defined __STDC__ || defined __C99__FUNC__ \
377 || defined __cplusplus || defined _MSC_VER)
378 static int
379 YYID (int yyi)
380 #else
381 static int
382 YYID (yyi)
383 int yyi;
384 #endif
386 return yyi;
388 #endif
390 #if ! defined yyoverflow || YYERROR_VERBOSE
392 /* The parser invokes alloca or malloc; define the necessary symbols. */
394 # ifdef YYSTACK_USE_ALLOCA
395 # if YYSTACK_USE_ALLOCA
396 # ifdef __GNUC__
397 # define YYSTACK_ALLOC __builtin_alloca
398 # elif defined __BUILTIN_VA_ARG_INCR
399 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
400 # elif defined _AIX
401 # define YYSTACK_ALLOC __alloca
402 # elif defined _MSC_VER
403 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
404 # define alloca _alloca
405 # else
406 # define YYSTACK_ALLOC alloca
407 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
408 || defined __cplusplus || defined _MSC_VER)
409 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
410 # ifndef _STDLIB_H
411 # define _STDLIB_H 1
412 # endif
413 # endif
414 # endif
415 # endif
416 # endif
418 # ifdef YYSTACK_ALLOC
419 /* Pacify GCC's `empty if-body' warning. */
420 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
421 # ifndef YYSTACK_ALLOC_MAXIMUM
422 /* The OS might guarantee only one guard page at the bottom of the stack,
423 and a page size can be as small as 4096 bytes. So we cannot safely
424 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
425 to allow for a few compiler-allocated temporary stack slots. */
426 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
427 # endif
428 # else
429 # define YYSTACK_ALLOC YYMALLOC
430 # define YYSTACK_FREE YYFREE
431 # ifndef YYSTACK_ALLOC_MAXIMUM
432 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
433 # endif
434 # if (defined __cplusplus && ! defined _STDLIB_H \
435 && ! ((defined YYMALLOC || defined malloc) \
436 && (defined YYFREE || defined free)))
437 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
438 # ifndef _STDLIB_H
439 # define _STDLIB_H 1
440 # endif
441 # endif
442 # ifndef YYMALLOC
443 # define YYMALLOC malloc
444 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
445 || defined __cplusplus || defined _MSC_VER)
446 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
447 # endif
448 # endif
449 # ifndef YYFREE
450 # define YYFREE free
451 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
452 || defined __cplusplus || defined _MSC_VER)
453 void free (void *); /* INFRINGES ON USER NAME SPACE */
454 # endif
455 # endif
456 # endif
457 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
460 #if (! defined yyoverflow \
461 && (! defined __cplusplus \
462 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
463 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
465 /* A type that is properly aligned for any stack member. */
466 union yyalloc
468 yytype_int16 yyss_alloc;
469 YYSTYPE yyvs_alloc;
470 YYLTYPE yyls_alloc;
473 /* The size of the maximum gap between one aligned stack and the next. */
474 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
476 /* The size of an array large to enough to hold all stacks, each with
477 N elements. */
478 # define YYSTACK_BYTES(N) \
479 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
480 + 2 * YYSTACK_GAP_MAXIMUM)
482 /* Copy COUNT objects from FROM to TO. The source and destination do
483 not overlap. */
484 # ifndef YYCOPY
485 # if defined __GNUC__ && 1 < __GNUC__
486 # define YYCOPY(To, From, Count) \
487 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
488 # else
489 # define YYCOPY(To, From, Count) \
490 do \
492 YYSIZE_T yyi; \
493 for (yyi = 0; yyi < (Count); yyi++) \
494 (To)[yyi] = (From)[yyi]; \
496 while (YYID (0))
497 # endif
498 # endif
500 /* Relocate STACK from its old location to the new one. The
501 local variables YYSIZE and YYSTACKSIZE give the old and new number of
502 elements in the stack, and YYPTR gives the new location of the
503 stack. Advance YYPTR to a properly aligned location for the next
504 stack. */
505 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
506 do \
508 YYSIZE_T yynewbytes; \
509 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
510 Stack = &yyptr->Stack_alloc; \
511 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
512 yyptr += yynewbytes / sizeof (*yyptr); \
514 while (YYID (0))
516 #endif
518 /* YYFINAL -- State number of the termination state. */
519 #define YYFINAL 2
520 /* YYLAST -- Last index in YYTABLE. */
521 #define YYLAST 606
523 /* YYNTOKENS -- Number of terminals. */
524 #define YYNTOKENS 57
525 /* YYNNTS -- Number of nonterminals. */
526 #define YYNNTS 17
527 /* YYNRULES -- Number of rules. */
528 #define YYNRULES 101
529 /* YYNRULES -- Number of states. */
530 #define YYNSTATES 162
532 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
533 #define YYUNDEFTOK 2
534 #define YYMAXUTOK 289
536 #define YYTRANSLATE(YYX) \
537 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
539 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
540 static const yytype_uint8 yytranslate[] =
542 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
543 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
544 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
545 2, 2, 2, 47, 2, 2, 2, 43, 30, 2,
546 45, 46, 41, 39, 49, 40, 54, 42, 2, 2,
547 2, 2, 2, 2, 2, 2, 2, 2, 2, 55,
548 33, 56, 34, 2, 2, 2, 2, 2, 2, 2,
549 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
550 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
551 2, 50, 2, 51, 29, 2, 2, 2, 2, 2,
552 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
553 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
554 2, 2, 2, 52, 28, 53, 48, 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, 2, 2, 2, 2,
567 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
568 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
569 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
570 25, 26, 27, 31, 32, 35, 36, 37, 38, 44
573 #if YYDEBUG
574 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
575 YYRHS. */
576 static const yytype_uint16 yyprhs[] =
578 0, 0, 3, 4, 7, 9, 11, 13, 16, 20,
579 24, 29, 36, 44, 48, 52, 55, 60, 65, 69,
580 72, 75, 78, 82, 85, 87, 89, 91, 95, 99,
581 103, 107, 111, 115, 119, 123, 127, 131, 135, 139,
582 143, 147, 151, 155, 159, 163, 166, 169, 172, 175,
583 179, 181, 185, 187, 190, 193, 194, 196, 197, 199,
584 202, 207, 209, 211, 214, 216, 219, 221, 223, 225,
585 227, 229, 231, 233, 235, 237, 239, 241, 243, 245,
586 247, 249, 251, 253, 255, 257, 259, 261, 263, 265,
587 267, 269, 271, 273, 275, 277, 279, 281, 283, 285,
588 287, 289
591 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
592 static const yytype_int8 yyrhs[] =
594 58, 0, -1, -1, 58, 59, -1, 61, -1, 65,
595 -1, 60, -1, 6, 66, -1, 18, 63, 21, -1,
596 5, 63, 21, -1, 8, 17, 67, 21, -1, 7,
597 17, 45, 46, 67, 21, -1, 7, 17, 45, 64,
598 46, 67, 21, -1, 15, 17, 21, -1, 12, 70,
599 21, -1, 12, 21, -1, 13, 17, 68, 21, -1,
600 14, 17, 68, 21, -1, 9, 70, 21, -1, 9,
601 21, -1, 10, 21, -1, 11, 21, -1, 16, 62,
602 21, -1, 6, 21, -1, 20, -1, 19, -1, 62,
603 -1, 63, 26, 63, -1, 63, 27, 63, -1, 63,
604 28, 63, -1, 63, 29, 63, -1, 63, 30, 63,
605 -1, 63, 31, 63, -1, 63, 32, 63, -1, 63,
606 35, 63, -1, 63, 36, 63, -1, 63, 34, 63,
607 -1, 63, 33, 63, -1, 63, 37, 63, -1, 63,
608 38, 63, -1, 63, 40, 63, -1, 63, 39, 63,
609 -1, 63, 43, 63, -1, 63, 42, 63, -1, 63,
610 41, 63, -1, 47, 63, -1, 48, 63, -1, 40,
611 63, -1, 39, 63, -1, 45, 63, 46, -1, 17,
612 -1, 64, 49, 17, -1, 21, -1, 71, 21, -1,
613 71, 21, -1, -1, 71, -1, -1, 71, -1, 4,
614 17, -1, 4, 45, 17, 46, -1, 72, -1, 69,
615 -1, 70, 69, -1, 72, -1, 71, 72, -1, 17,
616 -1, 20, -1, 73, -1, 22, -1, 24, -1, 50,
617 -1, 51, -1, 45, -1, 46, -1, 52, -1, 53,
618 -1, 54, -1, 30, -1, 41, -1, 39, -1, 40,
619 -1, 48, -1, 47, -1, 42, -1, 43, -1, 38,
620 -1, 37, -1, 33, -1, 34, -1, 36, -1, 35,
621 -1, 32, -1, 31, -1, 29, -1, 28, -1, 27,
622 -1, 26, -1, 55, -1, 49, -1, 56, -1, 25,
626 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
627 static const yytype_uint16 yyrline[] =
629 0, 181, 181, 183, 187, 190, 195, 196, 200, 203,
630 209, 212, 215, 218, 226, 245, 255, 260, 265, 284,
631 299, 302, 305, 314, 318, 327, 332, 333, 336, 339,
632 342, 345, 348, 351, 354, 357, 360, 363, 366, 369,
633 372, 375, 378, 381, 384, 387, 390, 393, 396, 399,
634 405, 410, 418, 419, 423, 429, 430, 433, 435, 442,
635 446, 450, 455, 461, 469, 475, 483, 487, 491, 495,
636 499, 506, 507, 508, 509, 510, 511, 512, 513, 514,
637 515, 516, 517, 518, 519, 520, 521, 522, 523, 524,
638 525, 526, 527, 528, 529, 530, 531, 532, 533, 534,
639 535, 536
641 #endif
643 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
644 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
645 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
646 static const char *const yytname[] =
648 "$end", "error", "$undefined", "COMMA_FINAL", "DEFINED",
649 "ELIF_EXPANDED", "HASH", "HASH_DEFINE_FUNC", "HASH_DEFINE_OBJ",
650 "HASH_ELIF", "HASH_ELSE", "HASH_ENDIF", "HASH_IF", "HASH_IFDEF",
651 "HASH_IFNDEF", "HASH_UNDEF", "HASH_VERSION", "IDENTIFIER", "IF_EXPANDED",
652 "INTEGER", "INTEGER_STRING", "NEWLINE", "OTHER", "PLACEHOLDER", "SPACE",
653 "PASTE", "OR", "AND", "'|'", "'^'", "'&'", "NOT_EQUAL", "EQUAL", "'<'",
654 "'>'", "GREATER_OR_EQUAL", "LESS_OR_EQUAL", "RIGHT_SHIFT", "LEFT_SHIFT",
655 "'+'", "'-'", "'*'", "'/'", "'%'", "UNARY", "'('", "')'", "'!'", "'~'",
656 "','", "'['", "']'", "'{'", "'}'", "'.'", "';'", "'='", "$accept",
657 "input", "line", "expanded_line", "control_line", "integer_constant",
658 "expression", "identifier_list", "text_line", "non_directive",
659 "replacement_list", "junk", "conditional_token", "conditional_tokens",
660 "pp_tokens", "preprocessing_token", "operator", 0
662 #endif
664 # ifdef YYPRINT
665 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
666 token YYLEX-NUM. */
667 static const yytype_uint16 yytoknum[] =
669 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
670 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
671 275, 276, 277, 278, 279, 280, 281, 282, 124, 94,
672 38, 283, 284, 60, 62, 285, 286, 287, 288, 43,
673 45, 42, 47, 37, 289, 40, 41, 33, 126, 44,
674 91, 93, 123, 125, 46, 59, 61
676 # endif
678 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
679 static const yytype_uint8 yyr1[] =
681 0, 57, 58, 58, 59, 59, 59, 59, 60, 60,
682 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
683 61, 61, 61, 61, 62, 62, 63, 63, 63, 63,
684 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
685 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
686 64, 64, 65, 65, 66, 67, 67, 68, 68, 69,
687 69, 69, 70, 70, 71, 71, 72, 72, 72, 72,
688 72, 73, 73, 73, 73, 73, 73, 73, 73, 73,
689 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
690 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
691 73, 73
694 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
695 static const yytype_uint8 yyr2[] =
697 0, 2, 0, 2, 1, 1, 1, 2, 3, 3,
698 4, 6, 7, 3, 3, 2, 4, 4, 3, 2,
699 2, 2, 3, 2, 1, 1, 1, 3, 3, 3,
700 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
701 3, 3, 3, 3, 3, 2, 2, 2, 2, 3,
702 1, 3, 1, 2, 2, 0, 1, 0, 1, 2,
703 4, 1, 1, 2, 1, 2, 1, 1, 1, 1,
704 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
705 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
706 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
707 1, 1
710 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
711 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
712 means the default is an error. */
713 static const yytype_uint8 yydefact[] =
715 2, 0, 1, 0, 0, 0, 0, 0, 0, 0,
716 0, 0, 0, 0, 0, 66, 0, 67, 52, 69,
717 70, 101, 97, 96, 95, 94, 78, 93, 92, 88,
718 89, 91, 90, 87, 86, 80, 81, 79, 84, 85,
719 73, 74, 83, 82, 99, 71, 72, 75, 76, 77,
720 98, 100, 3, 6, 4, 5, 0, 64, 68, 25,
721 24, 0, 0, 0, 0, 0, 26, 0, 23, 7,
722 0, 0, 55, 0, 19, 62, 0, 61, 20, 21,
723 15, 0, 57, 57, 0, 0, 0, 53, 65, 48,
724 47, 0, 45, 46, 9, 0, 0, 0, 0, 0,
725 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
726 0, 0, 0, 54, 0, 0, 56, 59, 0, 18,
727 63, 14, 0, 58, 0, 13, 22, 8, 49, 27,
728 28, 29, 30, 31, 32, 33, 37, 36, 34, 35,
729 38, 39, 41, 40, 44, 43, 42, 50, 55, 0,
730 10, 0, 16, 17, 0, 55, 0, 60, 11, 0,
731 51, 12
734 /* YYDEFGOTO[NTERM-NUM]. */
735 static const yytype_int16 yydefgoto[] =
737 -1, 1, 52, 53, 54, 66, 67, 149, 55, 69,
738 115, 122, 75, 76, 116, 57, 58
741 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
742 STATE-NUM. */
743 #define YYPACT_NINF -147
744 static const yytype_int16 yypact[] =
746 -147, 112, -147, 28, -10, 55, 62, 152, -15, 59,
747 192, 85, 86, 87, 51, -147, 28, -147, -147, -147,
748 -147, -147, -147, -147, -147, -147, -147, -147, -147, -147,
749 -147, -147, -147, -147, -147, -147, -147, -147, -147, -147,
750 -147, -147, -147, -147, -147, -147, -147, -147, -147, -147,
751 -147, -147, -147, -147, -147, -147, 312, -147, -147, -147,
752 -147, 28, 28, 28, 28, 28, -147, 428, -147, -147,
753 352, 63, 392, 17, -147, -147, 232, -147, -147, -147,
754 -147, 272, 392, 392, 84, 89, 451, -147, -147, -147,
755 -147, 469, -147, -147, -147, 28, 28, 28, 28, 28,
756 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
757 28, 28, 28, -147, 60, 90, 392, -147, 96, -147,
758 -147, -147, 93, 392, 94, -147, -147, -147, -147, 489,
759 505, 520, 534, 547, 558, 558, 18, 18, 18, 18,
760 563, 563, 23, 23, -147, -147, -147, -147, 392, 32,
761 -147, 61, -147, -147, 110, 392, 118, -147, -147, 149,
762 -147, -147
765 /* YYPGOTO[NTERM-NUM]. */
766 static const yytype_int16 yypgoto[] =
768 -147, -147, -147, -147, -147, 157, -11, -147, -147, -147,
769 -146, 92, -68, 200, 0, -7, -147
772 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
773 positive, shift that token. If negative, reduce the rule which
774 number is the opposite. If zero, do what YYDEFACT says.
775 If YYTABLE_NINF, syntax error. */
776 #define YYTABLE_NINF -1
777 static const yytype_uint8 yytable[] =
779 77, 56, 154, 77, 70, 86, 78, 15, 120, 159,
780 17, 68, 19, 120, 20, 21, 22, 23, 24, 25,
781 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
782 36, 37, 38, 39, 117, 40, 41, 42, 43, 44,
783 45, 46, 47, 48, 49, 50, 51, 59, 60, 88,
784 89, 90, 91, 92, 93, 106, 107, 108, 109, 110,
785 111, 112, 118, 88, 110, 111, 112, 61, 62, 77,
786 59, 60, 71, 63, 77, 64, 65, 147, 155, 72,
787 79, 156, 123, 123, 129, 130, 131, 132, 133, 134,
788 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
789 145, 146, 82, 83, 84, 125, 148, 157, 114, 88,
790 126, 150, 2, 151, 152, 153, 88, 3, 4, 5,
791 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
792 16, 158, 17, 18, 19, 160, 20, 21, 22, 23,
793 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
794 34, 35, 36, 37, 38, 39, 73, 40, 41, 42,
795 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
796 161, 85, 17, 74, 19, 124, 20, 21, 22, 23,
797 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
798 34, 35, 36, 37, 38, 39, 73, 40, 41, 42,
799 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
800 81, 0, 17, 80, 19, 0, 20, 21, 22, 23,
801 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
802 34, 35, 36, 37, 38, 39, 73, 40, 41, 42,
803 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
804 0, 0, 17, 119, 19, 0, 20, 21, 22, 23,
805 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
806 34, 35, 36, 37, 38, 39, 73, 40, 41, 42,
807 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
808 0, 0, 17, 121, 19, 0, 20, 21, 22, 23,
809 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
810 34, 35, 36, 37, 38, 39, 0, 40, 41, 42,
811 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
812 0, 0, 17, 87, 19, 0, 20, 21, 22, 23,
813 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
814 34, 35, 36, 37, 38, 39, 0, 40, 41, 42,
815 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
816 0, 0, 17, 113, 19, 0, 20, 21, 22, 23,
817 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
818 34, 35, 36, 37, 38, 39, 0, 40, 41, 42,
819 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
820 0, 0, 17, 0, 19, 0, 20, 21, 22, 23,
821 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
822 34, 35, 36, 37, 38, 39, 0, 40, 41, 42,
823 43, 44, 45, 46, 47, 48, 49, 50, 51, 94,
824 0, 0, 0, 0, 95, 96, 97, 98, 99, 100,
825 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
826 111, 112, 127, 0, 0, 0, 0, 95, 96, 97,
827 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
828 108, 109, 110, 111, 112, 95, 96, 97, 98, 99,
829 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
830 110, 111, 112, 0, 0, 128, 96, 97, 98, 99,
831 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
832 110, 111, 112, 97, 98, 99, 100, 101, 102, 103,
833 104, 105, 106, 107, 108, 109, 110, 111, 112, 98,
834 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
835 109, 110, 111, 112, 99, 100, 101, 102, 103, 104,
836 105, 106, 107, 108, 109, 110, 111, 112, 100, 101,
837 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
838 112, 102, 103, 104, 105, 106, 107, 108, 109, 110,
839 111, 112, 108, 109, 110, 111, 112
842 static const yytype_int16 yycheck[] =
844 7, 1, 148, 10, 4, 16, 21, 17, 76, 155,
845 20, 21, 22, 81, 24, 25, 26, 27, 28, 29,
846 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
847 40, 41, 42, 43, 17, 45, 46, 47, 48, 49,
848 50, 51, 52, 53, 54, 55, 56, 19, 20, 56,
849 61, 62, 63, 64, 65, 37, 38, 39, 40, 41,
850 42, 43, 45, 70, 41, 42, 43, 39, 40, 76,
851 19, 20, 17, 45, 81, 47, 48, 17, 46, 17,
852 21, 49, 82, 83, 95, 96, 97, 98, 99, 100,
853 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
854 111, 112, 17, 17, 17, 21, 46, 46, 45, 116,
855 21, 21, 0, 17, 21, 21, 123, 5, 6, 7,
856 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
857 18, 21, 20, 21, 22, 17, 24, 25, 26, 27,
858 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
859 38, 39, 40, 41, 42, 43, 4, 45, 46, 47,
860 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
861 21, 14, 20, 21, 22, 83, 24, 25, 26, 27,
862 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
863 38, 39, 40, 41, 42, 43, 4, 45, 46, 47,
864 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
865 10, -1, 20, 21, 22, -1, 24, 25, 26, 27,
866 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
867 38, 39, 40, 41, 42, 43, 4, 45, 46, 47,
868 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
869 -1, -1, 20, 21, 22, -1, 24, 25, 26, 27,
870 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
871 38, 39, 40, 41, 42, 43, 4, 45, 46, 47,
872 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
873 -1, -1, 20, 21, 22, -1, 24, 25, 26, 27,
874 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
875 38, 39, 40, 41, 42, 43, -1, 45, 46, 47,
876 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
877 -1, -1, 20, 21, 22, -1, 24, 25, 26, 27,
878 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
879 38, 39, 40, 41, 42, 43, -1, 45, 46, 47,
880 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
881 -1, -1, 20, 21, 22, -1, 24, 25, 26, 27,
882 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
883 38, 39, 40, 41, 42, 43, -1, 45, 46, 47,
884 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
885 -1, -1, 20, -1, 22, -1, 24, 25, 26, 27,
886 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
887 38, 39, 40, 41, 42, 43, -1, 45, 46, 47,
888 48, 49, 50, 51, 52, 53, 54, 55, 56, 21,
889 -1, -1, -1, -1, 26, 27, 28, 29, 30, 31,
890 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
891 42, 43, 21, -1, -1, -1, -1, 26, 27, 28,
892 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
893 39, 40, 41, 42, 43, 26, 27, 28, 29, 30,
894 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
895 41, 42, 43, -1, -1, 46, 27, 28, 29, 30,
896 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
897 41, 42, 43, 28, 29, 30, 31, 32, 33, 34,
898 35, 36, 37, 38, 39, 40, 41, 42, 43, 29,
899 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
900 40, 41, 42, 43, 30, 31, 32, 33, 34, 35,
901 36, 37, 38, 39, 40, 41, 42, 43, 31, 32,
902 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
903 43, 33, 34, 35, 36, 37, 38, 39, 40, 41,
904 42, 43, 39, 40, 41, 42, 43
907 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
908 symbol of state STATE-NUM. */
909 static const yytype_uint8 yystos[] =
911 0, 58, 0, 5, 6, 7, 8, 9, 10, 11,
912 12, 13, 14, 15, 16, 17, 18, 20, 21, 22,
913 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
914 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
915 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
916 55, 56, 59, 60, 61, 65, 71, 72, 73, 19,
917 20, 39, 40, 45, 47, 48, 62, 63, 21, 66,
918 71, 17, 17, 4, 21, 69, 70, 72, 21, 21,
919 21, 70, 17, 17, 17, 62, 63, 21, 72, 63,
920 63, 63, 63, 63, 21, 26, 27, 28, 29, 30,
921 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
922 41, 42, 43, 21, 45, 67, 71, 17, 45, 21,
923 69, 21, 68, 71, 68, 21, 21, 21, 46, 63,
924 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
925 63, 63, 63, 63, 63, 63, 63, 17, 46, 64,
926 21, 17, 21, 21, 67, 46, 49, 46, 21, 67,
927 17, 21
930 #define yyerrok (yyerrstatus = 0)
931 #define yyclearin (yychar = YYEMPTY)
932 #define YYEMPTY (-2)
933 #define YYEOF 0
935 #define YYACCEPT goto yyacceptlab
936 #define YYABORT goto yyabortlab
937 #define YYERROR goto yyerrorlab
940 /* Like YYERROR except do call yyerror. This remains here temporarily
941 to ease the transition to the new meaning of YYERROR, for GCC.
942 Once GCC version 2 has supplanted version 1, this can go. */
944 #define YYFAIL goto yyerrlab
946 #define YYRECOVERING() (!!yyerrstatus)
948 #define YYBACKUP(Token, Value) \
949 do \
950 if (yychar == YYEMPTY && yylen == 1) \
952 yychar = (Token); \
953 yylval = (Value); \
954 yytoken = YYTRANSLATE (yychar); \
955 YYPOPSTACK (1); \
956 goto yybackup; \
958 else \
960 yyerror (&yylloc, parser, YY_("syntax error: cannot back up")); \
961 YYERROR; \
963 while (YYID (0))
966 #define YYTERROR 1
967 #define YYERRCODE 256
970 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
971 If N is 0, then set CURRENT to the empty location which ends
972 the previous symbol: RHS[0] (always defined). */
974 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
975 #ifndef YYLLOC_DEFAULT
976 # define YYLLOC_DEFAULT(Current, Rhs, N) \
977 do \
978 if (YYID (N)) \
980 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
981 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
982 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
983 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
985 else \
987 (Current).first_line = (Current).last_line = \
988 YYRHSLOC (Rhs, 0).last_line; \
989 (Current).first_column = (Current).last_column = \
990 YYRHSLOC (Rhs, 0).last_column; \
992 while (YYID (0))
993 #endif
996 /* YY_LOCATION_PRINT -- Print the location on the stream.
997 This macro was not mandated originally: define only if we know
998 we won't break user code: when these are the locations we know. */
1000 #ifndef YY_LOCATION_PRINT
1001 # if YYLTYPE_IS_TRIVIAL
1002 # define YY_LOCATION_PRINT(File, Loc) \
1003 fprintf (File, "%d.%d-%d.%d", \
1004 (Loc).first_line, (Loc).first_column, \
1005 (Loc).last_line, (Loc).last_column)
1006 # else
1007 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1008 # endif
1009 #endif
1012 /* YYLEX -- calling `yylex' with the right arguments. */
1014 #ifdef YYLEX_PARAM
1015 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
1016 #else
1017 # define YYLEX yylex (&yylval, &yylloc, parser)
1018 #endif
1020 /* Enable debugging if requested. */
1021 #if YYDEBUG
1023 # ifndef YYFPRINTF
1024 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1025 # define YYFPRINTF fprintf
1026 # endif
1028 # define YYDPRINTF(Args) \
1029 do { \
1030 if (yydebug) \
1031 YYFPRINTF Args; \
1032 } while (YYID (0))
1034 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1035 do { \
1036 if (yydebug) \
1038 YYFPRINTF (stderr, "%s ", Title); \
1039 yy_symbol_print (stderr, \
1040 Type, Value, Location, parser); \
1041 YYFPRINTF (stderr, "\n"); \
1043 } while (YYID (0))
1046 /*--------------------------------.
1047 | Print this symbol on YYOUTPUT. |
1048 `--------------------------------*/
1050 /*ARGSUSED*/
1051 #if (defined __STDC__ || defined __C99__FUNC__ \
1052 || defined __cplusplus || defined _MSC_VER)
1053 static void
1054 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
1055 #else
1056 static void
1057 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser)
1058 FILE *yyoutput;
1059 int yytype;
1060 YYSTYPE const * const yyvaluep;
1061 YYLTYPE const * const yylocationp;
1062 glcpp_parser_t *parser;
1063 #endif
1065 if (!yyvaluep)
1066 return;
1067 YYUSE (yylocationp);
1068 YYUSE (parser);
1069 # ifdef YYPRINT
1070 if (yytype < YYNTOKENS)
1071 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1072 # else
1073 YYUSE (yyoutput);
1074 # endif
1075 switch (yytype)
1077 default:
1078 break;
1083 /*--------------------------------.
1084 | Print this symbol on YYOUTPUT. |
1085 `--------------------------------*/
1087 #if (defined __STDC__ || defined __C99__FUNC__ \
1088 || defined __cplusplus || defined _MSC_VER)
1089 static void
1090 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
1091 #else
1092 static void
1093 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, parser)
1094 FILE *yyoutput;
1095 int yytype;
1096 YYSTYPE const * const yyvaluep;
1097 YYLTYPE const * const yylocationp;
1098 glcpp_parser_t *parser;
1099 #endif
1101 if (yytype < YYNTOKENS)
1102 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1103 else
1104 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1106 YY_LOCATION_PRINT (yyoutput, *yylocationp);
1107 YYFPRINTF (yyoutput, ": ");
1108 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser);
1109 YYFPRINTF (yyoutput, ")");
1112 /*------------------------------------------------------------------.
1113 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1114 | TOP (included). |
1115 `------------------------------------------------------------------*/
1117 #if (defined __STDC__ || defined __C99__FUNC__ \
1118 || defined __cplusplus || defined _MSC_VER)
1119 static void
1120 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1121 #else
1122 static void
1123 yy_stack_print (yybottom, yytop)
1124 yytype_int16 *yybottom;
1125 yytype_int16 *yytop;
1126 #endif
1128 YYFPRINTF (stderr, "Stack now");
1129 for (; yybottom <= yytop; yybottom++)
1131 int yybot = *yybottom;
1132 YYFPRINTF (stderr, " %d", yybot);
1134 YYFPRINTF (stderr, "\n");
1137 # define YY_STACK_PRINT(Bottom, Top) \
1138 do { \
1139 if (yydebug) \
1140 yy_stack_print ((Bottom), (Top)); \
1141 } while (YYID (0))
1144 /*------------------------------------------------.
1145 | Report that the YYRULE is going to be reduced. |
1146 `------------------------------------------------*/
1148 #if (defined __STDC__ || defined __C99__FUNC__ \
1149 || defined __cplusplus || defined _MSC_VER)
1150 static void
1151 yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, glcpp_parser_t *parser)
1152 #else
1153 static void
1154 yy_reduce_print (yyvsp, yylsp, yyrule, parser)
1155 YYSTYPE *yyvsp;
1156 YYLTYPE *yylsp;
1157 int yyrule;
1158 glcpp_parser_t *parser;
1159 #endif
1161 int yynrhs = yyr2[yyrule];
1162 int yyi;
1163 unsigned long int yylno = yyrline[yyrule];
1164 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1165 yyrule - 1, yylno);
1166 /* The symbols being reduced. */
1167 for (yyi = 0; yyi < yynrhs; yyi++)
1169 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1170 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1171 &(yyvsp[(yyi + 1) - (yynrhs)])
1172 , &(yylsp[(yyi + 1) - (yynrhs)]) , parser);
1173 YYFPRINTF (stderr, "\n");
1177 # define YY_REDUCE_PRINT(Rule) \
1178 do { \
1179 if (yydebug) \
1180 yy_reduce_print (yyvsp, yylsp, Rule, parser); \
1181 } while (YYID (0))
1183 /* Nonzero means print parse trace. It is left uninitialized so that
1184 multiple parsers can coexist. */
1185 int yydebug;
1186 #else /* !YYDEBUG */
1187 # define YYDPRINTF(Args)
1188 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1189 # define YY_STACK_PRINT(Bottom, Top)
1190 # define YY_REDUCE_PRINT(Rule)
1191 #endif /* !YYDEBUG */
1194 /* YYINITDEPTH -- initial size of the parser's stacks. */
1195 #ifndef YYINITDEPTH
1196 # define YYINITDEPTH 200
1197 #endif
1199 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1200 if the built-in stack extension method is used).
1202 Do not make this value too large; the results are undefined if
1203 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1204 evaluated with infinite-precision integer arithmetic. */
1206 #ifndef YYMAXDEPTH
1207 # define YYMAXDEPTH 10000
1208 #endif
1212 #if YYERROR_VERBOSE
1214 # ifndef yystrlen
1215 # if defined __GLIBC__ && defined _STRING_H
1216 # define yystrlen strlen
1217 # else
1218 /* Return the length of YYSTR. */
1219 #if (defined __STDC__ || defined __C99__FUNC__ \
1220 || defined __cplusplus || defined _MSC_VER)
1221 static YYSIZE_T
1222 yystrlen (const char *yystr)
1223 #else
1224 static YYSIZE_T
1225 yystrlen (yystr)
1226 const char *yystr;
1227 #endif
1229 YYSIZE_T yylen;
1230 for (yylen = 0; yystr[yylen]; yylen++)
1231 continue;
1232 return yylen;
1234 # endif
1235 # endif
1237 # ifndef yystpcpy
1238 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1239 # define yystpcpy stpcpy
1240 # else
1241 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1242 YYDEST. */
1243 #if (defined __STDC__ || defined __C99__FUNC__ \
1244 || defined __cplusplus || defined _MSC_VER)
1245 static char *
1246 yystpcpy (char *yydest, const char *yysrc)
1247 #else
1248 static char *
1249 yystpcpy (yydest, yysrc)
1250 char *yydest;
1251 const char *yysrc;
1252 #endif
1254 char *yyd = yydest;
1255 const char *yys = yysrc;
1257 while ((*yyd++ = *yys++) != '\0')
1258 continue;
1260 return yyd - 1;
1262 # endif
1263 # endif
1265 # ifndef yytnamerr
1266 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1267 quotes and backslashes, so that it's suitable for yyerror. The
1268 heuristic is that double-quoting is unnecessary unless the string
1269 contains an apostrophe, a comma, or backslash (other than
1270 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1271 null, do not copy; instead, return the length of what the result
1272 would have been. */
1273 static YYSIZE_T
1274 yytnamerr (char *yyres, const char *yystr)
1276 if (*yystr == '"')
1278 YYSIZE_T yyn = 0;
1279 char const *yyp = yystr;
1281 for (;;)
1282 switch (*++yyp)
1284 case '\'':
1285 case ',':
1286 goto do_not_strip_quotes;
1288 case '\\':
1289 if (*++yyp != '\\')
1290 goto do_not_strip_quotes;
1291 /* Fall through. */
1292 default:
1293 if (yyres)
1294 yyres[yyn] = *yyp;
1295 yyn++;
1296 break;
1298 case '"':
1299 if (yyres)
1300 yyres[yyn] = '\0';
1301 return yyn;
1303 do_not_strip_quotes: ;
1306 if (! yyres)
1307 return yystrlen (yystr);
1309 return yystpcpy (yyres, yystr) - yyres;
1311 # endif
1313 /* Copy into YYRESULT an error message about the unexpected token
1314 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1315 including the terminating null byte. If YYRESULT is null, do not
1316 copy anything; just return the number of bytes that would be
1317 copied. As a special case, return 0 if an ordinary "syntax error"
1318 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1319 size calculation. */
1320 static YYSIZE_T
1321 yysyntax_error (char *yyresult, int yystate, int yychar)
1323 int yyn = yypact[yystate];
1325 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1326 return 0;
1327 else
1329 int yytype = YYTRANSLATE (yychar);
1330 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1331 YYSIZE_T yysize = yysize0;
1332 YYSIZE_T yysize1;
1333 int yysize_overflow = 0;
1334 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1335 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1336 int yyx;
1338 # if 0
1339 /* This is so xgettext sees the translatable formats that are
1340 constructed on the fly. */
1341 YY_("syntax error, unexpected %s");
1342 YY_("syntax error, unexpected %s, expecting %s");
1343 YY_("syntax error, unexpected %s, expecting %s or %s");
1344 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1345 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1346 # endif
1347 char *yyfmt;
1348 char const *yyf;
1349 static char const yyunexpected[] = "syntax error, unexpected %s";
1350 static char const yyexpecting[] = ", expecting %s";
1351 static char const yyor[] = " or %s";
1352 char yyformat[sizeof yyunexpected
1353 + sizeof yyexpecting - 1
1354 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1355 * (sizeof yyor - 1))];
1356 char const *yyprefix = yyexpecting;
1358 /* Start YYX at -YYN if negative to avoid negative indexes in
1359 YYCHECK. */
1360 int yyxbegin = yyn < 0 ? -yyn : 0;
1362 /* Stay within bounds of both yycheck and yytname. */
1363 int yychecklim = YYLAST - yyn + 1;
1364 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1365 int yycount = 1;
1367 yyarg[0] = yytname[yytype];
1368 yyfmt = yystpcpy (yyformat, yyunexpected);
1370 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1371 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1373 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1375 yycount = 1;
1376 yysize = yysize0;
1377 yyformat[sizeof yyunexpected - 1] = '\0';
1378 break;
1380 yyarg[yycount++] = yytname[yyx];
1381 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1382 yysize_overflow |= (yysize1 < yysize);
1383 yysize = yysize1;
1384 yyfmt = yystpcpy (yyfmt, yyprefix);
1385 yyprefix = yyor;
1388 yyf = YY_(yyformat);
1389 yysize1 = yysize + yystrlen (yyf);
1390 yysize_overflow |= (yysize1 < yysize);
1391 yysize = yysize1;
1393 if (yysize_overflow)
1394 return YYSIZE_MAXIMUM;
1396 if (yyresult)
1398 /* Avoid sprintf, as that infringes on the user's name space.
1399 Don't have undefined behavior even if the translation
1400 produced a string with the wrong number of "%s"s. */
1401 char *yyp = yyresult;
1402 int yyi = 0;
1403 while ((*yyp = *yyf) != '\0')
1405 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1407 yyp += yytnamerr (yyp, yyarg[yyi++]);
1408 yyf += 2;
1410 else
1412 yyp++;
1413 yyf++;
1417 return yysize;
1420 #endif /* YYERROR_VERBOSE */
1423 /*-----------------------------------------------.
1424 | Release the memory associated to this symbol. |
1425 `-----------------------------------------------*/
1427 /*ARGSUSED*/
1428 #if (defined __STDC__ || defined __C99__FUNC__ \
1429 || defined __cplusplus || defined _MSC_VER)
1430 static void
1431 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, glcpp_parser_t *parser)
1432 #else
1433 static void
1434 yydestruct (yymsg, yytype, yyvaluep, yylocationp, parser)
1435 const char *yymsg;
1436 int yytype;
1437 YYSTYPE *yyvaluep;
1438 YYLTYPE *yylocationp;
1439 glcpp_parser_t *parser;
1440 #endif
1442 YYUSE (yyvaluep);
1443 YYUSE (yylocationp);
1444 YYUSE (parser);
1446 if (!yymsg)
1447 yymsg = "Deleting";
1448 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1450 switch (yytype)
1453 default:
1454 break;
1458 /* Prevent warnings from -Wmissing-prototypes. */
1459 #ifdef YYPARSE_PARAM
1460 #if defined __STDC__ || defined __cplusplus
1461 int yyparse (void *YYPARSE_PARAM);
1462 #else
1463 int yyparse ();
1464 #endif
1465 #else /* ! YYPARSE_PARAM */
1466 #if defined __STDC__ || defined __cplusplus
1467 int yyparse (glcpp_parser_t *parser);
1468 #else
1469 int yyparse ();
1470 #endif
1471 #endif /* ! YYPARSE_PARAM */
1477 /*-------------------------.
1478 | yyparse or yypush_parse. |
1479 `-------------------------*/
1481 #ifdef YYPARSE_PARAM
1482 #if (defined __STDC__ || defined __C99__FUNC__ \
1483 || defined __cplusplus || defined _MSC_VER)
1485 yyparse (void *YYPARSE_PARAM)
1486 #else
1488 yyparse (YYPARSE_PARAM)
1489 void *YYPARSE_PARAM;
1490 #endif
1491 #else /* ! YYPARSE_PARAM */
1492 #if (defined __STDC__ || defined __C99__FUNC__ \
1493 || defined __cplusplus || defined _MSC_VER)
1495 yyparse (glcpp_parser_t *parser)
1496 #else
1498 yyparse (parser)
1499 glcpp_parser_t *parser;
1500 #endif
1501 #endif
1503 /* The lookahead symbol. */
1504 int yychar;
1506 /* The semantic value of the lookahead symbol. */
1507 YYSTYPE yylval;
1509 /* Location data for the lookahead symbol. */
1510 YYLTYPE yylloc;
1512 /* Number of syntax errors so far. */
1513 int yynerrs;
1515 int yystate;
1516 /* Number of tokens to shift before error messages enabled. */
1517 int yyerrstatus;
1519 /* The stacks and their tools:
1520 `yyss': related to states.
1521 `yyvs': related to semantic values.
1522 `yyls': related to locations.
1524 Refer to the stacks thru separate pointers, to allow yyoverflow
1525 to reallocate them elsewhere. */
1527 /* The state stack. */
1528 yytype_int16 yyssa[YYINITDEPTH];
1529 yytype_int16 *yyss;
1530 yytype_int16 *yyssp;
1532 /* The semantic value stack. */
1533 YYSTYPE yyvsa[YYINITDEPTH];
1534 YYSTYPE *yyvs;
1535 YYSTYPE *yyvsp;
1537 /* The location stack. */
1538 YYLTYPE yylsa[YYINITDEPTH];
1539 YYLTYPE *yyls;
1540 YYLTYPE *yylsp;
1542 /* The locations where the error started and ended. */
1543 YYLTYPE yyerror_range[2];
1545 YYSIZE_T yystacksize;
1547 int yyn;
1548 int yyresult;
1549 /* Lookahead token as an internal (translated) token number. */
1550 int yytoken;
1551 /* The variables used to return semantic value and location from the
1552 action routines. */
1553 YYSTYPE yyval;
1554 YYLTYPE yyloc;
1556 #if YYERROR_VERBOSE
1557 /* Buffer for error messages, and its allocated size. */
1558 char yymsgbuf[128];
1559 char *yymsg = yymsgbuf;
1560 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1561 #endif
1563 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1565 /* The number of symbols on the RHS of the reduced rule.
1566 Keep to zero when no symbol should be popped. */
1567 int yylen = 0;
1569 yytoken = 0;
1570 yyss = yyssa;
1571 yyvs = yyvsa;
1572 yyls = yylsa;
1573 yystacksize = YYINITDEPTH;
1575 YYDPRINTF ((stderr, "Starting parse\n"));
1577 yystate = 0;
1578 yyerrstatus = 0;
1579 yynerrs = 0;
1580 yychar = YYEMPTY; /* Cause a token to be read. */
1582 /* Initialize stack pointers.
1583 Waste one element of value and location stack
1584 so that they stay on the same level as the state stack.
1585 The wasted elements are never initialized. */
1586 yyssp = yyss;
1587 yyvsp = yyvs;
1588 yylsp = yyls;
1590 #if YYLTYPE_IS_TRIVIAL
1591 /* Initialize the default location before parsing starts. */
1592 yylloc.first_line = yylloc.last_line = 1;
1593 yylloc.first_column = yylloc.last_column = 1;
1594 #endif
1596 /* User initialization code. */
1598 /* Line 1242 of yacc.c */
1599 #line 148 "glcpp/glcpp-parse.y"
1601 yylloc.first_line = 1;
1602 yylloc.first_column = 1;
1603 yylloc.last_line = 1;
1604 yylloc.last_column = 1;
1605 yylloc.source = 0;
1608 /* Line 1242 of yacc.c */
1609 #line 1610 "glcpp/glcpp-parse.c"
1610 yylsp[0] = yylloc;
1612 goto yysetstate;
1614 /*------------------------------------------------------------.
1615 | yynewstate -- Push a new state, which is found in yystate. |
1616 `------------------------------------------------------------*/
1617 yynewstate:
1618 /* In all cases, when you get here, the value and location stacks
1619 have just been pushed. So pushing a state here evens the stacks. */
1620 yyssp++;
1622 yysetstate:
1623 *yyssp = yystate;
1625 if (yyss + yystacksize - 1 <= yyssp)
1627 /* Get the current used size of the three stacks, in elements. */
1628 YYSIZE_T yysize = yyssp - yyss + 1;
1630 #ifdef yyoverflow
1632 /* Give user a chance to reallocate the stack. Use copies of
1633 these so that the &'s don't force the real ones into
1634 memory. */
1635 YYSTYPE *yyvs1 = yyvs;
1636 yytype_int16 *yyss1 = yyss;
1637 YYLTYPE *yyls1 = yyls;
1639 /* Each stack pointer address is followed by the size of the
1640 data in use in that stack, in bytes. This used to be a
1641 conditional around just the two extra args, but that might
1642 be undefined if yyoverflow is a macro. */
1643 yyoverflow (YY_("memory exhausted"),
1644 &yyss1, yysize * sizeof (*yyssp),
1645 &yyvs1, yysize * sizeof (*yyvsp),
1646 &yyls1, yysize * sizeof (*yylsp),
1647 &yystacksize);
1649 yyls = yyls1;
1650 yyss = yyss1;
1651 yyvs = yyvs1;
1653 #else /* no yyoverflow */
1654 # ifndef YYSTACK_RELOCATE
1655 goto yyexhaustedlab;
1656 # else
1657 /* Extend the stack our own way. */
1658 if (YYMAXDEPTH <= yystacksize)
1659 goto yyexhaustedlab;
1660 yystacksize *= 2;
1661 if (YYMAXDEPTH < yystacksize)
1662 yystacksize = YYMAXDEPTH;
1665 yytype_int16 *yyss1 = yyss;
1666 union yyalloc *yyptr =
1667 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1668 if (! yyptr)
1669 goto yyexhaustedlab;
1670 YYSTACK_RELOCATE (yyss_alloc, yyss);
1671 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1672 YYSTACK_RELOCATE (yyls_alloc, yyls);
1673 # undef YYSTACK_RELOCATE
1674 if (yyss1 != yyssa)
1675 YYSTACK_FREE (yyss1);
1677 # endif
1678 #endif /* no yyoverflow */
1680 yyssp = yyss + yysize - 1;
1681 yyvsp = yyvs + yysize - 1;
1682 yylsp = yyls + yysize - 1;
1684 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1685 (unsigned long int) yystacksize));
1687 if (yyss + yystacksize - 1 <= yyssp)
1688 YYABORT;
1691 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1693 if (yystate == YYFINAL)
1694 YYACCEPT;
1696 goto yybackup;
1698 /*-----------.
1699 | yybackup. |
1700 `-----------*/
1701 yybackup:
1703 /* Do appropriate processing given the current state. Read a
1704 lookahead token if we need one and don't already have one. */
1706 /* First try to decide what to do without reference to lookahead token. */
1707 yyn = yypact[yystate];
1708 if (yyn == YYPACT_NINF)
1709 goto yydefault;
1711 /* Not known => get a lookahead token if don't already have one. */
1713 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1714 if (yychar == YYEMPTY)
1716 YYDPRINTF ((stderr, "Reading a token: "));
1717 yychar = YYLEX;
1720 if (yychar <= YYEOF)
1722 yychar = yytoken = YYEOF;
1723 YYDPRINTF ((stderr, "Now at end of input.\n"));
1725 else
1727 yytoken = YYTRANSLATE (yychar);
1728 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1731 /* If the proper action on seeing token YYTOKEN is to reduce or to
1732 detect an error, take that action. */
1733 yyn += yytoken;
1734 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1735 goto yydefault;
1736 yyn = yytable[yyn];
1737 if (yyn <= 0)
1739 if (yyn == 0 || yyn == YYTABLE_NINF)
1740 goto yyerrlab;
1741 yyn = -yyn;
1742 goto yyreduce;
1745 /* Count tokens shifted since error; after three, turn off error
1746 status. */
1747 if (yyerrstatus)
1748 yyerrstatus--;
1750 /* Shift the lookahead token. */
1751 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1753 /* Discard the shifted token. */
1754 yychar = YYEMPTY;
1756 yystate = yyn;
1757 *++yyvsp = yylval;
1758 *++yylsp = yylloc;
1759 goto yynewstate;
1762 /*-----------------------------------------------------------.
1763 | yydefault -- do the default action for the current state. |
1764 `-----------------------------------------------------------*/
1765 yydefault:
1766 yyn = yydefact[yystate];
1767 if (yyn == 0)
1768 goto yyerrlab;
1769 goto yyreduce;
1772 /*-----------------------------.
1773 | yyreduce -- Do a reduction. |
1774 `-----------------------------*/
1775 yyreduce:
1776 /* yyn is the number of a rule to reduce with. */
1777 yylen = yyr2[yyn];
1779 /* If YYLEN is nonzero, implement the default value of the action:
1780 `$$ = $1'.
1782 Otherwise, the following line sets YYVAL to garbage.
1783 This behavior is undocumented and Bison
1784 users should not rely upon it. Assigning to YYVAL
1785 unconditionally makes the parser a bit smaller, and it avoids a
1786 GCC warning that YYVAL may be used uninitialized. */
1787 yyval = yyvsp[1-yylen];
1789 /* Default location. */
1790 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1791 YY_REDUCE_PRINT (yyn);
1792 switch (yyn)
1794 case 4:
1796 /* Line 1455 of yacc.c */
1797 #line 187 "glcpp/glcpp-parse.y"
1799 glcpp_print(parser->output, "\n");
1801 break;
1803 case 5:
1805 /* Line 1455 of yacc.c */
1806 #line 190 "glcpp/glcpp-parse.y"
1808 _glcpp_parser_print_expanded_token_list (parser, (yyvsp[(1) - (1)].token_list));
1809 glcpp_print(parser->output, "\n");
1810 talloc_free ((yyvsp[(1) - (1)].token_list));
1812 break;
1814 case 8:
1816 /* Line 1455 of yacc.c */
1817 #line 200 "glcpp/glcpp-parse.y"
1819 _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), (yyvsp[(2) - (3)].ival));
1821 break;
1823 case 9:
1825 /* Line 1455 of yacc.c */
1826 #line 203 "glcpp/glcpp-parse.y"
1828 _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]), "elif", (yyvsp[(2) - (3)].ival));
1830 break;
1832 case 10:
1834 /* Line 1455 of yacc.c */
1835 #line 209 "glcpp/glcpp-parse.y"
1837 _define_object_macro (parser, & (yylsp[(2) - (4)]), (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].token_list));
1839 break;
1841 case 11:
1843 /* Line 1455 of yacc.c */
1844 #line 212 "glcpp/glcpp-parse.y"
1846 _define_function_macro (parser, & (yylsp[(2) - (6)]), (yyvsp[(2) - (6)].str), NULL, (yyvsp[(5) - (6)].token_list));
1848 break;
1850 case 12:
1852 /* Line 1455 of yacc.c */
1853 #line 215 "glcpp/glcpp-parse.y"
1855 _define_function_macro (parser, & (yylsp[(2) - (7)]), (yyvsp[(2) - (7)].str), (yyvsp[(4) - (7)].string_list), (yyvsp[(6) - (7)].token_list));
1857 break;
1859 case 13:
1861 /* Line 1455 of yacc.c */
1862 #line 218 "glcpp/glcpp-parse.y"
1864 macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (3)].str));
1865 if (macro) {
1866 hash_table_remove (parser->defines, (yyvsp[(2) - (3)].str));
1867 talloc_free (macro);
1869 talloc_free ((yyvsp[(2) - (3)].str));
1871 break;
1873 case 14:
1875 /* Line 1455 of yacc.c */
1876 #line 226 "glcpp/glcpp-parse.y"
1878 /* Be careful to only evaluate the 'if' expression if
1879 * we are not skipping. When we are skipping, we
1880 * simply push a new 0-valued 'if' onto the skip
1881 * stack.
1883 * This avoids generating diagnostics for invalid
1884 * expressions that are being skipped. */
1885 if (parser->skip_stack == NULL ||
1886 parser->skip_stack->type == SKIP_NO_SKIP)
1888 _glcpp_parser_expand_if (parser, IF_EXPANDED, (yyvsp[(2) - (3)].token_list));
1890 else
1892 _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), 0);
1893 parser->skip_stack->type = SKIP_TO_ENDIF;
1896 break;
1898 case 15:
1900 /* Line 1455 of yacc.c */
1901 #line 245 "glcpp/glcpp-parse.y"
1903 /* #if without an expression is only an error if we
1904 * are not skipping */
1905 if (parser->skip_stack == NULL ||
1906 parser->skip_stack->type == SKIP_NO_SKIP)
1908 glcpp_error(& (yylsp[(1) - (2)]), parser, "#if with no expression");
1910 _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (2)]), 0);
1912 break;
1914 case 16:
1916 /* Line 1455 of yacc.c */
1917 #line 255 "glcpp/glcpp-parse.y"
1919 macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str));
1920 talloc_free ((yyvsp[(2) - (4)].str));
1921 _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro != NULL);
1923 break;
1925 case 17:
1927 /* Line 1455 of yacc.c */
1928 #line 260 "glcpp/glcpp-parse.y"
1930 macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str));
1931 talloc_free ((yyvsp[(2) - (4)].str));
1932 _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro == NULL);
1934 break;
1936 case 18:
1938 /* Line 1455 of yacc.c */
1939 #line 265 "glcpp/glcpp-parse.y"
1941 /* Be careful to only evaluate the 'elif' expression
1942 * if we are not skipping. When we are skipping, we
1943 * simply change to a 0-valued 'elif' on the skip
1944 * stack.
1946 * This avoids generating diagnostics for invalid
1947 * expressions that are being skipped. */
1948 if (parser->skip_stack &&
1949 parser->skip_stack->type == SKIP_TO_ELSE)
1951 _glcpp_parser_expand_if (parser, ELIF_EXPANDED, (yyvsp[(2) - (3)].token_list));
1953 else
1955 _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]),
1956 "elif", 0);
1959 break;
1961 case 19:
1963 /* Line 1455 of yacc.c */
1964 #line 284 "glcpp/glcpp-parse.y"
1966 /* #elif without an expression is an error unless we
1967 * are skipping. */
1968 if (parser->skip_stack &&
1969 parser->skip_stack->type == SKIP_TO_ELSE)
1971 glcpp_error(& (yylsp[(1) - (2)]), parser, "#elif with no expression");
1973 else
1975 _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]),
1976 "elif", 0);
1977 glcpp_warning(& (yylsp[(1) - (2)]), parser, "ignoring illegal #elif without expression");
1980 break;
1982 case 20:
1984 /* Line 1455 of yacc.c */
1985 #line 299 "glcpp/glcpp-parse.y"
1987 _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]), "else", 1);
1989 break;
1991 case 21:
1993 /* Line 1455 of yacc.c */
1994 #line 302 "glcpp/glcpp-parse.y"
1996 _glcpp_parser_skip_stack_pop (parser, & (yylsp[(1) - (2)]));
1998 break;
2000 case 22:
2002 /* Line 1455 of yacc.c */
2003 #line 305 "glcpp/glcpp-parse.y"
2005 macro_t *macro = hash_table_find (parser->defines, "__VERSION__");
2006 if (macro) {
2007 hash_table_remove (parser->defines, "__VERSION__");
2008 talloc_free (macro);
2010 add_builtin_define (parser, "__VERSION__", (yyvsp[(2) - (3)].ival));
2011 glcpp_printf(parser->output, "#version %" PRIiMAX "\n", (yyvsp[(2) - (3)].ival));
2013 break;
2015 case 24:
2017 /* Line 1455 of yacc.c */
2018 #line 318 "glcpp/glcpp-parse.y"
2020 if (strlen ((yyvsp[(1) - (1)].str)) >= 3 && strncmp ((yyvsp[(1) - (1)].str), "0x", 2) == 0) {
2021 (yyval.ival) = strtoll ((yyvsp[(1) - (1)].str) + 2, NULL, 16);
2022 } else if ((yyvsp[(1) - (1)].str)[0] == '0') {
2023 (yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 8);
2024 } else {
2025 (yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 10);
2028 break;
2030 case 25:
2032 /* Line 1455 of yacc.c */
2033 #line 327 "glcpp/glcpp-parse.y"
2035 (yyval.ival) = (yyvsp[(1) - (1)].ival);
2037 break;
2039 case 27:
2041 /* Line 1455 of yacc.c */
2042 #line 333 "glcpp/glcpp-parse.y"
2044 (yyval.ival) = (yyvsp[(1) - (3)].ival) || (yyvsp[(3) - (3)].ival);
2046 break;
2048 case 28:
2050 /* Line 1455 of yacc.c */
2051 #line 336 "glcpp/glcpp-parse.y"
2053 (yyval.ival) = (yyvsp[(1) - (3)].ival) && (yyvsp[(3) - (3)].ival);
2055 break;
2057 case 29:
2059 /* Line 1455 of yacc.c */
2060 #line 339 "glcpp/glcpp-parse.y"
2062 (yyval.ival) = (yyvsp[(1) - (3)].ival) | (yyvsp[(3) - (3)].ival);
2064 break;
2066 case 30:
2068 /* Line 1455 of yacc.c */
2069 #line 342 "glcpp/glcpp-parse.y"
2071 (yyval.ival) = (yyvsp[(1) - (3)].ival) ^ (yyvsp[(3) - (3)].ival);
2073 break;
2075 case 31:
2077 /* Line 1455 of yacc.c */
2078 #line 345 "glcpp/glcpp-parse.y"
2080 (yyval.ival) = (yyvsp[(1) - (3)].ival) & (yyvsp[(3) - (3)].ival);
2082 break;
2084 case 32:
2086 /* Line 1455 of yacc.c */
2087 #line 348 "glcpp/glcpp-parse.y"
2089 (yyval.ival) = (yyvsp[(1) - (3)].ival) != (yyvsp[(3) - (3)].ival);
2091 break;
2093 case 33:
2095 /* Line 1455 of yacc.c */
2096 #line 351 "glcpp/glcpp-parse.y"
2098 (yyval.ival) = (yyvsp[(1) - (3)].ival) == (yyvsp[(3) - (3)].ival);
2100 break;
2102 case 34:
2104 /* Line 1455 of yacc.c */
2105 #line 354 "glcpp/glcpp-parse.y"
2107 (yyval.ival) = (yyvsp[(1) - (3)].ival) >= (yyvsp[(3) - (3)].ival);
2109 break;
2111 case 35:
2113 /* Line 1455 of yacc.c */
2114 #line 357 "glcpp/glcpp-parse.y"
2116 (yyval.ival) = (yyvsp[(1) - (3)].ival) <= (yyvsp[(3) - (3)].ival);
2118 break;
2120 case 36:
2122 /* Line 1455 of yacc.c */
2123 #line 360 "glcpp/glcpp-parse.y"
2125 (yyval.ival) = (yyvsp[(1) - (3)].ival) > (yyvsp[(3) - (3)].ival);
2127 break;
2129 case 37:
2131 /* Line 1455 of yacc.c */
2132 #line 363 "glcpp/glcpp-parse.y"
2134 (yyval.ival) = (yyvsp[(1) - (3)].ival) < (yyvsp[(3) - (3)].ival);
2136 break;
2138 case 38:
2140 /* Line 1455 of yacc.c */
2141 #line 366 "glcpp/glcpp-parse.y"
2143 (yyval.ival) = (yyvsp[(1) - (3)].ival) >> (yyvsp[(3) - (3)].ival);
2145 break;
2147 case 39:
2149 /* Line 1455 of yacc.c */
2150 #line 369 "glcpp/glcpp-parse.y"
2152 (yyval.ival) = (yyvsp[(1) - (3)].ival) << (yyvsp[(3) - (3)].ival);
2154 break;
2156 case 40:
2158 /* Line 1455 of yacc.c */
2159 #line 372 "glcpp/glcpp-parse.y"
2161 (yyval.ival) = (yyvsp[(1) - (3)].ival) - (yyvsp[(3) - (3)].ival);
2163 break;
2165 case 41:
2167 /* Line 1455 of yacc.c */
2168 #line 375 "glcpp/glcpp-parse.y"
2170 (yyval.ival) = (yyvsp[(1) - (3)].ival) + (yyvsp[(3) - (3)].ival);
2172 break;
2174 case 42:
2176 /* Line 1455 of yacc.c */
2177 #line 378 "glcpp/glcpp-parse.y"
2179 (yyval.ival) = (yyvsp[(1) - (3)].ival) % (yyvsp[(3) - (3)].ival);
2181 break;
2183 case 43:
2185 /* Line 1455 of yacc.c */
2186 #line 381 "glcpp/glcpp-parse.y"
2188 (yyval.ival) = (yyvsp[(1) - (3)].ival) / (yyvsp[(3) - (3)].ival);
2190 break;
2192 case 44:
2194 /* Line 1455 of yacc.c */
2195 #line 384 "glcpp/glcpp-parse.y"
2197 (yyval.ival) = (yyvsp[(1) - (3)].ival) * (yyvsp[(3) - (3)].ival);
2199 break;
2201 case 45:
2203 /* Line 1455 of yacc.c */
2204 #line 387 "glcpp/glcpp-parse.y"
2206 (yyval.ival) = ! (yyvsp[(2) - (2)].ival);
2208 break;
2210 case 46:
2212 /* Line 1455 of yacc.c */
2213 #line 390 "glcpp/glcpp-parse.y"
2215 (yyval.ival) = ~ (yyvsp[(2) - (2)].ival);
2217 break;
2219 case 47:
2221 /* Line 1455 of yacc.c */
2222 #line 393 "glcpp/glcpp-parse.y"
2224 (yyval.ival) = - (yyvsp[(2) - (2)].ival);
2226 break;
2228 case 48:
2230 /* Line 1455 of yacc.c */
2231 #line 396 "glcpp/glcpp-parse.y"
2233 (yyval.ival) = + (yyvsp[(2) - (2)].ival);
2235 break;
2237 case 49:
2239 /* Line 1455 of yacc.c */
2240 #line 399 "glcpp/glcpp-parse.y"
2242 (yyval.ival) = (yyvsp[(2) - (3)].ival);
2244 break;
2246 case 50:
2248 /* Line 1455 of yacc.c */
2249 #line 405 "glcpp/glcpp-parse.y"
2251 (yyval.string_list) = _string_list_create (parser);
2252 _string_list_append_item ((yyval.string_list), (yyvsp[(1) - (1)].str));
2253 talloc_steal ((yyval.string_list), (yyvsp[(1) - (1)].str));
2255 break;
2257 case 51:
2259 /* Line 1455 of yacc.c */
2260 #line 410 "glcpp/glcpp-parse.y"
2262 (yyval.string_list) = (yyvsp[(1) - (3)].string_list);
2263 _string_list_append_item ((yyval.string_list), (yyvsp[(3) - (3)].str));
2264 talloc_steal ((yyval.string_list), (yyvsp[(3) - (3)].str));
2266 break;
2268 case 52:
2270 /* Line 1455 of yacc.c */
2271 #line 418 "glcpp/glcpp-parse.y"
2272 { (yyval.token_list) = NULL; ;}
2273 break;
2275 case 54:
2277 /* Line 1455 of yacc.c */
2278 #line 423 "glcpp/glcpp-parse.y"
2280 yyerror (& (yylsp[(1) - (2)]), parser, "Invalid tokens after #");
2282 break;
2284 case 55:
2286 /* Line 1455 of yacc.c */
2287 #line 429 "glcpp/glcpp-parse.y"
2288 { (yyval.token_list) = NULL; ;}
2289 break;
2291 case 58:
2293 /* Line 1455 of yacc.c */
2294 #line 435 "glcpp/glcpp-parse.y"
2296 glcpp_warning(&(yylsp[(1) - (1)]), parser, "extra tokens at end of directive");
2298 break;
2300 case 59:
2302 /* Line 1455 of yacc.c */
2303 #line 442 "glcpp/glcpp-parse.y"
2305 int v = hash_table_find (parser->defines, (yyvsp[(2) - (2)].str)) ? 1 : 0;
2306 (yyval.token) = _token_create_ival (parser, INTEGER, v);
2308 break;
2310 case 60:
2312 /* Line 1455 of yacc.c */
2313 #line 446 "glcpp/glcpp-parse.y"
2315 int v = hash_table_find (parser->defines, (yyvsp[(3) - (4)].str)) ? 1 : 0;
2316 (yyval.token) = _token_create_ival (parser, INTEGER, v);
2318 break;
2320 case 62:
2322 /* Line 1455 of yacc.c */
2323 #line 455 "glcpp/glcpp-parse.y"
2325 parser->space_tokens = 1;
2326 (yyval.token_list) = _token_list_create (parser);
2327 _token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token));
2328 talloc_unlink (parser, (yyvsp[(1) - (1)].token));
2330 break;
2332 case 63:
2334 /* Line 1455 of yacc.c */
2335 #line 461 "glcpp/glcpp-parse.y"
2337 (yyval.token_list) = (yyvsp[(1) - (2)].token_list);
2338 _token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token));
2339 talloc_unlink (parser, (yyvsp[(2) - (2)].token));
2341 break;
2343 case 64:
2345 /* Line 1455 of yacc.c */
2346 #line 469 "glcpp/glcpp-parse.y"
2348 parser->space_tokens = 1;
2349 (yyval.token_list) = _token_list_create (parser);
2350 _token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token));
2351 talloc_unlink (parser, (yyvsp[(1) - (1)].token));
2353 break;
2355 case 65:
2357 /* Line 1455 of yacc.c */
2358 #line 475 "glcpp/glcpp-parse.y"
2360 (yyval.token_list) = (yyvsp[(1) - (2)].token_list);
2361 _token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token));
2362 talloc_unlink (parser, (yyvsp[(2) - (2)].token));
2364 break;
2366 case 66:
2368 /* Line 1455 of yacc.c */
2369 #line 483 "glcpp/glcpp-parse.y"
2371 (yyval.token) = _token_create_str (parser, IDENTIFIER, (yyvsp[(1) - (1)].str));
2372 (yyval.token)->location = yylloc;
2374 break;
2376 case 67:
2378 /* Line 1455 of yacc.c */
2379 #line 487 "glcpp/glcpp-parse.y"
2381 (yyval.token) = _token_create_str (parser, INTEGER_STRING, (yyvsp[(1) - (1)].str));
2382 (yyval.token)->location = yylloc;
2384 break;
2386 case 68:
2388 /* Line 1455 of yacc.c */
2389 #line 491 "glcpp/glcpp-parse.y"
2391 (yyval.token) = _token_create_ival (parser, (yyvsp[(1) - (1)].ival), (yyvsp[(1) - (1)].ival));
2392 (yyval.token)->location = yylloc;
2394 break;
2396 case 69:
2398 /* Line 1455 of yacc.c */
2399 #line 495 "glcpp/glcpp-parse.y"
2401 (yyval.token) = _token_create_str (parser, OTHER, (yyvsp[(1) - (1)].str));
2402 (yyval.token)->location = yylloc;
2404 break;
2406 case 70:
2408 /* Line 1455 of yacc.c */
2409 #line 499 "glcpp/glcpp-parse.y"
2411 (yyval.token) = _token_create_ival (parser, SPACE, SPACE);
2412 (yyval.token)->location = yylloc;
2414 break;
2416 case 71:
2418 /* Line 1455 of yacc.c */
2419 #line 506 "glcpp/glcpp-parse.y"
2420 { (yyval.ival) = '['; ;}
2421 break;
2423 case 72:
2425 /* Line 1455 of yacc.c */
2426 #line 507 "glcpp/glcpp-parse.y"
2427 { (yyval.ival) = ']'; ;}
2428 break;
2430 case 73:
2432 /* Line 1455 of yacc.c */
2433 #line 508 "glcpp/glcpp-parse.y"
2434 { (yyval.ival) = '('; ;}
2435 break;
2437 case 74:
2439 /* Line 1455 of yacc.c */
2440 #line 509 "glcpp/glcpp-parse.y"
2441 { (yyval.ival) = ')'; ;}
2442 break;
2444 case 75:
2446 /* Line 1455 of yacc.c */
2447 #line 510 "glcpp/glcpp-parse.y"
2448 { (yyval.ival) = '{'; ;}
2449 break;
2451 case 76:
2453 /* Line 1455 of yacc.c */
2454 #line 511 "glcpp/glcpp-parse.y"
2455 { (yyval.ival) = '}'; ;}
2456 break;
2458 case 77:
2460 /* Line 1455 of yacc.c */
2461 #line 512 "glcpp/glcpp-parse.y"
2462 { (yyval.ival) = '.'; ;}
2463 break;
2465 case 78:
2467 /* Line 1455 of yacc.c */
2468 #line 513 "glcpp/glcpp-parse.y"
2469 { (yyval.ival) = '&'; ;}
2470 break;
2472 case 79:
2474 /* Line 1455 of yacc.c */
2475 #line 514 "glcpp/glcpp-parse.y"
2476 { (yyval.ival) = '*'; ;}
2477 break;
2479 case 80:
2481 /* Line 1455 of yacc.c */
2482 #line 515 "glcpp/glcpp-parse.y"
2483 { (yyval.ival) = '+'; ;}
2484 break;
2486 case 81:
2488 /* Line 1455 of yacc.c */
2489 #line 516 "glcpp/glcpp-parse.y"
2490 { (yyval.ival) = '-'; ;}
2491 break;
2493 case 82:
2495 /* Line 1455 of yacc.c */
2496 #line 517 "glcpp/glcpp-parse.y"
2497 { (yyval.ival) = '~'; ;}
2498 break;
2500 case 83:
2502 /* Line 1455 of yacc.c */
2503 #line 518 "glcpp/glcpp-parse.y"
2504 { (yyval.ival) = '!'; ;}
2505 break;
2507 case 84:
2509 /* Line 1455 of yacc.c */
2510 #line 519 "glcpp/glcpp-parse.y"
2511 { (yyval.ival) = '/'; ;}
2512 break;
2514 case 85:
2516 /* Line 1455 of yacc.c */
2517 #line 520 "glcpp/glcpp-parse.y"
2518 { (yyval.ival) = '%'; ;}
2519 break;
2521 case 86:
2523 /* Line 1455 of yacc.c */
2524 #line 521 "glcpp/glcpp-parse.y"
2525 { (yyval.ival) = LEFT_SHIFT; ;}
2526 break;
2528 case 87:
2530 /* Line 1455 of yacc.c */
2531 #line 522 "glcpp/glcpp-parse.y"
2532 { (yyval.ival) = RIGHT_SHIFT; ;}
2533 break;
2535 case 88:
2537 /* Line 1455 of yacc.c */
2538 #line 523 "glcpp/glcpp-parse.y"
2539 { (yyval.ival) = '<'; ;}
2540 break;
2542 case 89:
2544 /* Line 1455 of yacc.c */
2545 #line 524 "glcpp/glcpp-parse.y"
2546 { (yyval.ival) = '>'; ;}
2547 break;
2549 case 90:
2551 /* Line 1455 of yacc.c */
2552 #line 525 "glcpp/glcpp-parse.y"
2553 { (yyval.ival) = LESS_OR_EQUAL; ;}
2554 break;
2556 case 91:
2558 /* Line 1455 of yacc.c */
2559 #line 526 "glcpp/glcpp-parse.y"
2560 { (yyval.ival) = GREATER_OR_EQUAL; ;}
2561 break;
2563 case 92:
2565 /* Line 1455 of yacc.c */
2566 #line 527 "glcpp/glcpp-parse.y"
2567 { (yyval.ival) = EQUAL; ;}
2568 break;
2570 case 93:
2572 /* Line 1455 of yacc.c */
2573 #line 528 "glcpp/glcpp-parse.y"
2574 { (yyval.ival) = NOT_EQUAL; ;}
2575 break;
2577 case 94:
2579 /* Line 1455 of yacc.c */
2580 #line 529 "glcpp/glcpp-parse.y"
2581 { (yyval.ival) = '^'; ;}
2582 break;
2584 case 95:
2586 /* Line 1455 of yacc.c */
2587 #line 530 "glcpp/glcpp-parse.y"
2588 { (yyval.ival) = '|'; ;}
2589 break;
2591 case 96:
2593 /* Line 1455 of yacc.c */
2594 #line 531 "glcpp/glcpp-parse.y"
2595 { (yyval.ival) = AND; ;}
2596 break;
2598 case 97:
2600 /* Line 1455 of yacc.c */
2601 #line 532 "glcpp/glcpp-parse.y"
2602 { (yyval.ival) = OR; ;}
2603 break;
2605 case 98:
2607 /* Line 1455 of yacc.c */
2608 #line 533 "glcpp/glcpp-parse.y"
2609 { (yyval.ival) = ';'; ;}
2610 break;
2612 case 99:
2614 /* Line 1455 of yacc.c */
2615 #line 534 "glcpp/glcpp-parse.y"
2616 { (yyval.ival) = ','; ;}
2617 break;
2619 case 100:
2621 /* Line 1455 of yacc.c */
2622 #line 535 "glcpp/glcpp-parse.y"
2623 { (yyval.ival) = '='; ;}
2624 break;
2626 case 101:
2628 /* Line 1455 of yacc.c */
2629 #line 536 "glcpp/glcpp-parse.y"
2630 { (yyval.ival) = PASTE; ;}
2631 break;
2635 /* Line 1455 of yacc.c */
2636 #line 2637 "glcpp/glcpp-parse.c"
2637 default: break;
2639 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2641 YYPOPSTACK (yylen);
2642 yylen = 0;
2643 YY_STACK_PRINT (yyss, yyssp);
2645 *++yyvsp = yyval;
2646 *++yylsp = yyloc;
2648 /* Now `shift' the result of the reduction. Determine what state
2649 that goes to, based on the state we popped back to and the rule
2650 number reduced by. */
2652 yyn = yyr1[yyn];
2654 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2655 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2656 yystate = yytable[yystate];
2657 else
2658 yystate = yydefgoto[yyn - YYNTOKENS];
2660 goto yynewstate;
2663 /*------------------------------------.
2664 | yyerrlab -- here on detecting error |
2665 `------------------------------------*/
2666 yyerrlab:
2667 /* If not already recovering from an error, report this error. */
2668 if (!yyerrstatus)
2670 ++yynerrs;
2671 #if ! YYERROR_VERBOSE
2672 yyerror (&yylloc, parser, YY_("syntax error"));
2673 #else
2675 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2676 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2678 YYSIZE_T yyalloc = 2 * yysize;
2679 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2680 yyalloc = YYSTACK_ALLOC_MAXIMUM;
2681 if (yymsg != yymsgbuf)
2682 YYSTACK_FREE (yymsg);
2683 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2684 if (yymsg)
2685 yymsg_alloc = yyalloc;
2686 else
2688 yymsg = yymsgbuf;
2689 yymsg_alloc = sizeof yymsgbuf;
2693 if (0 < yysize && yysize <= yymsg_alloc)
2695 (void) yysyntax_error (yymsg, yystate, yychar);
2696 yyerror (&yylloc, parser, yymsg);
2698 else
2700 yyerror (&yylloc, parser, YY_("syntax error"));
2701 if (yysize != 0)
2702 goto yyexhaustedlab;
2705 #endif
2708 yyerror_range[0] = yylloc;
2710 if (yyerrstatus == 3)
2712 /* If just tried and failed to reuse lookahead token after an
2713 error, discard it. */
2715 if (yychar <= YYEOF)
2717 /* Return failure if at end of input. */
2718 if (yychar == YYEOF)
2719 YYABORT;
2721 else
2723 yydestruct ("Error: discarding",
2724 yytoken, &yylval, &yylloc, parser);
2725 yychar = YYEMPTY;
2729 /* Else will try to reuse lookahead token after shifting the error
2730 token. */
2731 goto yyerrlab1;
2734 /*---------------------------------------------------.
2735 | yyerrorlab -- error raised explicitly by YYERROR. |
2736 `---------------------------------------------------*/
2737 yyerrorlab:
2739 /* Pacify compilers like GCC when the user code never invokes
2740 YYERROR and the label yyerrorlab therefore never appears in user
2741 code. */
2742 if (/*CONSTCOND*/ 0)
2743 goto yyerrorlab;
2745 yyerror_range[0] = yylsp[1-yylen];
2746 /* Do not reclaim the symbols of the rule which action triggered
2747 this YYERROR. */
2748 YYPOPSTACK (yylen);
2749 yylen = 0;
2750 YY_STACK_PRINT (yyss, yyssp);
2751 yystate = *yyssp;
2752 goto yyerrlab1;
2755 /*-------------------------------------------------------------.
2756 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2757 `-------------------------------------------------------------*/
2758 yyerrlab1:
2759 yyerrstatus = 3; /* Each real token shifted decrements this. */
2761 for (;;)
2763 yyn = yypact[yystate];
2764 if (yyn != YYPACT_NINF)
2766 yyn += YYTERROR;
2767 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2769 yyn = yytable[yyn];
2770 if (0 < yyn)
2771 break;
2775 /* Pop the current state because it cannot handle the error token. */
2776 if (yyssp == yyss)
2777 YYABORT;
2779 yyerror_range[0] = *yylsp;
2780 yydestruct ("Error: popping",
2781 yystos[yystate], yyvsp, yylsp, parser);
2782 YYPOPSTACK (1);
2783 yystate = *yyssp;
2784 YY_STACK_PRINT (yyss, yyssp);
2787 *++yyvsp = yylval;
2789 yyerror_range[1] = yylloc;
2790 /* Using YYLLOC is tempting, but would change the location of
2791 the lookahead. YYLOC is available though. */
2792 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
2793 *++yylsp = yyloc;
2795 /* Shift the error token. */
2796 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2798 yystate = yyn;
2799 goto yynewstate;
2802 /*-------------------------------------.
2803 | yyacceptlab -- YYACCEPT comes here. |
2804 `-------------------------------------*/
2805 yyacceptlab:
2806 yyresult = 0;
2807 goto yyreturn;
2809 /*-----------------------------------.
2810 | yyabortlab -- YYABORT comes here. |
2811 `-----------------------------------*/
2812 yyabortlab:
2813 yyresult = 1;
2814 goto yyreturn;
2816 #if !defined(yyoverflow) || YYERROR_VERBOSE
2817 /*-------------------------------------------------.
2818 | yyexhaustedlab -- memory exhaustion comes here. |
2819 `-------------------------------------------------*/
2820 yyexhaustedlab:
2821 yyerror (&yylloc, parser, YY_("memory exhausted"));
2822 yyresult = 2;
2823 /* Fall through. */
2824 #endif
2826 yyreturn:
2827 if (yychar != YYEMPTY)
2828 yydestruct ("Cleanup: discarding lookahead",
2829 yytoken, &yylval, &yylloc, parser);
2830 /* Do not reclaim the symbols of the rule which action triggered
2831 this YYABORT or YYACCEPT. */
2832 YYPOPSTACK (yylen);
2833 YY_STACK_PRINT (yyss, yyssp);
2834 while (yyssp != yyss)
2836 yydestruct ("Cleanup: popping",
2837 yystos[*yyssp], yyvsp, yylsp, parser);
2838 YYPOPSTACK (1);
2840 #ifndef yyoverflow
2841 if (yyss != yyssa)
2842 YYSTACK_FREE (yyss);
2843 #endif
2844 #if YYERROR_VERBOSE
2845 if (yymsg != yymsgbuf)
2846 YYSTACK_FREE (yymsg);
2847 #endif
2848 /* Make sure YYID is used. */
2849 return YYID (yyresult);
2854 /* Line 1675 of yacc.c */
2855 #line 539 "glcpp/glcpp-parse.y"
2858 string_list_t *
2859 _string_list_create (void *ctx)
2861 string_list_t *list;
2863 list = talloc (ctx, string_list_t);
2864 list->head = NULL;
2865 list->tail = NULL;
2867 return list;
2870 void
2871 _string_list_append_item (string_list_t *list, const char *str)
2873 string_node_t *node;
2875 node = talloc (list, string_node_t);
2876 node->str = talloc_strdup (node, str);
2878 node->next = NULL;
2880 if (list->head == NULL) {
2881 list->head = node;
2882 } else {
2883 list->tail->next = node;
2886 list->tail = node;
2890 _string_list_contains (string_list_t *list, const char *member, int *index)
2892 string_node_t *node;
2893 int i;
2895 if (list == NULL)
2896 return 0;
2898 for (i = 0, node = list->head; node; i++, node = node->next) {
2899 if (strcmp (node->str, member) == 0) {
2900 if (index)
2901 *index = i;
2902 return 1;
2906 return 0;
2910 _string_list_length (string_list_t *list)
2912 int length = 0;
2913 string_node_t *node;
2915 if (list == NULL)
2916 return 0;
2918 for (node = list->head; node; node = node->next)
2919 length++;
2921 return length;
2924 argument_list_t *
2925 _argument_list_create (void *ctx)
2927 argument_list_t *list;
2929 list = talloc (ctx, argument_list_t);
2930 list->head = NULL;
2931 list->tail = NULL;
2933 return list;
2936 void
2937 _argument_list_append (argument_list_t *list, token_list_t *argument)
2939 argument_node_t *node;
2941 node = talloc (list, argument_node_t);
2942 node->argument = argument;
2944 node->next = NULL;
2946 if (list->head == NULL) {
2947 list->head = node;
2948 } else {
2949 list->tail->next = node;
2952 list->tail = node;
2956 _argument_list_length (argument_list_t *list)
2958 int length = 0;
2959 argument_node_t *node;
2961 if (list == NULL)
2962 return 0;
2964 for (node = list->head; node; node = node->next)
2965 length++;
2967 return length;
2970 token_list_t *
2971 _argument_list_member_at (argument_list_t *list, int index)
2973 argument_node_t *node;
2974 int i;
2976 if (list == NULL)
2977 return NULL;
2979 node = list->head;
2980 for (i = 0; i < index; i++) {
2981 node = node->next;
2982 if (node == NULL)
2983 break;
2986 if (node)
2987 return node->argument;
2989 return NULL;
2992 /* Note: This function talloc_steal()s the str pointer. */
2993 token_t *
2994 _token_create_str (void *ctx, int type, char *str)
2996 token_t *token;
2998 token = talloc (ctx, token_t);
2999 token->type = type;
3000 token->value.str = talloc_steal (token, str);
3002 return token;
3005 token_t *
3006 _token_create_ival (void *ctx, int type, int ival)
3008 token_t *token;
3010 token = talloc (ctx, token_t);
3011 token->type = type;
3012 token->value.ival = ival;
3014 return token;
3017 token_list_t *
3018 _token_list_create (void *ctx)
3020 token_list_t *list;
3022 list = talloc (ctx, token_list_t);
3023 list->head = NULL;
3024 list->tail = NULL;
3025 list->non_space_tail = NULL;
3027 return list;
3030 void
3031 _token_list_append (token_list_t *list, token_t *token)
3033 token_node_t *node;
3035 node = talloc (list, token_node_t);
3036 node->token = talloc_reference (list, token);
3038 node->next = NULL;
3040 if (list->head == NULL) {
3041 list->head = node;
3042 } else {
3043 list->tail->next = node;
3046 list->tail = node;
3047 if (token->type != SPACE)
3048 list->non_space_tail = node;
3051 void
3052 _token_list_append_list (token_list_t *list, token_list_t *tail)
3054 if (tail == NULL || tail->head == NULL)
3055 return;
3057 if (list->head == NULL) {
3058 list->head = tail->head;
3059 } else {
3060 list->tail->next = tail->head;
3063 list->tail = tail->tail;
3064 list->non_space_tail = tail->non_space_tail;
3067 static token_list_t *
3068 _token_list_copy (void *ctx, token_list_t *other)
3070 token_list_t *copy;
3071 token_node_t *node;
3073 if (other == NULL)
3074 return NULL;
3076 copy = _token_list_create (ctx);
3077 for (node = other->head; node; node = node->next)
3078 _token_list_append (copy, node->token);
3080 return copy;
3083 static void
3084 _token_list_trim_trailing_space (token_list_t *list)
3086 token_node_t *tail, *next;
3088 if (list->non_space_tail) {
3089 tail = list->non_space_tail->next;
3090 list->non_space_tail->next = NULL;
3091 list->tail = list->non_space_tail;
3093 while (tail) {
3094 next = tail->next;
3095 talloc_free (tail);
3096 tail = next;
3101 static void
3102 _token_print (char **out, token_t *token)
3104 if (token->type < 256) {
3105 glcpp_printf (*out, "%c", token->type);
3106 return;
3109 switch (token->type) {
3110 case INTEGER:
3111 glcpp_printf (*out, "%" PRIiMAX, token->value.ival);
3112 break;
3113 case IDENTIFIER:
3114 case INTEGER_STRING:
3115 case OTHER:
3116 glcpp_print (*out, token->value.str);
3117 break;
3118 case SPACE:
3119 glcpp_print (*out, " ");
3120 break;
3121 case LEFT_SHIFT:
3122 glcpp_print (*out, "<<");
3123 break;
3124 case RIGHT_SHIFT:
3125 glcpp_print (*out, ">>");
3126 break;
3127 case LESS_OR_EQUAL:
3128 glcpp_print (*out, "<=");
3129 break;
3130 case GREATER_OR_EQUAL:
3131 glcpp_print (*out, ">=");
3132 break;
3133 case EQUAL:
3134 glcpp_print (*out, "==");
3135 break;
3136 case NOT_EQUAL:
3137 glcpp_print (*out, "!=");
3138 break;
3139 case AND:
3140 glcpp_print (*out, "&&");
3141 break;
3142 case OR:
3143 glcpp_print (*out, "||");
3144 break;
3145 case PASTE:
3146 glcpp_print (*out, "##");
3147 break;
3148 case COMMA_FINAL:
3149 glcpp_print (*out, ",");
3150 break;
3151 case PLACEHOLDER:
3152 /* Nothing to print. */
3153 break;
3154 default:
3155 assert(!"Error: Don't know how to print token.");
3156 break;
3160 /* Return a new token (talloc()ed off of 'token') formed by pasting
3161 * 'token' and 'other'. Note that this function may return 'token' or
3162 * 'other' directly rather than allocating anything new.
3164 * Caution: Only very cursory error-checking is performed to see if
3165 * the final result is a valid single token. */
3166 static token_t *
3167 _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
3169 token_t *combined = NULL;
3171 /* Pasting a placeholder onto anything makes no change. */
3172 if (other->type == PLACEHOLDER)
3173 return token;
3175 /* When 'token' is a placeholder, just return 'other'. */
3176 if (token->type == PLACEHOLDER)
3177 return other;
3179 /* A very few single-character punctuators can be combined
3180 * with another to form a multi-character punctuator. */
3181 switch (token->type) {
3182 case '<':
3183 if (other->type == '<')
3184 combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT);
3185 else if (other->type == '=')
3186 combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL);
3187 break;
3188 case '>':
3189 if (other->type == '>')
3190 combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT);
3191 else if (other->type == '=')
3192 combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
3193 break;
3194 case '=':
3195 if (other->type == '=')
3196 combined = _token_create_ival (token, EQUAL, EQUAL);
3197 break;
3198 case '!':
3199 if (other->type == '=')
3200 combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
3201 break;
3202 case '&':
3203 if (other->type == '&')
3204 combined = _token_create_ival (token, AND, AND);
3205 break;
3206 case '|':
3207 if (other->type == '|')
3208 combined = _token_create_ival (token, OR, OR);
3209 break;
3212 if (combined != NULL) {
3213 /* Inherit the location from the first token */
3214 combined->location = token->location;
3215 return combined;
3218 /* Two string-valued tokens can usually just be mashed
3219 * together.
3221 * XXX: This isn't actually legitimate. Several things here
3222 * should result in a diagnostic since the result cannot be a
3223 * valid, single pre-processing token. For example, pasting
3224 * "123" and "abc" is not legal, but we don't catch that
3225 * here. */
3226 if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) &&
3227 (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING))
3229 char *str;
3231 str = talloc_asprintf (token, "%s%s", token->value.str,
3232 other->value.str);
3233 combined = _token_create_str (token, token->type, str);
3234 combined->location = token->location;
3235 return combined;
3238 glcpp_error (&token->location, parser, "");
3239 glcpp_print (parser->info_log, "Pasting \"");
3240 _token_print (&parser->info_log, token);
3241 glcpp_print (parser->info_log, "\" and \"");
3242 _token_print (&parser->info_log, other);
3243 glcpp_print (parser->info_log, "\" does not give a valid preprocessing token.\n");
3245 return token;
3248 static void
3249 _token_list_print (glcpp_parser_t *parser, token_list_t *list)
3251 token_node_t *node;
3253 if (list == NULL)
3254 return;
3256 for (node = list->head; node; node = node->next)
3257 _token_print (&parser->output, node->token);
3260 void
3261 yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
3263 glcpp_error(locp, parser, "%s", error);
3266 static void add_builtin_define(glcpp_parser_t *parser,
3267 const char *name, int value)
3269 token_t *tok;
3270 token_list_t *list;
3272 tok = _token_create_ival (parser, INTEGER, value);
3274 list = _token_list_create(parser);
3275 _token_list_append(list, tok);
3276 _define_object_macro(parser, NULL, name, list);
3278 talloc_unlink(parser, tok);
3281 glcpp_parser_t *
3282 glcpp_parser_create (const struct gl_extensions *extensions)
3284 glcpp_parser_t *parser;
3285 int language_version;
3287 parser = talloc (NULL, glcpp_parser_t);
3289 glcpp_lex_init_extra (parser, &parser->scanner);
3290 parser->defines = hash_table_ctor (32, hash_table_string_hash,
3291 hash_table_string_compare);
3292 parser->active = NULL;
3293 parser->lexing_if = 0;
3294 parser->space_tokens = 1;
3295 parser->newline_as_space = 0;
3296 parser->in_control_line = 0;
3297 parser->paren_count = 0;
3299 parser->skip_stack = NULL;
3301 parser->lex_from_list = NULL;
3302 parser->lex_from_node = NULL;
3304 parser->output = talloc_strdup(parser, "");
3305 parser->info_log = talloc_strdup(parser, "");
3306 parser->error = 0;
3308 /* Add pre-defined macros. */
3309 add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
3310 add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
3312 if (extensions != NULL) {
3313 if (extensions->EXT_texture_array) {
3314 add_builtin_define(parser, "GL_EXT_texture_array", 1);
3317 if (extensions->ARB_fragment_coord_conventions)
3318 add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
3322 language_version = 110;
3323 add_builtin_define(parser, "__VERSION__", language_version);
3325 return parser;
3329 glcpp_parser_parse (glcpp_parser_t *parser)
3331 return yyparse (parser);
3334 void
3335 glcpp_parser_destroy (glcpp_parser_t *parser)
3337 glcpp_lex_destroy (parser->scanner);
3338 hash_table_dtor (parser->defines);
3339 talloc_free (parser);
3342 typedef enum function_status
3344 FUNCTION_STATUS_SUCCESS,
3345 FUNCTION_NOT_A_FUNCTION,
3346 FUNCTION_UNBALANCED_PARENTHESES
3347 } function_status_t;
3349 /* Find a set of function-like macro arguments by looking for a
3350 * balanced set of parentheses.
3352 * When called, 'node' should be the opening-parenthesis token, (or
3353 * perhaps preceeding SPACE tokens). Upon successful return *last will
3354 * be the last consumed node, (corresponding to the closing right
3355 * parenthesis).
3357 * Return values:
3359 * FUNCTION_STATUS_SUCCESS:
3361 * Successfully parsed a set of function arguments.
3363 * FUNCTION_NOT_A_FUNCTION:
3365 * Macro name not followed by a '('. This is not an error, but
3366 * simply that the macro name should be treated as a non-macro.
3368 * FUNCTION_UNBALANCED_PARENTHESES
3370 * Macro name is not followed by a balanced set of parentheses.
3372 static function_status_t
3373 _arguments_parse (argument_list_t *arguments,
3374 token_node_t *node,
3375 token_node_t **last)
3377 token_list_t *argument;
3378 int paren_count;
3380 node = node->next;
3382 /* Ignore whitespace before first parenthesis. */
3383 while (node && node->token->type == SPACE)
3384 node = node->next;
3386 if (node == NULL || node->token->type != '(')
3387 return FUNCTION_NOT_A_FUNCTION;
3389 node = node->next;
3391 argument = _token_list_create (arguments);
3392 _argument_list_append (arguments, argument);
3394 for (paren_count = 1; node; node = node->next) {
3395 if (node->token->type == '(')
3397 paren_count++;
3399 else if (node->token->type == ')')
3401 paren_count--;
3402 if (paren_count == 0)
3403 break;
3406 if (node->token->type == ',' &&
3407 paren_count == 1)
3409 _token_list_trim_trailing_space (argument);
3410 argument = _token_list_create (arguments);
3411 _argument_list_append (arguments, argument);
3413 else {
3414 if (argument->head == NULL) {
3415 /* Don't treat initial whitespace as
3416 * part of the arguement. */
3417 if (node->token->type == SPACE)
3418 continue;
3420 _token_list_append (argument, node->token);
3424 if (paren_count)
3425 return FUNCTION_UNBALANCED_PARENTHESES;
3427 *last = node;
3429 return FUNCTION_STATUS_SUCCESS;
3432 static token_list_t *
3433 _token_list_create_with_one_space (void *ctx)
3435 token_list_t *list;
3436 token_t *space;
3438 list = _token_list_create (ctx);
3439 space = _token_create_ival (list, SPACE, SPACE);
3440 _token_list_append (list, space);
3442 return list;
3445 static void
3446 _glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list)
3448 token_list_t *expanded;
3449 token_t *token;
3451 expanded = _token_list_create (parser);
3452 token = _token_create_ival (parser, type, type);
3453 _token_list_append (expanded, token);
3454 _glcpp_parser_expand_token_list (parser, list);
3455 _token_list_append_list (expanded, list);
3456 glcpp_parser_lex_from (parser, expanded);
3459 /* This is a helper function that's essentially part of the
3460 * implementation of _glcpp_parser_expand_node. It shouldn't be called
3461 * except for by that function.
3463 * Returns NULL if node is a simple token with no expansion, (that is,
3464 * although 'node' corresponds to an identifier defined as a
3465 * function-like macro, it is not followed with a parenthesized
3466 * argument list).
3468 * Compute the complete expansion of node (which is a function-like
3469 * macro) and subsequent nodes which are arguments.
3471 * Returns the token list that results from the expansion and sets
3472 * *last to the last node in the list that was consumed by the
3473 * expansion. Specifically, *last will be set as follows: as the
3474 * token of the closing right parenthesis.
3476 static token_list_t *
3477 _glcpp_parser_expand_function (glcpp_parser_t *parser,
3478 token_node_t *node,
3479 token_node_t **last)
3482 macro_t *macro;
3483 const char *identifier;
3484 argument_list_t *arguments;
3485 function_status_t status;
3486 token_list_t *substituted;
3487 int parameter_index;
3489 identifier = node->token->value.str;
3491 macro = hash_table_find (parser->defines, identifier);
3493 assert (macro->is_function);
3495 arguments = _argument_list_create (parser);
3496 status = _arguments_parse (arguments, node, last);
3498 switch (status) {
3499 case FUNCTION_STATUS_SUCCESS:
3500 break;
3501 case FUNCTION_NOT_A_FUNCTION:
3502 return NULL;
3503 case FUNCTION_UNBALANCED_PARENTHESES:
3504 glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
3505 return NULL;
3508 /* Replace a macro defined as empty with a SPACE token. */
3509 if (macro->replacements == NULL) {
3510 talloc_free (arguments);
3511 return _token_list_create_with_one_space (parser);
3514 if (! ((_argument_list_length (arguments) ==
3515 _string_list_length (macro->parameters)) ||
3516 (_string_list_length (macro->parameters) == 0 &&
3517 _argument_list_length (arguments) == 1 &&
3518 arguments->head->argument->head == NULL)))
3520 glcpp_error (&node->token->location, parser,
3521 "Error: macro %s invoked with %d arguments (expected %d)\n",
3522 identifier,
3523 _argument_list_length (arguments),
3524 _string_list_length (macro->parameters));
3525 return NULL;
3528 /* Perform argument substitution on the replacement list. */
3529 substituted = _token_list_create (arguments);
3531 for (node = macro->replacements->head; node; node = node->next)
3533 if (node->token->type == IDENTIFIER &&
3534 _string_list_contains (macro->parameters,
3535 node->token->value.str,
3536 &parameter_index))
3538 token_list_t *argument;
3539 argument = _argument_list_member_at (arguments,
3540 parameter_index);
3541 /* Before substituting, we expand the argument
3542 * tokens, or append a placeholder token for
3543 * an empty argument. */
3544 if (argument->head) {
3545 token_list_t *expanded_argument;
3546 expanded_argument = _token_list_copy (parser,
3547 argument);
3548 _glcpp_parser_expand_token_list (parser,
3549 expanded_argument);
3550 _token_list_append_list (substituted,
3551 expanded_argument);
3552 } else {
3553 token_t *new_token;
3555 new_token = _token_create_ival (substituted,
3556 PLACEHOLDER,
3557 PLACEHOLDER);
3558 _token_list_append (substituted, new_token);
3560 } else {
3561 _token_list_append (substituted, node->token);
3565 /* After argument substitution, and before further expansion
3566 * below, implement token pasting. */
3568 _token_list_trim_trailing_space (substituted);
3570 node = substituted->head;
3571 while (node)
3573 token_node_t *next_non_space;
3575 /* Look ahead for a PASTE token, skipping space. */
3576 next_non_space = node->next;
3577 while (next_non_space && next_non_space->token->type == SPACE)
3578 next_non_space = next_non_space->next;
3580 if (next_non_space == NULL)
3581 break;
3583 if (next_non_space->token->type != PASTE) {
3584 node = next_non_space;
3585 continue;
3588 /* Now find the next non-space token after the PASTE. */
3589 next_non_space = next_non_space->next;
3590 while (next_non_space && next_non_space->token->type == SPACE)
3591 next_non_space = next_non_space->next;
3593 if (next_non_space == NULL) {
3594 yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
3595 return NULL;
3598 node->token = _token_paste (parser, node->token, next_non_space->token);
3599 node->next = next_non_space->next;
3600 if (next_non_space == substituted->tail)
3601 substituted->tail = node;
3603 node = node->next;
3606 substituted->non_space_tail = substituted->tail;
3608 return substituted;
3611 /* Compute the complete expansion of node, (and subsequent nodes after
3612 * 'node' in the case that 'node' is a function-like macro and
3613 * subsequent nodes are arguments).
3615 * Returns NULL if node is a simple token with no expansion.
3617 * Otherwise, returns the token list that results from the expansion
3618 * and sets *last to the last node in the list that was consumed by
3619 * the expansion. Specifically, *last will be set as follows:
3621 * As 'node' in the case of object-like macro expansion.
3623 * As the token of the closing right parenthesis in the case of
3624 * function-like macro expansion.
3626 static token_list_t *
3627 _glcpp_parser_expand_node (glcpp_parser_t *parser,
3628 token_node_t *node,
3629 token_node_t **last)
3631 token_t *token = node->token;
3632 const char *identifier;
3633 macro_t *macro;
3635 /* We only expand identifiers */
3636 if (token->type != IDENTIFIER) {
3637 /* We change any COMMA into a COMMA_FINAL to prevent
3638 * it being mistaken for an argument separator
3639 * later. */
3640 if (token->type == ',') {
3641 token->type = COMMA_FINAL;
3642 token->value.ival = COMMA_FINAL;
3645 return NULL;
3648 /* Look up this identifier in the hash table. */
3649 identifier = token->value.str;
3650 macro = hash_table_find (parser->defines, identifier);
3652 /* Not a macro, so no expansion needed. */
3653 if (macro == NULL)
3654 return NULL;
3656 /* Finally, don't expand this macro if we're already actively
3657 * expanding it, (to avoid infinite recursion). */
3658 if (_active_list_contains (parser->active, identifier)) {
3659 /* We change the token type here from IDENTIFIER to
3660 * OTHER to prevent any future expansion of this
3661 * unexpanded token. */
3662 char *str;
3663 token_list_t *expansion;
3664 token_t *final;
3666 str = talloc_strdup (parser, token->value.str);
3667 final = _token_create_str (parser, OTHER, str);
3668 expansion = _token_list_create (parser);
3669 _token_list_append (expansion, final);
3670 *last = node;
3671 return expansion;
3674 if (! macro->is_function)
3676 *last = node;
3678 /* Replace a macro defined as empty with a SPACE token. */
3679 if (macro->replacements == NULL)
3680 return _token_list_create_with_one_space (parser);
3682 return _token_list_copy (parser, macro->replacements);
3685 return _glcpp_parser_expand_function (parser, node, last);
3688 /* Push a new identifier onto the active list, returning the new list.
3690 * Here, 'marker' is the token node that appears in the list after the
3691 * expansion of 'identifier'. That is, when the list iterator begins
3692 * examinging 'marker', then it is time to pop this node from the
3693 * active stack.
3695 active_list_t *
3696 _active_list_push (active_list_t *list,
3697 const char *identifier,
3698 token_node_t *marker)
3700 active_list_t *node;
3702 node = talloc (list, active_list_t);
3703 node->identifier = talloc_strdup (node, identifier);
3704 node->marker = marker;
3705 node->next = list;
3707 return node;
3710 active_list_t *
3711 _active_list_pop (active_list_t *list)
3713 active_list_t *node = list;
3715 if (node == NULL)
3716 return NULL;
3718 node = list->next;
3719 talloc_free (list);
3721 return node;
3725 _active_list_contains (active_list_t *list, const char *identifier)
3727 active_list_t *node;
3729 if (list == NULL)
3730 return 0;
3732 for (node = list; node; node = node->next)
3733 if (strcmp (node->identifier, identifier) == 0)
3734 return 1;
3736 return 0;
3739 /* Walk over the token list replacing nodes with their expansion.
3740 * Whenever nodes are expanded the walking will walk over the new
3741 * nodes, continuing to expand as necessary. The results are placed in
3742 * 'list' itself;
3744 static void
3745 _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
3746 token_list_t *list)
3748 token_node_t *node_prev;
3749 token_node_t *node, *last = NULL;
3750 token_list_t *expansion;
3752 if (list == NULL)
3753 return;
3755 _token_list_trim_trailing_space (list);
3757 node_prev = NULL;
3758 node = list->head;
3760 while (node) {
3762 while (parser->active && parser->active->marker == node)
3763 parser->active = _active_list_pop (parser->active);
3765 /* Find the expansion for node, which will replace all
3766 * nodes from node to last, inclusive. */
3767 expansion = _glcpp_parser_expand_node (parser, node, &last);
3768 if (expansion) {
3769 token_node_t *n;
3771 for (n = node; n != last->next; n = n->next)
3772 while (parser->active &&
3773 parser->active->marker == n)
3775 parser->active = _active_list_pop (parser->active);
3778 parser->active = _active_list_push (parser->active,
3779 node->token->value.str,
3780 last->next);
3782 /* Splice expansion into list, supporting a
3783 * simple deletion if the expansion is
3784 * empty. */
3785 if (expansion->head) {
3786 if (node_prev)
3787 node_prev->next = expansion->head;
3788 else
3789 list->head = expansion->head;
3790 expansion->tail->next = last->next;
3791 if (last == list->tail)
3792 list->tail = expansion->tail;
3793 } else {
3794 if (node_prev)
3795 node_prev->next = last->next;
3796 else
3797 list->head = last->next;
3798 if (last == list->tail)
3799 list->tail = NULL;
3801 } else {
3802 node_prev = node;
3804 node = node_prev ? node_prev->next : list->head;
3807 while (parser->active)
3808 parser->active = _active_list_pop (parser->active);
3810 list->non_space_tail = list->tail;
3813 void
3814 _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
3815 token_list_t *list)
3817 if (list == NULL)
3818 return;
3820 _glcpp_parser_expand_token_list (parser, list);
3822 _token_list_trim_trailing_space (list);
3824 _token_list_print (parser, list);
3827 static void
3828 _check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc,
3829 const char *identifier)
3831 /* According to the GLSL specification, macro names starting with "__"
3832 * or "GL_" are reserved for future use. So, don't allow them.
3834 if (strncmp(identifier, "__", 2) == 0) {
3835 glcpp_error (loc, parser, "Macro names starting with \"__\" are reserved.\n");
3837 if (strncmp(identifier, "GL_", 3) == 0) {
3838 glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
3842 void
3843 _define_object_macro (glcpp_parser_t *parser,
3844 YYLTYPE *loc,
3845 const char *identifier,
3846 token_list_t *replacements)
3848 macro_t *macro;
3850 if (loc != NULL)
3851 _check_for_reserved_macro_name(parser, loc, identifier);
3853 macro = talloc (parser, macro_t);
3855 macro->is_function = 0;
3856 macro->parameters = NULL;
3857 macro->identifier = talloc_strdup (macro, identifier);
3858 macro->replacements = talloc_steal (macro, replacements);
3860 hash_table_insert (parser->defines, macro, identifier);
3863 void
3864 _define_function_macro (glcpp_parser_t *parser,
3865 YYLTYPE *loc,
3866 const char *identifier,
3867 string_list_t *parameters,
3868 token_list_t *replacements)
3870 macro_t *macro;
3872 _check_for_reserved_macro_name(parser, loc, identifier);
3874 macro = talloc (parser, macro_t);
3876 macro->is_function = 1;
3877 macro->parameters = talloc_steal (macro, parameters);
3878 macro->identifier = talloc_strdup (macro, identifier);
3879 macro->replacements = talloc_steal (macro, replacements);
3881 hash_table_insert (parser->defines, macro, identifier);
3884 static int
3885 glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
3887 token_node_t *node;
3888 int ret;
3890 if (parser->lex_from_list == NULL) {
3891 ret = glcpp_lex (yylval, yylloc, parser->scanner);
3893 /* XXX: This ugly block of code exists for the sole
3894 * purpose of converting a NEWLINE token into a SPACE
3895 * token, but only in the case where we have seen a
3896 * function-like macro name, but have not yet seen its
3897 * closing parenthesis.
3899 * There's perhaps a more compact way to do this with
3900 * mid-rule actions in the grammar.
3902 * I'm definitely not pleased with the complexity of
3903 * this code here.
3905 if (parser->newline_as_space)
3907 if (ret == '(') {
3908 parser->paren_count++;
3909 } else if (ret == ')') {
3910 parser->paren_count--;
3911 if (parser->paren_count == 0)
3912 parser->newline_as_space = 0;
3913 } else if (ret == NEWLINE) {
3914 ret = SPACE;
3915 } else if (ret != SPACE) {
3916 if (parser->paren_count == 0)
3917 parser->newline_as_space = 0;
3920 else if (parser->in_control_line)
3922 if (ret == NEWLINE)
3923 parser->in_control_line = 0;
3925 else if (ret == HASH_DEFINE_OBJ || ret == HASH_DEFINE_FUNC ||
3926 ret == HASH_UNDEF || ret == HASH_IF ||
3927 ret == HASH_IFDEF || ret == HASH_IFNDEF ||
3928 ret == HASH_ELIF || ret == HASH_ELSE ||
3929 ret == HASH_ENDIF || ret == HASH)
3931 parser->in_control_line = 1;
3933 else if (ret == IDENTIFIER)
3935 macro_t *macro;
3936 macro = hash_table_find (parser->defines,
3937 yylval->str);
3938 if (macro && macro->is_function) {
3939 parser->newline_as_space = 1;
3940 parser->paren_count = 0;
3944 return ret;
3947 node = parser->lex_from_node;
3949 if (node == NULL) {
3950 talloc_free (parser->lex_from_list);
3951 parser->lex_from_list = NULL;
3952 return NEWLINE;
3955 *yylval = node->token->value;
3956 ret = node->token->type;
3958 parser->lex_from_node = node->next;
3960 return ret;
3963 static void
3964 glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list)
3966 token_node_t *node;
3968 assert (parser->lex_from_list == NULL);
3970 /* Copy list, eliminating any space tokens. */
3971 parser->lex_from_list = _token_list_create (parser);
3973 for (node = list->head; node; node = node->next) {
3974 if (node->token->type == SPACE)
3975 continue;
3976 _token_list_append (parser->lex_from_list, node->token);
3979 talloc_free (list);
3981 parser->lex_from_node = parser->lex_from_list->head;
3983 /* It's possible the list consisted of nothing but whitespace. */
3984 if (parser->lex_from_node == NULL) {
3985 talloc_free (parser->lex_from_list);
3986 parser->lex_from_list = NULL;
3990 static void
3991 _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
3992 int condition)
3994 skip_type_t current = SKIP_NO_SKIP;
3995 skip_node_t *node;
3997 if (parser->skip_stack)
3998 current = parser->skip_stack->type;
4000 node = talloc (parser, skip_node_t);
4001 node->loc = *loc;
4003 if (current == SKIP_NO_SKIP) {
4004 if (condition)
4005 node->type = SKIP_NO_SKIP;
4006 else
4007 node->type = SKIP_TO_ELSE;
4008 } else {
4009 node->type = SKIP_TO_ENDIF;
4012 node->next = parser->skip_stack;
4013 parser->skip_stack = node;
4016 static void
4017 _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
4018 const char *type, int condition)
4020 if (parser->skip_stack == NULL) {
4021 glcpp_error (loc, parser, "%s without #if\n", type);
4022 return;
4025 if (parser->skip_stack->type == SKIP_TO_ELSE) {
4026 if (condition)
4027 parser->skip_stack->type = SKIP_NO_SKIP;
4028 } else {
4029 parser->skip_stack->type = SKIP_TO_ENDIF;
4033 static void
4034 _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc)
4036 skip_node_t *node;
4038 if (parser->skip_stack == NULL) {
4039 glcpp_error (loc, parser, "#endif without #if\n");
4040 return;
4043 node = parser->skip_stack;
4044 parser->skip_stack = node->next;
4045 talloc_free (node);