OSDN Git Service

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