OSDN Git Service

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