OSDN Git Service

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