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 61
100 #define MIN_WORD_LENGTH 2
101 #define MAX_WORD_LENGTH 13
102 #define MIN_HASH_VALUE 10
103 #define MAX_HASH_VALUE 95
104 /* maximum key range = 86, duplicates = 0 */
112 register int unsigned len;
114 static unsigned char asso_values[] =
116 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
117 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
118 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
119 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
120 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
121 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
122 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
123 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
124 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
125 96, 96, 96, 96, 96, 1, 96, 15, 13, 23,
126 1, 6, 32, 36, 3, 5, 96, 1, 20, 29,
127 31, 44, 19, 96, 13, 2, 1, 54, 39, 11,
128 5, 96, 3, 96, 96, 96, 96, 96,
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 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
156 {"int", TYPESPEC, RID_INT},
158 {"__signed", TYPESPEC, RID_SIGNED},
159 {"__typeof__", TYPEOF, NORID},
160 {"__signed__", TYPESPEC, RID_SIGNED},
161 {"__imag__", IMAGPART, NORID},
162 {"switch", SWITCH, NORID},
163 {"__inline__", SCSPEC, RID_INLINE},
164 {"else", ELSE, NORID},
165 {"__iterator__", SCSPEC, RID_ITERATOR},
166 {"__inline", SCSPEC, RID_INLINE},
167 {"__extension__", EXTENSION, NORID},
168 {"struct", STRUCT, NORID},
169 {"__real__", REALPART, NORID},
170 {"__asm__", ASM_KEYWORD, NORID},
171 {"break", BREAK, NORID},
173 {"while", WHILE, NORID},
174 {"__alignof__", ALIGNOF, NORID},
175 {"__iterator", SCSPEC, RID_ITERATOR},
176 {"__attribute__", ATTRIBUTE, NORID},
177 {"__label__", LABEL, NORID},
178 {"__const", TYPE_QUAL, RID_CONST},
179 {"__attribute", ATTRIBUTE, NORID},
180 {"__const__", TYPE_QUAL, RID_CONST},
181 {"case", CASE, NORID},
182 {"__complex__", TYPESPEC, RID_COMPLEX},
183 {"inline", SCSPEC, RID_INLINE},
184 {"__complex", TYPESPEC, RID_COMPLEX},
186 {"__real", REALPART, NORID},
187 {"default", DEFAULT, NORID},
188 {"__typeof", TYPEOF, NORID},
189 {"sizeof", SIZEOF, NORID},
190 {"extern", SCSPEC, RID_EXTERN},
191 {"signed", TYPESPEC, RID_SIGNED},
192 {"static", SCSPEC, RID_STATIC},
194 {"__imag", IMAGPART, NORID},
195 {"void", TYPESPEC, RID_VOID},
196 {"__asm", ASM_KEYWORD, NORID},
197 {"return", RETURN, NORID},
198 {"short", TYPESPEC, RID_SHORT},
199 {"__volatile__", TYPE_QUAL, RID_VOLATILE},
201 {"char", TYPESPEC, RID_CHAR},
202 {"__volatile", TYPE_QUAL, RID_VOLATILE},
203 {"__alignof", ALIGNOF, NORID},
204 {"typeof", TYPEOF, NORID},
205 {"typedef", SCSPEC, RID_TYPEDEF},
206 {"const", TYPE_QUAL, RID_CONST},
209 {"auto", SCSPEC, RID_AUTO},
210 {"unsigned", TYPESPEC, RID_UNSIGNED},
212 {"double", TYPESPEC, RID_DOUBLE},
213 {"continue", CONTINUE, NORID},
215 {"register", SCSPEC, RID_REGISTER},
217 {"volatile", TYPE_QUAL, RID_VOLATILE},
219 {"asm", ASM_KEYWORD, NORID},
220 {"",}, {"",}, {"",}, {"",}, {"",},
221 {"float", TYPESPEC, RID_FLOAT},
223 {"goto", GOTO, NORID},
224 {"",}, {"",}, {"",}, {"",}, {"",},
225 {"long", TYPESPEC, RID_LONG},
227 {"enum", ENUM, NORID},
229 {"union", UNION, NORID},
232 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
234 register int key = hash (str, len);
236 if (key <= MAX_HASH_VALUE && key >= 0)
238 register char *s = wordlist[key].name;
240 if (*s == *str && !strcmp (str + 1, s + 1))
241 return &wordlist[key];
247 /* Return something to represent absolute declarators containing a *.
248 TARGET is the absolute declarator that the * contains.
249 TYPE_QUALS is a list of modifiers such as const or volatile
250 to apply to the pointer type, represented as identifiers.
252 We return an INDIRECT_REF whose "contents" are TARGET
253 and whose type is the modifier list. */
256 make_pointer_declarator (type_quals, target)
257 tree type_quals, target;
259 return build1 (INDIRECT_REF, type_quals, target);
265 /* Make identifier nodes long enough for the language-specific slots. */
266 set_identifier_size (sizeof (struct lang_identifier));
268 /* Start it at 0, because check_newline is called at the very beginning
269 and will increment it to 1. */
272 #ifdef MULTIBYTE_CHARS
273 /* Change to the native locale for multibyte conversions. */
274 setlocale (LC_CTYPE, "");
278 token_buffer = (char *) xmalloc (maxtoken + 2);
280 ridpointers[(int) RID_INT] = get_identifier ("int");
281 ridpointers[(int) RID_CHAR] = get_identifier ("char");
282 ridpointers[(int) RID_VOID] = get_identifier ("void");
283 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
284 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
285 ridpointers[(int) RID_SHORT] = get_identifier ("short");
286 ridpointers[(int) RID_LONG] = get_identifier ("long");
287 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
288 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
289 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
290 ridpointers[(int) RID_CONST] = get_identifier ("const");
291 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
292 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
293 ridpointers[(int) RID_STATIC] = get_identifier ("static");
294 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
295 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
296 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
297 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
298 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
300 /* Some options inhibit certain reserved words.
301 Clear those words out of the hash table so they won't be recognized. */
302 #define UNSET_RESERVED_WORD(STRING) \
303 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
304 if (s) s->name = ""; } while (0)
306 if (flag_traditional)
308 UNSET_RESERVED_WORD ("const");
309 UNSET_RESERVED_WORD ("volatile");
310 UNSET_RESERVED_WORD ("typeof");
311 UNSET_RESERVED_WORD ("signed");
312 UNSET_RESERVED_WORD ("inline");
313 UNSET_RESERVED_WORD ("iterator");
314 UNSET_RESERVED_WORD ("complex");
318 UNSET_RESERVED_WORD ("asm");
319 UNSET_RESERVED_WORD ("typeof");
320 UNSET_RESERVED_WORD ("inline");
321 UNSET_RESERVED_WORD ("iterator");
322 UNSET_RESERVED_WORD ("complex");
327 reinit_parse_for_function ()
331 /* Function used when yydebug is set, to print a token in more detail. */
334 yyprint (file, yychar, yylval)
345 if (IDENTIFIER_POINTER (t))
346 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
351 if (TREE_CODE (t) == INTEGER_CST)
353 #if HOST_BITS_PER_WIDE_INT == 64
354 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
360 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
366 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
372 /* If C is not whitespace, return C.
373 Otherwise skip whitespace and return first nonwhite char read. */
379 static int newline_warning = 0;
385 /* We don't recognize comments here, because
386 cpp output can include / and * consecutively as operators.
387 Also, there's no need, since cpp removes all comments. */
390 c = check_newline ();
402 /* ANSI C says the effects of a carriage return in a source file
404 if (pedantic && !newline_warning)
406 warning ("carriage return in source file");
407 warning ("(we only warn about the first carriage return)");
418 error ("stray '\\' in program");
428 /* Skips all of the white space at the current location in the input file.
429 Must use and reset nextchar if it has the next character. */
432 position_after_white_space ()
437 c = nextchar, nextchar = -1;
441 ungetc (skip_white_space (c), finput);
444 /* Make the token buffer longer, preserving the data in it.
445 P should point to just beyond the last valid character in the old buffer.
446 The value we return is a pointer to the new buffer
447 at a place corresponding to P. */
450 extend_token_buffer (p)
453 int offset = p - token_buffer;
455 maxtoken = maxtoken * 2 + 10;
456 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
458 return token_buffer + offset;
461 /* At the beginning of a line, increment the line number
462 and process any #-directive on this line.
463 If the line is a #-directive, read the entire line and return a newline.
464 Otherwise, return the line's first non-whitespace character. */
474 /* Read first nonwhite char on the line. */
477 while (c == ' ' || c == '\t')
482 /* If not #, return it so caller will use it. */
486 /* Read first nonwhite char after the `#'. */
489 while (c == ' ' || c == '\t')
492 /* If a letter follows, then if the word here is `line', skip
493 it and ignore it; otherwise, ignore the line, with an error
494 if the word isn't `pragma', `ident', `define', or `undef'. */
496 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
500 if (getc (finput) == 'r'
501 && getc (finput) == 'a'
502 && getc (finput) == 'g'
503 && getc (finput) == 'm'
504 && getc (finput) == 'a'
505 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
507 #ifdef HANDLE_SYSV_PRAGMA
508 return handle_sysv_pragma (finput, c);
509 #endif /* HANDLE_SYSV_PRAGMA */
511 HANDLE_PRAGMA (finput);
512 #endif /* HANDLE_PRAGMA */
519 if (getc (finput) == 'e'
520 && getc (finput) == 'f'
521 && getc (finput) == 'i'
522 && getc (finput) == 'n'
523 && getc (finput) == 'e'
524 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
526 #ifdef DWARF_DEBUGGING_INFO
527 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
528 && (write_symbols == DWARF_DEBUG))
529 dwarfout_define (lineno, get_directive_line (finput));
530 #endif /* DWARF_DEBUGGING_INFO */
536 if (getc (finput) == 'n'
537 && getc (finput) == 'd'
538 && getc (finput) == 'e'
539 && getc (finput) == 'f'
540 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
542 #ifdef DWARF_DEBUGGING_INFO
543 if ((debug_info_level == DINFO_LEVEL_VERBOSE)
544 && (write_symbols == DWARF_DEBUG))
545 dwarfout_undef (lineno, get_directive_line (finput));
546 #endif /* DWARF_DEBUGGING_INFO */
552 if (getc (finput) == 'i'
553 && getc (finput) == 'n'
554 && getc (finput) == 'e'
555 && ((c = getc (finput)) == ' ' || c == '\t'))
560 if (getc (finput) == 'd'
561 && getc (finput) == 'e'
562 && getc (finput) == 'n'
563 && getc (finput) == 't'
564 && ((c = getc (finput)) == ' ' || c == '\t'))
566 /* #ident. The pedantic warning is now in cccp.c. */
568 /* Here we have just seen `#ident '.
569 A string constant should follow. */
571 while (c == ' ' || c == '\t')
574 /* If no argument, ignore the line. */
581 || TREE_CODE (yylval.ttype) != STRING_CST)
583 error ("invalid #ident");
589 #ifdef ASM_OUTPUT_IDENT
590 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
594 /* Skip the rest of this line. */
599 error ("undefined or invalid # directive");
604 /* Here we have either `#line' or `# <nonletter>'.
605 In either case, it should be a line number; a digit should follow. */
607 while (c == ' ' || c == '\t')
610 /* If the # is the only nonwhite char on the line,
611 just ignore it. Check the new newline. */
615 /* Something follows the #; read a token. */
620 if (token == CONSTANT
621 && TREE_CODE (yylval.ttype) == INTEGER_CST)
623 int old_lineno = lineno;
625 /* subtract one, because it is the following line that
626 gets the specified number */
628 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
630 /* Is this the last nonwhite stuff on the line? */
632 while (c == ' ' || c == '\t')
636 /* No more: store the line number and check following line. */
642 /* More follows: it must be a string constant (filename). */
644 /* Read the string constant, but don't treat \ as special. */
645 ignore_escape_flag = 1;
647 ignore_escape_flag = 0;
649 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
651 error ("invalid #line");
656 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
657 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
660 /* Each change of file name
661 reinitializes whether we are now in a system header. */
662 in_system_header = 0;
664 if (main_input_filename == 0)
665 main_input_filename = input_filename;
667 /* Is this the last nonwhite stuff on the line? */
669 while (c == ' ' || c == '\t')
673 /* Update the name in the top element of input_file_stack. */
674 if (input_file_stack)
675 input_file_stack->name = input_filename;
684 /* `1' after file name means entering new file.
685 `2' after file name means just left a file. */
687 if (token == CONSTANT
688 && TREE_CODE (yylval.ttype) == INTEGER_CST)
690 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
692 /* Pushing to a new file. */
694 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
695 input_file_stack->line = old_lineno;
696 p->next = input_file_stack;
697 p->name = input_filename;
698 input_file_stack = p;
699 input_file_stack_tick++;
700 #ifdef DWARF_DEBUGGING_INFO
701 if (debug_info_level == DINFO_LEVEL_VERBOSE
702 && write_symbols == DWARF_DEBUG)
703 dwarfout_start_new_source_file (input_filename);
704 #endif /* DWARF_DEBUGGING_INFO */
708 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
710 /* Popping out of a file. */
711 if (input_file_stack->next)
713 struct file_stack *p = input_file_stack;
714 input_file_stack = p->next;
716 input_file_stack_tick++;
717 #ifdef DWARF_DEBUGGING_INFO
718 if (debug_info_level == DINFO_LEVEL_VERBOSE
719 && write_symbols == DWARF_DEBUG)
720 dwarfout_resume_previous_source_file (input_file_stack->line);
721 #endif /* DWARF_DEBUGGING_INFO */
724 error ("#-lines for entering and leaving files don't match");
730 /* Now that we've pushed or popped the input stack,
731 update the name in the top element. */
732 if (input_file_stack)
733 input_file_stack->name = input_filename;
735 /* If we have handled a `1' or a `2',
736 see if there is another number to read. */
739 /* Is this the last nonwhite stuff on the line? */
741 while (c == ' ' || c == '\t')
751 /* `3' after file name means this is a system header file. */
753 if (token == CONSTANT
754 && TREE_CODE (yylval.ttype) == INTEGER_CST
755 && TREE_INT_CST_LOW (yylval.ttype) == 3)
756 in_system_header = 1;
759 error ("invalid #-line");
761 /* skip the rest of this line. */
765 while ((c = getc (finput)) != EOF && c != '\n');
769 #ifdef HANDLE_SYSV_PRAGMA
771 /* Handle a #pragma directive. INPUT is the current input stream,
772 and C is a character to reread. Processes the entire input line
773 and returns a character for the caller to reread: either \n or EOF. */
775 /* This function has to be in this file, in order to get at
779 handle_sysv_pragma (input, c)
785 while (c == ' ' || c == '\t')
787 if (c == '\n' || c == EOF)
789 handle_pragma_token (0, 0);
799 handle_pragma_token (token_buffer, yylval.ttype);
802 handle_pragma_token (token_buffer, 0);
805 c = nextchar, nextchar = -1;
811 #endif /* HANDLE_SYSV_PRAGMA */
813 #define isalnum(char) ((char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'))
814 #define isdigit(char) (char >= '0' && char <= '9')
815 #define ENDFILE -1 /* token that represents end-of-file */
817 /* Read an escape sequence, returning its equivalent as a character,
818 or store 1 in *ignore_ptr if it is backslash-newline. */
821 readescape (ignore_ptr)
824 register int c = getc (finput);
826 register unsigned count;
833 if (warn_traditional)
834 warning ("the meaning of `\\x' varies with -traditional");
836 if (flag_traditional)
845 if (!(c >= 'a' && c <= 'f')
846 && !(c >= 'A' && c <= 'F')
847 && !(c >= '0' && c <= '9'))
853 if (c >= 'a' && c <= 'f')
854 code += c - 'a' + 10;
855 if (c >= 'A' && c <= 'F')
856 code += c - 'A' + 10;
857 if (c >= '0' && c <= '9')
859 if (code != 0 || count != 0)
868 error ("\\x used with no following hex digits");
870 /* Digits are all 0's. Ok. */
872 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
874 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
876 pedwarn ("hex escape out of range");
879 case '0': case '1': case '2': case '3': case '4':
880 case '5': case '6': case '7':
883 while ((c <= '7') && (c >= '0') && (count++ < 3))
885 code = (code * 8) + (c - '0');
891 case '\\': case '\'': case '"':
900 return TARGET_NEWLINE;
915 if (warn_traditional)
916 warning ("the meaning of `\\a' varies with -traditional");
918 if (flag_traditional)
923 #if 0 /* Vertical tab is present in common usage compilers. */
924 if (flag_traditional)
932 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
938 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
943 pedwarn ("non-ANSI escape sequence `\\%c'", c);
946 if (c >= 040 && c < 0177)
947 pedwarn ("unknown escape sequence `\\%c'", c);
949 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
959 strcpy (buf, string);
961 /* We can't print string and character constants well
962 because the token_buffer contains the result of processing escapes. */
964 strcat (buf, " at end of input");
965 else if (token_buffer[0] == 0)
966 strcat (buf, " at null character");
967 else if (token_buffer[0] == '"')
968 strcat (buf, " before string constant");
969 else if (token_buffer[0] == '\'')
970 strcat (buf, " before character constant");
971 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
972 sprintf (buf + strlen (buf), " before character 0%o",
973 (unsigned char) token_buffer[0]);
975 strcat (buf, " before `%s'");
977 error (buf, token_buffer);
990 struct try_type type_sequence[] =
992 { &integer_type_node, 0, 0, 0},
993 { &unsigned_type_node, 1, 0, 0},
994 { &long_integer_type_node, 0, 1, 0},
995 { &long_unsigned_type_node, 1, 1, 0},
996 { &long_long_integer_type_node, 0, 1, 1},
997 { &long_long_unsigned_type_node, 1, 1, 1}
1010 c = nextchar, nextchar = -1;
1014 /* Effectively do c = skip_white_space (c)
1015 but do it faster in the usual cases. */
1028 /* Call skip_white_space so we can warn if appropriate. */
1033 c = skip_white_space (c);
1035 goto found_nonwhite;
1039 token_buffer[0] = c;
1040 token_buffer[1] = 0;
1042 /* yylloc.first_line = lineno; */
1048 token_buffer[0] = 0;
1053 if (dollars_in_ident)
1058 /* Capital L may start a wide-string or wide-character constant. */
1060 register int c = getc (finput);
1069 goto string_constant;
1076 if (!doing_objc_thang)
1084 while (isalnum (c) || c == '_')
1086 if (p >= token_buffer + maxtoken)
1087 p = extend_token_buffer (p);
1095 value = recognize_objc_keyword (token_buffer + 1);
1098 error ("invalid Objective C keyword `%s'", token_buffer);
1099 /* Cause a syntax error--1 is not a valid token type. */
1103 case 'A': case 'B': case 'C': case 'D': case 'E':
1104 case 'F': case 'G': case 'H': case 'I': case 'J':
1105 case 'K': case 'M': case 'N': case 'O':
1106 case 'P': case 'Q': case 'R': case 'S': case 'T':
1107 case 'U': case 'V': case 'W': case 'X': case 'Y':
1109 case 'a': case 'b': case 'c': case 'd': case 'e':
1110 case 'f': case 'g': case 'h': case 'i': case 'j':
1111 case 'k': case 'l': case 'm': case 'n': case 'o':
1112 case 'p': case 'q': case 'r': case 's': case 't':
1113 case 'u': case 'v': case 'w': case 'x': case 'y':
1118 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1120 /* Make sure this char really belongs in an identifier. */
1121 if (c == '@' && ! doing_objc_thang)
1123 if (c == '$' && ! dollars_in_ident)
1126 if (p >= token_buffer + maxtoken)
1127 p = extend_token_buffer (p);
1139 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1142 register struct resword *ptr;
1144 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1147 yylval.ttype = ridpointers[(int) ptr->rid];
1148 value = (int) ptr->token;
1150 /* Even if we decided to recognize asm, still perhaps warn. */
1152 && (value == ASM_KEYWORD || value == TYPEOF
1153 || ptr->rid == RID_INLINE)
1154 && token_buffer[0] != '_')
1155 pedwarn ("ANSI does not permit the keyword `%s'",
1160 /* If we did not find a keyword, look for an identifier
1163 if (value == IDENTIFIER)
1165 yylval.ttype = get_identifier (token_buffer);
1166 lastiddecl = lookup_name (yylval.ttype);
1168 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1170 /* A user-invisible read-only initialized variable
1171 should be replaced by its value.
1172 We handle only strings since that's the only case used in C. */
1173 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1174 && DECL_IGNORED_P (lastiddecl)
1175 && TREE_READONLY (lastiddecl)
1176 && DECL_INITIAL (lastiddecl) != 0
1177 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1179 tree stringval = DECL_INITIAL (lastiddecl);
1181 /* Copy the string value so that we won't clobber anything
1182 if we put something in the TREE_CHAIN of this one. */
1183 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1184 TREE_STRING_POINTER (stringval));
1187 else if (doing_objc_thang)
1189 tree objc_interface_decl = lookup_interface (yylval.ttype);
1191 if (objc_interface_decl)
1194 yylval.ttype = objc_interface_decl;
1201 case '0': case '1': case '2': case '3': case '4':
1202 case '5': case '6': case '7': case '8': case '9':
1207 int largest_digit = 0;
1209 /* for multi-precision arithmetic,
1210 we actually store only HOST_BITS_PER_CHAR bits in each part.
1211 The number of parts is chosen so as to be sufficient to hold
1212 the enough bits to fit into the two HOST_WIDE_INTs that contain
1213 the integer value (this is always at least as many bits as are
1214 in a target `long long' value, but may be wider). */
1215 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1216 int parts[TOTAL_PARTS];
1219 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1222 for (count = 0; count < TOTAL_PARTS; count++)
1230 *p++ = (c = getc (finput));
1231 if ((c == 'x') || (c == 'X'))
1234 *p++ = (c = getc (finput));
1236 /* Leading 0 forces octal unless the 0 is the only digit. */
1237 else if (c >= '0' && c <= '9')
1246 /* Read all the digits-and-decimal-points. */
1249 || (isalnum (c) && c != 'l' && c != 'L'
1250 && c != 'u' && c != 'U'
1251 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1252 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1257 error ("floating constant may not be in radix 16");
1258 if (floatflag == AFTER_POINT)
1260 error ("malformed floating constant");
1261 floatflag = TOO_MANY_POINTS;
1264 floatflag = AFTER_POINT;
1267 *p++ = c = getc (finput);
1268 /* Accept '.' as the start of a floating-point number
1269 only when it is followed by a digit.
1270 Otherwise, unread the following non-digit
1271 and use the '.' as a structural token. */
1272 if (p == token_buffer + 2 && !isdigit (c))
1283 error ("parse error at `..'");
1286 token_buffer[1] = 0;
1293 /* It is not a decimal point.
1294 It should be a digit (perhaps a hex digit). */
1300 else if (base <= 10)
1302 if (c == 'e' || c == 'E')
1305 floatflag = AFTER_POINT;
1306 break; /* start of exponent */
1308 error ("nondigits in number and not hexadecimal");
1319 if (c >= largest_digit)
1323 for (count = 0; count < TOTAL_PARTS; count++)
1325 parts[count] *= base;
1329 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1331 &= (1 << HOST_BITS_PER_CHAR) - 1;
1337 /* If the extra highest-order part ever gets anything in it,
1338 the number is certainly too big. */
1339 if (parts[TOTAL_PARTS - 1] != 0)
1342 if (p >= token_buffer + maxtoken - 3)
1343 p = extend_token_buffer (p);
1344 *p++ = (c = getc (finput));
1349 error ("numeric constant with no digits");
1351 if (largest_digit >= base)
1352 error ("numeric constant contains digits beyond the radix");
1354 /* Remove terminating char from the token buffer and delimit the string */
1357 if (floatflag != NOT_FLOAT)
1359 tree type = double_type_node;
1360 int garbage_chars = 0, exceeds_double = 0;
1362 REAL_VALUE_TYPE value;
1365 /* Read explicit exponent if any, and put it in tokenbuf. */
1367 if ((c == 'e') || (c == 'E'))
1369 if (p >= token_buffer + maxtoken - 3)
1370 p = extend_token_buffer (p);
1373 if ((c == '+') || (c == '-'))
1379 error ("floating constant exponent has no digits");
1382 if (p >= token_buffer + maxtoken - 3)
1383 p = extend_token_buffer (p);
1392 /* Convert string to a double, checking for overflow. */
1393 if (setjmp (handler))
1395 error ("floating constant out of range");
1400 set_float_handler (handler);
1402 /* The second argument, machine_mode, of REAL_VALUE_ATOF tells the
1403 desired precision of the binary result of decimal-to-binary conversion. */
1405 /* Read the suffixes to choose a data type. */
1409 type = float_type_node;
1410 value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type));
1411 if (REAL_VALUE_ISINF (value) && pedantic)
1412 pedwarn ("floating point number exceeds range of `float'");
1417 type = long_double_type_node;
1418 value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type));
1419 if (REAL_VALUE_ISINF (value) && pedantic)
1421 "floating point number exceeds range of `long double'");
1427 error ("more than one `i' or `j' in numeric constant");
1433 value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type));
1434 if (REAL_VALUE_ISINF (value) && pedantic)
1435 pedwarn ("floating point number exceeds range of `double'");
1437 set_float_handler (NULL_PTR);
1440 if (errno == ERANGE && !flag_traditional && pedantic)
1442 /* ERANGE is also reported for underflow,
1443 so test the value to distinguish overflow from that. */
1444 if (REAL_VALUES_LESS (dconst1, value)
1445 || REAL_VALUES_LESS (value, dconstm1))
1447 pedwarn ("floating point number exceeds range of `double'");
1452 /* Note: garbage_chars is -1 if first char is *not* garbage. */
1453 while (isalnum (c) || c == '.' || c == '_'
1454 || (!flag_traditional && (c == '+' || c == '-')
1455 && (p[-1] == 'e' || p[-1] == 'E')))
1457 if (p >= token_buffer + maxtoken - 3)
1458 p = extend_token_buffer (p);
1463 if (garbage_chars > 0)
1464 error ("garbage at end of number");
1466 /* Create a node with determined type and value. */
1468 yylval.ttype = build_complex (convert (type, integer_zero_node),
1469 build_real (type, value));
1471 yylval.ttype = build_real (type, value);
1478 tree traditional_type, ansi_type, type;
1479 HOST_WIDE_INT high, low;
1480 int spec_unsigned = 0;
1482 int spec_long_long = 0;
1488 if (c == 'u' || c == 'U')
1491 error ("two `u's in integer constant");
1494 else if (c == 'l' || c == 'L')
1499 error ("three `l's in integer constant");
1501 pedwarn ("ANSI C forbids long long integer constants");
1506 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1509 error ("more than one `i' or `j' in numeric constant");
1514 if (isalnum (c) || c == '.' || c == '_'
1515 || (!flag_traditional && (c == '+' || c == '-')
1516 && (p[-1] == 'e' || p[-1] == 'E')))
1518 error ("garbage at end of number");
1519 while (isalnum (c) || c == '.' || c == '_'
1520 || (!flag_traditional && (c == '+' || c == '-')
1521 && (p[-1] == 'e' || p[-1] == 'E')))
1523 if (p >= token_buffer + maxtoken - 3)
1524 p = extend_token_buffer (p);
1531 if (p >= token_buffer + maxtoken - 3)
1532 p = extend_token_buffer (p);
1539 /* If the constant is not long long and it won't fit in an
1540 unsigned long, or if the constant is long long and won't fit
1541 in an unsigned long long, then warn that the constant is out
1544 /* ??? This assumes that long long and long integer types are
1545 a multiple of 8 bits. This better than the original code
1546 though which assumed that long was exactly 32 bits and long
1547 long was exactly 64 bits. */
1550 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1552 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1555 for (i = bytes; i < TOTAL_PARTS; i++)
1559 pedwarn ("integer constant out of range");
1561 /* This is simplified by the fact that our constant
1562 is always positive. */
1566 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1568 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1569 / HOST_BITS_PER_CHAR)]
1570 << (i * HOST_BITS_PER_CHAR));
1571 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1574 yylval.ttype = build_int_2 (low, high);
1575 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1577 /* If warn_traditional, calculate both the ANSI type and the
1578 traditional type, then see if they disagree.
1579 Otherwise, calculate only the type for the dialect in use. */
1580 if (warn_traditional || flag_traditional)
1582 /* Calculate the traditional type. */
1583 /* Traditionally, any constant is signed;
1584 but if unsigned is specified explicitly, obey that.
1585 Use the smallest size with the right number of bits,
1586 except for one special case with decimal constants. */
1587 if (! spec_long && base != 10
1588 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1589 traditional_type = (spec_unsigned ? unsigned_type_node
1590 : integer_type_node);
1591 /* A decimal constant must be long
1592 if it does not fit in type int.
1593 I think this is independent of whether
1594 the constant is signed. */
1595 else if (! spec_long && base == 10
1596 && int_fits_type_p (yylval.ttype, integer_type_node))
1597 traditional_type = (spec_unsigned ? unsigned_type_node
1598 : integer_type_node);
1599 else if (! spec_long_long)
1600 traditional_type = (spec_unsigned ? long_unsigned_type_node
1601 : long_integer_type_node);
1603 traditional_type = (spec_unsigned
1604 ? long_long_unsigned_type_node
1605 : long_long_integer_type_node);
1607 if (warn_traditional || ! flag_traditional)
1609 /* Calculate the ANSI type. */
1610 if (! spec_long && ! spec_unsigned
1611 && int_fits_type_p (yylval.ttype, integer_type_node))
1612 ansi_type = integer_type_node;
1613 else if (! spec_long && (base != 10 || spec_unsigned)
1614 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1615 ansi_type = unsigned_type_node;
1616 else if (! spec_unsigned && !spec_long_long
1617 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1618 ansi_type = long_integer_type_node;
1619 else if (! spec_long_long)
1620 ansi_type = long_unsigned_type_node;
1621 else if (! spec_unsigned
1622 /* Verify value does not overflow into sign bit. */
1623 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
1624 && int_fits_type_p (yylval.ttype,
1625 long_long_integer_type_node))
1626 ansi_type = long_long_integer_type_node;
1628 ansi_type = long_long_unsigned_type_node;
1631 type = flag_traditional ? traditional_type : ansi_type;
1633 if (warn_traditional && traditional_type != ansi_type)
1635 if (TYPE_PRECISION (traditional_type)
1636 != TYPE_PRECISION (ansi_type))
1637 warning ("width of integer constant changes with -traditional");
1638 else if (TREE_UNSIGNED (traditional_type)
1639 != TREE_UNSIGNED (ansi_type))
1640 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1642 warning ("width of integer constant may change on other systems with -traditional");
1645 if (!flag_traditional && !int_fits_type_p (yylval.ttype, type)
1647 pedwarn ("integer constant out of range");
1649 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1650 warning ("decimal constant is so large that it is unsigned");
1654 if (TYPE_PRECISION (type)
1655 <= TYPE_PRECISION (integer_type_node))
1657 = build_complex (integer_zero_node,
1658 convert (integer_type_node, yylval.ttype));
1660 error ("complex integer constant is too wide for `complex int'");
1662 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1663 /* The traditional constant 0x80000000 is signed
1664 but doesn't fit in the range of int.
1665 This will change it to -0x80000000, which does fit. */
1667 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1668 yylval.ttype = convert (type, yylval.ttype);
1671 TREE_TYPE (yylval.ttype) = type;
1676 value = CONSTANT; break;
1682 register int result = 0;
1683 register int num_chars = 0;
1684 unsigned width = TYPE_PRECISION (char_type_node);
1689 width = WCHAR_TYPE_SIZE;
1690 #ifdef MULTIBYTE_CHARS
1691 max_chars = MB_CUR_MAX;
1697 max_chars = TYPE_PRECISION (integer_type_node) / width;
1705 if (c == '\'' || c == EOF)
1711 c = readescape (&ignore);
1714 if (width < HOST_BITS_PER_INT
1715 && (unsigned) c >= (1 << width))
1716 pedwarn ("escape sequence out of range for character");
1717 #ifdef MAP_CHARACTER
1719 c = MAP_CHARACTER (c);
1725 pedwarn ("ANSI C forbids newline in character constant");
1728 #ifdef MAP_CHARACTER
1730 c = MAP_CHARACTER (c);
1734 if (num_chars > maxtoken - 4)
1735 extend_token_buffer (token_buffer);
1737 token_buffer[num_chars] = c;
1739 /* Merge character into result; ignore excess chars. */
1740 if (num_chars < max_chars + 1)
1742 if (width < HOST_BITS_PER_INT)
1743 result = (result << width) | (c & ((1 << width) - 1));
1749 token_buffer[num_chars + 1] = '\'';
1750 token_buffer[num_chars + 2] = 0;
1753 error ("malformatted character constant");
1754 else if (num_chars == 0)
1755 error ("empty character constant");
1756 else if (num_chars > max_chars)
1758 num_chars = max_chars;
1759 error ("character constant too long");
1761 else if (num_chars != 1 && ! flag_traditional)
1762 warning ("multi-character character constant");
1764 /* If char type is signed, sign-extend the constant. */
1767 int num_bits = num_chars * width;
1768 if (TREE_UNSIGNED (char_type_node)
1769 || ((result >> (num_bits - 1)) & 1) == 0)
1771 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1772 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1776 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1777 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1779 TREE_TYPE (yylval.ttype) = integer_type_node;
1783 #ifdef MULTIBYTE_CHARS
1784 /* Set the initial shift state and convert the next sequence. */
1786 /* In all locales L'\0' is zero and mbtowc will return zero,
1789 || (num_chars == 1 && token_buffer[1] != '\0'))
1792 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1793 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1796 warning ("Ignoring invalid multibyte character");
1799 yylval.ttype = build_int_2 (result, 0);
1800 TREE_TYPE (yylval.ttype) = wchar_type_node;
1811 p = token_buffer + 1;
1813 while (c != '"' && c >= 0)
1815 /* ignore_escape_flag is set for reading the filename in #line. */
1816 if (!ignore_escape_flag && c == '\\')
1819 c = readescape (&ignore);
1823 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1824 && c >= (1 << TYPE_PRECISION (char_type_node)))
1825 pedwarn ("escape sequence out of range for character");
1830 pedwarn ("ANSI C forbids newline in string constant");
1834 if (p == token_buffer + maxtoken)
1835 p = extend_token_buffer (p);
1843 /* We have read the entire constant.
1844 Construct a STRING_CST for the result. */
1848 /* If this is a L"..." wide-string, convert the multibyte string
1849 to a wide character string. */
1850 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1853 #ifdef MULTIBYTE_CHARS
1854 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1855 if ((unsigned) len >= (p - token_buffer))
1857 warning ("Ignoring invalid multibyte string");
1860 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1863 union { long l; char c[sizeof (long)]; } u;
1867 /* Determine whether host is little or big endian. */
1869 big_endian = u.c[sizeof (long) - 1];
1870 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1872 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1873 for (cp = token_buffer + 1; cp < p; cp++)
1874 *wp = *cp, wp += WCHAR_BYTES;
1875 len = p - token_buffer - 1;
1878 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1879 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1883 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
1884 TREE_TYPE (yylval.ttype) = char_array_type_node;
1890 value = STRING; break;
1913 yylval.code = PLUS_EXPR; break;
1915 yylval.code = MINUS_EXPR; break;
1917 yylval.code = BIT_AND_EXPR; break;
1919 yylval.code = BIT_IOR_EXPR; break;
1921 yylval.code = MULT_EXPR; break;
1923 yylval.code = TRUNC_DIV_EXPR; break;
1925 yylval.code = TRUNC_MOD_EXPR; break;
1927 yylval.code = BIT_XOR_EXPR; break;
1929 yylval.code = LSHIFT_EXPR; break;
1931 yylval.code = RSHIFT_EXPR; break;
1933 yylval.code = LT_EXPR; break;
1935 yylval.code = GT_EXPR; break;
1938 token_buffer[1] = c1 = getc (finput);
1939 token_buffer[2] = 0;
1946 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
1948 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
1950 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
1952 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
1954 value = ASSIGN; goto done;
1960 value = PLUSPLUS; goto done;
1962 value = MINUSMINUS; goto done;
1964 value = ANDAND; goto done;
1966 value = OROR; goto done;
1974 else if ((c == '-') && (c1 == '>'))
1975 { value = POINTSAT; goto done; }
1976 ungetc (c1, finput);
1977 token_buffer[1] = 0;
1979 if ((c == '<') || (c == '>'))
1980 value = ARITHCOMPARE;
1986 /* Don't make yyparse think this is eof. */
1995 /* yylloc.last_line = lineno; */
2000 /* Sets the value of the 'yydebug' variable to VALUE.
2001 This is a function so we don't have to have YYDEBUG defined
2002 in order to build the compiler. */
2011 warning ("YYDEBUG not defined.");