OSDN Git Service

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