OSDN Git Service

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