OSDN Git Service

* exlsi.h (CHECK_FLOAT_VALUE): Removed.
[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               ungetc (c, finput);
407               token = yylex ();
408               if (token != IDENTIFIER)
409                 goto skipline;
410               return handle_sysv_pragma (finput, token);
411 #else /* !HANDLE_SYSV_PRAGMA */
412 #ifdef HANDLE_PRAGMA
413               ungetc (c, finput);
414               token = yylex ();
415               if (token != IDENTIFIER)
416                 goto skipline;
417               if (HANDLE_PRAGMA (finput, yylval.ttype))
418                 {
419                   c = getc (finput);
420                   return c;
421                 }
422 #endif /* HANDLE_PRAGMA */
423 #endif /* !HANDLE_SYSV_PRAGMA */
424               goto skipline;
425             }
426         }
427
428       else if (c == 'd')
429         {
430           if (getc (finput) == 'e'
431               && getc (finput) == 'f'
432               && getc (finput) == 'i'
433               && getc (finput) == 'n'
434               && getc (finput) == 'e'
435               && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
436             {
437 #ifdef DWARF_DEBUGGING_INFO
438               if (c != '\n'
439                   && (debug_info_level == DINFO_LEVEL_VERBOSE)
440                   && (write_symbols == DWARF_DEBUG))
441                 dwarfout_define (lineno, get_directive_line (finput));
442 #endif /* DWARF_DEBUGGING_INFO */
443               goto skipline;
444             }
445         }
446       else if (c == 'u')
447         {
448           if (getc (finput) == 'n'
449               && getc (finput) == 'd'
450               && getc (finput) == 'e'
451               && getc (finput) == 'f'
452               && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
453             {
454 #ifdef DWARF_DEBUGGING_INFO
455               if (c != '\n'
456                   && (debug_info_level == DINFO_LEVEL_VERBOSE)
457                   && (write_symbols == DWARF_DEBUG))
458                 dwarfout_undef (lineno, get_directive_line (finput));
459 #endif /* DWARF_DEBUGGING_INFO */
460               goto skipline;
461             }
462         }
463       else if (c == 'l')
464         {
465           if (getc (finput) == 'i'
466               && getc (finput) == 'n'
467               && getc (finput) == 'e'
468               && ((c = getc (finput)) == ' ' || c == '\t'))
469             goto linenum;
470         }
471       else if (c == 'i')
472         {
473           if (getc (finput) == 'd'
474               && getc (finput) == 'e'
475               && getc (finput) == 'n'
476               && getc (finput) == 't'
477               && ((c = getc (finput)) == ' ' || c == '\t'))
478             {
479               /* #ident.  The pedantic warning is now in cccp.c.  */
480
481               /* Here we have just seen `#ident '.
482                  A string constant should follow.  */
483
484               while (c == ' ' || c == '\t')
485                 c = getc (finput);
486
487               /* If no argument, ignore the line.  */
488               if (c == '\n')
489                 return c;
490
491               ungetc (c, finput);
492               token = yylex ();
493               if (token != STRING
494                   || TREE_CODE (yylval.ttype) != STRING_CST)
495                 {
496                   error ("invalid #ident");
497                   goto skipline;
498                 }
499
500               if (!flag_no_ident)
501                 {
502 #ifdef ASM_OUTPUT_IDENT
503                   ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
504 #endif
505                 }
506
507               /* Skip the rest of this line.  */
508               goto skipline;
509             }
510         }
511
512       error ("undefined or invalid # directive");
513       goto skipline;
514     }
515
516 linenum:
517   /* Here we have either `#line' or `# <nonletter>'.
518      In either case, it should be a line number; a digit should follow.  */
519
520   while (c == ' ' || c == '\t')
521     c = getc (finput);
522
523   /* If the # is the only nonwhite char on the line,
524      just ignore it.  Check the new newline.  */
525   if (c == '\n')
526     return c;
527
528   /* Something follows the #; read a token.  */
529
530   ungetc (c, finput);
531   token = yylex ();
532
533   if (token == CONSTANT
534       && TREE_CODE (yylval.ttype) == INTEGER_CST)
535     {
536       int old_lineno = lineno;
537       int used_up = 0;
538       /* subtract one, because it is the following line that
539          gets the specified number */
540
541       int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
542
543       /* Is this the last nonwhite stuff on the line?  */
544       c = getc (finput);
545       while (c == ' ' || c == '\t')
546         c = getc (finput);
547       if (c == '\n')
548         {
549           /* No more: store the line number and check following line.  */
550           lineno = l;
551           return c;
552         }
553       ungetc (c, finput);
554
555       /* More follows: it must be a string constant (filename).  */
556
557       /* Read the string constant.  */
558       token = yylex ();
559
560       if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
561         {
562           error ("invalid #line");
563           goto skipline;
564         }
565
566       input_filename
567         = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
568       strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
569       lineno = l;
570
571       /* Each change of file name
572          reinitializes whether we are now in a system header.  */
573       in_system_header = 0;
574
575       if (main_input_filename == 0)
576         main_input_filename = input_filename;
577
578       /* Is this the last nonwhite stuff on the line?  */
579       c = getc (finput);
580       while (c == ' ' || c == '\t')
581         c = getc (finput);
582       if (c == '\n')
583         {
584           /* Update the name in the top element of input_file_stack.  */
585           if (input_file_stack)
586             input_file_stack->name = input_filename;
587
588           return c;
589         }
590       ungetc (c, finput);
591
592       token = yylex ();
593       used_up = 0;
594
595       /* `1' after file name means entering new file.
596          `2' after file name means just left a file.  */
597
598       if (token == CONSTANT
599           && TREE_CODE (yylval.ttype) == INTEGER_CST)
600         {
601           if (TREE_INT_CST_LOW (yylval.ttype) == 1)
602             {
603               /* Pushing to a new file.  */
604               struct file_stack *p
605                 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
606               input_file_stack->line = old_lineno;
607               p->next = input_file_stack;
608               p->name = input_filename;
609               input_file_stack = p;
610               input_file_stack_tick++;
611 #ifdef DBX_DEBUGGING_INFO
612               if (write_symbols == DBX_DEBUG)
613                 dbxout_start_new_source_file (input_filename);
614 #endif
615 #ifdef DWARF_DEBUGGING_INFO
616               if (debug_info_level == DINFO_LEVEL_VERBOSE
617                   && write_symbols == DWARF_DEBUG)
618                 dwarfout_start_new_source_file (input_filename);
619 #endif /* DWARF_DEBUGGING_INFO */
620
621               used_up = 1;
622             }
623           else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
624             {
625               /* Popping out of a file.  */
626               if (input_file_stack->next)
627                 {
628                   struct file_stack *p = input_file_stack;
629                   input_file_stack = p->next;
630                   free (p);
631                   input_file_stack_tick++;
632 #ifdef DBX_DEBUGGING_INFO
633                   if (write_symbols == DBX_DEBUG)
634                     dbxout_resume_previous_source_file ();
635 #endif
636 #ifdef DWARF_DEBUGGING_INFO
637                   if (debug_info_level == DINFO_LEVEL_VERBOSE
638                       && write_symbols == DWARF_DEBUG)
639                     dwarfout_resume_previous_source_file (input_file_stack->line);
640 #endif /* DWARF_DEBUGGING_INFO */
641                 }
642               else
643                 error ("#-lines for entering and leaving files don't match");
644
645               used_up = 1;
646             }
647         }
648
649       /* Now that we've pushed or popped the input stack,
650          update the name in the top element.  */
651       if (input_file_stack)
652         input_file_stack->name = input_filename;
653
654       /* If we have handled a `1' or a `2',
655          see if there is another number to read.  */
656       if (used_up)
657         {
658           /* Is this the last nonwhite stuff on the line?  */
659           c = getc (finput);
660           while (c == ' ' || c == '\t')
661             c = getc (finput);
662           if (c == '\n')
663             return c;
664           ungetc (c, finput);
665
666           token = yylex ();
667           used_up = 0;
668         }
669
670       /* `3' after file name means this is a system header file.  */
671
672       if (token == CONSTANT
673           && TREE_CODE (yylval.ttype) == INTEGER_CST
674           && TREE_INT_CST_LOW (yylval.ttype) == 3)
675         in_system_header = 1, used_up = 1;
676
677       if (used_up)
678         {
679           /* Is this the last nonwhite stuff on the line?  */
680           c = getc (finput);
681           while (c == ' ' || c == '\t')
682             c = getc (finput);
683           if (c == '\n')
684             return c;
685           ungetc (c, finput);
686         }
687
688       warning ("unrecognized text at end of #line");
689     }
690   else
691     error ("invalid #-line");
692
693   /* skip the rest of this line.  */
694  skipline:
695   while (c != '\n' && c != EOF)
696     c = getc (finput);
697   return c;
698 }
699 \f
700 #ifdef HANDLE_SYSV_PRAGMA
701
702 /* Handle a #pragma directive.  INPUT is the current input stream,
703    and TOKEN is the token we read after `#pragma'.  Processes the entire input
704    line and returns a character for the caller to reread: either \n or EOF.  */
705
706 /* This function has to be in this file, in order to get at
707    the token types.  */
708
709 int
710 handle_sysv_pragma (input, token)
711      FILE *input;
712      register int token;
713 {
714   register int c;
715
716   for (;;)
717     {
718       switch (token)
719         {
720         case IDENTIFIER:
721         case TYPENAME:
722         case STRING:
723         case CONSTANT:
724           handle_pragma_token (token_buffer, yylval.ttype);
725           break;
726         default:
727           handle_pragma_token (token_buffer, 0);
728         }
729
730       if (nextchar >= 0)
731         c = nextchar, nextchar = -1;
732       else
733         c = getc (input);
734
735       while (c == ' ' || c == '\t')
736         c = getc (input);
737       if (c == '\n' || c == EOF)
738         {
739           handle_pragma_token (0, 0);
740           return c;
741         }
742       ungetc (c, input);
743       token = yylex ();
744     }
745 }
746
747 #endif /* HANDLE_SYSV_PRAGMA */
748 \f
749 #define ENDFILE -1  /* token that represents end-of-file */
750
751 /* Read an escape sequence, returning its equivalent as a character,
752    or store 1 in *ignore_ptr if it is backslash-newline.  */
753
754 static int
755 readescape (ignore_ptr)
756      int *ignore_ptr;
757 {
758   register int c = getc (finput);
759   register int code;
760   register unsigned count;
761   unsigned firstdig = 0;
762   int nonnull;
763
764   switch (c)
765     {
766     case 'x':
767       if (warn_traditional)
768         warning ("the meaning of `\\x' varies with -traditional");
769
770       if (flag_traditional)
771         return c;
772
773       code = 0;
774       count = 0;
775       nonnull = 0;
776       while (1)
777         {
778           c = getc (finput);
779           if (!(c >= 'a' && c <= 'f')
780               && !(c >= 'A' && c <= 'F')
781               && !(c >= '0' && c <= '9'))
782             {
783               ungetc (c, finput);
784               break;
785             }
786           code *= 16;
787           if (c >= 'a' && c <= 'f')
788             code += c - 'a' + 10;
789           if (c >= 'A' && c <= 'F')
790             code += c - 'A' + 10;
791           if (c >= '0' && c <= '9')
792             code += c - '0';
793           if (code != 0 || count != 0)
794             {
795               if (count == 0)
796                 firstdig = code;
797               count++;
798             }
799           nonnull = 1;
800         }
801       if (! nonnull)
802         error ("\\x used with no following hex digits");
803       else if (count == 0)
804         /* Digits are all 0's.  Ok.  */
805         ;
806       else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
807                || (count > 1
808                    && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
809                        <= firstdig)))
810         pedwarn ("hex escape out of range");
811       return code;
812
813     case '0':  case '1':  case '2':  case '3':  case '4':
814     case '5':  case '6':  case '7':
815       code = 0;
816       count = 0;
817       while ((c <= '7') && (c >= '0') && (count++ < 3))
818         {
819           code = (code * 8) + (c - '0');
820           c = getc (finput);
821         }
822       ungetc (c, finput);
823       return code;
824
825     case '\\': case '\'': case '"':
826       return c;
827
828     case '\n':
829       lineno++;
830       *ignore_ptr = 1;
831       return 0;
832
833     case 'n':
834       return TARGET_NEWLINE;
835
836     case 't':
837       return TARGET_TAB;
838
839     case 'r':
840       return TARGET_CR;
841
842     case 'f':
843       return TARGET_FF;
844
845     case 'b':
846       return TARGET_BS;
847
848     case 'a':
849       if (warn_traditional)
850         warning ("the meaning of `\\a' varies with -traditional");
851
852       if (flag_traditional)
853         return c;
854       return TARGET_BELL;
855
856     case 'v':
857 #if 0 /* Vertical tab is present in common usage compilers.  */
858       if (flag_traditional)
859         return c;
860 #endif
861       return TARGET_VT;
862
863     case 'e':
864     case 'E':
865       if (pedantic)
866         pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
867       return 033;
868
869     case '?':
870       return c;
871
872       /* `\(', etc, are used at beginning of line to avoid confusing Emacs.  */
873     case '(':
874     case '{':
875     case '[':
876       /* `\%' is used to prevent SCCS from getting confused.  */
877     case '%':
878       if (pedantic)
879         pedwarn ("non-ANSI escape sequence `\\%c'", c);
880       return c;
881     }
882   if (c >= 040 && c < 0177)
883     pedwarn ("unknown escape sequence `\\%c'", c);
884   else
885     pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
886   return c;
887 }
888 \f
889 void
890 yyerror (string)
891      char *string;
892 {
893   char buf[200];
894
895   strcpy (buf, string);
896
897   /* We can't print string and character constants well
898      because the token_buffer contains the result of processing escapes.  */
899   if (end_of_file)
900     strcat (buf, " at end of input");
901   else if (token_buffer[0] == 0)
902     strcat (buf, " at null character");
903   else if (token_buffer[0] == '"')
904     strcat (buf, " before string constant");
905   else if (token_buffer[0] == '\'')
906     strcat (buf, " before character constant");
907   else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
908     sprintf (buf + strlen (buf), " before character 0%o",
909              (unsigned char) token_buffer[0]);
910   else
911     strcat (buf, " before `%s'");
912
913   error (buf, token_buffer);
914 }
915
916 #if 0
917
918 struct try_type
919 {
920   tree *node_var;
921   char unsigned_flag;
922   char long_flag;
923   char long_long_flag;
924 };
925
926 struct try_type type_sequence[] = 
927 {
928   { &integer_type_node, 0, 0, 0},
929   { &unsigned_type_node, 1, 0, 0},
930   { &long_integer_type_node, 0, 1, 0},
931   { &long_unsigned_type_node, 1, 1, 0},
932   { &long_long_integer_type_node, 0, 1, 1},
933   { &long_long_unsigned_type_node, 1, 1, 1}
934 };
935 #endif /* 0 */
936 \f
937 int
938 yylex ()
939 {
940   register int c;
941   register char *p;
942   register int value;
943   int wide_flag = 0;
944   int objc_flag = 0;
945
946   if (nextchar >= 0)
947     c = nextchar, nextchar = -1;
948   else
949     c = getc (finput);
950
951   /* Effectively do c = skip_white_space (c)
952      but do it faster in the usual cases.  */
953   while (1)
954     switch (c)
955       {
956       case ' ':
957       case '\t':
958       case '\f':
959       case '\v':
960       case '\b':
961         c = getc (finput);
962         break;
963
964       case '\r':
965         /* Call skip_white_space so we can warn if appropriate.  */
966
967       case '\n':
968       case '/':
969       case '\\':
970         c = skip_white_space (c);
971       default:
972         goto found_nonwhite;
973       }
974  found_nonwhite:
975
976   token_buffer[0] = c;
977   token_buffer[1] = 0;
978
979 /*  yylloc.first_line = lineno; */
980
981   switch (c)
982     {
983     case EOF:
984       end_of_file = 1;
985       token_buffer[0] = 0;
986       value = ENDFILE;
987       break;
988
989     case 'L':
990       /* Capital L may start a wide-string or wide-character constant.  */
991       {
992         register int c = getc (finput);
993         if (c == '\'')
994           {
995             wide_flag = 1;
996             goto char_constant;
997           }
998         if (c == '"')
999           {
1000             wide_flag = 1;
1001             goto string_constant;
1002           }
1003         ungetc (c, finput);
1004       }
1005       goto letter;
1006
1007     case '@':
1008       if (!doing_objc_thang)
1009         {
1010           value = c;
1011           break;
1012         }
1013       else
1014         {
1015           /* '@' may start a constant string object.  */
1016           register int c = getc(finput);
1017           if (c == '"')
1018             {
1019               objc_flag = 1;
1020               goto string_constant;
1021             }
1022           ungetc(c, finput);
1023           /* Fall through to treat '@' as the start of an identifier.  */
1024         }
1025
1026     case 'A':  case 'B':  case 'C':  case 'D':  case 'E':
1027     case 'F':  case 'G':  case 'H':  case 'I':  case 'J':
1028     case 'K':             case 'M':  case 'N':  case 'O':
1029     case 'P':  case 'Q':  case 'R':  case 'S':  case 'T':
1030     case 'U':  case 'V':  case 'W':  case 'X':  case 'Y':
1031     case 'Z':
1032     case 'a':  case 'b':  case 'c':  case 'd':  case 'e':
1033     case 'f':  case 'g':  case 'h':  case 'i':  case 'j':
1034     case 'k':  case 'l':  case 'm':  case 'n':  case 'o':
1035     case 'p':  case 'q':  case 'r':  case 's':  case 't':
1036     case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
1037     case 'z':
1038     case '_':
1039     case '$':
1040     letter:
1041       p = token_buffer;
1042       while (isalnum (c) || c == '_' || c == '$' || c == '@')
1043         {
1044           /* Make sure this char really belongs in an identifier.  */
1045           if (c == '@' && ! doing_objc_thang)
1046             break;
1047           if (c == '$')
1048             {
1049               if (! dollars_in_ident)
1050                 error ("`$' in identifier");
1051               else if (pedantic)
1052                 pedwarn ("`$' in identifier");
1053             }
1054
1055           if (p >= token_buffer + maxtoken)
1056             p = extend_token_buffer (p);
1057
1058           *p++ = c;
1059           c = getc (finput);
1060         }
1061
1062       *p = 0;
1063       nextchar = c;
1064
1065       value = IDENTIFIER;
1066       yylval.itype = 0;
1067
1068       /* Try to recognize a keyword.  Uses minimum-perfect hash function */
1069
1070       {
1071         register struct resword *ptr;
1072
1073         if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1074           {
1075             if (ptr->rid)
1076               yylval.ttype = ridpointers[(int) ptr->rid];
1077             value = (int) ptr->token;
1078
1079             /* Only return OBJECTNAME if it is a typedef.  */
1080             if (doing_objc_thang && value == OBJECTNAME)
1081               {
1082                 lastiddecl = lookup_name(yylval.ttype);
1083
1084                 if (lastiddecl == NULL_TREE
1085                     || TREE_CODE (lastiddecl) != TYPE_DECL)
1086                   value = IDENTIFIER;
1087               }
1088
1089             /* Even if we decided to recognize asm, still perhaps warn.  */
1090             if (pedantic
1091                 && (value == ASM_KEYWORD || value == TYPEOF
1092                     || ptr->rid == RID_INLINE)
1093                 && token_buffer[0] != '_')
1094               pedwarn ("ANSI does not permit the keyword `%s'",
1095                        token_buffer);
1096           }
1097       }
1098
1099       /* If we did not find a keyword, look for an identifier
1100          (or a typename).  */
1101
1102       if (value == IDENTIFIER)
1103         {
1104           if (token_buffer[0] == '@')
1105             error("invalid identifier `%s'", token_buffer);
1106
1107           yylval.ttype = get_identifier (token_buffer);
1108           lastiddecl = lookup_name (yylval.ttype);
1109
1110           if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1111             value = TYPENAME;
1112           /* A user-invisible read-only initialized variable
1113              should be replaced by its value.
1114              We handle only strings since that's the only case used in C.  */
1115           else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1116                    && DECL_IGNORED_P (lastiddecl)
1117                    && TREE_READONLY (lastiddecl)
1118                    && DECL_INITIAL (lastiddecl) != 0
1119                    && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1120             {
1121               tree stringval = DECL_INITIAL (lastiddecl);
1122               
1123               /* Copy the string value so that we won't clobber anything
1124                  if we put something in the TREE_CHAIN of this one.  */
1125               yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1126                                            TREE_STRING_POINTER (stringval));
1127               value = STRING;
1128             }
1129           else if (doing_objc_thang)
1130             {
1131               tree objc_interface_decl = is_class_name (yylval.ttype);
1132
1133               if (objc_interface_decl)
1134                 {
1135                   value = CLASSNAME;
1136                   yylval.ttype = objc_interface_decl;
1137                 }
1138             }
1139         }
1140
1141       break;
1142
1143     case '0':  case '1':
1144       {
1145         int next_c;
1146         /* Check first for common special case:  single-digit 0 or 1.  */
1147
1148         next_c = getc (finput);
1149         ungetc (next_c, finput);        /* Always undo this lookahead.  */
1150         if (!isalnum (next_c) && next_c != '.')
1151           {
1152             token_buffer[0] = (char)c,  token_buffer[1] = '\0';
1153             yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1154             value = CONSTANT;
1155             break;
1156           }
1157         /*FALLTHRU*/
1158       }
1159     case '2':  case '3':  case '4':
1160     case '5':  case '6':  case '7':  case '8':  case '9':
1161     case '.':
1162       {
1163         int base = 10;
1164         int count = 0;
1165         int largest_digit = 0;
1166         int numdigits = 0;
1167         /* for multi-precision arithmetic,
1168            we actually store only HOST_BITS_PER_CHAR bits in each part.
1169            The number of parts is chosen so as to be sufficient to hold
1170            the enough bits to fit into the two HOST_WIDE_INTs that contain
1171            the integer value (this is always at least as many bits as are
1172            in a target `long long' value, but may be wider).  */
1173 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1174         int parts[TOTAL_PARTS];
1175         int overflow = 0;
1176
1177         enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1178           = NOT_FLOAT;
1179
1180         for (count = 0; count < TOTAL_PARTS; count++)
1181           parts[count] = 0;
1182
1183         p = token_buffer;
1184         *p++ = c;
1185
1186         if (c == '0')
1187           {
1188             *p++ = (c = getc (finput));
1189             if ((c == 'x') || (c == 'X'))
1190               {
1191                 base = 16;
1192                 *p++ = (c = getc (finput));
1193               }
1194             /* Leading 0 forces octal unless the 0 is the only digit.  */
1195             else if (c >= '0' && c <= '9')
1196               {
1197                 base = 8;
1198                 numdigits++;
1199               }
1200             else
1201               numdigits++;
1202           }
1203
1204         /* Read all the digits-and-decimal-points.  */
1205
1206         while (c == '.'
1207                || (isalnum (c) && c != 'l' && c != 'L'
1208                    && c != 'u' && c != 'U'
1209                    && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1210                    && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1211           {
1212             if (c == '.')
1213               {
1214                 if (base == 16)
1215                   error ("floating constant may not be in radix 16");
1216                 if (floatflag == TOO_MANY_POINTS)
1217                   /* We have already emitted an error.  Don't need another.  */
1218                   ;
1219                 else if (floatflag == AFTER_POINT)
1220                   {
1221                     error ("malformed floating constant");
1222                     floatflag = TOO_MANY_POINTS;
1223                     /* Avoid another error from atof by forcing all characters
1224                        from here on to be ignored.  */
1225                     p[-1] = '\0';
1226                   }
1227                 else
1228                   floatflag = AFTER_POINT;
1229
1230                 base = 10;
1231                 *p++ = c = getc (finput);
1232                 /* Accept '.' as the start of a floating-point number
1233                    only when it is followed by a digit.
1234                    Otherwise, unread the following non-digit
1235                    and use the '.' as a structural token.  */
1236                 if (p == token_buffer + 2 && !isdigit (c))
1237                   {
1238                     if (c == '.')
1239                       {
1240                         c = getc (finput);
1241                         if (c == '.')
1242                           {
1243                             *p++ = c;
1244                             *p = 0;
1245                             return ELLIPSIS;
1246                           }
1247                         error ("parse error at `..'");
1248                       }
1249                     ungetc (c, finput);
1250                     token_buffer[1] = 0;
1251                     value = '.';
1252                     goto done;
1253                   }
1254               }
1255             else
1256               {
1257                 /* It is not a decimal point.
1258                    It should be a digit (perhaps a hex digit).  */
1259
1260                 if (isdigit (c))
1261                   {
1262                     c = c - '0';
1263                   }
1264                 else if (base <= 10)
1265                   {
1266                     if (c == 'e' || c == 'E')
1267                       {
1268                         base = 10;
1269                         floatflag = AFTER_POINT;
1270                         break;   /* start of exponent */
1271                       }
1272                     error ("nondigits in number and not hexadecimal");
1273                     c = 0;
1274                   }
1275                 else if (c >= 'a')
1276                   {
1277                     c = c - 'a' + 10;
1278                   }
1279                 else
1280                   {
1281                     c = c - 'A' + 10;
1282                   }
1283                 if (c >= largest_digit)
1284                   largest_digit = c;
1285                 numdigits++;
1286
1287                 for (count = 0; count < TOTAL_PARTS; count++)
1288                   {
1289                     parts[count] *= base;
1290                     if (count)
1291                       {
1292                         parts[count]
1293                           += (parts[count-1] >> HOST_BITS_PER_CHAR);
1294                         parts[count-1]
1295                           &= (1 << HOST_BITS_PER_CHAR) - 1;
1296                       }
1297                     else
1298                       parts[0] += c;
1299                   }
1300
1301                 /* If the extra highest-order part ever gets anything in it,
1302                    the number is certainly too big.  */
1303                 if (parts[TOTAL_PARTS - 1] != 0)
1304                   overflow = 1;
1305
1306                 if (p >= token_buffer + maxtoken - 3)
1307                   p = extend_token_buffer (p);
1308                 *p++ = (c = getc (finput));
1309               }
1310           }
1311
1312         if (numdigits == 0)
1313           error ("numeric constant with no digits");
1314
1315         if (largest_digit >= base)
1316           error ("numeric constant contains digits beyond the radix");
1317
1318         /* Remove terminating char from the token buffer and delimit the string */
1319         *--p = 0;
1320
1321         if (floatflag != NOT_FLOAT)
1322           {
1323             tree type = double_type_node;
1324             int exceeds_double = 0;
1325             int imag = 0;
1326             REAL_VALUE_TYPE value;
1327             jmp_buf handler;
1328
1329             /* Read explicit exponent if any, and put it in tokenbuf.  */
1330
1331             if ((c == 'e') || (c == 'E'))
1332               {
1333                 if (p >= token_buffer + maxtoken - 3)
1334                   p = extend_token_buffer (p);
1335                 *p++ = c;
1336                 c = getc (finput);
1337                 if ((c == '+') || (c == '-'))
1338                   {
1339                     *p++ = c;
1340                     c = getc (finput);
1341                   }
1342                 if (! isdigit (c))
1343                   error ("floating constant exponent has no digits");
1344                 while (isdigit (c))
1345                   {
1346                     if (p >= token_buffer + maxtoken - 3)
1347                       p = extend_token_buffer (p);
1348                     *p++ = c;
1349                     c = getc (finput);
1350                   }
1351               }
1352
1353             *p = 0;
1354             errno = 0;
1355
1356             /* Convert string to a double, checking for overflow.  */
1357             if (setjmp (handler))
1358               {
1359                 error ("floating constant out of range");
1360                 value = dconst0;
1361               }
1362             else
1363               {
1364                 int fflag = 0, lflag = 0;
1365                 /* Copy token_buffer now, while it has just the number
1366                    and not the suffixes; once we add `f' or `i',
1367                    REAL_VALUE_ATOF may not work any more.  */
1368                 char *copy = (char *) alloca (p - token_buffer + 1);
1369                 bcopy (token_buffer, copy, p - token_buffer + 1);
1370
1371                 set_float_handler (handler);
1372
1373                 while (1)
1374                   {
1375                     int lose = 0;
1376
1377                     /* Read the suffixes to choose a data type.  */
1378                     switch (c)
1379                       {
1380                       case 'f': case 'F':
1381                         if (fflag)
1382                           error ("more than one `f' in numeric constant");
1383                         fflag = 1;
1384                         break;
1385
1386                       case 'l': case 'L':
1387                         if (lflag)
1388                           error ("more than one `l' in numeric constant");
1389                         lflag = 1;
1390                         break;
1391
1392                       case 'i': case 'I':
1393                         if (imag)
1394                           error ("more than one `i' or `j' in numeric constant");
1395                         else if (pedantic)
1396                           pedwarn ("ANSI C forbids imaginary numeric constants");
1397                         imag = 1;
1398                         break;
1399
1400                       default:
1401                         lose = 1;
1402                       }
1403
1404                     if (lose)
1405                       break;
1406
1407                     if (p >= token_buffer + maxtoken - 3)
1408                       p = extend_token_buffer (p);
1409                     *p++ = c;
1410                     *p = 0;
1411                     c = getc (finput);
1412                   }
1413
1414                 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1415                    tells the desired precision of the binary result
1416                    of decimal-to-binary conversion.  */
1417
1418                 if (fflag)
1419                   {
1420                     if (lflag)
1421                       error ("both `f' and `l' in floating constant");
1422
1423                     type = float_type_node;
1424                     value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1425                     /* A diagnostic is required here by some ANSI C testsuites.
1426                        This is not pedwarn, become some people don't want
1427                        an error for this.  */
1428                     if (REAL_VALUE_ISINF (value) && pedantic)
1429                       warning ("floating point number exceeds range of `float'");
1430                   }
1431                 else if (lflag)
1432                   {
1433                     type = long_double_type_node;
1434                     value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1435                     if (REAL_VALUE_ISINF (value) && pedantic)
1436                       warning ("floating point number exceeds range of `long double'");
1437                   }
1438                 else
1439                   {
1440                     value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1441                     if (REAL_VALUE_ISINF (value) && pedantic)
1442                       warning ("floating point number exceeds range of `double'");
1443                   }
1444
1445                 set_float_handler (NULL_PTR);
1446             }
1447 #ifdef ERANGE
1448             if (errno == ERANGE && !flag_traditional && pedantic)
1449               {
1450                 /* ERANGE is also reported for underflow,
1451                    so test the value to distinguish overflow from that.  */
1452                 if (REAL_VALUES_LESS (dconst1, value)
1453                     || REAL_VALUES_LESS (value, dconstm1))
1454                   {
1455                     warning ("floating point number exceeds range of `double'");
1456                     exceeds_double = 1;
1457                   }
1458               }
1459 #endif
1460
1461             /* If the result is not a number, assume it must have been
1462                due to some error message above, so silently convert
1463                it to a zero.  */
1464             if (REAL_VALUE_ISNAN (value))
1465               value = dconst0;
1466
1467             /* Create a node with determined type and value.  */
1468             if (imag)
1469               yylval.ttype = build_complex (NULL_TREE,
1470                                             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 (NULL_TREE, integer_zero_node,
1640                                      convert (integer_type_node,
1641                                               yylval.ttype));
1642                 else
1643                   error ("complex integer constant is too wide for `complex int'");
1644               }
1645             else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1646               /* The traditional constant 0x80000000 is signed
1647                  but doesn't fit in the range of int.
1648                  This will change it to -0x80000000, which does fit.  */
1649               {
1650                 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1651                 yylval.ttype = convert (type, yylval.ttype);
1652                 TREE_OVERFLOW (yylval.ttype)
1653                   = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1654               }
1655             else
1656               TREE_TYPE (yylval.ttype) = type;
1657           }
1658
1659         ungetc (c, finput);
1660         *p = 0;
1661
1662         if (isalnum (c) || c == '.' || c == '_' || c == '$'
1663             || (!flag_traditional && (c == '-' || c == '+')
1664                 && (p[-1] == 'e' || p[-1] == 'E')))
1665           error ("missing white space after number `%s'", token_buffer);
1666
1667         value = CONSTANT; break;
1668       }
1669
1670     case '\'':
1671     char_constant:
1672       {
1673         register int result = 0;
1674         register int num_chars = 0;
1675         unsigned width = TYPE_PRECISION (char_type_node);
1676         int max_chars;
1677
1678         if (wide_flag)
1679           {
1680             width = WCHAR_TYPE_SIZE;
1681 #ifdef MULTIBYTE_CHARS
1682             max_chars = MB_CUR_MAX;
1683 #else
1684             max_chars = 1;
1685 #endif
1686           }
1687         else
1688           max_chars = TYPE_PRECISION (integer_type_node) / width;
1689
1690         while (1)
1691           {
1692           tryagain:
1693
1694             c = getc (finput);
1695
1696             if (c == '\'' || c == EOF)
1697               break;
1698
1699             if (c == '\\')
1700               {
1701                 int ignore = 0;
1702                 c = readescape (&ignore);
1703                 if (ignore)
1704                   goto tryagain;
1705                 if (width < HOST_BITS_PER_INT
1706                     && (unsigned) c >= (1 << width))
1707                   pedwarn ("escape sequence out of range for character");
1708 #ifdef MAP_CHARACTER
1709                 if (isprint (c))
1710                   c = MAP_CHARACTER (c);
1711 #endif
1712               }
1713             else if (c == '\n')
1714               {
1715                 if (pedantic)
1716                   pedwarn ("ANSI C forbids newline in character constant");
1717                 lineno++;
1718               }
1719 #ifdef MAP_CHARACTER
1720             else
1721               c = MAP_CHARACTER (c);
1722 #endif
1723
1724             num_chars++;
1725             if (num_chars > maxtoken - 4)
1726               extend_token_buffer (token_buffer);
1727
1728             token_buffer[num_chars] = c;
1729
1730             /* Merge character into result; ignore excess chars.  */
1731             if (num_chars < max_chars + 1)
1732               {
1733                 if (width < HOST_BITS_PER_INT)
1734                   result = (result << width) | (c & ((1 << width) - 1));
1735                 else
1736                   result = c;
1737               }
1738           }
1739
1740         token_buffer[num_chars + 1] = '\'';
1741         token_buffer[num_chars + 2] = 0;
1742
1743         if (c != '\'')
1744           error ("malformatted character constant");
1745         else if (num_chars == 0)
1746           error ("empty character constant");
1747         else if (num_chars > max_chars)
1748           {
1749             num_chars = max_chars;
1750             error ("character constant too long");
1751           }
1752         else if (num_chars != 1 && ! flag_traditional)
1753           warning ("multi-character character constant");
1754
1755         /* If char type is signed, sign-extend the constant.  */
1756         if (! wide_flag)
1757           {
1758             int num_bits = num_chars * width;
1759             if (num_bits == 0)
1760               /* We already got an error; avoid invalid shift.  */
1761               yylval.ttype = build_int_2 (0, 0);
1762             else if (TREE_UNSIGNED (char_type_node)
1763                      || ((result >> (num_bits - 1)) & 1) == 0)
1764               yylval.ttype
1765                 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1766                                          >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1767                                0);
1768             else
1769               yylval.ttype
1770                 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1771                                           >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1772                                -1);
1773             TREE_TYPE (yylval.ttype) = integer_type_node;
1774           }
1775         else
1776           {
1777 #ifdef MULTIBYTE_CHARS
1778             /* Set the initial shift state and convert the next sequence.  */
1779             result = 0;
1780             /* In all locales L'\0' is zero and mbtowc will return zero,
1781                so don't use it.  */
1782             if (num_chars > 1
1783                 || (num_chars == 1 && token_buffer[1] != '\0'))
1784               {
1785                 wchar_t wc;
1786                 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1787                 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1788                   result = wc;
1789                 else
1790                   warning ("Ignoring invalid multibyte character");
1791               }
1792 #endif
1793             yylval.ttype = build_int_2 (result, 0);
1794             TREE_TYPE (yylval.ttype) = wchar_type_node;
1795           }
1796
1797         value = CONSTANT;
1798         break;
1799       }
1800
1801     case '"':
1802     string_constant:
1803       {
1804         c = getc (finput);
1805         p = token_buffer + 1;
1806
1807         while (c != '"' && c >= 0)
1808           {
1809             if (c == '\\')
1810               {
1811                 int ignore = 0;
1812                 c = readescape (&ignore);
1813                 if (ignore)
1814                   goto skipnewline;
1815                 if (!wide_flag
1816                     && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1817                     && c >= (1 << TYPE_PRECISION (char_type_node)))
1818                   pedwarn ("escape sequence out of range for character");
1819               }
1820             else if (c == '\n')
1821               {
1822                 if (pedantic)
1823                   pedwarn ("ANSI C forbids newline in string constant");
1824                 lineno++;
1825               }
1826
1827             if (p == token_buffer + maxtoken)
1828               p = extend_token_buffer (p);
1829             *p++ = c;
1830
1831           skipnewline:
1832             c = getc (finput);
1833           }
1834         *p = 0;
1835
1836         if (c < 0)
1837           error ("Unterminated string constant");
1838
1839         /* We have read the entire constant.
1840            Construct a STRING_CST for the result.  */
1841
1842         if (wide_flag)
1843           {
1844             /* If this is a L"..." wide-string, convert the multibyte string
1845                to a wide character string.  */
1846             char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1847             int len;
1848
1849 #ifdef MULTIBYTE_CHARS
1850             len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1851             if (len < 0 || len >= (p - token_buffer))
1852               {
1853                 warning ("Ignoring invalid multibyte string");
1854                 len = 0;
1855               }
1856             bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1857 #else
1858             {
1859               union { long l; char c[sizeof (long)]; } u;
1860               int big_endian;
1861               char *wp, *cp;
1862
1863               /* Determine whether host is little or big endian.  */
1864               u.l = 1;
1865               big_endian = u.c[sizeof (long) - 1];
1866               wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1867
1868               bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1869               for (cp = token_buffer + 1; cp < p; cp++)
1870                 *wp = *cp, wp += WCHAR_BYTES;
1871               len = p - token_buffer - 1;
1872             }
1873 #endif
1874             yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1875             TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1876             value = STRING;
1877           }
1878         else if (objc_flag)
1879           {
1880             extern tree build_objc_string();
1881             /* Return an Objective-C @"..." constant string object.  */
1882             yylval.ttype = build_objc_string (p - token_buffer,
1883                                               token_buffer + 1);
1884             TREE_TYPE (yylval.ttype) = char_array_type_node;
1885             value = OBJC_STRING;
1886           }
1887         else
1888           {
1889             yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
1890             TREE_TYPE (yylval.ttype) = char_array_type_node;
1891             value = STRING;
1892           }
1893
1894         *p++ = '"';
1895         *p = 0;
1896
1897         break;
1898       }
1899
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     case '=':
1913       {
1914         register int c1;
1915
1916       combine:
1917
1918         switch (c)
1919           {
1920           case '+':
1921             yylval.code = PLUS_EXPR; break;
1922           case '-':
1923             yylval.code = MINUS_EXPR; break;
1924           case '&':
1925             yylval.code = BIT_AND_EXPR; break;
1926           case '|':
1927             yylval.code = BIT_IOR_EXPR; break;
1928           case '*':
1929             yylval.code = MULT_EXPR; break;
1930           case '/':
1931             yylval.code = TRUNC_DIV_EXPR; break;
1932           case '%':
1933             yylval.code = TRUNC_MOD_EXPR; break;
1934           case '^':
1935             yylval.code = BIT_XOR_EXPR; break;
1936           case LSHIFT:
1937             yylval.code = LSHIFT_EXPR; break;
1938           case RSHIFT:
1939             yylval.code = RSHIFT_EXPR; break;
1940           case '<':
1941             yylval.code = LT_EXPR; break;
1942           case '>':
1943             yylval.code = GT_EXPR; break;
1944           }
1945
1946         token_buffer[1] = c1 = getc (finput);
1947         token_buffer[2] = 0;
1948
1949         if (c1 == '=')
1950           {
1951             switch (c)
1952               {
1953               case '<':
1954                 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
1955               case '>':
1956                 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
1957               case '!':
1958                 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
1959               case '=':
1960                 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
1961               }
1962             value = ASSIGN; goto done;
1963           }
1964         else if (c == c1)
1965           switch (c)
1966             {
1967             case '+':
1968               value = PLUSPLUS; goto done;
1969             case '-':
1970               value = MINUSMINUS; goto done;
1971             case '&':
1972               value = ANDAND; goto done;
1973             case '|':
1974               value = OROR; goto done;
1975             case '<':
1976               c = LSHIFT;
1977               goto combine;
1978             case '>':
1979               c = RSHIFT;
1980               goto combine;
1981             }
1982         else
1983           switch (c)
1984             {
1985             case '-':
1986               if (c1 == '>')
1987                 { value = POINTSAT; goto done; }
1988               break;
1989             case ':':
1990               if (c1 == '>')
1991                 { value = ']'; goto done; }
1992               break;
1993             case '<':
1994               if (c1 == '%')
1995                 { value = '{'; goto done; }
1996               if (c1 == ':')
1997                 { value = '['; goto done; }
1998               break;
1999             case '%':
2000               if (c1 == '>')
2001                 { value = '}'; goto done; }
2002               break;
2003             }
2004         ungetc (c1, finput);
2005         token_buffer[1] = 0;
2006
2007         if ((c == '<') || (c == '>'))
2008           value = ARITHCOMPARE;
2009         else value = c;
2010         goto done;
2011       }
2012
2013     case 0:
2014       /* Don't make yyparse think this is eof.  */
2015       value = 1;
2016       break;
2017
2018     default:
2019       value = c;
2020     }
2021
2022 done:
2023 /*  yylloc.last_line = lineno; */
2024
2025   return value;
2026 }
2027
2028 /* Sets the value of the 'yydebug' variable to VALUE.
2029    This is a function so we don't have to have YYDEBUG defined
2030    in order to build the compiler.  */
2031
2032 void
2033 set_yydebug (value)
2034      int value;
2035 {
2036 #if YYDEBUG != 0
2037   yydebug = value;
2038 #else
2039   warning ("YYDEBUG not defined.");
2040 #endif
2041 }