]> gcc.gnu.org Git - gcc.git/blame - gcc/c-lex.c
(store_expr): Call size_binop instead of doing the same thing with
[gcc.git] / gcc / c-lex.c
CommitLineData
d45cf215 1/* Lexical analyzer for C and Objective C.
e8bbfc4e
RK
2 Copyright (C) 1987, 1988, 1989, 1992 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21#include <stdio.h>
22#include <errno.h>
23#include <setjmp.h>
24
25#include "config.h"
26#include "rtl.h"
27#include "tree.h"
28#include "input.h"
29#include "c-lex.h"
30#include "c-tree.h"
31#include "flags.h"
32#include "c-parse.h"
33
34#ifdef MULTIBYTE_CHARS
35#include <stdlib.h>
36#include <locale.h>
37#endif
38
39#ifndef errno
40extern int errno;
41#endif
42
43/* The elements of `ridpointers' are identifier nodes
44 for the reserved type names and storage classes.
45 It is indexed by a RID_... value. */
46tree ridpointers[(int) RID_MAX];
47
48/* Cause the `yydebug' variable to be defined. */
49#define YYDEBUG 1
50
51/* the declaration found for the last IDENTIFIER token read in.
52 yylex must look this up to detect typedefs, which get token type TYPENAME,
53 so it is left around in case the identifier is not a typedef but is
54 used in a context which makes it a reference to a variable. */
55tree lastiddecl;
56
57/* Nonzero enables objc features. */
58
59int doing_objc_thang;
60
61extern tree lookup_interface ();
62
63extern int yydebug;
64
65/* File used for outputting assembler code. */
66extern FILE *asm_out_file;
67
68#ifndef WCHAR_TYPE_SIZE
69#ifdef INT_TYPE_SIZE
70#define WCHAR_TYPE_SIZE INT_TYPE_SIZE
71#else
72#define WCHAR_TYPE_SIZE BITS_PER_WORD
73#endif
74#endif
75
76/* Number of bytes in a wide character. */
77#define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
78
79static int maxtoken; /* Current nominal length of token buffer. */
80char *token_buffer; /* Pointer to token buffer.
81 Actual allocated length is maxtoken + 2.
82 This is not static because objc-parse.y uses it. */
83
84/* Nonzero if end-of-file has been seen on input. */
85static int end_of_file;
86
87/* Buffered-back input character; faster than using ungetc. */
88static int nextchar = -1;
89
90int check_newline ();
91
92/* Nonzero tells yylex to ignore \ in string constants. */
93static int ignore_escape_flag = 0;
94\f
95/* C code produced by gperf version 2.5 (GNU C++ version) */
96/* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */
97struct resword { char *name; short token; enum rid rid; };
98
c4c7fef1 99#define TOTAL_KEYWORDS 61
e8bbfc4e
RK
100#define MIN_WORD_LENGTH 2
101#define MAX_WORD_LENGTH 13
c4c7fef1
RS
102#define MIN_HASH_VALUE 10
103#define MAX_HASH_VALUE 95
104/* maximum key range = 86, duplicates = 0 */
e8bbfc4e
RK
105
106#ifdef __GNUC__
107__inline
108#endif
109static unsigned int
110hash (str, len)
111 register char *str;
112 register int unsigned len;
113{
114 static unsigned char asso_values[] =
115 {
c4c7fef1
RS
116 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
117 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
118 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
119 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
120 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
121 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
122 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
123 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
124 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
125 96, 96, 96, 96, 96, 1, 96, 15, 13, 23,
126 1, 6, 32, 36, 3, 5, 96, 1, 20, 29,
127 31, 44, 19, 96, 13, 2, 1, 54, 39, 11,
128 5, 96, 3, 96, 96, 96, 96, 96,
e8bbfc4e
RK
129 };
130 register int hval = len;
131
132 switch (hval)
133 {
134 default:
135 case 3:
136 hval += asso_values[str[2]];
137 case 2:
138 case 1:
139 hval += asso_values[str[0]];
140 }
141 return hval + asso_values[str[len - 1]];
142}
143
144#ifdef __GNUC__
145__inline
146#endif
147struct resword *
148is_reserved_word (str, len)
149 register char *str;
150 register unsigned int len;
151{
152 static struct resword wordlist[] =
153 {
c4c7fef1 154 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
e8bbfc4e 155 {"",},
e8bbfc4e 156 {"int", TYPESPEC, RID_INT},
c4c7fef1
RS
157 {"",},
158 {"__signed", TYPESPEC, RID_SIGNED},
6506ecd7 159 {"__typeof__", TYPEOF, NORID},
e8bbfc4e 160 {"__signed__", TYPESPEC, RID_SIGNED},
c4c7fef1 161 {"__imag__", IMAGPART, NORID},
6506ecd7 162 {"switch", SWITCH, NORID},
6506ecd7 163 {"__inline__", SCSPEC, RID_INLINE},
c4c7fef1 164 {"else", ELSE, NORID},
6506ecd7 165 {"__iterator__", SCSPEC, RID_ITERATOR},
6506ecd7
RS
166 {"__inline", SCSPEC, RID_INLINE},
167 {"__extension__", EXTENSION, NORID},
122026c0 168 {"struct", STRUCT, NORID},
c4c7fef1
RS
169 {"__real__", REALPART, NORID},
170 {"__asm__", ASM_KEYWORD, NORID},
171 {"break", BREAK, NORID},
172 {"",},
173 {"while", WHILE, NORID},
6506ecd7 174 {"__alignof__", ALIGNOF, NORID},
c4c7fef1 175 {"__iterator", SCSPEC, RID_ITERATOR},
6506ecd7 176 {"__attribute__", ATTRIBUTE, NORID},
e8bbfc4e 177 {"__label__", LABEL, NORID},
c4c7fef1 178 {"__const", TYPE_QUAL, RID_CONST},
6506ecd7 179 {"__attribute", ATTRIBUTE, NORID},
c4c7fef1
RS
180 {"__const__", TYPE_QUAL, RID_CONST},
181 {"case", CASE, NORID},
182 {"__complex__", TYPESPEC, RID_COMPLEX},
183 {"inline", SCSPEC, RID_INLINE},
184 {"__complex", TYPESPEC, RID_COMPLEX},
185 {"if", IF, NORID},
186 {"__real", REALPART, NORID},
187 {"default", DEFAULT, NORID},
188 {"__typeof", TYPEOF, NORID},
189 {"sizeof", SIZEOF, NORID},
e8bbfc4e 190 {"extern", SCSPEC, RID_EXTERN},
c4c7fef1 191 {"signed", TYPESPEC, RID_SIGNED},
122026c0 192 {"static", SCSPEC, RID_STATIC},
c4c7fef1
RS
193 {"do", DO, NORID},
194 {"__imag", IMAGPART, NORID},
195 {"void", TYPESPEC, RID_VOID},
196 {"__asm", ASM_KEYWORD, NORID},
197 {"return", RETURN, NORID},
198 {"short", TYPESPEC, RID_SHORT},
199 {"__volatile__", TYPE_QUAL, RID_VOLATILE},
200 {"",},
201 {"char", TYPESPEC, RID_CHAR},
122026c0 202 {"__volatile", TYPE_QUAL, RID_VOLATILE},
c4c7fef1
RS
203 {"__alignof", ALIGNOF, NORID},
204 {"typeof", TYPEOF, NORID},
205 {"typedef", SCSPEC, RID_TYPEDEF},
122026c0
RS
206 {"const", TYPE_QUAL, RID_CONST},
207 {"for", FOR, NORID},
122026c0 208 {"",}, {"",},
c4c7fef1
RS
209 {"auto", SCSPEC, RID_AUTO},
210 {"unsigned", TYPESPEC, RID_UNSIGNED},
211 {"",},
212 {"double", TYPESPEC, RID_DOUBLE},
122026c0 213 {"continue", CONTINUE, NORID},
c4c7fef1 214 {"",},
122026c0 215 {"register", SCSPEC, RID_REGISTER},
122026c0 216 {"",}, {"",},
6506ecd7 217 {"volatile", TYPE_QUAL, RID_VOLATILE},
c4c7fef1
RS
218 {"",}, {"",},
219 {"asm", ASM_KEYWORD, NORID},
220 {"",}, {"",}, {"",}, {"",}, {"",},
221 {"float", TYPESPEC, RID_FLOAT},
222 {"",}, {"",},
223 {"goto", GOTO, NORID},
224 {"",}, {"",}, {"",}, {"",}, {"",},
225 {"long", TYPESPEC, RID_LONG},
226 {"",},
122026c0
RS
227 {"enum", ENUM, NORID},
228 {"",},
c4c7fef1 229 {"union", UNION, NORID},
e8bbfc4e
RK
230 };
231
232 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
233 {
234 register int key = hash (str, len);
235
236 if (key <= MAX_HASH_VALUE && key >= 0)
237 {
238 register char *s = wordlist[key].name;
239
240 if (*s == *str && !strcmp (str + 1, s + 1))
241 return &wordlist[key];
242 }
243 }
244 return 0;
245}
246\f
247/* Return something to represent absolute declarators containing a *.
248 TARGET is the absolute declarator that the * contains.
249 TYPE_QUALS is a list of modifiers such as const or volatile
250 to apply to the pointer type, represented as identifiers.
251
252 We return an INDIRECT_REF whose "contents" are TARGET
253 and whose type is the modifier list. */
254
255tree
256make_pointer_declarator (type_quals, target)
257 tree type_quals, target;
258{
259 return build1 (INDIRECT_REF, type_quals, target);
260}
261\f
262void
263init_lex ()
264{
265 /* Make identifier nodes long enough for the language-specific slots. */
266 set_identifier_size (sizeof (struct lang_identifier));
267
268 /* Start it at 0, because check_newline is called at the very beginning
269 and will increment it to 1. */
270 lineno = 0;
271
272#ifdef MULTIBYTE_CHARS
273 /* Change to the native locale for multibyte conversions. */
274 setlocale (LC_CTYPE, "");
275#endif
276
277 maxtoken = 40;
278 token_buffer = (char *) xmalloc (maxtoken + 2);
279
280 ridpointers[(int) RID_INT] = get_identifier ("int");
281 ridpointers[(int) RID_CHAR] = get_identifier ("char");
282 ridpointers[(int) RID_VOID] = get_identifier ("void");
283 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
284 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
285 ridpointers[(int) RID_SHORT] = get_identifier ("short");
286 ridpointers[(int) RID_LONG] = get_identifier ("long");
287 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
288 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
289 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
290 ridpointers[(int) RID_CONST] = get_identifier ("const");
291 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
292 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
293 ridpointers[(int) RID_STATIC] = get_identifier ("static");
294 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
295 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
296 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
6506ecd7 297 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
122026c0 298 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
e8bbfc4e
RK
299
300 /* Some options inhibit certain reserved words.
301 Clear those words out of the hash table so they won't be recognized. */
302#define UNSET_RESERVED_WORD(STRING) \
303 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
304 if (s) s->name = ""; } while (0)
305
306 if (flag_traditional)
307 {
308 UNSET_RESERVED_WORD ("const");
309 UNSET_RESERVED_WORD ("volatile");
310 UNSET_RESERVED_WORD ("typeof");
311 UNSET_RESERVED_WORD ("signed");
312 UNSET_RESERVED_WORD ("inline");
6f2f09cd 313 UNSET_RESERVED_WORD ("iterator");
122026c0 314 UNSET_RESERVED_WORD ("complex");
e8bbfc4e
RK
315 }
316 if (flag_no_asm)
317 {
318 UNSET_RESERVED_WORD ("asm");
319 UNSET_RESERVED_WORD ("typeof");
320 UNSET_RESERVED_WORD ("inline");
6f2f09cd 321 UNSET_RESERVED_WORD ("iterator");
122026c0 322 UNSET_RESERVED_WORD ("complex");
e8bbfc4e
RK
323 }
324}
325
326void
327reinit_parse_for_function ()
328{
329}
330\f
331/* Function used when yydebug is set, to print a token in more detail. */
332
333void
334yyprint (file, yychar, yylval)
335 FILE *file;
336 int yychar;
337 YYSTYPE yylval;
338{
339 tree t;
340 switch (yychar)
341 {
342 case IDENTIFIER:
343 case TYPENAME:
344 t = yylval.ttype;
345 if (IDENTIFIER_POINTER (t))
346 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
347 break;
348
349 case CONSTANT:
350 t = yylval.ttype;
351 if (TREE_CODE (t) == INTEGER_CST)
8d9bfdc5
RK
352 fprintf (file,
353#if HOST_BITS_PER_WIDE_INT == 64
354#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
355 " 0x%lx%016lx",
356#else
357 " 0x%x%016x",
358#endif
359#else
360#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
361 " 0x%lx%08lx",
362#else
363 " 0x%x%08x",
364#endif
365#endif
366 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
e8bbfc4e
RK
367 break;
368 }
369}
370
371\f
372/* If C is not whitespace, return C.
373 Otherwise skip whitespace and return first nonwhite char read. */
374
375static int
376skip_white_space (c)
377 register int c;
378{
0dcd8cee 379 static int newline_warning = 0;
e8bbfc4e
RK
380
381 for (;;)
382 {
383 switch (c)
384 {
0dcd8cee
RS
385 /* We don't recognize comments here, because
386 cpp output can include / and * consecutively as operators.
387 Also, there's no need, since cpp removes all comments. */
e8bbfc4e
RK
388
389 case '\n':
390 c = check_newline ();
391 break;
392
393 case ' ':
394 case '\t':
395 case '\f':
e8bbfc4e
RK
396 case '\v':
397 case '\b':
398 c = getc (finput);
399 break;
400
0dcd8cee
RS
401 case '\r':
402 /* ANSI C says the effects of a carriage return in a source file
403 are undefined. */
404 if (pedantic && !newline_warning)
405 {
406 warning ("carriage return in source file");
407 warning ("(we only warn about the first carriage return)");
408 newline_warning = 1;
409 }
410 c = getc (finput);
411 break;
412
e8bbfc4e
RK
413 case '\\':
414 c = getc (finput);
415 if (c == '\n')
416 lineno++;
417 else
418 error ("stray '\\' in program");
419 c = getc (finput);
420 break;
421
422 default:
423 return (c);
424 }
425 }
426}
427
428/* Skips all of the white space at the current location in the input file.
429 Must use and reset nextchar if it has the next character. */
430
431void
432position_after_white_space ()
433{
434 register int c;
435
436 if (nextchar != -1)
437 c = nextchar, nextchar = -1;
438 else
439 c = getc (finput);
440
441 ungetc (skip_white_space (c), finput);
442}
443
444/* Make the token buffer longer, preserving the data in it.
445 P should point to just beyond the last valid character in the old buffer.
446 The value we return is a pointer to the new buffer
447 at a place corresponding to P. */
448
449static char *
450extend_token_buffer (p)
451 char *p;
452{
453 int offset = p - token_buffer;
454
455 maxtoken = maxtoken * 2 + 10;
456 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
457
458 return token_buffer + offset;
459}
460\f
461/* At the beginning of a line, increment the line number
462 and process any #-directive on this line.
463 If the line is a #-directive, read the entire line and return a newline.
464 Otherwise, return the line's first non-whitespace character. */
465
466int
467check_newline ()
468{
469 register int c;
470 register int token;
471
472 lineno++;
473
474 /* Read first nonwhite char on the line. */
475
476 c = getc (finput);
477 while (c == ' ' || c == '\t')
478 c = getc (finput);
479
480 if (c != '#')
481 {
482 /* If not #, return it so caller will use it. */
483 return c;
484 }
485
486 /* Read first nonwhite char after the `#'. */
487
488 c = getc (finput);
489 while (c == ' ' || c == '\t')
490 c = getc (finput);
491
492 /* If a letter follows, then if the word here is `line', skip
493 it and ignore it; otherwise, ignore the line, with an error
494 if the word isn't `pragma', `ident', `define', or `undef'. */
495
496 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
497 {
498 if (c == 'p')
499 {
500 if (getc (finput) == 'r'
501 && getc (finput) == 'a'
502 && getc (finput) == 'g'
503 && getc (finput) == 'm'
504 && getc (finput) == 'a'
505 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
506 {
ca5b800a 507#ifdef HANDLE_SYSV_PRAGMA
a3100298 508 return handle_sysv_pragma (finput, c);
ca5b800a 509#endif /* HANDLE_SYSV_PRAGMA */
e8bbfc4e
RK
510#ifdef HANDLE_PRAGMA
511 HANDLE_PRAGMA (finput);
512#endif /* HANDLE_PRAGMA */
513 goto skipline;
514 }
515 }
516
517 else if (c == 'd')
518 {
519 if (getc (finput) == 'e'
520 && getc (finput) == 'f'
521 && getc (finput) == 'i'
522 && getc (finput) == 'n'
523 && getc (finput) == 'e'
524 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
525 {
526#ifdef DWARF_DEBUGGING_INFO
527 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
528 && (write_symbols == DWARF_DEBUG))
529 dwarfout_define (lineno, get_directive_line (finput));
530#endif /* DWARF_DEBUGGING_INFO */
531 goto skipline;
532 }
533 }
534 else if (c == 'u')
535 {
536 if (getc (finput) == 'n'
537 && getc (finput) == 'd'
538 && getc (finput) == 'e'
539 && getc (finput) == 'f'
540 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
541 {
542#ifdef DWARF_DEBUGGING_INFO
543 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
544 && (write_symbols == DWARF_DEBUG))
545 dwarfout_undef (lineno, get_directive_line (finput));
546#endif /* DWARF_DEBUGGING_INFO */
547 goto skipline;
548 }
549 }
550 else if (c == 'l')
551 {
552 if (getc (finput) == 'i'
553 && getc (finput) == 'n'
554 && getc (finput) == 'e'
555 && ((c = getc (finput)) == ' ' || c == '\t'))
556 goto linenum;
557 }
558 else if (c == 'i')
559 {
560 if (getc (finput) == 'd'
561 && getc (finput) == 'e'
562 && getc (finput) == 'n'
563 && getc (finput) == 't'
564 && ((c = getc (finput)) == ' ' || c == '\t'))
565 {
566 /* #ident. The pedantic warning is now in cccp.c. */
567
568 /* Here we have just seen `#ident '.
569 A string constant should follow. */
570
571 while (c == ' ' || c == '\t')
572 c = getc (finput);
573
574 /* If no argument, ignore the line. */
575 if (c == '\n')
576 return c;
577
578 ungetc (c, finput);
579 token = yylex ();
580 if (token != STRING
581 || TREE_CODE (yylval.ttype) != STRING_CST)
582 {
583 error ("invalid #ident");
584 goto skipline;
585 }
586
587 if (!flag_no_ident)
588 {
589#ifdef ASM_OUTPUT_IDENT
590 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
591#endif
592 }
593
594 /* Skip the rest of this line. */
595 goto skipline;
596 }
597 }
598
599 error ("undefined or invalid # directive");
600 goto skipline;
601 }
602
603linenum:
604 /* Here we have either `#line' or `# <nonletter>'.
605 In either case, it should be a line number; a digit should follow. */
606
607 while (c == ' ' || c == '\t')
608 c = getc (finput);
609
610 /* If the # is the only nonwhite char on the line,
611 just ignore it. Check the new newline. */
612 if (c == '\n')
613 return c;
614
615 /* Something follows the #; read a token. */
616
617 ungetc (c, finput);
618 token = yylex ();
619
620 if (token == CONSTANT
621 && TREE_CODE (yylval.ttype) == INTEGER_CST)
622 {
623 int old_lineno = lineno;
624 int used_up = 0;
625 /* subtract one, because it is the following line that
626 gets the specified number */
627
628 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
629
630 /* Is this the last nonwhite stuff on the line? */
631 c = getc (finput);
632 while (c == ' ' || c == '\t')
633 c = getc (finput);
634 if (c == '\n')
635 {
636 /* No more: store the line number and check following line. */
637 lineno = l;
638 return c;
639 }
640 ungetc (c, finput);
641
642 /* More follows: it must be a string constant (filename). */
643
644 /* Read the string constant, but don't treat \ as special. */
645 ignore_escape_flag = 1;
646 token = yylex ();
647 ignore_escape_flag = 0;
648
649 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
650 {
651 error ("invalid #line");
652 goto skipline;
653 }
654
655 input_filename
656 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
657 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
658 lineno = l;
659
660 /* Each change of file name
661 reinitializes whether we are now in a system header. */
662 in_system_header = 0;
663
664 if (main_input_filename == 0)
665 main_input_filename = input_filename;
666
667 /* Is this the last nonwhite stuff on the line? */
668 c = getc (finput);
669 while (c == ' ' || c == '\t')
670 c = getc (finput);
671 if (c == '\n')
5b450ae5
RS
672 {
673 /* Update the name in the top element of input_file_stack. */
674 if (input_file_stack)
675 input_file_stack->name = input_filename;
676
677 return c;
678 }
e8bbfc4e
RK
679 ungetc (c, finput);
680
681 token = yylex ();
682 used_up = 0;
683
684 /* `1' after file name means entering new file.
685 `2' after file name means just left a file. */
686
687 if (token == CONSTANT
688 && TREE_CODE (yylval.ttype) == INTEGER_CST)
689 {
690 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
691 {
692 /* Pushing to a new file. */
693 struct file_stack *p
694 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
695 input_file_stack->line = old_lineno;
696 p->next = input_file_stack;
697 p->name = input_filename;
698 input_file_stack = p;
699 input_file_stack_tick++;
700#ifdef DWARF_DEBUGGING_INFO
701 if (debug_info_level == DINFO_LEVEL_VERBOSE
702 && write_symbols == DWARF_DEBUG)
703 dwarfout_start_new_source_file (input_filename);
704#endif /* DWARF_DEBUGGING_INFO */
705
706 used_up = 1;
707 }
708 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
709 {
710 /* Popping out of a file. */
711 if (input_file_stack->next)
712 {
713 struct file_stack *p = input_file_stack;
714 input_file_stack = p->next;
715 free (p);
716 input_file_stack_tick++;
717#ifdef DWARF_DEBUGGING_INFO
718 if (debug_info_level == DINFO_LEVEL_VERBOSE
719 && write_symbols == DWARF_DEBUG)
720 dwarfout_resume_previous_source_file (input_file_stack->line);
721#endif /* DWARF_DEBUGGING_INFO */
722 }
723 else
724 error ("#-lines for entering and leaving files don't match");
725
726 used_up = 1;
727 }
728 }
729
5b450ae5
RS
730 /* Now that we've pushed or popped the input stack,
731 update the name in the top element. */
732 if (input_file_stack)
733 input_file_stack->name = input_filename;
734
e8bbfc4e
RK
735 /* If we have handled a `1' or a `2',
736 see if there is another number to read. */
737 if (used_up)
738 {
739 /* Is this the last nonwhite stuff on the line? */
740 c = getc (finput);
741 while (c == ' ' || c == '\t')
742 c = getc (finput);
743 if (c == '\n')
744 return c;
745 ungetc (c, finput);
746
747 token = yylex ();
748 used_up = 0;
749 }
750
751 /* `3' after file name means this is a system header file. */
752
753 if (token == CONSTANT
754 && TREE_CODE (yylval.ttype) == INTEGER_CST
755 && TREE_INT_CST_LOW (yylval.ttype) == 3)
756 in_system_header = 1;
757 }
758 else
759 error ("invalid #-line");
760
761 /* skip the rest of this line. */
762 skipline:
763 if (c == '\n')
764 return c;
765 while ((c = getc (finput)) != EOF && c != '\n');
766 return c;
767}
768\f
ca5b800a
RS
769#ifdef HANDLE_SYSV_PRAGMA
770
771/* Handle a #pragma directive. INPUT is the current input stream,
a3100298
TW
772 and C is a character to reread. Processes the entire input line
773 and returns a character for the caller to reread: either \n or EOF. */
ca5b800a
RS
774
775/* This function has to be in this file, in order to get at
776 the token types. */
777
778int
779handle_sysv_pragma (input, c)
780 FILE *input;
781 int c;
782{
a3100298 783 for (;;)
ca5b800a 784 {
a3100298
TW
785 while (c == ' ' || c == '\t')
786 c = getc (input);
787 if (c == '\n' || c == EOF)
788 {
789 handle_pragma_token (0, 0);
790 return c;
791 }
792 ungetc (c, input);
793 switch (yylex ())
794 {
795 case IDENTIFIER:
796 case TYPENAME:
797 case STRING:
798 case CONSTANT:
799 handle_pragma_token (token_buffer, yylval.ttype);
800 break;
801 default:
802 handle_pragma_token (token_buffer, 0);
803 }
804 if (nextchar >= 0)
805 c = nextchar, nextchar = -1;
806 else
807 c = getc (input);
ca5b800a 808 }
ca5b800a
RS
809}
810
811#endif /* HANDLE_SYSV_PRAGMA */
812\f
e8bbfc4e
RK
813#define isalnum(char) ((char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'))
814#define isdigit(char) (char >= '0' && char <= '9')
815#define ENDFILE -1 /* token that represents end-of-file */
816
817/* Read an escape sequence, returning its equivalent as a character,
b70af677 818 or store 1 in *ignore_ptr if it is backslash-newline. */
e8bbfc4e
RK
819
820static int
b70af677
RS
821readescape (ignore_ptr)
822 int *ignore_ptr;
e8bbfc4e
RK
823{
824 register int c = getc (finput);
825 register int code;
826 register unsigned count;
827 unsigned firstdig;
8696da34 828 int nonnull;
e8bbfc4e
RK
829
830 switch (c)
831 {
832 case 'x':
833 if (warn_traditional)
834 warning ("the meaning of `\\x' varies with -traditional");
835
836 if (flag_traditional)
837 return c;
838
839 code = 0;
840 count = 0;
8696da34 841 nonnull = 0;
e8bbfc4e
RK
842 while (1)
843 {
844 c = getc (finput);
845 if (!(c >= 'a' && c <= 'f')
846 && !(c >= 'A' && c <= 'F')
847 && !(c >= '0' && c <= '9'))
848 {
849 ungetc (c, finput);
850 break;
851 }
852 code *= 16;
853 if (c >= 'a' && c <= 'f')
854 code += c - 'a' + 10;
855 if (c >= 'A' && c <= 'F')
856 code += c - 'A' + 10;
857 if (c >= '0' && c <= '9')
858 code += c - '0';
8696da34
RS
859 if (code != 0 || count != 0)
860 {
861 if (count == 0)
862 firstdig = code;
863 count++;
864 }
865 nonnull = 1;
e8bbfc4e 866 }
8696da34 867 if (! nonnull)
e8bbfc4e 868 error ("\\x used with no following hex digits");
be63d912
RS
869 else if (count == 0)
870 /* Digits are all 0's. Ok. */
871 ;
e8bbfc4e
RK
872 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
873 || (count > 1
874 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
875 <= firstdig)))
876 pedwarn ("hex escape out of range");
877 return code;
878
879 case '0': case '1': case '2': case '3': case '4':
880 case '5': case '6': case '7':
881 code = 0;
882 count = 0;
883 while ((c <= '7') && (c >= '0') && (count++ < 3))
884 {
885 code = (code * 8) + (c - '0');
886 c = getc (finput);
887 }
888 ungetc (c, finput);
889 return code;
890
891 case '\\': case '\'': case '"':
892 return c;
893
894 case '\n':
895 lineno++;
b70af677
RS
896 *ignore_ptr = 1;
897 return 0;
e8bbfc4e
RK
898
899 case 'n':
900 return TARGET_NEWLINE;
901
902 case 't':
903 return TARGET_TAB;
904
905 case 'r':
906 return TARGET_CR;
907
908 case 'f':
909 return TARGET_FF;
910
911 case 'b':
912 return TARGET_BS;
913
914 case 'a':
915 if (warn_traditional)
916 warning ("the meaning of `\\a' varies with -traditional");
917
918 if (flag_traditional)
919 return c;
920 return TARGET_BELL;
921
922 case 'v':
923#if 0 /* Vertical tab is present in common usage compilers. */
924 if (flag_traditional)
925 return c;
926#endif
927 return TARGET_VT;
928
dad112ca 929 case 'e':
e8bbfc4e 930 case 'E':
dad112ca
RS
931 if (pedantic)
932 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
e8bbfc4e
RK
933 return 033;
934
935 case '?':
936 return c;
937
938 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
939 case '(':
940 case '{':
941 case '[':
942 if (pedantic)
943 pedwarn ("non-ANSI escape sequence `\\%c'", c);
944 return c;
945 }
7e6b19dc 946 if (c >= 040 && c < 0177)
e8bbfc4e
RK
947 pedwarn ("unknown escape sequence `\\%c'", c);
948 else
949 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
950 return c;
951}
952\f
953void
954yyerror (string)
955 char *string;
956{
957 char buf[200];
958
959 strcpy (buf, string);
960
961 /* We can't print string and character constants well
962 because the token_buffer contains the result of processing escapes. */
963 if (end_of_file)
964 strcat (buf, " at end of input");
965 else if (token_buffer[0] == 0)
966 strcat (buf, " at null character");
967 else if (token_buffer[0] == '"')
968 strcat (buf, " before string constant");
969 else if (token_buffer[0] == '\'')
970 strcat (buf, " before character constant");
971 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
972 sprintf (buf + strlen (buf), " before character 0%o",
973 (unsigned char) token_buffer[0]);
974 else
975 strcat (buf, " before `%s'");
976
977 error (buf, token_buffer);
978}
979
980#if 0
981
982struct try_type
983{
984 tree *node_var;
985 char unsigned_flag;
986 char long_flag;
987 char long_long_flag;
988};
989
990struct try_type type_sequence[] =
991{
992 { &integer_type_node, 0, 0, 0},
993 { &unsigned_type_node, 1, 0, 0},
994 { &long_integer_type_node, 0, 1, 0},
995 { &long_unsigned_type_node, 1, 1, 0},
996 { &long_long_integer_type_node, 0, 1, 1},
997 { &long_long_unsigned_type_node, 1, 1, 1}
998};
999#endif /* 0 */
1000\f
1001int
1002yylex ()
1003{
1004 register int c;
1005 register char *p;
1006 register int value;
1007 int wide_flag = 0;
1008
1009 if (nextchar >= 0)
1010 c = nextchar, nextchar = -1;
1011 else
1012 c = getc (finput);
1013
1014 /* Effectively do c = skip_white_space (c)
1015 but do it faster in the usual cases. */
1016 while (1)
1017 switch (c)
1018 {
e8bbfc4e
RK
1019 case ' ':
1020 case '\t':
1021 case '\f':
1022 case '\v':
1023 case '\b':
1024 c = getc (finput);
1025 break;
1026
80f5b9d8
RS
1027 case '\r':
1028 /* Call skip_white_space so we can warn if appropriate. */
1029
e8bbfc4e
RK
1030 case '\n':
1031 case '/':
1032 case '\\':
1033 c = skip_white_space (c);
1034 default:
1035 goto found_nonwhite;
1036 }
1037 found_nonwhite:
1038
1039 token_buffer[0] = c;
1040 token_buffer[1] = 0;
1041
1042/* yylloc.first_line = lineno; */
1043
1044 switch (c)
1045 {
1046 case EOF:
1047 end_of_file = 1;
1048 token_buffer[0] = 0;
1049 value = ENDFILE;
1050 break;
1051
1052 case '$':
1053 if (dollars_in_ident)
1054 goto letter;
1055 return '$';
1056
1057 case 'L':
1058 /* Capital L may start a wide-string or wide-character constant. */
1059 {
1060 register int c = getc (finput);
1061 if (c == '\'')
1062 {
1063 wide_flag = 1;
1064 goto char_constant;
1065 }
1066 if (c == '"')
1067 {
1068 wide_flag = 1;
1069 goto string_constant;
1070 }
1071 ungetc (c, finput);
1072 }
1073 goto letter;
1074
1075 case '@':
1076 if (!doing_objc_thang)
1077 {
1078 value = c;
1079 break;
1080 }
1081 p = token_buffer;
1082 *p++ = '@';
1083 c = getc (finput);
1084 while (isalnum (c) || c == '_')
1085 {
1086 if (p >= token_buffer + maxtoken)
1087 p = extend_token_buffer (p);
1088
1089 *p++ = c;
1090 c = getc (finput);
1091 }
1092
1093 *p = 0;
1094 nextchar = c;
1095 value = recognize_objc_keyword (token_buffer + 1);
1096 if (value != 0)
1097 break;
1098 error ("invalid Objective C keyword `%s'", token_buffer);
1099 /* Cause a syntax error--1 is not a valid token type. */
1100 value = 1;
1101 break;
1102
1103 case 'A': case 'B': case 'C': case 'D': case 'E':
1104 case 'F': case 'G': case 'H': case 'I': case 'J':
1105 case 'K': case 'M': case 'N': case 'O':
1106 case 'P': case 'Q': case 'R': case 'S': case 'T':
1107 case 'U': case 'V': case 'W': case 'X': case 'Y':
1108 case 'Z':
1109 case 'a': case 'b': case 'c': case 'd': case 'e':
1110 case 'f': case 'g': case 'h': case 'i': case 'j':
1111 case 'k': case 'l': case 'm': case 'n': case 'o':
1112 case 'p': case 'q': case 'r': case 's': case 't':
1113 case 'u': case 'v': case 'w': case 'x': case 'y':
1114 case 'z':
1115 case '_':
1116 letter:
1117 p = token_buffer;
1118 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1119 {
8355fc27
RS
1120 /* Make sure this char really belongs in an identifier. */
1121 if (c == '@' && ! doing_objc_thang)
1122 break;
e8bbfc4e
RK
1123 if (c == '$' && ! dollars_in_ident)
1124 break;
1125
8355fc27
RS
1126 if (p >= token_buffer + maxtoken)
1127 p = extend_token_buffer (p);
1128
e8bbfc4e
RK
1129 *p++ = c;
1130 c = getc (finput);
1131 }
1132
1133 *p = 0;
1134 nextchar = c;
1135
1136 value = IDENTIFIER;
1137 yylval.itype = 0;
1138
1139 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1140
1141 {
1142 register struct resword *ptr;
1143
1144 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1145 {
1146 if (ptr->rid)
1147 yylval.ttype = ridpointers[(int) ptr->rid];
1148 value = (int) ptr->token;
1149
1150 /* Even if we decided to recognize asm, still perhaps warn. */
1151 if (pedantic
d45cf215 1152 && (value == ASM_KEYWORD || value == TYPEOF
e8bbfc4e
RK
1153 || ptr->rid == RID_INLINE)
1154 && token_buffer[0] != '_')
1155 pedwarn ("ANSI does not permit the keyword `%s'",
1156 token_buffer);
1157 }
1158 }
1159
1160 /* If we did not find a keyword, look for an identifier
1161 (or a typename). */
1162
1163 if (value == IDENTIFIER)
1164 {
1165 yylval.ttype = get_identifier (token_buffer);
1166 lastiddecl = lookup_name (yylval.ttype);
1167
1168 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1169 value = TYPENAME;
6dbf678a
RS
1170 /* A user-invisible read-only initialized variable
1171 should be replaced by its value.
1172 We handle only strings since that's the only case used in C. */
1173 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1174 && DECL_IGNORED_P (lastiddecl)
1175 && TREE_READONLY (lastiddecl)
1176 && DECL_INITIAL (lastiddecl) != 0
1177 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1178 {
8f7ac220
RS
1179 tree stringval = DECL_INITIAL (lastiddecl);
1180
1181 /* Copy the string value so that we won't clobber anything
1182 if we put something in the TREE_CHAIN of this one. */
1183 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1184 TREE_STRING_POINTER (stringval));
6dbf678a
RS
1185 value = STRING;
1186 }
e8bbfc4e
RK
1187 else if (doing_objc_thang)
1188 {
1189 tree objc_interface_decl = lookup_interface (yylval.ttype);
1190
1191 if (objc_interface_decl)
1192 {
1193 value = CLASSNAME;
1194 yylval.ttype = objc_interface_decl;
1195 }
1196 }
1197 }
1198
1199 break;
1200
1201 case '0': case '1': case '2': case '3': case '4':
1202 case '5': case '6': case '7': case '8': case '9':
1203 case '.':
1204 {
1205 int base = 10;
1206 int count = 0;
1207 int largest_digit = 0;
1208 int numdigits = 0;
1209 /* for multi-precision arithmetic,
4ca827d0
RS
1210 we actually store only HOST_BITS_PER_CHAR bits in each part.
1211 The number of parts is chosen so as to be sufficient to hold
9b0995aa
RK
1212 the enough bits to fit into the two HOST_WIDE_INTs that contain
1213 the integer value (this is always at least as many bits as are
1214 in a target `long long' value, but may be wider). */
1215#define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
4ca827d0 1216 int parts[TOTAL_PARTS];
e8bbfc4e
RK
1217 int overflow = 0;
1218
1219 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1220 = NOT_FLOAT;
1221
4ca827d0
RS
1222 for (count = 0; count < TOTAL_PARTS; count++)
1223 parts[count] = 0;
e8bbfc4e
RK
1224
1225 p = token_buffer;
1226 *p++ = c;
1227
1228 if (c == '0')
1229 {
1230 *p++ = (c = getc (finput));
1231 if ((c == 'x') || (c == 'X'))
1232 {
1233 base = 16;
1234 *p++ = (c = getc (finput));
1235 }
1236 /* Leading 0 forces octal unless the 0 is the only digit. */
1237 else if (c >= '0' && c <= '9')
1238 {
1239 base = 8;
1240 numdigits++;
1241 }
1242 else
1243 numdigits++;
1244 }
1245
1246 /* Read all the digits-and-decimal-points. */
1247
1248 while (c == '.'
122026c0
RS
1249 || (isalnum (c) && c != 'l' && c != 'L'
1250 && c != 'u' && c != 'U'
1251 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
e8bbfc4e
RK
1252 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1253 {
1254 if (c == '.')
1255 {
1256 if (base == 16)
1257 error ("floating constant may not be in radix 16");
1258 if (floatflag == AFTER_POINT)
1259 {
1260 error ("malformed floating constant");
1261 floatflag = TOO_MANY_POINTS;
1262 }
1263 else
1264 floatflag = AFTER_POINT;
1265
1266 base = 10;
1267 *p++ = c = getc (finput);
1268 /* Accept '.' as the start of a floating-point number
1269 only when it is followed by a digit.
1270 Otherwise, unread the following non-digit
1271 and use the '.' as a structural token. */
1272 if (p == token_buffer + 2 && !isdigit (c))
1273 {
1274 if (c == '.')
1275 {
1276 c = getc (finput);
1277 if (c == '.')
1278 {
1279 *p++ = c;
1280 *p = 0;
1281 return ELLIPSIS;
1282 }
1283 error ("parse error at `..'");
1284 }
1285 ungetc (c, finput);
1286 token_buffer[1] = 0;
1287 value = '.';
1288 goto done;
1289 }
1290 }
1291 else
1292 {
1293 /* It is not a decimal point.
1294 It should be a digit (perhaps a hex digit). */
1295
1296 if (isdigit (c))
1297 {
1298 c = c - '0';
1299 }
1300 else if (base <= 10)
1301 {
f3acae4d 1302 if (c == 'e' || c == 'E')
e8bbfc4e
RK
1303 {
1304 base = 10;
1305 floatflag = AFTER_POINT;
1306 break; /* start of exponent */
1307 }
1308 error ("nondigits in number and not hexadecimal");
1309 c = 0;
1310 }
1311 else if (c >= 'a')
1312 {
1313 c = c - 'a' + 10;
1314 }
1315 else
1316 {
1317 c = c - 'A' + 10;
1318 }
1319 if (c >= largest_digit)
1320 largest_digit = c;
1321 numdigits++;
1322
4ca827d0 1323 for (count = 0; count < TOTAL_PARTS; count++)
e8bbfc4e 1324 {
4ca827d0 1325 parts[count] *= base;
e8bbfc4e
RK
1326 if (count)
1327 {
4ca827d0
RS
1328 parts[count]
1329 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1330 parts[count-1]
1331 &= (1 << HOST_BITS_PER_CHAR) - 1;
e8bbfc4e 1332 }
4ca827d0
RS
1333 else
1334 parts[0] += c;
e8bbfc4e
RK
1335 }
1336
4ca827d0
RS
1337 /* If the extra highest-order part ever gets anything in it,
1338 the number is certainly too big. */
1339 if (parts[TOTAL_PARTS - 1] != 0)
1340 overflow = 1;
e8bbfc4e
RK
1341
1342 if (p >= token_buffer + maxtoken - 3)
1343 p = extend_token_buffer (p);
1344 *p++ = (c = getc (finput));
1345 }
1346 }
1347
1348 if (numdigits == 0)
1349 error ("numeric constant with no digits");
1350
1351 if (largest_digit >= base)
1352 error ("numeric constant contains digits beyond the radix");
1353
1354 /* Remove terminating char from the token buffer and delimit the string */
1355 *--p = 0;
1356
1357 if (floatflag != NOT_FLOAT)
1358 {
1359 tree type = double_type_node;
63ea33ce 1360 int garbage_chars = 0, exceeds_double = 0;
122026c0 1361 int imag = 0;
e8bbfc4e
RK
1362 REAL_VALUE_TYPE value;
1363 jmp_buf handler;
1364
1365 /* Read explicit exponent if any, and put it in tokenbuf. */
1366
1367 if ((c == 'e') || (c == 'E'))
1368 {
1369 if (p >= token_buffer + maxtoken - 3)
1370 p = extend_token_buffer (p);
1371 *p++ = c;
1372 c = getc (finput);
1373 if ((c == '+') || (c == '-'))
1374 {
1375 *p++ = c;
1376 c = getc (finput);
1377 }
1378 if (! isdigit (c))
1379 error ("floating constant exponent has no digits");
1380 while (isdigit (c))
1381 {
1382 if (p >= token_buffer + maxtoken - 3)
1383 p = extend_token_buffer (p);
1384 *p++ = c;
1385 c = getc (finput);
1386 }
1387 }
1388
1389 *p = 0;
1390 errno = 0;
1391
1392 /* Convert string to a double, checking for overflow. */
1393 if (setjmp (handler))
1394 {
1395 error ("floating constant out of range");
1396 value = dconst0;
1397 }
1398 else
1399 {
1400 set_float_handler (handler);
1454a5ba
RS
1401
1402/* The second argument, machine_mode, of REAL_VALUE_ATOF tells the
1403 desired precision of the binary result of decimal-to-binary conversion. */
e8bbfc4e
RK
1404
1405 /* Read the suffixes to choose a data type. */
63ea33ce
RS
1406 switch (c)
1407 {
1408 case 'f': case 'F':
1409 type = float_type_node;
1454a5ba
RS
1410 value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type));
1411 if (REAL_VALUE_ISINF (value) && pedantic)
63ea33ce
RS
1412 pedwarn ("floating point number exceeds range of `float'");
1413 garbage_chars = -1;
1414 break;
1415
1416 case 'l': case 'L':
1417 type = long_double_type_node;
1454a5ba
RS
1418 value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type));
1419 if (REAL_VALUE_ISINF (value) && pedantic)
1420 pedwarn (
1421 "floating point number exceeds range of `long double'");
63ea33ce
RS
1422 garbage_chars = -1;
1423 break;
122026c0
RS
1424
1425 case 'i': case 'I':
1426 if (imag)
1427 error ("more than one `i' or `j' in numeric constant");
1428 imag = 1;
1429 garbage_chars = -1;
1454a5ba
RS
1430 break;
1431
1432 default:
1433 value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type));
1434 if (REAL_VALUE_ISINF (value) && pedantic)
1435 pedwarn ("floating point number exceeds range of `double'");
63ea33ce 1436 }
1454a5ba
RS
1437 set_float_handler (NULL_PTR);
1438 }
1439#ifdef ERANGE
1440 if (errno == ERANGE && !flag_traditional && pedantic)
1441 {
1442 /* ERANGE is also reported for underflow,
1443 so test the value to distinguish overflow from that. */
1444 if (REAL_VALUES_LESS (dconst1, value)
1445 || REAL_VALUES_LESS (value, dconstm1))
1446 {
1447 pedwarn ("floating point number exceeds range of `double'");
1448 exceeds_double = 1;
1449 }
1450 }
1451#endif
63ea33ce 1452 /* Note: garbage_chars is -1 if first char is *not* garbage. */
f3acae4d
RS
1453 while (isalnum (c) || c == '.' || c == '_'
1454 || (!flag_traditional && (c == '+' || c == '-')
1455 && (p[-1] == 'e' || p[-1] == 'E')))
e8bbfc4e 1456 {
e8bbfc4e
RK
1457 if (p >= token_buffer + maxtoken - 3)
1458 p = extend_token_buffer (p);
1459 *p++ = c;
1460 c = getc (finput);
63ea33ce 1461 garbage_chars++;
e8bbfc4e 1462 }
63ea33ce
RS
1463 if (garbage_chars > 0)
1464 error ("garbage at end of number");
e8bbfc4e
RK
1465
1466 /* Create a node with determined type and value. */
122026c0
RS
1467 if (imag)
1468 yylval.ttype = build_complex (convert (type, integer_zero_node),
1469 build_real (type, value));
1470 else
1471 yylval.ttype = build_real (type, value);
e8bbfc4e
RK
1472
1473 ungetc (c, finput);
1474 *p = 0;
1475 }
1476 else
1477 {
1478 tree traditional_type, ansi_type, type;
8d9bfdc5 1479 HOST_WIDE_INT high, low;
e8bbfc4e
RK
1480 int spec_unsigned = 0;
1481 int spec_long = 0;
1482 int spec_long_long = 0;
122026c0 1483 int spec_imag = 0;
e8bbfc4e
RK
1484 int bytes, warn, i;
1485
1486 while (1)
1487 {
1488 if (c == 'u' || c == 'U')
1489 {
1490 if (spec_unsigned)
1491 error ("two `u's in integer constant");
1492 spec_unsigned = 1;
1493 }
1494 else if (c == 'l' || c == 'L')
1495 {
1496 if (spec_long)
1497 {
1498 if (spec_long_long)
1499 error ("three `l's in integer constant");
1500 else if (pedantic)
1501 pedwarn ("ANSI C forbids long long integer constants");
1502 spec_long_long = 1;
1503 }
1504 spec_long = 1;
1505 }
122026c0
RS
1506 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1507 {
1508 if (spec_imag)
1509 error ("more than one `i' or `j' in numeric constant");
1510 spec_imag = 1;
1511 }
e8bbfc4e
RK
1512 else
1513 {
f3acae4d
RS
1514 if (isalnum (c) || c == '.' || c == '_'
1515 || (!flag_traditional && (c == '+' || c == '-')
1516 && (p[-1] == 'e' || p[-1] == 'E')))
e8bbfc4e
RK
1517 {
1518 error ("garbage at end of number");
f3acae4d
RS
1519 while (isalnum (c) || c == '.' || c == '_'
1520 || (!flag_traditional && (c == '+' || c == '-')
1521 && (p[-1] == 'e' || p[-1] == 'E')))
e8bbfc4e
RK
1522 {
1523 if (p >= token_buffer + maxtoken - 3)
1524 p = extend_token_buffer (p);
1525 *p++ = c;
1526 c = getc (finput);
1527 }
1528 }
1529 break;
1530 }
1531 if (p >= token_buffer + maxtoken - 3)
1532 p = extend_token_buffer (p);
1533 *p++ = c;
1534 c = getc (finput);
1535 }
1536
1537 ungetc (c, finput);
1538
1539 /* If the constant is not long long and it won't fit in an
1540 unsigned long, or if the constant is long long and won't fit
1541 in an unsigned long long, then warn that the constant is out
1542 of range. */
1543
1544 /* ??? This assumes that long long and long integer types are
1545 a multiple of 8 bits. This better than the original code
1546 though which assumed that long was exactly 32 bits and long
1547 long was exactly 64 bits. */
1548
1549 if (spec_long_long)
1550 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1551 else
1552 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1553
4ca827d0
RS
1554 warn = overflow;
1555 for (i = bytes; i < TOTAL_PARTS; i++)
1556 if (parts[i])
1557 warn = 1;
1558 if (warn)
1559 pedwarn ("integer constant out of range");
e8bbfc4e
RK
1560
1561 /* This is simplified by the fact that our constant
1562 is always positive. */
8d9bfdc5
RK
1563
1564 high = low = 0;
1565
1566 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1567 {
1568 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1569 / HOST_BITS_PER_CHAR)]
1570 << (i * HOST_BITS_PER_CHAR));
1571 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1572 }
1573
1574 yylval.ttype = build_int_2 (low, high);
5a9085c7 1575 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
e8bbfc4e 1576
e8bbfc4e
RK
1577 /* If warn_traditional, calculate both the ANSI type and the
1578 traditional type, then see if they disagree.
1579 Otherwise, calculate only the type for the dialect in use. */
1580 if (warn_traditional || flag_traditional)
1581 {
1582 /* Calculate the traditional type. */
1583 /* Traditionally, any constant is signed;
1584 but if unsigned is specified explicitly, obey that.
1585 Use the smallest size with the right number of bits,
1586 except for one special case with decimal constants. */
1587 if (! spec_long && base != 10
1588 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1589 traditional_type = (spec_unsigned ? unsigned_type_node
1590 : integer_type_node);
1591 /* A decimal constant must be long
1592 if it does not fit in type int.
1593 I think this is independent of whether
1594 the constant is signed. */
1595 else if (! spec_long && base == 10
1596 && int_fits_type_p (yylval.ttype, integer_type_node))
1597 traditional_type = (spec_unsigned ? unsigned_type_node
1598 : integer_type_node);
4ca827d0 1599 else if (! spec_long_long)
e8bbfc4e
RK
1600 traditional_type = (spec_unsigned ? long_unsigned_type_node
1601 : long_integer_type_node);
1602 else
1603 traditional_type = (spec_unsigned
1604 ? long_long_unsigned_type_node
1605 : long_long_integer_type_node);
1606 }
1607 if (warn_traditional || ! flag_traditional)
1608 {
1609 /* Calculate the ANSI type. */
1610 if (! spec_long && ! spec_unsigned
1611 && int_fits_type_p (yylval.ttype, integer_type_node))
1612 ansi_type = integer_type_node;
1613 else if (! spec_long && (base != 10 || spec_unsigned)
1614 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1615 ansi_type = unsigned_type_node;
1616 else if (! spec_unsigned && !spec_long_long
1617 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1618 ansi_type = long_integer_type_node;
4ca827d0 1619 else if (! spec_long_long)
e8bbfc4e
RK
1620 ansi_type = long_unsigned_type_node;
1621 else if (! spec_unsigned
a120b788
RS
1622 /* Verify value does not overflow into sign bit. */
1623 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
e8bbfc4e
RK
1624 && int_fits_type_p (yylval.ttype,
1625 long_long_integer_type_node))
1626 ansi_type = long_long_integer_type_node;
1627 else
1628 ansi_type = long_long_unsigned_type_node;
1629 }
1630
1631 type = flag_traditional ? traditional_type : ansi_type;
1632
1633 if (warn_traditional && traditional_type != ansi_type)
1634 {
1635 if (TYPE_PRECISION (traditional_type)
1636 != TYPE_PRECISION (ansi_type))
1637 warning ("width of integer constant changes with -traditional");
1638 else if (TREE_UNSIGNED (traditional_type)
1639 != TREE_UNSIGNED (ansi_type))
1640 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
a3ee5899
JW
1641 else
1642 warning ("width of integer constant may change on other systems with -traditional");
e8bbfc4e 1643 }
e8bbfc4e 1644
4ca827d0
RS
1645 if (!flag_traditional && !int_fits_type_p (yylval.ttype, type)
1646 && !warn)
88d92ca5
RS
1647 pedwarn ("integer constant out of range");
1648
c832a30e 1649 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
ba99333a 1650 warning ("decimal constant is so large that it is unsigned");
c832a30e 1651
122026c0
RS
1652 if (spec_imag)
1653 {
1654 if (TYPE_PRECISION (type)
1655 <= TYPE_PRECISION (integer_type_node))
1656 yylval.ttype
1657 = build_complex (integer_zero_node,
1658 convert (integer_type_node, yylval.ttype));
1659 else
1660 error ("complex integer constant is too wide for `complex int'");
1661 }
1662 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
88dd95c1
RS
1663 /* The traditional constant 0x80000000 is signed
1664 but doesn't fit in the range of int.
1665 This will change it to -0x80000000, which does fit. */
1666 {
1667 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1668 yylval.ttype = convert (type, yylval.ttype);
1669 }
1670 else
1671 TREE_TYPE (yylval.ttype) = type;
1672
e8bbfc4e
RK
1673 *p = 0;
1674 }
1675
1676 value = CONSTANT; break;
1677 }
1678
1679 case '\'':
1680 char_constant:
1681 {
1682 register int result = 0;
a2543283 1683 register int num_chars = 0;
e8bbfc4e
RK
1684 unsigned width = TYPE_PRECISION (char_type_node);
1685 int max_chars;
1686
1687 if (wide_flag)
1688 {
1689 width = WCHAR_TYPE_SIZE;
1690#ifdef MULTIBYTE_CHARS
1691 max_chars = MB_CUR_MAX;
1692#else
1693 max_chars = 1;
1694#endif
1695 }
1696 else
1697 max_chars = TYPE_PRECISION (integer_type_node) / width;
1698
1699 while (1)
1700 {
1701 tryagain:
1702
1703 c = getc (finput);
1704
1705 if (c == '\'' || c == EOF)
1706 break;
1707
1708 if (c == '\\')
1709 {
b70af677
RS
1710 int ignore = 0;
1711 c = readescape (&ignore);
1712 if (ignore)
e8bbfc4e
RK
1713 goto tryagain;
1714 if (width < HOST_BITS_PER_INT
1715 && (unsigned) c >= (1 << width))
1716 pedwarn ("escape sequence out of range for character");
1717 }
1718 else if (c == '\n')
1719 {
1720 if (pedantic)
1721 pedwarn ("ANSI C forbids newline in character constant");
1722 lineno++;
1723 }
1724
1725 num_chars++;
1726 if (num_chars > maxtoken - 4)
1727 extend_token_buffer (token_buffer);
1728
1729 token_buffer[num_chars] = c;
1730
1731 /* Merge character into result; ignore excess chars. */
1732 if (num_chars < max_chars + 1)
1733 {
1734 if (width < HOST_BITS_PER_INT)
1735 result = (result << width) | (c & ((1 << width) - 1));
1736 else
1737 result = c;
1738 }
1739 }
1740
1741 token_buffer[num_chars + 1] = '\'';
1742 token_buffer[num_chars + 2] = 0;
1743
1744 if (c != '\'')
1745 error ("malformatted character constant");
1746 else if (num_chars == 0)
1747 error ("empty character constant");
1748 else if (num_chars > max_chars)
1749 {
1750 num_chars = max_chars;
1751 error ("character constant too long");
1752 }
1753 else if (num_chars != 1 && ! flag_traditional)
1754 warning ("multi-character character constant");
1755
1756 /* If char type is signed, sign-extend the constant. */
1757 if (! wide_flag)
1758 {
1759 int num_bits = num_chars * width;
1760 if (TREE_UNSIGNED (char_type_node)
1761 || ((result >> (num_bits - 1)) & 1) == 0)
1762 yylval.ttype
8d9bfdc5
RK
1763 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1764 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
e8bbfc4e
RK
1765 0);
1766 else
1767 yylval.ttype
8d9bfdc5
RK
1768 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1769 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
e8bbfc4e 1770 -1);
f3acae4d 1771 TREE_TYPE (yylval.ttype) = integer_type_node;
e8bbfc4e
RK
1772 }
1773 else
1774 {
1775#ifdef MULTIBYTE_CHARS
1776 /* Set the initial shift state and convert the next sequence. */
1777 result = 0;
1778 /* In all locales L'\0' is zero and mbtowc will return zero,
1779 so don't use it. */
1780 if (num_chars > 1
1781 || (num_chars == 1 && token_buffer[1] != '\0'))
1782 {
1783 wchar_t wc;
8d9bfdc5 1784 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
e8bbfc4e
RK
1785 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1786 result = wc;
1787 else
1788 warning ("Ignoring invalid multibyte character");
1789 }
1790#endif
1791 yylval.ttype = build_int_2 (result, 0);
f3acae4d 1792 TREE_TYPE (yylval.ttype) = wchar_type_node;
e8bbfc4e
RK
1793 }
1794
e8bbfc4e
RK
1795 value = CONSTANT;
1796 break;
1797 }
1798
1799 case '"':
1800 string_constant:
1801 {
1802 c = getc (finput);
1803 p = token_buffer + 1;
1804
1805 while (c != '"' && c >= 0)
1806 {
1807 /* ignore_escape_flag is set for reading the filename in #line. */
1808 if (!ignore_escape_flag && c == '\\')
1809 {
fad04099 1810 int ignore = 0;
b70af677
RS
1811 c = readescape (&ignore);
1812 if (ignore)
e8bbfc4e
RK
1813 goto skipnewline;
1814 if (!wide_flag
1815 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1816 && c >= (1 << TYPE_PRECISION (char_type_node)))
1817 pedwarn ("escape sequence out of range for character");
1818 }
1819 else if (c == '\n')
1820 {
1821 if (pedantic)
1822 pedwarn ("ANSI C forbids newline in string constant");
1823 lineno++;
1824 }
1825
1826 if (p == token_buffer + maxtoken)
1827 p = extend_token_buffer (p);
1828 *p++ = c;
1829
1830 skipnewline:
1831 c = getc (finput);
1832 }
1833 *p = 0;
1834
1835 /* We have read the entire constant.
1836 Construct a STRING_CST for the result. */
1837
1838 if (wide_flag)
1839 {
1840 /* If this is a L"..." wide-string, convert the multibyte string
1841 to a wide character string. */
1842 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1843 int len;
1844
1845#ifdef MULTIBYTE_CHARS
1846 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1847 if ((unsigned) len >= (p - token_buffer))
1848 {
1849 warning ("Ignoring invalid multibyte string");
1850 len = 0;
1851 }
1852 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1853#else
1854 {
1855 union { long l; char c[sizeof (long)]; } u;
1856 int big_endian;
1857 char *wp, *cp;
1858
1859 /* Determine whether host is little or big endian. */
1860 u.l = 1;
1861 big_endian = u.c[sizeof (long) - 1];
1862 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1863
1864 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1865 for (cp = token_buffer + 1; cp < p; cp++)
1866 *wp = *cp, wp += WCHAR_BYTES;
1867 len = p - token_buffer - 1;
1868 }
1869#endif
1870 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1871 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1872 }
1873 else
1874 {
1875 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
1876 TREE_TYPE (yylval.ttype) = char_array_type_node;
1877 }
1878
1879 *p++ = '"';
1880 *p = 0;
1881
1882 value = STRING; break;
1883 }
1884
1885 case '+':
1886 case '-':
1887 case '&':
1888 case '|':
1889 case '<':
1890 case '>':
1891 case '*':
1892 case '/':
1893 case '%':
1894 case '^':
1895 case '!':
1896 case '=':
1897 {
1898 register int c1;
1899
1900 combine:
1901
1902 switch (c)
1903 {
1904 case '+':
1905 yylval.code = PLUS_EXPR; break;
1906 case '-':
1907 yylval.code = MINUS_EXPR; break;
1908 case '&':
1909 yylval.code = BIT_AND_EXPR; break;
1910 case '|':
1911 yylval.code = BIT_IOR_EXPR; break;
1912 case '*':
1913 yylval.code = MULT_EXPR; break;
1914 case '/':
1915 yylval.code = TRUNC_DIV_EXPR; break;
1916 case '%':
1917 yylval.code = TRUNC_MOD_EXPR; break;
1918 case '^':
1919 yylval.code = BIT_XOR_EXPR; break;
1920 case LSHIFT:
1921 yylval.code = LSHIFT_EXPR; break;
1922 case RSHIFT:
1923 yylval.code = RSHIFT_EXPR; break;
1924 case '<':
1925 yylval.code = LT_EXPR; break;
1926 case '>':
1927 yylval.code = GT_EXPR; break;
1928 }
1929
1930 token_buffer[1] = c1 = getc (finput);
1931 token_buffer[2] = 0;
1932
1933 if (c1 == '=')
1934 {
1935 switch (c)
1936 {
1937 case '<':
1938 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
1939 case '>':
1940 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
1941 case '!':
1942 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
1943 case '=':
1944 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
1945 }
1946 value = ASSIGN; goto done;
1947 }
1948 else if (c == c1)
1949 switch (c)
1950 {
1951 case '+':
1952 value = PLUSPLUS; goto done;
1953 case '-':
1954 value = MINUSMINUS; goto done;
1955 case '&':
1956 value = ANDAND; goto done;
1957 case '|':
1958 value = OROR; goto done;
1959 case '<':
1960 c = LSHIFT;
1961 goto combine;
1962 case '>':
1963 c = RSHIFT;
1964 goto combine;
1965 }
1966 else if ((c == '-') && (c1 == '>'))
1967 { value = POINTSAT; goto done; }
1968 ungetc (c1, finput);
1969 token_buffer[1] = 0;
1970
1971 if ((c == '<') || (c == '>'))
1972 value = ARITHCOMPARE;
1973 else value = c;
1974 goto done;
1975 }
1976
1977 case 0:
1978 /* Don't make yyparse think this is eof. */
1979 value = 1;
1980 break;
1981
1982 default:
1983 value = c;
1984 }
1985
1986done:
1987/* yylloc.last_line = lineno; */
1988
1989 return value;
1990}
1991
d45cf215 1992/* Sets the value of the 'yydebug' variable to VALUE.
e8bbfc4e
RK
1993 This is a function so we don't have to have YYDEBUG defined
1994 in order to build the compiler. */
1995
1996void
1997set_yydebug (value)
1998 int value;
1999{
2000#if YYDEBUG != 0
2001 yydebug = value;
2002#else
2003 warning ("YYDEBUG not defined.");
2004#endif
2005}
This page took 0.29965 seconds and 5 git commands to generate.