OSDN Git Service

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