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)
343 #if HOST_BITS_PER_WIDE_INT == 64
344 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
350 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
356 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
362 /* If C is not whitespace, return C.
363 Otherwise skip whitespace and return first nonwhite char read. */
369 static int newline_warning = 0;
375 /* We don't recognize comments here, because
376 cpp output can include / and * consecutively as operators.
377 Also, there's no need, since cpp removes all comments. */
380 c = check_newline ();
392 /* ANSI C says the effects of a carriage return in a source file
394 if (pedantic && !newline_warning)
396 warning ("carriage return in source file");
397 warning ("(we only warn about the first carriage return)");
408 error ("stray '\\' in program");
418 /* Skips all of the white space at the current location in the input file.
419 Must use and reset nextchar if it has the next character. */
422 position_after_white_space ()
427 c = nextchar, nextchar = -1;
431 ungetc (skip_white_space (c), finput);
434 /* Make the token buffer longer, preserving the data in it.
435 P should point to just beyond the last valid character in the old buffer.
436 The value we return is a pointer to the new buffer
437 at a place corresponding to P. */
440 extend_token_buffer (p)
443 int offset = p - token_buffer;
445 maxtoken = maxtoken * 2 + 10;
446 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
448 return token_buffer + offset;
451 /* At the beginning of a line, increment the line number
452 and process any #-directive on this line.
453 If the line is a #-directive, read the entire line and return a newline.
454 Otherwise, return the line's first non-whitespace character. */
464 /* Read first nonwhite char on the line. */
467 while (c == ' ' || c == '\t')
472 /* If not #, return it so caller will use it. */
476 /* Read first nonwhite char after the `#'. */
479 while (c == ' ' || c == '\t')
482 /* If a letter follows, then if the word here is `line', skip
483 it and ignore it; otherwise, ignore the line, with an error
484 if the word isn't `pragma', `ident', `define', or `undef'. */
486 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
490 if (getc (finput) == 'r'
491 && getc (finput) == 'a'
492 && getc (finput) == 'g'
493 && getc (finput) == 'm'
494 && getc (finput) == 'a'
495 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
497 #ifdef HANDLE_SYSV_PRAGMA
498 return handle_sysv_pragma (finput, c);
499 #endif /* HANDLE_SYSV_PRAGMA */
501 HANDLE_PRAGMA (finput);
502 #endif /* HANDLE_PRAGMA */
509 if (getc (finput) == 'e'
510 && getc (finput) == 'f'
511 && getc (finput) == 'i'
512 && getc (finput) == 'n'
513 && getc (finput) == 'e'
514 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
516 #ifdef DWARF_DEBUGGING_INFO
517 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
518 && (write_symbols == DWARF_DEBUG))
519 dwarfout_define (lineno, get_directive_line (finput));
520 #endif /* DWARF_DEBUGGING_INFO */
526 if (getc (finput) == 'n'
527 && getc (finput) == 'd'
528 && getc (finput) == 'e'
529 && getc (finput) == 'f'
530 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
532 #ifdef DWARF_DEBUGGING_INFO
533 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
534 && (write_symbols == DWARF_DEBUG))
535 dwarfout_undef (lineno, get_directive_line (finput));
536 #endif /* DWARF_DEBUGGING_INFO */
542 if (getc (finput) == 'i'
543 && getc (finput) == 'n'
544 && getc (finput) == 'e'
545 && ((c = getc (finput)) == ' ' || c == '\t'))
550 if (getc (finput) == 'd'
551 && getc (finput) == 'e'
552 && getc (finput) == 'n'
553 && getc (finput) == 't'
554 && ((c = getc (finput)) == ' ' || c == '\t'))
556 /* #ident. The pedantic warning is now in cccp.c. */
558 /* Here we have just seen `#ident '.
559 A string constant should follow. */
561 while (c == ' ' || c == '\t')
564 /* If no argument, ignore the line. */
571 || TREE_CODE (yylval.ttype) != STRING_CST)
573 error ("invalid #ident");
579 #ifdef ASM_OUTPUT_IDENT
580 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
584 /* Skip the rest of this line. */
589 error ("undefined or invalid # directive");
594 /* Here we have either `#line' or `# <nonletter>'.
595 In either case, it should be a line number; a digit should follow. */
597 while (c == ' ' || c == '\t')
600 /* If the # is the only nonwhite char on the line,
601 just ignore it. Check the new newline. */
605 /* Something follows the #; read a token. */
610 if (token == CONSTANT
611 && TREE_CODE (yylval.ttype) == INTEGER_CST)
613 int old_lineno = lineno;
615 /* subtract one, because it is the following line that
616 gets the specified number */
618 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
620 /* Is this the last nonwhite stuff on the line? */
622 while (c == ' ' || c == '\t')
626 /* No more: store the line number and check following line. */
632 /* More follows: it must be a string constant (filename). */
634 /* Read the string constant, but don't treat \ as special. */
635 ignore_escape_flag = 1;
637 ignore_escape_flag = 0;
639 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
641 error ("invalid #line");
646 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
647 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
650 /* Each change of file name
651 reinitializes whether we are now in a system header. */
652 in_system_header = 0;
654 if (main_input_filename == 0)
655 main_input_filename = input_filename;
657 /* Is this the last nonwhite stuff on the line? */
659 while (c == ' ' || c == '\t')
668 /* `1' after file name means entering new file.
669 `2' after file name means just left a file. */
671 if (token == CONSTANT
672 && TREE_CODE (yylval.ttype) == INTEGER_CST)
674 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
676 /* Pushing to a new file. */
678 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
679 input_file_stack->line = old_lineno;
680 p->next = input_file_stack;
681 p->name = input_filename;
682 input_file_stack = p;
683 input_file_stack_tick++;
684 #ifdef DWARF_DEBUGGING_INFO
685 if (debug_info_level == DINFO_LEVEL_VERBOSE
686 && write_symbols == DWARF_DEBUG)
687 dwarfout_start_new_source_file (input_filename);
688 #endif /* DWARF_DEBUGGING_INFO */
692 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
694 /* Popping out of a file. */
695 if (input_file_stack->next)
697 struct file_stack *p = input_file_stack;
698 input_file_stack = p->next;
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_resume_previous_source_file (input_file_stack->line);
705 #endif /* DWARF_DEBUGGING_INFO */
708 error ("#-lines for entering and leaving files don't match");
714 /* If we have handled a `1' or a `2',
715 see if there is another number to read. */
718 /* Is this the last nonwhite stuff on the line? */
720 while (c == ' ' || c == '\t')
730 /* `3' after file name means this is a system header file. */
732 if (token == CONSTANT
733 && TREE_CODE (yylval.ttype) == INTEGER_CST
734 && TREE_INT_CST_LOW (yylval.ttype) == 3)
735 in_system_header = 1;
738 error ("invalid #-line");
740 /* skip the rest of this line. */
744 while ((c = getc (finput)) != EOF && c != '\n');
748 #ifdef HANDLE_SYSV_PRAGMA
750 /* Handle a #pragma directive. INPUT is the current input stream,
751 and C is a character to reread. Processes the entire input line
752 and returns a character for the caller to reread: either \n or EOF. */
754 /* This function has to be in this file, in order to get at
758 handle_sysv_pragma (input, c)
764 while (c == ' ' || c == '\t')
766 if (c == '\n' || c == EOF)
768 handle_pragma_token (0, 0);
778 handle_pragma_token (token_buffer, yylval.ttype);
781 handle_pragma_token (token_buffer, 0);
784 c = nextchar, nextchar = -1;
790 #endif /* HANDLE_SYSV_PRAGMA */
792 #define isalnum(char) ((char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'))
793 #define isdigit(char) (char >= '0' && char <= '9')
794 #define ENDFILE -1 /* token that represents end-of-file */
796 /* Read an escape sequence, returning its equivalent as a character,
797 or store 1 in *ignore_ptr if it is backslash-newline. */
800 readescape (ignore_ptr)
803 register int c = getc (finput);
805 register unsigned count;
812 if (warn_traditional)
813 warning ("the meaning of `\\x' varies with -traditional");
815 if (flag_traditional)
824 if (!(c >= 'a' && c <= 'f')
825 && !(c >= 'A' && c <= 'F')
826 && !(c >= '0' && c <= '9'))
832 if (c >= 'a' && c <= 'f')
833 code += c - 'a' + 10;
834 if (c >= 'A' && c <= 'F')
835 code += c - 'A' + 10;
836 if (c >= '0' && c <= '9')
838 if (code != 0 || count != 0)
847 error ("\\x used with no following hex digits");
849 /* Digits are all 0's. Ok. */
851 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
853 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
855 pedwarn ("hex escape out of range");
858 case '0': case '1': case '2': case '3': case '4':
859 case '5': case '6': case '7':
862 while ((c <= '7') && (c >= '0') && (count++ < 3))
864 code = (code * 8) + (c - '0');
870 case '\\': case '\'': case '"':
879 return TARGET_NEWLINE;
894 if (warn_traditional)
895 warning ("the meaning of `\\a' varies with -traditional");
897 if (flag_traditional)
902 #if 0 /* Vertical tab is present in common usage compilers. */
903 if (flag_traditional)
911 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
917 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
922 pedwarn ("non-ANSI escape sequence `\\%c'", c);
925 if (c >= 040 && c < 0177)
926 pedwarn ("unknown escape sequence `\\%c'", c);
928 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
938 strcpy (buf, string);
940 /* We can't print string and character constants well
941 because the token_buffer contains the result of processing escapes. */
943 strcat (buf, " at end of input");
944 else if (token_buffer[0] == 0)
945 strcat (buf, " at null character");
946 else if (token_buffer[0] == '"')
947 strcat (buf, " before string constant");
948 else if (token_buffer[0] == '\'')
949 strcat (buf, " before character constant");
950 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
951 sprintf (buf + strlen (buf), " before character 0%o",
952 (unsigned char) token_buffer[0]);
954 strcat (buf, " before `%s'");
956 error (buf, token_buffer);
969 struct try_type type_sequence[] =
971 { &integer_type_node, 0, 0, 0},
972 { &unsigned_type_node, 1, 0, 0},
973 { &long_integer_type_node, 0, 1, 0},
974 { &long_unsigned_type_node, 1, 1, 0},
975 { &long_long_integer_type_node, 0, 1, 1},
976 { &long_long_unsigned_type_node, 1, 1, 1}
989 c = nextchar, nextchar = -1;
993 /* Effectively do c = skip_white_space (c)
994 but do it faster in the usual cases. */
1007 /* Call skip_white_space so we can warn if appropriate. */
1012 c = skip_white_space (c);
1014 goto found_nonwhite;
1018 token_buffer[0] = c;
1019 token_buffer[1] = 0;
1021 /* yylloc.first_line = lineno; */
1027 if (! global_bindings_p ())
1029 yyerror ("parse error");
1030 token_buffer[0] = '}';
1034 token_buffer[0] = 0;
1039 if (dollars_in_ident)
1044 /* Capital L may start a wide-string or wide-character constant. */
1046 register int c = getc (finput);
1055 goto string_constant;
1062 if (!doing_objc_thang)
1070 while (isalnum (c) || c == '_')
1072 if (p >= token_buffer + maxtoken)
1073 p = extend_token_buffer (p);
1081 value = recognize_objc_keyword (token_buffer + 1);
1084 error ("invalid Objective C keyword `%s'", token_buffer);
1085 /* Cause a syntax error--1 is not a valid token type. */
1089 case 'A': case 'B': case 'C': case 'D': case 'E':
1090 case 'F': case 'G': case 'H': case 'I': case 'J':
1091 case 'K': case 'M': case 'N': case 'O':
1092 case 'P': case 'Q': case 'R': case 'S': case 'T':
1093 case 'U': case 'V': case 'W': case 'X': case 'Y':
1095 case 'a': case 'b': case 'c': case 'd': case 'e':
1096 case 'f': case 'g': case 'h': case 'i': case 'j':
1097 case 'k': case 'l': case 'm': case 'n': case 'o':
1098 case 'p': case 'q': case 'r': case 's': case 't':
1099 case 'u': case 'v': case 'w': case 'x': case 'y':
1104 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1106 /* Make sure this char really belongs in an identifier. */
1107 if (c == '@' && ! doing_objc_thang)
1109 if (c == '$' && ! dollars_in_ident)
1112 if (p >= token_buffer + maxtoken)
1113 p = extend_token_buffer (p);
1125 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1128 register struct resword *ptr;
1130 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1133 yylval.ttype = ridpointers[(int) ptr->rid];
1134 value = (int) ptr->token;
1136 /* Even if we decided to recognize asm, still perhaps warn. */
1138 && (value == ASM_KEYWORD || value == TYPEOF
1139 || ptr->rid == RID_INLINE)
1140 && token_buffer[0] != '_')
1141 pedwarn ("ANSI does not permit the keyword `%s'",
1146 /* If we did not find a keyword, look for an identifier
1149 if (value == IDENTIFIER)
1151 yylval.ttype = get_identifier (token_buffer);
1152 lastiddecl = lookup_name (yylval.ttype);
1154 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1156 /* A user-invisible read-only initialized variable
1157 should be replaced by its value.
1158 We handle only strings since that's the only case used in C. */
1159 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1160 && DECL_IGNORED_P (lastiddecl)
1161 && TREE_READONLY (lastiddecl)
1162 && DECL_INITIAL (lastiddecl) != 0
1163 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1165 yylval.ttype = DECL_INITIAL (lastiddecl);
1168 else if (doing_objc_thang)
1170 tree objc_interface_decl = lookup_interface (yylval.ttype);
1172 if (objc_interface_decl)
1175 yylval.ttype = objc_interface_decl;
1182 case '0': case '1': case '2': case '3': case '4':
1183 case '5': case '6': case '7': case '8': case '9':
1188 int largest_digit = 0;
1190 /* for multi-precision arithmetic,
1191 we actually store only HOST_BITS_PER_CHAR bits in each part.
1192 The number of parts is chosen so as to be sufficient to hold
1193 the enough bits to fit into the two HOST_WIDE_INTs that contain
1194 the integer value (this is always at least as many bits as are
1195 in a target `long long' value, but may be wider). */
1196 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1197 int parts[TOTAL_PARTS];
1200 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1203 for (count = 0; count < TOTAL_PARTS; count++)
1211 *p++ = (c = getc (finput));
1212 if ((c == 'x') || (c == 'X'))
1215 *p++ = (c = getc (finput));
1217 /* Leading 0 forces octal unless the 0 is the only digit. */
1218 else if (c >= '0' && c <= '9')
1227 /* Read all the digits-and-decimal-points. */
1230 || (isalnum (c) && (c != 'l') && (c != 'L')
1231 && (c != 'u') && (c != 'U')
1232 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1237 error ("floating constant may not be in radix 16");
1238 if (floatflag == AFTER_POINT)
1240 error ("malformed floating constant");
1241 floatflag = TOO_MANY_POINTS;
1244 floatflag = AFTER_POINT;
1247 *p++ = c = getc (finput);
1248 /* Accept '.' as the start of a floating-point number
1249 only when it is followed by a digit.
1250 Otherwise, unread the following non-digit
1251 and use the '.' as a structural token. */
1252 if (p == token_buffer + 2 && !isdigit (c))
1263 error ("parse error at `..'");
1266 token_buffer[1] = 0;
1273 /* It is not a decimal point.
1274 It should be a digit (perhaps a hex digit). */
1280 else if (base <= 10)
1282 if ((c&~040) == 'E')
1285 floatflag = AFTER_POINT;
1286 break; /* start of exponent */
1288 error ("nondigits in number and not hexadecimal");
1299 if (c >= largest_digit)
1303 for (count = 0; count < TOTAL_PARTS; count++)
1305 parts[count] *= base;
1309 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1311 &= (1 << HOST_BITS_PER_CHAR) - 1;
1317 /* If the extra highest-order part ever gets anything in it,
1318 the number is certainly too big. */
1319 if (parts[TOTAL_PARTS - 1] != 0)
1322 if (p >= token_buffer + maxtoken - 3)
1323 p = extend_token_buffer (p);
1324 *p++ = (c = getc (finput));
1329 error ("numeric constant with no digits");
1331 if (largest_digit >= base)
1332 error ("numeric constant contains digits beyond the radix");
1334 /* Remove terminating char from the token buffer and delimit the string */
1337 if (floatflag != NOT_FLOAT)
1339 tree type = double_type_node;
1340 int garbage_chars = 0, exceeds_double = 0;
1341 REAL_VALUE_TYPE value;
1344 /* Read explicit exponent if any, and put it in tokenbuf. */
1346 if ((c == 'e') || (c == 'E'))
1348 if (p >= token_buffer + maxtoken - 3)
1349 p = extend_token_buffer (p);
1352 if ((c == '+') || (c == '-'))
1358 error ("floating constant exponent has no digits");
1361 if (p >= token_buffer + maxtoken - 3)
1362 p = extend_token_buffer (p);
1371 /* Convert string to a double, checking for overflow. */
1372 if (setjmp (handler))
1374 error ("floating constant out of range");
1379 set_float_handler (handler);
1380 value = REAL_VALUE_ATOF (token_buffer);
1381 set_float_handler (NULL_PTR);
1384 if (errno == ERANGE && !flag_traditional && pedantic)
1386 /* ERANGE is also reported for underflow,
1387 so test the value to distinguish overflow from that. */
1388 if (REAL_VALUES_LESS (dconst1, value)
1389 || REAL_VALUES_LESS (value, dconstm1))
1391 pedwarn ("floating point number exceeds range of `double'");
1397 /* Read the suffixes to choose a data type. */
1401 type = float_type_node;
1402 value = REAL_VALUE_TRUNCATE (TYPE_MODE (type), value);
1403 if (REAL_VALUE_ISINF (value) && ! exceeds_double && pedantic)
1404 pedwarn ("floating point number exceeds range of `float'");
1409 type = long_double_type_node;
1413 /* Note: garbage_chars is -1 if first char is *not* garbage. */
1416 if (p >= token_buffer + maxtoken - 3)
1417 p = extend_token_buffer (p);
1422 if (garbage_chars > 0)
1423 error ("garbage at end of number");
1425 /* Create a node with determined type and value. */
1426 yylval.ttype = build_real (type, value);
1433 tree traditional_type, ansi_type, type;
1434 HOST_WIDE_INT high, low;
1435 int spec_unsigned = 0;
1437 int spec_long_long = 0;
1442 if (c == 'u' || c == 'U')
1445 error ("two `u's in integer constant");
1448 else if (c == 'l' || c == 'L')
1453 error ("three `l's in integer constant");
1455 pedwarn ("ANSI C forbids long long integer constants");
1464 error ("garbage at end of number");
1467 if (p >= token_buffer + maxtoken - 3)
1468 p = extend_token_buffer (p);
1475 if (p >= token_buffer + maxtoken - 3)
1476 p = extend_token_buffer (p);
1483 /* If the constant is not long long and it won't fit in an
1484 unsigned long, or if the constant is long long and won't fit
1485 in an unsigned long long, then warn that the constant is out
1488 /* ??? This assumes that long long and long integer types are
1489 a multiple of 8 bits. This better than the original code
1490 though which assumed that long was exactly 32 bits and long
1491 long was exactly 64 bits. */
1494 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1496 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1499 for (i = bytes; i < TOTAL_PARTS; i++)
1503 pedwarn ("integer constant out of range");
1505 /* This is simplified by the fact that our constant
1506 is always positive. */
1510 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1512 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1513 / HOST_BITS_PER_CHAR)]
1514 << (i * HOST_BITS_PER_CHAR));
1515 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1518 yylval.ttype = build_int_2 (low, high);
1519 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1521 /* If warn_traditional, calculate both the ANSI type and the
1522 traditional type, then see if they disagree.
1523 Otherwise, calculate only the type for the dialect in use. */
1524 if (warn_traditional || flag_traditional)
1526 /* Calculate the traditional type. */
1527 /* Traditionally, any constant is signed;
1528 but if unsigned is specified explicitly, obey that.
1529 Use the smallest size with the right number of bits,
1530 except for one special case with decimal constants. */
1531 if (! spec_long && base != 10
1532 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1533 traditional_type = (spec_unsigned ? unsigned_type_node
1534 : integer_type_node);
1535 /* A decimal constant must be long
1536 if it does not fit in type int.
1537 I think this is independent of whether
1538 the constant is signed. */
1539 else if (! spec_long && base == 10
1540 && int_fits_type_p (yylval.ttype, integer_type_node))
1541 traditional_type = (spec_unsigned ? unsigned_type_node
1542 : integer_type_node);
1543 else if (! spec_long_long)
1544 traditional_type = (spec_unsigned ? long_unsigned_type_node
1545 : long_integer_type_node);
1547 traditional_type = (spec_unsigned
1548 ? long_long_unsigned_type_node
1549 : long_long_integer_type_node);
1551 if (warn_traditional || ! flag_traditional)
1553 /* Calculate the ANSI type. */
1554 if (! spec_long && ! spec_unsigned
1555 && int_fits_type_p (yylval.ttype, integer_type_node))
1556 ansi_type = integer_type_node;
1557 else if (! spec_long && (base != 10 || spec_unsigned)
1558 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1559 ansi_type = unsigned_type_node;
1560 else if (! spec_unsigned && !spec_long_long
1561 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1562 ansi_type = long_integer_type_node;
1563 else if (! spec_long_long)
1564 ansi_type = long_unsigned_type_node;
1565 else if (! spec_unsigned
1566 /* Verify value does not overflow into sign bit. */
1567 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
1568 && int_fits_type_p (yylval.ttype,
1569 long_long_integer_type_node))
1570 ansi_type = long_long_integer_type_node;
1572 ansi_type = long_long_unsigned_type_node;
1575 type = flag_traditional ? traditional_type : ansi_type;
1577 if (warn_traditional && traditional_type != ansi_type)
1579 if (TYPE_PRECISION (traditional_type)
1580 != TYPE_PRECISION (ansi_type))
1581 warning ("width of integer constant changes with -traditional");
1582 else if (TREE_UNSIGNED (traditional_type)
1583 != TREE_UNSIGNED (ansi_type))
1584 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1586 warning ("width of integer constant may change on other systems with -traditional");
1589 if (!flag_traditional && !int_fits_type_p (yylval.ttype, type)
1591 pedwarn ("integer constant out of range");
1593 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1594 warning ("decimal constant is so large that it is unsigned");
1596 if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1597 /* The traditional constant 0x80000000 is signed
1598 but doesn't fit in the range of int.
1599 This will change it to -0x80000000, which does fit. */
1601 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1602 yylval.ttype = convert (type, yylval.ttype);
1605 TREE_TYPE (yylval.ttype) = type;
1610 value = CONSTANT; break;
1616 register int result = 0;
1617 register int num_chars = 0;
1618 unsigned width = TYPE_PRECISION (char_type_node);
1623 width = WCHAR_TYPE_SIZE;
1624 #ifdef MULTIBYTE_CHARS
1625 max_chars = MB_CUR_MAX;
1631 max_chars = TYPE_PRECISION (integer_type_node) / width;
1639 if (c == '\'' || c == EOF)
1645 c = readescape (&ignore);
1648 if (width < HOST_BITS_PER_INT
1649 && (unsigned) c >= (1 << width))
1650 pedwarn ("escape sequence out of range for character");
1655 pedwarn ("ANSI C forbids newline in character constant");
1660 if (num_chars > maxtoken - 4)
1661 extend_token_buffer (token_buffer);
1663 token_buffer[num_chars] = c;
1665 /* Merge character into result; ignore excess chars. */
1666 if (num_chars < max_chars + 1)
1668 if (width < HOST_BITS_PER_INT)
1669 result = (result << width) | (c & ((1 << width) - 1));
1675 token_buffer[num_chars + 1] = '\'';
1676 token_buffer[num_chars + 2] = 0;
1679 error ("malformatted character constant");
1680 else if (num_chars == 0)
1681 error ("empty character constant");
1682 else if (num_chars > max_chars)
1684 num_chars = max_chars;
1685 error ("character constant too long");
1687 else if (num_chars != 1 && ! flag_traditional)
1688 warning ("multi-character character constant");
1690 /* If char type is signed, sign-extend the constant. */
1693 int num_bits = num_chars * width;
1694 if (TREE_UNSIGNED (char_type_node)
1695 || ((result >> (num_bits - 1)) & 1) == 0)
1697 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1698 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1702 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1703 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1708 #ifdef MULTIBYTE_CHARS
1709 /* Set the initial shift state and convert the next sequence. */
1711 /* In all locales L'\0' is zero and mbtowc will return zero,
1714 || (num_chars == 1 && token_buffer[1] != '\0'))
1717 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1718 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1721 warning ("Ignoring invalid multibyte character");
1724 yylval.ttype = build_int_2 (result, 0);
1727 TREE_TYPE (yylval.ttype) = integer_type_node;
1736 p = token_buffer + 1;
1738 while (c != '"' && c >= 0)
1740 /* ignore_escape_flag is set for reading the filename in #line. */
1741 if (!ignore_escape_flag && c == '\\')
1744 c = readescape (&ignore);
1748 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1749 && c >= (1 << TYPE_PRECISION (char_type_node)))
1750 pedwarn ("escape sequence out of range for character");
1755 pedwarn ("ANSI C forbids newline in string constant");
1759 if (p == token_buffer + maxtoken)
1760 p = extend_token_buffer (p);
1768 /* We have read the entire constant.
1769 Construct a STRING_CST for the result. */
1773 /* If this is a L"..." wide-string, convert the multibyte string
1774 to a wide character string. */
1775 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1778 #ifdef MULTIBYTE_CHARS
1779 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1780 if ((unsigned) len >= (p - token_buffer))
1782 warning ("Ignoring invalid multibyte string");
1785 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1788 union { long l; char c[sizeof (long)]; } u;
1792 /* Determine whether host is little or big endian. */
1794 big_endian = u.c[sizeof (long) - 1];
1795 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1797 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1798 for (cp = token_buffer + 1; cp < p; cp++)
1799 *wp = *cp, wp += WCHAR_BYTES;
1800 len = p - token_buffer - 1;
1803 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1804 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1808 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
1809 TREE_TYPE (yylval.ttype) = char_array_type_node;
1815 value = STRING; break;
1838 yylval.code = PLUS_EXPR; break;
1840 yylval.code = MINUS_EXPR; break;
1842 yylval.code = BIT_AND_EXPR; break;
1844 yylval.code = BIT_IOR_EXPR; break;
1846 yylval.code = MULT_EXPR; break;
1848 yylval.code = TRUNC_DIV_EXPR; break;
1850 yylval.code = TRUNC_MOD_EXPR; break;
1852 yylval.code = BIT_XOR_EXPR; break;
1854 yylval.code = LSHIFT_EXPR; break;
1856 yylval.code = RSHIFT_EXPR; break;
1858 yylval.code = LT_EXPR; break;
1860 yylval.code = GT_EXPR; break;
1863 token_buffer[1] = c1 = getc (finput);
1864 token_buffer[2] = 0;
1871 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
1873 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
1875 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
1877 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
1879 value = ASSIGN; goto done;
1885 value = PLUSPLUS; goto done;
1887 value = MINUSMINUS; goto done;
1889 value = ANDAND; goto done;
1891 value = OROR; goto done;
1899 else if ((c == '-') && (c1 == '>'))
1900 { value = POINTSAT; goto done; }
1901 ungetc (c1, finput);
1902 token_buffer[1] = 0;
1904 if ((c == '<') || (c == '>'))
1905 value = ARITHCOMPARE;
1911 /* Don't make yyparse think this is eof. */
1920 /* yylloc.last_line = lineno; */
1925 /* Sets the value of the 'yydebug' variable to VALUE.
1926 This is a function so we don't have to have YYDEBUG defined
1927 in order to build the compiler. */
1936 warning ("YYDEBUG not defined.");