OSDN Git Service

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