OSDN Git Service

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