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. */
356 static int newline_warning = 0;
362 /* We don't recognize comments here, because
363 cpp output can include / and * consecutively as operators.
364 Also, there's no need, since cpp removes all comments. */
367 c = check_newline ();
379 /* ANSI C says the effects of a carriage return in a source file
381 if (pedantic && !newline_warning)
383 warning ("carriage return in source file");
384 warning ("(we only warn about the first carriage return)");
395 error ("stray '\\' in program");
405 /* Skips all of the white space at the current location in the input file.
406 Must use and reset nextchar if it has the next character. */
409 position_after_white_space ()
414 c = nextchar, nextchar = -1;
418 ungetc (skip_white_space (c), finput);
421 /* Make the token buffer longer, preserving the data in it.
422 P should point to just beyond the last valid character in the old buffer.
423 The value we return is a pointer to the new buffer
424 at a place corresponding to P. */
427 extend_token_buffer (p)
430 int offset = p - token_buffer;
432 maxtoken = maxtoken * 2 + 10;
433 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
435 return token_buffer + offset;
438 /* At the beginning of a line, increment the line number
439 and process any #-directive on this line.
440 If the line is a #-directive, read the entire line and return a newline.
441 Otherwise, return the line's first non-whitespace character. */
451 /* Read first nonwhite char on the line. */
454 while (c == ' ' || c == '\t')
459 /* If not #, return it so caller will use it. */
463 /* Read first nonwhite char after the `#'. */
466 while (c == ' ' || c == '\t')
469 /* If a letter follows, then if the word here is `line', skip
470 it and ignore it; otherwise, ignore the line, with an error
471 if the word isn't `pragma', `ident', `define', or `undef'. */
473 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
477 if (getc (finput) == 'r'
478 && getc (finput) == 'a'
479 && getc (finput) == 'g'
480 && getc (finput) == 'm'
481 && getc (finput) == 'a'
482 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
484 #ifdef HANDLE_SYSV_PRAGMA
485 return handle_sysv_pragma (finput, c);
486 #endif /* HANDLE_SYSV_PRAGMA */
488 HANDLE_PRAGMA (finput);
489 #endif /* HANDLE_PRAGMA */
496 if (getc (finput) == 'e'
497 && getc (finput) == 'f'
498 && getc (finput) == 'i'
499 && getc (finput) == 'n'
500 && getc (finput) == 'e'
501 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
503 #ifdef DWARF_DEBUGGING_INFO
504 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
505 && (write_symbols == DWARF_DEBUG))
506 dwarfout_define (lineno, get_directive_line (finput));
507 #endif /* DWARF_DEBUGGING_INFO */
513 if (getc (finput) == 'n'
514 && getc (finput) == 'd'
515 && getc (finput) == 'e'
516 && getc (finput) == 'f'
517 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
519 #ifdef DWARF_DEBUGGING_INFO
520 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
521 && (write_symbols == DWARF_DEBUG))
522 dwarfout_undef (lineno, get_directive_line (finput));
523 #endif /* DWARF_DEBUGGING_INFO */
529 if (getc (finput) == 'i'
530 && getc (finput) == 'n'
531 && getc (finput) == 'e'
532 && ((c = getc (finput)) == ' ' || c == '\t'))
537 if (getc (finput) == 'd'
538 && getc (finput) == 'e'
539 && getc (finput) == 'n'
540 && getc (finput) == 't'
541 && ((c = getc (finput)) == ' ' || c == '\t'))
543 /* #ident. The pedantic warning is now in cccp.c. */
545 /* Here we have just seen `#ident '.
546 A string constant should follow. */
548 while (c == ' ' || c == '\t')
551 /* If no argument, ignore the line. */
558 || TREE_CODE (yylval.ttype) != STRING_CST)
560 error ("invalid #ident");
566 #ifdef ASM_OUTPUT_IDENT
567 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
571 /* Skip the rest of this line. */
576 error ("undefined or invalid # directive");
581 /* Here we have either `#line' or `# <nonletter>'.
582 In either case, it should be a line number; a digit should follow. */
584 while (c == ' ' || c == '\t')
587 /* If the # is the only nonwhite char on the line,
588 just ignore it. Check the new newline. */
592 /* Something follows the #; read a token. */
597 if (token == CONSTANT
598 && TREE_CODE (yylval.ttype) == INTEGER_CST)
600 int old_lineno = lineno;
602 /* subtract one, because it is the following line that
603 gets the specified number */
605 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
607 /* Is this the last nonwhite stuff on the line? */
609 while (c == ' ' || c == '\t')
613 /* No more: store the line number and check following line. */
619 /* More follows: it must be a string constant (filename). */
621 /* Read the string constant, but don't treat \ as special. */
622 ignore_escape_flag = 1;
624 ignore_escape_flag = 0;
626 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
628 error ("invalid #line");
633 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
634 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
637 /* Each change of file name
638 reinitializes whether we are now in a system header. */
639 in_system_header = 0;
641 if (main_input_filename == 0)
642 main_input_filename = input_filename;
644 /* Is this the last nonwhite stuff on the line? */
646 while (c == ' ' || c == '\t')
655 /* `1' after file name means entering new file.
656 `2' after file name means just left a file. */
658 if (token == CONSTANT
659 && TREE_CODE (yylval.ttype) == INTEGER_CST)
661 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
663 /* Pushing to a new file. */
665 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
666 input_file_stack->line = old_lineno;
667 p->next = input_file_stack;
668 p->name = input_filename;
669 input_file_stack = p;
670 input_file_stack_tick++;
671 #ifdef DWARF_DEBUGGING_INFO
672 if (debug_info_level == DINFO_LEVEL_VERBOSE
673 && write_symbols == DWARF_DEBUG)
674 dwarfout_start_new_source_file (input_filename);
675 #endif /* DWARF_DEBUGGING_INFO */
679 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
681 /* Popping out of a file. */
682 if (input_file_stack->next)
684 struct file_stack *p = input_file_stack;
685 input_file_stack = p->next;
687 input_file_stack_tick++;
688 #ifdef DWARF_DEBUGGING_INFO
689 if (debug_info_level == DINFO_LEVEL_VERBOSE
690 && write_symbols == DWARF_DEBUG)
691 dwarfout_resume_previous_source_file (input_file_stack->line);
692 #endif /* DWARF_DEBUGGING_INFO */
695 error ("#-lines for entering and leaving files don't match");
701 /* If we have handled a `1' or a `2',
702 see if there is another number to read. */
705 /* Is this the last nonwhite stuff on the line? */
707 while (c == ' ' || c == '\t')
717 /* `3' after file name means this is a system header file. */
719 if (token == CONSTANT
720 && TREE_CODE (yylval.ttype) == INTEGER_CST
721 && TREE_INT_CST_LOW (yylval.ttype) == 3)
722 in_system_header = 1;
725 error ("invalid #-line");
727 /* skip the rest of this line. */
731 while ((c = getc (finput)) != EOF && c != '\n');
735 #ifdef HANDLE_SYSV_PRAGMA
737 /* Handle a #pragma directive. INPUT is the current input stream,
738 and C is a character to reread. Processes the entire input line
739 and returns a character for the caller to reread: either \n or EOF. */
741 /* This function has to be in this file, in order to get at
745 handle_sysv_pragma (input, c)
751 while (c == ' ' || c == '\t')
753 if (c == '\n' || c == EOF)
755 handle_pragma_token (0, 0);
765 handle_pragma_token (token_buffer, yylval.ttype);
768 handle_pragma_token (token_buffer, 0);
771 c = nextchar, nextchar = -1;
777 #endif /* HANDLE_SYSV_PRAGMA */
779 #define isalnum(char) ((char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'))
780 #define isdigit(char) (char >= '0' && char <= '9')
781 #define ENDFILE -1 /* token that represents end-of-file */
783 /* Read an escape sequence, returning its equivalent as a character,
784 or -1 if it is backslash-newline. */
789 register int c = getc (finput);
791 register unsigned count;
797 if (warn_traditional)
798 warning ("the meaning of `\\x' varies with -traditional");
800 if (flag_traditional)
808 if (!(c >= 'a' && c <= 'f')
809 && !(c >= 'A' && c <= 'F')
810 && !(c >= '0' && c <= '9'))
816 if (c >= 'a' && c <= 'f')
817 code += c - 'a' + 10;
818 if (c >= 'A' && c <= 'F')
819 code += c - 'A' + 10;
820 if (c >= '0' && c <= '9')
827 error ("\\x used with no following hex digits");
828 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
830 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
832 pedwarn ("hex escape out of range");
835 case '0': case '1': case '2': case '3': case '4':
836 case '5': case '6': case '7':
839 while ((c <= '7') && (c >= '0') && (count++ < 3))
841 code = (code * 8) + (c - '0');
847 case '\\': case '\'': case '"':
855 return TARGET_NEWLINE;
870 if (warn_traditional)
871 warning ("the meaning of `\\a' varies with -traditional");
873 if (flag_traditional)
878 #if 0 /* Vertical tab is present in common usage compilers. */
879 if (flag_traditional)
885 pedwarn ("non-ANSI-standard escape sequence, `\\E'");
891 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
896 pedwarn ("non-ANSI escape sequence `\\%c'", c);
899 if (c >= 040 && c <= 0177)
900 pedwarn ("unknown escape sequence `\\%c'", c);
902 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
912 strcpy (buf, string);
914 /* We can't print string and character constants well
915 because the token_buffer contains the result of processing escapes. */
917 strcat (buf, " at end of input");
918 else if (token_buffer[0] == 0)
919 strcat (buf, " at null character");
920 else if (token_buffer[0] == '"')
921 strcat (buf, " before string constant");
922 else if (token_buffer[0] == '\'')
923 strcat (buf, " before character constant");
924 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
925 sprintf (buf + strlen (buf), " before character 0%o",
926 (unsigned char) token_buffer[0]);
928 strcat (buf, " before `%s'");
930 error (buf, token_buffer);
943 struct try_type type_sequence[] =
945 { &integer_type_node, 0, 0, 0},
946 { &unsigned_type_node, 1, 0, 0},
947 { &long_integer_type_node, 0, 1, 0},
948 { &long_unsigned_type_node, 1, 1, 0},
949 { &long_long_integer_type_node, 0, 1, 1},
950 { &long_long_unsigned_type_node, 1, 1, 1}
963 c = nextchar, nextchar = -1;
967 /* Effectively do c = skip_white_space (c)
968 but do it faster in the usual cases. */
981 /* Call skip_white_space so we can warn if appropriate. */
986 c = skip_white_space (c);
995 /* yylloc.first_line = lineno; */
1001 token_buffer[0] = 0;
1006 if (dollars_in_ident)
1011 /* Capital L may start a wide-string or wide-character constant. */
1013 register int c = getc (finput);
1022 goto string_constant;
1029 if (!doing_objc_thang)
1037 while (isalnum (c) || c == '_')
1039 if (p >= token_buffer + maxtoken)
1040 p = extend_token_buffer (p);
1048 value = recognize_objc_keyword (token_buffer + 1);
1051 error ("invalid Objective C keyword `%s'", token_buffer);
1052 /* Cause a syntax error--1 is not a valid token type. */
1056 case 'A': case 'B': case 'C': case 'D': case 'E':
1057 case 'F': case 'G': case 'H': case 'I': case 'J':
1058 case 'K': case 'M': case 'N': case 'O':
1059 case 'P': case 'Q': case 'R': case 'S': case 'T':
1060 case 'U': case 'V': case 'W': case 'X': case 'Y':
1062 case 'a': case 'b': case 'c': case 'd': case 'e':
1063 case 'f': case 'g': case 'h': case 'i': case 'j':
1064 case 'k': case 'l': case 'm': case 'n': case 'o':
1065 case 'p': case 'q': case 'r': case 's': case 't':
1066 case 'u': case 'v': case 'w': case 'x': case 'y':
1071 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1073 if (p >= token_buffer + maxtoken)
1074 p = extend_token_buffer (p);
1075 if (c == '$' && ! dollars_in_ident)
1088 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1091 register struct resword *ptr;
1093 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1096 yylval.ttype = ridpointers[(int) ptr->rid];
1097 value = (int) ptr->token;
1099 /* Even if we decided to recognize asm, still perhaps warn. */
1101 && (value == ASM_KEYWORD || value == TYPEOF
1102 || ptr->rid == RID_INLINE)
1103 && token_buffer[0] != '_')
1104 pedwarn ("ANSI does not permit the keyword `%s'",
1109 /* If we did not find a keyword, look for an identifier
1112 if (value == IDENTIFIER)
1114 yylval.ttype = get_identifier (token_buffer);
1115 lastiddecl = lookup_name (yylval.ttype);
1117 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1119 /* A user-invisible read-only initialized variable
1120 should be replaced by its value.
1121 We handle only strings since that's the only case used in C. */
1122 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1123 && DECL_IGNORED_P (lastiddecl)
1124 && TREE_READONLY (lastiddecl)
1125 && DECL_INITIAL (lastiddecl) != 0
1126 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1128 yylval.ttype = DECL_INITIAL (lastiddecl);
1131 else if (doing_objc_thang)
1133 tree objc_interface_decl = lookup_interface (yylval.ttype);
1135 if (objc_interface_decl)
1138 yylval.ttype = objc_interface_decl;
1145 case '0': case '1': case '2': case '3': case '4':
1146 case '5': case '6': case '7': case '8': case '9':
1151 int largest_digit = 0;
1153 /* for multi-precision arithmetic,
1154 we store only 8 live bits in each short,
1155 giving us 64 bits of reliable precision */
1159 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1162 for (count = 0; count < 8; count++)
1170 *p++ = (c = getc (finput));
1171 if ((c == 'x') || (c == 'X'))
1174 *p++ = (c = getc (finput));
1176 /* Leading 0 forces octal unless the 0 is the only digit. */
1177 else if (c >= '0' && c <= '9')
1186 /* Read all the digits-and-decimal-points. */
1189 || (isalnum (c) && (c != 'l') && (c != 'L')
1190 && (c != 'u') && (c != 'U')
1191 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1196 error ("floating constant may not be in radix 16");
1197 if (floatflag == AFTER_POINT)
1199 error ("malformed floating constant");
1200 floatflag = TOO_MANY_POINTS;
1203 floatflag = AFTER_POINT;
1206 *p++ = c = getc (finput);
1207 /* Accept '.' as the start of a floating-point number
1208 only when it is followed by a digit.
1209 Otherwise, unread the following non-digit
1210 and use the '.' as a structural token. */
1211 if (p == token_buffer + 2 && !isdigit (c))
1222 error ("parse error at `..'");
1225 token_buffer[1] = 0;
1232 /* It is not a decimal point.
1233 It should be a digit (perhaps a hex digit). */
1239 else if (base <= 10)
1241 if ((c&~040) == 'E')
1244 floatflag = AFTER_POINT;
1245 break; /* start of exponent */
1247 error ("nondigits in number and not hexadecimal");
1258 if (c >= largest_digit)
1262 for (count = 0; count < 8; count++)
1264 shorts[count] *= base;
1267 shorts[count] += (shorts[count-1] >> 8);
1268 shorts[count-1] &= (1<<8)-1;
1270 else shorts[0] += c;
1273 if (shorts[7] >= 1<<8
1274 || shorts[7] < - (1 << 8))
1277 if (p >= token_buffer + maxtoken - 3)
1278 p = extend_token_buffer (p);
1279 *p++ = (c = getc (finput));
1284 error ("numeric constant with no digits");
1286 if (largest_digit >= base)
1287 error ("numeric constant contains digits beyond the radix");
1289 /* Remove terminating char from the token buffer and delimit the string */
1292 if (floatflag != NOT_FLOAT)
1294 tree type = double_type_node;
1297 REAL_VALUE_TYPE value;
1300 /* Read explicit exponent if any, and put it in tokenbuf. */
1302 if ((c == 'e') || (c == 'E'))
1304 if (p >= token_buffer + maxtoken - 3)
1305 p = extend_token_buffer (p);
1308 if ((c == '+') || (c == '-'))
1314 error ("floating constant exponent has no digits");
1317 if (p >= token_buffer + maxtoken - 3)
1318 p = extend_token_buffer (p);
1327 /* Convert string to a double, checking for overflow. */
1328 if (setjmp (handler))
1330 error ("floating constant out of range");
1335 set_float_handler (handler);
1336 value = REAL_VALUE_ATOF (token_buffer);
1337 set_float_handler (0);
1340 if (errno == ERANGE && !flag_traditional && pedantic)
1342 char *p1 = token_buffer;
1343 /* Check for "0.0" and variants;
1344 SunOS 4 spuriously returns ERANGE for them. */
1345 while (*p1 == '0') p1++;
1349 while (*p1 == '0') p1++;
1351 if (*p1 == 'e' || *p1 == 'E')
1353 /* with significand==0, ignore the exponent */
1355 while (*p1 != 0) p1++;
1357 /* ERANGE is also reported for underflow,
1358 so test the value to distinguish overflow from that. */
1359 if (*p1 != 0 && (value > 1.0 || value < -1.0))
1360 pedwarn ("floating point number exceeds range of `double'");
1364 /* Read the suffixes to choose a data type. */
1367 if (c == 'f' || c == 'F')
1370 error ("two `f's in floating constant");
1374 type = float_type_node;
1375 value = real_value_truncate (TYPE_MODE (type), value);
1376 if (REAL_VALUE_ISINF (value) && pedantic)
1377 pedwarn ("floating point number exceeds range of `float'");
1380 else if (c == 'l' || c == 'L')
1383 error ("two `l's in floating constant");
1385 type = long_double_type_node;
1391 error ("garbage at end of number");
1394 if (p >= token_buffer + maxtoken - 3)
1395 p = extend_token_buffer (p);
1402 if (p >= token_buffer + maxtoken - 3)
1403 p = extend_token_buffer (p);
1408 /* Create a node with determined type and value. */
1409 yylval.ttype = build_real (type, value);
1416 tree traditional_type, ansi_type, type;
1417 int spec_unsigned = 0;
1419 int spec_long_long = 0;
1424 if (c == 'u' || c == 'U')
1427 error ("two `u's in integer constant");
1430 else if (c == 'l' || c == 'L')
1435 error ("three `l's in integer constant");
1437 pedwarn ("ANSI C forbids long long integer constants");
1446 error ("garbage at end of number");
1449 if (p >= token_buffer + maxtoken - 3)
1450 p = extend_token_buffer (p);
1457 if (p >= token_buffer + maxtoken - 3)
1458 p = extend_token_buffer (p);
1465 /* If the constant is not long long and it won't fit in an
1466 unsigned long, or if the constant is long long and won't fit
1467 in an unsigned long long, then warn that the constant is out
1470 /* ??? This assumes that long long and long integer types are
1471 a multiple of 8 bits. This better than the original code
1472 though which assumed that long was exactly 32 bits and long
1473 long was exactly 64 bits. */
1476 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1478 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1483 for (i = bytes; i < 8; i++)
1486 /* If LL was not used, then clear any excess precision.
1487 This is equivalent to the original code, but it is
1488 not clear why this is being done. Perhaps to prevent
1489 ANSI programs from creating long long constants
1491 if (! spec_long_long)
1496 pedwarn ("integer constant out of range");
1499 pedwarn ("integer constant larger than compiler can handle");
1501 /* If it overflowed our internal buffer, then make it unsigned.
1502 We can't distinguish based on the tree node because
1503 any integer constant fits any long long type. */
1507 /* This is simplified by the fact that our constant
1508 is always positive. */
1509 /* The casts in the following statement should not be
1510 needed, but they get around bugs in some C compilers. */
1513 ((((long)shorts[3]<<24) + ((long)shorts[2]<<16)
1514 + ((long)shorts[1]<<8) + (long)shorts[0]),
1515 (((long)shorts[7]<<24) + ((long)shorts[6]<<16)
1516 + ((long)shorts[5]<<8) + (long)shorts[4])));
1519 /* Find the first allowable type that the value fits in. */
1521 for (i = 0; i < sizeof (type_sequence) / sizeof (type_sequence[0]);
1523 if (!(spec_long && !type_sequence[i].long_flag)
1524 && !(spec_long_long && !type_sequence[i].long_long_flag)
1525 && !(spec_unsigned && !type_sequence[i].unsigned_flag)
1526 /* A decimal constant can't be unsigned int
1527 unless explicitly specified. */
1528 && !(base == 10 && !spec_unsigned
1529 && *type_sequence[i].node_var == unsigned_type_node))
1530 if (int_fits_type_p (yylval.ttype, *type_sequence[i].node_var))
1532 type = *type_sequence[i].node_var;
1535 if (flag_traditional && type == long_unsigned_type_node
1537 type = long_integer_type_node;
1541 type = long_long_integer_type_node;
1542 warning ("integer constant out of range");
1545 /* Warn about some cases where the type of a given constant
1546 changes from traditional C to ANSI C. */
1547 if (warn_traditional)
1549 tree other_type = 0;
1551 /* This computation is the same as the previous one
1552 except that flag_traditional is used backwards. */
1553 for (i = 0; i < sizeof (type_sequence) / sizeof (type_sequence[0]);
1555 if (!(spec_long && !type_sequence[i].long_flag)
1556 && !(spec_long_long && !type_sequence[i].long_long_flag)
1557 && !(spec_unsigned && !type_sequence[i].unsigned_flag)
1558 /* A decimal constant can't be unsigned int
1559 unless explicitly specified. */
1560 && !(base == 10 && !spec_unsigned
1561 && *type_sequence[i].node_var == unsigned_type_node))
1562 if (int_fits_type_p (yylval.ttype, *type_sequence[i].node_var))
1564 other_type = *type_sequence[i].node_var;
1567 if (!flag_traditional && type == long_unsigned_type_node
1569 type = long_integer_type_node;
1571 if (other_type != 0 && other_type != type)
1573 if (flag_traditional)
1574 warning ("type of integer constant would be different without -traditional");
1576 warning ("type of integer constant would be different with -traditional");
1581 /* If warn_traditional, calculate both the ANSI type and the
1582 traditional type, then see if they disagree.
1583 Otherwise, calculate only the type for the dialect in use. */
1584 if (warn_traditional || flag_traditional)
1586 /* Calculate the traditional type. */
1587 /* Traditionally, any constant is signed;
1588 but if unsigned is specified explicitly, obey that.
1589 Use the smallest size with the right number of bits,
1590 except for one special case with decimal constants. */
1591 if (! spec_long && base != 10
1592 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1593 traditional_type = (spec_unsigned ? unsigned_type_node
1594 : integer_type_node);
1595 /* A decimal constant must be long
1596 if it does not fit in type int.
1597 I think this is independent of whether
1598 the constant is signed. */
1599 else if (! spec_long && base == 10
1600 && int_fits_type_p (yylval.ttype, integer_type_node))
1601 traditional_type = (spec_unsigned ? unsigned_type_node
1602 : integer_type_node);
1603 else if (! spec_long_long
1604 && int_fits_type_p (yylval.ttype,
1605 long_unsigned_type_node))
1606 traditional_type = (spec_unsigned ? long_unsigned_type_node
1607 : long_integer_type_node);
1609 traditional_type = (spec_unsigned
1610 ? long_long_unsigned_type_node
1611 : long_long_integer_type_node);
1613 if (warn_traditional || ! flag_traditional)
1615 /* Calculate the ANSI type. */
1616 if (! spec_long && ! spec_unsigned
1617 && int_fits_type_p (yylval.ttype, integer_type_node))
1618 ansi_type = integer_type_node;
1619 else if (! spec_long && (base != 10 || spec_unsigned)
1620 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1621 ansi_type = unsigned_type_node;
1622 else if (! spec_unsigned && !spec_long_long
1623 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1624 ansi_type = long_integer_type_node;
1625 else if (! spec_long_long
1626 && int_fits_type_p (yylval.ttype,
1627 long_unsigned_type_node))
1628 ansi_type = long_unsigned_type_node;
1629 else if (! spec_unsigned
1630 && int_fits_type_p (yylval.ttype,
1631 long_long_integer_type_node))
1632 ansi_type = long_long_integer_type_node;
1634 ansi_type = long_long_unsigned_type_node;
1637 type = flag_traditional ? traditional_type : ansi_type;
1639 if (warn_traditional && traditional_type != ansi_type)
1641 if (TYPE_PRECISION (traditional_type)
1642 != TYPE_PRECISION (ansi_type))
1643 warning ("width of integer constant changes with -traditional");
1644 else if (TREE_UNSIGNED (traditional_type)
1645 != TREE_UNSIGNED (ansi_type))
1646 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1648 warning ("width of integer constant may change on other systems with -traditional");
1652 if (!flag_traditional && !int_fits_type_p (yylval.ttype, type))
1653 pedwarn ("integer constant out of range");
1655 TREE_TYPE (yylval.ttype) = type;
1659 value = CONSTANT; break;
1665 register int result = 0;
1666 register num_chars = 0;
1667 unsigned width = TYPE_PRECISION (char_type_node);
1672 width = WCHAR_TYPE_SIZE;
1673 #ifdef MULTIBYTE_CHARS
1674 max_chars = MB_CUR_MAX;
1680 max_chars = TYPE_PRECISION (integer_type_node) / width;
1688 if (c == '\'' || c == EOF)
1696 if (width < HOST_BITS_PER_INT
1697 && (unsigned) c >= (1 << width))
1698 pedwarn ("escape sequence out of range for character");
1703 pedwarn ("ANSI C forbids newline in character constant");
1708 if (num_chars > maxtoken - 4)
1709 extend_token_buffer (token_buffer);
1711 token_buffer[num_chars] = c;
1713 /* Merge character into result; ignore excess chars. */
1714 if (num_chars < max_chars + 1)
1716 if (width < HOST_BITS_PER_INT)
1717 result = (result << width) | (c & ((1 << width) - 1));
1723 token_buffer[num_chars + 1] = '\'';
1724 token_buffer[num_chars + 2] = 0;
1727 error ("malformatted character constant");
1728 else if (num_chars == 0)
1729 error ("empty character constant");
1730 else if (num_chars > max_chars)
1732 num_chars = max_chars;
1733 error ("character constant too long");
1735 else if (num_chars != 1 && ! flag_traditional)
1736 warning ("multi-character character constant");
1738 /* If char type is signed, sign-extend the constant. */
1741 int num_bits = num_chars * width;
1742 if (TREE_UNSIGNED (char_type_node)
1743 || ((result >> (num_bits - 1)) & 1) == 0)
1745 = build_int_2 (result & ((unsigned) ~0
1746 >> (HOST_BITS_PER_INT - num_bits)),
1750 = build_int_2 (result | ~((unsigned) ~0
1751 >> (HOST_BITS_PER_INT - num_bits)),
1756 #ifdef MULTIBYTE_CHARS
1757 /* Set the initial shift state and convert the next sequence. */
1759 /* In all locales L'\0' is zero and mbtowc will return zero,
1762 || (num_chars == 1 && token_buffer[1] != '\0'))
1765 (void) mbtowc (NULL, NULL, 0);
1766 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1769 warning ("Ignoring invalid multibyte character");
1772 yylval.ttype = build_int_2 (result, 0);
1775 TREE_TYPE (yylval.ttype) = integer_type_node;
1784 p = token_buffer + 1;
1786 while (c != '"' && c >= 0)
1788 /* ignore_escape_flag is set for reading the filename in #line. */
1789 if (!ignore_escape_flag && c == '\\')
1795 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1796 && c >= (1 << TYPE_PRECISION (char_type_node)))
1797 pedwarn ("escape sequence out of range for character");
1802 pedwarn ("ANSI C forbids newline in string constant");
1806 if (p == token_buffer + maxtoken)
1807 p = extend_token_buffer (p);
1815 /* We have read the entire constant.
1816 Construct a STRING_CST for the result. */
1820 /* If this is a L"..." wide-string, convert the multibyte string
1821 to a wide character string. */
1822 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1825 #ifdef MULTIBYTE_CHARS
1826 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1827 if ((unsigned) len >= (p - token_buffer))
1829 warning ("Ignoring invalid multibyte string");
1832 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1835 union { long l; char c[sizeof (long)]; } u;
1839 /* Determine whether host is little or big endian. */
1841 big_endian = u.c[sizeof (long) - 1];
1842 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1844 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1845 for (cp = token_buffer + 1; cp < p; cp++)
1846 *wp = *cp, wp += WCHAR_BYTES;
1847 len = p - token_buffer - 1;
1850 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1851 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1855 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
1856 TREE_TYPE (yylval.ttype) = char_array_type_node;
1862 value = STRING; break;
1885 yylval.code = PLUS_EXPR; break;
1887 yylval.code = MINUS_EXPR; break;
1889 yylval.code = BIT_AND_EXPR; break;
1891 yylval.code = BIT_IOR_EXPR; break;
1893 yylval.code = MULT_EXPR; break;
1895 yylval.code = TRUNC_DIV_EXPR; break;
1897 yylval.code = TRUNC_MOD_EXPR; break;
1899 yylval.code = BIT_XOR_EXPR; break;
1901 yylval.code = LSHIFT_EXPR; break;
1903 yylval.code = RSHIFT_EXPR; break;
1905 yylval.code = LT_EXPR; break;
1907 yylval.code = GT_EXPR; break;
1910 token_buffer[1] = c1 = getc (finput);
1911 token_buffer[2] = 0;
1918 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
1920 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
1922 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
1924 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
1926 value = ASSIGN; goto done;
1932 value = PLUSPLUS; goto done;
1934 value = MINUSMINUS; goto done;
1936 value = ANDAND; goto done;
1938 value = OROR; goto done;
1946 else if ((c == '-') && (c1 == '>'))
1947 { value = POINTSAT; goto done; }
1948 ungetc (c1, finput);
1949 token_buffer[1] = 0;
1951 if ((c == '<') || (c == '>'))
1952 value = ARITHCOMPARE;
1958 /* Don't make yyparse think this is eof. */
1967 /* yylloc.last_line = lineno; */
1972 /* Sets the value of the 'yydebug' variable to VALUE.
1973 This is a function so we don't have to have YYDEBUG defined
1974 in order to build the compiler. */
1983 warning ("YYDEBUG not defined.");