* flow.c (mark_used_regs): Revert last change.
[official-gcc.git] / gcc / c-lex.c
blobbeda889d5896991c46458950a98b545a0fefac47
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.
5 This file is part of GNU CC.
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.
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.
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. */
22 #include "config.h"
23 #include "system.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "input.h"
28 #include "output.h"
29 #include "c-lex.h"
30 #include "c-tree.h"
31 #include "flags.h"
32 #include "c-parse.h"
33 #include "c-pragma.h"
34 #include "toplev.h"
35 #include "intl.h"
36 #include "ggc.h"
37 #include "tm_p.h"
39 /* MULTIBYTE_CHARS support only works for native compilers.
40 ??? Ideally what we want is to model widechar support after
41 the current floating point support. */
42 #ifdef CROSS_COMPILE
43 #undef MULTIBYTE_CHARS
44 #endif
46 #ifdef MULTIBYTE_CHARS
47 #include "mbchar.h"
48 #include <locale.h>
49 #endif /* MULTIBYTE_CHARS */
50 #ifndef GET_ENVIRONMENT
51 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME))
52 #endif
54 #if USE_CPPLIB
55 #include "cpplib.h"
56 extern cpp_reader parse_in;
57 extern cpp_options parse_options;
58 #else
59 /* Stream for reading from the input file. */
60 FILE *finput;
61 #endif
63 extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
65 /* The elements of `ridpointers' are identifier nodes
66 for the reserved type names and storage classes.
67 It is indexed by a RID_... value. */
68 tree ridpointers[(int) RID_MAX];
70 /* Cause the `yydebug' variable to be defined. */
71 #define YYDEBUG 1
73 #if USE_CPPLIB
74 extern unsigned char *yy_cur, *yy_lim;
75 extern enum cpp_token cpp_token;
77 extern int yy_get_token ();
79 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
80 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
82 #else /* ! USE_CPPLIB */
84 #define GETC() getch ()
85 #define UNGETC(c) put_back (c)
87 struct putback_buffer {
88 unsigned char *buffer;
89 int buffer_size;
90 int index;
93 static struct putback_buffer putback = {NULL, 0, -1};
95 static inline int getch PARAMS ((void));
97 static inline int
98 getch ()
100 if (putback.index != -1)
102 int ch = putback.buffer[putback.index];
103 --putback.index;
104 return ch;
106 return getc (finput);
109 static inline void put_back PARAMS ((int));
111 static inline void
112 put_back (ch)
113 int ch;
115 if (ch != EOF)
117 if (putback.index == putback.buffer_size - 1)
119 putback.buffer_size += 16;
120 putback.buffer = xrealloc (putback.buffer, putback.buffer_size);
122 putback.buffer[++putback.index] = ch;
125 #endif /* ! USE_CPPLIB */
127 int linemode;
129 /* the declaration found for the last IDENTIFIER token read in.
130 yylex must look this up to detect typedefs, which get token type TYPENAME,
131 so it is left around in case the identifier is not a typedef but is
132 used in a context which makes it a reference to a variable. */
133 tree lastiddecl;
135 extern int yydebug;
137 /* File used for outputting assembler code. */
138 extern FILE *asm_out_file;
140 #undef WCHAR_TYPE_SIZE
141 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
143 /* Number of bytes in a wide character. */
144 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
146 static int maxtoken; /* Current nominal length of token buffer. */
147 char *token_buffer; /* Pointer to token buffer.
148 Actual allocated length is maxtoken + 2.
149 This is not static because objc-parse.y uses it. */
151 static int indent_level; /* Number of { minus number of }. */
153 /* Nonzero tells yylex to ignore \ in string constants. */
154 static int ignore_escape_flag;
156 /* Nonzero if end-of-file has been seen on input. */
157 static int end_of_file;
159 #ifdef HANDLE_GENERIC_PRAGMAS
160 static int handle_generic_pragma PARAMS ((int));
161 #endif /* HANDLE_GENERIC_PRAGMAS */
162 static int whitespace_cr PARAMS ((int));
163 static int skip_white_space PARAMS ((int));
164 static char *extend_token_buffer PARAMS ((const char *));
165 static int readescape PARAMS ((int *));
166 static void parse_float PARAMS ((PTR));
167 static void extend_token_buffer_to PARAMS ((int));
168 static int read_line_number PARAMS ((int *));
170 /* Do not insert generated code into the source, instead, include it.
171 This allows us to build gcc automatically even for targets that
172 need to add or modify the reserved keyword lists. */
173 #include "c-gperf.h"
175 /* Return something to represent absolute declarators containing a *.
176 TARGET is the absolute declarator that the * contains.
177 TYPE_QUALS is a list of modifiers such as const or volatile
178 to apply to the pointer type, represented as identifiers.
180 We return an INDIRECT_REF whose "contents" are TARGET
181 and whose type is the modifier list. */
183 tree
184 make_pointer_declarator (type_quals, target)
185 tree type_quals, target;
187 return build1 (INDIRECT_REF, type_quals, target);
190 void
191 forget_protocol_qualifiers ()
193 int i, n = sizeof wordlist / sizeof (struct resword);
195 for (i = 0; i < n; i++)
196 if ((int) wordlist[i].rid >= (int) RID_IN
197 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
198 wordlist[i].name = "";
201 void
202 remember_protocol_qualifiers ()
204 int i, n = sizeof wordlist / sizeof (struct resword);
206 for (i = 0; i < n; i++)
207 if (wordlist[i].rid == RID_IN)
208 wordlist[i].name = "in";
209 else if (wordlist[i].rid == RID_OUT)
210 wordlist[i].name = "out";
211 else if (wordlist[i].rid == RID_INOUT)
212 wordlist[i].name = "inout";
213 else if (wordlist[i].rid == RID_BYCOPY)
214 wordlist[i].name = "bycopy";
215 else if (wordlist[i].rid == RID_BYREF)
216 wordlist[i].name = "byref";
217 else if (wordlist[i].rid == RID_ONEWAY)
218 wordlist[i].name = "oneway";
221 const char *
222 init_parse (filename)
223 const char *filename;
225 #if !USE_CPPLIB
226 /* Open input file. */
227 if (filename == 0 || !strcmp (filename, "-"))
229 finput = stdin;
230 filename = "stdin";
232 else
233 finput = fopen (filename, "r");
234 if (finput == 0)
235 pfatal_with_name (filename);
237 #ifdef IO_BUFFER_SIZE
238 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
239 #endif
240 #else /* !USE_CPPLIB */
241 parse_in.show_column = 1;
242 if (! cpp_start_read (&parse_in, filename))
243 abort ();
245 if (filename == 0 || !strcmp (filename, "-"))
246 filename = "stdin";
248 /* cpp_start_read always puts at least one line directive into the
249 token buffer. We must arrange to read it out here. */
250 yy_cur = parse_in.token_buffer;
251 yy_lim = CPP_PWRITTEN (&parse_in);
252 cpp_token = CPP_DIRECTIVE;
253 #endif
255 init_lex ();
256 init_pragma ();
258 return filename;
261 void
262 finish_parse ()
264 #if USE_CPPLIB
265 cpp_finish (&parse_in);
266 errorcount += parse_in.errors;
267 #else
268 fclose (finput);
269 #endif
272 void
273 init_lex ()
275 /* Make identifier nodes long enough for the language-specific slots. */
276 set_identifier_size (sizeof (struct lang_identifier));
278 /* Start it at 0, because check_newline is called at the very beginning
279 and will increment it to 1. */
280 lineno = 0;
282 #ifdef MULTIBYTE_CHARS
283 /* Change to the native locale for multibyte conversions. */
284 setlocale (LC_CTYPE, "");
285 GET_ENVIRONMENT (literal_codeset, "LANG");
286 #endif
288 maxtoken = 40;
289 token_buffer = (char *) xmalloc (maxtoken + 2);
291 ridpointers[(int) RID_INT] = get_identifier ("int");
292 ridpointers[(int) RID_CHAR] = get_identifier ("char");
293 ridpointers[(int) RID_VOID] = get_identifier ("void");
294 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
295 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
296 ridpointers[(int) RID_SHORT] = get_identifier ("short");
297 ridpointers[(int) RID_LONG] = get_identifier ("long");
298 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
299 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
300 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
301 ridpointers[(int) RID_CONST] = get_identifier ("const");
302 ridpointers[(int) RID_RESTRICT] = get_identifier ("restrict");
303 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
304 ridpointers[(int) RID_BOUNDED] = get_identifier ("__bounded");
305 ridpointers[(int) RID_UNBOUNDED] = get_identifier ("__unbounded");
306 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
307 ridpointers[(int) RID_STATIC] = get_identifier ("static");
308 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
309 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
310 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
311 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
312 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
313 ridpointers[(int) RID_ID] = get_identifier ("id");
314 ridpointers[(int) RID_IN] = get_identifier ("in");
315 ridpointers[(int) RID_OUT] = get_identifier ("out");
316 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
317 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
318 ridpointers[(int) RID_BYREF] = get_identifier ("byref");
319 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
320 forget_protocol_qualifiers();
322 /* Some options inhibit certain reserved words.
323 Clear those words out of the hash table so they won't be recognized. */
324 #define UNSET_RESERVED_WORD(STRING) \
325 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
326 if (s) s->name = ""; } while (0)
328 if (! doing_objc_thang)
329 UNSET_RESERVED_WORD ("id");
331 if (flag_traditional)
333 UNSET_RESERVED_WORD ("const");
334 UNSET_RESERVED_WORD ("restrict");
335 UNSET_RESERVED_WORD ("volatile");
336 UNSET_RESERVED_WORD ("typeof");
337 UNSET_RESERVED_WORD ("signed");
338 UNSET_RESERVED_WORD ("inline");
339 UNSET_RESERVED_WORD ("iterator");
340 UNSET_RESERVED_WORD ("complex");
342 else if (!flag_isoc99)
343 UNSET_RESERVED_WORD ("restrict");
345 if (flag_no_asm)
347 UNSET_RESERVED_WORD ("asm");
348 UNSET_RESERVED_WORD ("typeof");
349 UNSET_RESERVED_WORD ("inline");
350 UNSET_RESERVED_WORD ("iterator");
351 UNSET_RESERVED_WORD ("complex");
355 void
356 reinit_parse_for_function ()
360 /* Function used when yydebug is set, to print a token in more detail. */
362 void
363 yyprint (file, yychar, yylval)
364 FILE *file;
365 int yychar;
366 YYSTYPE yylval;
368 tree t;
369 switch (yychar)
371 case IDENTIFIER:
372 case TYPENAME:
373 case OBJECTNAME:
374 t = yylval.ttype;
375 if (IDENTIFIER_POINTER (t))
376 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
377 break;
379 case CONSTANT:
380 t = yylval.ttype;
381 if (TREE_CODE (t) == INTEGER_CST)
382 fprintf (file,
383 #if HOST_BITS_PER_WIDE_INT == 64
384 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
385 " 0x%x%016x",
386 #else
387 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
388 " 0x%lx%016lx",
389 #else
390 " 0x%llx%016llx",
391 #endif
392 #endif
393 #else
394 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
395 " 0x%lx%08lx",
396 #else
397 " 0x%x%08x",
398 #endif
399 #endif
400 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
401 break;
405 /* Iff C is a carriage return, warn about it - if appropriate -
406 and return nonzero. */
408 static int
409 whitespace_cr (c)
410 int c;
412 static int newline_warning = 0;
414 if (c == '\r')
416 /* ANSI C says the effects of a carriage return in a source file
417 are undefined. */
418 if (pedantic && !newline_warning)
420 warning ("carriage return in source file");
421 warning ("(we only warn about the first carriage return)");
422 newline_warning = 1;
424 return 1;
426 return 0;
429 /* If C is not whitespace, return C.
430 Otherwise skip whitespace and return first nonwhite char read. */
432 static int
433 skip_white_space (c)
434 register int c;
436 for (;;)
438 switch (c)
440 /* We don't recognize comments here, because
441 cpp output can include / and * consecutively as operators.
442 Also, there's no need, since cpp removes all comments. */
444 case '\n':
445 if (linemode)
447 UNGETC (c);
448 return EOF;
450 c = check_newline ();
451 break;
453 case ' ':
454 case '\t':
455 case '\f':
456 case '\v':
457 case '\b':
458 #if USE_CPPLIB
459 /* While processing a # directive we don't get CPP_HSPACE
460 tokens, so we also need to handle whitespace the normal way. */
461 if (cpp_token == CPP_HSPACE)
462 c = yy_get_token ();
463 else
464 #endif
465 c = GETC();
466 break;
468 case '\r':
469 whitespace_cr (c);
470 c = GETC();
471 break;
473 case '\\':
474 c = GETC();
475 if (c == '\n')
476 lineno++;
477 else
478 error ("stray '\\' in program");
479 c = GETC();
480 break;
482 default:
483 return (c);
488 /* Skips all of the white space at the current location in the input file. */
490 void
491 position_after_white_space ()
493 register int c;
495 c = GETC();
497 UNGETC (skip_white_space (c));
500 /* Make the token buffer longer, preserving the data in it.
501 P should point to just beyond the last valid character in the old buffer.
502 The value we return is a pointer to the new buffer
503 at a place corresponding to P. */
505 static void
506 extend_token_buffer_to (size)
507 int size;
510 maxtoken = maxtoken * 2 + 10;
511 while (maxtoken < size);
512 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
515 static char *
516 extend_token_buffer (p)
517 const char *p;
519 int offset = p - token_buffer;
520 extend_token_buffer_to (offset);
521 return token_buffer + offset;
524 #if defined HANDLE_PRAGMA
525 /* Local versions of these macros, that can be passed as function pointers. */
526 static int
527 pragma_getc ()
529 return GETC ();
532 static void
533 pragma_ungetc (arg)
534 int arg;
536 UNGETC (arg);
538 #endif
540 static int
541 read_line_number (num)
542 int *num;
544 register int token = yylex ();
546 if (token == CONSTANT
547 && TREE_CODE (yylval.ttype) == INTEGER_CST)
549 *num = TREE_INT_CST_LOW (yylval.ttype);
550 return 1;
552 else
554 if (token != END_OF_LINE)
555 error ("invalid #-line");
556 return 0;
560 /* At the beginning of a line, increment the line number
561 and process any #-directive on this line.
562 If the line is a #-directive, read the entire line and return a newline.
563 Otherwise, return the line's first non-whitespace character.
565 Note that in the case of USE_CPPLIB, we get the whole line as one
566 CPP_DIRECTIVE token. */
569 check_newline ()
571 register int c;
572 register int token;
573 int saw_line;
574 enum { act_none, act_push, act_pop } action;
575 int old_lineno, action_number, l;
577 restart:
578 /* Read first nonwhite char on the line. */
580 #ifdef USE_CPPLIB
581 c = GETC ();
582 /* In some cases where we're leaving an include file, we can get multiple
583 CPP_HSPACE tokens in a row, so we need to loop. */
584 while (cpp_token == CPP_HSPACE)
585 c = yy_get_token ();
586 #else
588 c = GETC ();
589 while (c == ' ' || c == '\t');
590 #endif
592 lineno++;
594 if (c != '#')
596 /* Sequences of multiple newlines are very common; optimize them. */
597 if (c == '\n')
598 goto restart;
600 /* If not #, return it so caller will use it. */
601 return c;
604 /* Don't read beyond this line. */
605 saw_line = 0;
606 linemode = 1;
608 #if USE_CPPLIB
609 if (cpp_token == CPP_VSPACE)
611 /* Format is "<space> <line number> <filename> <newline>".
612 Only the line number is interesting, and even that
613 we can get more efficiently than scanning the line. */
614 yy_cur = yy_lim - 1;
615 lineno = parse_in.lineno - 1;
616 goto skipline;
618 #endif
620 token = yylex ();
622 if (token == IDENTIFIER)
624 /* If a letter follows, then if the word here is `line', skip
625 it and ignore it; otherwise, ignore the line, with an error
626 if the word isn't `pragma'. */
628 const char *name = IDENTIFIER_POINTER (yylval.ttype);
630 if (!strcmp (name, "pragma"))
632 token = yylex ();
633 if (token != IDENTIFIER
634 || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
635 goto skipline;
637 #ifdef HANDLE_PRAGMA
638 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
639 (if both are defined), in order to give the back
640 end a chance to override the interpretation of
641 SYSV style pragmas. */
642 if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
643 IDENTIFIER_POINTER (yylval.ttype)))
644 goto skipline;
645 #endif /* HANDLE_PRAGMA */
647 #ifdef HANDLE_GENERIC_PRAGMAS
648 if (handle_generic_pragma (token))
649 goto skipline;
650 #endif /* HANDLE_GENERIC_PRAGMAS */
652 /* Issue a warning message if we have been asked to do so.
653 Ignoring unknown pragmas in system header file unless
654 an explcit -Wunknown-pragmas has been given. */
655 if (warn_unknown_pragmas > 1
656 || (warn_unknown_pragmas && ! in_system_header))
657 warning ("ignoring pragma: %s", token_buffer);
659 goto skipline;
661 else if (!strcmp (name, "define"))
663 debug_define (lineno, GET_DIRECTIVE_LINE ());
664 goto skipline;
666 else if (!strcmp (name, "undef"))
668 debug_undef (lineno, GET_DIRECTIVE_LINE ());
669 goto skipline;
671 else if (!strcmp (name, "line"))
673 saw_line = 1;
674 token = yylex ();
675 goto linenum;
677 else if (!strcmp (name, "ident"))
679 /* #ident. The pedantic warning is now in cpp. */
681 /* Here we have just seen `#ident '.
682 A string constant should follow. */
684 token = yylex ();
685 if (token == END_OF_LINE)
686 goto skipline;
687 if (token != STRING
688 || TREE_CODE (yylval.ttype) != STRING_CST)
690 error ("invalid #ident");
691 goto skipline;
694 if (! flag_no_ident)
696 #ifdef ASM_OUTPUT_IDENT
697 ASM_OUTPUT_IDENT (asm_out_file,
698 TREE_STRING_POINTER (yylval.ttype));
699 #endif
702 /* Skip the rest of this line. */
703 goto skipline;
706 error ("undefined or invalid # directive `%s'", name);
707 goto skipline;
710 /* If the # is the only nonwhite char on the line,
711 just ignore it. Check the new newline. */
712 if (token == END_OF_LINE)
713 goto skipline;
715 linenum:
716 /* Here we have either `#line' or `# <nonletter>'.
717 In either case, it should be a line number; a digit should follow. */
719 if (token != CONSTANT
720 || TREE_CODE (yylval.ttype) != INTEGER_CST)
722 error ("invalid #-line");
723 goto skipline;
726 /* subtract one, because it is the following line that
727 gets the specified number */
729 l = TREE_INT_CST_LOW (yylval.ttype) - 1;
731 /* More follows: it must be a string constant (filename).
732 It would be neat to use cpplib to quickly process the string, but
733 (1) we don't have a handy tokenization of the string, and
734 (2) I don't know how well that would work in the presense
735 of filenames that contain wide characters. */
737 if (saw_line)
739 /* Don't treat \ as special if we are processing #line 1 "...".
740 If you want it to be treated specially, use # 1 "...". */
741 ignore_escape_flag = 1;
744 /* Read the string constant. */
745 token = yylex ();
747 ignore_escape_flag = 0;
749 if (token == END_OF_LINE)
751 /* No more: store the line number and check following line. */
752 lineno = l;
753 goto skipline;
756 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
758 error ("invalid #line");
759 goto skipline;
762 input_filename = TREE_STRING_POINTER (yylval.ttype);
764 if (main_input_filename == 0)
765 main_input_filename = input_filename;
767 old_lineno = lineno;
768 action = act_none;
769 action_number = 0;
770 lineno = l;
772 /* Each change of file name
773 reinitializes whether we are now in a system header. */
774 in_system_header = 0;
776 if (!read_line_number (&action_number))
778 /* Update the name in the top element of input_file_stack. */
779 if (input_file_stack)
780 input_file_stack->name = input_filename;
783 /* `1' after file name means entering new file.
784 `2' after file name means just left a file. */
786 if (action_number == 1)
788 action = act_push;
789 read_line_number (&action_number);
791 else if (action_number == 2)
793 action = act_pop;
794 read_line_number (&action_number);
796 if (action_number == 3)
798 /* `3' after file name means this is a system header file. */
799 in_system_header = 1;
800 read_line_number (&action_number);
803 /* Do the actions implied by the preceding numbers. */
805 if (action == act_push)
807 /* Pushing to a new file. */
808 struct file_stack *p
809 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
810 input_file_stack->line = old_lineno;
811 p->next = input_file_stack;
812 p->name = input_filename;
813 p->indent_level = indent_level;
814 input_file_stack = p;
815 input_file_stack_tick++;
816 debug_start_source_file (input_filename);
818 else if (action == act_pop)
820 /* Popping out of a file. */
821 if (input_file_stack->next)
823 struct file_stack *p = input_file_stack;
824 if (indent_level != p->indent_level)
826 warning_with_file_and_line
827 (p->name, old_lineno,
828 "This file contains more `%c's than `%c's.",
829 indent_level > p->indent_level ? '{' : '}',
830 indent_level > p->indent_level ? '}' : '{');
832 input_file_stack = p->next;
833 free (p);
834 input_file_stack_tick++;
835 debug_end_source_file (input_file_stack->line);
837 else
838 error ("#-lines for entering and leaving files don't match");
841 /* Now that we've pushed or popped the input stack,
842 update the name in the top element. */
843 if (input_file_stack)
844 input_file_stack->name = input_filename;
846 /* skip the rest of this line. */
847 skipline:
848 linemode = 0;
849 end_of_file = 0;
852 c = GETC();
853 while (c != '\n' && c != EOF);
854 return c;
857 #ifdef HANDLE_GENERIC_PRAGMAS
859 /* Handle a #pragma directive.
860 TOKEN is the token we read after `#pragma'. Processes the entire input
861 line and return non-zero iff the pragma has been successfully parsed. */
863 /* This function has to be in this file, in order to get at
864 the token types. */
866 static int
867 handle_generic_pragma (token)
868 register int token;
870 for (;;)
872 switch (token)
874 case IDENTIFIER:
875 case TYPENAME:
876 case STRING:
877 case CONSTANT:
878 handle_pragma_token (token_buffer, yylval.ttype);
879 break;
881 case END_OF_LINE:
882 return handle_pragma_token (NULL_PTR, NULL_TREE);
884 default:
885 handle_pragma_token (token_buffer, NULL);
888 token = yylex ();
892 #endif /* HANDLE_GENERIC_PRAGMAS */
894 #define ENDFILE -1 /* token that represents end-of-file */
896 /* Read an escape sequence, returning its equivalent as a character,
897 or store 1 in *ignore_ptr if it is backslash-newline. */
899 static int
900 readescape (ignore_ptr)
901 int *ignore_ptr;
903 register int c = GETC();
904 register int code;
905 register unsigned count;
906 unsigned firstdig = 0;
907 int nonnull;
909 switch (c)
911 case 'x':
912 if (warn_traditional)
913 warning ("the meaning of `\\x' varies with -traditional");
915 if (flag_traditional)
916 return c;
918 code = 0;
919 count = 0;
920 nonnull = 0;
921 while (1)
923 c = GETC();
924 if (! ISXDIGIT (c))
926 UNGETC (c);
927 break;
929 code *= 16;
930 if (c >= 'a' && c <= 'f')
931 code += c - 'a' + 10;
932 if (c >= 'A' && c <= 'F')
933 code += c - 'A' + 10;
934 if (c >= '0' && c <= '9')
935 code += c - '0';
936 if (code != 0 || count != 0)
938 if (count == 0)
939 firstdig = code;
940 count++;
942 nonnull = 1;
944 if (! nonnull)
946 warning ("\\x used with no following hex digits");
947 return 'x';
949 else if (count == 0)
950 /* Digits are all 0's. Ok. */
952 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
953 || (count > 1
954 && (((unsigned)1
955 << (TYPE_PRECISION (integer_type_node)
956 - (count - 1) * 4))
957 <= firstdig)))
958 pedwarn ("hex escape out of range");
959 return code;
961 case '0': case '1': case '2': case '3': case '4':
962 case '5': case '6': case '7':
963 code = 0;
964 count = 0;
965 while ((c <= '7') && (c >= '0') && (count++ < 3))
967 code = (code * 8) + (c - '0');
968 c = GETC();
970 UNGETC (c);
971 return code;
973 case '\\': case '\'': case '"':
974 return c;
976 case '\n':
977 lineno++;
978 *ignore_ptr = 1;
979 return 0;
981 case 'n':
982 return TARGET_NEWLINE;
984 case 't':
985 return TARGET_TAB;
987 case 'r':
988 return TARGET_CR;
990 case 'f':
991 return TARGET_FF;
993 case 'b':
994 return TARGET_BS;
996 case 'a':
997 if (warn_traditional)
998 warning ("the meaning of `\\a' varies with -traditional");
1000 if (flag_traditional)
1001 return c;
1002 return TARGET_BELL;
1004 case 'v':
1005 #if 0 /* Vertical tab is present in common usage compilers. */
1006 if (flag_traditional)
1007 return c;
1008 #endif
1009 return TARGET_VT;
1011 case 'e':
1012 case 'E':
1013 if (pedantic)
1014 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1015 return TARGET_ESC;
1017 case '?':
1018 return c;
1020 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1021 case '(':
1022 case '{':
1023 case '[':
1024 /* `\%' is used to prevent SCCS from getting confused. */
1025 case '%':
1026 if (pedantic)
1027 pedwarn ("unknown escape sequence `\\%c'", c);
1028 return c;
1030 if (ISGRAPH (c))
1031 pedwarn ("unknown escape sequence `\\%c'", c);
1032 else
1033 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1034 return c;
1037 void
1038 yyerror (msgid)
1039 const char *msgid;
1041 const char *string = _(msgid);
1043 /* We can't print string and character constants well
1044 because the token_buffer contains the result of processing escapes. */
1045 if (end_of_file)
1046 error ("%s at end of input", string);
1047 else if (token_buffer[0] == 0)
1048 error ("%s at null character", string);
1049 else if (token_buffer[0] == '"')
1050 error ("%s before string constant", string);
1051 else if (token_buffer[0] == '\'')
1052 error ("%s before character constant", string);
1053 else if (!ISGRAPH(token_buffer[0]))
1054 error ("%s before character 0%o", string, (unsigned char) token_buffer[0]);
1055 else
1056 error ("%s before `%s'", string, token_buffer);
1059 #if 0
1061 struct try_type
1063 tree *node_var;
1064 char unsigned_flag;
1065 char long_flag;
1066 char long_long_flag;
1069 struct try_type type_sequence[] =
1071 { &integer_type_node, 0, 0, 0},
1072 { &unsigned_type_node, 1, 0, 0},
1073 { &long_integer_type_node, 0, 1, 0},
1074 { &long_unsigned_type_node, 1, 1, 0},
1075 { &long_long_integer_type_node, 0, 1, 1},
1076 { &long_long_unsigned_type_node, 1, 1, 1}
1078 #endif /* 0 */
1080 struct pf_args
1082 /* Input */
1083 int base;
1084 char * p;
1085 /* I/O */
1086 int c;
1087 /* Output */
1088 int imag;
1089 tree type;
1090 int conversion_errno;
1091 REAL_VALUE_TYPE value;
1094 static void
1095 parse_float (data)
1096 PTR data;
1098 struct pf_args * args = (struct pf_args *) data;
1099 int fflag = 0, lflag = 0;
1100 /* Copy token_buffer now, while it has just the number
1101 and not the suffixes; once we add `f' or `i',
1102 REAL_VALUE_ATOF may not work any more. */
1103 char *copy = (char *) alloca (args->p - token_buffer + 1);
1104 bcopy (token_buffer, copy, args->p - token_buffer + 1);
1105 args->imag = 0;
1106 args->conversion_errno = 0;
1107 args->type = double_type_node;
1109 while (1)
1111 int lose = 0;
1113 /* Read the suffixes to choose a data type. */
1114 switch (args->c)
1116 case 'f': case 'F':
1117 if (fflag)
1118 error ("more than one `f' in numeric constant");
1119 fflag = 1;
1120 break;
1122 case 'l': case 'L':
1123 if (lflag)
1124 error ("more than one `l' in numeric constant");
1125 lflag = 1;
1126 break;
1128 case 'i': case 'I':
1129 if (args->imag)
1130 error ("more than one `i' or `j' in numeric constant");
1131 else if (pedantic)
1132 pedwarn ("ANSI C forbids imaginary numeric constants");
1133 args->imag = 1;
1134 break;
1136 default:
1137 lose = 1;
1140 if (lose)
1141 break;
1143 if (args->p >= token_buffer + maxtoken - 3)
1144 args->p = extend_token_buffer (args->p);
1145 *(args->p++) = args->c;
1146 *(args->p) = 0;
1147 args->c = GETC();
1150 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1151 tells the desired precision of the binary result
1152 of decimal-to-binary conversion. */
1154 if (fflag)
1156 if (lflag)
1157 error ("both `f' and `l' in floating constant");
1159 args->type = float_type_node;
1160 errno = 0;
1161 if (args->base == 16)
1162 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
1163 else
1164 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
1165 args->conversion_errno = errno;
1166 /* A diagnostic is required here by some ANSI C testsuites.
1167 This is not pedwarn, because some people don't want
1168 an error for this. */
1169 if (REAL_VALUE_ISINF (args->value) && pedantic)
1170 warning ("floating point number exceeds range of `float'");
1172 else if (lflag)
1174 args->type = long_double_type_node;
1175 errno = 0;
1176 if (args->base == 16)
1177 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
1178 else
1179 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
1180 args->conversion_errno = errno;
1181 if (REAL_VALUE_ISINF (args->value) && pedantic)
1182 warning ("floating point number exceeds range of `long double'");
1184 else
1186 errno = 0;
1187 if (args->base == 16)
1188 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
1189 else
1190 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
1191 args->conversion_errno = errno;
1192 if (REAL_VALUE_ISINF (args->value) && pedantic)
1193 warning ("floating point number exceeds range of `double'");
1197 /* Get the next character, staying within the current token if possible.
1198 If we're lexing a token, we don't want to look beyond the end of the
1199 token cpplib has prepared for us; otherwise, we end up reading in the
1200 next token, which screws up feed_input. So just return a null
1201 character. */
1203 static inline int token_getch PARAMS ((void));
1205 static inline int
1206 token_getch ()
1208 #if USE_CPPLIB
1209 if (yy_cur == yy_lim)
1210 return '\0';
1211 #endif
1212 return GETC ();
1215 static inline void token_put_back PARAMS ((int));
1217 static inline void
1218 token_put_back (ch)
1219 int ch;
1221 #if USE_CPPLIB
1222 if (ch == '\0')
1223 return;
1224 #endif
1225 UNGETC (ch);
1228 /* Read a single token from the input stream, and assign it lexical
1229 semantics. */
1232 yylex ()
1234 register int c;
1235 register char *p;
1236 register int value;
1237 int wide_flag = 0;
1238 int objc_flag = 0;
1240 c = GETC();
1242 /* Effectively do c = skip_white_space (c)
1243 but do it faster in the usual cases. */
1244 while (1)
1245 switch (c)
1247 case ' ':
1248 case '\t':
1249 case '\f':
1250 case '\v':
1251 case '\b':
1252 #if USE_CPPLIB
1253 if (cpp_token == CPP_HSPACE)
1254 c = yy_get_token ();
1255 else
1256 #endif
1257 c = GETC();
1258 break;
1260 case '\r':
1261 /* Call skip_white_space so we can warn if appropriate. */
1263 case '\n':
1264 case '/':
1265 case '\\':
1266 c = skip_white_space (c);
1267 default:
1268 goto found_nonwhite;
1270 found_nonwhite:
1272 token_buffer[0] = c;
1273 token_buffer[1] = 0;
1275 /* yylloc.first_line = lineno; */
1277 switch (c)
1279 case EOF:
1280 end_of_file = 1;
1281 token_buffer[0] = 0;
1282 if (linemode)
1283 value = END_OF_LINE;
1284 else
1285 value = ENDFILE;
1286 break;
1288 case 'L':
1289 #if USE_CPPLIB
1290 if (cpp_token == CPP_NAME)
1291 goto letter;
1292 #endif
1293 /* Capital L may start a wide-string or wide-character constant. */
1295 register int c = token_getch();
1296 if (c == '\'')
1298 wide_flag = 1;
1299 goto char_constant;
1301 if (c == '"')
1303 wide_flag = 1;
1304 goto string_constant;
1306 token_put_back (c);
1308 goto letter;
1310 case '@':
1311 if (!doing_objc_thang)
1313 value = c;
1314 break;
1316 else
1318 /* '@' may start a constant string object. */
1319 register int c = token_getch ();
1320 if (c == '"')
1322 objc_flag = 1;
1323 goto string_constant;
1325 token_put_back (c);
1326 /* Fall through to treat '@' as the start of an identifier. */
1329 case 'A': case 'B': case 'C': case 'D': case 'E':
1330 case 'F': case 'G': case 'H': case 'I': case 'J':
1331 case 'K': case 'M': case 'N': case 'O':
1332 case 'P': case 'Q': case 'R': case 'S': case 'T':
1333 case 'U': case 'V': case 'W': case 'X': case 'Y':
1334 case 'Z':
1335 case 'a': case 'b': case 'c': case 'd': case 'e':
1336 case 'f': case 'g': case 'h': case 'i': case 'j':
1337 case 'k': case 'l': case 'm': case 'n': case 'o':
1338 case 'p': case 'q': case 'r': case 's': case 't':
1339 case 'u': case 'v': case 'w': case 'x': case 'y':
1340 case 'z':
1341 case '_':
1342 case '$':
1343 letter:
1344 #if USE_CPPLIB
1345 if (cpp_token == CPP_NAME)
1347 /* Note that one character has already been read from
1348 yy_cur into token_buffer. Also, cpplib complains about
1349 $ in identifiers, so we don't have to. */
1351 int len = yy_lim - yy_cur + 1;
1352 if (len >= maxtoken)
1353 extend_token_buffer_to (len + 1);
1354 memcpy (token_buffer + 1, yy_cur, len);
1355 p = token_buffer + len;
1356 yy_cur = yy_lim;
1358 else
1359 #endif
1361 p = token_buffer;
1362 while (ISALNUM (c) || c == '_' || c == '$' || c == '@')
1364 /* Make sure this char really belongs in an identifier. */
1365 if (c == '$')
1367 if (! dollars_in_ident)
1368 error ("`$' in identifier");
1369 else if (pedantic)
1370 pedwarn ("`$' in identifier");
1373 if (p >= token_buffer + maxtoken)
1374 p = extend_token_buffer (p);
1376 *p++ = c;
1377 c = token_getch();
1380 *p = 0;
1381 token_put_back (c);
1384 value = IDENTIFIER;
1385 yylval.itype = 0;
1387 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1390 register struct resword *ptr;
1392 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
1394 if (ptr->rid)
1395 yylval.ttype = ridpointers[(int) ptr->rid];
1396 value = (int) ptr->token;
1398 /* Only return OBJECTNAME if it is a typedef. */
1399 if (doing_objc_thang && value == OBJECTNAME)
1401 lastiddecl = lookup_name(yylval.ttype);
1403 if (lastiddecl == NULL_TREE
1404 || TREE_CODE (lastiddecl) != TYPE_DECL)
1405 value = IDENTIFIER;
1408 /* Even if we decided to recognize asm, still perhaps warn. */
1409 if (pedantic
1410 && (value == ASM_KEYWORD || value == TYPEOF
1411 || ptr->rid == RID_INLINE)
1412 && token_buffer[0] != '_')
1413 pedwarn ("ANSI does not permit the keyword `%s'",
1414 token_buffer);
1418 /* If we did not find a keyword, look for an identifier
1419 (or a typename). */
1421 if (value == IDENTIFIER)
1423 if (token_buffer[0] == '@')
1424 error("invalid identifier `%s'", token_buffer);
1426 yylval.ttype = get_identifier (token_buffer);
1427 lastiddecl = lookup_name (yylval.ttype);
1429 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1430 value = TYPENAME;
1431 /* A user-invisible read-only initialized variable
1432 should be replaced by its value.
1433 We handle only strings since that's the only case used in C. */
1434 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1435 && DECL_IGNORED_P (lastiddecl)
1436 && TREE_READONLY (lastiddecl)
1437 && DECL_INITIAL (lastiddecl) != 0
1438 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1440 tree stringval = DECL_INITIAL (lastiddecl);
1442 /* Copy the string value so that we won't clobber anything
1443 if we put something in the TREE_CHAIN of this one. */
1444 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1445 TREE_STRING_POINTER (stringval));
1446 value = STRING;
1448 else if (doing_objc_thang)
1450 tree objc_interface_decl = is_class_name (yylval.ttype);
1452 if (objc_interface_decl)
1454 value = CLASSNAME;
1455 yylval.ttype = objc_interface_decl;
1460 break;
1462 case '.':
1463 #if USE_CPPLIB
1464 if (yy_cur < yy_lim)
1465 #endif
1467 /* It's hard to preserve tokenization on '.' because
1468 it could be a symbol by itself, or it could be the
1469 start of a floating point number and cpp won't tell us. */
1470 register int c1 = token_getch ();
1471 token_buffer[1] = c1;
1472 if (c1 == '.')
1474 c1 = token_getch ();
1475 if (c1 == '.')
1477 token_buffer[2] = c1;
1478 token_buffer[3] = 0;
1479 value = ELLIPSIS;
1480 goto done;
1482 error ("parse error at `..'");
1484 if (ISDIGIT (c1))
1486 token_put_back (c1);
1487 goto number;
1489 token_put_back (c1);
1491 value = '.';
1492 token_buffer[1] = 0;
1493 break;
1495 case '0': case '1':
1496 /* Optimize for most frequent case. */
1498 register int cond;
1500 #if USE_CPPLIB
1501 cond = (yy_cur == yy_lim);
1502 #else
1503 register int c1 = token_getch ();
1504 token_put_back (c1);
1505 cond = (! ISALNUM (c1) && c1 != '.');
1506 #endif
1507 if (cond)
1509 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1510 value = CONSTANT;
1511 break;
1513 /*FALLTHRU*/
1515 case '2': case '3': case '4':
1516 case '5': case '6': case '7': case '8': case '9':
1517 number:
1519 int base = 10;
1520 int count = 0;
1521 int largest_digit = 0;
1522 int numdigits = 0;
1523 int overflow = 0;
1525 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
1526 The code below which fills the parts array assumes that a host
1527 int is at least twice as wide as a host char, and that
1528 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
1529 Two HOST_WIDE_INTs is the largest int literal we can store.
1530 In order to detect overflow below, the number of parts (TOTAL_PARTS)
1531 must be exactly the number of parts needed to hold the bits
1532 of two HOST_WIDE_INTs. */
1533 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
1534 unsigned int parts[TOTAL_PARTS];
1536 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON}
1537 floatflag = NOT_FLOAT;
1539 for (count = 0; count < TOTAL_PARTS; count++)
1540 parts[count] = 0;
1542 p = token_buffer;
1543 *p++ = c;
1545 if (c == '0')
1547 *p++ = (c = token_getch());
1548 if ((c == 'x') || (c == 'X'))
1550 base = 16;
1551 *p++ = (c = token_getch());
1553 /* Leading 0 forces octal unless the 0 is the only digit. */
1554 else if (c >= '0' && c <= '9')
1556 base = 8;
1557 numdigits++;
1559 else
1560 numdigits++;
1563 /* Read all the digits-and-decimal-points. */
1565 while (c == '.'
1566 || (ISALNUM (c) && c != 'l' && c != 'L'
1567 && c != 'u' && c != 'U'
1568 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1569 && (floatflag == NOT_FLOAT
1570 || ((base != 16) && (c != 'f') && (c != 'F'))
1571 || base == 16)))
1573 if (c == '.')
1575 if (base == 16 && pedantic)
1576 pedwarn ("floating constant may not be in radix 16");
1577 if (floatflag == TOO_MANY_POINTS)
1578 /* We have already emitted an error. Don't need another. */
1580 else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON)
1582 error ("malformed floating constant");
1583 floatflag = TOO_MANY_POINTS;
1584 /* Avoid another error from atof by forcing all characters
1585 from here on to be ignored. */
1586 p[-1] = '\0';
1588 else
1589 floatflag = AFTER_POINT;
1591 if (base == 8)
1592 base = 10;
1593 *p++ = c = token_getch();
1594 /* Accept '.' as the start of a floating-point number
1595 only when it is followed by a digit. */
1596 if (p == token_buffer + 2 && !ISDIGIT (c))
1597 abort ();
1599 else
1601 /* It is not a decimal point.
1602 It should be a digit (perhaps a hex digit). */
1604 if (ISDIGIT (c))
1606 c = c - '0';
1608 else if (base <= 10)
1610 if (c == 'e' || c == 'E')
1612 base = 10;
1613 floatflag = AFTER_EXPON;
1614 break; /* start of exponent */
1616 error ("nondigits in number and not hexadecimal");
1617 c = 0;
1619 else if (base == 16 && (c == 'p' || c == 'P'))
1621 floatflag = AFTER_EXPON;
1622 break; /* start of exponent */
1624 else if (c >= 'a' && c <= 'f')
1626 c = c - 'a' + 10;
1628 else
1630 c = c - 'A' + 10;
1632 if (c >= largest_digit)
1633 largest_digit = c;
1634 numdigits++;
1636 for (count = 0; count < TOTAL_PARTS; count++)
1638 parts[count] *= base;
1639 if (count)
1641 parts[count]
1642 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1643 parts[count-1]
1644 &= (1 << HOST_BITS_PER_CHAR) - 1;
1646 else
1647 parts[0] += c;
1650 /* If the highest-order part overflows (gets larger than
1651 a host char will hold) then the whole number has
1652 overflowed. Record this and truncate the highest-order
1653 part. */
1654 if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
1656 overflow = 1;
1657 parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
1660 if (p >= token_buffer + maxtoken - 3)
1661 p = extend_token_buffer (p);
1662 *p++ = (c = token_getch());
1666 /* This can happen on input like `int i = 0x;' */
1667 if (numdigits == 0)
1668 error ("numeric constant with no digits");
1670 if (largest_digit >= base)
1671 error ("numeric constant contains digits beyond the radix");
1673 /* Remove terminating char from the token buffer and delimit the
1674 string. */
1675 *--p = 0;
1677 if (floatflag != NOT_FLOAT)
1679 tree type;
1680 int imag, conversion_errno;
1681 REAL_VALUE_TYPE value;
1682 struct pf_args args;
1684 /* Read explicit exponent if any, and put it in tokenbuf. */
1686 if ((base == 10 && ((c == 'e') || (c == 'E')))
1687 || (base == 16 && (c == 'p' || c == 'P')))
1689 if (p >= token_buffer + maxtoken - 3)
1690 p = extend_token_buffer (p);
1691 *p++ = c;
1692 c = token_getch();
1693 if ((c == '+') || (c == '-'))
1695 *p++ = c;
1696 c = token_getch();
1698 /* Exponent is decimal, even if string is a hex float. */
1699 if (! ISDIGIT (c))
1700 error ("floating constant exponent has no digits");
1701 while (ISDIGIT (c))
1703 if (p >= token_buffer + maxtoken - 3)
1704 p = extend_token_buffer (p);
1705 *p++ = c;
1706 c = token_getch ();
1709 if (base == 16 && floatflag != AFTER_EXPON)
1710 error ("hexadecimal floating constant has no exponent");
1712 *p = 0;
1714 /* Setup input for parse_float() */
1715 args.base = base;
1716 args.p = p;
1717 args.c = c;
1719 /* Convert string to a double, checking for overflow. */
1720 if (do_float_handler (parse_float, (PTR) &args))
1722 /* Receive output from parse_float() */
1723 value = args.value;
1725 else
1727 /* We got an exception from parse_float() */
1728 error ("floating constant out of range");
1729 value = dconst0;
1732 /* Receive output from parse_float() */
1733 c = args.c;
1734 imag = args.imag;
1735 type = args.type;
1736 conversion_errno = args.conversion_errno;
1738 #ifdef ERANGE
1739 /* ERANGE is also reported for underflow,
1740 so test the value to distinguish overflow from that. */
1741 if (conversion_errno == ERANGE && !flag_traditional && pedantic
1742 && (REAL_VALUES_LESS (dconst1, value)
1743 || REAL_VALUES_LESS (value, dconstm1)))
1744 warning ("floating point number exceeds range of `double'");
1745 #endif
1747 /* If the result is not a number, assume it must have been
1748 due to some error message above, so silently convert
1749 it to a zero. */
1750 if (REAL_VALUE_ISNAN (value))
1751 value = dconst0;
1753 /* Create a node with determined type and value. */
1754 if (imag)
1755 yylval.ttype = build_complex (NULL_TREE,
1756 convert (type, integer_zero_node),
1757 build_real (type, value));
1758 else
1759 yylval.ttype = build_real (type, value);
1761 else
1763 tree traditional_type, ansi_type, type;
1764 HOST_WIDE_INT high, low;
1765 int spec_unsigned = 0;
1766 int spec_long = 0;
1767 int spec_long_long = 0;
1768 int spec_imag = 0;
1769 int warn = 0, i;
1771 traditional_type = ansi_type = type = NULL_TREE;
1772 while (1)
1774 if (c == 'u' || c == 'U')
1776 if (spec_unsigned)
1777 error ("two `u's in integer constant");
1778 spec_unsigned = 1;
1780 else if (c == 'l' || c == 'L')
1782 if (spec_long)
1784 if (spec_long_long)
1785 error ("three `l's in integer constant");
1786 else if (pedantic && ! in_system_header && warn_long_long)
1787 pedwarn ("ANSI C forbids long long integer constants");
1788 spec_long_long = 1;
1790 spec_long = 1;
1792 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1794 if (spec_imag)
1795 error ("more than one `i' or `j' in numeric constant");
1796 else if (pedantic)
1797 pedwarn ("ANSI C forbids imaginary numeric constants");
1798 spec_imag = 1;
1800 else
1801 break;
1802 if (p >= token_buffer + maxtoken - 3)
1803 p = extend_token_buffer (p);
1804 *p++ = c;
1805 c = token_getch();
1808 /* If the literal overflowed, pedwarn about it now. */
1809 if (overflow)
1811 warn = 1;
1812 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2);
1815 /* This is simplified by the fact that our constant
1816 is always positive. */
1818 high = low = 0;
1820 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1822 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1823 / HOST_BITS_PER_CHAR)]
1824 << (i * HOST_BITS_PER_CHAR));
1825 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1828 yylval.ttype = build_int_2 (low, high);
1829 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1831 /* If warn_traditional, calculate both the ANSI type and the
1832 traditional type, then see if they disagree.
1833 Otherwise, calculate only the type for the dialect in use. */
1834 if (warn_traditional || flag_traditional)
1836 /* Calculate the traditional type. */
1837 /* Traditionally, any constant is signed;
1838 but if unsigned is specified explicitly, obey that.
1839 Use the smallest size with the right number of bits,
1840 except for one special case with decimal constants. */
1841 if (! spec_long && base != 10
1842 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1843 traditional_type = (spec_unsigned ? unsigned_type_node
1844 : integer_type_node);
1845 /* A decimal constant must be long
1846 if it does not fit in type int.
1847 I think this is independent of whether
1848 the constant is signed. */
1849 else if (! spec_long && base == 10
1850 && int_fits_type_p (yylval.ttype, integer_type_node))
1851 traditional_type = (spec_unsigned ? unsigned_type_node
1852 : integer_type_node);
1853 else if (! spec_long_long)
1854 traditional_type = (spec_unsigned ? long_unsigned_type_node
1855 : long_integer_type_node);
1856 else if (int_fits_type_p (yylval.ttype,
1857 spec_unsigned
1858 ? long_long_unsigned_type_node
1859 : long_long_integer_type_node))
1860 traditional_type = (spec_unsigned
1861 ? long_long_unsigned_type_node
1862 : long_long_integer_type_node);
1863 else
1864 traditional_type = (spec_unsigned
1865 ? widest_unsigned_literal_type_node
1866 : widest_integer_literal_type_node);
1868 if (warn_traditional || ! flag_traditional)
1870 /* Calculate the ANSI type. */
1871 if (! spec_long && ! spec_unsigned
1872 && int_fits_type_p (yylval.ttype, integer_type_node))
1873 ansi_type = integer_type_node;
1874 else if (! spec_long && (base != 10 || spec_unsigned)
1875 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1876 ansi_type = unsigned_type_node;
1877 else if (! spec_unsigned && !spec_long_long
1878 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1879 ansi_type = long_integer_type_node;
1880 else if (! spec_long_long
1881 && int_fits_type_p (yylval.ttype,
1882 long_unsigned_type_node))
1883 ansi_type = long_unsigned_type_node;
1884 else if (! spec_unsigned
1885 && int_fits_type_p (yylval.ttype,
1886 long_long_integer_type_node))
1887 ansi_type = long_long_integer_type_node;
1888 else if (int_fits_type_p (yylval.ttype,
1889 long_long_unsigned_type_node))
1890 ansi_type = long_long_unsigned_type_node;
1891 else if (! spec_unsigned
1892 && int_fits_type_p (yylval.ttype,
1893 widest_integer_literal_type_node))
1894 ansi_type = widest_integer_literal_type_node;
1895 else
1896 ansi_type = widest_unsigned_literal_type_node;
1899 type = flag_traditional ? traditional_type : ansi_type;
1901 /* We assume that constants specified in a non-decimal
1902 base are bit patterns, and that the programmer really
1903 meant what they wrote. */
1904 if (warn_traditional && base == 10
1905 && traditional_type != ansi_type)
1907 if (TYPE_PRECISION (traditional_type)
1908 != TYPE_PRECISION (ansi_type))
1909 warning ("width of integer constant changes with -traditional");
1910 else if (TREE_UNSIGNED (traditional_type)
1911 != TREE_UNSIGNED (ansi_type))
1912 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1913 else
1914 warning ("width of integer constant may change on other systems with -traditional");
1917 if (pedantic && !flag_traditional && !spec_long_long && !warn
1918 && (TYPE_PRECISION (long_integer_type_node)
1919 < TYPE_PRECISION (type)))
1921 warn = 1;
1922 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
1925 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1926 warning ("decimal constant is so large that it is unsigned");
1928 if (spec_imag)
1930 if (TYPE_PRECISION (type)
1931 <= TYPE_PRECISION (integer_type_node))
1932 yylval.ttype
1933 = build_complex (NULL_TREE, integer_zero_node,
1934 convert (integer_type_node,
1935 yylval.ttype));
1936 else
1937 error ("complex integer constant is too wide for `complex int'");
1939 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1940 /* The traditional constant 0x80000000 is signed
1941 but doesn't fit in the range of int.
1942 This will change it to -0x80000000, which does fit. */
1944 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1945 yylval.ttype = convert (type, yylval.ttype);
1946 TREE_OVERFLOW (yylval.ttype)
1947 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1949 else
1950 TREE_TYPE (yylval.ttype) = type;
1953 /* If it's still an integer (not a complex), and it doesn't
1954 fit in the type we choose for it, then pedwarn. */
1956 if (! warn
1957 && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE
1958 && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype)))
1959 pedwarn ("integer constant is larger than the maximum value for its type");
1962 token_put_back (c);
1963 *p = 0;
1965 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
1966 || (!flag_traditional && (c == '-' || c == '+')
1967 && (p[-1] == 'e' || p[-1] == 'E')))
1968 error ("missing white space after number `%s'", token_buffer);
1970 value = CONSTANT; break;
1973 case '\'':
1974 char_constant:
1976 register int result = 0;
1977 register int num_chars = 0;
1978 int chars_seen = 0;
1979 unsigned width = TYPE_PRECISION (char_type_node);
1980 int max_chars;
1981 #ifdef MULTIBYTE_CHARS
1982 int longest_char = local_mb_cur_max ();
1983 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
1984 #endif
1986 max_chars = TYPE_PRECISION (integer_type_node) / width;
1987 if (wide_flag)
1988 width = WCHAR_TYPE_SIZE;
1990 while (1)
1992 tryagain:
1993 c = token_getch();
1995 if (c == '\'' || c == EOF)
1996 break;
1998 ++chars_seen;
1999 if (c == '\\')
2001 int ignore = 0;
2002 c = readescape (&ignore);
2003 if (ignore)
2004 goto tryagain;
2005 if (width < HOST_BITS_PER_INT
2006 && (unsigned) c >= ((unsigned)1 << width))
2007 pedwarn ("escape sequence out of range for character");
2008 #ifdef MAP_CHARACTER
2009 if (ISPRINT (c))
2010 c = MAP_CHARACTER (c);
2011 #endif
2013 else if (c == '\n')
2015 if (pedantic)
2016 pedwarn ("ANSI C forbids newline in character constant");
2017 lineno++;
2019 else
2021 #ifdef MULTIBYTE_CHARS
2022 wchar_t wc;
2023 int i;
2024 int char_len = -1;
2025 for (i = 1; i <= longest_char; ++i)
2027 if (i > maxtoken - 4)
2028 extend_token_buffer (token_buffer);
2030 token_buffer[i] = c;
2031 char_len = local_mbtowc (& wc,
2032 token_buffer + 1,
2034 if (char_len != -1)
2035 break;
2036 c = token_getch ();
2038 if (char_len > 1)
2040 /* mbtowc sometimes needs an extra char before accepting */
2041 if (char_len < i)
2042 token_put_back (c);
2043 if (! wide_flag)
2045 /* Merge character into result; ignore excess chars. */
2046 for (i = 1; i <= char_len; ++i)
2048 if (i > max_chars)
2049 break;
2050 if (width < HOST_BITS_PER_INT)
2051 result = (result << width)
2052 | (token_buffer[i]
2053 & ((1 << width) - 1));
2054 else
2055 result = token_buffer[i];
2057 num_chars += char_len;
2058 goto tryagain;
2060 c = wc;
2062 else
2064 if (char_len == -1)
2066 warning ("Ignoring invalid multibyte character");
2067 /* Replace all but the first byte. */
2068 for (--i; i > 1; --i)
2069 token_put_back (token_buffer[i]);
2070 wc = token_buffer[1];
2072 #ifdef MAP_CHARACTER
2073 c = MAP_CHARACTER (wc);
2074 #else
2075 c = wc;
2076 #endif
2078 #else /* ! MULTIBYTE_CHARS */
2079 #ifdef MAP_CHARACTER
2080 c = MAP_CHARACTER (c);
2081 #endif
2082 #endif /* ! MULTIBYTE_CHARS */
2085 if (wide_flag)
2087 if (chars_seen == 1) /* only keep the first one */
2088 result = c;
2089 goto tryagain;
2092 /* Merge character into result; ignore excess chars. */
2093 num_chars += (width / TYPE_PRECISION (char_type_node));
2094 if (num_chars < max_chars + 1)
2096 if (width < HOST_BITS_PER_INT)
2097 result = (result << width) | (c & ((1 << width) - 1));
2098 else
2099 result = c;
2103 if (c != '\'')
2104 error ("malformed character constant");
2105 else if (chars_seen == 0)
2106 error ("empty character constant");
2107 else if (num_chars > max_chars)
2109 num_chars = max_chars;
2110 error ("character constant too long");
2112 else if (chars_seen != 1 && ! flag_traditional && warn_multichar)
2113 warning ("multi-character character constant");
2115 /* If char type is signed, sign-extend the constant. */
2116 if (! wide_flag)
2118 int num_bits = num_chars * width;
2119 if (num_bits == 0)
2120 /* We already got an error; avoid invalid shift. */
2121 yylval.ttype = build_int_2 (0, 0);
2122 else if (TREE_UNSIGNED (char_type_node)
2123 || ((result >> (num_bits - 1)) & 1) == 0)
2124 yylval.ttype
2125 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
2126 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
2128 else
2129 yylval.ttype
2130 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
2131 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
2132 -1);
2133 TREE_TYPE (yylval.ttype) = integer_type_node;
2135 else
2137 yylval.ttype = build_int_2 (result, 0);
2138 TREE_TYPE (yylval.ttype) = wchar_type_node;
2141 value = CONSTANT;
2142 break;
2145 case '"':
2146 string_constant:
2148 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
2149 : TYPE_PRECISION (char_type_node);
2150 #ifdef MULTIBYTE_CHARS
2151 int longest_char = local_mb_cur_max ();
2152 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
2153 #endif
2154 c = token_getch ();
2155 p = token_buffer + 1;
2157 while (c != '"' && c != EOF)
2159 /* ignore_escape_flag is set for reading the filename in #line. */
2160 if (!ignore_escape_flag && c == '\\')
2162 int ignore = 0;
2163 c = readescape (&ignore);
2164 if (ignore)
2165 goto skipnewline;
2166 if (width < HOST_BITS_PER_INT
2167 && (unsigned) c >= ((unsigned)1 << width))
2168 pedwarn ("escape sequence out of range for character");
2170 else if (c == '\n')
2172 if (pedantic)
2173 pedwarn ("ANSI C forbids newline in string constant");
2174 lineno++;
2176 else
2178 #ifdef MULTIBYTE_CHARS
2179 wchar_t wc;
2180 int i;
2181 int char_len = -1;
2182 for (i = 0; i < longest_char; ++i)
2184 if (p + i >= token_buffer + maxtoken)
2185 p = extend_token_buffer (p);
2186 p[i] = c;
2188 char_len = local_mbtowc (& wc, p, i + 1);
2189 if (char_len != -1)
2190 break;
2191 c = token_getch ();
2193 if (char_len == -1)
2195 warning ("Ignoring invalid multibyte character");
2196 /* Replace all except the first byte. */
2197 token_put_back (c);
2198 for (--i; i > 0; --i)
2199 token_put_back (p[i]);
2200 char_len = 1;
2202 /* mbtowc sometimes needs an extra char before accepting */
2203 if (char_len <= i)
2204 token_put_back (c);
2205 if (! wide_flag)
2207 p += (i + 1);
2208 c = token_getch ();
2209 continue;
2211 c = wc;
2212 #endif /* MULTIBYTE_CHARS */
2215 /* Add this single character into the buffer either as a wchar_t
2216 or as a single byte. */
2217 if (wide_flag)
2219 unsigned width = TYPE_PRECISION (char_type_node);
2220 unsigned bytemask = (1 << width) - 1;
2221 int byte;
2223 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2224 p = extend_token_buffer (p);
2226 for (byte = 0; byte < WCHAR_BYTES; ++byte)
2228 int value;
2229 if (byte >= (int) sizeof (c))
2230 value = 0;
2231 else
2232 value = (c >> (byte * width)) & bytemask;
2233 if (BYTES_BIG_ENDIAN)
2234 p[WCHAR_BYTES - byte - 1] = value;
2235 else
2236 p[byte] = value;
2238 p += WCHAR_BYTES;
2240 else
2242 if (p >= token_buffer + maxtoken)
2243 p = extend_token_buffer (p);
2244 *p++ = c;
2247 skipnewline:
2248 c = token_getch ();
2251 /* Terminate the string value, either with a single byte zero
2252 or with a wide zero. */
2253 if (wide_flag)
2255 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2256 p = extend_token_buffer (p);
2257 bzero (p, WCHAR_BYTES);
2258 p += WCHAR_BYTES;
2260 else
2262 if (p >= token_buffer + maxtoken)
2263 p = extend_token_buffer (p);
2264 *p++ = 0;
2267 if (c == EOF)
2268 error ("Unterminated string constant");
2270 /* We have read the entire constant.
2271 Construct a STRING_CST for the result. */
2273 if (wide_flag)
2275 yylval.ttype = build_string (p - (token_buffer + 1),
2276 token_buffer + 1);
2277 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2278 value = STRING;
2280 else if (objc_flag)
2282 /* Return an Objective-C @"..." constant string object. */
2283 yylval.ttype = build_objc_string (p - (token_buffer + 1),
2284 token_buffer + 1);
2285 TREE_TYPE (yylval.ttype) = char_array_type_node;
2286 value = OBJC_STRING;
2288 else
2290 yylval.ttype = build_string (p - (token_buffer + 1),
2291 token_buffer + 1);
2292 TREE_TYPE (yylval.ttype) = char_array_type_node;
2293 value = STRING;
2296 break;
2299 case '+':
2300 case '-':
2301 case '&':
2302 case '|':
2303 case ':':
2304 case '<':
2305 case '>':
2306 case '*':
2307 case '/':
2308 case '%':
2309 case '^':
2310 case '!':
2311 case '=':
2313 register int c1;
2315 combine:
2317 switch (c)
2319 case '+':
2320 yylval.code = PLUS_EXPR; break;
2321 case '-':
2322 yylval.code = MINUS_EXPR; break;
2323 case '&':
2324 yylval.code = BIT_AND_EXPR; break;
2325 case '|':
2326 yylval.code = BIT_IOR_EXPR; break;
2327 case '*':
2328 yylval.code = MULT_EXPR; break;
2329 case '/':
2330 yylval.code = TRUNC_DIV_EXPR; break;
2331 case '%':
2332 yylval.code = TRUNC_MOD_EXPR; break;
2333 case '^':
2334 yylval.code = BIT_XOR_EXPR; break;
2335 case LSHIFT:
2336 yylval.code = LSHIFT_EXPR; break;
2337 case RSHIFT:
2338 yylval.code = RSHIFT_EXPR; break;
2339 case '<':
2340 yylval.code = LT_EXPR; break;
2341 case '>':
2342 yylval.code = GT_EXPR; break;
2345 token_buffer[1] = c1 = token_getch();
2346 token_buffer[2] = 0;
2348 if (c1 == '=')
2350 switch (c)
2352 case '<':
2353 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2354 case '>':
2355 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2356 case '!':
2357 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2358 case '=':
2359 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2361 value = ASSIGN; goto done;
2363 else if (c == c1)
2364 switch (c)
2366 case '+':
2367 value = PLUSPLUS; goto done;
2368 case '-':
2369 value = MINUSMINUS; goto done;
2370 case '&':
2371 value = ANDAND; goto done;
2372 case '|':
2373 value = OROR; goto done;
2374 case '<':
2375 c = LSHIFT;
2376 goto combine;
2377 case '>':
2378 c = RSHIFT;
2379 goto combine;
2381 else
2382 switch (c)
2384 case '-':
2385 if (c1 == '>')
2386 { value = POINTSAT; goto done; }
2387 break;
2389 /* digraphs */
2390 case ':':
2391 if (c1 == '>')
2392 { value = ']'; goto done; }
2393 break;
2394 case '<':
2395 if (c1 == '%')
2396 { value = '{'; indent_level++; goto done; }
2397 if (c1 == ':')
2398 { value = '['; goto done; }
2399 break;
2400 case '%':
2401 if (c1 == '>')
2402 { value = '}'; indent_level--; goto done; }
2403 break;
2406 token_put_back (c1);
2407 token_buffer[1] = 0;
2409 if ((c == '<') || (c == '>'))
2410 value = ARITHCOMPARE;
2411 else value = c;
2412 break;
2415 case 0:
2416 /* Don't make yyparse think this is eof. */
2417 value = 1;
2418 break;
2420 case '{':
2421 indent_level++;
2422 value = c;
2423 break;
2425 case '}':
2426 indent_level--;
2427 value = c;
2428 break;
2430 default:
2431 value = c;
2434 done:
2435 /* yylloc.last_line = lineno; */
2437 return value;
2440 /* Sets the value of the 'yydebug' variable to VALUE.
2441 This is a function so we don't have to have YYDEBUG defined
2442 in order to build the compiler. */
2444 void
2445 set_yydebug (value)
2446 int value;
2448 #if YYDEBUG != 0
2449 yydebug = value;
2450 #else
2451 warning ("YYDEBUG not defined.");
2452 #endif