OSDN Git Service

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