1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 88, 89, 92, 94-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
35 /* MULTIBYTE_CHARS support only works for native compilers.
36 ??? Ideally what we want is to model widechar support after
37 the current floating point support. */
39 #undef MULTIBYTE_CHARS
42 #ifdef MULTIBYTE_CHARS
49 cpp_options parse_options;
50 static enum cpp_token cpp_token;
52 /* Stream for reading from the input file. */
56 /* The elements of `ridpointers' are identifier nodes
57 for the reserved type names and storage classes.
58 It is indexed by a RID_... value. */
59 tree ridpointers[(int) RID_MAX];
61 /* Cause the `yydebug' variable to be defined. */
65 static unsigned char *yy_cur, *yy_lim;
72 parse_in.limit = parse_in.token_buffer;
73 cpp_token = cpp_get_token (&parse_in);
74 if (cpp_token == CPP_EOF)
76 yy_lim = CPP_PWRITTEN (&parse_in);
77 yy_cur = parse_in.token_buffer;
83 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
84 #define UNGETC(c) ((c), yy_cur--)
86 #define GETC() getc (finput)
87 #define UNGETC(c) ungetc (c, finput)
90 /* the declaration found for the last IDENTIFIER token read in.
91 yylex must look this up to detect typedefs, which get token type TYPENAME,
92 so it is left around in case the identifier is not a typedef but is
93 used in a context which makes it a reference to a variable. */
96 /* Nonzero enables objc features. */
102 /* File used for outputting assembler code. */
103 extern FILE *asm_out_file;
105 #ifndef WCHAR_TYPE_SIZE
107 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
109 #define WCHAR_TYPE_SIZE BITS_PER_WORD
113 /* Number of bytes in a wide character. */
114 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
116 static int maxtoken; /* Current nominal length of token buffer. */
117 char *token_buffer; /* Pointer to token buffer.
118 Actual allocated length is maxtoken + 2.
119 This is not static because objc-parse.y uses it. */
121 static int indent_level = 0; /* Number of { minus number of }. */
123 /* Nonzero if end-of-file has been seen on input. */
124 static int end_of_file;
127 /* Buffered-back input character; faster than using ungetc. */
128 static int nextchar = -1;
131 #ifdef HANDLE_SYSV_PRAGMA
132 static int handle_sysv_pragma PROTO((int));
133 #endif /* HANDLE_SYSV_PRAGMA */
134 static int whitespace_cr PROTO((int));
135 static int skip_white_space PROTO((int));
136 static int skip_white_space_on_line PROTO((void));
137 static char *extend_token_buffer PROTO((char *));
138 static int readescape PROTO((int *));
139 int check_newline ();
141 /* Do not insert generated code into the source, instead, include it.
142 This allows us to build gcc automatically even for targets that
143 need to add or modify the reserved keyword lists. */
146 /* Return something to represent absolute declarators containing a *.
147 TARGET is the absolute declarator that the * contains.
148 TYPE_QUALS is a list of modifiers such as const or volatile
149 to apply to the pointer type, represented as identifiers.
151 We return an INDIRECT_REF whose "contents" are TARGET
152 and whose type is the modifier list. */
155 make_pointer_declarator (type_quals, target)
156 tree type_quals, target;
158 return build1 (INDIRECT_REF, type_quals, target);
162 forget_protocol_qualifiers ()
164 int i, n = sizeof wordlist / sizeof (struct resword);
166 for (i = 0; i < n; i++)
167 if ((int) wordlist[i].rid >= (int) RID_IN
168 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
169 wordlist[i].name = "";
173 remember_protocol_qualifiers ()
175 int i, n = sizeof wordlist / sizeof (struct resword);
177 for (i = 0; i < n; i++)
178 if (wordlist[i].rid == RID_IN)
179 wordlist[i].name = "in";
180 else if (wordlist[i].rid == RID_OUT)
181 wordlist[i].name = "out";
182 else if (wordlist[i].rid == RID_INOUT)
183 wordlist[i].name = "inout";
184 else if (wordlist[i].rid == RID_BYCOPY)
185 wordlist[i].name = "bycopy";
186 else if (wordlist[i].rid == RID_ONEWAY)
187 wordlist[i].name = "oneway";
191 init_parse (filename)
195 /* Open input file. */
196 if (filename == 0 || !strcmp (filename, "-"))
202 finput = fopen (filename, "r");
204 pfatal_with_name (filename);
206 #ifdef IO_BUFFER_SIZE
207 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
209 #endif /* !USE_CPPLIB */
217 cpp_reader_init (&parse_in);
218 parse_in.data = &parse_options;
219 cpp_options_init (&parse_options);
220 cpp_handle_options (&parse_in, 0, NULL); /* FIXME */
221 parse_in.show_column = 1;
222 if (! cpp_start_read (&parse_in, filename))
233 cpp_finish (&parse_in);
242 /* Make identifier nodes long enough for the language-specific slots. */
243 set_identifier_size (sizeof (struct lang_identifier));
245 /* Start it at 0, because check_newline is called at the very beginning
246 and will increment it to 1. */
249 #ifdef MULTIBYTE_CHARS
250 /* Change to the native locale for multibyte conversions. */
251 setlocale (LC_CTYPE, "");
255 token_buffer = (char *) xmalloc (maxtoken + 2);
257 ridpointers[(int) RID_INT] = get_identifier ("int");
258 ridpointers[(int) RID_CHAR] = get_identifier ("char");
259 ridpointers[(int) RID_VOID] = get_identifier ("void");
260 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
261 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
262 ridpointers[(int) RID_SHORT] = get_identifier ("short");
263 ridpointers[(int) RID_LONG] = get_identifier ("long");
264 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
265 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
266 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
267 ridpointers[(int) RID_CONST] = get_identifier ("const");
268 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
269 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
270 ridpointers[(int) RID_STATIC] = get_identifier ("static");
271 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
272 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
273 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
274 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
275 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
276 ridpointers[(int) RID_ID] = get_identifier ("id");
277 ridpointers[(int) RID_IN] = get_identifier ("in");
278 ridpointers[(int) RID_OUT] = get_identifier ("out");
279 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
280 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
281 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
282 forget_protocol_qualifiers();
284 /* Some options inhibit certain reserved words.
285 Clear those words out of the hash table so they won't be recognized. */
286 #define UNSET_RESERVED_WORD(STRING) \
287 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
288 if (s) s->name = ""; } while (0)
290 if (! doing_objc_thang)
291 UNSET_RESERVED_WORD ("id");
293 if (flag_traditional)
295 UNSET_RESERVED_WORD ("const");
296 UNSET_RESERVED_WORD ("volatile");
297 UNSET_RESERVED_WORD ("typeof");
298 UNSET_RESERVED_WORD ("signed");
299 UNSET_RESERVED_WORD ("inline");
300 UNSET_RESERVED_WORD ("iterator");
301 UNSET_RESERVED_WORD ("complex");
305 UNSET_RESERVED_WORD ("asm");
306 UNSET_RESERVED_WORD ("typeof");
307 UNSET_RESERVED_WORD ("inline");
308 UNSET_RESERVED_WORD ("iterator");
309 UNSET_RESERVED_WORD ("complex");
314 reinit_parse_for_function ()
318 /* Function used when yydebug is set, to print a token in more detail. */
321 yyprint (file, yychar, yylval)
333 if (IDENTIFIER_POINTER (t))
334 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
339 if (TREE_CODE (t) == INTEGER_CST)
341 #if HOST_BITS_PER_WIDE_INT == 64
342 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
345 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
352 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
358 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
363 /* Iff C is a carriage return, warn about it - if appropriate -
364 and return nonzero. */
369 static int newline_warning = 0;
373 /* ANSI C says the effects of a carriage return in a source file
375 if (pedantic && !newline_warning)
377 warning ("carriage return in source file");
378 warning ("(we only warn about the first carriage return)");
386 /* If C is not whitespace, return C.
387 Otherwise skip whitespace and return first nonwhite char read. */
397 /* We don't recognize comments here, because
398 cpp output can include / and * consecutively as operators.
399 Also, there's no need, since cpp removes all comments. */
402 c = check_newline ();
423 error ("stray '\\' in program");
433 /* Skips all of the white space at the current location in the input file.
434 Must use and reset nextchar if it has the next character. */
437 position_after_white_space ()
443 c = nextchar, nextchar = -1;
448 UNGETC (skip_white_space (c));
451 /* Like skip_white_space, but don't advance beyond the end of line.
452 Moreover, we don't get passed a character to start with. */
454 skip_white_space_on_line ()
483 /* Make the token buffer longer, preserving the data in it.
484 P should point to just beyond the last valid character in the old buffer.
485 The value we return is a pointer to the new buffer
486 at a place corresponding to P. */
489 extend_token_buffer (p)
492 int offset = p - token_buffer;
494 maxtoken = maxtoken * 2 + 10;
495 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
497 return token_buffer + offset;
501 #define GET_DIRECTIVE_LINE() get_directive_line (finput)
502 #else /* USE_CPPLIB */
503 /* Read the rest of a #-directive from input stream FINPUT.
504 In normal use, the directive name and the white space after it
505 have already been read, so they won't be included in the result.
506 We allow for the fact that the directive line may contain
507 a newline embedded within a character or string literal which forms
508 a part of the directive.
510 The value is a string in a reusable buffer. It remains valid
511 only until the next time this function is called. */
514 GET_DIRECTIVE_LINE ()
516 static char *directive_buffer = NULL;
517 static unsigned buffer_length = 0;
519 register char *buffer_limit;
520 register int looking_for = 0;
521 register int char_escaped = 0;
523 if (buffer_length == 0)
525 directive_buffer = (char *)xmalloc (128);
529 buffer_limit = &directive_buffer[buffer_length];
531 for (p = directive_buffer; ; )
535 /* Make buffer bigger if it is full. */
536 if (p >= buffer_limit)
538 register unsigned bytes_used = (p - directive_buffer);
542 = (char *)xrealloc (directive_buffer, buffer_length);
543 p = &directive_buffer[bytes_used];
544 buffer_limit = &directive_buffer[buffer_length];
549 /* Discard initial whitespace. */
550 if ((c == ' ' || c == '\t') && p == directive_buffer)
553 /* Detect the end of the directive. */
554 if (c == '\n' && looking_for == 0)
563 return directive_buffer;
565 /* Handle string and character constant syntax. */
568 if (looking_for == c && !char_escaped)
569 looking_for = 0; /* Found terminator... stop looking. */
572 if (c == '\'' || c == '"')
573 looking_for = c; /* Don't stop buffering until we see another
574 another one of these (or an EOF). */
576 /* Handle backslash. */
577 char_escaped = (c == '\\' && ! char_escaped);
580 #endif /* USE_CPPLIB */
582 /* At the beginning of a line, increment the line number
583 and process any #-directive on this line.
584 If the line is a #-directive, read the entire line and return a newline.
585 Otherwise, return the line's first non-whitespace character. */
595 /* Read first nonwhite char on the line. */
598 while (c == ' ' || c == '\t')
603 /* If not #, return it so caller will use it. */
607 /* Read first nonwhite char after the `#'. */
610 while (c == ' ' || c == '\t')
613 /* If a letter follows, then if the word here is `line', skip
614 it and ignore it; otherwise, ignore the line, with an error
615 if the word isn't `pragma', `ident', `define', or `undef'. */
617 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
626 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'
627 || whitespace_cr (c) ))
629 while (c == ' ' || c == '\t' || whitespace_cr (c))
633 #ifdef HANDLE_SYSV_PRAGMA
636 if (token != IDENTIFIER)
638 return handle_sysv_pragma (token);
639 #else /* !HANDLE_SYSV_PRAGMA */
644 if (token != IDENTIFIER)
646 if (HANDLE_PRAGMA (finput, yylval.ttype))
652 ??? do not know what to do ???;
653 #endif /* !USE_CPPLIB */
654 #endif /* HANDLE_PRAGMA */
655 #endif /* !HANDLE_SYSV_PRAGMA */
667 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
670 debug_define (lineno, GET_DIRECTIVE_LINE ());
680 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
683 debug_undef (lineno, GET_DIRECTIVE_LINE ());
692 && ((c = GETC()) == ' ' || c == '\t'))
701 && ((c = GETC()) == ' ' || c == '\t'))
703 /* #ident. The pedantic warning is now in cccp.c. */
705 /* Here we have just seen `#ident '.
706 A string constant should follow. */
708 c = skip_white_space_on_line ();
710 /* If no argument, ignore the line. */
717 || TREE_CODE (yylval.ttype) != STRING_CST)
719 error ("invalid #ident");
725 #ifdef ASM_OUTPUT_IDENT
726 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
730 /* Skip the rest of this line. */
735 error ("undefined or invalid # directive");
740 /* Here we have either `#line' or `# <nonletter>'.
741 In either case, it should be a line number; a digit should follow. */
743 /* Can't use skip_white_space here, but must handle all whitespace
744 that is not '\n', lest we get a recursion for '\r' '\n' when
747 c = skip_white_space_on_line ();
749 /* If the # is the only nonwhite char on the line,
750 just ignore it. Check the new newline. */
754 /* Something follows the #; read a token. */
759 if (token == CONSTANT
760 && TREE_CODE (yylval.ttype) == INTEGER_CST)
762 int old_lineno = lineno;
764 /* subtract one, because it is the following line that
765 gets the specified number */
767 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
769 /* Is this the last nonwhite stuff on the line? */
770 c = skip_white_space_on_line ();
773 /* No more: store the line number and check following line. */
779 /* More follows: it must be a string constant (filename). */
781 /* Read the string constant. */
784 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
786 error ("invalid #line");
791 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
792 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
795 /* Each change of file name
796 reinitializes whether we are now in a system header. */
797 in_system_header = 0;
799 if (main_input_filename == 0)
800 main_input_filename = input_filename;
802 /* Is this the last nonwhite stuff on the line? */
803 c = skip_white_space_on_line ();
806 /* Update the name in the top element of input_file_stack. */
807 if (input_file_stack)
808 input_file_stack->name = input_filename;
817 /* `1' after file name means entering new file.
818 `2' after file name means just left a file. */
820 if (token == CONSTANT
821 && TREE_CODE (yylval.ttype) == INTEGER_CST)
823 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
825 /* Pushing to a new file. */
827 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
828 input_file_stack->line = old_lineno;
829 p->next = input_file_stack;
830 p->name = input_filename;
831 p->indent_level = indent_level;
832 input_file_stack = p;
833 input_file_stack_tick++;
834 debug_start_source_file (input_filename);
837 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
839 /* Popping out of a file. */
840 if (input_file_stack->next)
842 struct file_stack *p = input_file_stack;
843 if (indent_level != p->indent_level)
845 warning_with_file_and_line
846 (p->name, old_lineno,
847 "This file contains more `%c's than `%c's.",
848 indent_level > p->indent_level ? '{' : '}',
849 indent_level > p->indent_level ? '}' : '{');
851 input_file_stack = p->next;
853 input_file_stack_tick++;
854 debug_end_source_file (input_file_stack->line);
857 error ("#-lines for entering and leaving files don't match");
863 /* Now that we've pushed or popped the input stack,
864 update the name in the top element. */
865 if (input_file_stack)
866 input_file_stack->name = input_filename;
868 /* If we have handled a `1' or a `2',
869 see if there is another number to read. */
872 /* Is this the last nonwhite stuff on the line? */
873 c = skip_white_space_on_line ();
882 /* `3' after file name means this is a system header file. */
884 if (token == CONSTANT
885 && TREE_CODE (yylval.ttype) == INTEGER_CST
886 && TREE_INT_CST_LOW (yylval.ttype) == 3)
887 in_system_header = 1, used_up = 1;
891 /* Is this the last nonwhite stuff on the line? */
892 c = skip_white_space_on_line ();
898 warning ("unrecognized text at end of #line");
901 error ("invalid #-line");
903 /* skip the rest of this line. */
906 if (c != '\n' && c != EOF && nextchar >= 0)
907 c = nextchar, nextchar = -1;
909 while (c != '\n' && c != EOF)
914 #ifdef HANDLE_SYSV_PRAGMA
916 /* Handle a #pragma directive.
917 TOKEN is the token we read after `#pragma'. Processes the entire input
918 line and returns a character for the caller to reread: either \n or EOF. */
920 /* This function has to be in this file, in order to get at
924 handle_sysv_pragma (token)
937 handle_pragma_token (token_buffer, yylval.ttype);
940 handle_pragma_token (token_buffer, 0);
944 c = nextchar, nextchar = -1;
949 while (c == ' ' || c == '\t')
951 if (c == '\n' || c == EOF)
953 handle_pragma_token (0, 0);
961 #endif /* HANDLE_SYSV_PRAGMA */
963 #define ENDFILE -1 /* token that represents end-of-file */
965 /* Read an escape sequence, returning its equivalent as a character,
966 or store 1 in *ignore_ptr if it is backslash-newline. */
969 readescape (ignore_ptr)
972 register int c = GETC();
974 register unsigned count;
975 unsigned firstdig = 0;
981 if (warn_traditional)
982 warning ("the meaning of `\\x' varies with -traditional");
984 if (flag_traditional)
993 if (!(c >= 'a' && c <= 'f')
994 && !(c >= 'A' && c <= 'F')
995 && !(c >= '0' && c <= '9'))
1001 if (c >= 'a' && c <= 'f')
1002 code += c - 'a' + 10;
1003 if (c >= 'A' && c <= 'F')
1004 code += c - 'A' + 10;
1005 if (c >= '0' && c <= '9')
1007 if (code != 0 || count != 0)
1016 error ("\\x used with no following hex digits");
1017 else if (count == 0)
1018 /* Digits are all 0's. Ok. */
1020 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
1022 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
1024 pedwarn ("hex escape out of range");
1027 case '0': case '1': case '2': case '3': case '4':
1028 case '5': case '6': case '7':
1031 while ((c <= '7') && (c >= '0') && (count++ < 3))
1033 code = (code * 8) + (c - '0');
1039 case '\\': case '\'': case '"':
1048 return TARGET_NEWLINE;
1063 if (warn_traditional)
1064 warning ("the meaning of `\\a' varies with -traditional");
1066 if (flag_traditional)
1071 #if 0 /* Vertical tab is present in common usage compilers. */
1072 if (flag_traditional)
1080 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1086 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1090 /* `\%' is used to prevent SCCS from getting confused. */
1093 pedwarn ("non-ANSI escape sequence `\\%c'", c);
1096 if (c >= 040 && c < 0177)
1097 pedwarn ("unknown escape sequence `\\%c'", c);
1099 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1109 strcpy (buf, string);
1111 /* We can't print string and character constants well
1112 because the token_buffer contains the result of processing escapes. */
1114 strcat (buf, " at end of input");
1115 else if (token_buffer[0] == 0)
1116 strcat (buf, " at null character");
1117 else if (token_buffer[0] == '"')
1118 strcat (buf, " before string constant");
1119 else if (token_buffer[0] == '\'')
1120 strcat (buf, " before character constant");
1121 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
1122 sprintf (buf + strlen (buf), " before character 0%o",
1123 (unsigned char) token_buffer[0]);
1125 strcat (buf, " before `%s'");
1127 error (buf, token_buffer);
1137 char long_long_flag;
1140 struct try_type type_sequence[] =
1142 { &integer_type_node, 0, 0, 0},
1143 { &unsigned_type_node, 1, 0, 0},
1144 { &long_integer_type_node, 0, 1, 0},
1145 { &long_unsigned_type_node, 1, 1, 0},
1146 { &long_long_integer_type_node, 0, 1, 1},
1147 { &long_long_unsigned_type_node, 1, 1, 1}
1162 c = nextchar, nextchar = -1;
1167 /* Effectively do c = skip_white_space (c)
1168 but do it faster in the usual cases. */
1181 /* Call skip_white_space so we can warn if appropriate. */
1186 c = skip_white_space (c);
1188 goto found_nonwhite;
1192 token_buffer[0] = c;
1193 token_buffer[1] = 0;
1195 /* yylloc.first_line = lineno; */
1201 token_buffer[0] = 0;
1206 /* Capital L may start a wide-string or wide-character constant. */
1208 register int c = GETC();
1217 goto string_constant;
1224 if (!doing_objc_thang)
1231 /* '@' may start a constant string object. */
1232 register int c = GETC ();
1236 goto string_constant;
1239 /* Fall through to treat '@' as the start of an identifier. */
1242 case 'A': case 'B': case 'C': case 'D': case 'E':
1243 case 'F': case 'G': case 'H': case 'I': case 'J':
1244 case 'K': case 'M': case 'N': case 'O':
1245 case 'P': case 'Q': case 'R': case 'S': case 'T':
1246 case 'U': case 'V': case 'W': case 'X': case 'Y':
1248 case 'a': case 'b': case 'c': case 'd': case 'e':
1249 case 'f': case 'g': case 'h': case 'i': case 'j':
1250 case 'k': case 'l': case 'm': case 'n': case 'o':
1251 case 'p': case 'q': case 'r': case 's': case 't':
1252 case 'u': case 'v': case 'w': case 'x': case 'y':
1258 while (ISALNUM (c) || c == '_' || c == '$' || c == '@')
1260 /* Make sure this char really belongs in an identifier. */
1261 if (c == '@' && ! doing_objc_thang)
1265 if (! dollars_in_ident)
1266 error ("`$' in identifier");
1268 pedwarn ("`$' in identifier");
1271 if (p >= token_buffer + maxtoken)
1272 p = extend_token_buffer (p);
1288 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1291 register struct resword *ptr;
1293 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
1296 yylval.ttype = ridpointers[(int) ptr->rid];
1297 value = (int) ptr->token;
1299 /* Only return OBJECTNAME if it is a typedef. */
1300 if (doing_objc_thang && value == OBJECTNAME)
1302 lastiddecl = lookup_name(yylval.ttype);
1304 if (lastiddecl == NULL_TREE
1305 || TREE_CODE (lastiddecl) != TYPE_DECL)
1309 /* Even if we decided to recognize asm, still perhaps warn. */
1311 && (value == ASM_KEYWORD || value == TYPEOF
1312 || ptr->rid == RID_INLINE)
1313 && token_buffer[0] != '_')
1314 pedwarn ("ANSI does not permit the keyword `%s'",
1319 /* If we did not find a keyword, look for an identifier
1322 if (value == IDENTIFIER)
1324 if (token_buffer[0] == '@')
1325 error("invalid identifier `%s'", token_buffer);
1327 yylval.ttype = get_identifier (token_buffer);
1328 lastiddecl = lookup_name (yylval.ttype);
1330 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1332 /* A user-invisible read-only initialized variable
1333 should be replaced by its value.
1334 We handle only strings since that's the only case used in C. */
1335 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1336 && DECL_IGNORED_P (lastiddecl)
1337 && TREE_READONLY (lastiddecl)
1338 && DECL_INITIAL (lastiddecl) != 0
1339 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1341 tree stringval = DECL_INITIAL (lastiddecl);
1343 /* Copy the string value so that we won't clobber anything
1344 if we put something in the TREE_CHAIN of this one. */
1345 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1346 TREE_STRING_POINTER (stringval));
1349 else if (doing_objc_thang)
1351 tree objc_interface_decl = is_class_name (yylval.ttype);
1353 if (objc_interface_decl)
1356 yylval.ttype = objc_interface_decl;
1366 /* Check first for common special case: single-digit 0 or 1. */
1369 UNGETC (next_c); /* Always undo this lookahead. */
1370 if (!ISALNUM (next_c) && next_c != '.')
1372 token_buffer[0] = (char)c, token_buffer[1] = '\0';
1373 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1379 case '2': case '3': case '4':
1380 case '5': case '6': case '7': case '8': case '9':
1385 int largest_digit = 0;
1387 /* for multi-precision arithmetic,
1388 we actually store only HOST_BITS_PER_CHAR bits in each part.
1389 The number of parts is chosen so as to be sufficient to hold
1390 the enough bits to fit into the two HOST_WIDE_INTs that contain
1391 the integer value (this is always at least as many bits as are
1392 in a target `long long' value, but may be wider). */
1393 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1394 int parts[TOTAL_PARTS];
1397 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1400 for (count = 0; count < TOTAL_PARTS; count++)
1408 *p++ = (c = GETC());
1409 if ((c == 'x') || (c == 'X'))
1412 *p++ = (c = GETC());
1414 /* Leading 0 forces octal unless the 0 is the only digit. */
1415 else if (c >= '0' && c <= '9')
1424 /* Read all the digits-and-decimal-points. */
1427 || (ISALNUM (c) && c != 'l' && c != 'L'
1428 && c != 'u' && c != 'U'
1429 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1430 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1435 error ("floating constant may not be in radix 16");
1436 if (floatflag == TOO_MANY_POINTS)
1437 /* We have already emitted an error. Don't need another. */
1439 else if (floatflag == AFTER_POINT)
1441 error ("malformed floating constant");
1442 floatflag = TOO_MANY_POINTS;
1443 /* Avoid another error from atof by forcing all characters
1444 from here on to be ignored. */
1448 floatflag = AFTER_POINT;
1452 /* Accept '.' as the start of a floating-point number
1453 only when it is followed by a digit.
1454 Otherwise, unread the following non-digit
1455 and use the '.' as a structural token. */
1456 if (p == token_buffer + 2 && !ISDIGIT (c))
1467 error ("parse error at `..'");
1470 token_buffer[1] = 0;
1477 /* It is not a decimal point.
1478 It should be a digit (perhaps a hex digit). */
1484 else if (base <= 10)
1486 if (c == 'e' || c == 'E')
1489 floatflag = AFTER_POINT;
1490 break; /* start of exponent */
1492 error ("nondigits in number and not hexadecimal");
1503 if (c >= largest_digit)
1507 for (count = 0; count < TOTAL_PARTS; count++)
1509 parts[count] *= base;
1513 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1515 &= (1 << HOST_BITS_PER_CHAR) - 1;
1521 /* If the extra highest-order part ever gets anything in it,
1522 the number is certainly too big. */
1523 if (parts[TOTAL_PARTS - 1] != 0)
1526 if (p >= token_buffer + maxtoken - 3)
1527 p = extend_token_buffer (p);
1528 *p++ = (c = GETC());
1533 error ("numeric constant with no digits");
1535 if (largest_digit >= base)
1536 error ("numeric constant contains digits beyond the radix");
1538 /* Remove terminating char from the token buffer and delimit the string */
1541 if (floatflag != NOT_FLOAT)
1543 tree type = double_type_node;
1545 int conversion_errno = 0;
1546 REAL_VALUE_TYPE value;
1549 /* Read explicit exponent if any, and put it in tokenbuf. */
1551 if ((c == 'e') || (c == 'E'))
1553 if (p >= token_buffer + maxtoken - 3)
1554 p = extend_token_buffer (p);
1557 if ((c == '+') || (c == '-'))
1563 error ("floating constant exponent has no digits");
1566 if (p >= token_buffer + maxtoken - 3)
1567 p = extend_token_buffer (p);
1575 /* Convert string to a double, checking for overflow. */
1576 if (setjmp (handler))
1578 error ("floating constant out of range");
1583 int fflag = 0, lflag = 0;
1584 /* Copy token_buffer now, while it has just the number
1585 and not the suffixes; once we add `f' or `i',
1586 REAL_VALUE_ATOF may not work any more. */
1587 char *copy = (char *) alloca (p - token_buffer + 1);
1588 bcopy (token_buffer, copy, p - token_buffer + 1);
1590 set_float_handler (handler);
1596 /* Read the suffixes to choose a data type. */
1601 error ("more than one `f' in numeric constant");
1607 error ("more than one `l' in numeric constant");
1613 error ("more than one `i' or `j' in numeric constant");
1615 pedwarn ("ANSI C forbids imaginary numeric constants");
1626 if (p >= token_buffer + maxtoken - 3)
1627 p = extend_token_buffer (p);
1633 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1634 tells the desired precision of the binary result
1635 of decimal-to-binary conversion. */
1640 error ("both `f' and `l' in floating constant");
1642 type = float_type_node;
1644 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1645 conversion_errno = errno;
1646 /* A diagnostic is required here by some ANSI C testsuites.
1647 This is not pedwarn, become some people don't want
1648 an error for this. */
1649 if (REAL_VALUE_ISINF (value) && pedantic)
1650 warning ("floating point number exceeds range of `float'");
1654 type = long_double_type_node;
1656 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1657 conversion_errno = errno;
1658 if (REAL_VALUE_ISINF (value) && pedantic)
1659 warning ("floating point number exceeds range of `long double'");
1664 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1665 conversion_errno = errno;
1666 if (REAL_VALUE_ISINF (value) && pedantic)
1667 warning ("floating point number exceeds range of `double'");
1670 set_float_handler (NULL_PTR);
1673 /* ERANGE is also reported for underflow,
1674 so test the value to distinguish overflow from that. */
1675 if (conversion_errno == ERANGE && !flag_traditional && pedantic
1676 && (REAL_VALUES_LESS (dconst1, value)
1677 || REAL_VALUES_LESS (value, dconstm1)))
1678 warning ("floating point number exceeds range of `double'");
1681 /* If the result is not a number, assume it must have been
1682 due to some error message above, so silently convert
1684 if (REAL_VALUE_ISNAN (value))
1687 /* Create a node with determined type and value. */
1689 yylval.ttype = build_complex (NULL_TREE,
1690 convert (type, integer_zero_node),
1691 build_real (type, value));
1693 yylval.ttype = build_real (type, value);
1697 tree traditional_type, ansi_type, type;
1698 HOST_WIDE_INT high, low;
1699 int spec_unsigned = 0;
1701 int spec_long_long = 0;
1705 traditional_type = ansi_type = type = NULL_TREE;
1708 if (c == 'u' || c == 'U')
1711 error ("two `u's in integer constant");
1714 else if (c == 'l' || c == 'L')
1719 error ("three `l's in integer constant");
1721 pedwarn ("ANSI C forbids long long integer constants");
1726 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1729 error ("more than one `i' or `j' in numeric constant");
1731 pedwarn ("ANSI C forbids imaginary numeric constants");
1736 if (p >= token_buffer + maxtoken - 3)
1737 p = extend_token_buffer (p);
1742 /* If the constant won't fit in an unsigned long long,
1743 then warn that the constant is out of range. */
1745 /* ??? This assumes that long long and long integer types are
1746 a multiple of 8 bits. This better than the original code
1747 though which assumed that long was exactly 32 bits and long
1748 long was exactly 64 bits. */
1750 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1753 for (i = bytes; i < TOTAL_PARTS; i++)
1757 pedwarn ("integer constant out of range");
1759 /* This is simplified by the fact that our constant
1760 is always positive. */
1764 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1766 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1767 / HOST_BITS_PER_CHAR)]
1768 << (i * HOST_BITS_PER_CHAR));
1769 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1772 yylval.ttype = build_int_2 (low, high);
1773 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1775 /* If warn_traditional, calculate both the ANSI type and the
1776 traditional type, then see if they disagree.
1777 Otherwise, calculate only the type for the dialect in use. */
1778 if (warn_traditional || flag_traditional)
1780 /* Calculate the traditional type. */
1781 /* Traditionally, any constant is signed;
1782 but if unsigned is specified explicitly, obey that.
1783 Use the smallest size with the right number of bits,
1784 except for one special case with decimal constants. */
1785 if (! spec_long && base != 10
1786 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1787 traditional_type = (spec_unsigned ? unsigned_type_node
1788 : integer_type_node);
1789 /* A decimal constant must be long
1790 if it does not fit in type int.
1791 I think this is independent of whether
1792 the constant is signed. */
1793 else if (! spec_long && base == 10
1794 && int_fits_type_p (yylval.ttype, integer_type_node))
1795 traditional_type = (spec_unsigned ? unsigned_type_node
1796 : integer_type_node);
1797 else if (! spec_long_long)
1798 traditional_type = (spec_unsigned ? long_unsigned_type_node
1799 : long_integer_type_node);
1801 traditional_type = (spec_unsigned
1802 ? long_long_unsigned_type_node
1803 : long_long_integer_type_node);
1805 if (warn_traditional || ! flag_traditional)
1807 /* Calculate the ANSI type. */
1808 if (! spec_long && ! spec_unsigned
1809 && int_fits_type_p (yylval.ttype, integer_type_node))
1810 ansi_type = integer_type_node;
1811 else if (! spec_long && (base != 10 || spec_unsigned)
1812 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1813 ansi_type = unsigned_type_node;
1814 else if (! spec_unsigned && !spec_long_long
1815 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1816 ansi_type = long_integer_type_node;
1817 else if (! spec_long_long
1818 && int_fits_type_p (yylval.ttype,
1819 long_unsigned_type_node))
1820 ansi_type = long_unsigned_type_node;
1821 else if (! spec_unsigned
1822 && int_fits_type_p (yylval.ttype,
1823 long_long_integer_type_node))
1824 ansi_type = long_long_integer_type_node;
1826 ansi_type = long_long_unsigned_type_node;
1829 type = flag_traditional ? traditional_type : ansi_type;
1831 if (warn_traditional && traditional_type != ansi_type)
1833 if (TYPE_PRECISION (traditional_type)
1834 != TYPE_PRECISION (ansi_type))
1835 warning ("width of integer constant changes with -traditional");
1836 else if (TREE_UNSIGNED (traditional_type)
1837 != TREE_UNSIGNED (ansi_type))
1838 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1840 warning ("width of integer constant may change on other systems with -traditional");
1843 if (pedantic && !flag_traditional && !spec_long_long && !warn
1844 && (TYPE_PRECISION (long_integer_type_node)
1845 < TYPE_PRECISION (type)))
1846 pedwarn ("integer constant out of range");
1848 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1849 warning ("decimal constant is so large that it is unsigned");
1853 if (TYPE_PRECISION (type)
1854 <= TYPE_PRECISION (integer_type_node))
1856 = build_complex (NULL_TREE, integer_zero_node,
1857 convert (integer_type_node,
1860 error ("complex integer constant is too wide for `complex int'");
1862 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1863 /* The traditional constant 0x80000000 is signed
1864 but doesn't fit in the range of int.
1865 This will change it to -0x80000000, which does fit. */
1867 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1868 yylval.ttype = convert (type, yylval.ttype);
1869 TREE_OVERFLOW (yylval.ttype)
1870 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1873 TREE_TYPE (yylval.ttype) = type;
1879 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
1880 || (!flag_traditional && (c == '-' || c == '+')
1881 && (p[-1] == 'e' || p[-1] == 'E')))
1882 error ("missing white space after number `%s'", token_buffer);
1884 value = CONSTANT; break;
1890 register int result = 0;
1891 register int num_chars = 0;
1892 unsigned width = TYPE_PRECISION (char_type_node);
1897 width = WCHAR_TYPE_SIZE;
1898 #ifdef MULTIBYTE_CHARS
1899 max_chars = MB_CUR_MAX;
1905 max_chars = TYPE_PRECISION (integer_type_node) / width;
1913 if (c == '\'' || c == EOF)
1919 c = readescape (&ignore);
1922 if (width < HOST_BITS_PER_INT
1923 && (unsigned) c >= (1 << width))
1924 pedwarn ("escape sequence out of range for character");
1925 #ifdef MAP_CHARACTER
1927 c = MAP_CHARACTER (c);
1933 pedwarn ("ANSI C forbids newline in character constant");
1936 #ifdef MAP_CHARACTER
1938 c = MAP_CHARACTER (c);
1942 if (num_chars > maxtoken - 4)
1943 extend_token_buffer (token_buffer);
1945 token_buffer[num_chars] = c;
1947 /* Merge character into result; ignore excess chars. */
1948 if (num_chars < max_chars + 1)
1950 if (width < HOST_BITS_PER_INT)
1951 result = (result << width) | (c & ((1 << width) - 1));
1957 token_buffer[num_chars + 1] = '\'';
1958 token_buffer[num_chars + 2] = 0;
1961 error ("malformatted character constant");
1962 else if (num_chars == 0)
1963 error ("empty character constant");
1964 else if (num_chars > max_chars)
1966 num_chars = max_chars;
1967 error ("character constant too long");
1969 else if (num_chars != 1 && ! flag_traditional)
1970 warning ("multi-character character constant");
1972 /* If char type is signed, sign-extend the constant. */
1975 int num_bits = num_chars * width;
1977 /* We already got an error; avoid invalid shift. */
1978 yylval.ttype = build_int_2 (0, 0);
1979 else if (TREE_UNSIGNED (char_type_node)
1980 || ((result >> (num_bits - 1)) & 1) == 0)
1982 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
1983 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1987 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
1988 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1990 TREE_TYPE (yylval.ttype) = integer_type_node;
1994 #ifdef MULTIBYTE_CHARS
1995 /* Set the initial shift state and convert the next sequence. */
1997 /* In all locales L'\0' is zero and mbtowc will return zero,
2000 || (num_chars == 1 && token_buffer[1] != '\0'))
2003 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
2004 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
2007 warning ("Ignoring invalid multibyte character");
2010 yylval.ttype = build_int_2 (result, 0);
2011 TREE_TYPE (yylval.ttype) = wchar_type_node;
2022 p = token_buffer + 1;
2024 while (c != '"' && c >= 0)
2029 c = readescape (&ignore);
2033 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
2034 && c >= (1 << TYPE_PRECISION (char_type_node)))
2035 pedwarn ("escape sequence out of range for character");
2040 pedwarn ("ANSI C forbids newline in string constant");
2044 if (p == token_buffer + maxtoken)
2045 p = extend_token_buffer (p);
2054 error ("Unterminated string constant");
2056 /* We have read the entire constant.
2057 Construct a STRING_CST for the result. */
2061 /* If this is a L"..." wide-string, convert the multibyte string
2062 to a wide character string. */
2063 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
2066 #ifdef MULTIBYTE_CHARS
2067 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
2068 if (len < 0 || len >= (p - token_buffer))
2070 warning ("Ignoring invalid multibyte string");
2073 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
2078 wp = widep + (BYTES_BIG_ENDIAN ? WCHAR_BYTES - 1 : 0);
2079 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
2080 for (cp = token_buffer + 1; cp < p; cp++)
2081 *wp = *cp, wp += WCHAR_BYTES;
2082 len = p - token_buffer - 1;
2085 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
2086 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2091 extern tree build_objc_string();
2092 /* Return an Objective-C @"..." constant string object. */
2093 yylval.ttype = build_objc_string (p - token_buffer,
2095 TREE_TYPE (yylval.ttype) = char_array_type_node;
2096 value = OBJC_STRING;
2100 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
2101 TREE_TYPE (yylval.ttype) = char_array_type_node;
2132 yylval.code = PLUS_EXPR; break;
2134 yylval.code = MINUS_EXPR; break;
2136 yylval.code = BIT_AND_EXPR; break;
2138 yylval.code = BIT_IOR_EXPR; break;
2140 yylval.code = MULT_EXPR; break;
2142 yylval.code = TRUNC_DIV_EXPR; break;
2144 yylval.code = TRUNC_MOD_EXPR; break;
2146 yylval.code = BIT_XOR_EXPR; break;
2148 yylval.code = LSHIFT_EXPR; break;
2150 yylval.code = RSHIFT_EXPR; break;
2152 yylval.code = LT_EXPR; break;
2154 yylval.code = GT_EXPR; break;
2157 token_buffer[1] = c1 = GETC();
2158 token_buffer[2] = 0;
2165 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2167 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2169 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2171 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2173 value = ASSIGN; goto done;
2179 value = PLUSPLUS; goto done;
2181 value = MINUSMINUS; goto done;
2183 value = ANDAND; goto done;
2185 value = OROR; goto done;
2198 { value = POINTSAT; goto done; }
2202 { value = ']'; goto done; }
2206 { value = '{'; indent_level++; goto done; }
2208 { value = '['; goto done; }
2212 { value = '}'; indent_level--; goto done; }
2216 token_buffer[1] = 0;
2218 if ((c == '<') || (c == '>'))
2219 value = ARITHCOMPARE;
2225 /* Don't make yyparse think this is eof. */
2244 /* yylloc.last_line = lineno; */
2249 /* Sets the value of the 'yydebug' variable to VALUE.
2250 This is a function so we don't have to have YYDEBUG defined
2251 in order to build the compiler. */
2260 warning ("YYDEBUG not defined.");