OSDN Git Service

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