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