OSDN Git Service

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