OSDN Git Service

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