OSDN Git Service

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