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)
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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
38 #ifdef MULTIBYTE_CHARS
47 /* The elements of `ridpointers' are identifier nodes
48 for the reserved type names and storage classes.
49 It is indexed by a RID_... value. */
50 tree ridpointers[(int) RID_MAX];
52 /* Cause the `yydebug' variable to be defined. */
55 /* the declaration found for the last IDENTIFIER token read in.
56 yylex must look this up to detect typedefs, which get token type TYPENAME,
57 so it is left around in case the identifier is not a typedef but is
58 used in a context which makes it a reference to a variable. */
61 /* Nonzero enables objc features. */
65 extern tree is_class_name ();
69 /* File used for outputting assembler code. */
70 extern FILE *asm_out_file;
72 #ifndef WCHAR_TYPE_SIZE
74 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
76 #define WCHAR_TYPE_SIZE BITS_PER_WORD
80 /* Number of bytes in a wide character. */
81 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
83 static int maxtoken; /* Current nominal length of token buffer. */
84 char *token_buffer; /* Pointer to token buffer.
85 Actual allocated length is maxtoken + 2.
86 This is not static because objc-parse.y uses it. */
88 /* Nonzero if end-of-file has been seen on input. */
89 static int end_of_file;
91 /* Buffered-back input character; faster than using ungetc. */
92 static int nextchar = -1;
96 /* Do not insert generated code into the source, instead, include it.
97 This allows us to build gcc automatically even for targets that
98 need to add or modify the reserved keyword lists. */
101 /* Return something to represent absolute declarators containing a *.
102 TARGET is the absolute declarator that the * contains.
103 TYPE_QUALS is a list of modifiers such as const or volatile
104 to apply to the pointer type, represented as identifiers.
106 We return an INDIRECT_REF whose "contents" are TARGET
107 and whose type is the modifier list. */
110 make_pointer_declarator (type_quals, target)
111 tree type_quals, target;
113 return build1 (INDIRECT_REF, type_quals, target);
117 forget_protocol_qualifiers ()
119 int i, n = sizeof wordlist / sizeof (struct resword);
121 for (i = 0; i < n; i++)
122 if ((int) wordlist[i].rid >= (int) RID_IN
123 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
124 wordlist[i].name = "";
128 remember_protocol_qualifiers ()
130 int i, n = sizeof wordlist / sizeof (struct resword);
132 for (i = 0; i < n; i++)
133 if (wordlist[i].rid == RID_IN)
134 wordlist[i].name = "in";
135 else if (wordlist[i].rid == RID_OUT)
136 wordlist[i].name = "out";
137 else if (wordlist[i].rid == RID_INOUT)
138 wordlist[i].name = "inout";
139 else if (wordlist[i].rid == RID_BYCOPY)
140 wordlist[i].name = "bycopy";
141 else if (wordlist[i].rid == RID_ONEWAY)
142 wordlist[i].name = "oneway";
148 /* Make identifier nodes long enough for the language-specific slots. */
149 set_identifier_size (sizeof (struct lang_identifier));
151 /* Start it at 0, because check_newline is called at the very beginning
152 and will increment it to 1. */
155 #ifdef MULTIBYTE_CHARS
156 /* Change to the native locale for multibyte conversions. */
157 setlocale (LC_CTYPE, "");
161 token_buffer = (char *) xmalloc (maxtoken + 2);
163 ridpointers[(int) RID_INT] = get_identifier ("int");
164 ridpointers[(int) RID_CHAR] = get_identifier ("char");
165 ridpointers[(int) RID_VOID] = get_identifier ("void");
166 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
167 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
168 ridpointers[(int) RID_SHORT] = get_identifier ("short");
169 ridpointers[(int) RID_LONG] = get_identifier ("long");
170 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
171 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
172 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
173 ridpointers[(int) RID_CONST] = get_identifier ("const");
174 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
175 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
176 ridpointers[(int) RID_STATIC] = get_identifier ("static");
177 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
178 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
179 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
180 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
181 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
182 ridpointers[(int) RID_ID] = get_identifier ("id");
183 ridpointers[(int) RID_IN] = get_identifier ("in");
184 ridpointers[(int) RID_OUT] = get_identifier ("out");
185 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
186 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
187 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
188 forget_protocol_qualifiers();
190 /* Some options inhibit certain reserved words.
191 Clear those words out of the hash table so they won't be recognized. */
192 #define UNSET_RESERVED_WORD(STRING) \
193 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
194 if (s) s->name = ""; } while (0)
196 if (! doing_objc_thang)
197 UNSET_RESERVED_WORD ("id");
199 if (flag_traditional)
201 UNSET_RESERVED_WORD ("const");
202 UNSET_RESERVED_WORD ("volatile");
203 UNSET_RESERVED_WORD ("typeof");
204 UNSET_RESERVED_WORD ("signed");
205 UNSET_RESERVED_WORD ("inline");
206 UNSET_RESERVED_WORD ("iterator");
207 UNSET_RESERVED_WORD ("complex");
211 UNSET_RESERVED_WORD ("asm");
212 UNSET_RESERVED_WORD ("typeof");
213 UNSET_RESERVED_WORD ("inline");
214 UNSET_RESERVED_WORD ("iterator");
215 UNSET_RESERVED_WORD ("complex");
220 reinit_parse_for_function ()
224 /* Function used when yydebug is set, to print a token in more detail. */
227 yyprint (file, yychar, yylval)
239 if (IDENTIFIER_POINTER (t))
240 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
245 if (TREE_CODE (t) == INTEGER_CST)
247 #if HOST_BITS_PER_WIDE_INT == 64
248 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
254 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
260 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
266 /* If C is not whitespace, return C.
267 Otherwise skip whitespace and return first nonwhite char read. */
273 static int newline_warning = 0;
279 /* We don't recognize comments here, because
280 cpp output can include / and * consecutively as operators.
281 Also, there's no need, since cpp removes all comments. */
284 c = check_newline ();
296 /* ANSI C says the effects of a carriage return in a source file
298 if (pedantic && !newline_warning)
300 warning ("carriage return in source file");
301 warning ("(we only warn about the first carriage return)");
312 error ("stray '\\' in program");
322 /* Skips all of the white space at the current location in the input file.
323 Must use and reset nextchar if it has the next character. */
326 position_after_white_space ()
331 c = nextchar, nextchar = -1;
335 ungetc (skip_white_space (c), finput);
338 /* Make the token buffer longer, preserving the data in it.
339 P should point to just beyond the last valid character in the old buffer.
340 The value we return is a pointer to the new buffer
341 at a place corresponding to P. */
344 extend_token_buffer (p)
347 int offset = p - token_buffer;
349 maxtoken = maxtoken * 2 + 10;
350 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
352 return token_buffer + offset;
355 /* At the beginning of a line, increment the line number
356 and process any #-directive on this line.
357 If the line is a #-directive, read the entire line and return a newline.
358 Otherwise, return the line's first non-whitespace character. */
368 /* Read first nonwhite char on the line. */
371 while (c == ' ' || c == '\t')
376 /* If not #, return it so caller will use it. */
380 /* Read first nonwhite char after the `#'. */
383 while (c == ' ' || c == '\t')
386 /* If a letter follows, then if the word here is `line', skip
387 it and ignore it; otherwise, ignore the line, with an error
388 if the word isn't `pragma', `ident', `define', or `undef'. */
390 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
394 if (getc (finput) == 'r'
395 && getc (finput) == 'a'
396 && getc (finput) == 'g'
397 && getc (finput) == 'm'
398 && getc (finput) == 'a'
399 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
401 #ifdef HANDLE_SYSV_PRAGMA
402 return handle_sysv_pragma (finput, c);
403 #else /* !HANDLE_SYSV_PRAGMA */
405 HANDLE_PRAGMA (finput);
406 #endif /* HANDLE_PRAGMA */
408 #endif /* !HANDLE_SYSV_PRAGMA */
414 if (getc (finput) == 'e'
415 && getc (finput) == 'f'
416 && getc (finput) == 'i'
417 && getc (finput) == 'n'
418 && getc (finput) == 'e'
419 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
421 #ifdef DWARF_DEBUGGING_INFO
422 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
423 && (write_symbols == DWARF_DEBUG))
424 dwarfout_define (lineno, get_directive_line (finput));
425 #endif /* DWARF_DEBUGGING_INFO */
431 if (getc (finput) == 'n'
432 && getc (finput) == 'd'
433 && getc (finput) == 'e'
434 && getc (finput) == 'f'
435 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
437 #ifdef DWARF_DEBUGGING_INFO
438 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
439 && (write_symbols == DWARF_DEBUG))
440 dwarfout_undef (lineno, get_directive_line (finput));
441 #endif /* DWARF_DEBUGGING_INFO */
447 if (getc (finput) == 'i'
448 && getc (finput) == 'n'
449 && getc (finput) == 'e'
450 && ((c = getc (finput)) == ' ' || c == '\t'))
455 if (getc (finput) == 'd'
456 && getc (finput) == 'e'
457 && getc (finput) == 'n'
458 && getc (finput) == 't'
459 && ((c = getc (finput)) == ' ' || c == '\t'))
461 /* #ident. The pedantic warning is now in cccp.c. */
463 /* Here we have just seen `#ident '.
464 A string constant should follow. */
466 while (c == ' ' || c == '\t')
469 /* If no argument, ignore the line. */
476 || TREE_CODE (yylval.ttype) != STRING_CST)
478 error ("invalid #ident");
484 #ifdef ASM_OUTPUT_IDENT
485 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
489 /* Skip the rest of this line. */
494 error ("undefined or invalid # directive");
499 /* Here we have either `#line' or `# <nonletter>'.
500 In either case, it should be a line number; a digit should follow. */
502 while (c == ' ' || c == '\t')
505 /* If the # is the only nonwhite char on the line,
506 just ignore it. Check the new newline. */
510 /* Something follows the #; read a token. */
515 if (token == CONSTANT
516 && TREE_CODE (yylval.ttype) == INTEGER_CST)
518 int old_lineno = lineno;
520 /* subtract one, because it is the following line that
521 gets the specified number */
523 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
525 /* Is this the last nonwhite stuff on the line? */
527 while (c == ' ' || c == '\t')
531 /* No more: store the line number and check following line. */
537 /* More follows: it must be a string constant (filename). */
539 /* Read the string constant. */
542 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
544 error ("invalid #line");
549 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
550 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
553 /* Each change of file name
554 reinitializes whether we are now in a system header. */
555 in_system_header = 0;
557 if (main_input_filename == 0)
558 main_input_filename = input_filename;
560 /* Is this the last nonwhite stuff on the line? */
562 while (c == ' ' || c == '\t')
566 /* Update the name in the top element of input_file_stack. */
567 if (input_file_stack)
568 input_file_stack->name = input_filename;
577 /* `1' after file name means entering new file.
578 `2' after file name means just left a file. */
580 if (token == CONSTANT
581 && TREE_CODE (yylval.ttype) == INTEGER_CST)
583 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
585 /* Pushing to a new file. */
587 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
588 input_file_stack->line = old_lineno;
589 p->next = input_file_stack;
590 p->name = input_filename;
591 input_file_stack = p;
592 input_file_stack_tick++;
593 #ifdef DWARF_DEBUGGING_INFO
594 if (debug_info_level == DINFO_LEVEL_VERBOSE
595 && write_symbols == DWARF_DEBUG)
596 dwarfout_start_new_source_file (input_filename);
597 #endif /* DWARF_DEBUGGING_INFO */
601 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
603 /* Popping out of a file. */
604 if (input_file_stack->next)
606 struct file_stack *p = input_file_stack;
607 input_file_stack = p->next;
609 input_file_stack_tick++;
610 #ifdef DWARF_DEBUGGING_INFO
611 if (debug_info_level == DINFO_LEVEL_VERBOSE
612 && write_symbols == DWARF_DEBUG)
613 dwarfout_resume_previous_source_file (input_file_stack->line);
614 #endif /* DWARF_DEBUGGING_INFO */
617 error ("#-lines for entering and leaving files don't match");
623 /* Now that we've pushed or popped the input stack,
624 update the name in the top element. */
625 if (input_file_stack)
626 input_file_stack->name = input_filename;
628 /* If we have handled a `1' or a `2',
629 see if there is another number to read. */
632 /* Is this the last nonwhite stuff on the line? */
634 while (c == ' ' || c == '\t')
644 /* `3' after file name means this is a system header file. */
646 if (token == CONSTANT
647 && TREE_CODE (yylval.ttype) == INTEGER_CST
648 && TREE_INT_CST_LOW (yylval.ttype) == 3)
649 in_system_header = 1, used_up = 1;
653 /* Is this the last nonwhite stuff on the line? */
655 while (c == ' ' || c == '\t')
662 warning ("unrecognized text at end of #line");
665 error ("invalid #-line");
667 /* skip the rest of this line. */
671 while ((c = getc (finput)) != EOF && c != '\n');
675 #ifdef HANDLE_SYSV_PRAGMA
677 /* Handle a #pragma directive. INPUT is the current input stream,
678 and C is a character to reread. Processes the entire input line
679 and returns a character for the caller to reread: either \n or EOF. */
681 /* This function has to be in this file, in order to get at
685 handle_sysv_pragma (input, c)
691 while (c == ' ' || c == '\t')
693 if (c == '\n' || c == EOF)
695 handle_pragma_token (0, 0);
705 handle_pragma_token (token_buffer, yylval.ttype);
708 handle_pragma_token (token_buffer, 0);
711 c = nextchar, nextchar = -1;
717 #endif /* HANDLE_SYSV_PRAGMA */
719 #define ENDFILE -1 /* token that represents end-of-file */
721 /* Read an escape sequence, returning its equivalent as a character,
722 or store 1 in *ignore_ptr if it is backslash-newline. */
725 readescape (ignore_ptr)
728 register int c = getc (finput);
730 register unsigned count;
731 unsigned firstdig = 0;
737 if (warn_traditional)
738 warning ("the meaning of `\\x' varies with -traditional");
740 if (flag_traditional)
749 if (!(c >= 'a' && c <= 'f')
750 && !(c >= 'A' && c <= 'F')
751 && !(c >= '0' && c <= '9'))
757 if (c >= 'a' && c <= 'f')
758 code += c - 'a' + 10;
759 if (c >= 'A' && c <= 'F')
760 code += c - 'A' + 10;
761 if (c >= '0' && c <= '9')
763 if (code != 0 || count != 0)
772 error ("\\x used with no following hex digits");
774 /* Digits are all 0's. Ok. */
776 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
778 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
780 pedwarn ("hex escape out of range");
783 case '0': case '1': case '2': case '3': case '4':
784 case '5': case '6': case '7':
787 while ((c <= '7') && (c >= '0') && (count++ < 3))
789 code = (code * 8) + (c - '0');
795 case '\\': case '\'': case '"':
804 return TARGET_NEWLINE;
819 if (warn_traditional)
820 warning ("the meaning of `\\a' varies with -traditional");
822 if (flag_traditional)
827 #if 0 /* Vertical tab is present in common usage compilers. */
828 if (flag_traditional)
836 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
842 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
846 /* `\%' is used to prevent SCCS from getting confused. */
849 pedwarn ("non-ANSI escape sequence `\\%c'", c);
852 if (c >= 040 && c < 0177)
853 pedwarn ("unknown escape sequence `\\%c'", c);
855 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
865 strcpy (buf, string);
867 /* We can't print string and character constants well
868 because the token_buffer contains the result of processing escapes. */
870 strcat (buf, " at end of input");
871 else if (token_buffer[0] == 0)
872 strcat (buf, " at null character");
873 else if (token_buffer[0] == '"')
874 strcat (buf, " before string constant");
875 else if (token_buffer[0] == '\'')
876 strcat (buf, " before character constant");
877 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
878 sprintf (buf + strlen (buf), " before character 0%o",
879 (unsigned char) token_buffer[0]);
881 strcat (buf, " before `%s'");
883 error (buf, token_buffer);
896 struct try_type type_sequence[] =
898 { &integer_type_node, 0, 0, 0},
899 { &unsigned_type_node, 1, 0, 0},
900 { &long_integer_type_node, 0, 1, 0},
901 { &long_unsigned_type_node, 1, 1, 0},
902 { &long_long_integer_type_node, 0, 1, 1},
903 { &long_long_unsigned_type_node, 1, 1, 1}
917 c = nextchar, nextchar = -1;
921 /* Effectively do c = skip_white_space (c)
922 but do it faster in the usual cases. */
935 /* Call skip_white_space so we can warn if appropriate. */
940 c = skip_white_space (c);
949 /* yylloc.first_line = lineno; */
960 if (dollars_in_ident)
965 /* Capital L may start a wide-string or wide-character constant. */
967 register int c = getc (finput);
976 goto string_constant;
983 if (!doing_objc_thang)
990 /* '@' may start a constant string object. */
991 register int c = getc(finput);
995 goto string_constant;
998 /* Fall through to treat '@' as the start of an identifier. */
1001 case 'A': case 'B': case 'C': case 'D': case 'E':
1002 case 'F': case 'G': case 'H': case 'I': case 'J':
1003 case 'K': case 'M': case 'N': case 'O':
1004 case 'P': case 'Q': case 'R': case 'S': case 'T':
1005 case 'U': case 'V': case 'W': case 'X': case 'Y':
1007 case 'a': case 'b': case 'c': case 'd': case 'e':
1008 case 'f': case 'g': case 'h': case 'i': case 'j':
1009 case 'k': case 'l': case 'm': case 'n': case 'o':
1010 case 'p': case 'q': case 'r': case 's': case 't':
1011 case 'u': case 'v': case 'w': case 'x': case 'y':
1016 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1018 /* Make sure this char really belongs in an identifier. */
1019 if (c == '@' && ! doing_objc_thang)
1021 if (c == '$' && ! dollars_in_ident)
1024 if (p >= token_buffer + maxtoken)
1025 p = extend_token_buffer (p);
1037 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1040 register struct resword *ptr;
1042 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1045 yylval.ttype = ridpointers[(int) ptr->rid];
1046 value = (int) ptr->token;
1048 /* Only return OBJECTNAME if it is a typedef. */
1049 if (doing_objc_thang && value == OBJECTNAME)
1051 lastiddecl = lookup_name(yylval.ttype);
1053 if (lastiddecl == NULL_TREE
1054 || TREE_CODE (lastiddecl) != TYPE_DECL)
1058 /* Even if we decided to recognize asm, still perhaps warn. */
1060 && (value == ASM_KEYWORD || value == TYPEOF
1061 || ptr->rid == RID_INLINE)
1062 && token_buffer[0] != '_')
1063 pedwarn ("ANSI does not permit the keyword `%s'",
1068 /* If we did not find a keyword, look for an identifier
1071 if (value == IDENTIFIER)
1073 if (token_buffer[0] == '@')
1074 error("invalid identifier `%s'", token_buffer);
1076 yylval.ttype = get_identifier (token_buffer);
1077 lastiddecl = lookup_name (yylval.ttype);
1079 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1081 /* A user-invisible read-only initialized variable
1082 should be replaced by its value.
1083 We handle only strings since that's the only case used in C. */
1084 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1085 && DECL_IGNORED_P (lastiddecl)
1086 && TREE_READONLY (lastiddecl)
1087 && DECL_INITIAL (lastiddecl) != 0
1088 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1090 tree stringval = DECL_INITIAL (lastiddecl);
1092 /* Copy the string value so that we won't clobber anything
1093 if we put something in the TREE_CHAIN of this one. */
1094 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1095 TREE_STRING_POINTER (stringval));
1098 else if (doing_objc_thang)
1100 tree objc_interface_decl = is_class_name (yylval.ttype);
1102 if (objc_interface_decl)
1105 yylval.ttype = objc_interface_decl;
1112 case '0': case '1': case '2': case '3': case '4':
1113 case '5': case '6': case '7': case '8': case '9':
1118 int largest_digit = 0;
1120 /* for multi-precision arithmetic,
1121 we actually store only HOST_BITS_PER_CHAR bits in each part.
1122 The number of parts is chosen so as to be sufficient to hold
1123 the enough bits to fit into the two HOST_WIDE_INTs that contain
1124 the integer value (this is always at least as many bits as are
1125 in a target `long long' value, but may be wider). */
1126 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1127 int parts[TOTAL_PARTS];
1130 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1133 for (count = 0; count < TOTAL_PARTS; count++)
1141 *p++ = (c = getc (finput));
1142 if ((c == 'x') || (c == 'X'))
1145 *p++ = (c = getc (finput));
1147 /* Leading 0 forces octal unless the 0 is the only digit. */
1148 else if (c >= '0' && c <= '9')
1157 /* Read all the digits-and-decimal-points. */
1160 || (isalnum (c) && c != 'l' && c != 'L'
1161 && c != 'u' && c != 'U'
1162 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1163 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1168 error ("floating constant may not be in radix 16");
1169 if (floatflag == TOO_MANY_POINTS)
1170 /* We have already emitted an error. Don't need another. */
1172 else if (floatflag == AFTER_POINT)
1174 error ("malformed floating constant");
1175 floatflag = TOO_MANY_POINTS;
1176 /* Avoid another error from atof by forcing all characters
1177 from here on to be ignored. */
1181 floatflag = AFTER_POINT;
1184 *p++ = c = getc (finput);
1185 /* Accept '.' as the start of a floating-point number
1186 only when it is followed by a digit.
1187 Otherwise, unread the following non-digit
1188 and use the '.' as a structural token. */
1189 if (p == token_buffer + 2 && !isdigit (c))
1200 error ("parse error at `..'");
1203 token_buffer[1] = 0;
1210 /* It is not a decimal point.
1211 It should be a digit (perhaps a hex digit). */
1217 else if (base <= 10)
1219 if (c == 'e' || c == 'E')
1222 floatflag = AFTER_POINT;
1223 break; /* start of exponent */
1225 error ("nondigits in number and not hexadecimal");
1236 if (c >= largest_digit)
1240 for (count = 0; count < TOTAL_PARTS; count++)
1242 parts[count] *= base;
1246 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1248 &= (1 << HOST_BITS_PER_CHAR) - 1;
1254 /* If the extra highest-order part ever gets anything in it,
1255 the number is certainly too big. */
1256 if (parts[TOTAL_PARTS - 1] != 0)
1259 if (p >= token_buffer + maxtoken - 3)
1260 p = extend_token_buffer (p);
1261 *p++ = (c = getc (finput));
1266 error ("numeric constant with no digits");
1268 if (largest_digit >= base)
1269 error ("numeric constant contains digits beyond the radix");
1271 /* Remove terminating char from the token buffer and delimit the string */
1274 if (floatflag != NOT_FLOAT)
1276 tree type = double_type_node;
1277 int garbage_chars = 0, exceeds_double = 0;
1279 REAL_VALUE_TYPE value;
1282 /* Read explicit exponent if any, and put it in tokenbuf. */
1284 if ((c == 'e') || (c == 'E'))
1286 if (p >= token_buffer + maxtoken - 3)
1287 p = extend_token_buffer (p);
1290 if ((c == '+') || (c == '-'))
1296 error ("floating constant exponent has no digits");
1299 if (p >= token_buffer + maxtoken - 3)
1300 p = extend_token_buffer (p);
1309 /* Convert string to a double, checking for overflow. */
1310 if (setjmp (handler))
1312 error ("floating constant out of range");
1317 int fflag = 0, lflag = 0;
1318 /* Copy token_buffer now, while it has just the number
1319 and not the suffixes; once we add `f' or `i',
1320 REAL_VALUE_ATOF may not work any more. */
1321 char *copy = (char *) alloca (p - token_buffer + 1);
1322 bcopy (token_buffer, copy, p - token_buffer + 1);
1324 set_float_handler (handler);
1330 /* Read the suffixes to choose a data type. */
1335 error ("more than one `f' in numeric constant");
1341 error ("more than one `l' in numeric constant");
1347 error ("more than one `i' or `j' in numeric constant");
1349 pedwarn ("ANSI C forbids imaginary numeric constants");
1360 if (p >= token_buffer + maxtoken - 3)
1361 p = extend_token_buffer (p);
1367 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1368 tells the desired precision of the binary result
1369 of decimal-to-binary conversion. */
1374 error ("both `f' and `l' in floating constant");
1376 type = float_type_node;
1377 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1378 /* A diagnostic is required here by some ANSI C testsuites.
1379 This is not pedwarn, become some people don't want
1380 an error for this. */
1381 if (REAL_VALUE_ISINF (value) && pedantic)
1382 warning ("floating point number exceeds range of `float'");
1386 type = long_double_type_node;
1387 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1388 if (REAL_VALUE_ISINF (value) && pedantic)
1389 warning ("floating point number exceeds range of `long double'");
1393 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1394 if (REAL_VALUE_ISINF (value) && pedantic)
1395 warning ("floating point number exceeds range of `double'");
1398 set_float_handler (NULL_PTR);
1401 if (errno == ERANGE && !flag_traditional && pedantic)
1403 /* ERANGE is also reported for underflow,
1404 so test the value to distinguish overflow from that. */
1405 if (REAL_VALUES_LESS (dconst1, value)
1406 || REAL_VALUES_LESS (value, dconstm1))
1408 warning ("floating point number exceeds range of `double'");
1414 while (isalnum (c) || c == '.' || c == '_'
1415 || (!flag_traditional && (c == '+' || c == '-')
1416 && (p[-1] == 'e' || p[-1] == 'E')))
1418 if (p >= token_buffer + maxtoken - 3)
1419 p = extend_token_buffer (p);
1424 if (garbage_chars > 0)
1425 error ("garbage at end of number");
1427 /* If the result is not a number, assume it must have been
1428 due to some error message above, so silently convert
1430 if (REAL_VALUE_ISNAN (value))
1433 /* Create a node with determined type and value. */
1435 yylval.ttype = build_complex (convert (type, integer_zero_node),
1436 build_real (type, value));
1438 yylval.ttype = build_real (type, value);
1445 tree traditional_type, ansi_type, type;
1446 HOST_WIDE_INT high, low;
1447 int spec_unsigned = 0;
1449 int spec_long_long = 0;
1455 if (c == 'u' || c == 'U')
1458 error ("two `u's in integer constant");
1461 else if (c == 'l' || c == 'L')
1466 error ("three `l's in integer constant");
1468 pedwarn ("ANSI C forbids long long integer constants");
1473 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1476 error ("more than one `i' or `j' in numeric constant");
1478 pedwarn ("ANSI C forbids imaginary numeric constants");
1483 if (isalnum (c) || c == '.' || c == '_'
1484 || (!flag_traditional && (c == '+' || c == '-')
1485 && (p[-1] == 'e' || p[-1] == 'E')))
1487 error ("garbage at end of number");
1488 while (isalnum (c) || c == '.' || c == '_'
1489 || (!flag_traditional && (c == '+' || c == '-')
1490 && (p[-1] == 'e' || p[-1] == 'E')))
1492 if (p >= token_buffer + maxtoken - 3)
1493 p = extend_token_buffer (p);
1500 if (p >= token_buffer + maxtoken - 3)
1501 p = extend_token_buffer (p);
1508 /* If the constant is not long long and it won't fit in an
1509 unsigned long, or if the constant is long long and won't fit
1510 in an unsigned long long, then warn that the constant is out
1513 /* ??? This assumes that long long and long integer types are
1514 a multiple of 8 bits. This better than the original code
1515 though which assumed that long was exactly 32 bits and long
1516 long was exactly 64 bits. */
1519 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1521 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1524 for (i = bytes; i < TOTAL_PARTS; i++)
1528 pedwarn ("integer constant out of range");
1530 /* This is simplified by the fact that our constant
1531 is always positive. */
1535 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1537 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1538 / HOST_BITS_PER_CHAR)]
1539 << (i * HOST_BITS_PER_CHAR));
1540 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1543 yylval.ttype = build_int_2 (low, high);
1544 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1546 /* If warn_traditional, calculate both the ANSI type and the
1547 traditional type, then see if they disagree.
1548 Otherwise, calculate only the type for the dialect in use. */
1549 if (warn_traditional || flag_traditional)
1551 /* Calculate the traditional type. */
1552 /* Traditionally, any constant is signed;
1553 but if unsigned is specified explicitly, obey that.
1554 Use the smallest size with the right number of bits,
1555 except for one special case with decimal constants. */
1556 if (! spec_long && base != 10
1557 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1558 traditional_type = (spec_unsigned ? unsigned_type_node
1559 : integer_type_node);
1560 /* A decimal constant must be long
1561 if it does not fit in type int.
1562 I think this is independent of whether
1563 the constant is signed. */
1564 else if (! spec_long && base == 10
1565 && int_fits_type_p (yylval.ttype, integer_type_node))
1566 traditional_type = (spec_unsigned ? unsigned_type_node
1567 : integer_type_node);
1568 else if (! spec_long_long)
1569 traditional_type = (spec_unsigned ? long_unsigned_type_node
1570 : long_integer_type_node);
1572 traditional_type = (spec_unsigned
1573 ? long_long_unsigned_type_node
1574 : long_long_integer_type_node);
1576 if (warn_traditional || ! flag_traditional)
1578 /* Calculate the ANSI type. */
1579 if (! spec_long && ! spec_unsigned
1580 && int_fits_type_p (yylval.ttype, integer_type_node))
1581 ansi_type = integer_type_node;
1582 else if (! spec_long && (base != 10 || spec_unsigned)
1583 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1584 ansi_type = unsigned_type_node;
1585 else if (! spec_unsigned && !spec_long_long
1586 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1587 ansi_type = long_integer_type_node;
1588 else if (! spec_long_long)
1589 ansi_type = long_unsigned_type_node;
1590 else if (! spec_unsigned
1591 /* Verify value does not overflow into sign bit. */
1592 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
1593 && int_fits_type_p (yylval.ttype,
1594 long_long_integer_type_node))
1595 ansi_type = long_long_integer_type_node;
1597 ansi_type = long_long_unsigned_type_node;
1600 type = flag_traditional ? traditional_type : ansi_type;
1602 if (warn_traditional && traditional_type != ansi_type)
1604 if (TYPE_PRECISION (traditional_type)
1605 != TYPE_PRECISION (ansi_type))
1606 warning ("width of integer constant changes with -traditional");
1607 else if (TREE_UNSIGNED (traditional_type)
1608 != TREE_UNSIGNED (ansi_type))
1609 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1611 warning ("width of integer constant may change on other systems with -traditional");
1614 if (!flag_traditional && !int_fits_type_p (yylval.ttype, type)
1616 pedwarn ("integer constant out of range");
1618 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1619 warning ("decimal constant is so large that it is unsigned");
1623 if (TYPE_PRECISION (type)
1624 <= TYPE_PRECISION (integer_type_node))
1626 = build_complex (integer_zero_node,
1627 convert (integer_type_node, yylval.ttype));
1629 error ("complex integer constant is too wide for `complex int'");
1631 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1632 /* The traditional constant 0x80000000 is signed
1633 but doesn't fit in the range of int.
1634 This will change it to -0x80000000, which does fit. */
1636 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1637 yylval.ttype = convert (type, yylval.ttype);
1638 TREE_OVERFLOW (yylval.ttype)
1639 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1642 TREE_TYPE (yylval.ttype) = type;
1647 value = CONSTANT; break;
1653 register int result = 0;
1654 register int num_chars = 0;
1655 unsigned width = TYPE_PRECISION (char_type_node);
1660 width = WCHAR_TYPE_SIZE;
1661 #ifdef MULTIBYTE_CHARS
1662 max_chars = MB_CUR_MAX;
1668 max_chars = TYPE_PRECISION (integer_type_node) / width;
1676 if (c == '\'' || c == EOF)
1682 c = readescape (&ignore);
1685 if (width < HOST_BITS_PER_INT
1686 && (unsigned) c >= (1 << width))
1687 pedwarn ("escape sequence out of range for character");
1688 #ifdef MAP_CHARACTER
1690 c = MAP_CHARACTER (c);
1696 pedwarn ("ANSI C forbids newline in character constant");
1699 #ifdef MAP_CHARACTER
1701 c = MAP_CHARACTER (c);
1705 if (num_chars > maxtoken - 4)
1706 extend_token_buffer (token_buffer);
1708 token_buffer[num_chars] = c;
1710 /* Merge character into result; ignore excess chars. */
1711 if (num_chars < max_chars + 1)
1713 if (width < HOST_BITS_PER_INT)
1714 result = (result << width) | (c & ((1 << width) - 1));
1720 token_buffer[num_chars + 1] = '\'';
1721 token_buffer[num_chars + 2] = 0;
1724 error ("malformatted character constant");
1725 else if (num_chars == 0)
1726 error ("empty character constant");
1727 else if (num_chars > max_chars)
1729 num_chars = max_chars;
1730 error ("character constant too long");
1732 else if (num_chars != 1 && ! flag_traditional)
1733 warning ("multi-character character constant");
1735 /* If char type is signed, sign-extend the constant. */
1738 int num_bits = num_chars * width;
1740 /* We already got an error; avoid invalid shift. */
1741 yylval.ttype = build_int_2 (0, 0);
1742 else if (TREE_UNSIGNED (char_type_node)
1743 || ((result >> (num_bits - 1)) & 1) == 0)
1745 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1746 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1750 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1751 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1753 TREE_TYPE (yylval.ttype) = integer_type_node;
1757 #ifdef MULTIBYTE_CHARS
1758 /* Set the initial shift state and convert the next sequence. */
1760 /* In all locales L'\0' is zero and mbtowc will return zero,
1763 || (num_chars == 1 && token_buffer[1] != '\0'))
1766 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1767 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1770 warning ("Ignoring invalid multibyte character");
1773 yylval.ttype = build_int_2 (result, 0);
1774 TREE_TYPE (yylval.ttype) = wchar_type_node;
1785 p = token_buffer + 1;
1787 while (c != '"' && c >= 0)
1792 c = readescape (&ignore);
1796 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1797 && c >= (1 << TYPE_PRECISION (char_type_node)))
1798 pedwarn ("escape sequence out of range for character");
1803 pedwarn ("ANSI C forbids newline in string constant");
1807 if (p == token_buffer + maxtoken)
1808 p = extend_token_buffer (p);
1817 error ("Unterminated string constant");
1819 /* We have read the entire constant.
1820 Construct a STRING_CST for the result. */
1824 /* If this is a L"..." wide-string, convert the multibyte string
1825 to a wide character string. */
1826 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1829 #ifdef MULTIBYTE_CHARS
1830 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1831 if (len < 0 || len >= (p - token_buffer))
1833 warning ("Ignoring invalid multibyte string");
1836 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1839 union { long l; char c[sizeof (long)]; } u;
1843 /* Determine whether host is little or big endian. */
1845 big_endian = u.c[sizeof (long) - 1];
1846 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1848 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1849 for (cp = token_buffer + 1; cp < p; cp++)
1850 *wp = *cp, wp += WCHAR_BYTES;
1851 len = p - token_buffer - 1;
1854 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1855 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1860 extern tree build_objc_string();
1861 /* Return an Objective-C @"..." constant string object. */
1862 yylval.ttype = build_objc_string (p - token_buffer,
1864 TREE_TYPE (yylval.ttype) = char_array_type_node;
1865 value = OBJC_STRING;
1869 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
1870 TREE_TYPE (yylval.ttype) = char_array_type_node;
1901 yylval.code = PLUS_EXPR; break;
1903 yylval.code = MINUS_EXPR; break;
1905 yylval.code = BIT_AND_EXPR; break;
1907 yylval.code = BIT_IOR_EXPR; break;
1909 yylval.code = MULT_EXPR; break;
1911 yylval.code = TRUNC_DIV_EXPR; break;
1913 yylval.code = TRUNC_MOD_EXPR; break;
1915 yylval.code = BIT_XOR_EXPR; break;
1917 yylval.code = LSHIFT_EXPR; break;
1919 yylval.code = RSHIFT_EXPR; break;
1921 yylval.code = LT_EXPR; break;
1923 yylval.code = GT_EXPR; break;
1926 token_buffer[1] = c1 = getc (finput);
1927 token_buffer[2] = 0;
1934 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
1936 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
1938 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
1940 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
1942 value = ASSIGN; goto done;
1948 value = PLUSPLUS; goto done;
1950 value = MINUSMINUS; goto done;
1952 value = ANDAND; goto done;
1954 value = OROR; goto done;
1967 { value = POINTSAT; goto done; }
1971 { value = ']'; goto done; }
1975 { value = '{'; goto done; }
1977 { value = '['; goto done; }
1981 { value = '}'; goto done; }
1984 ungetc (c1, finput);
1985 token_buffer[1] = 0;
1987 if ((c == '<') || (c == '>'))
1988 value = ARITHCOMPARE;
1994 /* Don't make yyparse think this is eof. */
2003 /* yylloc.last_line = lineno; */
2008 /* Sets the value of the 'yydebug' variable to VALUE.
2009 This is a function so we don't have to have YYDEBUG defined
2010 in order to build the compiler. */
2019 warning ("YYDEBUG not defined.");