OSDN Git Service

Patches to use cpplib with cc1 #if USE_CPPLIB.
[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
824 void
825 lang_init ()
826 {
827 #if !USE_CPPLIB
828   /* the beginning of the file is a new line; check for # */
829   /* With luck, we discover the real source file's name from that
830      and put it in input_filename.  */
831   UNGETC (check_newline ());
832 #endif
833 }
834 \f
835 #ifdef HANDLE_SYSV_PRAGMA
836
837 /* Handle a #pragma directive.
838    TOKEN is the token we read after `#pragma'.  Processes the entire input
839    line and returns a character for the caller to reread: either \n or EOF.  */
840
841 /* This function has to be in this file, in order to get at
842    the token types.  */
843
844 int
845 handle_sysv_pragma (token)
846      register int token;
847 {
848   register int c;
849
850   for (;;)
851     {
852       switch (token)
853         {
854         case IDENTIFIER:
855         case TYPENAME:
856         case STRING:
857         case CONSTANT:
858           handle_pragma_token (token_buffer, yylval.ttype);
859           break;
860         default:
861           handle_pragma_token (token_buffer, 0);
862         }
863 #if !USE_CPPLIB
864       if (nextchar >= 0)
865         c = nextchar, nextchar = -1;
866       else
867 #endif
868         c = GETC ();
869
870       while (c == ' ' || c == '\t')
871         c = GETC ();
872       if (c == '\n' || c == EOF)
873         {
874           handle_pragma_token (0, 0);
875           return c;
876         }
877       UNGETC (c);
878       token = yylex ();
879     }
880 }
881
882 #endif /* HANDLE_SYSV_PRAGMA */
883 \f
884 #define ENDFILE -1  /* token that represents end-of-file */
885
886 /* Read an escape sequence, returning its equivalent as a character,
887    or store 1 in *ignore_ptr if it is backslash-newline.  */
888
889 static int
890 readescape (ignore_ptr)
891      int *ignore_ptr;
892 {
893   register int c = GETC();
894   register int code;
895   register unsigned count;
896   unsigned firstdig = 0;
897   int nonnull;
898
899   switch (c)
900     {
901     case 'x':
902       if (warn_traditional)
903         warning ("the meaning of `\\x' varies with -traditional");
904
905       if (flag_traditional)
906         return c;
907
908       code = 0;
909       count = 0;
910       nonnull = 0;
911       while (1)
912         {
913           c = GETC();
914           if (!(c >= 'a' && c <= 'f')
915               && !(c >= 'A' && c <= 'F')
916               && !(c >= '0' && c <= '9'))
917             {
918               UNGETC (c);
919               break;
920             }
921           code *= 16;
922           if (c >= 'a' && c <= 'f')
923             code += c - 'a' + 10;
924           if (c >= 'A' && c <= 'F')
925             code += c - 'A' + 10;
926           if (c >= '0' && c <= '9')
927             code += c - '0';
928           if (code != 0 || count != 0)
929             {
930               if (count == 0)
931                 firstdig = code;
932               count++;
933             }
934           nonnull = 1;
935         }
936       if (! nonnull)
937         error ("\\x used with no following hex digits");
938       else if (count == 0)
939         /* Digits are all 0's.  Ok.  */
940         ;
941       else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
942                || (count > 1
943                    && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
944                        <= firstdig)))
945         pedwarn ("hex escape out of range");
946       return code;
947
948     case '0':  case '1':  case '2':  case '3':  case '4':
949     case '5':  case '6':  case '7':
950       code = 0;
951       count = 0;
952       while ((c <= '7') && (c >= '0') && (count++ < 3))
953         {
954           code = (code * 8) + (c - '0');
955           c = GETC();
956         }
957       UNGETC (c);
958       return code;
959
960     case '\\': case '\'': case '"':
961       return c;
962
963     case '\n':
964       lineno++;
965       *ignore_ptr = 1;
966       return 0;
967
968     case 'n':
969       return TARGET_NEWLINE;
970
971     case 't':
972       return TARGET_TAB;
973
974     case 'r':
975       return TARGET_CR;
976
977     case 'f':
978       return TARGET_FF;
979
980     case 'b':
981       return TARGET_BS;
982
983     case 'a':
984       if (warn_traditional)
985         warning ("the meaning of `\\a' varies with -traditional");
986
987       if (flag_traditional)
988         return c;
989       return TARGET_BELL;
990
991     case 'v':
992 #if 0 /* Vertical tab is present in common usage compilers.  */
993       if (flag_traditional)
994         return c;
995 #endif
996       return TARGET_VT;
997
998     case 'e':
999     case 'E':
1000       if (pedantic)
1001         pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1002       return 033;
1003
1004     case '?':
1005       return c;
1006
1007       /* `\(', etc, are used at beginning of line to avoid confusing Emacs.  */
1008     case '(':
1009     case '{':
1010     case '[':
1011       /* `\%' is used to prevent SCCS from getting confused.  */
1012     case '%':
1013       if (pedantic)
1014         pedwarn ("non-ANSI escape sequence `\\%c'", c);
1015       return c;
1016     }
1017   if (c >= 040 && c < 0177)
1018     pedwarn ("unknown escape sequence `\\%c'", c);
1019   else
1020     pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1021   return c;
1022 }
1023 \f
1024 void
1025 yyerror (string)
1026      char *string;
1027 {
1028   char buf[200];
1029
1030   strcpy (buf, string);
1031
1032   /* We can't print string and character constants well
1033      because the token_buffer contains the result of processing escapes.  */
1034   if (end_of_file)
1035     strcat (buf, " at end of input");
1036   else if (token_buffer[0] == 0)
1037     strcat (buf, " at null character");
1038   else if (token_buffer[0] == '"')
1039     strcat (buf, " before string constant");
1040   else if (token_buffer[0] == '\'')
1041     strcat (buf, " before character constant");
1042   else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
1043     sprintf (buf + strlen (buf), " before character 0%o",
1044              (unsigned char) token_buffer[0]);
1045   else
1046     strcat (buf, " before `%s'");
1047
1048   error (buf, token_buffer);
1049 }
1050
1051 #if 0
1052
1053 struct try_type
1054 {
1055   tree *node_var;
1056   char unsigned_flag;
1057   char long_flag;
1058   char long_long_flag;
1059 };
1060
1061 struct try_type type_sequence[] = 
1062 {
1063   { &integer_type_node, 0, 0, 0},
1064   { &unsigned_type_node, 1, 0, 0},
1065   { &long_integer_type_node, 0, 1, 0},
1066   { &long_unsigned_type_node, 1, 1, 0},
1067   { &long_long_integer_type_node, 0, 1, 1},
1068   { &long_long_unsigned_type_node, 1, 1, 1}
1069 };
1070 #endif /* 0 */
1071 \f
1072 int
1073 yylex ()
1074 {
1075   register int c;
1076   register char *p;
1077   register int value;
1078   int wide_flag = 0;
1079   int objc_flag = 0;
1080
1081 #if !USE_CPPLIB
1082   if (nextchar >= 0)
1083     c = nextchar, nextchar = -1;
1084   else
1085 #endif
1086     c = GETC();
1087
1088   /* Effectively do c = skip_white_space (c)
1089      but do it faster in the usual cases.  */
1090   while (1)
1091     switch (c)
1092       {
1093       case ' ':
1094       case '\t':
1095       case '\f':
1096       case '\v':
1097       case '\b':
1098         c = GETC();
1099         break;
1100
1101       case '\r':
1102         /* Call skip_white_space so we can warn if appropriate.  */
1103
1104       case '\n':
1105       case '/':
1106       case '\\':
1107         c = skip_white_space (c);
1108       default:
1109         goto found_nonwhite;
1110       }
1111  found_nonwhite:
1112
1113   token_buffer[0] = c;
1114   token_buffer[1] = 0;
1115
1116 /*  yylloc.first_line = lineno; */
1117
1118   switch (c)
1119     {
1120     case EOF:
1121       end_of_file = 1;
1122       token_buffer[0] = 0;
1123       value = ENDFILE;
1124       break;
1125
1126     case 'L':
1127       /* Capital L may start a wide-string or wide-character constant.  */
1128       {
1129         register int c = GETC();
1130         if (c == '\'')
1131           {
1132             wide_flag = 1;
1133             goto char_constant;
1134           }
1135         if (c == '"')
1136           {
1137             wide_flag = 1;
1138             goto string_constant;
1139           }
1140         UNGETC (c);
1141       }
1142       goto letter;
1143
1144     case '@':
1145       if (!doing_objc_thang)
1146         {
1147           value = c;
1148           break;
1149         }
1150       else
1151         {
1152           /* '@' may start a constant string object.  */
1153           register int c = GETC ();
1154           if (c == '"')
1155             {
1156               objc_flag = 1;
1157               goto string_constant;
1158             }
1159           UNGETC (c);
1160           /* Fall through to treat '@' as the start of an identifier.  */
1161         }
1162
1163     case 'A':  case 'B':  case 'C':  case 'D':  case 'E':
1164     case 'F':  case 'G':  case 'H':  case 'I':  case 'J':
1165     case 'K':             case 'M':  case 'N':  case 'O':
1166     case 'P':  case 'Q':  case 'R':  case 'S':  case 'T':
1167     case 'U':  case 'V':  case 'W':  case 'X':  case 'Y':
1168     case 'Z':
1169     case 'a':  case 'b':  case 'c':  case 'd':  case 'e':
1170     case 'f':  case 'g':  case 'h':  case 'i':  case 'j':
1171     case 'k':  case 'l':  case 'm':  case 'n':  case 'o':
1172     case 'p':  case 'q':  case 'r':  case 's':  case 't':
1173     case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
1174     case 'z':
1175     case '_':
1176     case '$':
1177     letter:
1178       p = token_buffer;
1179       while (isalnum (c) || c == '_' || c == '$' || c == '@')
1180         {
1181           /* Make sure this char really belongs in an identifier.  */
1182           if (c == '@' && ! doing_objc_thang)
1183             break;
1184           if (c == '$')
1185             {
1186               if (! dollars_in_ident)
1187                 error ("`$' in identifier");
1188               else if (pedantic)
1189                 pedwarn ("`$' in identifier");
1190             }
1191
1192           if (p >= token_buffer + maxtoken)
1193             p = extend_token_buffer (p);
1194
1195           *p++ = c;
1196           c = GETC();
1197         }
1198
1199       *p = 0;
1200 #if USE_CPPLIB
1201       UNGETC (c);
1202 #else
1203       nextchar = c;
1204 #endif
1205
1206       value = IDENTIFIER;
1207       yylval.itype = 0;
1208
1209       /* Try to recognize a keyword.  Uses minimum-perfect hash function */
1210
1211       {
1212         register struct resword *ptr;
1213
1214         if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1215           {
1216             if (ptr->rid)
1217               yylval.ttype = ridpointers[(int) ptr->rid];
1218             value = (int) ptr->token;
1219
1220             /* Only return OBJECTNAME if it is a typedef.  */
1221             if (doing_objc_thang && value == OBJECTNAME)
1222               {
1223                 lastiddecl = lookup_name(yylval.ttype);
1224
1225                 if (lastiddecl == NULL_TREE
1226                     || TREE_CODE (lastiddecl) != TYPE_DECL)
1227                   value = IDENTIFIER;
1228               }
1229
1230             /* Even if we decided to recognize asm, still perhaps warn.  */
1231             if (pedantic
1232                 && (value == ASM_KEYWORD || value == TYPEOF
1233                     || ptr->rid == RID_INLINE)
1234                 && token_buffer[0] != '_')
1235               pedwarn ("ANSI does not permit the keyword `%s'",
1236                        token_buffer);
1237           }
1238       }
1239
1240       /* If we did not find a keyword, look for an identifier
1241          (or a typename).  */
1242
1243       if (value == IDENTIFIER)
1244         {
1245           if (token_buffer[0] == '@')
1246             error("invalid identifier `%s'", token_buffer);
1247
1248           yylval.ttype = get_identifier (token_buffer);
1249           lastiddecl = lookup_name (yylval.ttype);
1250
1251           if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1252             value = TYPENAME;
1253           /* A user-invisible read-only initialized variable
1254              should be replaced by its value.
1255              We handle only strings since that's the only case used in C.  */
1256           else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1257                    && DECL_IGNORED_P (lastiddecl)
1258                    && TREE_READONLY (lastiddecl)
1259                    && DECL_INITIAL (lastiddecl) != 0
1260                    && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1261             {
1262               tree stringval = DECL_INITIAL (lastiddecl);
1263               
1264               /* Copy the string value so that we won't clobber anything
1265                  if we put something in the TREE_CHAIN of this one.  */
1266               yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1267                                            TREE_STRING_POINTER (stringval));
1268               value = STRING;
1269             }
1270           else if (doing_objc_thang)
1271             {
1272               tree objc_interface_decl = is_class_name (yylval.ttype);
1273
1274               if (objc_interface_decl)
1275                 {
1276                   value = CLASSNAME;
1277                   yylval.ttype = objc_interface_decl;
1278                 }
1279             }
1280         }
1281
1282       break;
1283
1284     case '0':  case '1':
1285       {
1286         int next_c;
1287         /* Check first for common special case:  single-digit 0 or 1.  */
1288
1289         next_c = GETC ();
1290         UNGETC (next_c);        /* Always undo this lookahead.  */
1291         if (!isalnum (next_c) && next_c != '.')
1292           {
1293             token_buffer[0] = (char)c,  token_buffer[1] = '\0';
1294             yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1295             value = CONSTANT;
1296             break;
1297           }
1298         /*FALLTHRU*/
1299       }
1300     case '2':  case '3':  case '4':
1301     case '5':  case '6':  case '7':  case '8':  case '9':
1302     case '.':
1303       {
1304         int base = 10;
1305         int count = 0;
1306         int largest_digit = 0;
1307         int numdigits = 0;
1308         /* for multi-precision arithmetic,
1309            we actually store only HOST_BITS_PER_CHAR bits in each part.
1310            The number of parts is chosen so as to be sufficient to hold
1311            the enough bits to fit into the two HOST_WIDE_INTs that contain
1312            the integer value (this is always at least as many bits as are
1313            in a target `long long' value, but may be wider).  */
1314 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1315         int parts[TOTAL_PARTS];
1316         int overflow = 0;
1317
1318         enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1319           = NOT_FLOAT;
1320
1321         for (count = 0; count < TOTAL_PARTS; count++)
1322           parts[count] = 0;
1323
1324         p = token_buffer;
1325         *p++ = c;
1326
1327         if (c == '0')
1328           {
1329             *p++ = (c = GETC());
1330             if ((c == 'x') || (c == 'X'))
1331               {
1332                 base = 16;
1333                 *p++ = (c = GETC());
1334               }
1335             /* Leading 0 forces octal unless the 0 is the only digit.  */
1336             else if (c >= '0' && c <= '9')
1337               {
1338                 base = 8;
1339                 numdigits++;
1340               }
1341             else
1342               numdigits++;
1343           }
1344
1345         /* Read all the digits-and-decimal-points.  */
1346
1347         while (c == '.'
1348                || (isalnum (c) && c != 'l' && c != 'L'
1349                    && c != 'u' && c != 'U'
1350                    && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1351                    && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1352           {
1353             if (c == '.')
1354               {
1355                 if (base == 16)
1356                   error ("floating constant may not be in radix 16");
1357                 if (floatflag == TOO_MANY_POINTS)
1358                   /* We have already emitted an error.  Don't need another.  */
1359                   ;
1360                 else if (floatflag == AFTER_POINT)
1361                   {
1362                     error ("malformed floating constant");
1363                     floatflag = TOO_MANY_POINTS;
1364                     /* Avoid another error from atof by forcing all characters
1365                        from here on to be ignored.  */
1366                     p[-1] = '\0';
1367                   }
1368                 else
1369                   floatflag = AFTER_POINT;
1370
1371                 base = 10;
1372                 *p++ = c = GETC();
1373                 /* Accept '.' as the start of a floating-point number
1374                    only when it is followed by a digit.
1375                    Otherwise, unread the following non-digit
1376                    and use the '.' as a structural token.  */
1377                 if (p == token_buffer + 2 && !isdigit (c))
1378                   {
1379                     if (c == '.')
1380                       {
1381                         c = GETC();
1382                         if (c == '.')
1383                           {
1384                             *p++ = c;
1385                             *p = 0;
1386                             return ELLIPSIS;
1387                           }
1388                         error ("parse error at `..'");
1389                       }
1390                     UNGETC (c);
1391                     token_buffer[1] = 0;
1392                     value = '.';
1393                     goto done;
1394                   }
1395               }
1396             else
1397               {
1398                 /* It is not a decimal point.
1399                    It should be a digit (perhaps a hex digit).  */
1400
1401                 if (isdigit (c))
1402                   {
1403                     c = c - '0';
1404                   }
1405                 else if (base <= 10)
1406                   {
1407                     if (c == 'e' || c == 'E')
1408                       {
1409                         base = 10;
1410                         floatflag = AFTER_POINT;
1411                         break;   /* start of exponent */
1412                       }
1413                     error ("nondigits in number and not hexadecimal");
1414                     c = 0;
1415                   }
1416                 else if (c >= 'a')
1417                   {
1418                     c = c - 'a' + 10;
1419                   }
1420                 else
1421                   {
1422                     c = c - 'A' + 10;
1423                   }
1424                 if (c >= largest_digit)
1425                   largest_digit = c;
1426                 numdigits++;
1427
1428                 for (count = 0; count < TOTAL_PARTS; count++)
1429                   {
1430                     parts[count] *= base;
1431                     if (count)
1432                       {
1433                         parts[count]
1434                           += (parts[count-1] >> HOST_BITS_PER_CHAR);
1435                         parts[count-1]
1436                           &= (1 << HOST_BITS_PER_CHAR) - 1;
1437                       }
1438                     else
1439                       parts[0] += c;
1440                   }
1441
1442                 /* If the extra highest-order part ever gets anything in it,
1443                    the number is certainly too big.  */
1444                 if (parts[TOTAL_PARTS - 1] != 0)
1445                   overflow = 1;
1446
1447                 if (p >= token_buffer + maxtoken - 3)
1448                   p = extend_token_buffer (p);
1449                 *p++ = (c = GETC());
1450               }
1451           }
1452
1453         if (numdigits == 0)
1454           error ("numeric constant with no digits");
1455
1456         if (largest_digit >= base)
1457           error ("numeric constant contains digits beyond the radix");
1458
1459         /* Remove terminating char from the token buffer and delimit the string */
1460         *--p = 0;
1461
1462         if (floatflag != NOT_FLOAT)
1463           {
1464             tree type = double_type_node;
1465             int exceeds_double = 0;
1466             int imag = 0;
1467             REAL_VALUE_TYPE value;
1468             jmp_buf handler;
1469
1470             /* Read explicit exponent if any, and put it in tokenbuf.  */
1471
1472             if ((c == 'e') || (c == 'E'))
1473               {
1474                 if (p >= token_buffer + maxtoken - 3)
1475                   p = extend_token_buffer (p);
1476                 *p++ = c;
1477                 c = GETC();
1478                 if ((c == '+') || (c == '-'))
1479                   {
1480                     *p++ = c;
1481                     c = GETC();
1482                   }
1483                 if (! isdigit (c))
1484                   error ("floating constant exponent has no digits");
1485                 while (isdigit (c))
1486                   {
1487                     if (p >= token_buffer + maxtoken - 3)
1488                       p = extend_token_buffer (p);
1489                     *p++ = c;
1490                     c = GETC();
1491                   }
1492               }
1493
1494             *p = 0;
1495             errno = 0;
1496
1497             /* Convert string to a double, checking for overflow.  */
1498             if (setjmp (handler))
1499               {
1500                 error ("floating constant out of range");
1501                 value = dconst0;
1502               }
1503             else
1504               {
1505                 int fflag = 0, lflag = 0;
1506                 /* Copy token_buffer now, while it has just the number
1507                    and not the suffixes; once we add `f' or `i',
1508                    REAL_VALUE_ATOF may not work any more.  */
1509                 char *copy = (char *) alloca (p - token_buffer + 1);
1510                 bcopy (token_buffer, copy, p - token_buffer + 1);
1511
1512                 set_float_handler (handler);
1513
1514                 while (1)
1515                   {
1516                     int lose = 0;
1517
1518                     /* Read the suffixes to choose a data type.  */
1519                     switch (c)
1520                       {
1521                       case 'f': case 'F':
1522                         if (fflag)
1523                           error ("more than one `f' in numeric constant");
1524                         fflag = 1;
1525                         break;
1526
1527                       case 'l': case 'L':
1528                         if (lflag)
1529                           error ("more than one `l' in numeric constant");
1530                         lflag = 1;
1531                         break;
1532
1533                       case 'i': case 'I':
1534                         if (imag)
1535                           error ("more than one `i' or `j' in numeric constant");
1536                         else if (pedantic)
1537                           pedwarn ("ANSI C forbids imaginary numeric constants");
1538                         imag = 1;
1539                         break;
1540
1541                       default:
1542                         lose = 1;
1543                       }
1544
1545                     if (lose)
1546                       break;
1547
1548                     if (p >= token_buffer + maxtoken - 3)
1549                       p = extend_token_buffer (p);
1550                     *p++ = c;
1551                     *p = 0;
1552                     c = GETC();
1553                   }
1554
1555                 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1556                    tells the desired precision of the binary result
1557                    of decimal-to-binary conversion.  */
1558
1559                 if (fflag)
1560                   {
1561                     if (lflag)
1562                       error ("both `f' and `l' in floating constant");
1563
1564                     type = float_type_node;
1565                     value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1566                     /* A diagnostic is required here by some ANSI C testsuites.
1567                        This is not pedwarn, become some people don't want
1568                        an error for this.  */
1569                     if (REAL_VALUE_ISINF (value) && pedantic)
1570                       warning ("floating point number exceeds range of `float'");
1571                   }
1572                 else if (lflag)
1573                   {
1574                     type = long_double_type_node;
1575                     value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1576                     if (REAL_VALUE_ISINF (value) && pedantic)
1577                       warning ("floating point number exceeds range of `long double'");
1578                   }
1579                 else
1580                   {
1581                     value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1582                     if (REAL_VALUE_ISINF (value) && pedantic)
1583                       warning ("floating point number exceeds range of `double'");
1584                   }
1585
1586                 set_float_handler (NULL_PTR);
1587             }
1588 #ifdef ERANGE
1589             if (errno == ERANGE && !flag_traditional && pedantic)
1590               {
1591                 /* ERANGE is also reported for underflow,
1592                    so test the value to distinguish overflow from that.  */
1593                 if (REAL_VALUES_LESS (dconst1, value)
1594                     || REAL_VALUES_LESS (value, dconstm1))
1595                   {
1596                     warning ("floating point number exceeds range of `double'");
1597                     exceeds_double = 1;
1598                   }
1599               }
1600 #endif
1601
1602             /* If the result is not a number, assume it must have been
1603                due to some error message above, so silently convert
1604                it to a zero.  */
1605             if (REAL_VALUE_ISNAN (value))
1606               value = dconst0;
1607
1608             /* Create a node with determined type and value.  */
1609             if (imag)
1610               yylval.ttype = build_complex (NULL_TREE,
1611                                             convert (type, integer_zero_node),
1612                                             build_real (type, value));
1613             else
1614               yylval.ttype = build_real (type, value);
1615           }
1616         else
1617           {
1618             tree traditional_type, ansi_type, type;
1619             HOST_WIDE_INT high, low;
1620             int spec_unsigned = 0;
1621             int spec_long = 0;
1622             int spec_long_long = 0;
1623             int spec_imag = 0;
1624             int bytes, warn, i;
1625
1626             while (1)
1627               {
1628                 if (c == 'u' || c == 'U')
1629                   {
1630                     if (spec_unsigned)
1631                       error ("two `u's in integer constant");
1632                     spec_unsigned = 1;
1633                   }
1634                 else if (c == 'l' || c == 'L')
1635                   {
1636                     if (spec_long)
1637                       {
1638                         if (spec_long_long)
1639                           error ("three `l's in integer constant");
1640                         else if (pedantic)
1641                           pedwarn ("ANSI C forbids long long integer constants");
1642                         spec_long_long = 1;
1643                       }
1644                     spec_long = 1;
1645                   }
1646                 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1647                   {
1648                     if (spec_imag)
1649                       error ("more than one `i' or `j' in numeric constant");
1650                     else if (pedantic)
1651                       pedwarn ("ANSI C forbids imaginary numeric constants");
1652                     spec_imag = 1;
1653                   }
1654                 else
1655                   break;
1656                 if (p >= token_buffer + maxtoken - 3)
1657                   p = extend_token_buffer (p);
1658                 *p++ = c;
1659                 c = GETC();
1660               }
1661
1662             /* If the constant is not long long and it won't fit in an
1663                unsigned long, or if the constant is long long and won't fit
1664                in an unsigned long long, then warn that the constant is out
1665                of range.  */
1666
1667             /* ??? This assumes that long long and long integer types are
1668                a multiple of 8 bits.  This better than the original code
1669                though which assumed that long was exactly 32 bits and long
1670                long was exactly 64 bits.  */
1671
1672             if (spec_long_long)
1673               bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1674             else
1675               bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1676
1677             warn = overflow;
1678             for (i = bytes; i < TOTAL_PARTS; i++)
1679               if (parts[i])
1680                 warn = 1;
1681             if (warn)
1682               pedwarn ("integer constant out of range");
1683
1684             /* This is simplified by the fact that our constant
1685                is always positive.  */
1686
1687             high = low = 0;
1688
1689             for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1690               {
1691                 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1692                                                     / HOST_BITS_PER_CHAR)]
1693                          << (i * HOST_BITS_PER_CHAR));
1694                 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1695               }
1696             
1697             yylval.ttype = build_int_2 (low, high);
1698             TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1699
1700             /* If warn_traditional, calculate both the ANSI type and the
1701                traditional type, then see if they disagree.
1702                Otherwise, calculate only the type for the dialect in use.  */
1703             if (warn_traditional || flag_traditional)
1704               {
1705                 /* Calculate the traditional type.  */
1706                 /* Traditionally, any constant is signed;
1707                    but if unsigned is specified explicitly, obey that.
1708                    Use the smallest size with the right number of bits,
1709                    except for one special case with decimal constants.  */
1710                 if (! spec_long && base != 10
1711                     && int_fits_type_p (yylval.ttype, unsigned_type_node))
1712                   traditional_type = (spec_unsigned ? unsigned_type_node
1713                                       : integer_type_node);
1714                 /* A decimal constant must be long
1715                    if it does not fit in type int.
1716                    I think this is independent of whether
1717                    the constant is signed.  */
1718                 else if (! spec_long && base == 10
1719                          && int_fits_type_p (yylval.ttype, integer_type_node))
1720                   traditional_type = (spec_unsigned ? unsigned_type_node
1721                                       : integer_type_node);
1722                 else if (! spec_long_long)
1723                   traditional_type = (spec_unsigned ? long_unsigned_type_node
1724                                       : long_integer_type_node);
1725                 else
1726                   traditional_type = (spec_unsigned
1727                                       ? long_long_unsigned_type_node
1728                                       : long_long_integer_type_node);
1729               }
1730             if (warn_traditional || ! flag_traditional)
1731               {
1732                 /* Calculate the ANSI type.  */
1733                 if (! spec_long && ! spec_unsigned
1734                     && int_fits_type_p (yylval.ttype, integer_type_node))
1735                   ansi_type = integer_type_node;
1736                 else if (! spec_long && (base != 10 || spec_unsigned)
1737                          && int_fits_type_p (yylval.ttype, unsigned_type_node))
1738                   ansi_type = unsigned_type_node;
1739                 else if (! spec_unsigned && !spec_long_long
1740                          && int_fits_type_p (yylval.ttype, long_integer_type_node))
1741                   ansi_type = long_integer_type_node;
1742                 else if (! spec_long_long)
1743                   ansi_type = long_unsigned_type_node;
1744                 else if (! spec_unsigned
1745                          /* Verify value does not overflow into sign bit.  */
1746                          && TREE_INT_CST_HIGH (yylval.ttype) >= 0
1747                          && int_fits_type_p (yylval.ttype,
1748                                              long_long_integer_type_node))
1749                   ansi_type = long_long_integer_type_node;
1750                 else
1751                   ansi_type = long_long_unsigned_type_node;
1752               }
1753
1754             type = flag_traditional ? traditional_type : ansi_type;
1755
1756             if (warn_traditional && traditional_type != ansi_type)
1757               {
1758                 if (TYPE_PRECISION (traditional_type)
1759                     != TYPE_PRECISION (ansi_type))
1760                   warning ("width of integer constant changes with -traditional");
1761                 else if (TREE_UNSIGNED (traditional_type)
1762                          != TREE_UNSIGNED (ansi_type))
1763                   warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1764                 else
1765                   warning ("width of integer constant may change on other systems with -traditional");
1766               }
1767
1768             if (!flag_traditional && !int_fits_type_p (yylval.ttype, type)
1769                 && !warn)
1770               pedwarn ("integer constant out of range");
1771
1772             if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1773               warning ("decimal constant is so large that it is unsigned");
1774
1775             if (spec_imag)
1776               {
1777                 if (TYPE_PRECISION (type)
1778                     <= TYPE_PRECISION (integer_type_node))
1779                   yylval.ttype
1780                     = build_complex (NULL_TREE, integer_zero_node,
1781                                      convert (integer_type_node,
1782                                               yylval.ttype));
1783                 else
1784                   error ("complex integer constant is too wide for `complex int'");
1785               }
1786             else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1787               /* The traditional constant 0x80000000 is signed
1788                  but doesn't fit in the range of int.
1789                  This will change it to -0x80000000, which does fit.  */
1790               {
1791                 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1792                 yylval.ttype = convert (type, yylval.ttype);
1793                 TREE_OVERFLOW (yylval.ttype)
1794                   = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1795               }
1796             else
1797               TREE_TYPE (yylval.ttype) = type;
1798           }
1799
1800         UNGETC (c);
1801         *p = 0;
1802
1803         if (isalnum (c) || c == '.' || c == '_' || c == '$'
1804             || (!flag_traditional && (c == '-' || c == '+')
1805                 && (p[-1] == 'e' || p[-1] == 'E')))
1806           error ("missing white space after number `%s'", token_buffer);
1807
1808         value = CONSTANT; break;
1809       }
1810
1811     case '\'':
1812     char_constant:
1813       {
1814         register int result = 0;
1815         register int num_chars = 0;
1816         unsigned width = TYPE_PRECISION (char_type_node);
1817         int max_chars;
1818
1819         if (wide_flag)
1820           {
1821             width = WCHAR_TYPE_SIZE;
1822 #ifdef MULTIBYTE_CHARS
1823             max_chars = MB_CUR_MAX;
1824 #else
1825             max_chars = 1;
1826 #endif
1827           }
1828         else
1829           max_chars = TYPE_PRECISION (integer_type_node) / width;
1830
1831         while (1)
1832           {
1833           tryagain:
1834
1835             c = GETC();
1836
1837             if (c == '\'' || c == EOF)
1838               break;
1839
1840             if (c == '\\')
1841               {
1842                 int ignore = 0;
1843                 c = readescape (&ignore);
1844                 if (ignore)
1845                   goto tryagain;
1846                 if (width < HOST_BITS_PER_INT
1847                     && (unsigned) c >= (1 << width))
1848                   pedwarn ("escape sequence out of range for character");
1849 #ifdef MAP_CHARACTER
1850                 if (isprint (c))
1851                   c = MAP_CHARACTER (c);
1852 #endif
1853               }
1854             else if (c == '\n')
1855               {
1856                 if (pedantic)
1857                   pedwarn ("ANSI C forbids newline in character constant");
1858                 lineno++;
1859               }
1860 #ifdef MAP_CHARACTER
1861             else
1862               c = MAP_CHARACTER (c);
1863 #endif
1864
1865             num_chars++;
1866             if (num_chars > maxtoken - 4)
1867               extend_token_buffer (token_buffer);
1868
1869             token_buffer[num_chars] = c;
1870
1871             /* Merge character into result; ignore excess chars.  */
1872             if (num_chars < max_chars + 1)
1873               {
1874                 if (width < HOST_BITS_PER_INT)
1875                   result = (result << width) | (c & ((1 << width) - 1));
1876                 else
1877                   result = c;
1878               }
1879           }
1880
1881         token_buffer[num_chars + 1] = '\'';
1882         token_buffer[num_chars + 2] = 0;
1883
1884         if (c != '\'')
1885           error ("malformatted character constant");
1886         else if (num_chars == 0)
1887           error ("empty character constant");
1888         else if (num_chars > max_chars)
1889           {
1890             num_chars = max_chars;
1891             error ("character constant too long");
1892           }
1893         else if (num_chars != 1 && ! flag_traditional)
1894           warning ("multi-character character constant");
1895
1896         /* If char type is signed, sign-extend the constant.  */
1897         if (! wide_flag)
1898           {
1899             int num_bits = num_chars * width;
1900             if (num_bits == 0)
1901               /* We already got an error; avoid invalid shift.  */
1902               yylval.ttype = build_int_2 (0, 0);
1903             else if (TREE_UNSIGNED (char_type_node)
1904                      || ((result >> (num_bits - 1)) & 1) == 0)
1905               yylval.ttype
1906                 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1907                                          >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1908                                0);
1909             else
1910               yylval.ttype
1911                 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1912                                           >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1913                                -1);
1914             TREE_TYPE (yylval.ttype) = integer_type_node;
1915           }
1916         else
1917           {
1918 #ifdef MULTIBYTE_CHARS
1919             /* Set the initial shift state and convert the next sequence.  */
1920             result = 0;
1921             /* In all locales L'\0' is zero and mbtowc will return zero,
1922                so don't use it.  */
1923             if (num_chars > 1
1924                 || (num_chars == 1 && token_buffer[1] != '\0'))
1925               {
1926                 wchar_t wc;
1927                 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1928                 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1929                   result = wc;
1930                 else
1931                   warning ("Ignoring invalid multibyte character");
1932               }
1933 #endif
1934             yylval.ttype = build_int_2 (result, 0);
1935             TREE_TYPE (yylval.ttype) = wchar_type_node;
1936           }
1937
1938         value = CONSTANT;
1939         break;
1940       }
1941
1942     case '"':
1943     string_constant:
1944       {
1945         c = GETC();
1946         p = token_buffer + 1;
1947
1948         while (c != '"' && c >= 0)
1949           {
1950             if (c == '\\')
1951               {
1952                 int ignore = 0;
1953                 c = readescape (&ignore);
1954                 if (ignore)
1955                   goto skipnewline;
1956                 if (!wide_flag
1957                     && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1958                     && c >= (1 << TYPE_PRECISION (char_type_node)))
1959                   pedwarn ("escape sequence out of range for character");
1960               }
1961             else if (c == '\n')
1962               {
1963                 if (pedantic)
1964                   pedwarn ("ANSI C forbids newline in string constant");
1965                 lineno++;
1966               }
1967
1968             if (p == token_buffer + maxtoken)
1969               p = extend_token_buffer (p);
1970             *p++ = c;
1971
1972           skipnewline:
1973             c = GETC();
1974           }
1975         *p = 0;
1976
1977         if (c < 0)
1978           error ("Unterminated string constant");
1979
1980         /* We have read the entire constant.
1981            Construct a STRING_CST for the result.  */
1982
1983         if (wide_flag)
1984           {
1985             /* If this is a L"..." wide-string, convert the multibyte string
1986                to a wide character string.  */
1987             char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1988             int len;
1989
1990 #ifdef MULTIBYTE_CHARS
1991             len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1992             if (len < 0 || len >= (p - token_buffer))
1993               {
1994                 warning ("Ignoring invalid multibyte string");
1995                 len = 0;
1996               }
1997             bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1998 #else
1999             {
2000               union { long l; char c[sizeof (long)]; } u;
2001               int big_endian;
2002               char *wp, *cp;
2003
2004               /* Determine whether host is little or big endian.  */
2005               u.l = 1;
2006               big_endian = u.c[sizeof (long) - 1];
2007               wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
2008
2009               bzero (widep, (p - token_buffer) * WCHAR_BYTES);
2010               for (cp = token_buffer + 1; cp < p; cp++)
2011                 *wp = *cp, wp += WCHAR_BYTES;
2012               len = p - token_buffer - 1;
2013             }
2014 #endif
2015             yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
2016             TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2017             value = STRING;
2018           }
2019         else if (objc_flag)
2020           {
2021             extern tree build_objc_string();
2022             /* Return an Objective-C @"..." constant string object.  */
2023             yylval.ttype = build_objc_string (p - token_buffer,
2024                                               token_buffer + 1);
2025             TREE_TYPE (yylval.ttype) = char_array_type_node;
2026             value = OBJC_STRING;
2027           }
2028         else
2029           {
2030             yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
2031             TREE_TYPE (yylval.ttype) = char_array_type_node;
2032             value = STRING;
2033           }
2034
2035         *p++ = '"';
2036         *p = 0;
2037
2038         break;
2039       }
2040
2041     case '+':
2042     case '-':
2043     case '&':
2044     case '|':
2045     case ':':
2046     case '<':
2047     case '>':
2048     case '*':
2049     case '/':
2050     case '%':
2051     case '^':
2052     case '!':
2053     case '=':
2054       {
2055         register int c1;
2056
2057       combine:
2058
2059         switch (c)
2060           {
2061           case '+':
2062             yylval.code = PLUS_EXPR; break;
2063           case '-':
2064             yylval.code = MINUS_EXPR; break;
2065           case '&':
2066             yylval.code = BIT_AND_EXPR; break;
2067           case '|':
2068             yylval.code = BIT_IOR_EXPR; break;
2069           case '*':
2070             yylval.code = MULT_EXPR; break;
2071           case '/':
2072             yylval.code = TRUNC_DIV_EXPR; break;
2073           case '%':
2074             yylval.code = TRUNC_MOD_EXPR; break;
2075           case '^':
2076             yylval.code = BIT_XOR_EXPR; break;
2077           case LSHIFT:
2078             yylval.code = LSHIFT_EXPR; break;
2079           case RSHIFT:
2080             yylval.code = RSHIFT_EXPR; break;
2081           case '<':
2082             yylval.code = LT_EXPR; break;
2083           case '>':
2084             yylval.code = GT_EXPR; break;
2085           }
2086
2087         token_buffer[1] = c1 = GETC();
2088         token_buffer[2] = 0;
2089
2090         if (c1 == '=')
2091           {
2092             switch (c)
2093               {
2094               case '<':
2095                 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2096               case '>':
2097                 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2098               case '!':
2099                 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2100               case '=':
2101                 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2102               }
2103             value = ASSIGN; goto done;
2104           }
2105         else if (c == c1)
2106           switch (c)
2107             {
2108             case '+':
2109               value = PLUSPLUS; goto done;
2110             case '-':
2111               value = MINUSMINUS; goto done;
2112             case '&':
2113               value = ANDAND; goto done;
2114             case '|':
2115               value = OROR; goto done;
2116             case '<':
2117               c = LSHIFT;
2118               goto combine;
2119             case '>':
2120               c = RSHIFT;
2121               goto combine;
2122             }
2123         else
2124           switch (c)
2125             {
2126             case '-':
2127               if (c1 == '>')
2128                 { value = POINTSAT; goto done; }
2129               break;
2130             case ':':
2131               if (c1 == '>')
2132                 { value = ']'; goto done; }
2133               break;
2134             case '<':
2135               if (c1 == '%')
2136                 { value = '{'; goto done; }
2137               if (c1 == ':')
2138                 { value = '['; goto done; }
2139               break;
2140             case '%':
2141               if (c1 == '>')
2142                 { value = '}'; goto done; }
2143               break;
2144             }
2145         UNGETC (c1);
2146         token_buffer[1] = 0;
2147
2148         if ((c == '<') || (c == '>'))
2149           value = ARITHCOMPARE;
2150         else value = c;
2151         goto done;
2152       }
2153
2154     case 0:
2155       /* Don't make yyparse think this is eof.  */
2156       value = 1;
2157       break;
2158
2159     default:
2160       value = c;
2161     }
2162
2163 done:
2164 /*  yylloc.last_line = lineno; */
2165
2166   return value;
2167 }
2168
2169 /* Sets the value of the 'yydebug' variable to VALUE.
2170    This is a function so we don't have to have YYDEBUG defined
2171    in order to build the compiler.  */
2172
2173 void
2174 set_yydebug (value)
2175      int value;
2176 {
2177 #if YYDEBUG != 0
2178   yydebug = value;
2179 #else
2180   warning ("YYDEBUG not defined.");
2181 #endif
2182 }