1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 1988, 1989, 1992 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
34 #ifdef MULTIBYTE_CHARS
43 /* The elements of `ridpointers' are identifier nodes
44 for the reserved type names and storage classes.
45 It is indexed by a RID_... value. */
46 tree ridpointers[(int) RID_MAX];
48 /* Cause the `yydebug' variable to be defined. */
51 /* the declaration found for the last IDENTIFIER token read in.
52 yylex must look this up to detect typedefs, which get token type TYPENAME,
53 so it is left around in case the identifier is not a typedef but is
54 used in a context which makes it a reference to a variable. */
57 /* Nonzero enables objc features. */
61 extern tree lookup_interface ();
65 /* File used for outputting assembler code. */
66 extern FILE *asm_out_file;
68 #ifndef WCHAR_TYPE_SIZE
70 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
72 #define WCHAR_TYPE_SIZE BITS_PER_WORD
76 /* Number of bytes in a wide character. */
77 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
79 static int maxtoken; /* Current nominal length of token buffer. */
80 char *token_buffer; /* Pointer to token buffer.
81 Actual allocated length is maxtoken + 2.
82 This is not static because objc-parse.y uses it. */
84 /* Nonzero if end-of-file has been seen on input. */
85 static int end_of_file;
87 /* Buffered-back input character; faster than using ungetc. */
88 static int nextchar = -1;
92 /* Nonzero tells yylex to ignore \ in string constants. */
93 static int ignore_escape_flag = 0;
95 /* C code produced by gperf version 2.5 (GNU C++ version) */
96 /* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */
97 struct resword { char *name; short token; enum rid rid; };
99 #define TOTAL_KEYWORDS 53
100 #define MIN_WORD_LENGTH 2
101 #define MAX_WORD_LENGTH 13
102 #define MIN_HASH_VALUE 7
103 #define MAX_HASH_VALUE 102
104 /* maximum key range = 96, duplicates = 0 */
112 register int unsigned len;
114 static unsigned char asso_values[] =
116 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
117 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
118 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
119 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
120 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
121 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
122 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
123 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
124 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
125 103, 103, 103, 103, 103, 1, 103, 2, 1, 24,
126 1, 5, 19, 39, 16, 13, 103, 1, 25, 1,
127 34, 34, 24, 103, 13, 12, 1, 45, 24, 7,
128 103, 103, 2, 103, 103, 103, 103, 103,
130 register int hval = len;
136 hval += asso_values[str[2]];
139 hval += asso_values[str[0]];
141 return hval + asso_values[str[len - 1]];
148 is_reserved_word (str, len)
150 register unsigned int len;
152 static struct resword wordlist[] =
154 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
155 {"asm", ASM_KEYWORD, NORID},
157 {"__asm", ASM_KEYWORD, NORID},
159 {"__asm__", ASM_KEYWORD, NORID},
160 {"break", BREAK, NORID},
161 {"__typeof__", TYPEOF, NORID},
163 {"__alignof__", ALIGNOF, NORID},
165 {"__attribute__", ATTRIBUTE, NORID},
166 {"int", TYPESPEC, RID_INT},
167 {"__attribute", ATTRIBUTE, NORID},
168 {"__extension__", EXTENSION, NORID},
170 {"__signed", TYPESPEC, RID_SIGNED},
172 {"__signed__", TYPESPEC, RID_SIGNED},
173 {"__inline__", SCSPEC, RID_INLINE},
174 {"else", ELSE, NORID},
175 {"__inline", SCSPEC, RID_INLINE},
176 {"default", DEFAULT, NORID},
177 {"__typeof", TYPEOF, NORID},
178 {"while", WHILE, NORID},
179 {"__alignof", ALIGNOF, NORID},
180 {"struct", STRUCT, NORID},
181 {"__const", TYPE_QUAL, RID_CONST},
183 {"__const__", TYPE_QUAL, RID_CONST},
184 {"__label__", LABEL, NORID},
186 {"__volatile__", TYPE_QUAL, RID_VOLATILE},
187 {"sizeof", SIZEOF, NORID},
188 {"__volatile", TYPE_QUAL, RID_VOLATILE},
189 {"auto", SCSPEC, RID_AUTO},
190 {"void", TYPESPEC, RID_VOID},
191 {"char", TYPESPEC, RID_CHAR},
192 {"static", SCSPEC, RID_STATIC},
193 {"case", CASE, NORID},
194 {"extern", SCSPEC, RID_EXTERN},
195 {"switch", SWITCH, NORID},
197 {"inline", SCSPEC, RID_INLINE},
198 {"typeof", TYPEOF, NORID},
199 {"typedef", SCSPEC, RID_TYPEDEF},
200 {"short", TYPESPEC, RID_SHORT},
202 {"return", RETURN, NORID},
203 {"enum", ENUM, NORID},
205 {"double", TYPESPEC, RID_DOUBLE},
206 {"signed", TYPESPEC, RID_SIGNED},
207 {"float", TYPESPEC, RID_FLOAT},
209 {"volatile", TYPE_QUAL, RID_VOLATILE},
211 {"const", TYPE_QUAL, RID_CONST},
213 {"unsigned", TYPESPEC, RID_UNSIGNED},
214 {"",}, {"",}, {"",}, {"",},
215 {"continue", CONTINUE, NORID},
217 {"register", SCSPEC, RID_REGISTER},
218 {"",}, {"",}, {"",}, {"",},
219 {"goto", GOTO, NORID},
220 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
221 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
223 {"union", UNION, NORID},
224 {"",}, {"",}, {"",}, {"",},
225 {"long", TYPESPEC, RID_LONG},
228 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
230 register int key = hash (str, len);
232 if (key <= MAX_HASH_VALUE && key >= 0)
234 register char *s = wordlist[key].name;
236 if (*s == *str && !strcmp (str + 1, s + 1))
237 return &wordlist[key];
243 /* Return something to represent absolute declarators containing a *.
244 TARGET is the absolute declarator that the * contains.
245 TYPE_QUALS is a list of modifiers such as const or volatile
246 to apply to the pointer type, represented as identifiers.
248 We return an INDIRECT_REF whose "contents" are TARGET
249 and whose type is the modifier list. */
252 make_pointer_declarator (type_quals, target)
253 tree type_quals, target;
255 return build1 (INDIRECT_REF, type_quals, target);
261 /* Make identifier nodes long enough for the language-specific slots. */
262 set_identifier_size (sizeof (struct lang_identifier));
264 /* Start it at 0, because check_newline is called at the very beginning
265 and will increment it to 1. */
268 #ifdef MULTIBYTE_CHARS
269 /* Change to the native locale for multibyte conversions. */
270 setlocale (LC_CTYPE, "");
274 token_buffer = (char *) xmalloc (maxtoken + 2);
276 ridpointers[(int) RID_INT] = get_identifier ("int");
277 ridpointers[(int) RID_CHAR] = get_identifier ("char");
278 ridpointers[(int) RID_VOID] = get_identifier ("void");
279 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
280 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
281 ridpointers[(int) RID_SHORT] = get_identifier ("short");
282 ridpointers[(int) RID_LONG] = get_identifier ("long");
283 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
284 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
285 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
286 ridpointers[(int) RID_CONST] = get_identifier ("const");
287 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
288 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
289 ridpointers[(int) RID_STATIC] = get_identifier ("static");
290 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
291 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
292 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
294 /* Some options inhibit certain reserved words.
295 Clear those words out of the hash table so they won't be recognized. */
296 #define UNSET_RESERVED_WORD(STRING) \
297 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
298 if (s) s->name = ""; } while (0)
300 if (flag_traditional)
302 UNSET_RESERVED_WORD ("const");
303 UNSET_RESERVED_WORD ("volatile");
304 UNSET_RESERVED_WORD ("typeof");
305 UNSET_RESERVED_WORD ("signed");
306 UNSET_RESERVED_WORD ("inline");
310 UNSET_RESERVED_WORD ("asm");
311 UNSET_RESERVED_WORD ("typeof");
312 UNSET_RESERVED_WORD ("inline");
317 reinit_parse_for_function ()
321 /* Function used when yydebug is set, to print a token in more detail. */
324 yyprint (file, yychar, yylval)
335 if (IDENTIFIER_POINTER (t))
336 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
341 if (TREE_CODE (t) == INTEGER_CST)
342 fprintf (file, " 0x%8x%8x", TREE_INT_CST_HIGH (t),
343 TREE_INT_CST_LOW (t));
349 /* If C is not whitespace, return C.
350 Otherwise skip whitespace and return first nonwhite char read. */
364 /* Don't recognize comments in cc1: all comments are removed by cpp,
365 and cpp output can include / and * consecutively as operators. */
398 error ("unterminated comment");
409 c = check_newline ();
415 #if 0 /* ANSI says no. */
428 error ("stray '\\' in program");
438 /* Skips all of the white space at the current location in the input file.
439 Must use and reset nextchar if it has the next character. */
442 position_after_white_space ()
447 c = nextchar, nextchar = -1;
451 ungetc (skip_white_space (c), finput);
454 /* Make the token buffer longer, preserving the data in it.
455 P should point to just beyond the last valid character in the old buffer.
456 The value we return is a pointer to the new buffer
457 at a place corresponding to P. */
460 extend_token_buffer (p)
463 int offset = p - token_buffer;
465 maxtoken = maxtoken * 2 + 10;
466 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
468 return token_buffer + offset;
471 /* At the beginning of a line, increment the line number
472 and process any #-directive on this line.
473 If the line is a #-directive, read the entire line and return a newline.
474 Otherwise, return the line's first non-whitespace character. */
484 /* Read first nonwhite char on the line. */
487 while (c == ' ' || c == '\t')
492 /* If not #, return it so caller will use it. */
496 /* Read first nonwhite char after the `#'. */
499 while (c == ' ' || c == '\t')
502 /* If a letter follows, then if the word here is `line', skip
503 it and ignore it; otherwise, ignore the line, with an error
504 if the word isn't `pragma', `ident', `define', or `undef'. */
506 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
510 if (getc (finput) == 'r'
511 && getc (finput) == 'a'
512 && getc (finput) == 'g'
513 && getc (finput) == 'm'
514 && getc (finput) == 'a'
515 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
518 HANDLE_PRAGMA (finput);
519 #endif /* HANDLE_PRAGMA */
526 if (getc (finput) == 'e'
527 && getc (finput) == 'f'
528 && getc (finput) == 'i'
529 && getc (finput) == 'n'
530 && getc (finput) == 'e'
531 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
533 #ifdef DWARF_DEBUGGING_INFO
534 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
535 && (write_symbols == DWARF_DEBUG))
536 dwarfout_define (lineno, get_directive_line (finput));
537 #endif /* DWARF_DEBUGGING_INFO */
543 if (getc (finput) == 'n'
544 && getc (finput) == 'd'
545 && getc (finput) == 'e'
546 && getc (finput) == 'f'
547 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
549 #ifdef DWARF_DEBUGGING_INFO
550 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
551 && (write_symbols == DWARF_DEBUG))
552 dwarfout_undef (lineno, get_directive_line (finput));
553 #endif /* DWARF_DEBUGGING_INFO */
559 if (getc (finput) == 'i'
560 && getc (finput) == 'n'
561 && getc (finput) == 'e'
562 && ((c = getc (finput)) == ' ' || c == '\t'))
567 if (getc (finput) == 'd'
568 && getc (finput) == 'e'
569 && getc (finput) == 'n'
570 && getc (finput) == 't'
571 && ((c = getc (finput)) == ' ' || c == '\t'))
573 /* #ident. The pedantic warning is now in cccp.c. */
575 /* Here we have just seen `#ident '.
576 A string constant should follow. */
578 while (c == ' ' || c == '\t')
581 /* If no argument, ignore the line. */
588 || TREE_CODE (yylval.ttype) != STRING_CST)
590 error ("invalid #ident");
596 #ifdef ASM_OUTPUT_IDENT
597 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
601 /* Skip the rest of this line. */
606 error ("undefined or invalid # directive");
611 /* Here we have either `#line' or `# <nonletter>'.
612 In either case, it should be a line number; a digit should follow. */
614 while (c == ' ' || c == '\t')
617 /* If the # is the only nonwhite char on the line,
618 just ignore it. Check the new newline. */
622 /* Something follows the #; read a token. */
627 if (token == CONSTANT
628 && TREE_CODE (yylval.ttype) == INTEGER_CST)
630 int old_lineno = lineno;
632 /* subtract one, because it is the following line that
633 gets the specified number */
635 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
637 /* Is this the last nonwhite stuff on the line? */
639 while (c == ' ' || c == '\t')
643 /* No more: store the line number and check following line. */
649 /* More follows: it must be a string constant (filename). */
651 /* Read the string constant, but don't treat \ as special. */
652 ignore_escape_flag = 1;
654 ignore_escape_flag = 0;
656 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
658 error ("invalid #line");
663 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
664 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
667 /* Each change of file name
668 reinitializes whether we are now in a system header. */
669 in_system_header = 0;
671 if (main_input_filename == 0)
672 main_input_filename = input_filename;
674 /* Is this the last nonwhite stuff on the line? */
676 while (c == ' ' || c == '\t')
685 /* `1' after file name means entering new file.
686 `2' after file name means just left a file. */
688 if (token == CONSTANT
689 && TREE_CODE (yylval.ttype) == INTEGER_CST)
691 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
693 /* Pushing to a new file. */
695 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
696 input_file_stack->line = old_lineno;
697 p->next = input_file_stack;
698 p->name = input_filename;
699 input_file_stack = p;
700 input_file_stack_tick++;
701 #ifdef DWARF_DEBUGGING_INFO
702 if (debug_info_level == DINFO_LEVEL_VERBOSE
703 && write_symbols == DWARF_DEBUG)
704 dwarfout_start_new_source_file (input_filename);
705 #endif /* DWARF_DEBUGGING_INFO */
709 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
711 /* Popping out of a file. */
712 if (input_file_stack->next)
714 struct file_stack *p = input_file_stack;
715 input_file_stack = p->next;
717 input_file_stack_tick++;
718 #ifdef DWARF_DEBUGGING_INFO
719 if (debug_info_level == DINFO_LEVEL_VERBOSE
720 && write_symbols == DWARF_DEBUG)
721 dwarfout_resume_previous_source_file (input_file_stack->line);
722 #endif /* DWARF_DEBUGGING_INFO */
725 error ("#-lines for entering and leaving files don't match");
731 /* If we have handled a `1' or a `2',
732 see if there is another number to read. */
735 /* Is this the last nonwhite stuff on the line? */
737 while (c == ' ' || c == '\t')
747 /* `3' after file name means this is a system header file. */
749 if (token == CONSTANT
750 && TREE_CODE (yylval.ttype) == INTEGER_CST
751 && TREE_INT_CST_LOW (yylval.ttype) == 3)
752 in_system_header = 1;
755 error ("invalid #-line");
757 /* skip the rest of this line. */
761 while ((c = getc (finput)) != EOF && c != '\n');
765 #define isalnum(char) ((char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'))
766 #define isdigit(char) (char >= '0' && char <= '9')
767 #define ENDFILE -1 /* token that represents end-of-file */
769 /* Read an escape sequence, returning its equivalent as a character,
770 or -1 if it is backslash-newline. */
775 register int c = getc (finput);
777 register unsigned count;
783 if (warn_traditional)
784 warning ("the meaning of `\\x' varies with -traditional");
786 if (flag_traditional)
794 if (!(c >= 'a' && c <= 'f')
795 && !(c >= 'A' && c <= 'F')
796 && !(c >= '0' && c <= '9'))
802 if (c >= 'a' && c <= 'f')
803 code += c - 'a' + 10;
804 if (c >= 'A' && c <= 'F')
805 code += c - 'A' + 10;
806 if (c >= '0' && c <= '9')
813 error ("\\x used with no following hex digits");
814 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
816 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
818 pedwarn ("hex escape out of range");
821 case '0': case '1': case '2': case '3': case '4':
822 case '5': case '6': case '7':
825 while ((c <= '7') && (c >= '0') && (count++ < 3))
827 code = (code * 8) + (c - '0');
833 case '\\': case '\'': case '"':
841 return TARGET_NEWLINE;
856 if (warn_traditional)
857 warning ("the meaning of `\\a' varies with -traditional");
859 if (flag_traditional)
864 #if 0 /* Vertical tab is present in common usage compilers. */
865 if (flag_traditional)
871 pedwarn ("non-ANSI-standard escape sequence, `\\E'");
877 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
882 pedwarn ("non-ANSI escape sequence `\\%c'", c);
885 if (c >= 040 && c <= 0177)
886 pedwarn ("unknown escape sequence `\\%c'", c);
888 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
898 strcpy (buf, string);
900 /* We can't print string and character constants well
901 because the token_buffer contains the result of processing escapes. */
903 strcat (buf, " at end of input");
904 else if (token_buffer[0] == 0)
905 strcat (buf, " at null character");
906 else if (token_buffer[0] == '"')
907 strcat (buf, " before string constant");
908 else if (token_buffer[0] == '\'')
909 strcat (buf, " before character constant");
910 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
911 sprintf (buf + strlen (buf), " before character 0%o",
912 (unsigned char) token_buffer[0]);
914 strcat (buf, " before `%s'");
916 error (buf, token_buffer);
929 struct try_type type_sequence[] =
931 { &integer_type_node, 0, 0, 0},
932 { &unsigned_type_node, 1, 0, 0},
933 { &long_integer_type_node, 0, 1, 0},
934 { &long_unsigned_type_node, 1, 1, 0},
935 { &long_long_integer_type_node, 0, 1, 1},
936 { &long_long_unsigned_type_node, 1, 1, 1}
949 c = nextchar, nextchar = -1;
953 /* Effectively do c = skip_white_space (c)
954 but do it faster in the usual cases. */
959 if (!flag_traditional) /* ANSI says no */
972 c = skip_white_space (c);
981 /* yylloc.first_line = lineno; */
992 if (dollars_in_ident)
997 /* Capital L may start a wide-string or wide-character constant. */
999 register int c = getc (finput);
1008 goto string_constant;
1015 if (!doing_objc_thang)
1023 while (isalnum (c) || c == '_')
1025 if (p >= token_buffer + maxtoken)
1026 p = extend_token_buffer (p);
1034 value = recognize_objc_keyword (token_buffer + 1);
1037 error ("invalid Objective C keyword `%s'", token_buffer);
1038 /* Cause a syntax error--1 is not a valid token type. */
1042 case 'A': case 'B': case 'C': case 'D': case 'E':
1043 case 'F': case 'G': case 'H': case 'I': case 'J':
1044 case 'K': case 'M': case 'N': case 'O':
1045 case 'P': case 'Q': case 'R': case 'S': case 'T':
1046 case 'U': case 'V': case 'W': case 'X': case 'Y':
1048 case 'a': case 'b': case 'c': case 'd': case 'e':
1049 case 'f': case 'g': case 'h': case 'i': case 'j':
1050 case 'k': case 'l': case 'm': case 'n': case 'o':
1051 case 'p': case 'q': case 'r': case 's': case 't':
1052 case 'u': case 'v': case 'w': case 'x': case 'y':
1057 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1059 if (p >= token_buffer + maxtoken)
1060 p = extend_token_buffer (p);
1061 if (c == '$' && ! dollars_in_ident)
1074 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1077 register struct resword *ptr;
1079 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1082 yylval.ttype = ridpointers[(int) ptr->rid];
1083 value = (int) ptr->token;
1085 /* Even if we decided to recognize asm, still perhaps warn. */
1087 && (value == ASM_KEYWORD || value == TYPEOF
1088 || ptr->rid == RID_INLINE)
1089 && token_buffer[0] != '_')
1090 pedwarn ("ANSI does not permit the keyword `%s'",
1095 /* If we did not find a keyword, look for an identifier
1098 if (value == IDENTIFIER)
1100 yylval.ttype = get_identifier (token_buffer);
1101 lastiddecl = lookup_name (yylval.ttype);
1103 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1105 else if (doing_objc_thang)
1107 tree objc_interface_decl = lookup_interface (yylval.ttype);
1109 if (objc_interface_decl)
1112 yylval.ttype = objc_interface_decl;
1119 case '0': case '1': case '2': case '3': case '4':
1120 case '5': case '6': case '7': case '8': case '9':
1125 int largest_digit = 0;
1127 /* for multi-precision arithmetic,
1128 we store only 8 live bits in each short,
1129 giving us 64 bits of reliable precision */
1133 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1136 for (count = 0; count < 8; count++)
1144 *p++ = (c = getc (finput));
1145 if ((c == 'x') || (c == 'X'))
1148 *p++ = (c = getc (finput));
1150 /* Leading 0 forces octal unless the 0 is the only digit. */
1151 else if (c >= '0' && c <= '9')
1160 /* Read all the digits-and-decimal-points. */
1163 || (isalnum (c) && (c != 'l') && (c != 'L')
1164 && (c != 'u') && (c != 'U')
1165 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1170 error ("floating constant may not be in radix 16");
1171 if (floatflag == AFTER_POINT)
1173 error ("malformed floating constant");
1174 floatflag = TOO_MANY_POINTS;
1177 floatflag = AFTER_POINT;
1180 *p++ = c = getc (finput);
1181 /* Accept '.' as the start of a floating-point number
1182 only when it is followed by a digit.
1183 Otherwise, unread the following non-digit
1184 and use the '.' as a structural token. */
1185 if (p == token_buffer + 2 && !isdigit (c))
1196 error ("parse error at `..'");
1199 token_buffer[1] = 0;
1206 /* It is not a decimal point.
1207 It should be a digit (perhaps a hex digit). */
1213 else if (base <= 10)
1215 if ((c&~040) == 'E')
1218 floatflag = AFTER_POINT;
1219 break; /* start of exponent */
1221 error ("nondigits in number and not hexadecimal");
1232 if (c >= largest_digit)
1236 for (count = 0; count < 8; count++)
1238 shorts[count] *= base;
1241 shorts[count] += (shorts[count-1] >> 8);
1242 shorts[count-1] &= (1<<8)-1;
1244 else shorts[0] += c;
1247 if (shorts[7] >= 1<<8
1248 || shorts[7] < - (1 << 8))
1251 if (p >= token_buffer + maxtoken - 3)
1252 p = extend_token_buffer (p);
1253 *p++ = (c = getc (finput));
1258 error ("numeric constant with no digits");
1260 if (largest_digit >= base)
1261 error ("numeric constant contains digits beyond the radix");
1263 /* Remove terminating char from the token buffer and delimit the string */
1266 if (floatflag != NOT_FLOAT)
1268 tree type = double_type_node;
1271 REAL_VALUE_TYPE value;
1274 /* Read explicit exponent if any, and put it in tokenbuf. */
1276 if ((c == 'e') || (c == 'E'))
1278 if (p >= token_buffer + maxtoken - 3)
1279 p = extend_token_buffer (p);
1282 if ((c == '+') || (c == '-'))
1288 error ("floating constant exponent has no digits");
1291 if (p >= token_buffer + maxtoken - 3)
1292 p = extend_token_buffer (p);
1301 /* Convert string to a double, checking for overflow. */
1302 if (setjmp (handler))
1304 error ("floating constant out of range");
1309 set_float_handler (handler);
1310 value = REAL_VALUE_ATOF (token_buffer);
1311 set_float_handler (0);
1314 if (errno == ERANGE && !flag_traditional)
1316 char *p1 = token_buffer;
1317 /* Check for "0.0" and variants;
1318 Sunos 4 spuriously returns ERANGE for them. */
1319 while (*p1 == '0') p1++;
1323 while (*p1 == '0') p1++;
1325 if (*p1 == 'e' || *p1 == 'E')
1327 /* with significand==0, ignore the exponent */
1329 while (*p1 != 0) p1++;
1331 /* ERANGE is also reported for underflow,
1332 so test the value to distinguish overflow from that. */
1333 if (*p1 != 0 && (value > 1.0 || value < -1.0))
1334 warning ("floating point number exceeds range of `double'");
1338 /* Read the suffixes to choose a data type. */
1341 if (c == 'f' || c == 'F')
1344 error ("two `f's in floating constant");
1346 type = float_type_node;
1347 value = REAL_VALUE_TRUNCATE (TYPE_MODE (type), value);
1349 else if (c == 'l' || c == 'L')
1352 error ("two `l's in floating constant");
1354 type = long_double_type_node;
1360 error ("garbage at end of number");
1363 if (p >= token_buffer + maxtoken - 3)
1364 p = extend_token_buffer (p);
1371 if (p >= token_buffer + maxtoken - 3)
1372 p = extend_token_buffer (p);
1377 /* Create a node with determined type and value. */
1378 yylval.ttype = build_real (type, value);
1385 tree traditional_type, ansi_type, type;
1386 int spec_unsigned = 0;
1388 int spec_long_long = 0;
1393 if (c == 'u' || c == 'U')
1396 error ("two `u's in integer constant");
1399 else if (c == 'l' || c == 'L')
1404 error ("three `l's in integer constant");
1406 pedwarn ("ANSI C forbids long long integer constants");
1415 error ("garbage at end of number");
1418 if (p >= token_buffer + maxtoken - 3)
1419 p = extend_token_buffer (p);
1426 if (p >= token_buffer + maxtoken - 3)
1427 p = extend_token_buffer (p);
1434 /* If the constant is not long long and it won't fit in an
1435 unsigned long, or if the constant is long long and won't fit
1436 in an unsigned long long, then warn that the constant is out
1439 /* ??? This assumes that long long and long integer types are
1440 a multiple of 8 bits. This better than the original code
1441 though which assumed that long was exactly 32 bits and long
1442 long was exactly 64 bits. */
1445 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1447 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1452 for (i = bytes; i < 8; i++)
1455 /* If LL was not used, then clear any excess precision.
1456 This is equivalent to the original code, but it is
1457 not clear why this is being done. Perhaps to prevent
1458 ANSI programs from creating long long constants
1460 if (! spec_long_long)
1465 warning ("integer constant out of range");
1468 warning ("integer constant larger than compiler can handle");
1470 /* If it overflowed our internal buffer, then make it unsigned.
1471 We can't distinguish based on the tree node because
1472 any integer constant fits any long long type. */
1476 /* This is simplified by the fact that our constant
1477 is always positive. */
1478 /* The casts in the following statement should not be
1479 needed, but they get around bugs in some C compilers. */
1482 ((((long)shorts[3]<<24) + ((long)shorts[2]<<16)
1483 + ((long)shorts[1]<<8) + (long)shorts[0]),
1484 (((long)shorts[7]<<24) + ((long)shorts[6]<<16)
1485 + ((long)shorts[5]<<8) + (long)shorts[4])));
1488 /* Find the first allowable type that the value fits in. */
1490 for (i = 0; i < sizeof (type_sequence) / sizeof (type_sequence[0]);
1492 if (!(spec_long && !type_sequence[i].long_flag)
1493 && !(spec_long_long && !type_sequence[i].long_long_flag)
1494 && !(spec_unsigned && !type_sequence[i].unsigned_flag)
1495 /* A decimal constant can't be unsigned int
1496 unless explicitly specified. */
1497 && !(base == 10 && !spec_unsigned
1498 && *type_sequence[i].node_var == unsigned_type_node))
1499 if (int_fits_type_p (yylval.ttype, *type_sequence[i].node_var))
1501 type = *type_sequence[i].node_var;
1504 if (flag_traditional && type == long_unsigned_type_node
1506 type = long_integer_type_node;
1510 type = long_long_integer_type_node;
1511 warning ("integer constant out of range");
1514 /* Warn about some cases where the type of a given constant
1515 changes from traditional C to ANSI C. */
1516 if (warn_traditional)
1518 tree other_type = 0;
1520 /* This computation is the same as the previous one
1521 except that flag_traditional is used backwards. */
1522 for (i = 0; i < sizeof (type_sequence) / sizeof (type_sequence[0]);
1524 if (!(spec_long && !type_sequence[i].long_flag)
1525 && !(spec_long_long && !type_sequence[i].long_long_flag)
1526 && !(spec_unsigned && !type_sequence[i].unsigned_flag)
1527 /* A decimal constant can't be unsigned int
1528 unless explicitly specified. */
1529 && !(base == 10 && !spec_unsigned
1530 && *type_sequence[i].node_var == unsigned_type_node))
1531 if (int_fits_type_p (yylval.ttype, *type_sequence[i].node_var))
1533 other_type = *type_sequence[i].node_var;
1536 if (!flag_traditional && type == long_unsigned_type_node
1538 type = long_integer_type_node;
1540 if (other_type != 0 && other_type != type)
1542 if (flag_traditional)
1543 warning ("type of integer constant would be different without -traditional");
1545 warning ("type of integer constant would be different with -traditional");
1550 /* If warn_traditional, calculate both the ANSI type and the
1551 traditional type, then see if they disagree.
1552 Otherwise, calculate only the type for the dialect in use. */
1553 if (warn_traditional || flag_traditional)
1555 /* Calculate the traditional type. */
1556 /* Traditionally, any constant is signed;
1557 but if unsigned is specified explicitly, obey that.
1558 Use the smallest size with the right number of bits,
1559 except for one special case with decimal constants. */
1560 if (! spec_long && base != 10
1561 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1562 traditional_type = (spec_unsigned ? unsigned_type_node
1563 : integer_type_node);
1564 /* A decimal constant must be long
1565 if it does not fit in type int.
1566 I think this is independent of whether
1567 the constant is signed. */
1568 else if (! spec_long && base == 10
1569 && int_fits_type_p (yylval.ttype, integer_type_node))
1570 traditional_type = (spec_unsigned ? unsigned_type_node
1571 : integer_type_node);
1572 else if (! spec_long_long
1573 && int_fits_type_p (yylval.ttype,
1574 long_unsigned_type_node))
1575 traditional_type = (spec_unsigned ? long_unsigned_type_node
1576 : long_integer_type_node);
1578 traditional_type = (spec_unsigned
1579 ? long_long_unsigned_type_node
1580 : long_long_integer_type_node);
1582 if (warn_traditional || ! flag_traditional)
1584 /* Calculate the ANSI type. */
1585 if (! spec_long && ! spec_unsigned
1586 && int_fits_type_p (yylval.ttype, integer_type_node))
1587 ansi_type = integer_type_node;
1588 else if (! spec_long && (base != 10 || spec_unsigned)
1589 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1590 ansi_type = unsigned_type_node;
1591 else if (! spec_unsigned && !spec_long_long
1592 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1593 ansi_type = long_integer_type_node;
1594 else if (! spec_long_long
1595 && int_fits_type_p (yylval.ttype,
1596 long_unsigned_type_node))
1597 ansi_type = long_unsigned_type_node;
1598 else if (! spec_unsigned
1599 && int_fits_type_p (yylval.ttype,
1600 long_long_integer_type_node))
1601 ansi_type = long_long_integer_type_node;
1603 ansi_type = long_long_unsigned_type_node;
1606 type = flag_traditional ? traditional_type : ansi_type;
1608 if (warn_traditional && traditional_type != ansi_type)
1610 if (TYPE_PRECISION (traditional_type)
1611 != TYPE_PRECISION (ansi_type))
1612 warning ("width of integer constant changes with -traditional");
1613 else if (TREE_UNSIGNED (traditional_type)
1614 != TREE_UNSIGNED (ansi_type))
1615 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1617 warning ("width of integer constant may change on other systems with -traditional");
1621 TREE_TYPE (yylval.ttype) = type;
1625 value = CONSTANT; break;
1631 register int result = 0;
1632 register num_chars = 0;
1633 unsigned width = TYPE_PRECISION (char_type_node);
1638 width = WCHAR_TYPE_SIZE;
1639 #ifdef MULTIBYTE_CHARS
1640 max_chars = MB_CUR_MAX;
1646 max_chars = TYPE_PRECISION (integer_type_node) / width;
1654 if (c == '\'' || c == EOF)
1662 if (width < HOST_BITS_PER_INT
1663 && (unsigned) c >= (1 << width))
1664 pedwarn ("escape sequence out of range for character");
1669 pedwarn ("ANSI C forbids newline in character constant");
1674 if (num_chars > maxtoken - 4)
1675 extend_token_buffer (token_buffer);
1677 token_buffer[num_chars] = c;
1679 /* Merge character into result; ignore excess chars. */
1680 if (num_chars < max_chars + 1)
1682 if (width < HOST_BITS_PER_INT)
1683 result = (result << width) | (c & ((1 << width) - 1));
1689 token_buffer[num_chars + 1] = '\'';
1690 token_buffer[num_chars + 2] = 0;
1693 error ("malformatted character constant");
1694 else if (num_chars == 0)
1695 error ("empty character constant");
1696 else if (num_chars > max_chars)
1698 num_chars = max_chars;
1699 error ("character constant too long");
1701 else if (num_chars != 1 && ! flag_traditional)
1702 warning ("multi-character character constant");
1704 /* If char type is signed, sign-extend the constant. */
1707 int num_bits = num_chars * width;
1708 if (TREE_UNSIGNED (char_type_node)
1709 || ((result >> (num_bits - 1)) & 1) == 0)
1711 = build_int_2 (result & ((unsigned) ~0
1712 >> (HOST_BITS_PER_INT - num_bits)),
1716 = build_int_2 (result | ~((unsigned) ~0
1717 >> (HOST_BITS_PER_INT - num_bits)),
1722 #ifdef MULTIBYTE_CHARS
1723 /* Set the initial shift state and convert the next sequence. */
1725 /* In all locales L'\0' is zero and mbtowc will return zero,
1728 || (num_chars == 1 && token_buffer[1] != '\0'))
1731 (void) mbtowc (NULL, NULL, 0);
1732 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1735 warning ("Ignoring invalid multibyte character");
1738 yylval.ttype = build_int_2 (result, 0);
1741 TREE_TYPE (yylval.ttype) = integer_type_node;
1750 p = token_buffer + 1;
1752 while (c != '"' && c >= 0)
1754 /* ignore_escape_flag is set for reading the filename in #line. */
1755 if (!ignore_escape_flag && c == '\\')
1761 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1762 && c >= (1 << TYPE_PRECISION (char_type_node)))
1763 pedwarn ("escape sequence out of range for character");
1768 pedwarn ("ANSI C forbids newline in string constant");
1772 if (p == token_buffer + maxtoken)
1773 p = extend_token_buffer (p);
1781 /* We have read the entire constant.
1782 Construct a STRING_CST for the result. */
1786 /* If this is a L"..." wide-string, convert the multibyte string
1787 to a wide character string. */
1788 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1791 #ifdef MULTIBYTE_CHARS
1792 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1793 if ((unsigned) len >= (p - token_buffer))
1795 warning ("Ignoring invalid multibyte string");
1798 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1801 union { long l; char c[sizeof (long)]; } u;
1805 /* Determine whether host is little or big endian. */
1807 big_endian = u.c[sizeof (long) - 1];
1808 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1810 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1811 for (cp = token_buffer + 1; cp < p; cp++)
1812 *wp = *cp, wp += WCHAR_BYTES;
1813 len = p - token_buffer - 1;
1816 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1817 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1821 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
1822 TREE_TYPE (yylval.ttype) = char_array_type_node;
1828 value = STRING; break;
1851 yylval.code = PLUS_EXPR; break;
1853 yylval.code = MINUS_EXPR; break;
1855 yylval.code = BIT_AND_EXPR; break;
1857 yylval.code = BIT_IOR_EXPR; break;
1859 yylval.code = MULT_EXPR; break;
1861 yylval.code = TRUNC_DIV_EXPR; break;
1863 yylval.code = TRUNC_MOD_EXPR; break;
1865 yylval.code = BIT_XOR_EXPR; break;
1867 yylval.code = LSHIFT_EXPR; break;
1869 yylval.code = RSHIFT_EXPR; break;
1871 yylval.code = LT_EXPR; break;
1873 yylval.code = GT_EXPR; break;
1876 token_buffer[1] = c1 = getc (finput);
1877 token_buffer[2] = 0;
1884 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
1886 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
1888 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
1890 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
1892 value = ASSIGN; goto done;
1898 value = PLUSPLUS; goto done;
1900 value = MINUSMINUS; goto done;
1902 value = ANDAND; goto done;
1904 value = OROR; goto done;
1912 else if ((c == '-') && (c1 == '>'))
1913 { value = POINTSAT; goto done; }
1914 ungetc (c1, finput);
1915 token_buffer[1] = 0;
1917 if ((c == '<') || (c == '>'))
1918 value = ARITHCOMPARE;
1924 /* Don't make yyparse think this is eof. */
1933 /* yylloc.last_line = lineno; */
1938 /* Sets the value of the 'yydebug' variable to VALUE.
1939 This is a function so we don't have to have YYDEBUG defined
1940 in order to build the compiler. */
1949 warning ("YYDEBUG not defined.");