OSDN Git Service

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