OSDN Git Service

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