OSDN Git Service

* jcf-parse.c (init_jcf_parse): Register current_file_list root.
[pf3gnuchains/gcc-fork.git] / gcc / c-lex.c
1 /* Lexical analyzer for C and Objective C.
2    Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
3    1998, 1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24
25 #include "rtl.h"
26 #include "expr.h"
27 #include "tree.h"
28 #include "input.h"
29 #include "output.h"
30 #include "c-lex.h"
31 #include "c-tree.h"
32 #include "flags.h"
33 #include "timevar.h"
34 #include "cpplib.h"
35 #include "c-pragma.h"
36 #include "toplev.h"
37 #include "intl.h"
38 #include "tm_p.h"
39 #include "splay-tree.h"
40
41 /* MULTIBYTE_CHARS support only works for native compilers.
42    ??? Ideally what we want is to model widechar support after
43    the current floating point support.  */
44 #ifdef CROSS_COMPILE
45 #undef MULTIBYTE_CHARS
46 #endif
47
48 #ifdef MULTIBYTE_CHARS
49 #include "mbchar.h"
50 #include <locale.h>
51 #endif /* MULTIBYTE_CHARS */
52 #ifndef GET_ENVIRONMENT
53 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME))
54 #endif
55
56 #if USE_CPPLIB
57 extern cpp_reader  parse_in;
58 #else
59 /* Stream for reading from the input file.  */
60 FILE *finput;
61 #endif
62
63 /* The original file name, before changing "-" to "stdin".  */
64 static const char *orig_filename;
65
66 /* Private idea of the line number.  See discussion in c_lex().  */
67 static int lex_lineno;
68
69 /* We may keep statistics about how long which files took to compile.  */
70 static int header_time, body_time;
71 static splay_tree file_info_tree;
72
73 /* Cause the `yydebug' variable to be defined.  */
74 #define YYDEBUG 1
75
76 #if !USE_CPPLIB
77
78 struct putback_buffer
79 {
80   unsigned char *buffer;
81   int   buffer_size;
82   int   index;
83 };
84
85 static struct putback_buffer putback = {NULL, 0, -1};
86
87 static inline int getch PARAMS ((void));
88
89 static inline int
90 getch ()
91 {
92   if (putback.index != -1)
93     {
94       int ch = putback.buffer[putback.index];
95       --putback.index;
96       return ch;
97     }
98   return getc (finput);
99 }
100
101 static inline void put_back PARAMS ((int));
102
103 static inline void
104 put_back (ch)
105      int ch;
106 {
107   if (ch != EOF)
108     {
109       if (putback.index == putback.buffer_size - 1)
110         {
111           putback.buffer_size += 16;
112           putback.buffer = xrealloc (putback.buffer, putback.buffer_size);
113         }
114       putback.buffer[++putback.index] = ch;
115     }
116 }
117
118 int linemode;
119
120 #endif
121
122 /* File used for outputting assembler code.  */
123 extern FILE *asm_out_file;
124
125 #undef WCHAR_TYPE_SIZE
126 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
127
128 /* Number of bytes in a wide character.  */
129 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
130
131 #if !USE_CPPLIB
132 static int maxtoken;            /* Current nominal length of token buffer.  */
133 static char *token_buffer;      /* Pointer to token buffer.
134                                    Actual allocated length is maxtoken + 2. */
135 #endif
136
137 int indent_level;        /* Number of { minus number of }. */
138 int pending_lang_change; /* If we need to switch languages - C++ only */
139 int c_header_level;      /* depth in C headers - C++ only */
140
141 /* Nonzero tells yylex to ignore \ in string constants.  */
142 static int ignore_escape_flag;
143
144 static const char *readescape   PARAMS ((const char *, const char *,
145                                          unsigned int *));
146 static const char *read_ucs     PARAMS ((const char *, const char *,
147                                          unsigned int *, int));
148 static void parse_float         PARAMS ((PTR));
149 static tree lex_number          PARAMS ((const char *, unsigned int));
150 static tree lex_string          PARAMS ((const char *, unsigned int, int));
151 static tree lex_charconst       PARAMS ((const char *, unsigned int, int));
152 static void update_header_times PARAMS ((const char *));
153 static int dump_one_header      PARAMS ((splay_tree_node, void *));
154
155 #if !USE_CPPLIB
156 static int skip_white_space             PARAMS ((int));
157 static char *extend_token_buffer        PARAMS ((const char *));
158 static void extend_token_buffer_to      PARAMS ((int));
159 static int read_line_number             PARAMS ((int *));
160 static void process_directive           PARAMS ((void));
161 #else
162 static void cb_ident            PARAMS ((cpp_reader *, const cpp_string *));
163 static void cb_enter_file       PARAMS ((cpp_reader *));
164 static void cb_leave_file       PARAMS ((cpp_reader *));
165 static void cb_rename_file      PARAMS ((cpp_reader *));
166 static void cb_def_pragma       PARAMS ((cpp_reader *));
167 #endif
168
169 \f
170 const char *
171 init_c_lex (filename)
172      const char *filename;
173 {
174   struct c_fileinfo *toplevel;
175
176   orig_filename = filename;
177
178   /* Set up filename timing.  Must happen before cpp_start_read.  */
179   file_info_tree = splay_tree_new ((splay_tree_compare_fn)strcmp,
180                                    0,
181                                    (splay_tree_delete_value_fn)free);
182   toplevel = get_fileinfo ("<top level>");
183   if (flag_detailed_statistics)
184     {
185       header_time = 0;
186       body_time = get_run_time ();
187       toplevel->time = body_time;
188     }
189   
190 #ifdef MULTIBYTE_CHARS
191   /* Change to the native locale for multibyte conversions.  */
192   setlocale (LC_CTYPE, "");
193   GET_ENVIRONMENT (literal_codeset, "LANG");
194 #endif
195
196 #if !USE_CPPLIB
197   /* Open input file.  */
198   if (filename == 0 || !strcmp (filename, "-"))
199     {
200       finput = stdin;
201       filename = "stdin";
202     }
203   else
204     finput = fopen (filename, "r");
205   if (finput == 0)
206     pfatal_with_name (filename);
207
208 #ifdef IO_BUFFER_SIZE
209   setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
210 #endif
211 #else /* !USE_CPPLIB */
212
213   parse_in.cb.ident = cb_ident;
214   parse_in.cb.enter_file = cb_enter_file;
215   parse_in.cb.leave_file = cb_leave_file;
216   parse_in.cb.rename_file = cb_rename_file;
217   parse_in.cb.def_pragma = cb_def_pragma;
218
219   /* Make sure parse_in.digraphs matches flag_digraphs.  */
220   CPP_OPTION (&parse_in, digraphs) = flag_digraphs;
221
222   if (filename == 0 || !strcmp (filename, "-"))
223     filename = "stdin";
224 #endif
225
226 #if !USE_CPPLIB
227   maxtoken = 40;
228   token_buffer = (char *) xmalloc (maxtoken + 2);
229 #endif
230   /* Start it at 0, because check_newline is called at the very beginning
231      and will increment it to 1.  */
232   lineno = lex_lineno = 0;
233
234   return filename;
235 }
236
237 /* A thin wrapper around the real parser that initializes the 
238    integrated preprocessor after debug output has been initialized.  */
239
240 int
241 yyparse()
242 {
243   if (! cpp_start_read (&parse_in, orig_filename))
244     return 1;                   /* cpplib has emitted an error.  */
245
246   return yyparse_1();
247 }
248
249 struct c_fileinfo *
250 get_fileinfo (name)
251      const char *name;
252 {
253   splay_tree_node n;
254   struct c_fileinfo *fi;
255
256   n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
257   if (n)
258     return (struct c_fileinfo *) n->value;
259
260   fi = (struct c_fileinfo *) xmalloc (sizeof (struct c_fileinfo));
261   fi->time = 0;
262   fi->interface_only = 0;
263   fi->interface_unknown = 1;
264   splay_tree_insert (file_info_tree, (splay_tree_key) name,
265                      (splay_tree_value) fi);
266   return fi;
267 }
268
269 static void
270 update_header_times (name)
271      const char *name;
272 {
273   /* Changing files again.  This means currently collected time
274      is charged against header time, and body time starts back at 0.  */
275   if (flag_detailed_statistics)
276     {
277       int this_time = get_run_time ();
278       struct c_fileinfo *file = get_fileinfo (name);
279       header_time += this_time - body_time;
280       file->time += this_time - body_time;
281       body_time = this_time;
282     }
283 }
284
285 static int
286 dump_one_header (n, dummy)
287      splay_tree_node n;
288      void *dummy ATTRIBUTE_UNUSED;
289 {
290   print_time ((const char *) n->key,
291               ((struct c_fileinfo *) n->value)->time);
292   return 0;
293 }
294
295 void
296 dump_time_statistics ()
297 {
298   struct c_fileinfo *file = get_fileinfo (input_filename);
299   int this_time = get_run_time ();
300   file->time += this_time - body_time;
301
302   fprintf (stderr, "\n******\n");
303   print_time ("header files (total)", header_time);
304   print_time ("main file (total)", this_time - body_time);
305   fprintf (stderr, "ratio = %g : 1\n",
306            (double)header_time / (double)(this_time - body_time));
307   fprintf (stderr, "\n******\n");
308
309   splay_tree_foreach (file_info_tree, dump_one_header, 0);
310 }
311
312 #if !USE_CPPLIB
313
314 /* If C is not whitespace, return C.
315    Otherwise skip whitespace and return first nonwhite char read.  */
316
317 static int
318 skip_white_space (c)
319      register int c;
320 {
321   for (;;)
322     {
323       switch (c)
324         {
325           /* There is no need to process comments or backslash-newline
326              here.  None can occur in the output of cpp.  Do handle \r
327              in case someone sent us a .i file.  */
328
329         case '\n':
330           if (linemode)
331             {
332               put_back (c);
333               return EOF;
334             }
335           c = check_newline ();
336           break;
337
338         case '\r':
339           /* Per C99, horizontal whitespace is just these four characters.  */
340         case ' ':
341         case '\t':
342         case '\f':
343         case '\v':
344           c = getch ();
345           break;
346
347         case '\\':
348           error ("stray '\\' in program");
349           c = getch ();
350           break;
351
352         default:
353           return (c);
354         }
355     }
356 }
357
358 /* Skips all of the white space at the current location in the input file.  */
359
360 void
361 position_after_white_space ()
362 {
363   register int c;
364
365   c = getch ();
366
367   put_back (skip_white_space (c));
368 }
369
370 /* Make the token buffer longer, preserving the data in it.
371    P should point to just beyond the last valid character in the old buffer.
372    The value we return is a pointer to the new buffer
373    at a place corresponding to P.  */
374
375 static void
376 extend_token_buffer_to (size)
377      int size;
378 {
379   do
380     maxtoken = maxtoken * 2 + 10;
381   while (maxtoken < size);
382   token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
383 }
384
385 static char *
386 extend_token_buffer (p)
387      const char *p;
388 {
389   int offset = p - token_buffer;
390   extend_token_buffer_to (offset);
391   return token_buffer + offset;
392 }
393 \f
394
395 static int
396 read_line_number (num)
397      int *num;
398 {
399   tree value;
400   enum cpp_ttype token = c_lex (&value);
401
402   if (token == CPP_NUMBER && TREE_CODE (value) == INTEGER_CST)
403     {
404       *num = TREE_INT_CST_LOW (value);
405       return 1;
406     }
407   else
408     {
409       if (token != CPP_EOF)
410         error ("invalid #-line");
411       return 0;
412     }
413 }
414
415 /* At the beginning of a line, increment the line number
416    and process any #-directive on this line.
417    If the line is a #-directive, read the entire line and return a newline.
418    Otherwise, return the line's first non-whitespace character.  */
419
420 int
421 check_newline ()
422 {
423   register int c;
424
425   /* Loop till we get a nonblank, non-directive line.  */
426   for (;;)
427     {
428       /* Read first nonwhite char on the line.  */
429       do
430         c = getch ();
431       while (c == ' ' || c == '\t');
432
433       lex_lineno++;
434       if (c == '#')
435         {
436           process_directive ();
437           return '\n';
438         }
439
440       else if (c != '\n')
441         break;
442     }
443   return c;
444 }
445
446 static void
447 process_directive ()
448 {
449   enum cpp_ttype token;
450   tree value;
451   int saw_line;
452   enum { act_none, act_push, act_pop } action;
453   int action_number, l;
454   const char *new_file;
455 #ifndef NO_IMPLICIT_EXTERN_C
456   int entering_c_header = 0;
457 #endif
458   
459   /* Don't read beyond this line.  */
460   saw_line = 0;
461   linemode = 1;
462   
463   token = c_lex (&value);
464
465   if (token == CPP_NAME)
466     {
467       /* If a letter follows, then if the word here is `line', skip
468          it and ignore it; otherwise, ignore the line, with an error
469          if the word isn't `pragma'.  */
470
471       const char *name = IDENTIFIER_POINTER (value);
472
473       if (!strcmp (name, "pragma"))
474         {
475           dispatch_pragma ();
476           goto skipline;
477         }
478       else if (!strcmp (name, "define"))
479         {
480           debug_define (lex_lineno, GET_DIRECTIVE_LINE ());
481           goto skipline;
482         }
483       else if (!strcmp (name, "undef"))
484         {
485           debug_undef (lex_lineno, GET_DIRECTIVE_LINE ());
486           goto skipline;
487         }
488       else if (!strcmp (name, "line"))
489         {
490           saw_line = 1;
491           token = c_lex (&value);
492           goto linenum;
493         }
494       else if (!strcmp (name, "ident"))
495         {
496           /* #ident.  We expect a string constant here.
497              The pedantic warning and syntax error are now in cpp.  */
498
499           token = c_lex (&value);
500           if (token != CPP_STRING || TREE_CODE (value) != STRING_CST)
501             goto skipline;
502
503 #ifdef ASM_OUTPUT_IDENT
504           if (! flag_no_ident)
505             {
506               ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (value));
507             }
508 #endif
509
510           /* Skip the rest of this line.  */
511           goto skipline;
512         }
513
514       error ("undefined or invalid # directive `%s'", name);
515       goto skipline;
516     }
517
518   /* If the # is the only nonwhite char on the line,
519      just ignore it.  Check the new newline.  */
520   if (token == CPP_EOF)
521     goto skipline;
522
523 linenum:
524   /* Here we have either `#line' or `# <nonletter>'.
525      In either case, it should be a line number; a digit should follow.  */
526
527   if (token != CPP_NUMBER || TREE_CODE (value) != INTEGER_CST)
528     {
529       error ("invalid #-line");
530       goto skipline;
531     }
532
533   /* subtract one, because it is the following line that
534      gets the specified number */
535
536   l = TREE_INT_CST_LOW (value) - 1;
537
538   /* More follows: it must be a string constant (filename).
539      It would be neat to use cpplib to quickly process the string, but
540      (1) we don't have a handy tokenization of the string, and
541      (2) I don't know how well that would work in the presense
542      of filenames that contain wide characters.  */
543
544   if (saw_line)
545     {
546       /* Don't treat \ as special if we are processing #line 1 "...".
547          If you want it to be treated specially, use # 1 "...".  */
548       ignore_escape_flag = 1;
549     }
550
551   /* Read the string constant.  */
552   token = c_lex (&value);
553
554   ignore_escape_flag = 0;
555
556   if (token == CPP_EOF)
557     {
558       /* No more: store the line number and check following line.  */
559       lex_lineno = l;
560       goto skipline;
561     }
562
563   if (token != CPP_STRING || TREE_CODE (value) != STRING_CST)
564     {
565       error ("invalid #line");
566       goto skipline;
567     }
568
569   new_file = TREE_STRING_POINTER (value);
570
571   if (main_input_filename == 0)
572     main_input_filename = new_file;
573
574   action = act_none;
575   action_number = 0;
576
577   /* Each change of file name
578      reinitializes whether we are now in a system header.  */
579   in_system_header = 0;
580
581   if (!read_line_number (&action_number))
582     {
583       /* Update the name in the top element of input_file_stack.  */
584       if (input_file_stack)
585         input_file_stack->name = input_filename;
586     }
587
588   /* `1' after file name means entering new file.
589      `2' after file name means just left a file.  */
590
591   if (action_number == 1)
592     {
593       action = act_push;
594       read_line_number (&action_number);
595     }
596   else if (action_number == 2)
597     {
598       action = act_pop;
599       read_line_number (&action_number);
600     }
601   if (action_number == 3)
602     {
603       /* `3' after file name means this is a system header file.  */
604       in_system_header = 1;
605       read_line_number (&action_number);
606     }
607 #ifndef NO_IMPLICIT_EXTERN_C
608   if (action_number == 4)
609     {
610       /* `4' after file name means this is a C header file.  */
611       entering_c_header = 1;
612       read_line_number (&action_number);
613     }
614 #endif
615
616   /* Do the actions implied by the preceding numbers.  */
617   if (action == act_push)
618     {
619       lineno = lex_lineno;
620       push_srcloc (input_filename, 1);
621       input_file_stack->indent_level = indent_level;
622       debug_start_source_file (input_filename);
623 #ifndef NO_IMPLICIT_EXTERN_C
624       if (c_header_level)
625         ++c_header_level;
626       else if (entering_c_header)
627         {
628           c_header_level = 1;
629           ++pending_lang_change;
630         }
631 #endif
632     }
633   else if (action == act_pop)
634     {
635       /* Popping out of a file.  */
636       if (input_file_stack->next)
637         {
638 #ifndef NO_IMPLICIT_EXTERN_C
639           if (c_header_level && --c_header_level == 0)
640             {
641               if (entering_c_header)
642                 warning ("badly nested C headers from preprocessor");
643               --pending_lang_change;
644             }
645 #endif
646 #if 0
647           if (indent_level != input_file_stack->indent_level)
648             {
649               warning_with_file_and_line
650                 (input_filename, lex_lineno,
651                  "This file contains more '%c's than '%c's.",
652                  indent_level > input_file_stack->indent_level ? '{' : '}',
653                  indent_level > input_file_stack->indent_level ? '}' : '{');
654             }
655 #endif
656           pop_srcloc ();
657           debug_end_source_file (input_file_stack->line);
658         }
659       else
660         error ("#-lines for entering and leaving files don't match");
661     }
662
663   update_header_times (new_file);
664
665   input_filename = new_file;
666   lex_lineno = l;
667
668   /* Hook for C++.  */
669   extract_interface_info ();
670
671   /* skip the rest of this line.  */
672  skipline:
673   linemode = 0;
674
675   while (getch () != '\n');
676 }
677 #else /* USE_CPPLIB */
678
679 /* Not yet handled: #pragma, #define, #undef.
680    No need to deal with linemarkers under normal conditions.  */
681
682 static void
683 cb_ident (pfile, str)
684      cpp_reader *pfile ATTRIBUTE_UNUSED;
685      const cpp_string *str;
686 {
687 #ifdef ASM_OUTPUT_IDENT
688   if (! flag_no_ident)
689     {
690       /* Convert escapes in the string.  */
691       tree value = lex_string ((const char *)str->text, str->len, 0);
692       ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (value));
693     }
694 #endif
695 }
696
697 static void
698 cb_enter_file (pfile)
699      cpp_reader *pfile;
700 {
701   cpp_buffer *ip = CPP_BUFFER (pfile);
702   /* Bleah, need a better interface to this.  */
703   const char *flags = cpp_syshdr_flags (pfile, ip);
704
705   /* Mustn't stack the main buffer on the input stack.  (Ick.)  */
706   if (ip->prev)
707     {
708       lex_lineno = lineno = ip->prev->lineno - 1;
709       push_srcloc (ip->nominal_fname, 1);
710       input_file_stack->indent_level = indent_level;
711       debug_start_source_file (ip->nominal_fname);
712     }
713   else
714     lex_lineno = 1;
715
716   update_header_times (ip->nominal_fname);
717
718   /* Hook for C++.  */
719   extract_interface_info ();
720
721   in_system_header = (flags[0] != 0);
722 #ifndef NO_IMPLICIT_EXTERN_C
723   if (c_header_level)
724     ++c_header_level;
725   else if (in_system_header && flags[1] != 0 && flags[2] != 0)
726     {
727       c_header_level = 1;
728       ++pending_lang_change;
729     }
730 #endif
731 }
732
733 static void
734 cb_leave_file (pfile)
735      cpp_reader *pfile;
736 {
737   /* Bleah, need a better interface to this.  */
738   const char *flags = cpp_syshdr_flags (pfile, CPP_BUFFER (pfile));
739
740   if (input_file_stack->next)
741     {
742 #ifndef NO_IMPLICIT_EXTERN_C
743       if (c_header_level && --c_header_level == 0)
744         {
745           if (flags[2] != 0)
746             warning ("badly nested C headers from preprocessor");
747           --pending_lang_change;
748         }
749 #endif
750 #if 0
751       if (indent_level != input_file_stack->indent_level)
752         {
753           warning_with_file_and_line
754             (input_filename, lex_lineno,
755              "This file contains more '%c's than '%c's.",
756              indent_level > input_file_stack->indent_level ? '{' : '}',
757              indent_level > input_file_stack->indent_level ? '}' : '{');
758         }
759 #endif
760       /* We get called for the main buffer, but we mustn't pop it.  */
761       pop_srcloc ();
762       debug_end_source_file (input_file_stack->line);
763     }
764
765   in_system_header = (flags[0] != 0);
766   lex_lineno = CPP_BUFFER (pfile)->lineno;
767
768   update_header_times (input_file_stack->name);
769   /* Hook for C++.  */
770   extract_interface_info ();
771 }
772
773 static void
774 cb_rename_file (pfile)
775      cpp_reader *pfile;
776 {
777   cpp_buffer *ip = CPP_BUFFER (pfile);
778   /* Bleah, need a better interface to this.  */
779   const char *flags = cpp_syshdr_flags (pfile, ip);
780   input_filename = ip->nominal_fname;
781   lex_lineno = ip->lineno;
782   in_system_header = (flags[0] != 0);
783
784   update_header_times (ip->nominal_fname);
785   /* Hook for C++.  */
786   extract_interface_info ();
787 }
788
789 static void
790 cb_def_pragma (pfile)
791      cpp_reader *pfile;
792 {
793   /* Issue a warning message if we have been asked to do so.  Ignore
794      unknown pragmas in system headers unless an explicit
795      -Wunknown-pragmas has been given. */
796   if (warn_unknown_pragmas > in_system_header)
797     {
798       const unsigned char *space, *name = 0;
799       cpp_token s;
800
801       cpp_get_token (pfile, &s);
802       space = cpp_token_as_text (pfile, &s);
803       cpp_get_token (pfile, &s);
804       if (s.type == CPP_NAME)
805         name = cpp_token_as_text (pfile, &s);
806
807       if (name)
808         warning ("ignoring #pragma %s %s", space, name);
809       else
810         warning ("ignoring #pragma %s", space);
811     }
812 }
813 #endif /* USE_CPPLIB */
814
815 /* Parse a '\uNNNN' or '\UNNNNNNNN' sequence.
816
817    [lex.charset]: The character designated by the universal-character-name 
818    \UNNNNNNNN is that character whose character short name in ISO/IEC 10646
819    is NNNNNNNN; the character designated by the universal-character-name
820    \uNNNN is that character whose character short name in ISO/IEC 10646 is
821    0000NNNN. If the hexadecimal value for a universal character name is
822    less than 0x20 or in the range 0x7F-0x9F (inclusive), or if the
823    universal character name designates a character in the basic source
824    character set, then the program is ill-formed.
825
826    We assume that wchar_t is Unicode, so we don't need to do any
827    mapping.  Is this ever wrong?  */
828
829 static const char *
830 read_ucs (p, limit, cptr, length)
831      const char *p;
832      const char *limit;
833      unsigned int *cptr;
834      int length;
835 {
836   unsigned int code = 0;
837   int c;
838
839   for (; length; --length)
840     {
841       if (p >= limit)
842         {
843           error ("incomplete universal-character-name");
844           break;
845         }
846
847       c = *p++;
848       if (! ISXDIGIT (c))
849         {
850           error ("non hex digit '%c' in universal-character-name", c);
851           p--;
852           break;
853         }
854
855       code <<= 4;
856       if (c >= 'a' && c <= 'f')
857         code += c - 'a' + 10;
858       if (c >= 'A' && c <= 'F')
859         code += c - 'A' + 10;
860       if (c >= '0' && c <= '9')
861         code += c - '0';
862     }
863
864 #ifdef TARGET_EBCDIC
865   sorry ("universal-character-name on EBCDIC target");
866   *cptr = 0x3f;  /* EBCDIC invalid character */
867   return p;
868 #endif
869
870   if (code > 0x9f && !(code & 0x80000000))
871     /* True extended character, OK.  */;
872   else if (code >= 0x20 && code < 0x7f)
873     {
874       /* ASCII printable character.  The C character set consists of all of
875          these except $, @ and `.  We use hex escapes so that this also
876          works with EBCDIC hosts.  */
877       if (code != 0x24 && code != 0x40 && code != 0x60)
878         error ("universal-character-name used for '%c'", code);
879     }
880   else
881     error ("invalid universal-character-name");
882
883   *cptr = code;
884   return p;
885 }
886
887 /* Read an escape sequence and write its character equivalent into *CPTR.
888    P is the input pointer, which is just after the backslash.  LIMIT
889    is how much text we have.
890    Returns the updated input pointer.  */
891
892 static const char *
893 readescape (p, limit, cptr)
894      const char *p;
895      const char *limit;
896      unsigned int *cptr;
897 {
898   unsigned int c, code, count;
899   unsigned firstdig = 0;
900   int nonnull;
901
902   if (p == limit)
903     {
904       /* cpp has already issued an error for this.  */
905       *cptr = 0;
906       return p;
907     }
908
909   c = *p++;
910
911   switch (c)
912     {
913     case 'x':
914       if (warn_traditional && !in_system_header)
915         warning ("the meaning of `\\x' varies with -traditional");
916
917       if (flag_traditional)
918         {
919           *cptr = 'x';
920           return p;
921         }
922
923       code = 0;
924       count = 0;
925       nonnull = 0;
926       while (p < limit)
927         {
928           c = *p++;
929           if (! ISXDIGIT (c))
930             {
931               p--;
932               break;
933             }
934           code *= 16;
935           if (c >= 'a' && c <= 'f')
936             code += c - 'a' + 10;
937           if (c >= 'A' && c <= 'F')
938             code += c - 'A' + 10;
939           if (c >= '0' && c <= '9')
940             code += c - '0';
941           if (code != 0 || count != 0)
942             {
943               if (count == 0)
944                 firstdig = code;
945               count++;
946             }
947           nonnull = 1;
948         }
949       if (! nonnull)
950         {
951           warning ("\\x used with no following hex digits");
952           *cptr = 'x';
953           return p;
954         }
955       else if (count == 0)
956         /* Digits are all 0's.  Ok.  */
957         ;
958       else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
959                || (count > 1
960                    && (((unsigned)1
961                         << (TYPE_PRECISION (integer_type_node)
962                             - (count - 1) * 4))
963                        <= firstdig)))
964         pedwarn ("hex escape out of range");
965       *cptr = code;
966       return p;
967
968     case '0':  case '1':  case '2':  case '3':  case '4':
969     case '5':  case '6':  case '7':
970       code = 0;
971       for (count = 0; count < 3; count++)
972         {
973           if (c < '0' || c > '7')
974             {
975               p--;
976               break;
977             }
978           code = (code * 8) + (c - '0');
979           if (p == limit)
980             break;
981           c = *p++;
982         }
983
984       if (count == 3)
985         p--;
986
987       *cptr = code;
988       return p;
989
990     case '\\': case '\'': case '"': case '?':
991       *cptr = c;
992       return p;
993
994     case 'n': *cptr = TARGET_NEWLINE;   return p;
995     case 't': *cptr = TARGET_TAB;       return p;
996     case 'r': *cptr = TARGET_CR;        return p;
997     case 'f': *cptr = TARGET_FF;        return p;
998     case 'b': *cptr = TARGET_BS;        return p;
999     case 'v': *cptr = TARGET_VT;        return p;
1000     case 'a':
1001       if (warn_traditional && !in_system_header)
1002         warning ("the meaning of '\\a' varies with -traditional");
1003       *cptr = flag_traditional ? c : TARGET_BELL;
1004       return p;
1005
1006       /* Warnings and support checks handled by read_ucs().  */
1007     case 'u': case 'U':
1008       if (c_language != clk_cplusplus && !flag_isoc99)
1009         break;
1010
1011       if (warn_traditional && !in_system_header)
1012         warning ("the meaning of '\\%c' varies with -traditional", c);
1013
1014       return read_ucs (p, limit, cptr, c == 'u' ? 4 : 8);
1015       
1016     case 'e': case 'E':
1017       if (pedantic)
1018         pedwarn ("non-ISO-standard escape sequence, '\\%c'", c);
1019       *cptr = TARGET_ESC; return p;
1020
1021       /* '\(', etc, are used at beginning of line to avoid confusing Emacs.
1022          '\%' is used to prevent SCCS from getting confused.  */
1023     case '(': case '{': case '[': case '%':
1024       if (pedantic)
1025         pedwarn ("unknown escape sequence '\\%c'", c);
1026       *cptr = c;
1027       return p;
1028     }
1029
1030   if (ISGRAPH (c))
1031     pedwarn ("unknown escape sequence '\\%c'", c);
1032   else
1033     pedwarn ("unknown escape sequence: '\\' followed by char 0x%x", c);
1034
1035   *cptr = c;
1036   return p;
1037 }
1038
1039 #if 0 /* not yet */
1040 /* Returns nonzero if C is a universal-character-name.  Give an error if it
1041    is not one which may appear in an identifier, as per [extendid].
1042
1043    Note that extended character support in identifiers has not yet been
1044    implemented.  It is my personal opinion that this is not a desirable
1045    feature.  Portable code cannot count on support for more than the basic
1046    identifier character set.  */
1047
1048 static inline int
1049 is_extended_char (c)
1050      int c;
1051 {
1052 #ifdef TARGET_EBCDIC
1053   return 0;
1054 #else
1055   /* ASCII.  */
1056   if (c < 0x7f)
1057     return 0;
1058
1059   /* None of the valid chars are outside the Basic Multilingual Plane (the
1060      low 16 bits).  */
1061   if (c > 0xffff)
1062     {
1063       error ("universal-character-name '\\U%08x' not valid in identifier", c);
1064       return 1;
1065     }
1066   
1067   /* Latin */
1068   if ((c >= 0x00c0 && c <= 0x00d6)
1069       || (c >= 0x00d8 && c <= 0x00f6)
1070       || (c >= 0x00f8 && c <= 0x01f5)
1071       || (c >= 0x01fa && c <= 0x0217)
1072       || (c >= 0x0250 && c <= 0x02a8)
1073       || (c >= 0x1e00 && c <= 0x1e9a)
1074       || (c >= 0x1ea0 && c <= 0x1ef9))
1075     return 1;
1076
1077   /* Greek */
1078   if ((c == 0x0384)
1079       || (c >= 0x0388 && c <= 0x038a)
1080       || (c == 0x038c)
1081       || (c >= 0x038e && c <= 0x03a1)
1082       || (c >= 0x03a3 && c <= 0x03ce)
1083       || (c >= 0x03d0 && c <= 0x03d6)
1084       || (c == 0x03da)
1085       || (c == 0x03dc)
1086       || (c == 0x03de)
1087       || (c == 0x03e0)
1088       || (c >= 0x03e2 && c <= 0x03f3)
1089       || (c >= 0x1f00 && c <= 0x1f15)
1090       || (c >= 0x1f18 && c <= 0x1f1d)
1091       || (c >= 0x1f20 && c <= 0x1f45)
1092       || (c >= 0x1f48 && c <= 0x1f4d)
1093       || (c >= 0x1f50 && c <= 0x1f57)
1094       || (c == 0x1f59)
1095       || (c == 0x1f5b)
1096       || (c == 0x1f5d)
1097       || (c >= 0x1f5f && c <= 0x1f7d)
1098       || (c >= 0x1f80 && c <= 0x1fb4)
1099       || (c >= 0x1fb6 && c <= 0x1fbc)
1100       || (c >= 0x1fc2 && c <= 0x1fc4)
1101       || (c >= 0x1fc6 && c <= 0x1fcc)
1102       || (c >= 0x1fd0 && c <= 0x1fd3)
1103       || (c >= 0x1fd6 && c <= 0x1fdb)
1104       || (c >= 0x1fe0 && c <= 0x1fec)
1105       || (c >= 0x1ff2 && c <= 0x1ff4)
1106       || (c >= 0x1ff6 && c <= 0x1ffc))
1107     return 1;
1108
1109   /* Cyrillic */
1110   if ((c >= 0x0401 && c <= 0x040d)
1111       || (c >= 0x040f && c <= 0x044f)
1112       || (c >= 0x0451 && c <= 0x045c)
1113       || (c >= 0x045e && c <= 0x0481)
1114       || (c >= 0x0490 && c <= 0x04c4)
1115       || (c >= 0x04c7 && c <= 0x04c8)
1116       || (c >= 0x04cb && c <= 0x04cc)
1117       || (c >= 0x04d0 && c <= 0x04eb)
1118       || (c >= 0x04ee && c <= 0x04f5)
1119       || (c >= 0x04f8 && c <= 0x04f9))
1120     return 1;
1121
1122   /* Armenian */
1123   if ((c >= 0x0531 && c <= 0x0556)
1124       || (c >= 0x0561 && c <= 0x0587))
1125     return 1;
1126
1127   /* Hebrew */
1128   if ((c >= 0x05d0 && c <= 0x05ea)
1129       || (c >= 0x05f0 && c <= 0x05f4))
1130     return 1;
1131
1132   /* Arabic */
1133   if ((c >= 0x0621 && c <= 0x063a)
1134       || (c >= 0x0640 && c <= 0x0652)
1135       || (c >= 0x0670 && c <= 0x06b7)
1136       || (c >= 0x06ba && c <= 0x06be)
1137       || (c >= 0x06c0 && c <= 0x06ce)
1138       || (c >= 0x06e5 && c <= 0x06e7))
1139     return 1;
1140
1141   /* Devanagari */
1142   if ((c >= 0x0905 && c <= 0x0939)
1143       || (c >= 0x0958 && c <= 0x0962))
1144     return 1;
1145
1146   /* Bengali */
1147   if ((c >= 0x0985 && c <= 0x098c)
1148       || (c >= 0x098f && c <= 0x0990)
1149       || (c >= 0x0993 && c <= 0x09a8)
1150       || (c >= 0x09aa && c <= 0x09b0)
1151       || (c == 0x09b2)
1152       || (c >= 0x09b6 && c <= 0x09b9)
1153       || (c >= 0x09dc && c <= 0x09dd)
1154       || (c >= 0x09df && c <= 0x09e1)
1155       || (c >= 0x09f0 && c <= 0x09f1))
1156     return 1;
1157
1158   /* Gurmukhi */
1159   if ((c >= 0x0a05 && c <= 0x0a0a)
1160       || (c >= 0x0a0f && c <= 0x0a10)
1161       || (c >= 0x0a13 && c <= 0x0a28)
1162       || (c >= 0x0a2a && c <= 0x0a30)
1163       || (c >= 0x0a32 && c <= 0x0a33)
1164       || (c >= 0x0a35 && c <= 0x0a36)
1165       || (c >= 0x0a38 && c <= 0x0a39)
1166       || (c >= 0x0a59 && c <= 0x0a5c)
1167       || (c == 0x0a5e))
1168     return 1;
1169
1170   /* Gujarati */
1171   if ((c >= 0x0a85 && c <= 0x0a8b)
1172       || (c == 0x0a8d)
1173       || (c >= 0x0a8f && c <= 0x0a91)
1174       || (c >= 0x0a93 && c <= 0x0aa8)
1175       || (c >= 0x0aaa && c <= 0x0ab0)
1176       || (c >= 0x0ab2 && c <= 0x0ab3)
1177       || (c >= 0x0ab5 && c <= 0x0ab9)
1178       || (c == 0x0ae0))
1179     return 1;
1180
1181   /* Oriya */
1182   if ((c >= 0x0b05 && c <= 0x0b0c)
1183       || (c >= 0x0b0f && c <= 0x0b10)
1184       || (c >= 0x0b13 && c <= 0x0b28)
1185       || (c >= 0x0b2a && c <= 0x0b30)
1186       || (c >= 0x0b32 && c <= 0x0b33)
1187       || (c >= 0x0b36 && c <= 0x0b39)
1188       || (c >= 0x0b5c && c <= 0x0b5d)
1189       || (c >= 0x0b5f && c <= 0x0b61))
1190     return 1;
1191
1192   /* Tamil */
1193   if ((c >= 0x0b85 && c <= 0x0b8a)
1194       || (c >= 0x0b8e && c <= 0x0b90)
1195       || (c >= 0x0b92 && c <= 0x0b95)
1196       || (c >= 0x0b99 && c <= 0x0b9a)
1197       || (c == 0x0b9c)
1198       || (c >= 0x0b9e && c <= 0x0b9f)
1199       || (c >= 0x0ba3 && c <= 0x0ba4)
1200       || (c >= 0x0ba8 && c <= 0x0baa)
1201       || (c >= 0x0bae && c <= 0x0bb5)
1202       || (c >= 0x0bb7 && c <= 0x0bb9))
1203     return 1;
1204
1205   /* Telugu */
1206   if ((c >= 0x0c05 && c <= 0x0c0c)
1207       || (c >= 0x0c0e && c <= 0x0c10)
1208       || (c >= 0x0c12 && c <= 0x0c28)
1209       || (c >= 0x0c2a && c <= 0x0c33)
1210       || (c >= 0x0c35 && c <= 0x0c39)
1211       || (c >= 0x0c60 && c <= 0x0c61))
1212     return 1;
1213
1214   /* Kannada */
1215   if ((c >= 0x0c85 && c <= 0x0c8c)
1216       || (c >= 0x0c8e && c <= 0x0c90)
1217       || (c >= 0x0c92 && c <= 0x0ca8)
1218       || (c >= 0x0caa && c <= 0x0cb3)
1219       || (c >= 0x0cb5 && c <= 0x0cb9)
1220       || (c >= 0x0ce0 && c <= 0x0ce1))
1221     return 1;
1222
1223   /* Malayalam */
1224   if ((c >= 0x0d05 && c <= 0x0d0c)
1225       || (c >= 0x0d0e && c <= 0x0d10)
1226       || (c >= 0x0d12 && c <= 0x0d28)
1227       || (c >= 0x0d2a && c <= 0x0d39)
1228       || (c >= 0x0d60 && c <= 0x0d61))
1229     return 1;
1230
1231   /* Thai */
1232   if ((c >= 0x0e01 && c <= 0x0e30)
1233       || (c >= 0x0e32 && c <= 0x0e33)
1234       || (c >= 0x0e40 && c <= 0x0e46)
1235       || (c >= 0x0e4f && c <= 0x0e5b))
1236     return 1;
1237
1238   /* Lao */
1239   if ((c >= 0x0e81 && c <= 0x0e82)
1240       || (c == 0x0e84)
1241       || (c == 0x0e87)
1242       || (c == 0x0e88)
1243       || (c == 0x0e8a)
1244       || (c == 0x0e0d)
1245       || (c >= 0x0e94 && c <= 0x0e97)
1246       || (c >= 0x0e99 && c <= 0x0e9f)
1247       || (c >= 0x0ea1 && c <= 0x0ea3)
1248       || (c == 0x0ea5)
1249       || (c == 0x0ea7)
1250       || (c == 0x0eaa)
1251       || (c == 0x0eab)
1252       || (c >= 0x0ead && c <= 0x0eb0)
1253       || (c == 0x0eb2)
1254       || (c == 0x0eb3)
1255       || (c == 0x0ebd)
1256       || (c >= 0x0ec0 && c <= 0x0ec4)
1257       || (c == 0x0ec6))
1258     return 1;
1259
1260   /* Georgian */
1261   if ((c >= 0x10a0 && c <= 0x10c5)
1262       || (c >= 0x10d0 && c <= 0x10f6))
1263     return 1;
1264
1265   /* Hiragana */
1266   if ((c >= 0x3041 && c <= 0x3094)
1267       || (c >= 0x309b && c <= 0x309e))
1268     return 1;
1269
1270   /* Katakana */
1271   if ((c >= 0x30a1 && c <= 0x30fe))
1272     return 1;
1273
1274   /* Bopmofo */
1275   if ((c >= 0x3105 && c <= 0x312c))
1276     return 1;
1277
1278   /* Hangul */
1279   if ((c >= 0x1100 && c <= 0x1159)
1280       || (c >= 0x1161 && c <= 0x11a2)
1281       || (c >= 0x11a8 && c <= 0x11f9))
1282     return 1;
1283
1284   /* CJK Unified Ideographs */
1285   if ((c >= 0xf900 && c <= 0xfa2d)
1286       || (c >= 0xfb1f && c <= 0xfb36)
1287       || (c >= 0xfb38 && c <= 0xfb3c)
1288       || (c == 0xfb3e)
1289       || (c >= 0xfb40 && c <= 0xfb41)
1290       || (c >= 0xfb42 && c <= 0xfb44)
1291       || (c >= 0xfb46 && c <= 0xfbb1)
1292       || (c >= 0xfbd3 && c <= 0xfd3f)
1293       || (c >= 0xfd50 && c <= 0xfd8f)
1294       || (c >= 0xfd92 && c <= 0xfdc7)
1295       || (c >= 0xfdf0 && c <= 0xfdfb)
1296       || (c >= 0xfe70 && c <= 0xfe72)
1297       || (c == 0xfe74)
1298       || (c >= 0xfe76 && c <= 0xfefc)
1299       || (c >= 0xff21 && c <= 0xff3a)
1300       || (c >= 0xff41 && c <= 0xff5a)
1301       || (c >= 0xff66 && c <= 0xffbe)
1302       || (c >= 0xffc2 && c <= 0xffc7)
1303       || (c >= 0xffca && c <= 0xffcf)
1304       || (c >= 0xffd2 && c <= 0xffd7)
1305       || (c >= 0xffda && c <= 0xffdc)
1306       || (c >= 0x4e00 && c <= 0x9fa5))
1307     return 1;
1308
1309   error ("universal-character-name '\\u%04x' not valid in identifier", c);
1310   return 1;
1311 #endif
1312 }
1313
1314 /* Add the UTF-8 representation of C to the token_buffer.  */
1315
1316 static void
1317 utf8_extend_token (c)
1318      int c;
1319 {
1320   int shift, mask;
1321
1322   if      (c <= 0x0000007f)
1323     {
1324       extend_token (c);
1325       return;
1326     }
1327   else if (c <= 0x000007ff)
1328     shift = 6, mask = 0xc0;
1329   else if (c <= 0x0000ffff)
1330     shift = 12, mask = 0xe0;
1331   else if (c <= 0x001fffff)
1332     shift = 18, mask = 0xf0;
1333   else if (c <= 0x03ffffff)
1334     shift = 24, mask = 0xf8;
1335   else
1336     shift = 30, mask = 0xfc;
1337
1338   extend_token (mask | (c >> shift));
1339   do
1340     {
1341       shift -= 6;
1342       extend_token ((unsigned char) (0x80 | (c >> shift)));
1343     }
1344   while (shift);
1345 }
1346 #endif
1347
1348 #if 0
1349 struct try_type
1350 {
1351   tree *node_var;
1352   char unsigned_flag;
1353   char long_flag;
1354   char long_long_flag;
1355 };
1356
1357 struct try_type type_sequence[] =
1358 {
1359   { &integer_type_node, 0, 0, 0},
1360   { &unsigned_type_node, 1, 0, 0},
1361   { &long_integer_type_node, 0, 1, 0},
1362   { &long_unsigned_type_node, 1, 1, 0},
1363   { &long_long_integer_type_node, 0, 1, 1},
1364   { &long_long_unsigned_type_node, 1, 1, 1}
1365 };
1366 #endif /* 0 */
1367 \f
1368 struct pf_args
1369 {
1370   /* Input */
1371   const char *str;
1372   int fflag;
1373   int lflag;
1374   int base;
1375   /* Output */
1376   int conversion_errno;
1377   REAL_VALUE_TYPE value;
1378   tree type;
1379 };
1380  
1381 static void
1382 parse_float (data)
1383   PTR data;
1384 {
1385   struct pf_args * args = (struct pf_args *) data;
1386   const char *typename;
1387
1388   args->conversion_errno = 0;
1389   args->type = double_type_node;
1390   typename = "double";
1391
1392   /* The second argument, machine_mode, of REAL_VALUE_ATOF
1393      tells the desired precision of the binary result
1394      of decimal-to-binary conversion.  */
1395
1396   if (args->fflag)
1397     {
1398       if (args->lflag)
1399         error ("both 'f' and 'l' suffixes on floating constant");
1400
1401       args->type = float_type_node;
1402       typename = "float";
1403     }
1404   else if (args->lflag)
1405     {
1406       args->type = long_double_type_node;
1407       typename = "long double";
1408     }
1409   else if (flag_single_precision_constant)
1410     {
1411       args->type = float_type_node;
1412       typename = "float";
1413     }
1414
1415   errno = 0;
1416   if (args->base == 16)
1417     args->value = REAL_VALUE_HTOF (args->str, TYPE_MODE (args->type));
1418   else
1419     args->value = REAL_VALUE_ATOF (args->str, TYPE_MODE (args->type));
1420
1421   args->conversion_errno = errno;
1422   /* A diagnostic is required here by some ISO C testsuites.
1423      This is not pedwarn, because some people don't want
1424      an error for this.  */
1425   if (REAL_VALUE_ISINF (args->value) && pedantic)
1426     warning ("floating point number exceeds range of '%s'", typename);
1427 }
1428  
1429 int
1430 c_lex (value)
1431      tree *value;
1432 {
1433 #if USE_CPPLIB
1434   cpp_token tok;
1435   enum cpp_ttype type;
1436
1437   retry:
1438   timevar_push (TV_CPP);
1439   cpp_get_token (&parse_in, &tok);
1440   timevar_pop (TV_CPP);
1441
1442   /* The C++ front end does horrible things with the current line
1443      number.  To ensure an accurate line number, we must reset it
1444      every time we return a token.  */
1445   lex_lineno = cpp_get_line (&parse_in)->line;
1446
1447   *value = NULL_TREE;
1448   lineno = lex_lineno;
1449   type = tok.type;
1450   switch (type)
1451     {
1452     case CPP_OPEN_BRACE:  indent_level++;  break;
1453     case CPP_CLOSE_BRACE: indent_level--;  break;
1454
1455     /* Issue this error here, where we can get at tok.val.c.  */
1456     case CPP_OTHER:
1457       if (ISGRAPH (tok.val.c))
1458         error ("stray '%c' in program", tok.val.c);
1459       else
1460         error ("stray '\\%#o' in program", tok.val.c);
1461       goto retry;
1462       
1463     case CPP_NAME:
1464       *value = get_identifier ((const char *)tok.val.node->name);
1465       break;
1466
1467     case CPP_INT:
1468     case CPP_FLOAT:
1469     case CPP_NUMBER:
1470       *value = lex_number ((const char *)tok.val.str.text, tok.val.str.len);
1471       break;
1472
1473     case CPP_CHAR:
1474     case CPP_WCHAR:
1475       *value = lex_charconst ((const char *)tok.val.str.text,
1476                               tok.val.str.len, tok.type == CPP_WCHAR);
1477       break;
1478
1479     case CPP_STRING:
1480     case CPP_WSTRING:
1481     case CPP_OSTRING:
1482       *value = lex_string ((const char *)tok.val.str.text,
1483                            tok.val.str.len, tok.type == CPP_WSTRING);
1484       break;
1485
1486       /* These tokens should not be visible outside cpplib.  */
1487     case CPP_HEADER_NAME:
1488     case CPP_COMMENT:
1489     case CPP_MACRO_ARG:
1490       abort ();
1491
1492     default: break;
1493     }
1494
1495   return type;
1496   
1497 #else
1498   int c;
1499   char *p;
1500   int wide_flag = 0;
1501   int objc_flag = 0;
1502   int charconst = 0;
1503
1504   *value = NULL_TREE;
1505
1506  retry:
1507   c = getch ();
1508
1509   /* Effectively do c = skip_white_space (c)
1510      but do it faster in the usual cases.  */
1511   while (1)
1512     switch (c)
1513       {
1514       case ' ':
1515       case '\t':
1516       case '\f':
1517       case '\v':
1518         c = getch ();
1519         break;
1520
1521       case '\r':
1522       case '\n':
1523         c = skip_white_space (c);
1524       default:
1525         goto found_nonwhite;
1526       }
1527  found_nonwhite:
1528
1529   lineno = lex_lineno;
1530
1531   switch (c)
1532     {
1533     case EOF:
1534       return CPP_EOF;
1535
1536     case 'L':
1537       /* Capital L may start a wide-string or wide-character constant.  */
1538       {
1539         register int c1 = getch();
1540         if (c1 == '\'')
1541           {
1542             wide_flag = 1;
1543             goto char_constant;
1544           }
1545         if (c1 == '"')
1546           {
1547             wide_flag = 1;
1548             goto string_constant;
1549           }
1550         put_back (c1);
1551       }
1552       goto letter;
1553
1554     case '@':
1555       if (!doing_objc_thang)
1556         goto straychar;
1557       else
1558         {
1559           /* '@' may start a constant string object.  */
1560           register int c1 = getch ();
1561           if (c1 == '"')
1562             {
1563               objc_flag = 1;
1564               goto string_constant;
1565             }
1566           put_back (c1);
1567           /* Fall through to treat '@' as the start of an identifier.  */
1568         }
1569
1570     case 'A':  case 'B':  case 'C':  case 'D':  case 'E':
1571     case 'F':  case 'G':  case 'H':  case 'I':  case 'J':
1572     case 'K':             case 'M':  case 'N':  case 'O':
1573     case 'P':  case 'Q':  case 'R':  case 'S':  case 'T':
1574     case 'U':  case 'V':  case 'W':  case 'X':  case 'Y':
1575     case 'Z':
1576     case 'a':  case 'b':  case 'c':  case 'd':  case 'e':
1577     case 'f':  case 'g':  case 'h':  case 'i':  case 'j':
1578     case 'k':  case 'l':  case 'm':  case 'n':  case 'o':
1579     case 'p':  case 'q':  case 'r':  case 's':  case 't':
1580     case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
1581     case 'z':
1582     case '_':
1583     case '$':
1584     letter:
1585       p = token_buffer;
1586       while (ISALNUM (c) || c == '_' || c == '$' || c == '@')
1587         {
1588           /* Make sure this char really belongs in an identifier.  */
1589           if (c == '$')
1590             {
1591               if (! dollars_in_ident)
1592                 error ("'$' in identifier");
1593               else if (pedantic)
1594                 pedwarn ("'$' in identifier");
1595             }
1596
1597           if (p >= token_buffer + maxtoken)
1598             p = extend_token_buffer (p);
1599
1600           *p++ = c;
1601           c = getch();
1602         }
1603
1604       put_back (c);
1605
1606       if (p >= token_buffer + maxtoken)
1607         p = extend_token_buffer (p);
1608       *p = 0;
1609
1610       *value = get_identifier (token_buffer);
1611       return CPP_NAME;
1612
1613     case '.':
1614         {
1615           /* It's hard to preserve tokenization on '.' because
1616              it could be a symbol by itself, or it could be the
1617              start of a floating point number and cpp won't tell us.  */
1618           int c1 = getch ();
1619           if (c1 == '.')
1620             {
1621               int c2 = getch ();
1622               if (c2 == '.')
1623                 return CPP_ELLIPSIS;
1624
1625               put_back (c2);
1626               error ("parse error at '..'");
1627             }
1628           else if (c1 == '*' && c_language == clk_cplusplus)
1629             return CPP_DOT_STAR;
1630
1631           put_back (c1);
1632           if (ISDIGIT (c1))
1633             goto number;
1634         }
1635         return CPP_DOT;
1636
1637     case '0':  case '1':  case '2':  case '3':  case '4':
1638     case '5':  case '6':  case '7':  case '8':  case '9':
1639     number:
1640       p = token_buffer;
1641       /* Scan the next preprocessing number.  All C numeric constants
1642          are preprocessing numbers, but not all preprocessing numbers
1643          are valid numeric constants.  Preprocessing numbers fit the
1644          regular expression \.?[0-9]([0-9a-zA-Z_.]|[eEpP][+-])*
1645          See C99 section 6.4.8. */
1646       for (;;)
1647         {
1648           if (p >= token_buffer + maxtoken)
1649             p = extend_token_buffer (p);
1650
1651           *p++ = c;
1652           c = getch();
1653
1654           if (c == '+' || c == '-')
1655             {
1656               int d = p[-1];
1657               if (d == 'e' || d == 'E' || d == 'p' || d == 'P')
1658                 continue;
1659             }
1660           if (ISALNUM (c) || c == '_' || c == '.')
1661             continue;
1662           break;
1663         }
1664       put_back (c);
1665
1666       *value = lex_number (token_buffer, p - token_buffer);
1667       return CPP_NUMBER;
1668
1669     case '\'':
1670     char_constant:
1671     charconst = 1;
1672
1673     case '"':
1674     string_constant:
1675       {
1676         int delimiter = charconst ? '\'' : '"';
1677 #ifdef MULTIBYTE_CHARS
1678         int longest_char = local_mb_cur_max ();
1679         (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
1680 #endif
1681         c = getch ();
1682         p = token_buffer + 1;
1683
1684         while (c != delimiter && c != EOF)
1685           {
1686             if (p + 2 > token_buffer + maxtoken)
1687               p = extend_token_buffer (p);
1688
1689             /* ignore_escape_flag is set for reading the filename in #line.  */
1690             if (!ignore_escape_flag && c == '\\')
1691               {
1692                 *p++ = c;
1693                 *p++ = getch ();  /* escaped character */
1694                 c = getch ();
1695                 continue;
1696               }
1697             else
1698               {
1699 #ifdef MULTIBYTE_CHARS
1700                 int i;
1701                 int char_len = -1;
1702                 for (i = 0; i < longest_char; ++i)
1703                   {
1704                     if (p + i >= token_buffer + maxtoken)
1705                       p = extend_token_buffer (p);
1706                     p[i] = c;
1707
1708                     char_len = local_mblen (p, i + 1);
1709                     if (char_len != -1)
1710                       break;
1711                     c = getch ();
1712                   }
1713                 if (char_len == -1)
1714                   {
1715                     /* Replace all except the first byte.  */
1716                     put_back (c);
1717                     for (--i; i > 0; --i)
1718                       put_back (p[i]);
1719                     char_len = 1;
1720                   }
1721                 /* mbtowc sometimes needs an extra char before accepting */
1722                 else if (char_len <= i)
1723                   put_back (c);
1724
1725                 p += char_len;
1726 #else
1727                 *p++ = c;
1728 #endif
1729                 c = getch ();
1730               }
1731           }
1732       }
1733
1734       if (charconst)
1735         {
1736           *value =  lex_charconst (token_buffer + 1, p - (token_buffer + 1),
1737                                    wide_flag);
1738           return wide_flag ? CPP_WCHAR : CPP_CHAR;
1739         }
1740       else
1741         {
1742           *value = lex_string (token_buffer + 1, p - (token_buffer + 1),
1743                                wide_flag);
1744           return wide_flag ? CPP_WSTRING : objc_flag ? CPP_OSTRING : CPP_STRING;
1745         }
1746
1747     case '+':
1748     case '-':
1749     case '&':
1750     case '|':
1751     case ':':
1752     case '<':
1753     case '>':
1754     case '*':
1755     case '/':
1756     case '%':
1757     case '^':
1758     case '!':
1759     case '=':
1760       {
1761         int c1;
1762         enum cpp_ttype type = CPP_EOF;
1763
1764         switch (c)
1765           {
1766           case '+': type = CPP_PLUS;    break;
1767           case '-': type = CPP_MINUS;   break;
1768           case '&': type = CPP_AND;     break;
1769           case '|': type = CPP_OR;      break;
1770           case ':': type = CPP_COLON;   break;
1771           case '<': type = CPP_LESS;    break;
1772           case '>': type = CPP_GREATER; break;
1773           case '*': type = CPP_MULT;    break;
1774           case '/': type = CPP_DIV;     break;
1775           case '%': type = CPP_MOD;     break;
1776           case '^': type = CPP_XOR;     break;
1777           case '!': type = CPP_NOT;     break;
1778           case '=': type = CPP_EQ;      break;
1779           }
1780
1781         c1 = getch ();
1782
1783         if (c1 == '=' && type < CPP_LAST_EQ)
1784           return type + (CPP_EQ_EQ - CPP_EQ);
1785         else if (c == c1)
1786           switch (c)
1787             {
1788             case '+':   return CPP_PLUS_PLUS;
1789             case '-':   return CPP_MINUS_MINUS;
1790             case '&':   return CPP_AND_AND;
1791             case '|':   return CPP_OR_OR;
1792             case ':':
1793               if (c_language == clk_cplusplus)
1794                 return CPP_SCOPE;
1795               break;
1796
1797             case '<':   type = CPP_LSHIFT;      goto do_triad;
1798             case '>':   type = CPP_RSHIFT;      goto do_triad;
1799             }
1800         else
1801           switch (c)
1802             {
1803             case '-':
1804               if (c1 == '>')
1805                 {
1806                   if (c_language == clk_cplusplus)
1807                     {
1808                       c1 = getch ();
1809                       if (c1 == '*')
1810                         return CPP_DEREF_STAR;
1811                       put_back (c1);
1812                     }
1813                   return CPP_DEREF;
1814                 }
1815               break;
1816
1817             case '>':
1818               if (c1 == '?' && c_language == clk_cplusplus)
1819                 { type = CPP_MAX; goto do_triad; }
1820               break;
1821
1822             case '<':
1823               if (c1 == ':' && flag_digraphs)
1824                 return CPP_OPEN_SQUARE;
1825               if (c1 == '%' && flag_digraphs)
1826                 { indent_level++; return CPP_OPEN_BRACE; }
1827               if (c1 == '?' && c_language == clk_cplusplus)
1828                 { type = CPP_MIN; goto do_triad; }
1829               break;
1830
1831             case ':':
1832               if (c1 == '>' && flag_digraphs)
1833                 return CPP_CLOSE_SQUARE;
1834               break;
1835             case '%':
1836               if (c1 == '>' && flag_digraphs)
1837                 { indent_level--; return CPP_CLOSE_BRACE; }
1838               break;
1839             }
1840
1841         put_back (c1);
1842         return type;
1843
1844       do_triad:
1845         c1 = getch ();
1846         if (c1 == '=')
1847           type += (CPP_EQ_EQ - CPP_EQ);
1848         else
1849           put_back (c1);
1850         return type;
1851       }
1852
1853     case '~':                   return CPP_COMPL;
1854     case '?':                   return CPP_QUERY;
1855     case ',':                   return CPP_COMMA;
1856     case '(':                   return CPP_OPEN_PAREN;
1857     case ')':                   return CPP_CLOSE_PAREN;
1858     case '[':                   return CPP_OPEN_SQUARE;
1859     case ']':                   return CPP_CLOSE_SQUARE;
1860     case '{': indent_level++;   return CPP_OPEN_BRACE;
1861     case '}': indent_level--;   return CPP_CLOSE_BRACE;
1862     case ';':                   return CPP_SEMICOLON;
1863
1864     straychar:
1865     default:
1866       if (ISGRAPH (c))
1867         error ("stray '%c' in program", c);
1868       else
1869         error ("stray '\\%#o' in program", c);
1870       goto retry;
1871     }
1872   /* NOTREACHED */
1873 #endif
1874 }
1875
1876
1877 #define ERROR(msgid) do { error(msgid); goto syntax_error; } while(0)
1878
1879 static tree
1880 lex_number (str, len)
1881      const char *str;
1882      unsigned int len;
1883 {
1884   int base = 10;
1885   int count = 0;
1886   int largest_digit = 0;
1887   int numdigits = 0;
1888   int overflow = 0;
1889   int c;
1890   tree value;
1891   const char *p;
1892   enum anon1 { NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON } floatflag = NOT_FLOAT;
1893   
1894   /* We actually store only HOST_BITS_PER_CHAR bits in each part.
1895      The code below which fills the parts array assumes that a host
1896      int is at least twice as wide as a host char, and that 
1897      HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
1898      Two HOST_WIDE_INTs is the largest int literal we can store.
1899      In order to detect overflow below, the number of parts (TOTAL_PARTS)
1900      must be exactly the number of parts needed to hold the bits
1901      of two HOST_WIDE_INTs. */
1902 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
1903   unsigned int parts[TOTAL_PARTS];
1904   
1905   /* Optimize for most frequent case.  */
1906   if (len == 1)
1907     {
1908       if (*str == '0')
1909         return integer_zero_node;
1910       else if (*str == '1')
1911         return integer_one_node;
1912       else
1913         return build_int_2 (*str - '0', 0);
1914     }
1915
1916   for (count = 0; count < TOTAL_PARTS; count++)
1917     parts[count] = 0;
1918
1919   /* len is known to be >1 at this point.  */
1920   p = str;
1921
1922   if (len > 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
1923     {
1924       base = 16;
1925       p = str + 2;
1926     }
1927   /* The ISDIGIT check is so we are not confused by a suffix on 0.  */
1928   else if (str[0] == '0' && ISDIGIT (str[1]))
1929     {
1930       base = 8;
1931       p = str + 1;
1932     }
1933
1934   do
1935     {
1936       c = *p++;
1937
1938       if (c == '.')
1939         {
1940           if (base == 16 && pedantic && !flag_isoc99)
1941             pedwarn ("floating constant may not be in radix 16");
1942           else if (floatflag == AFTER_POINT)
1943             ERROR ("too many decimal points in floating constant");
1944           else if (floatflag == AFTER_EXPON)
1945             ERROR ("decimal point in exponent - impossible!");
1946           else
1947             floatflag = AFTER_POINT;
1948
1949           if (base == 8)
1950             base = 10;
1951         }
1952       else if (c == '_')
1953         /* Possible future extension: silently ignore _ in numbers,
1954            permitting cosmetic grouping - e.g. 0x8000_0000 == 0x80000000
1955            but somewhat easier to read.  Ada has this?  */
1956         ERROR ("underscore in number");
1957       else
1958         {
1959           int n;
1960           /* It is not a decimal point.
1961              It should be a digit (perhaps a hex digit).  */
1962
1963           if (ISDIGIT (c))
1964             {
1965               n = c - '0';
1966             }
1967           else if (base <= 10 && (c == 'e' || c == 'E'))
1968             {
1969               base = 10;
1970               floatflag = AFTER_EXPON;
1971               break;
1972             }
1973           else if (base == 16 && (c == 'p' || c == 'P'))
1974             {
1975               floatflag = AFTER_EXPON;
1976               break;   /* start of exponent */
1977             }
1978           else if (base == 16 && c >= 'a' && c <= 'f')
1979             {
1980               n = c - 'a' + 10;
1981             }
1982           else if (base == 16 && c >= 'A' && c <= 'F')
1983             {
1984               n = c - 'A' + 10;
1985             }
1986           else
1987             {
1988               p--;
1989               break;  /* start of suffix */
1990             }
1991
1992           if (n >= largest_digit)
1993             largest_digit = n;
1994           numdigits++;
1995
1996           for (count = 0; count < TOTAL_PARTS; count++)
1997             {
1998               parts[count] *= base;
1999               if (count)
2000                 {
2001                   parts[count]
2002                     += (parts[count-1] >> HOST_BITS_PER_CHAR);
2003                   parts[count-1]
2004                     &= (1 << HOST_BITS_PER_CHAR) - 1;
2005                 }
2006               else
2007                 parts[0] += n;
2008             }
2009
2010           /* If the highest-order part overflows (gets larger than
2011              a host char will hold) then the whole number has 
2012              overflowed.  Record this and truncate the highest-order
2013              part. */
2014           if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
2015             {
2016               overflow = 1;
2017               parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
2018             }
2019         }
2020     }
2021   while (p < str + len);
2022
2023   /* This can happen on input like `int i = 0x;' */
2024   if (numdigits == 0)
2025     ERROR ("numeric constant with no digits");
2026
2027   if (largest_digit >= base)
2028     ERROR ("numeric constant contains digits beyond the radix");
2029
2030   if (floatflag != NOT_FLOAT)
2031     {
2032       tree type;
2033       int imag, fflag, lflag, conversion_errno;
2034       REAL_VALUE_TYPE real;
2035       struct pf_args args;
2036       char *copy;
2037
2038       if (base == 16 && floatflag != AFTER_EXPON)
2039         ERROR ("hexadecimal floating constant has no exponent");
2040
2041       /* Read explicit exponent if any, and put it in tokenbuf.  */
2042       if ((base == 10 && ((c == 'e') || (c == 'E')))
2043           || (base == 16 && (c == 'p' || c == 'P')))
2044         {
2045           if (p < str + len)
2046             c = *p++;
2047           if (p < str + len && (c == '+' || c == '-'))
2048             c = *p++;
2049           /* Exponent is decimal, even if string is a hex float.  */
2050           if (! ISDIGIT (c))
2051             ERROR ("floating constant exponent has no digits");
2052           while (p < str + len && ISDIGIT (c))
2053             c = *p++;
2054           if (! ISDIGIT (c))
2055             p--;
2056         }
2057
2058       /* Copy the float constant now; we don't want any suffixes in the
2059          string passed to parse_float.  */
2060       copy = alloca (p - str + 1);
2061       memcpy (copy, str, p - str);
2062       copy[p - str] = '\0';
2063
2064       /* Now parse suffixes.  */
2065       fflag = lflag = imag = 0;
2066       while (p < str + len)
2067         switch (*p++)
2068           {
2069           case 'f': case 'F':
2070             if (fflag)
2071               ERROR ("more than one 'f' suffix on floating constant");
2072             else if (warn_traditional && !in_system_header)
2073               warning ("traditional C rejects the 'f' suffix");
2074
2075             fflag = 1;
2076             break;
2077
2078           case 'l': case 'L':
2079             if (lflag)
2080               ERROR ("more than one 'l' suffix on floating constant");
2081             else if (warn_traditional && !in_system_header)
2082               warning ("traditional C rejects the 'l' suffix");
2083
2084             lflag = 1;
2085             break;
2086
2087           case 'i': case 'I':
2088           case 'j': case 'J':
2089             if (imag)
2090               ERROR ("more than one 'i' or 'j' suffix on floating constant");
2091             else if (pedantic)
2092               pedwarn ("ISO C forbids imaginary numeric constants");
2093             imag = 1;
2094             break;
2095
2096           default:
2097             ERROR ("invalid suffix on floating constant");
2098           }
2099
2100       /* Setup input for parse_float() */
2101       args.str = copy;
2102       args.fflag = fflag;
2103       args.lflag = lflag;
2104       args.base = base;
2105
2106       /* Convert string to a double, checking for overflow.  */
2107       if (do_float_handler (parse_float, (PTR) &args))
2108         {
2109           /* Receive output from parse_float() */
2110           real = args.value;
2111         }
2112       else
2113           /* We got an exception from parse_float() */
2114           ERROR ("floating constant out of range");
2115
2116       /* Receive output from parse_float() */
2117       conversion_errno = args.conversion_errno;
2118       type = args.type;
2119             
2120 #ifdef ERANGE
2121       /* ERANGE is also reported for underflow,
2122          so test the value to distinguish overflow from that.  */
2123       if (conversion_errno == ERANGE && !flag_traditional && pedantic
2124           && (REAL_VALUES_LESS (dconst1, real)
2125               || REAL_VALUES_LESS (real, dconstm1)))
2126         warning ("floating point number exceeds range of 'double'");
2127 #endif
2128
2129       /* Create a node with determined type and value.  */
2130       if (imag)
2131         value = build_complex (NULL_TREE, convert (type, integer_zero_node),
2132                                build_real (type, real));
2133       else
2134         value = build_real (type, real);
2135     }
2136   else
2137     {
2138       tree trad_type, ansi_type, type;
2139       HOST_WIDE_INT high, low;
2140       int spec_unsigned = 0;
2141       int spec_long = 0;
2142       int spec_long_long = 0;
2143       int spec_imag = 0;
2144       int suffix_lu = 0;
2145       int warn = 0, i;
2146
2147       trad_type = ansi_type = type = NULL_TREE;
2148       while (p < str + len)
2149         {
2150           c = *p++;
2151           switch (c)
2152             {
2153             case 'u': case 'U':
2154               if (spec_unsigned)
2155                 error ("two 'u' suffixes on integer constant");
2156               else if (warn_traditional && !in_system_header)
2157                 warning ("traditional C rejects the 'u' suffix");
2158
2159               spec_unsigned = 1;
2160               if (spec_long)
2161                 suffix_lu = 1;
2162               break;
2163
2164             case 'l': case 'L':
2165               if (spec_long)
2166                 {
2167                   if (spec_long_long)
2168                     error ("three 'l' suffixes on integer constant");
2169                   else if (suffix_lu)
2170                     error ("'lul' is not a valid integer suffix");
2171                   else if (c != spec_long)
2172                     error ("'Ll' and 'lL' are not valid integer suffixes");
2173                   else if (pedantic && ! flag_isoc99
2174                            && ! in_system_header && warn_long_long)
2175                     pedwarn ("ISO C89 forbids long long integer constants");
2176                   spec_long_long = 1;
2177                 }
2178               spec_long = c;
2179               break;
2180
2181             case 'i': case 'I': case 'j': case 'J':
2182               if (spec_imag)
2183                 error ("more than one 'i' or 'j' suffix on integer constant");
2184               else if (pedantic)
2185                 pedwarn ("ISO C forbids imaginary numeric constants");
2186               spec_imag = 1;
2187               break;
2188
2189             default:
2190               ERROR ("invalid suffix on integer constant");
2191             }
2192         }
2193
2194       /* If the literal overflowed, pedwarn about it now. */
2195       if (overflow)
2196         {
2197           warn = 1;
2198           pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2);
2199         }
2200
2201       /* This is simplified by the fact that our constant
2202          is always positive.  */
2203
2204       high = low = 0;
2205
2206       for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
2207         {
2208           high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
2209                                               / HOST_BITS_PER_CHAR)]
2210                    << (i * HOST_BITS_PER_CHAR));
2211           low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
2212         }
2213
2214       value = build_int_2 (low, high);
2215       TREE_TYPE (value) = long_long_unsigned_type_node;
2216
2217       /* If warn_traditional, calculate both the ISO type and the
2218          traditional type, then see if they disagree.
2219          Otherwise, calculate only the type for the dialect in use.  */
2220       if (warn_traditional || flag_traditional)
2221         {
2222           /* Calculate the traditional type.  */
2223           /* Traditionally, any constant is signed; but if unsigned is
2224              specified explicitly, obey that.  Use the smallest size
2225              with the right number of bits, except for one special
2226              case with decimal constants.  */
2227           if (! spec_long && base != 10
2228               && int_fits_type_p (value, unsigned_type_node))
2229             trad_type = spec_unsigned ? unsigned_type_node : integer_type_node;
2230           /* A decimal constant must be long if it does not fit in
2231              type int.  I think this is independent of whether the
2232              constant is signed.  */
2233           else if (! spec_long && base == 10
2234                    && int_fits_type_p (value, integer_type_node))
2235             trad_type = spec_unsigned ? unsigned_type_node : integer_type_node;
2236           else if (! spec_long_long)
2237             trad_type = (spec_unsigned
2238                          ? long_unsigned_type_node
2239                          : long_integer_type_node);
2240           else if (int_fits_type_p (value,
2241                                     spec_unsigned 
2242                                     ? long_long_unsigned_type_node
2243                                     : long_long_integer_type_node)) 
2244             trad_type = (spec_unsigned
2245                          ? long_long_unsigned_type_node
2246                          : long_long_integer_type_node);
2247           else
2248             trad_type = (spec_unsigned
2249                          ? widest_unsigned_literal_type_node
2250                          : widest_integer_literal_type_node);
2251         }
2252       if (warn_traditional || ! flag_traditional)
2253         {
2254           /* Calculate the ISO type.  */
2255           if (! spec_long && ! spec_unsigned
2256               && int_fits_type_p (value, integer_type_node))
2257             ansi_type = integer_type_node;
2258           else if (! spec_long && (base != 10 || spec_unsigned)
2259                    && int_fits_type_p (value, unsigned_type_node))
2260             ansi_type = unsigned_type_node;
2261           else if (! spec_unsigned && !spec_long_long
2262                    && int_fits_type_p (value, long_integer_type_node))
2263             ansi_type = long_integer_type_node;
2264           else if (! spec_long_long
2265                    && int_fits_type_p (value, long_unsigned_type_node))
2266             ansi_type = long_unsigned_type_node;
2267           else if (! spec_unsigned
2268                    && int_fits_type_p (value, long_long_integer_type_node))
2269             ansi_type = long_long_integer_type_node;
2270           else if (int_fits_type_p (value, long_long_unsigned_type_node))
2271             ansi_type = long_long_unsigned_type_node;
2272           else if (! spec_unsigned
2273                    && int_fits_type_p (value, widest_integer_literal_type_node))
2274             ansi_type = widest_integer_literal_type_node;
2275           else
2276             ansi_type = widest_unsigned_literal_type_node;
2277         }
2278
2279       type = flag_traditional ? trad_type : ansi_type;
2280
2281       /* We assume that constants specified in a non-decimal
2282          base are bit patterns, and that the programmer really
2283          meant what they wrote.  */
2284       if (warn_traditional && !in_system_header
2285           && base == 10 && trad_type != ansi_type)
2286         {
2287           if (TYPE_PRECISION (trad_type) != TYPE_PRECISION (ansi_type))
2288             warning ("width of integer constant changes with -traditional");
2289           else if (TREE_UNSIGNED (trad_type) != TREE_UNSIGNED (ansi_type))
2290             warning ("integer constant is unsigned in ISO C, signed with -traditional");
2291           else
2292             warning ("width of integer constant may change on other systems with -traditional");
2293         }
2294
2295       if (pedantic && !flag_traditional && (flag_isoc99 || !spec_long_long)
2296           && !warn
2297           && ((flag_isoc99
2298                ? TYPE_PRECISION (long_long_integer_type_node)
2299                : TYPE_PRECISION (long_integer_type_node)) < TYPE_PRECISION (type)))
2300         {
2301           warn = 1;
2302           pedwarn ("integer constant larger than the maximum value of %s",
2303                    (flag_isoc99
2304                     ? (TREE_UNSIGNED (type)
2305                        ? "an unsigned long long int"
2306                        : "a long long int")
2307                     : "an unsigned long int"));
2308         }
2309
2310       if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
2311         warning ("decimal constant is so large that it is unsigned");
2312
2313       if (spec_imag)
2314         {
2315           if (TYPE_PRECISION (type)
2316               <= TYPE_PRECISION (integer_type_node))
2317             value = build_complex (NULL_TREE, integer_zero_node,
2318                                    convert (integer_type_node, value));
2319           else
2320             ERROR ("complex integer constant is too wide for 'complex int'");
2321         }
2322       else if (flag_traditional && !int_fits_type_p (value, type))
2323         /* The traditional constant 0x80000000 is signed
2324            but doesn't fit in the range of int.
2325            This will change it to -0x80000000, which does fit.  */
2326         {
2327           TREE_TYPE (value) = unsigned_type (type);
2328           value = convert (type, value);
2329           TREE_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (value) = 0;
2330         }
2331       else
2332         TREE_TYPE (value) = type;
2333
2334       /* If it's still an integer (not a complex), and it doesn't
2335          fit in the type we choose for it, then pedwarn. */
2336
2337       if (! warn
2338           && TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
2339           && ! int_fits_type_p (value, TREE_TYPE (value)))
2340         pedwarn ("integer constant is larger than the maximum value for its type");
2341     }
2342
2343   if (p < str + len)
2344     error ("missing white space after number '%.*s'", (int) (p - str), str);
2345
2346   return value;
2347
2348  syntax_error:
2349   return integer_zero_node;
2350 }
2351
2352 static tree
2353 lex_string (str, len, wide)
2354      const char *str;
2355      unsigned int len;
2356      int wide;
2357 {
2358   tree value;
2359   char *buf = alloca ((len + 1) * (wide ? WCHAR_BYTES : 1));
2360   char *q = buf;
2361   const char *p = str, *limit = str + len;
2362   unsigned int c;
2363   unsigned width = wide ? WCHAR_TYPE_SIZE
2364                         : TYPE_PRECISION (char_type_node);
2365
2366 #ifdef MULTIBYTE_CHARS
2367   /* Reset multibyte conversion state.  */
2368   (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
2369 #endif
2370
2371   while (p < limit)
2372     {
2373 #ifdef MULTIBYTE_CHARS
2374       wchar_t wc;
2375       int char_len;
2376
2377       char_len = local_mbtowc (&wc, p, limit - p);
2378       if (char_len == -1)
2379         {
2380           warning ("Ignoring invalid multibyte character");
2381           char_len = 1;
2382           c = *p++;
2383         }
2384       else
2385         {
2386           p += char_len;
2387           c = wc;
2388         }
2389 #else
2390       c = *p++;
2391 #endif
2392
2393       if (c == '\\' && !ignore_escape_flag)
2394         {
2395           p = readescape (p, limit, &c);
2396           if (width < HOST_BITS_PER_INT
2397               && (unsigned) c >= ((unsigned)1 << width))
2398             pedwarn ("escape sequence out of range for character");
2399         }
2400         
2401       /* Add this single character into the buffer either as a wchar_t
2402          or as a single byte.  */
2403       if (wide)
2404         {
2405           unsigned charwidth = TYPE_PRECISION (char_type_node);
2406           unsigned bytemask = (1 << charwidth) - 1;
2407           int byte;
2408
2409           for (byte = 0; byte < WCHAR_BYTES; ++byte)
2410             {
2411               int n;
2412               if (byte >= (int) sizeof (c))
2413                 n = 0;
2414               else
2415                 n = (c >> (byte * charwidth)) & bytemask;
2416               if (BYTES_BIG_ENDIAN)
2417                 q[WCHAR_BYTES - byte - 1] = n;
2418               else
2419                 q[byte] = n;
2420             }
2421           q += WCHAR_BYTES;
2422         }
2423       else
2424         {
2425           *q++ = c;
2426         }
2427     }
2428
2429   /* Terminate the string value, either with a single byte zero
2430      or with a wide zero.  */
2431
2432   if (wide)
2433     {
2434       memset (q, 0, WCHAR_BYTES);
2435       q += WCHAR_BYTES;
2436     }
2437   else
2438     {
2439       *q++ = '\0';
2440     }
2441
2442   value = build_string (q - buf, buf);
2443
2444   if (wide)
2445     TREE_TYPE (value) = wchar_array_type_node;
2446   else
2447     TREE_TYPE (value) = char_array_type_node;
2448   return value;
2449 }
2450
2451 static tree
2452 lex_charconst (str, len, wide)
2453      const char *str;
2454      unsigned int len;
2455      int wide;
2456 {
2457   const char *limit = str + len;
2458   int result = 0;
2459   int num_chars = 0;
2460   int chars_seen = 0;
2461   unsigned width = TYPE_PRECISION (char_type_node);
2462   int max_chars;
2463   unsigned int c;
2464   tree value;
2465
2466 #ifdef MULTIBYTE_CHARS
2467   int longest_char = local_mb_cur_max ();
2468   (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
2469 #endif
2470
2471   max_chars = TYPE_PRECISION (integer_type_node) / width;
2472   if (wide)
2473     width = WCHAR_TYPE_SIZE;
2474
2475   while (str < limit)
2476     {
2477 #ifdef MULTIBYTE_CHARS
2478       wchar_t wc;
2479       int char_len;
2480
2481       char_len = local_mbtowc (&wc, str, limit - str);
2482       if (char_len == -1)
2483         {
2484           warning ("Ignoring invalid multibyte character");
2485           char_len = 1;
2486           c = *str++;
2487         }
2488       else
2489         {
2490           p += char_len;
2491           c = wc;
2492         }
2493 #else
2494       c = *str++;
2495 #endif
2496
2497       ++chars_seen;
2498       if (c == '\\')
2499         {
2500           str = readescape (str, limit, &c);
2501           if (width < HOST_BITS_PER_INT
2502               && (unsigned) c >= ((unsigned)1 << width))
2503             pedwarn ("escape sequence out of range for character");
2504         }
2505 #ifdef MAP_CHARACTER
2506       if (ISPRINT (c))
2507         c = MAP_CHARACTER (c);
2508 #endif
2509       
2510       /* Merge character into result; ignore excess chars.  */
2511       num_chars += (width / TYPE_PRECISION (char_type_node));
2512       if (num_chars < max_chars + 1)
2513         {
2514           if (width < HOST_BITS_PER_INT)
2515             result = (result << width) | (c & ((1 << width) - 1));
2516           else
2517             result = c;
2518         }
2519     }
2520
2521   if (chars_seen == 0)
2522     error ("empty character constant");
2523   else if (num_chars > max_chars)
2524     {
2525       num_chars = max_chars;
2526       error ("character constant too long");
2527     }
2528   else if (chars_seen != 1 && ! flag_traditional && warn_multichar)
2529     warning ("multi-character character constant");
2530
2531   /* If char type is signed, sign-extend the constant.  */
2532   if (! wide)
2533     {
2534       int num_bits = num_chars * width;
2535       if (num_bits == 0)
2536         /* We already got an error; avoid invalid shift.  */
2537         value = build_int_2 (0, 0);
2538       else if (TREE_UNSIGNED (char_type_node)
2539                || ((result >> (num_bits - 1)) & 1) == 0)
2540         value = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
2541                                        >> (HOST_BITS_PER_WIDE_INT - num_bits)),
2542                              0);
2543       else
2544         value = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
2545                                         >> (HOST_BITS_PER_WIDE_INT - num_bits)),
2546                              -1);
2547       /* In C, a character constant has type 'int'; in C++, 'char'.  */
2548       if (chars_seen <= 1 && c_language == clk_cplusplus)
2549         TREE_TYPE (value) = char_type_node;
2550       else
2551         TREE_TYPE (value) = integer_type_node;
2552     }
2553   else
2554     {
2555       value = build_int_2 (result, 0);
2556       TREE_TYPE (value) = wchar_type_node;
2557     }
2558
2559   return value;
2560 }