(yylex): For float, build constant in long double.
[official-gcc.git] / gcc / c-lex.c
blobf5d3b40a9a187f76c75277ba9371ba2a37c5f804
1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 88, 89, 92, 94, 1995 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #include <stdio.h>
22 #include <errno.h>
23 #include <setjmp.h>
25 #include "config.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "input.h"
29 #include "c-lex.h"
30 #include "c-tree.h"
31 #include "flags.h"
32 #include "c-parse.h"
34 #include <ctype.h>
36 #ifdef MULTIBYTE_CHARS
37 #include <stdlib.h>
38 #include <locale.h>
39 #endif
41 #ifndef errno
42 extern int errno;
43 #endif
45 /* The elements of `ridpointers' are identifier nodes
46 for the reserved type names and storage classes.
47 It is indexed by a RID_... value. */
48 tree ridpointers[(int) RID_MAX];
50 /* Cause the `yydebug' variable to be defined. */
51 #define YYDEBUG 1
53 /* the declaration found for the last IDENTIFIER token read in.
54 yylex must look this up to detect typedefs, which get token type TYPENAME,
55 so it is left around in case the identifier is not a typedef but is
56 used in a context which makes it a reference to a variable. */
57 tree lastiddecl;
59 /* Nonzero enables objc features. */
61 int doing_objc_thang;
63 extern tree is_class_name ();
65 extern int yydebug;
67 /* File used for outputting assembler code. */
68 extern FILE *asm_out_file;
70 #ifndef WCHAR_TYPE_SIZE
71 #ifdef INT_TYPE_SIZE
72 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
73 #else
74 #define WCHAR_TYPE_SIZE BITS_PER_WORD
75 #endif
76 #endif
78 /* Number of bytes in a wide character. */
79 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
81 static int maxtoken; /* Current nominal length of token buffer. */
82 char *token_buffer; /* Pointer to token buffer.
83 Actual allocated length is maxtoken + 2.
84 This is not static because objc-parse.y uses it. */
86 /* Nonzero if end-of-file has been seen on input. */
87 static int end_of_file;
89 /* Buffered-back input character; faster than using ungetc. */
90 static int nextchar = -1;
92 int check_newline ();
94 /* Do not insert generated code into the source, instead, include it.
95 This allows us to build gcc automatically even for targets that
96 need to add or modify the reserved keyword lists. */
97 #include "c-gperf.h"
99 /* Return something to represent absolute declarators containing a *.
100 TARGET is the absolute declarator that the * contains.
101 TYPE_QUALS is a list of modifiers such as const or volatile
102 to apply to the pointer type, represented as identifiers.
104 We return an INDIRECT_REF whose "contents" are TARGET
105 and whose type is the modifier list. */
107 tree
108 make_pointer_declarator (type_quals, target)
109 tree type_quals, target;
111 return build1 (INDIRECT_REF, type_quals, target);
114 void
115 forget_protocol_qualifiers ()
117 int i, n = sizeof wordlist / sizeof (struct resword);
119 for (i = 0; i < n; i++)
120 if ((int) wordlist[i].rid >= (int) RID_IN
121 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
122 wordlist[i].name = "";
125 void
126 remember_protocol_qualifiers ()
128 int i, n = sizeof wordlist / sizeof (struct resword);
130 for (i = 0; i < n; i++)
131 if (wordlist[i].rid == RID_IN)
132 wordlist[i].name = "in";
133 else if (wordlist[i].rid == RID_OUT)
134 wordlist[i].name = "out";
135 else if (wordlist[i].rid == RID_INOUT)
136 wordlist[i].name = "inout";
137 else if (wordlist[i].rid == RID_BYCOPY)
138 wordlist[i].name = "bycopy";
139 else if (wordlist[i].rid == RID_ONEWAY)
140 wordlist[i].name = "oneway";
143 void
144 init_lex ()
146 /* Make identifier nodes long enough for the language-specific slots. */
147 set_identifier_size (sizeof (struct lang_identifier));
149 /* Start it at 0, because check_newline is called at the very beginning
150 and will increment it to 1. */
151 lineno = 0;
153 #ifdef MULTIBYTE_CHARS
154 /* Change to the native locale for multibyte conversions. */
155 setlocale (LC_CTYPE, "");
156 #endif
158 maxtoken = 40;
159 token_buffer = (char *) xmalloc (maxtoken + 2);
161 ridpointers[(int) RID_INT] = get_identifier ("int");
162 ridpointers[(int) RID_CHAR] = get_identifier ("char");
163 ridpointers[(int) RID_VOID] = get_identifier ("void");
164 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
165 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
166 ridpointers[(int) RID_SHORT] = get_identifier ("short");
167 ridpointers[(int) RID_LONG] = get_identifier ("long");
168 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
169 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
170 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
171 ridpointers[(int) RID_CONST] = get_identifier ("const");
172 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
173 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
174 ridpointers[(int) RID_STATIC] = get_identifier ("static");
175 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
176 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
177 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
178 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
179 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
180 ridpointers[(int) RID_ID] = get_identifier ("id");
181 ridpointers[(int) RID_IN] = get_identifier ("in");
182 ridpointers[(int) RID_OUT] = get_identifier ("out");
183 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
184 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
185 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
186 forget_protocol_qualifiers();
188 /* Some options inhibit certain reserved words.
189 Clear those words out of the hash table so they won't be recognized. */
190 #define UNSET_RESERVED_WORD(STRING) \
191 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
192 if (s) s->name = ""; } while (0)
194 if (! doing_objc_thang)
195 UNSET_RESERVED_WORD ("id");
197 if (flag_traditional)
199 UNSET_RESERVED_WORD ("const");
200 UNSET_RESERVED_WORD ("volatile");
201 UNSET_RESERVED_WORD ("typeof");
202 UNSET_RESERVED_WORD ("signed");
203 UNSET_RESERVED_WORD ("inline");
204 UNSET_RESERVED_WORD ("iterator");
205 UNSET_RESERVED_WORD ("complex");
207 if (flag_no_asm)
209 UNSET_RESERVED_WORD ("asm");
210 UNSET_RESERVED_WORD ("typeof");
211 UNSET_RESERVED_WORD ("inline");
212 UNSET_RESERVED_WORD ("iterator");
213 UNSET_RESERVED_WORD ("complex");
217 void
218 reinit_parse_for_function ()
222 /* Function used when yydebug is set, to print a token in more detail. */
224 void
225 yyprint (file, yychar, yylval)
226 FILE *file;
227 int yychar;
228 YYSTYPE yylval;
230 tree t;
231 switch (yychar)
233 case IDENTIFIER:
234 case TYPENAME:
235 case OBJECTNAME:
236 t = yylval.ttype;
237 if (IDENTIFIER_POINTER (t))
238 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
239 break;
241 case CONSTANT:
242 t = yylval.ttype;
243 if (TREE_CODE (t) == INTEGER_CST)
244 fprintf (file,
245 #if HOST_BITS_PER_WIDE_INT == 64
246 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
247 " 0x%lx%016lx",
248 #else
249 " 0x%x%016x",
250 #endif
251 #else
252 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
253 " 0x%lx%08lx",
254 #else
255 " 0x%x%08x",
256 #endif
257 #endif
258 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
259 break;
264 /* If C is not whitespace, return C.
265 Otherwise skip whitespace and return first nonwhite char read. */
267 static int
268 skip_white_space (c)
269 register int c;
271 static int newline_warning = 0;
273 for (;;)
275 switch (c)
277 /* We don't recognize comments here, because
278 cpp output can include / and * consecutively as operators.
279 Also, there's no need, since cpp removes all comments. */
281 case '\n':
282 c = check_newline ();
283 break;
285 case ' ':
286 case '\t':
287 case '\f':
288 case '\v':
289 case '\b':
290 c = getc (finput);
291 break;
293 case '\r':
294 /* ANSI C says the effects of a carriage return in a source file
295 are undefined. */
296 if (pedantic && !newline_warning)
298 warning ("carriage return in source file");
299 warning ("(we only warn about the first carriage return)");
300 newline_warning = 1;
302 c = getc (finput);
303 break;
305 case '\\':
306 c = getc (finput);
307 if (c == '\n')
308 lineno++;
309 else
310 error ("stray '\\' in program");
311 c = getc (finput);
312 break;
314 default:
315 return (c);
320 /* Skips all of the white space at the current location in the input file.
321 Must use and reset nextchar if it has the next character. */
323 void
324 position_after_white_space ()
326 register int c;
328 if (nextchar != -1)
329 c = nextchar, nextchar = -1;
330 else
331 c = getc (finput);
333 ungetc (skip_white_space (c), finput);
336 /* Make the token buffer longer, preserving the data in it.
337 P should point to just beyond the last valid character in the old buffer.
338 The value we return is a pointer to the new buffer
339 at a place corresponding to P. */
341 static char *
342 extend_token_buffer (p)
343 char *p;
345 int offset = p - token_buffer;
347 maxtoken = maxtoken * 2 + 10;
348 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
350 return token_buffer + offset;
353 /* At the beginning of a line, increment the line number
354 and process any #-directive on this line.
355 If the line is a #-directive, read the entire line and return a newline.
356 Otherwise, return the line's first non-whitespace character. */
359 check_newline ()
361 register int c;
362 register int token;
364 lineno++;
366 /* Read first nonwhite char on the line. */
368 c = getc (finput);
369 while (c == ' ' || c == '\t')
370 c = getc (finput);
372 if (c != '#')
374 /* If not #, return it so caller will use it. */
375 return c;
378 /* Read first nonwhite char after the `#'. */
380 c = getc (finput);
381 while (c == ' ' || c == '\t')
382 c = getc (finput);
384 /* If a letter follows, then if the word here is `line', skip
385 it and ignore it; otherwise, ignore the line, with an error
386 if the word isn't `pragma', `ident', `define', or `undef'. */
388 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
390 if (c == 'p')
392 if (getc (finput) == 'r'
393 && getc (finput) == 'a'
394 && getc (finput) == 'g'
395 && getc (finput) == 'm'
396 && getc (finput) == 'a'
397 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
399 #ifdef HANDLE_SYSV_PRAGMA
400 return handle_sysv_pragma (finput, c);
401 #else /* !HANDLE_SYSV_PRAGMA */
402 #ifdef HANDLE_PRAGMA
403 HANDLE_PRAGMA (finput);
404 #endif /* HANDLE_PRAGMA */
405 goto skipline;
406 #endif /* !HANDLE_SYSV_PRAGMA */
410 else if (c == 'd')
412 if (getc (finput) == 'e'
413 && getc (finput) == 'f'
414 && getc (finput) == 'i'
415 && getc (finput) == 'n'
416 && getc (finput) == 'e'
417 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
419 #ifdef DWARF_DEBUGGING_INFO
420 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
421 && (write_symbols == DWARF_DEBUG))
422 dwarfout_define (lineno, get_directive_line (finput));
423 #endif /* DWARF_DEBUGGING_INFO */
424 goto skipline;
427 else if (c == 'u')
429 if (getc (finput) == 'n'
430 && getc (finput) == 'd'
431 && getc (finput) == 'e'
432 && getc (finput) == 'f'
433 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
435 #ifdef DWARF_DEBUGGING_INFO
436 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
437 && (write_symbols == DWARF_DEBUG))
438 dwarfout_undef (lineno, get_directive_line (finput));
439 #endif /* DWARF_DEBUGGING_INFO */
440 goto skipline;
443 else if (c == 'l')
445 if (getc (finput) == 'i'
446 && getc (finput) == 'n'
447 && getc (finput) == 'e'
448 && ((c = getc (finput)) == ' ' || c == '\t'))
449 goto linenum;
451 else if (c == 'i')
453 if (getc (finput) == 'd'
454 && getc (finput) == 'e'
455 && getc (finput) == 'n'
456 && getc (finput) == 't'
457 && ((c = getc (finput)) == ' ' || c == '\t'))
459 /* #ident. The pedantic warning is now in cccp.c. */
461 /* Here we have just seen `#ident '.
462 A string constant should follow. */
464 while (c == ' ' || c == '\t')
465 c = getc (finput);
467 /* If no argument, ignore the line. */
468 if (c == '\n')
469 return c;
471 ungetc (c, finput);
472 token = yylex ();
473 if (token != STRING
474 || TREE_CODE (yylval.ttype) != STRING_CST)
476 error ("invalid #ident");
477 goto skipline;
480 if (!flag_no_ident)
482 #ifdef ASM_OUTPUT_IDENT
483 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
484 #endif
487 /* Skip the rest of this line. */
488 goto skipline;
492 error ("undefined or invalid # directive");
493 goto skipline;
496 linenum:
497 /* Here we have either `#line' or `# <nonletter>'.
498 In either case, it should be a line number; a digit should follow. */
500 while (c == ' ' || c == '\t')
501 c = getc (finput);
503 /* If the # is the only nonwhite char on the line,
504 just ignore it. Check the new newline. */
505 if (c == '\n')
506 return c;
508 /* Something follows the #; read a token. */
510 ungetc (c, finput);
511 token = yylex ();
513 if (token == CONSTANT
514 && TREE_CODE (yylval.ttype) == INTEGER_CST)
516 int old_lineno = lineno;
517 int used_up = 0;
518 /* subtract one, because it is the following line that
519 gets the specified number */
521 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
523 /* Is this the last nonwhite stuff on the line? */
524 c = getc (finput);
525 while (c == ' ' || c == '\t')
526 c = getc (finput);
527 if (c == '\n')
529 /* No more: store the line number and check following line. */
530 lineno = l;
531 return c;
533 ungetc (c, finput);
535 /* More follows: it must be a string constant (filename). */
537 /* Read the string constant. */
538 token = yylex ();
540 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
542 error ("invalid #line");
543 goto skipline;
546 input_filename
547 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
548 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
549 lineno = l;
551 /* Each change of file name
552 reinitializes whether we are now in a system header. */
553 in_system_header = 0;
555 if (main_input_filename == 0)
556 main_input_filename = input_filename;
558 /* Is this the last nonwhite stuff on the line? */
559 c = getc (finput);
560 while (c == ' ' || c == '\t')
561 c = getc (finput);
562 if (c == '\n')
564 /* Update the name in the top element of input_file_stack. */
565 if (input_file_stack)
566 input_file_stack->name = input_filename;
568 return c;
570 ungetc (c, finput);
572 token = yylex ();
573 used_up = 0;
575 /* `1' after file name means entering new file.
576 `2' after file name means just left a file. */
578 if (token == CONSTANT
579 && TREE_CODE (yylval.ttype) == INTEGER_CST)
581 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
583 /* Pushing to a new file. */
584 struct file_stack *p
585 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
586 input_file_stack->line = old_lineno;
587 p->next = input_file_stack;
588 p->name = input_filename;
589 input_file_stack = p;
590 input_file_stack_tick++;
591 #ifdef DWARF_DEBUGGING_INFO
592 if (debug_info_level == DINFO_LEVEL_VERBOSE
593 && write_symbols == DWARF_DEBUG)
594 dwarfout_start_new_source_file (input_filename);
595 #endif /* DWARF_DEBUGGING_INFO */
597 used_up = 1;
599 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
601 /* Popping out of a file. */
602 if (input_file_stack->next)
604 struct file_stack *p = input_file_stack;
605 input_file_stack = p->next;
606 free (p);
607 input_file_stack_tick++;
608 #ifdef DWARF_DEBUGGING_INFO
609 if (debug_info_level == DINFO_LEVEL_VERBOSE
610 && write_symbols == DWARF_DEBUG)
611 dwarfout_resume_previous_source_file (input_file_stack->line);
612 #endif /* DWARF_DEBUGGING_INFO */
614 else
615 error ("#-lines for entering and leaving files don't match");
617 used_up = 1;
621 /* Now that we've pushed or popped the input stack,
622 update the name in the top element. */
623 if (input_file_stack)
624 input_file_stack->name = input_filename;
626 /* If we have handled a `1' or a `2',
627 see if there is another number to read. */
628 if (used_up)
630 /* Is this the last nonwhite stuff on the line? */
631 c = getc (finput);
632 while (c == ' ' || c == '\t')
633 c = getc (finput);
634 if (c == '\n')
635 return c;
636 ungetc (c, finput);
638 token = yylex ();
639 used_up = 0;
642 /* `3' after file name means this is a system header file. */
644 if (token == CONSTANT
645 && TREE_CODE (yylval.ttype) == INTEGER_CST
646 && TREE_INT_CST_LOW (yylval.ttype) == 3)
647 in_system_header = 1, used_up = 1;
649 if (used_up)
651 /* Is this the last nonwhite stuff on the line? */
652 c = getc (finput);
653 while (c == ' ' || c == '\t')
654 c = getc (finput);
655 if (c == '\n')
656 return c;
657 ungetc (c, finput);
660 warning ("unrecognized text at end of #line");
662 else
663 error ("invalid #-line");
665 /* skip the rest of this line. */
666 skipline:
667 if (c == '\n')
668 return c;
669 while ((c = getc (finput)) != EOF && c != '\n');
670 return c;
673 #ifdef HANDLE_SYSV_PRAGMA
675 /* Handle a #pragma directive. INPUT is the current input stream,
676 and C is a character to reread. Processes the entire input line
677 and returns a character for the caller to reread: either \n or EOF. */
679 /* This function has to be in this file, in order to get at
680 the token types. */
683 handle_sysv_pragma (input, c)
684 FILE *input;
685 int c;
687 for (;;)
689 while (c == ' ' || c == '\t')
690 c = getc (input);
691 if (c == '\n' || c == EOF)
693 handle_pragma_token (0, 0);
694 return c;
696 ungetc (c, input);
697 switch (yylex ())
699 case IDENTIFIER:
700 case TYPENAME:
701 case STRING:
702 case CONSTANT:
703 handle_pragma_token (token_buffer, yylval.ttype);
704 break;
705 default:
706 handle_pragma_token (token_buffer, 0);
708 if (nextchar >= 0)
709 c = nextchar, nextchar = -1;
710 else
711 c = getc (input);
715 #endif /* HANDLE_SYSV_PRAGMA */
717 #define ENDFILE -1 /* token that represents end-of-file */
719 /* Read an escape sequence, returning its equivalent as a character,
720 or store 1 in *ignore_ptr if it is backslash-newline. */
722 static int
723 readescape (ignore_ptr)
724 int *ignore_ptr;
726 register int c = getc (finput);
727 register int code;
728 register unsigned count;
729 unsigned firstdig = 0;
730 int nonnull;
732 switch (c)
734 case 'x':
735 if (warn_traditional)
736 warning ("the meaning of `\\x' varies with -traditional");
738 if (flag_traditional)
739 return c;
741 code = 0;
742 count = 0;
743 nonnull = 0;
744 while (1)
746 c = getc (finput);
747 if (!(c >= 'a' && c <= 'f')
748 && !(c >= 'A' && c <= 'F')
749 && !(c >= '0' && c <= '9'))
751 ungetc (c, finput);
752 break;
754 code *= 16;
755 if (c >= 'a' && c <= 'f')
756 code += c - 'a' + 10;
757 if (c >= 'A' && c <= 'F')
758 code += c - 'A' + 10;
759 if (c >= '0' && c <= '9')
760 code += c - '0';
761 if (code != 0 || count != 0)
763 if (count == 0)
764 firstdig = code;
765 count++;
767 nonnull = 1;
769 if (! nonnull)
770 error ("\\x used with no following hex digits");
771 else if (count == 0)
772 /* Digits are all 0's. Ok. */
774 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
775 || (count > 1
776 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
777 <= firstdig)))
778 pedwarn ("hex escape out of range");
779 return code;
781 case '0': case '1': case '2': case '3': case '4':
782 case '5': case '6': case '7':
783 code = 0;
784 count = 0;
785 while ((c <= '7') && (c >= '0') && (count++ < 3))
787 code = (code * 8) + (c - '0');
788 c = getc (finput);
790 ungetc (c, finput);
791 return code;
793 case '\\': case '\'': case '"':
794 return c;
796 case '\n':
797 lineno++;
798 *ignore_ptr = 1;
799 return 0;
801 case 'n':
802 return TARGET_NEWLINE;
804 case 't':
805 return TARGET_TAB;
807 case 'r':
808 return TARGET_CR;
810 case 'f':
811 return TARGET_FF;
813 case 'b':
814 return TARGET_BS;
816 case 'a':
817 if (warn_traditional)
818 warning ("the meaning of `\\a' varies with -traditional");
820 if (flag_traditional)
821 return c;
822 return TARGET_BELL;
824 case 'v':
825 #if 0 /* Vertical tab is present in common usage compilers. */
826 if (flag_traditional)
827 return c;
828 #endif
829 return TARGET_VT;
831 case 'e':
832 case 'E':
833 if (pedantic)
834 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
835 return 033;
837 case '?':
838 return c;
840 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
841 case '(':
842 case '{':
843 case '[':
844 /* `\%' is used to prevent SCCS from getting confused. */
845 case '%':
846 if (pedantic)
847 pedwarn ("non-ANSI escape sequence `\\%c'", c);
848 return c;
850 if (c >= 040 && c < 0177)
851 pedwarn ("unknown escape sequence `\\%c'", c);
852 else
853 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
854 return c;
857 void
858 yyerror (string)
859 char *string;
861 char buf[200];
863 strcpy (buf, string);
865 /* We can't print string and character constants well
866 because the token_buffer contains the result of processing escapes. */
867 if (end_of_file)
868 strcat (buf, " at end of input");
869 else if (token_buffer[0] == 0)
870 strcat (buf, " at null character");
871 else if (token_buffer[0] == '"')
872 strcat (buf, " before string constant");
873 else if (token_buffer[0] == '\'')
874 strcat (buf, " before character constant");
875 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
876 sprintf (buf + strlen (buf), " before character 0%o",
877 (unsigned char) token_buffer[0]);
878 else
879 strcat (buf, " before `%s'");
881 error (buf, token_buffer);
884 #if 0
886 struct try_type
888 tree *node_var;
889 char unsigned_flag;
890 char long_flag;
891 char long_long_flag;
894 struct try_type type_sequence[] =
896 { &integer_type_node, 0, 0, 0},
897 { &unsigned_type_node, 1, 0, 0},
898 { &long_integer_type_node, 0, 1, 0},
899 { &long_unsigned_type_node, 1, 1, 0},
900 { &long_long_integer_type_node, 0, 1, 1},
901 { &long_long_unsigned_type_node, 1, 1, 1}
903 #endif /* 0 */
906 yylex ()
908 register int c;
909 register char *p;
910 register int value;
911 int wide_flag = 0;
912 int objc_flag = 0;
914 if (nextchar >= 0)
915 c = nextchar, nextchar = -1;
916 else
917 c = getc (finput);
919 /* Effectively do c = skip_white_space (c)
920 but do it faster in the usual cases. */
921 while (1)
922 switch (c)
924 case ' ':
925 case '\t':
926 case '\f':
927 case '\v':
928 case '\b':
929 c = getc (finput);
930 break;
932 case '\r':
933 /* Call skip_white_space so we can warn if appropriate. */
935 case '\n':
936 case '/':
937 case '\\':
938 c = skip_white_space (c);
939 default:
940 goto found_nonwhite;
942 found_nonwhite:
944 token_buffer[0] = c;
945 token_buffer[1] = 0;
947 /* yylloc.first_line = lineno; */
949 switch (c)
951 case EOF:
952 end_of_file = 1;
953 token_buffer[0] = 0;
954 value = ENDFILE;
955 break;
957 case '$':
958 if (dollars_in_ident)
959 goto letter;
960 return '$';
962 case 'L':
963 /* Capital L may start a wide-string or wide-character constant. */
965 register int c = getc (finput);
966 if (c == '\'')
968 wide_flag = 1;
969 goto char_constant;
971 if (c == '"')
973 wide_flag = 1;
974 goto string_constant;
976 ungetc (c, finput);
978 goto letter;
980 case '@':
981 if (!doing_objc_thang)
983 value = c;
984 break;
986 else
988 /* '@' may start a constant string object. */
989 register int c = getc(finput);
990 if (c == '"')
992 objc_flag = 1;
993 goto string_constant;
995 ungetc(c, finput);
996 /* Fall through to treat '@' as the start of an indentifier. */
999 case 'A': case 'B': case 'C': case 'D': case 'E':
1000 case 'F': case 'G': case 'H': case 'I': case 'J':
1001 case 'K': case 'M': case 'N': case 'O':
1002 case 'P': case 'Q': case 'R': case 'S': case 'T':
1003 case 'U': case 'V': case 'W': case 'X': case 'Y':
1004 case 'Z':
1005 case 'a': case 'b': case 'c': case 'd': case 'e':
1006 case 'f': case 'g': case 'h': case 'i': case 'j':
1007 case 'k': case 'l': case 'm': case 'n': case 'o':
1008 case 'p': case 'q': case 'r': case 's': case 't':
1009 case 'u': case 'v': case 'w': case 'x': case 'y':
1010 case 'z':
1011 case '_':
1012 letter:
1013 p = token_buffer;
1014 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1016 /* Make sure this char really belongs in an identifier. */
1017 if (c == '@' && ! doing_objc_thang)
1018 break;
1019 if (c == '$' && ! dollars_in_ident)
1020 break;
1022 if (p >= token_buffer + maxtoken)
1023 p = extend_token_buffer (p);
1025 *p++ = c;
1026 c = getc (finput);
1029 *p = 0;
1030 nextchar = c;
1032 value = IDENTIFIER;
1033 yylval.itype = 0;
1035 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1038 register struct resword *ptr;
1040 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1042 if (ptr->rid)
1043 yylval.ttype = ridpointers[(int) ptr->rid];
1044 value = (int) ptr->token;
1046 /* Only return OBJECTNAME if it is a typedef. */
1047 if (doing_objc_thang && value == OBJECTNAME)
1049 lastiddecl = lookup_name(yylval.ttype);
1051 if (lastiddecl == NULL_TREE
1052 || TREE_CODE (lastiddecl) != TYPE_DECL)
1053 value = IDENTIFIER;
1056 /* Even if we decided to recognize asm, still perhaps warn. */
1057 if (pedantic
1058 && (value == ASM_KEYWORD || value == TYPEOF
1059 || ptr->rid == RID_INLINE)
1060 && token_buffer[0] != '_')
1061 pedwarn ("ANSI does not permit the keyword `%s'",
1062 token_buffer);
1066 /* If we did not find a keyword, look for an identifier
1067 (or a typename). */
1069 if (value == IDENTIFIER)
1071 if (token_buffer[0] == '@')
1072 error("invalid identifier `%s'", token_buffer);
1074 yylval.ttype = get_identifier (token_buffer);
1075 lastiddecl = lookup_name (yylval.ttype);
1077 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1078 value = TYPENAME;
1079 /* A user-invisible read-only initialized variable
1080 should be replaced by its value.
1081 We handle only strings since that's the only case used in C. */
1082 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1083 && DECL_IGNORED_P (lastiddecl)
1084 && TREE_READONLY (lastiddecl)
1085 && DECL_INITIAL (lastiddecl) != 0
1086 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1088 tree stringval = DECL_INITIAL (lastiddecl);
1090 /* Copy the string value so that we won't clobber anything
1091 if we put something in the TREE_CHAIN of this one. */
1092 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1093 TREE_STRING_POINTER (stringval));
1094 value = STRING;
1096 else if (doing_objc_thang)
1098 tree objc_interface_decl = is_class_name (yylval.ttype);
1100 if (objc_interface_decl)
1102 value = CLASSNAME;
1103 yylval.ttype = objc_interface_decl;
1108 break;
1110 case '0': case '1': case '2': case '3': case '4':
1111 case '5': case '6': case '7': case '8': case '9':
1112 case '.':
1114 int base = 10;
1115 int count = 0;
1116 int largest_digit = 0;
1117 int numdigits = 0;
1118 /* for multi-precision arithmetic,
1119 we actually store only HOST_BITS_PER_CHAR bits in each part.
1120 The number of parts is chosen so as to be sufficient to hold
1121 the enough bits to fit into the two HOST_WIDE_INTs that contain
1122 the integer value (this is always at least as many bits as are
1123 in a target `long long' value, but may be wider). */
1124 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1125 int parts[TOTAL_PARTS];
1126 int overflow = 0;
1128 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1129 = NOT_FLOAT;
1131 for (count = 0; count < TOTAL_PARTS; count++)
1132 parts[count] = 0;
1134 p = token_buffer;
1135 *p++ = c;
1137 if (c == '0')
1139 *p++ = (c = getc (finput));
1140 if ((c == 'x') || (c == 'X'))
1142 base = 16;
1143 *p++ = (c = getc (finput));
1145 /* Leading 0 forces octal unless the 0 is the only digit. */
1146 else if (c >= '0' && c <= '9')
1148 base = 8;
1149 numdigits++;
1151 else
1152 numdigits++;
1155 /* Read all the digits-and-decimal-points. */
1157 while (c == '.'
1158 || (isalnum (c) && c != 'l' && c != 'L'
1159 && c != 'u' && c != 'U'
1160 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1161 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1163 if (c == '.')
1165 if (base == 16)
1166 error ("floating constant may not be in radix 16");
1167 if (floatflag == TOO_MANY_POINTS)
1168 /* We have already emitted an error. Don't need another. */
1170 else if (floatflag == AFTER_POINT)
1172 error ("malformed floating constant");
1173 floatflag = TOO_MANY_POINTS;
1174 /* Avoid another error from atof by forcing all characters
1175 from here on to be ignored. */
1176 p[-1] = '\0';
1178 else
1179 floatflag = AFTER_POINT;
1181 base = 10;
1182 *p++ = c = getc (finput);
1183 /* Accept '.' as the start of a floating-point number
1184 only when it is followed by a digit.
1185 Otherwise, unread the following non-digit
1186 and use the '.' as a structural token. */
1187 if (p == token_buffer + 2 && !isdigit (c))
1189 if (c == '.')
1191 c = getc (finput);
1192 if (c == '.')
1194 *p++ = c;
1195 *p = 0;
1196 return ELLIPSIS;
1198 error ("parse error at `..'");
1200 ungetc (c, finput);
1201 token_buffer[1] = 0;
1202 value = '.';
1203 goto done;
1206 else
1208 /* It is not a decimal point.
1209 It should be a digit (perhaps a hex digit). */
1211 if (isdigit (c))
1213 c = c - '0';
1215 else if (base <= 10)
1217 if (c == 'e' || c == 'E')
1219 base = 10;
1220 floatflag = AFTER_POINT;
1221 break; /* start of exponent */
1223 error ("nondigits in number and not hexadecimal");
1224 c = 0;
1226 else if (c >= 'a')
1228 c = c - 'a' + 10;
1230 else
1232 c = c - 'A' + 10;
1234 if (c >= largest_digit)
1235 largest_digit = c;
1236 numdigits++;
1238 for (count = 0; count < TOTAL_PARTS; count++)
1240 parts[count] *= base;
1241 if (count)
1243 parts[count]
1244 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1245 parts[count-1]
1246 &= (1 << HOST_BITS_PER_CHAR) - 1;
1248 else
1249 parts[0] += c;
1252 /* If the extra highest-order part ever gets anything in it,
1253 the number is certainly too big. */
1254 if (parts[TOTAL_PARTS - 1] != 0)
1255 overflow = 1;
1257 if (p >= token_buffer + maxtoken - 3)
1258 p = extend_token_buffer (p);
1259 *p++ = (c = getc (finput));
1263 if (numdigits == 0)
1264 error ("numeric constant with no digits");
1266 if (largest_digit >= base)
1267 error ("numeric constant contains digits beyond the radix");
1269 /* Remove terminating char from the token buffer and delimit the string */
1270 *--p = 0;
1272 if (floatflag != NOT_FLOAT)
1274 tree type = long_double_type_node;
1275 int garbage_chars = 0, exceeds_double = 0;
1276 int imag = 0;
1277 REAL_VALUE_TYPE value;
1278 jmp_buf handler;
1280 /* Read explicit exponent if any, and put it in tokenbuf. */
1282 if ((c == 'e') || (c == 'E'))
1284 if (p >= token_buffer + maxtoken - 3)
1285 p = extend_token_buffer (p);
1286 *p++ = c;
1287 c = getc (finput);
1288 if ((c == '+') || (c == '-'))
1290 *p++ = c;
1291 c = getc (finput);
1293 if (! isdigit (c))
1294 error ("floating constant exponent has no digits");
1295 while (isdigit (c))
1297 if (p >= token_buffer + maxtoken - 3)
1298 p = extend_token_buffer (p);
1299 *p++ = c;
1300 c = getc (finput);
1304 *p = 0;
1305 errno = 0;
1307 /* Convert string to a double, checking for overflow. */
1308 if (setjmp (handler))
1310 error ("floating constant out of range");
1311 value = dconst0;
1313 else
1315 int fflag = 0, lflag = 0;
1316 /* Copy token_buffer now, while it has just the number
1317 and not the suffixes; once we add `f' or `i',
1318 REAL_VALUE_ATOF may not work any more. */
1319 char *copy = (char *) alloca (p - token_buffer + 1);
1320 bcopy (token_buffer, copy, p - token_buffer + 1);
1322 set_float_handler (handler);
1324 while (1)
1326 int lose = 0;
1328 /* Read the suffixes to choose a data type. */
1329 switch (c)
1331 case 'f': case 'F':
1332 if (fflag)
1333 error ("more than one `f' in numeric constant");
1334 fflag = 1;
1335 break;
1337 case 'l': case 'L':
1338 if (lflag)
1339 error ("more than one `l' in numeric constant");
1340 lflag = 1;
1341 break;
1343 case 'i': case 'I':
1344 if (imag)
1345 error ("more than one `i' or `j' in numeric constant");
1346 else if (pedantic)
1347 pedwarn ("ANSI C forbids imaginary numeric constants");
1348 imag = 1;
1349 break;
1351 default:
1352 lose = 1;
1355 if (lose)
1356 break;
1358 if (p >= token_buffer + maxtoken - 3)
1359 p = extend_token_buffer (p);
1360 *p++ = c;
1361 *p = 0;
1362 c = getc (finput);
1365 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1366 tells the desired precision of the binary result
1367 of decimal-to-binary conversion. */
1369 if (fflag)
1371 if (lflag)
1372 error ("both `f' and `l' in floating constant");
1374 type = float_type_node;
1375 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1376 /* A diagnostic is required here by some ANSI C testsuites.
1377 This is not pedwarn, become some people don't want
1378 an error for this. */
1379 if (REAL_VALUE_ISINF (value) && pedantic)
1380 warning ("floating point number exceeds range of `float'");
1382 else if (lflag)
1384 type = long_double_type_node;
1385 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1386 if (REAL_VALUE_ISINF (value) && pedantic)
1387 warning ("floating point number exceeds range of `long double'");
1389 else
1391 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1392 if (REAL_VALUE_ISINF (value) && pedantic)
1393 warning ("floating point number exceeds range of `double'");
1396 set_float_handler (NULL_PTR);
1398 #ifdef ERANGE
1399 if (errno == ERANGE && !flag_traditional && pedantic)
1401 /* ERANGE is also reported for underflow,
1402 so test the value to distinguish overflow from that. */
1403 if (REAL_VALUES_LESS (dconst1, value)
1404 || REAL_VALUES_LESS (value, dconstm1))
1406 warning ("floating point number exceeds range of `double'");
1407 exceeds_double = 1;
1410 #endif
1411 garbage_chars = 0;
1412 while (isalnum (c) || c == '.' || c == '_'
1413 || (!flag_traditional && (c == '+' || c == '-')
1414 && (p[-1] == 'e' || p[-1] == 'E')))
1416 if (p >= token_buffer + maxtoken - 3)
1417 p = extend_token_buffer (p);
1418 *p++ = c;
1419 c = getc (finput);
1420 garbage_chars++;
1422 if (garbage_chars > 0)
1423 error ("garbage at end of number");
1425 /* If the result is not a number, assume it must have been
1426 due to some error message above, so silently convert
1427 it to a zero. */
1428 if (REAL_VALUE_ISNAN (value))
1429 value = dconst0;
1431 /* Create a node with determined type and value. */
1432 if (imag)
1433 yylval.ttype = build_complex (convert (type, integer_zero_node),
1434 build_real (type, value));
1435 else
1436 yylval.ttype = build_real (type, value);
1438 ungetc (c, finput);
1439 *p = 0;
1441 else
1443 tree traditional_type, ansi_type, type;
1444 HOST_WIDE_INT high, low;
1445 int spec_unsigned = 0;
1446 int spec_long = 0;
1447 int spec_long_long = 0;
1448 int spec_imag = 0;
1449 int bytes, warn, i;
1451 while (1)
1453 if (c == 'u' || c == 'U')
1455 if (spec_unsigned)
1456 error ("two `u's in integer constant");
1457 spec_unsigned = 1;
1459 else if (c == 'l' || c == 'L')
1461 if (spec_long)
1463 if (spec_long_long)
1464 error ("three `l's in integer constant");
1465 else if (pedantic)
1466 pedwarn ("ANSI C forbids long long integer constants");
1467 spec_long_long = 1;
1469 spec_long = 1;
1471 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1473 if (spec_imag)
1474 error ("more than one `i' or `j' in numeric constant");
1475 else if (pedantic)
1476 pedwarn ("ANSI C forbids imaginary numeric constants");
1477 spec_imag = 1;
1479 else
1481 if (isalnum (c) || c == '.' || c == '_'
1482 || (!flag_traditional && (c == '+' || c == '-')
1483 && (p[-1] == 'e' || p[-1] == 'E')))
1485 error ("garbage at end of number");
1486 while (isalnum (c) || c == '.' || c == '_'
1487 || (!flag_traditional && (c == '+' || c == '-')
1488 && (p[-1] == 'e' || p[-1] == 'E')))
1490 if (p >= token_buffer + maxtoken - 3)
1491 p = extend_token_buffer (p);
1492 *p++ = c;
1493 c = getc (finput);
1496 break;
1498 if (p >= token_buffer + maxtoken - 3)
1499 p = extend_token_buffer (p);
1500 *p++ = c;
1501 c = getc (finput);
1504 ungetc (c, finput);
1506 /* If the constant is not long long and it won't fit in an
1507 unsigned long, or if the constant is long long and won't fit
1508 in an unsigned long long, then warn that the constant is out
1509 of range. */
1511 /* ??? This assumes that long long and long integer types are
1512 a multiple of 8 bits. This better than the original code
1513 though which assumed that long was exactly 32 bits and long
1514 long was exactly 64 bits. */
1516 if (spec_long_long)
1517 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1518 else
1519 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1521 warn = overflow;
1522 for (i = bytes; i < TOTAL_PARTS; i++)
1523 if (parts[i])
1524 warn = 1;
1525 if (warn)
1526 pedwarn ("integer constant out of range");
1528 /* This is simplified by the fact that our constant
1529 is always positive. */
1531 high = low = 0;
1533 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1535 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1536 / HOST_BITS_PER_CHAR)]
1537 << (i * HOST_BITS_PER_CHAR));
1538 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1541 yylval.ttype = build_int_2 (low, high);
1542 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1544 /* If warn_traditional, calculate both the ANSI type and the
1545 traditional type, then see if they disagree.
1546 Otherwise, calculate only the type for the dialect in use. */
1547 if (warn_traditional || flag_traditional)
1549 /* Calculate the traditional type. */
1550 /* Traditionally, any constant is signed;
1551 but if unsigned is specified explicitly, obey that.
1552 Use the smallest size with the right number of bits,
1553 except for one special case with decimal constants. */
1554 if (! spec_long && base != 10
1555 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1556 traditional_type = (spec_unsigned ? unsigned_type_node
1557 : integer_type_node);
1558 /* A decimal constant must be long
1559 if it does not fit in type int.
1560 I think this is independent of whether
1561 the constant is signed. */
1562 else if (! spec_long && base == 10
1563 && int_fits_type_p (yylval.ttype, integer_type_node))
1564 traditional_type = (spec_unsigned ? unsigned_type_node
1565 : integer_type_node);
1566 else if (! spec_long_long)
1567 traditional_type = (spec_unsigned ? long_unsigned_type_node
1568 : long_integer_type_node);
1569 else
1570 traditional_type = (spec_unsigned
1571 ? long_long_unsigned_type_node
1572 : long_long_integer_type_node);
1574 if (warn_traditional || ! flag_traditional)
1576 /* Calculate the ANSI type. */
1577 if (! spec_long && ! spec_unsigned
1578 && int_fits_type_p (yylval.ttype, integer_type_node))
1579 ansi_type = integer_type_node;
1580 else if (! spec_long && (base != 10 || spec_unsigned)
1581 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1582 ansi_type = unsigned_type_node;
1583 else if (! spec_unsigned && !spec_long_long
1584 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1585 ansi_type = long_integer_type_node;
1586 else if (! spec_long_long)
1587 ansi_type = long_unsigned_type_node;
1588 else if (! spec_unsigned
1589 /* Verify value does not overflow into sign bit. */
1590 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
1591 && int_fits_type_p (yylval.ttype,
1592 long_long_integer_type_node))
1593 ansi_type = long_long_integer_type_node;
1594 else
1595 ansi_type = long_long_unsigned_type_node;
1598 type = flag_traditional ? traditional_type : ansi_type;
1600 if (warn_traditional && traditional_type != ansi_type)
1602 if (TYPE_PRECISION (traditional_type)
1603 != TYPE_PRECISION (ansi_type))
1604 warning ("width of integer constant changes with -traditional");
1605 else if (TREE_UNSIGNED (traditional_type)
1606 != TREE_UNSIGNED (ansi_type))
1607 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1608 else
1609 warning ("width of integer constant may change on other systems with -traditional");
1612 if (!flag_traditional && !int_fits_type_p (yylval.ttype, type)
1613 && !warn)
1614 pedwarn ("integer constant out of range");
1616 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1617 warning ("decimal constant is so large that it is unsigned");
1619 if (spec_imag)
1621 if (TYPE_PRECISION (type)
1622 <= TYPE_PRECISION (integer_type_node))
1623 yylval.ttype
1624 = build_complex (integer_zero_node,
1625 convert (integer_type_node, yylval.ttype));
1626 else
1627 error ("complex integer constant is too wide for `complex int'");
1629 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1630 /* The traditional constant 0x80000000 is signed
1631 but doesn't fit in the range of int.
1632 This will change it to -0x80000000, which does fit. */
1634 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1635 yylval.ttype = convert (type, yylval.ttype);
1636 TREE_OVERFLOW (yylval.ttype)
1637 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1639 else
1640 TREE_TYPE (yylval.ttype) = type;
1642 *p = 0;
1645 value = CONSTANT; break;
1648 case '\'':
1649 char_constant:
1651 register int result = 0;
1652 register int num_chars = 0;
1653 unsigned width = TYPE_PRECISION (char_type_node);
1654 int max_chars;
1656 if (wide_flag)
1658 width = WCHAR_TYPE_SIZE;
1659 #ifdef MULTIBYTE_CHARS
1660 max_chars = MB_CUR_MAX;
1661 #else
1662 max_chars = 1;
1663 #endif
1665 else
1666 max_chars = TYPE_PRECISION (integer_type_node) / width;
1668 while (1)
1670 tryagain:
1672 c = getc (finput);
1674 if (c == '\'' || c == EOF)
1675 break;
1677 if (c == '\\')
1679 int ignore = 0;
1680 c = readescape (&ignore);
1681 if (ignore)
1682 goto tryagain;
1683 if (width < HOST_BITS_PER_INT
1684 && (unsigned) c >= (1 << width))
1685 pedwarn ("escape sequence out of range for character");
1686 #ifdef MAP_CHARACTER
1687 if (isprint (c))
1688 c = MAP_CHARACTER (c);
1689 #endif
1691 else if (c == '\n')
1693 if (pedantic)
1694 pedwarn ("ANSI C forbids newline in character constant");
1695 lineno++;
1697 #ifdef MAP_CHARACTER
1698 else
1699 c = MAP_CHARACTER (c);
1700 #endif
1702 num_chars++;
1703 if (num_chars > maxtoken - 4)
1704 extend_token_buffer (token_buffer);
1706 token_buffer[num_chars] = c;
1708 /* Merge character into result; ignore excess chars. */
1709 if (num_chars < max_chars + 1)
1711 if (width < HOST_BITS_PER_INT)
1712 result = (result << width) | (c & ((1 << width) - 1));
1713 else
1714 result = c;
1718 token_buffer[num_chars + 1] = '\'';
1719 token_buffer[num_chars + 2] = 0;
1721 if (c != '\'')
1722 error ("malformatted character constant");
1723 else if (num_chars == 0)
1724 error ("empty character constant");
1725 else if (num_chars > max_chars)
1727 num_chars = max_chars;
1728 error ("character constant too long");
1730 else if (num_chars != 1 && ! flag_traditional)
1731 warning ("multi-character character constant");
1733 /* If char type is signed, sign-extend the constant. */
1734 if (! wide_flag)
1736 int num_bits = num_chars * width;
1737 if (num_bits == 0)
1738 /* We already got an error; avoid invalid shift. */
1739 yylval.ttype = build_int_2 (0, 0);
1740 else if (TREE_UNSIGNED (char_type_node)
1741 || ((result >> (num_bits - 1)) & 1) == 0)
1742 yylval.ttype
1743 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1744 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1746 else
1747 yylval.ttype
1748 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1749 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1750 -1);
1751 TREE_TYPE (yylval.ttype) = integer_type_node;
1753 else
1755 #ifdef MULTIBYTE_CHARS
1756 /* Set the initial shift state and convert the next sequence. */
1757 result = 0;
1758 /* In all locales L'\0' is zero and mbtowc will return zero,
1759 so don't use it. */
1760 if (num_chars > 1
1761 || (num_chars == 1 && token_buffer[1] != '\0'))
1763 wchar_t wc;
1764 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1765 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1766 result = wc;
1767 else
1768 warning ("Ignoring invalid multibyte character");
1770 #endif
1771 yylval.ttype = build_int_2 (result, 0);
1772 TREE_TYPE (yylval.ttype) = wchar_type_node;
1775 value = CONSTANT;
1776 break;
1779 case '"':
1780 string_constant:
1782 c = getc (finput);
1783 p = token_buffer + 1;
1785 while (c != '"' && c >= 0)
1787 if (c == '\\')
1789 int ignore = 0;
1790 c = readescape (&ignore);
1791 if (ignore)
1792 goto skipnewline;
1793 if (!wide_flag
1794 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1795 && c >= (1 << TYPE_PRECISION (char_type_node)))
1796 pedwarn ("escape sequence out of range for character");
1798 else if (c == '\n')
1800 if (pedantic)
1801 pedwarn ("ANSI C forbids newline in string constant");
1802 lineno++;
1805 if (p == token_buffer + maxtoken)
1806 p = extend_token_buffer (p);
1807 *p++ = c;
1809 skipnewline:
1810 c = getc (finput);
1812 *p = 0;
1814 if (c < 0)
1815 error ("Unterminated string constant");
1817 /* We have read the entire constant.
1818 Construct a STRING_CST for the result. */
1820 if (wide_flag)
1822 /* If this is a L"..." wide-string, convert the multibyte string
1823 to a wide character string. */
1824 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1825 int len;
1827 #ifdef MULTIBYTE_CHARS
1828 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1829 if (len < 0 || len >= (p - token_buffer))
1831 warning ("Ignoring invalid multibyte string");
1832 len = 0;
1834 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1835 #else
1837 union { long l; char c[sizeof (long)]; } u;
1838 int big_endian;
1839 char *wp, *cp;
1841 /* Determine whether host is little or big endian. */
1842 u.l = 1;
1843 big_endian = u.c[sizeof (long) - 1];
1844 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1846 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1847 for (cp = token_buffer + 1; cp < p; cp++)
1848 *wp = *cp, wp += WCHAR_BYTES;
1849 len = p - token_buffer - 1;
1851 #endif
1852 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1853 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1854 value = STRING;
1856 else if (objc_flag)
1858 extern tree build_objc_string();
1859 /* Return an Objective-C @"..." constant string object. */
1860 yylval.ttype = build_objc_string (p - token_buffer,
1861 token_buffer + 1);
1862 TREE_TYPE (yylval.ttype) = char_array_type_node;
1863 value = OBJC_STRING;
1865 else
1867 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
1868 TREE_TYPE (yylval.ttype) = char_array_type_node;
1869 value = STRING;
1872 *p++ = '"';
1873 *p = 0;
1875 break;
1878 case '+':
1879 case '-':
1880 case '&':
1881 case '|':
1882 case '<':
1883 case '>':
1884 case '*':
1885 case '/':
1886 case '%':
1887 case '^':
1888 case '!':
1889 case '=':
1891 register int c1;
1893 combine:
1895 switch (c)
1897 case '+':
1898 yylval.code = PLUS_EXPR; break;
1899 case '-':
1900 yylval.code = MINUS_EXPR; break;
1901 case '&':
1902 yylval.code = BIT_AND_EXPR; break;
1903 case '|':
1904 yylval.code = BIT_IOR_EXPR; break;
1905 case '*':
1906 yylval.code = MULT_EXPR; break;
1907 case '/':
1908 yylval.code = TRUNC_DIV_EXPR; break;
1909 case '%':
1910 yylval.code = TRUNC_MOD_EXPR; break;
1911 case '^':
1912 yylval.code = BIT_XOR_EXPR; break;
1913 case LSHIFT:
1914 yylval.code = LSHIFT_EXPR; break;
1915 case RSHIFT:
1916 yylval.code = RSHIFT_EXPR; break;
1917 case '<':
1918 yylval.code = LT_EXPR; break;
1919 case '>':
1920 yylval.code = GT_EXPR; break;
1923 token_buffer[1] = c1 = getc (finput);
1924 token_buffer[2] = 0;
1926 if (c1 == '=')
1928 switch (c)
1930 case '<':
1931 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
1932 case '>':
1933 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
1934 case '!':
1935 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
1936 case '=':
1937 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
1939 value = ASSIGN; goto done;
1941 else if (c == c1)
1942 switch (c)
1944 case '+':
1945 value = PLUSPLUS; goto done;
1946 case '-':
1947 value = MINUSMINUS; goto done;
1948 case '&':
1949 value = ANDAND; goto done;
1950 case '|':
1951 value = OROR; goto done;
1952 case '<':
1953 c = LSHIFT;
1954 goto combine;
1955 case '>':
1956 c = RSHIFT;
1957 goto combine;
1959 else if ((c == '-') && (c1 == '>'))
1960 { value = POINTSAT; goto done; }
1961 ungetc (c1, finput);
1962 token_buffer[1] = 0;
1964 if ((c == '<') || (c == '>'))
1965 value = ARITHCOMPARE;
1966 else value = c;
1967 goto done;
1970 case 0:
1971 /* Don't make yyparse think this is eof. */
1972 value = 1;
1973 break;
1975 default:
1976 value = c;
1979 done:
1980 /* yylloc.last_line = lineno; */
1982 return value;
1985 /* Sets the value of the 'yydebug' variable to VALUE.
1986 This is a function so we don't have to have YYDEBUG defined
1987 in order to build the compiler. */
1989 void
1990 set_yydebug (value)
1991 int value;
1993 #if YYDEBUG != 0
1994 yydebug = value;
1995 #else
1996 warning ("YYDEBUG not defined.");
1997 #endif