OSDN Git Service

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