OSDN Git Service

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