OSDN Git Service

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