OSDN Git Service

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