OSDN Git Service

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