OSDN Git Service

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