Do not do src->dest copy if register would not be allocated a normal register
[official-gcc.git] / gcc / cexp.c
blobf9c6d847406bc09f8f260ea11c35a4cebbebf350
2 /* A Bison parser, made from cexp.y
3 by GNU Bison version 1.25
4 */
6 #define YYBISON 1 /* Identify Bison output. */
8 #define INT 258
9 #define CHAR 259
10 #define NAME 260
11 #define ERROR 261
12 #define OR 262
13 #define AND 263
14 #define EQUAL 264
15 #define NOTEQUAL 265
16 #define LEQ 266
17 #define GEQ 267
18 #define LSH 268
19 #define RSH 269
20 #define UNARY 270
22 #line 27 "cexp.y"
24 #include "config.h"
25 #ifdef __STDC__
26 # include <stdarg.h>
27 #else
28 # include <varargs.h>
29 #endif
31 #define PRINTF_PROTO(ARGS, m, n) PVPROTO (ARGS) ATTRIBUTE_PRINTF(m, n)
33 #define PRINTF_PROTO_1(ARGS) PRINTF_PROTO(ARGS, 1, 2)
35 #include "system.h"
36 #include <setjmp.h>
37 /* #define YYDEBUG 1 */
39 #ifdef MULTIBYTE_CHARS
40 #include <locale.h>
41 #endif
43 #include "gansidecl.h"
45 typedef unsigned char U_CHAR;
47 /* This is used for communicating lists of keywords with cccp.c. */
48 struct arglist {
49 struct arglist *next;
50 U_CHAR *name;
51 int length;
52 int argno;
55 /* Find the largest host integer type and set its size and type.
56 Watch out: on some crazy hosts `long' is shorter than `int'. */
58 #ifndef HOST_WIDE_INT
59 # if HAVE_INTTYPES_H
60 # include <inttypes.h>
61 # define HOST_WIDE_INT intmax_t
62 # define unsigned_HOST_WIDE_INT uintmax_t
63 # else
64 # if (HOST_BITS_PER_LONG <= HOST_BITS_PER_INT && HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_INT)
65 # define HOST_WIDE_INT int
66 # else
67 # if (HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_LONG || ! (defined LONG_LONG_MAX || defined LLONG_MAX))
68 # define HOST_WIDE_INT long
69 # else
70 # define HOST_WIDE_INT long long
71 # endif
72 # endif
73 # endif
74 #endif
76 #ifndef unsigned_HOST_WIDE_INT
77 #define unsigned_HOST_WIDE_INT unsigned HOST_WIDE_INT
78 #endif
80 #ifndef CHAR_BIT
81 #define CHAR_BIT 8
82 #endif
84 #ifndef HOST_BITS_PER_WIDE_INT
85 #define HOST_BITS_PER_WIDE_INT (CHAR_BIT * sizeof (HOST_WIDE_INT))
86 #endif
88 HOST_WIDE_INT parse_c_expression PROTO((char *, int));
90 static int yylex PROTO((void));
91 static void yyerror PROTO((char *)) __attribute__ ((noreturn));
92 static HOST_WIDE_INT expression_value;
93 #ifdef TEST_EXP_READER
94 static int expression_signedp;
95 #endif
97 static jmp_buf parse_return_error;
99 /* Nonzero means count most punctuation as part of a name. */
100 static int keyword_parsing = 0;
102 /* Nonzero means do not evaluate this expression.
103 This is a count, since unevaluated expressions can nest. */
104 static int skip_evaluation;
106 /* Nonzero means warn if undefined identifiers are evaluated. */
107 static int warn_undef;
109 /* some external tables of character types */
110 extern unsigned char is_idstart[], is_idchar[], is_space[];
112 /* Flag for -pedantic. */
113 extern int pedantic;
115 /* Flag for -traditional. */
116 extern int traditional;
118 /* Flag for -lang-c89. */
119 extern int c89;
121 #ifndef CHAR_TYPE_SIZE
122 #define CHAR_TYPE_SIZE BITS_PER_UNIT
123 #endif
125 #ifndef INT_TYPE_SIZE
126 #define INT_TYPE_SIZE BITS_PER_WORD
127 #endif
129 #ifndef LONG_TYPE_SIZE
130 #define LONG_TYPE_SIZE BITS_PER_WORD
131 #endif
133 #ifndef WCHAR_TYPE_SIZE
134 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
135 #endif
137 #ifndef MAX_CHAR_TYPE_SIZE
138 #define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE
139 #endif
141 #ifndef MAX_INT_TYPE_SIZE
142 #define MAX_INT_TYPE_SIZE INT_TYPE_SIZE
143 #endif
145 #ifndef MAX_LONG_TYPE_SIZE
146 #define MAX_LONG_TYPE_SIZE LONG_TYPE_SIZE
147 #endif
149 #ifndef MAX_WCHAR_TYPE_SIZE
150 #define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
151 #endif
153 #define MAX_CHAR_TYPE_MASK (MAX_CHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT \
154 ? (~ (~ (HOST_WIDE_INT) 0 << MAX_CHAR_TYPE_SIZE)) \
155 : ~ (HOST_WIDE_INT) 0)
157 #define MAX_WCHAR_TYPE_MASK (MAX_WCHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT \
158 ? ~ (~ (HOST_WIDE_INT) 0 << MAX_WCHAR_TYPE_SIZE) \
159 : ~ (HOST_WIDE_INT) 0)
161 /* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
162 Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.
163 Suppose SIGNEDP is negative if the result is signed, zero if unsigned.
164 Then this yields nonzero if overflow occurred during the addition.
165 Overflow occurs if A and B have the same sign, but A and SUM differ in sign,
166 and SIGNEDP is negative.
167 Use `^' to test whether signs differ, and `< 0' to isolate the sign. */
168 #define overflow_sum_sign(a, b, sum, signedp) \
169 ((~((a) ^ (b)) & ((a) ^ (sum)) & (signedp)) < 0)
171 struct constant;
173 GENERIC_PTR xmalloc PROTO((size_t));
174 HOST_WIDE_INT parse_escape PROTO((char **, HOST_WIDE_INT));
175 int check_assertion PROTO((U_CHAR *, int, int, struct arglist *));
176 struct hashnode *lookup PROTO((U_CHAR *, int, int));
177 void error PRINTF_PROTO_1((char *, ...));
178 void pedwarn PRINTF_PROTO_1((char *, ...));
179 void warning PRINTF_PROTO_1((char *, ...));
181 static int parse_number PROTO((int));
182 static HOST_WIDE_INT left_shift PROTO((struct constant *, unsigned_HOST_WIDE_INT));
183 static HOST_WIDE_INT right_shift PROTO((struct constant *, unsigned_HOST_WIDE_INT));
184 static void integer_overflow PROTO((void));
186 /* `signedp' values */
187 #define SIGNED (~0)
188 #define UNSIGNED 0
190 #line 251 "cexp.y"
191 typedef union {
192 struct constant {HOST_WIDE_INT value; int signedp;} integer;
193 struct name {U_CHAR *address; int length;} name;
194 struct arglist *keywords;
195 } YYSTYPE;
196 #include <stdio.h>
198 #ifndef __cplusplus
199 #ifndef __STDC__
200 #define const
201 #endif
202 #endif
206 #define YYFINAL 77
207 #define YYFLAG -32768
208 #define YYNTBASE 34
210 #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 43)
212 static const char yytranslate[] = { 0,
213 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
214 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
215 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
216 2, 2, 29, 2, 31, 2, 27, 14, 2, 32,
217 33, 25, 23, 9, 24, 2, 26, 2, 2, 2,
218 2, 2, 2, 2, 2, 2, 2, 8, 2, 17,
219 2, 18, 7, 2, 2, 2, 2, 2, 2, 2,
220 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
221 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
222 2, 2, 2, 13, 2, 2, 2, 2, 2, 2,
223 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
224 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
225 2, 2, 2, 12, 2, 30, 2, 2, 2, 2,
226 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
227 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
228 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
229 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
230 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
231 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
232 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
233 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
234 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
235 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
236 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
237 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
238 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
239 6, 10, 11, 15, 16, 19, 20, 21, 22, 28
242 #if YYDEBUG != 0
243 static const short yyprhs[] = { 0,
244 0, 2, 4, 8, 11, 14, 17, 20, 23, 24,
245 31, 35, 39, 43, 47, 51, 55, 59, 63, 67,
246 71, 75, 79, 83, 87, 91, 95, 99, 100, 105,
247 106, 111, 112, 113, 121, 123, 125, 127, 128, 133
250 static const short yyrhs[] = { 35,
251 0, 36, 0, 35, 9, 36, 0, 24, 36, 0,
252 29, 36, 0, 23, 36, 0, 30, 36, 0, 31,
253 5, 0, 0, 31, 5, 37, 32, 42, 33, 0,
254 32, 35, 33, 0, 36, 25, 36, 0, 36, 26,
255 36, 0, 36, 27, 36, 0, 36, 23, 36, 0,
256 36, 24, 36, 0, 36, 21, 36, 0, 36, 22,
257 36, 0, 36, 15, 36, 0, 36, 16, 36, 0,
258 36, 19, 36, 0, 36, 20, 36, 0, 36, 17,
259 36, 0, 36, 18, 36, 0, 36, 14, 36, 0,
260 36, 13, 36, 0, 36, 12, 36, 0, 0, 36,
261 11, 38, 36, 0, 0, 36, 10, 39, 36, 0,
262 0, 0, 36, 7, 40, 36, 8, 41, 36, 0,
263 3, 0, 4, 0, 5, 0, 0, 32, 42, 33,
264 42, 0, 5, 42, 0
267 #endif
269 #if YYDEBUG != 0
270 static const short yyrline[] = { 0,
271 281, 291, 292, 299, 304, 307, 309, 312, 316, 318,
272 323, 328, 341, 358, 371, 377, 383, 389, 395, 398,
273 401, 408, 415, 422, 429, 432, 435, 438, 441, 444,
274 447, 450, 452, 455, 458, 460, 462, 470, 472, 485
276 #endif
279 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
281 static const char * const yytname[] = { "$","error","$undefined.","INT","CHAR",
282 "NAME","ERROR","'?'","':'","','","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL",
283 "'<'","'>'","LEQ","GEQ","LSH","RSH","'+'","'-'","'*'","'/'","'%'","UNARY","'!'",
284 "'~'","'#'","'('","')'","start","exp1","exp","@1","@2","@3","@4","@5","keywords", NULL
286 #endif
288 static const short yyr1[] = { 0,
289 34, 35, 35, 36, 36, 36, 36, 36, 37, 36,
290 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
291 36, 36, 36, 36, 36, 36, 36, 38, 36, 39,
292 36, 40, 41, 36, 36, 36, 36, 42, 42, 42
295 static const short yyr2[] = { 0,
296 1, 1, 3, 2, 2, 2, 2, 2, 0, 6,
297 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
298 3, 3, 3, 3, 3, 3, 3, 0, 4, 0,
299 4, 0, 0, 7, 1, 1, 1, 0, 4, 2
302 static const short yydefact[] = { 0,
303 35, 36, 37, 0, 0, 0, 0, 0, 0, 1,
304 2, 6, 4, 5, 7, 8, 0, 0, 32, 30,
305 28, 0, 0, 0, 0, 0, 0, 0, 0, 0,
306 0, 0, 0, 0, 0, 0, 0, 0, 11, 3,
307 0, 0, 0, 27, 26, 25, 19, 20, 23, 24,
308 21, 22, 17, 18, 15, 16, 12, 13, 14, 38,
309 0, 31, 29, 38, 38, 0, 33, 40, 0, 10,
310 0, 38, 34, 39, 0, 0, 0
313 static const short yydefgoto[] = { 75,
314 10, 11, 38, 43, 42, 41, 71, 66
317 static const short yypact[] = { 12,
318 -32768,-32768,-32768, 12, 12, 12, 12, 1, 12, 4,
319 79,-32768,-32768,-32768,-32768, -21, 31, 12,-32768,-32768,
320 -32768, 12, 12, 12, 12, 12, 12, 12, 12, 12,
321 12, 12, 12, 12, 12, 12, 12, 30,-32768, 79,
322 12, 12, 12, 110, 124, 137, 148, 148, 155, 155,
323 155, 155, 160, 160, -17, -17,-32768,-32768,-32768, 2,
324 58, 34, 95, 2, 2, 54,-32768,-32768, 55,-32768,
325 12, 2, 79,-32768, 63, 188,-32768
328 static const short yypgoto[] = {-32768,
329 180, -4,-32768,-32768,-32768,-32768,-32768, -60
333 #define YYLAST 189
336 static const short yytable[] = { 12,
337 13, 14, 15, 68, 69, 16, 64, 35, 36, 37,
338 -9, 74, 18, 40, 1, 2, 3, 44, 45, 46,
339 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
340 57, 58, 59, 65, 4, 5, 61, 62, 63, 18,
341 6, 7, 8, 9, 21, 22, 23, 24, 25, 26,
342 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
343 37, 60, 76, 39, 19, 67, 73, 20, 21, 22,
344 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
345 33, 34, 35, 36, 37, 19, 70, 72, 20, 21,
346 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
347 32, 33, 34, 35, 36, 37, 22, 23, 24, 25,
348 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
349 36, 37, 23, 24, 25, 26, 27, 28, 29, 30,
350 31, 32, 33, 34, 35, 36, 37, 24, 25, 26,
351 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
352 37, 25, 26, 27, 28, 29, 30, 31, 32, 33,
353 34, 35, 36, 37, 27, 28, 29, 30, 31, 32,
354 33, 34, 35, 36, 37, 31, 32, 33, 34, 35,
355 36, 37, 33, 34, 35, 36, 37, 77, 17
358 static const short yycheck[] = { 4,
359 5, 6, 7, 64, 65, 5, 5, 25, 26, 27,
360 32, 72, 9, 18, 3, 4, 5, 22, 23, 24,
361 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
362 35, 36, 37, 32, 23, 24, 41, 42, 43, 9,
363 29, 30, 31, 32, 11, 12, 13, 14, 15, 16,
364 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
365 27, 32, 0, 33, 7, 8, 71, 10, 11, 12,
366 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
367 23, 24, 25, 26, 27, 7, 33, 33, 10, 11,
368 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
369 22, 23, 24, 25, 26, 27, 12, 13, 14, 15,
370 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
371 26, 27, 13, 14, 15, 16, 17, 18, 19, 20,
372 21, 22, 23, 24, 25, 26, 27, 14, 15, 16,
373 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
374 27, 15, 16, 17, 18, 19, 20, 21, 22, 23,
375 24, 25, 26, 27, 17, 18, 19, 20, 21, 22,
376 23, 24, 25, 26, 27, 21, 22, 23, 24, 25,
377 26, 27, 23, 24, 25, 26, 27, 0, 9
379 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
380 #line 3 "/usr/cygnus/latest-940103/share/bison.simple"
382 /* Skeleton output parser for bison,
383 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
385 This program is free software; you can redistribute it and/or modify
386 it under the terms of the GNU General Public License as published by
387 the Free Software Foundation; either version 2, or (at your option)
388 any later version.
390 This program is distributed in the hope that it will be useful,
391 but WITHOUT ANY WARRANTY; without even the implied warranty of
392 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
393 GNU General Public License for more details.
395 You should have received a copy of the GNU General Public License
396 along with this program; if not, write to the Free Software
397 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
399 /* As a special exception, when this file is copied by Bison into a
400 Bison output file, you may use that output file without restriction.
401 This special exception was added by the Free Software Foundation
402 in version 1.24 of Bison. */
404 #ifndef alloca
405 #ifdef __GNUC__
406 #define alloca __builtin_alloca
407 #else /* not GNU C. */
408 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
409 #include <alloca.h>
410 #else /* not sparc */
411 #if defined (MSDOS) && !defined (__TURBOC__)
412 #include <malloc.h>
413 #else /* not MSDOS, or __TURBOC__ */
414 #if defined(_AIX)
415 #include <malloc.h>
416 #pragma alloca
417 #else /* not MSDOS, __TURBOC__, or _AIX */
418 #ifdef __hpux
419 #ifdef __cplusplus
420 extern "C" {
421 void *alloca (unsigned int);
423 #else /* not __cplusplus */
424 void *alloca ();
425 #endif /* not __cplusplus */
426 #endif /* __hpux */
427 #endif /* not _AIX */
428 #endif /* not MSDOS, or __TURBOC__ */
429 #endif /* not sparc. */
430 #endif /* not GNU C. */
431 #endif /* alloca not defined. */
433 /* This is the parser code that is written into each bison parser
434 when the %semantic_parser declaration is not specified in the grammar.
435 It was written by Richard Stallman by simplifying the hairy parser
436 used when %semantic_parser is specified. */
438 /* Note: there must be only one dollar sign in this file.
439 It is replaced by the list of actions, each action
440 as one case of the switch. */
442 #define yyerrok (yyerrstatus = 0)
443 #define yyclearin (yychar = YYEMPTY)
444 #define YYEMPTY -2
445 #define YYEOF 0
446 #define YYACCEPT return(0)
447 #define YYABORT return(1)
448 #define YYERROR goto yyerrlab1
449 /* Like YYERROR except do call yyerror.
450 This remains here temporarily to ease the
451 transition to the new meaning of YYERROR, for GCC.
452 Once GCC version 2 has supplanted version 1, this can go. */
453 #define YYFAIL goto yyerrlab
454 #define YYRECOVERING() (!!yyerrstatus)
455 #define YYBACKUP(token, value) \
456 do \
457 if (yychar == YYEMPTY && yylen == 1) \
458 { yychar = (token), yylval = (value); \
459 yychar1 = YYTRANSLATE (yychar); \
460 YYPOPSTACK; \
461 goto yybackup; \
463 else \
464 { yyerror ("syntax error: cannot back up"); YYERROR; } \
465 while (0)
467 #define YYTERROR 1
468 #define YYERRCODE 256
470 #ifndef YYPURE
471 #define YYLEX yylex()
472 #endif
474 #ifdef YYPURE
475 #ifdef YYLSP_NEEDED
476 #ifdef YYLEX_PARAM
477 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
478 #else
479 #define YYLEX yylex(&yylval, &yylloc)
480 #endif
481 #else /* not YYLSP_NEEDED */
482 #ifdef YYLEX_PARAM
483 #define YYLEX yylex(&yylval, YYLEX_PARAM)
484 #else
485 #define YYLEX yylex(&yylval)
486 #endif
487 #endif /* not YYLSP_NEEDED */
488 #endif
490 /* If nonreentrant, generate the variables here */
492 #ifndef YYPURE
494 int yychar; /* the lookahead symbol */
495 YYSTYPE yylval; /* the semantic value of the */
496 /* lookahead symbol */
498 #ifdef YYLSP_NEEDED
499 YYLTYPE yylloc; /* location data for the lookahead */
500 /* symbol */
501 #endif
503 int yynerrs; /* number of parse errors so far */
504 #endif /* not YYPURE */
506 #if YYDEBUG != 0
507 int yydebug; /* nonzero means print parse trace */
508 /* Since this is uninitialized, it does not stop multiple parsers
509 from coexisting. */
510 #endif
512 /* YYINITDEPTH indicates the initial size of the parser's stacks */
514 #ifndef YYINITDEPTH
515 #define YYINITDEPTH 200
516 #endif
518 /* YYMAXDEPTH is the maximum size the stacks can grow to
519 (effective only if the built-in stack extension method is used). */
521 #if YYMAXDEPTH == 0
522 #undef YYMAXDEPTH
523 #endif
525 #ifndef YYMAXDEPTH
526 #define YYMAXDEPTH 10000
527 #endif
529 /* Prevent warning if -Wstrict-prototypes. */
530 #ifdef __GNUC__
531 int yyparse (void);
532 #endif
534 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
535 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
536 #else /* not GNU C or C++ */
537 #ifndef __cplusplus
539 /* This is the most reliable way to avoid incompatibilities
540 in available built-in functions on various systems. */
541 static void
542 __yy_memcpy (to, from, count)
543 char *to;
544 char *from;
545 int count;
547 register char *f = from;
548 register char *t = to;
549 register int i = count;
551 while (i-- > 0)
552 *t++ = *f++;
555 #else /* __cplusplus */
557 /* This is the most reliable way to avoid incompatibilities
558 in available built-in functions on various systems. */
559 static void
560 __yy_memcpy (char *to, char *from, int count)
562 register char *f = from;
563 register char *t = to;
564 register int i = count;
566 while (i-- > 0)
567 *t++ = *f++;
570 #endif
571 #endif
573 #line 196 "/usr/cygnus/latest-940103/share/bison.simple"
575 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
576 into yyparse. The argument should have type void *.
577 It should actually point to an object.
578 Grammar actions can access the variable by casting it
579 to the proper pointer type. */
581 #ifdef YYPARSE_PARAM
582 #ifdef __cplusplus
583 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
584 #define YYPARSE_PARAM_DECL
585 #else /* not __cplusplus */
586 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
587 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
588 #endif /* not __cplusplus */
589 #else /* not YYPARSE_PARAM */
590 #define YYPARSE_PARAM_ARG
591 #define YYPARSE_PARAM_DECL
592 #endif /* not YYPARSE_PARAM */
595 yyparse(YYPARSE_PARAM_ARG)
596 YYPARSE_PARAM_DECL
598 register int yystate;
599 register int yyn;
600 register short *yyssp;
601 register YYSTYPE *yyvsp;
602 int yyerrstatus; /* number of tokens to shift before error messages enabled */
603 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
605 short yyssa[YYINITDEPTH]; /* the state stack */
606 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
608 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
609 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
611 #ifdef YYLSP_NEEDED
612 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
613 YYLTYPE *yyls = yylsa;
614 YYLTYPE *yylsp;
616 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
617 #else
618 #define YYPOPSTACK (yyvsp--, yyssp--)
619 #endif
621 int yystacksize = YYINITDEPTH;
623 #ifdef YYPURE
624 int yychar;
625 YYSTYPE yylval;
626 int yynerrs;
627 #ifdef YYLSP_NEEDED
628 YYLTYPE yylloc;
629 #endif
630 #endif
632 YYSTYPE yyval; /* the variable used to return */
633 /* semantic values from the action */
634 /* routines */
636 int yylen;
638 #if YYDEBUG != 0
639 if (yydebug)
640 fprintf(stderr, "Starting parse\n");
641 #endif
643 yystate = 0;
644 yyerrstatus = 0;
645 yynerrs = 0;
646 yychar = YYEMPTY; /* Cause a token to be read. */
648 /* Initialize stack pointers.
649 Waste one element of value and location stack
650 so that they stay on the same level as the state stack.
651 The wasted elements are never initialized. */
653 yyssp = yyss - 1;
654 yyvsp = yyvs;
655 #ifdef YYLSP_NEEDED
656 yylsp = yyls;
657 #endif
659 /* Push a new state, which is found in yystate . */
660 /* In all cases, when you get here, the value and location stacks
661 have just been pushed. so pushing a state here evens the stacks. */
662 yynewstate:
664 *++yyssp = yystate;
666 if (yyssp >= yyss + yystacksize - 1)
668 /* Give user a chance to reallocate the stack */
669 /* Use copies of these so that the &'s don't force the real ones into memory. */
670 YYSTYPE *yyvs1 = yyvs;
671 short *yyss1 = yyss;
672 #ifdef YYLSP_NEEDED
673 YYLTYPE *yyls1 = yyls;
674 #endif
676 /* Get the current used size of the three stacks, in elements. */
677 int size = yyssp - yyss + 1;
679 #ifdef yyoverflow
680 /* Each stack pointer address is followed by the size of
681 the data in use in that stack, in bytes. */
682 #ifdef YYLSP_NEEDED
683 /* This used to be a conditional around just the two extra args,
684 but that might be undefined if yyoverflow is a macro. */
685 yyoverflow("parser stack overflow",
686 &yyss1, size * sizeof (*yyssp),
687 &yyvs1, size * sizeof (*yyvsp),
688 &yyls1, size * sizeof (*yylsp),
689 &yystacksize);
690 #else
691 yyoverflow("parser stack overflow",
692 &yyss1, size * sizeof (*yyssp),
693 &yyvs1, size * sizeof (*yyvsp),
694 &yystacksize);
695 #endif
697 yyss = yyss1; yyvs = yyvs1;
698 #ifdef YYLSP_NEEDED
699 yyls = yyls1;
700 #endif
701 #else /* no yyoverflow */
702 /* Extend the stack our own way. */
703 if (yystacksize >= YYMAXDEPTH)
705 yyerror("parser stack overflow");
706 return 2;
708 yystacksize *= 2;
709 if (yystacksize > YYMAXDEPTH)
710 yystacksize = YYMAXDEPTH;
711 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
712 __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
713 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
714 __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
715 #ifdef YYLSP_NEEDED
716 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
717 __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
718 #endif
719 #endif /* no yyoverflow */
721 yyssp = yyss + size - 1;
722 yyvsp = yyvs + size - 1;
723 #ifdef YYLSP_NEEDED
724 yylsp = yyls + size - 1;
725 #endif
727 #if YYDEBUG != 0
728 if (yydebug)
729 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
730 #endif
732 if (yyssp >= yyss + yystacksize - 1)
733 YYABORT;
736 #if YYDEBUG != 0
737 if (yydebug)
738 fprintf(stderr, "Entering state %d\n", yystate);
739 #endif
741 goto yybackup;
742 yybackup:
744 /* Do appropriate processing given the current state. */
745 /* Read a lookahead token if we need one and don't already have one. */
746 /* yyresume: */
748 /* First try to decide what to do without reference to lookahead token. */
750 yyn = yypact[yystate];
751 if (yyn == YYFLAG)
752 goto yydefault;
754 /* Not known => get a lookahead token if don't already have one. */
756 /* yychar is either YYEMPTY or YYEOF
757 or a valid token in external form. */
759 if (yychar == YYEMPTY)
761 #if YYDEBUG != 0
762 if (yydebug)
763 fprintf(stderr, "Reading a token: ");
764 #endif
765 yychar = YYLEX;
768 /* Convert token to internal form (in yychar1) for indexing tables with */
770 if (yychar <= 0) /* This means end of input. */
772 yychar1 = 0;
773 yychar = YYEOF; /* Don't call YYLEX any more */
775 #if YYDEBUG != 0
776 if (yydebug)
777 fprintf(stderr, "Now at end of input.\n");
778 #endif
780 else
782 yychar1 = YYTRANSLATE(yychar);
784 #if YYDEBUG != 0
785 if (yydebug)
787 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
788 /* Give the individual parser a way to print the precise meaning
789 of a token, for further debugging info. */
790 #ifdef YYPRINT
791 YYPRINT (stderr, yychar, yylval);
792 #endif
793 fprintf (stderr, ")\n");
795 #endif
798 yyn += yychar1;
799 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
800 goto yydefault;
802 yyn = yytable[yyn];
804 /* yyn is what to do for this token type in this state.
805 Negative => reduce, -yyn is rule number.
806 Positive => shift, yyn is new state.
807 New state is final state => don't bother to shift,
808 just return success.
809 0, or most negative number => error. */
811 if (yyn < 0)
813 if (yyn == YYFLAG)
814 goto yyerrlab;
815 yyn = -yyn;
816 goto yyreduce;
818 else if (yyn == 0)
819 goto yyerrlab;
821 if (yyn == YYFINAL)
822 YYACCEPT;
824 /* Shift the lookahead token. */
826 #if YYDEBUG != 0
827 if (yydebug)
828 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
829 #endif
831 /* Discard the token being shifted unless it is eof. */
832 if (yychar != YYEOF)
833 yychar = YYEMPTY;
835 *++yyvsp = yylval;
836 #ifdef YYLSP_NEEDED
837 *++yylsp = yylloc;
838 #endif
840 /* count tokens shifted since error; after three, turn off error status. */
841 if (yyerrstatus) yyerrstatus--;
843 yystate = yyn;
844 goto yynewstate;
846 /* Do the default action for the current state. */
847 yydefault:
849 yyn = yydefact[yystate];
850 if (yyn == 0)
851 goto yyerrlab;
853 /* Do a reduction. yyn is the number of a rule to reduce with. */
854 yyreduce:
855 yylen = yyr2[yyn];
856 if (yylen > 0)
857 yyval = yyvsp[1-yylen]; /* implement default value of the action */
859 #if YYDEBUG != 0
860 if (yydebug)
862 int i;
864 fprintf (stderr, "Reducing via rule %d (line %d), ",
865 yyn, yyrline[yyn]);
867 /* Print the symbols being reduced, and their result. */
868 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
869 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
870 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
872 #endif
875 switch (yyn) {
877 case 1:
878 #line 282 "cexp.y"
880 expression_value = yyvsp[0].integer.value;
881 #ifdef TEST_EXP_READER
882 expression_signedp = yyvsp[0].integer.signedp;
883 #endif
885 break;}
886 case 3:
887 #line 293 "cexp.y"
888 { if (pedantic)
889 pedwarn ("comma operator in operand of `#if'");
890 yyval.integer = yyvsp[0].integer; ;
891 break;}
892 case 4:
893 #line 300 "cexp.y"
894 { yyval.integer.value = - yyvsp[0].integer.value;
895 yyval.integer.signedp = yyvsp[0].integer.signedp;
896 if ((yyval.integer.value & yyvsp[0].integer.value & yyval.integer.signedp) < 0)
897 integer_overflow (); ;
898 break;}
899 case 5:
900 #line 305 "cexp.y"
901 { yyval.integer.value = ! yyvsp[0].integer.value;
902 yyval.integer.signedp = SIGNED; ;
903 break;}
904 case 6:
905 #line 308 "cexp.y"
906 { yyval.integer = yyvsp[0].integer; ;
907 break;}
908 case 7:
909 #line 310 "cexp.y"
910 { yyval.integer.value = ~ yyvsp[0].integer.value;
911 yyval.integer.signedp = yyvsp[0].integer.signedp; ;
912 break;}
913 case 8:
914 #line 313 "cexp.y"
915 { yyval.integer.value = check_assertion (yyvsp[0].name.address, yyvsp[0].name.length,
916 0, NULL_PTR);
917 yyval.integer.signedp = SIGNED; ;
918 break;}
919 case 9:
920 #line 317 "cexp.y"
921 { keyword_parsing = 1; ;
922 break;}
923 case 10:
924 #line 319 "cexp.y"
925 { yyval.integer.value = check_assertion (yyvsp[-4].name.address, yyvsp[-4].name.length,
926 1, yyvsp[-1].keywords);
927 keyword_parsing = 0;
928 yyval.integer.signedp = SIGNED; ;
929 break;}
930 case 11:
931 #line 324 "cexp.y"
932 { yyval.integer = yyvsp[-1].integer; ;
933 break;}
934 case 12:
935 #line 329 "cexp.y"
936 { yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
937 if (yyval.integer.signedp)
939 yyval.integer.value = yyvsp[-2].integer.value * yyvsp[0].integer.value;
940 if (yyvsp[-2].integer.value
941 && (yyval.integer.value / yyvsp[-2].integer.value != yyvsp[0].integer.value
942 || (yyval.integer.value & yyvsp[-2].integer.value & yyvsp[0].integer.value) < 0))
943 integer_overflow ();
945 else
946 yyval.integer.value = ((unsigned_HOST_WIDE_INT) yyvsp[-2].integer.value
947 * yyvsp[0].integer.value); ;
948 break;}
949 case 13:
950 #line 342 "cexp.y"
951 { if (yyvsp[0].integer.value == 0)
953 if (!skip_evaluation)
954 error ("division by zero in #if");
955 yyvsp[0].integer.value = 1;
957 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
958 if (yyval.integer.signedp)
960 yyval.integer.value = yyvsp[-2].integer.value / yyvsp[0].integer.value;
961 if ((yyval.integer.value & yyvsp[-2].integer.value & yyvsp[0].integer.value) < 0)
962 integer_overflow ();
964 else
965 yyval.integer.value = ((unsigned_HOST_WIDE_INT) yyvsp[-2].integer.value
966 / yyvsp[0].integer.value); ;
967 break;}
968 case 14:
969 #line 359 "cexp.y"
970 { if (yyvsp[0].integer.value == 0)
972 if (!skip_evaluation)
973 error ("division by zero in #if");
974 yyvsp[0].integer.value = 1;
976 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
977 if (yyval.integer.signedp)
978 yyval.integer.value = yyvsp[-2].integer.value % yyvsp[0].integer.value;
979 else
980 yyval.integer.value = ((unsigned_HOST_WIDE_INT) yyvsp[-2].integer.value
981 % yyvsp[0].integer.value); ;
982 break;}
983 case 15:
984 #line 372 "cexp.y"
985 { yyval.integer.value = yyvsp[-2].integer.value + yyvsp[0].integer.value;
986 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
987 if (overflow_sum_sign (yyvsp[-2].integer.value, yyvsp[0].integer.value,
988 yyval.integer.value, yyval.integer.signedp))
989 integer_overflow (); ;
990 break;}
991 case 16:
992 #line 378 "cexp.y"
993 { yyval.integer.value = yyvsp[-2].integer.value - yyvsp[0].integer.value;
994 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
995 if (overflow_sum_sign (yyval.integer.value, yyvsp[0].integer.value,
996 yyvsp[-2].integer.value, yyval.integer.signedp))
997 integer_overflow (); ;
998 break;}
999 case 17:
1000 #line 384 "cexp.y"
1001 { yyval.integer.signedp = yyvsp[-2].integer.signedp;
1002 if ((yyvsp[0].integer.value & yyvsp[0].integer.signedp) < 0)
1003 yyval.integer.value = right_shift (&yyvsp[-2].integer, -yyvsp[0].integer.value);
1004 else
1005 yyval.integer.value = left_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); ;
1006 break;}
1007 case 18:
1008 #line 390 "cexp.y"
1009 { yyval.integer.signedp = yyvsp[-2].integer.signedp;
1010 if ((yyvsp[0].integer.value & yyvsp[0].integer.signedp) < 0)
1011 yyval.integer.value = left_shift (&yyvsp[-2].integer, -yyvsp[0].integer.value);
1012 else
1013 yyval.integer.value = right_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); ;
1014 break;}
1015 case 19:
1016 #line 396 "cexp.y"
1017 { yyval.integer.value = (yyvsp[-2].integer.value == yyvsp[0].integer.value);
1018 yyval.integer.signedp = SIGNED; ;
1019 break;}
1020 case 20:
1021 #line 399 "cexp.y"
1022 { yyval.integer.value = (yyvsp[-2].integer.value != yyvsp[0].integer.value);
1023 yyval.integer.signedp = SIGNED; ;
1024 break;}
1025 case 21:
1026 #line 402 "cexp.y"
1027 { yyval.integer.signedp = SIGNED;
1028 if (yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp)
1029 yyval.integer.value = yyvsp[-2].integer.value <= yyvsp[0].integer.value;
1030 else
1031 yyval.integer.value = ((unsigned_HOST_WIDE_INT) yyvsp[-2].integer.value
1032 <= yyvsp[0].integer.value); ;
1033 break;}
1034 case 22:
1035 #line 409 "cexp.y"
1036 { yyval.integer.signedp = SIGNED;
1037 if (yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp)
1038 yyval.integer.value = yyvsp[-2].integer.value >= yyvsp[0].integer.value;
1039 else
1040 yyval.integer.value = ((unsigned_HOST_WIDE_INT) yyvsp[-2].integer.value
1041 >= yyvsp[0].integer.value); ;
1042 break;}
1043 case 23:
1044 #line 416 "cexp.y"
1045 { yyval.integer.signedp = SIGNED;
1046 if (yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp)
1047 yyval.integer.value = yyvsp[-2].integer.value < yyvsp[0].integer.value;
1048 else
1049 yyval.integer.value = ((unsigned_HOST_WIDE_INT) yyvsp[-2].integer.value
1050 < yyvsp[0].integer.value); ;
1051 break;}
1052 case 24:
1053 #line 423 "cexp.y"
1054 { yyval.integer.signedp = SIGNED;
1055 if (yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp)
1056 yyval.integer.value = yyvsp[-2].integer.value > yyvsp[0].integer.value;
1057 else
1058 yyval.integer.value = ((unsigned_HOST_WIDE_INT) yyvsp[-2].integer.value
1059 > yyvsp[0].integer.value); ;
1060 break;}
1061 case 25:
1062 #line 430 "cexp.y"
1063 { yyval.integer.value = yyvsp[-2].integer.value & yyvsp[0].integer.value;
1064 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp; ;
1065 break;}
1066 case 26:
1067 #line 433 "cexp.y"
1068 { yyval.integer.value = yyvsp[-2].integer.value ^ yyvsp[0].integer.value;
1069 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp; ;
1070 break;}
1071 case 27:
1072 #line 436 "cexp.y"
1073 { yyval.integer.value = yyvsp[-2].integer.value | yyvsp[0].integer.value;
1074 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp; ;
1075 break;}
1076 case 28:
1077 #line 439 "cexp.y"
1078 { skip_evaluation += !yyvsp[-1].integer.value; ;
1079 break;}
1080 case 29:
1081 #line 441 "cexp.y"
1082 { skip_evaluation -= !yyvsp[-3].integer.value;
1083 yyval.integer.value = (yyvsp[-3].integer.value && yyvsp[0].integer.value);
1084 yyval.integer.signedp = SIGNED; ;
1085 break;}
1086 case 30:
1087 #line 445 "cexp.y"
1088 { skip_evaluation += !!yyvsp[-1].integer.value; ;
1089 break;}
1090 case 31:
1091 #line 447 "cexp.y"
1092 { skip_evaluation -= !!yyvsp[-3].integer.value;
1093 yyval.integer.value = (yyvsp[-3].integer.value || yyvsp[0].integer.value);
1094 yyval.integer.signedp = SIGNED; ;
1095 break;}
1096 case 32:
1097 #line 451 "cexp.y"
1098 { skip_evaluation += !yyvsp[-1].integer.value; ;
1099 break;}
1100 case 33:
1101 #line 453 "cexp.y"
1102 { skip_evaluation += !!yyvsp[-4].integer.value - !yyvsp[-4].integer.value; ;
1103 break;}
1104 case 34:
1105 #line 455 "cexp.y"
1106 { skip_evaluation -= !!yyvsp[-6].integer.value;
1107 yyval.integer.value = yyvsp[-6].integer.value ? yyvsp[-3].integer.value : yyvsp[0].integer.value;
1108 yyval.integer.signedp = yyvsp[-3].integer.signedp & yyvsp[0].integer.signedp; ;
1109 break;}
1110 case 35:
1111 #line 459 "cexp.y"
1112 { yyval.integer = yylval.integer; ;
1113 break;}
1114 case 36:
1115 #line 461 "cexp.y"
1116 { yyval.integer = yylval.integer; ;
1117 break;}
1118 case 37:
1119 #line 463 "cexp.y"
1120 { if (warn_undef && !skip_evaluation)
1121 warning ("`%.*s' is not defined",
1122 yyvsp[0].name.length, yyvsp[0].name.address);
1123 yyval.integer.value = 0;
1124 yyval.integer.signedp = SIGNED; ;
1125 break;}
1126 case 38:
1127 #line 471 "cexp.y"
1128 { yyval.keywords = 0; ;
1129 break;}
1130 case 39:
1131 #line 473 "cexp.y"
1132 { struct arglist *temp;
1133 yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));
1134 yyval.keywords->next = yyvsp[-2].keywords;
1135 yyval.keywords->name = (U_CHAR *) "(";
1136 yyval.keywords->length = 1;
1137 temp = yyval.keywords;
1138 while (temp != 0 && temp->next != 0)
1139 temp = temp->next;
1140 temp->next = (struct arglist *) xmalloc (sizeof (struct arglist));
1141 temp->next->next = yyvsp[0].keywords;
1142 temp->next->name = (U_CHAR *) ")";
1143 temp->next->length = 1; ;
1144 break;}
1145 case 40:
1146 #line 486 "cexp.y"
1147 { yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));
1148 yyval.keywords->name = yyvsp[-1].name.address;
1149 yyval.keywords->length = yyvsp[-1].name.length;
1150 yyval.keywords->next = yyvsp[0].keywords; ;
1151 break;}
1153 /* the action file gets copied in in place of this dollarsign */
1154 #line 498 "/usr/cygnus/latest-940103/share/bison.simple"
1156 yyvsp -= yylen;
1157 yyssp -= yylen;
1158 #ifdef YYLSP_NEEDED
1159 yylsp -= yylen;
1160 #endif
1162 #if YYDEBUG != 0
1163 if (yydebug)
1165 short *ssp1 = yyss - 1;
1166 fprintf (stderr, "state stack now");
1167 while (ssp1 != yyssp)
1168 fprintf (stderr, " %d", *++ssp1);
1169 fprintf (stderr, "\n");
1171 #endif
1173 *++yyvsp = yyval;
1175 #ifdef YYLSP_NEEDED
1176 yylsp++;
1177 if (yylen == 0)
1179 yylsp->first_line = yylloc.first_line;
1180 yylsp->first_column = yylloc.first_column;
1181 yylsp->last_line = (yylsp-1)->last_line;
1182 yylsp->last_column = (yylsp-1)->last_column;
1183 yylsp->text = 0;
1185 else
1187 yylsp->last_line = (yylsp+yylen-1)->last_line;
1188 yylsp->last_column = (yylsp+yylen-1)->last_column;
1190 #endif
1192 /* Now "shift" the result of the reduction.
1193 Determine what state that goes to,
1194 based on the state we popped back to
1195 and the rule number reduced by. */
1197 yyn = yyr1[yyn];
1199 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1200 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1201 yystate = yytable[yystate];
1202 else
1203 yystate = yydefgoto[yyn - YYNTBASE];
1205 goto yynewstate;
1207 yyerrlab: /* here on detecting error */
1209 if (! yyerrstatus)
1210 /* If not already recovering from an error, report this error. */
1212 ++yynerrs;
1214 #ifdef YYERROR_VERBOSE
1215 yyn = yypact[yystate];
1217 if (yyn > YYFLAG && yyn < YYLAST)
1219 int size = 0;
1220 char *msg;
1221 int x, count;
1223 count = 0;
1224 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1225 for (x = (yyn < 0 ? -yyn : 0);
1226 x < (sizeof(yytname) / sizeof(char *)); x++)
1227 if (yycheck[x + yyn] == x)
1228 size += strlen(yytname[x]) + 15, count++;
1229 msg = (char *) malloc(size + 15);
1230 if (msg != 0)
1232 strcpy(msg, "parse error");
1234 if (count < 5)
1236 count = 0;
1237 for (x = (yyn < 0 ? -yyn : 0);
1238 x < (sizeof(yytname) / sizeof(char *)); x++)
1239 if (yycheck[x + yyn] == x)
1241 strcat(msg, count == 0 ? ", expecting `" : " or `");
1242 strcat(msg, yytname[x]);
1243 strcat(msg, "'");
1244 count++;
1247 yyerror(msg);
1248 free(msg);
1250 else
1251 yyerror ("parse error; also virtual memory exceeded");
1253 else
1254 #endif /* YYERROR_VERBOSE */
1255 yyerror("parse error");
1258 goto yyerrlab1;
1259 yyerrlab1: /* here on error raised explicitly by an action */
1261 if (yyerrstatus == 3)
1263 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1265 /* return failure if at end of input */
1266 if (yychar == YYEOF)
1267 YYABORT;
1269 #if YYDEBUG != 0
1270 if (yydebug)
1271 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1272 #endif
1274 yychar = YYEMPTY;
1277 /* Else will try to reuse lookahead token
1278 after shifting the error token. */
1280 yyerrstatus = 3; /* Each real token shifted decrements this */
1282 goto yyerrhandle;
1284 yyerrdefault: /* current state does not do anything special for the error token. */
1286 #if 0
1287 /* This is wrong; only states that explicitly want error tokens
1288 should shift them. */
1289 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1290 if (yyn) goto yydefault;
1291 #endif
1293 yyerrpop: /* pop the current state because it cannot handle the error token */
1295 if (yyssp == yyss) YYABORT;
1296 yyvsp--;
1297 yystate = *--yyssp;
1298 #ifdef YYLSP_NEEDED
1299 yylsp--;
1300 #endif
1302 #if YYDEBUG != 0
1303 if (yydebug)
1305 short *ssp1 = yyss - 1;
1306 fprintf (stderr, "Error: state stack now");
1307 while (ssp1 != yyssp)
1308 fprintf (stderr, " %d", *++ssp1);
1309 fprintf (stderr, "\n");
1311 #endif
1313 yyerrhandle:
1315 yyn = yypact[yystate];
1316 if (yyn == YYFLAG)
1317 goto yyerrdefault;
1319 yyn += YYTERROR;
1320 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1321 goto yyerrdefault;
1323 yyn = yytable[yyn];
1324 if (yyn < 0)
1326 if (yyn == YYFLAG)
1327 goto yyerrpop;
1328 yyn = -yyn;
1329 goto yyreduce;
1331 else if (yyn == 0)
1332 goto yyerrpop;
1334 if (yyn == YYFINAL)
1335 YYACCEPT;
1337 #if YYDEBUG != 0
1338 if (yydebug)
1339 fprintf(stderr, "Shifting error token, ");
1340 #endif
1342 *++yyvsp = yylval;
1343 #ifdef YYLSP_NEEDED
1344 *++yylsp = yylloc;
1345 #endif
1347 yystate = yyn;
1348 goto yynewstate;
1350 #line 491 "cexp.y"
1353 /* During parsing of a C expression, the pointer to the next character
1354 is in this variable. */
1356 static char *lexptr;
1358 /* Take care of parsing a number (anything that starts with a digit).
1359 Set yylval and return the token type; update lexptr.
1360 LEN is the number of characters in it. */
1362 /* maybe needs to actually deal with floating point numbers */
1364 static int
1365 parse_number (olen)
1366 int olen;
1368 register char *p = lexptr;
1369 register int c;
1370 register unsigned_HOST_WIDE_INT n = 0, nd, max_over_base;
1371 register int base = 10;
1372 register int len = olen;
1373 register int overflow = 0;
1374 register int digit, largest_digit = 0;
1375 int spec_long = 0;
1377 yylval.integer.signedp = SIGNED;
1379 if (*p == '0') {
1380 base = 8;
1381 if (len >= 3 && (p[1] == 'x' || p[1] == 'X')) {
1382 p += 2;
1383 base = 16;
1384 len -= 2;
1388 max_over_base = (unsigned_HOST_WIDE_INT) -1 / base;
1390 for (; len > 0; len--) {
1391 c = *p++;
1393 if (c >= '0' && c <= '9')
1394 digit = c - '0';
1395 else if (base == 16 && c >= 'a' && c <= 'f')
1396 digit = c - 'a' + 10;
1397 else if (base == 16 && c >= 'A' && c <= 'F')
1398 digit = c - 'A' + 10;
1399 else {
1400 /* `l' means long, and `u' means unsigned. */
1401 while (1) {
1402 if (c == 'l' || c == 'L')
1404 if (!pedantic < spec_long)
1405 yyerror ("too many `l's in integer constant");
1406 spec_long++;
1408 else if (c == 'u' || c == 'U')
1410 if (! yylval.integer.signedp)
1411 yyerror ("two `u's in integer constant");
1412 yylval.integer.signedp = UNSIGNED;
1414 else {
1415 if (c == '.' || c == 'e' || c == 'E' || c == 'p' || c == 'P')
1416 yyerror ("Floating point numbers not allowed in #if expressions");
1417 else {
1418 char *buf = (char *) alloca (p - lexptr + 40);
1419 sprintf (buf, "missing white space after number `%.*s'",
1420 (int) (p - lexptr - 1), lexptr);
1421 yyerror (buf);
1425 if (--len == 0)
1426 break;
1427 c = *p++;
1429 /* Don't look for any more digits after the suffixes. */
1430 break;
1432 if (largest_digit < digit)
1433 largest_digit = digit;
1434 nd = n * base + digit;
1435 overflow |= (max_over_base < n) | (nd < n);
1436 n = nd;
1439 if (base <= largest_digit)
1440 pedwarn ("integer constant contains digits beyond the radix");
1442 if (overflow)
1443 pedwarn ("integer constant out of range");
1445 /* If too big to be signed, consider it unsigned. */
1446 if (((HOST_WIDE_INT) n & yylval.integer.signedp) < 0)
1448 if (base == 10)
1449 warning ("integer constant is so large that it is unsigned");
1450 yylval.integer.signedp = UNSIGNED;
1453 lexptr = p;
1454 yylval.integer.value = n;
1455 return INT;
1458 struct token {
1459 char *operator;
1460 int token;
1463 static struct token tokentab2[] = {
1464 {"&&", AND},
1465 {"||", OR},
1466 {"<<", LSH},
1467 {">>", RSH},
1468 {"==", EQUAL},
1469 {"!=", NOTEQUAL},
1470 {"<=", LEQ},
1471 {">=", GEQ},
1472 {"++", ERROR},
1473 {"--", ERROR},
1474 {NULL, ERROR}
1477 /* Read one token, getting characters through lexptr. */
1479 static int
1480 yylex ()
1482 register int c;
1483 register int namelen;
1484 register unsigned char *tokstart;
1485 register struct token *toktab;
1486 int wide_flag;
1487 HOST_WIDE_INT mask;
1489 retry:
1491 tokstart = (unsigned char *) lexptr;
1492 c = *tokstart;
1493 /* See if it is a special token of length 2. */
1494 if (! keyword_parsing)
1495 for (toktab = tokentab2; toktab->operator != NULL; toktab++)
1496 if (c == *toktab->operator && tokstart[1] == toktab->operator[1]) {
1497 lexptr += 2;
1498 if (toktab->token == ERROR)
1500 char *buf = (char *) alloca (40);
1501 sprintf (buf, "`%s' not allowed in operand of `#if'", toktab->operator);
1502 yyerror (buf);
1504 return toktab->token;
1507 switch (c) {
1508 case '\n':
1509 return 0;
1511 case ' ':
1512 case '\t':
1513 case '\r':
1514 lexptr++;
1515 goto retry;
1517 case 'L':
1518 /* Capital L may start a wide-string or wide-character constant. */
1519 if (lexptr[1] == '\'')
1521 lexptr++;
1522 wide_flag = 1;
1523 mask = MAX_WCHAR_TYPE_MASK;
1524 goto char_constant;
1526 if (lexptr[1] == '"')
1528 lexptr++;
1529 wide_flag = 1;
1530 mask = MAX_WCHAR_TYPE_MASK;
1531 goto string_constant;
1533 break;
1535 case '\'':
1536 wide_flag = 0;
1537 mask = MAX_CHAR_TYPE_MASK;
1538 char_constant:
1539 lexptr++;
1540 if (keyword_parsing) {
1541 char *start_ptr = lexptr - 1;
1542 while (1) {
1543 c = *lexptr++;
1544 if (c == '\\')
1545 c = parse_escape (&lexptr, mask);
1546 else if (c == '\'')
1547 break;
1549 yylval.name.address = tokstart;
1550 yylval.name.length = lexptr - start_ptr;
1551 return NAME;
1554 /* This code for reading a character constant
1555 handles multicharacter constants and wide characters.
1556 It is mostly copied from c-lex.c. */
1558 register HOST_WIDE_INT result = 0;
1559 register int num_chars = 0;
1560 unsigned width = MAX_CHAR_TYPE_SIZE;
1561 int max_chars;
1562 char *token_buffer;
1564 if (wide_flag)
1566 width = MAX_WCHAR_TYPE_SIZE;
1567 #ifdef MULTIBYTE_CHARS
1568 max_chars = MB_CUR_MAX;
1569 #else
1570 max_chars = 1;
1571 #endif
1573 else
1574 max_chars = MAX_LONG_TYPE_SIZE / width;
1576 token_buffer = (char *) alloca (max_chars + 1);
1578 while (1)
1580 c = *lexptr++;
1582 if (c == '\'' || c == EOF)
1583 break;
1585 if (c == '\\')
1587 c = parse_escape (&lexptr, mask);
1590 num_chars++;
1592 /* Merge character into result; ignore excess chars. */
1593 if (num_chars <= max_chars)
1595 if (width < HOST_BITS_PER_WIDE_INT)
1596 result = (result << width) | c;
1597 else
1598 result = c;
1599 token_buffer[num_chars - 1] = c;
1603 token_buffer[num_chars] = 0;
1605 if (c != '\'')
1606 error ("malformatted character constant");
1607 else if (num_chars == 0)
1608 error ("empty character constant");
1609 else if (num_chars > max_chars)
1611 num_chars = max_chars;
1612 error ("character constant too long");
1614 else if (num_chars != 1 && ! traditional)
1615 warning ("multi-character character constant");
1617 /* If char type is signed, sign-extend the constant. */
1618 if (! wide_flag)
1620 int num_bits = num_chars * width;
1622 if (lookup ((U_CHAR *) "__CHAR_UNSIGNED__",
1623 sizeof ("__CHAR_UNSIGNED__") - 1, -1)
1624 || ((result >> (num_bits - 1)) & 1) == 0)
1625 yylval.integer.value
1626 = result & (~ (unsigned_HOST_WIDE_INT) 0
1627 >> (HOST_BITS_PER_WIDE_INT - num_bits));
1628 else
1629 yylval.integer.value
1630 = result | ~(~ (unsigned_HOST_WIDE_INT) 0
1631 >> (HOST_BITS_PER_WIDE_INT - num_bits));
1633 else
1635 #ifdef MULTIBYTE_CHARS
1636 /* Set the initial shift state and convert the next sequence. */
1637 result = 0;
1638 /* In all locales L'\0' is zero and mbtowc will return zero,
1639 so don't use it. */
1640 if (num_chars > 1
1641 || (num_chars == 1 && token_buffer[0] != '\0'))
1643 wchar_t wc;
1644 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1645 if (mbtowc (& wc, token_buffer, num_chars) == num_chars)
1646 result = wc;
1647 else
1648 pedwarn ("Ignoring invalid multibyte character");
1650 #endif
1651 yylval.integer.value = result;
1655 /* This is always a signed type. */
1656 yylval.integer.signedp = SIGNED;
1658 return CHAR;
1660 /* some of these chars are invalid in constant expressions;
1661 maybe do something about them later */
1662 case '/':
1663 case '+':
1664 case '-':
1665 case '*':
1666 case '%':
1667 case '|':
1668 case '&':
1669 case '^':
1670 case '~':
1671 case '!':
1672 case '@':
1673 case '<':
1674 case '>':
1675 case '[':
1676 case ']':
1677 case '.':
1678 case '?':
1679 case ':':
1680 case '=':
1681 case '{':
1682 case '}':
1683 case ',':
1684 case '#':
1685 if (keyword_parsing)
1686 break;
1687 case '(':
1688 case ')':
1689 lexptr++;
1690 return c;
1692 case '"':
1693 mask = MAX_CHAR_TYPE_MASK;
1694 string_constant:
1695 if (keyword_parsing) {
1696 char *start_ptr = lexptr;
1697 lexptr++;
1698 while (1) {
1699 c = *lexptr++;
1700 if (c == '\\')
1701 c = parse_escape (&lexptr, mask);
1702 else if (c == '"')
1703 break;
1705 yylval.name.address = tokstart;
1706 yylval.name.length = lexptr - start_ptr;
1707 return NAME;
1709 yyerror ("string constants not allowed in #if expressions");
1710 return ERROR;
1713 if (c >= '0' && c <= '9' && !keyword_parsing) {
1714 /* It's a number */
1715 for (namelen = 1; ; namelen++) {
1716 int d = tokstart[namelen];
1717 if (! ((is_idchar[d] || d == '.')
1718 || ((d == '-' || d == '+')
1719 && (c == 'e' || c == 'E'
1720 || ((c == 'p' || c == 'P') && ! c89))
1721 && ! traditional)))
1722 break;
1723 c = d;
1725 return parse_number (namelen);
1728 /* It is a name. See how long it is. */
1730 if (keyword_parsing) {
1731 for (namelen = 0;; namelen++) {
1732 if (is_space[tokstart[namelen]])
1733 break;
1734 if (tokstart[namelen] == '(' || tokstart[namelen] == ')')
1735 break;
1736 if (tokstart[namelen] == '"' || tokstart[namelen] == '\'')
1737 break;
1739 } else {
1740 if (!is_idstart[c]) {
1741 yyerror ("Invalid token in expression");
1742 return ERROR;
1745 for (namelen = 0; is_idchar[tokstart[namelen]]; namelen++)
1749 lexptr += namelen;
1750 yylval.name.address = tokstart;
1751 yylval.name.length = namelen;
1752 return NAME;
1756 /* Parse a C escape sequence. STRING_PTR points to a variable
1757 containing a pointer to the string to parse. That pointer
1758 is updated past the characters we use. The value of the
1759 escape sequence is returned.
1761 RESULT_MASK is used to mask out the result;
1762 an error is reported if bits are lost thereby.
1764 A negative value means the sequence \ newline was seen,
1765 which is supposed to be equivalent to nothing at all.
1767 If \ is followed by a null character, we return a negative
1768 value and leave the string pointer pointing at the null character.
1770 If \ is followed by 000, we return 0 and leave the string pointer
1771 after the zeros. A value of 0 does not mean end of string. */
1773 HOST_WIDE_INT
1774 parse_escape (string_ptr, result_mask)
1775 char **string_ptr;
1776 HOST_WIDE_INT result_mask;
1778 register int c = *(*string_ptr)++;
1779 switch (c)
1781 case 'a':
1782 return TARGET_BELL;
1783 case 'b':
1784 return TARGET_BS;
1785 case 'e':
1786 case 'E':
1787 if (pedantic)
1788 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1789 return 033;
1790 case 'f':
1791 return TARGET_FF;
1792 case 'n':
1793 return TARGET_NEWLINE;
1794 case 'r':
1795 return TARGET_CR;
1796 case 't':
1797 return TARGET_TAB;
1798 case 'v':
1799 return TARGET_VT;
1800 case '\n':
1801 return -2;
1802 case 0:
1803 (*string_ptr)--;
1804 return 0;
1806 case '0':
1807 case '1':
1808 case '2':
1809 case '3':
1810 case '4':
1811 case '5':
1812 case '6':
1813 case '7':
1815 register HOST_WIDE_INT i = c - '0';
1816 register int count = 0;
1817 while (++count < 3)
1819 c = *(*string_ptr)++;
1820 if (c >= '0' && c <= '7')
1821 i = (i << 3) + c - '0';
1822 else
1824 (*string_ptr)--;
1825 break;
1828 if (i != (i & result_mask))
1830 i &= result_mask;
1831 pedwarn ("octal escape sequence out of range");
1833 return i;
1835 case 'x':
1837 register unsigned_HOST_WIDE_INT i = 0, overflow = 0;
1838 register int digits_found = 0, digit;
1839 for (;;)
1841 c = *(*string_ptr)++;
1842 if (c >= '0' && c <= '9')
1843 digit = c - '0';
1844 else if (c >= 'a' && c <= 'f')
1845 digit = c - 'a' + 10;
1846 else if (c >= 'A' && c <= 'F')
1847 digit = c - 'A' + 10;
1848 else
1850 (*string_ptr)--;
1851 break;
1853 overflow |= i ^ (i << 4 >> 4);
1854 i = (i << 4) + digit;
1855 digits_found = 1;
1857 if (!digits_found)
1858 yyerror ("\\x used with no following hex digits");
1859 if (overflow | (i != (i & result_mask)))
1861 i &= result_mask;
1862 pedwarn ("hex escape sequence out of range");
1864 return i;
1866 default:
1867 return c;
1871 static void
1872 yyerror (s)
1873 char *s;
1875 error ("%s", s);
1876 skip_evaluation = 0;
1877 longjmp (parse_return_error, 1);
1880 static void
1881 integer_overflow ()
1883 if (!skip_evaluation && pedantic)
1884 pedwarn ("integer overflow in preprocessor expression");
1887 static HOST_WIDE_INT
1888 left_shift (a, b)
1889 struct constant *a;
1890 unsigned_HOST_WIDE_INT b;
1892 /* It's unclear from the C standard whether shifts can overflow.
1893 The following code ignores overflow; perhaps a C standard
1894 interpretation ruling is needed. */
1895 if (b >= HOST_BITS_PER_WIDE_INT)
1896 return 0;
1897 else
1898 return (unsigned_HOST_WIDE_INT) a->value << b;
1901 static HOST_WIDE_INT
1902 right_shift (a, b)
1903 struct constant *a;
1904 unsigned_HOST_WIDE_INT b;
1906 if (b >= HOST_BITS_PER_WIDE_INT)
1907 return a->signedp ? a->value >> (HOST_BITS_PER_WIDE_INT - 1) : 0;
1908 else if (a->signedp)
1909 return a->value >> b;
1910 else
1911 return (unsigned_HOST_WIDE_INT) a->value >> b;
1914 /* This page contains the entry point to this file. */
1916 /* Parse STRING as an expression, and complain if this fails
1917 to use up all of the contents of STRING.
1918 STRING may contain '\0' bytes; it is terminated by the first '\n'
1919 outside a string constant, so that we can diagnose '\0' properly.
1920 If WARN_UNDEFINED is nonzero, warn if undefined identifiers are evaluated.
1921 We do not support C comments. They should be removed before
1922 this function is called. */
1924 HOST_WIDE_INT
1925 parse_c_expression (string, warn_undefined)
1926 char *string;
1927 int warn_undefined;
1929 lexptr = string;
1930 warn_undef = warn_undefined;
1932 /* if there is some sort of scanning error, just return 0 and assume
1933 the parsing routine has printed an error message somewhere.
1934 there is surely a better thing to do than this. */
1935 if (setjmp (parse_return_error))
1936 return 0;
1938 if (yyparse () != 0)
1939 abort ();
1941 if (*lexptr != '\n')
1942 error ("Junk after end of expression.");
1944 return expression_value; /* set by yyparse () */
1947 #ifdef TEST_EXP_READER
1949 #if YYDEBUG
1950 extern int yydebug;
1951 #endif
1953 int pedantic;
1954 int traditional;
1956 int main PROTO((int, char **));
1957 static void initialize_random_junk PROTO((void));
1958 static void print_unsigned_host_wide_int PROTO((unsigned_HOST_WIDE_INT));
1960 /* Main program for testing purposes. */
1962 main (argc, argv)
1963 int argc;
1964 char **argv;
1966 int n, c;
1967 char buf[1024];
1968 unsigned_HOST_WIDE_INT u;
1970 pedantic = 1 < argc;
1971 traditional = 2 < argc;
1972 #if YYDEBUG
1973 yydebug = 3 < argc;
1974 #endif
1975 initialize_random_junk ();
1977 for (;;) {
1978 printf ("enter expression: ");
1979 n = 0;
1980 while ((buf[n] = c = getchar ()) != '\n' && c != EOF)
1981 n++;
1982 if (c == EOF)
1983 break;
1984 parse_c_expression (buf, 1);
1985 printf ("parser returned ");
1986 u = (unsigned_HOST_WIDE_INT) expression_value;
1987 if (expression_value < 0 && expression_signedp) {
1988 u = -u;
1989 printf ("-");
1991 if (u == 0)
1992 printf ("0");
1993 else
1994 print_unsigned_host_wide_int (u);
1995 if (! expression_signedp)
1996 printf("u");
1997 printf ("\n");
2000 return 0;
2003 static void
2004 print_unsigned_host_wide_int (u)
2005 unsigned_HOST_WIDE_INT u;
2007 if (u) {
2008 print_unsigned_host_wide_int (u / 10);
2009 putchar ('0' + (int) (u % 10));
2013 /* table to tell if char can be part of a C identifier. */
2014 unsigned char is_idchar[256];
2015 /* table to tell if char can be first char of a c identifier. */
2016 unsigned char is_idstart[256];
2017 /* table to tell if c is horizontal or vertical space. */
2018 unsigned char is_space[256];
2021 * initialize random junk in the hash table and maybe other places
2023 static void
2024 initialize_random_junk ()
2026 register int i;
2029 * Set up is_idchar and is_idstart tables. These should be
2030 * faster than saying (is_alpha (c) || c == '_'), etc.
2031 * Must do set up these things before calling any routines tthat
2032 * refer to them.
2034 for (i = 'a'; i <= 'z'; i++) {
2035 ++is_idchar[i - 'a' + 'A'];
2036 ++is_idchar[i];
2037 ++is_idstart[i - 'a' + 'A'];
2038 ++is_idstart[i];
2040 for (i = '0'; i <= '9'; i++)
2041 ++is_idchar[i];
2042 ++is_idchar['_'];
2043 ++is_idstart['_'];
2044 ++is_idchar['$'];
2045 ++is_idstart['$'];
2047 ++is_space[' '];
2048 ++is_space['\t'];
2049 ++is_space['\v'];
2050 ++is_space['\f'];
2051 ++is_space['\n'];
2052 ++is_space['\r'];
2055 void
2056 error VPROTO ((char * msg, ...))
2058 #ifndef __STDC__
2059 char * msg;
2060 #endif
2061 va_list args;
2063 VA_START (args, msg);
2065 #ifndef __STDC__
2066 msg = va_arg (args, char *);
2067 #endif
2069 fprintf (stderr, "error: ");
2070 vfprintf (stderr, msg, args);
2071 fprintf (stderr, "\n");
2072 va_end (args);
2075 void
2076 pedwarn VPROTO ((char * msg, ...))
2078 #ifndef __STDC__
2079 char * msg;
2080 #endif
2081 va_list args;
2083 VA_START (args, msg);
2085 #ifndef __STDC__
2086 msg = va_arg (args, char *);
2087 #endif
2089 fprintf (stderr, "pedwarn: ");
2090 vfprintf (stderr, msg, args);
2091 fprintf (stderr, "\n");
2092 va_end (args);
2095 void
2096 warning VPROTO ((char * msg, ...))
2098 #ifndef __STDC__
2099 char * msg;
2100 #endif
2101 va_list args;
2103 VA_START (args, msg);
2105 #ifndef __STDC__
2106 msg = va_arg (args, char *);
2107 #endif
2109 fprintf (stderr, "warning: ");
2110 vfprintf (stderr, msg, args);
2111 fprintf (stderr, "\n");
2112 va_end (args);
2116 check_assertion (name, sym_length, tokens_specified, tokens)
2117 U_CHAR *name;
2118 int sym_length;
2119 int tokens_specified;
2120 struct arglist *tokens;
2122 return 0;
2125 struct hashnode *
2126 lookup (name, len, hash)
2127 U_CHAR *name;
2128 int len;
2129 int hash;
2131 return (DEFAULT_SIGNED_CHAR) ? 0 : ((struct hashnode *) -1);
2134 GENERIC_PTR
2135 xmalloc (size)
2136 size_t size;
2138 return (GENERIC_PTR) malloc (size);
2140 #endif