1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 88, 89, 92, 94, 95, 1996 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. */
38 #ifdef MULTIBYTE_CHARS
50 cpp_options parse_options;
51 static enum cpp_token cpp_token;
54 /* The elements of `ridpointers' are identifier nodes
55 for the reserved type names and storage classes.
56 It is indexed by a RID_... value. */
57 tree ridpointers[(int) RID_MAX];
59 /* Cause the `yydebug' variable to be defined. */
63 static unsigned char *yy_cur, *yy_lim;
70 parse_in.limit = parse_in.token_buffer;
71 cpp_token = cpp_get_token (&parse_in);
72 if (cpp_token == CPP_EOF)
74 yy_lim = CPP_PWRITTEN (&parse_in);
75 yy_cur = parse_in.token_buffer;
81 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
82 #define UNGETC(c) ((c), yy_cur--)
84 #define GETC() getc (finput)
85 #define UNGETC(c) ungetc (c, finput)
88 /* the declaration found for the last IDENTIFIER token read in.
89 yylex must look this up to detect typedefs, which get token type TYPENAME,
90 so it is left around in case the identifier is not a typedef but is
91 used in a context which makes it a reference to a variable. */
94 /* Nonzero enables objc features. */
98 extern tree is_class_name ();
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 /* Nonzero if end-of-file has been seen on input. */
122 static int end_of_file;
125 /* Buffered-back input character; faster than using ungetc. */
126 static int nextchar = -1;
129 int check_newline ();
131 /* Do not insert generated code into the source, instead, include it.
132 This allows us to build gcc automatically even for targets that
133 need to add or modify the reserved keyword lists. */
136 /* Return something to represent absolute declarators containing a *.
137 TARGET is the absolute declarator that the * contains.
138 TYPE_QUALS is a list of modifiers such as const or volatile
139 to apply to the pointer type, represented as identifiers.
141 We return an INDIRECT_REF whose "contents" are TARGET
142 and whose type is the modifier list. */
145 make_pointer_declarator (type_quals, target)
146 tree type_quals, target;
148 return build1 (INDIRECT_REF, type_quals, target);
152 forget_protocol_qualifiers ()
154 int i, n = sizeof wordlist / sizeof (struct resword);
156 for (i = 0; i < n; i++)
157 if ((int) wordlist[i].rid >= (int) RID_IN
158 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
159 wordlist[i].name = "";
163 remember_protocol_qualifiers ()
165 int i, n = sizeof wordlist / sizeof (struct resword);
167 for (i = 0; i < n; i++)
168 if (wordlist[i].rid == RID_IN)
169 wordlist[i].name = "in";
170 else if (wordlist[i].rid == RID_OUT)
171 wordlist[i].name = "out";
172 else if (wordlist[i].rid == RID_INOUT)
173 wordlist[i].name = "inout";
174 else if (wordlist[i].rid == RID_BYCOPY)
175 wordlist[i].name = "bycopy";
176 else if (wordlist[i].rid == RID_ONEWAY)
177 wordlist[i].name = "oneway";
182 init_parse (filename)
189 cpp_reader_init (&parse_in);
190 parse_in.data = &parse_options;
191 cpp_options_init (&parse_options);
192 cpp_handle_options (&parse_in, 0, NULL); /* FIXME */
193 parse_in.show_column = 1;
194 if (! cpp_start_read (&parse_in, filename))
201 cpp_finish (&parse_in);
208 /* Make identifier nodes long enough for the language-specific slots. */
209 set_identifier_size (sizeof (struct lang_identifier));
211 /* Start it at 0, because check_newline is called at the very beginning
212 and will increment it to 1. */
215 #ifdef MULTIBYTE_CHARS
216 /* Change to the native locale for multibyte conversions. */
217 setlocale (LC_CTYPE, "");
221 token_buffer = (char *) xmalloc (maxtoken + 2);
223 ridpointers[(int) RID_INT] = get_identifier ("int");
224 ridpointers[(int) RID_CHAR] = get_identifier ("char");
225 ridpointers[(int) RID_VOID] = get_identifier ("void");
226 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
227 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
228 ridpointers[(int) RID_SHORT] = get_identifier ("short");
229 ridpointers[(int) RID_LONG] = get_identifier ("long");
230 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
231 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
232 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
233 ridpointers[(int) RID_CONST] = get_identifier ("const");
234 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
235 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
236 ridpointers[(int) RID_STATIC] = get_identifier ("static");
237 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
238 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
239 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
240 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
241 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
242 ridpointers[(int) RID_ID] = get_identifier ("id");
243 ridpointers[(int) RID_IN] = get_identifier ("in");
244 ridpointers[(int) RID_OUT] = get_identifier ("out");
245 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
246 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
247 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
248 forget_protocol_qualifiers();
250 /* Some options inhibit certain reserved words.
251 Clear those words out of the hash table so they won't be recognized. */
252 #define UNSET_RESERVED_WORD(STRING) \
253 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
254 if (s) s->name = ""; } while (0)
256 if (! doing_objc_thang)
257 UNSET_RESERVED_WORD ("id");
259 if (flag_traditional)
261 UNSET_RESERVED_WORD ("const");
262 UNSET_RESERVED_WORD ("volatile");
263 UNSET_RESERVED_WORD ("typeof");
264 UNSET_RESERVED_WORD ("signed");
265 UNSET_RESERVED_WORD ("inline");
266 UNSET_RESERVED_WORD ("iterator");
267 UNSET_RESERVED_WORD ("complex");
271 UNSET_RESERVED_WORD ("asm");
272 UNSET_RESERVED_WORD ("typeof");
273 UNSET_RESERVED_WORD ("inline");
274 UNSET_RESERVED_WORD ("iterator");
275 UNSET_RESERVED_WORD ("complex");
280 reinit_parse_for_function ()
284 /* Function used when yydebug is set, to print a token in more detail. */
287 yyprint (file, yychar, yylval)
299 if (IDENTIFIER_POINTER (t))
300 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
305 if (TREE_CODE (t) == INTEGER_CST)
307 #if HOST_BITS_PER_WIDE_INT == 64
308 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
314 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
320 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
326 /* If C is not whitespace, return C.
327 Otherwise skip whitespace and return first nonwhite char read. */
333 static int newline_warning = 0;
339 /* We don't recognize comments here, because
340 cpp output can include / and * consecutively as operators.
341 Also, there's no need, since cpp removes all comments. */
344 c = check_newline ();
356 /* ANSI C says the effects of a carriage return in a source file
358 if (pedantic && !newline_warning)
360 warning ("carriage return in source file");
361 warning ("(we only warn about the first carriage return)");
372 error ("stray '\\' in program");
382 /* Skips all of the white space at the current location in the input file.
383 Must use and reset nextchar if it has the next character. */
386 position_after_white_space ()
392 c = nextchar, nextchar = -1;
397 UNGETC (skip_white_space (c));
400 /* Make the token buffer longer, preserving the data in it.
401 P should point to just beyond the last valid character in the old buffer.
402 The value we return is a pointer to the new buffer
403 at a place corresponding to P. */
406 extend_token_buffer (p)
409 int offset = p - token_buffer;
411 maxtoken = maxtoken * 2 + 10;
412 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
414 return token_buffer + offset;
419 #define GET_DIRECTIVE_LINE() get_directive_line (finput)
420 #else /* USE_CPPLIB */
421 /* Read the rest of a #-directive from input stream FINPUT.
422 In normal use, the directive name and the white space after it
423 have already been read, so they won't be included in the result.
424 We allow for the fact that the directive line may contain
425 a newline embedded within a character or string literal which forms
426 a part of the directive.
428 The value is a string in a reusable buffer. It remains valid
429 only until the next time this function is called. */
432 GET_DIRECTIVE_LINE ()
434 static char *directive_buffer = NULL;
435 static unsigned buffer_length = 0;
437 register char *buffer_limit;
438 register int looking_for = 0;
439 register int char_escaped = 0;
441 if (buffer_length == 0)
443 directive_buffer = (char *)xmalloc (128);
447 buffer_limit = &directive_buffer[buffer_length];
449 for (p = directive_buffer; ; )
453 /* Make buffer bigger if it is full. */
454 if (p >= buffer_limit)
456 register unsigned bytes_used = (p - directive_buffer);
460 = (char *)xrealloc (directive_buffer, buffer_length);
461 p = &directive_buffer[bytes_used];
462 buffer_limit = &directive_buffer[buffer_length];
467 /* Discard initial whitespace. */
468 if ((c == ' ' || c == '\t') && p == directive_buffer)
471 /* Detect the end of the directive. */
472 if (c == '\n' && looking_for == 0)
481 return directive_buffer;
483 /* Handle string and character constant syntax. */
486 if (looking_for == c && !char_escaped)
487 looking_for = 0; /* Found terminator... stop looking. */
490 if (c == '\'' || c == '"')
491 looking_for = c; /* Don't stop buffering until we see another
492 another one of these (or an EOF). */
494 /* Handle backslash. */
495 char_escaped = (c == '\\' && ! char_escaped);
498 #endif /* USE_CPPLIB */
500 /* At the beginning of a line, increment the line number
501 and process any #-directive on this line.
502 If the line is a #-directive, read the entire line and return a newline.
503 Otherwise, return the line's first non-whitespace character. */
513 /* Read first nonwhite char on the line. */
516 while (c == ' ' || c == '\t')
521 /* If not #, return it so caller will use it. */
525 /* Read first nonwhite char after the `#'. */
528 while (c == ' ' || c == '\t')
531 /* If a letter follows, then if the word here is `line', skip
532 it and ignore it; otherwise, ignore the line, with an error
533 if the word isn't `pragma', `ident', `define', or `undef'. */
535 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
544 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
546 while (c == ' ' || c == '\t')
550 #ifdef HANDLE_SYSV_PRAGMA
553 if (token != IDENTIFIER)
555 return handle_sysv_pragma (token);
556 #else /* !HANDLE_SYSV_PRAGMA */
561 if (token != IDENTIFIER)
563 if (HANDLE_PRAGMA (yylval.ttype))
569 ??? do not know what to do ???;
570 #endif /* !USE_CPPLIB */
571 #endif /* HANDLE_PRAGMA */
572 #endif /* !HANDLE_SYSV_PRAGMA */
584 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
587 debug_define (lineno, GET_DIRECTIVE_LINE ());
597 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
600 debug_undef (lineno, GET_DIRECTIVE_LINE ());
609 && ((c = GETC()) == ' ' || c == '\t'))
618 && ((c = GETC()) == ' ' || c == '\t'))
620 /* #ident. The pedantic warning is now in cccp.c. */
622 /* Here we have just seen `#ident '.
623 A string constant should follow. */
625 while (c == ' ' || c == '\t')
628 /* If no argument, ignore the line. */
635 || TREE_CODE (yylval.ttype) != STRING_CST)
637 error ("invalid #ident");
643 #ifdef ASM_OUTPUT_IDENT
644 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
648 /* Skip the rest of this line. */
653 error ("undefined or invalid # directive");
658 /* Here we have either `#line' or `# <nonletter>'.
659 In either case, it should be a line number; a digit should follow. */
661 while (c == ' ' || c == '\t')
664 /* If the # is the only nonwhite char on the line,
665 just ignore it. Check the new newline. */
669 /* Something follows the #; read a token. */
674 if (token == CONSTANT
675 && TREE_CODE (yylval.ttype) == INTEGER_CST)
677 int old_lineno = lineno;
679 /* subtract one, because it is the following line that
680 gets the specified number */
682 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
684 /* Is this the last nonwhite stuff on the line? */
686 while (c == ' ' || c == '\t')
690 /* No more: store the line number and check following line. */
696 /* More follows: it must be a string constant (filename). */
698 /* Read the string constant. */
701 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
703 error ("invalid #line");
708 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
709 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
712 /* Each change of file name
713 reinitializes whether we are now in a system header. */
714 in_system_header = 0;
716 if (main_input_filename == 0)
717 main_input_filename = input_filename;
719 /* Is this the last nonwhite stuff on the line? */
721 while (c == ' ' || c == '\t')
725 /* Update the name in the top element of input_file_stack. */
726 if (input_file_stack)
727 input_file_stack->name = input_filename;
736 /* `1' after file name means entering new file.
737 `2' after file name means just left a file. */
739 if (token == CONSTANT
740 && TREE_CODE (yylval.ttype) == INTEGER_CST)
742 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
744 /* Pushing to a new file. */
746 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
747 input_file_stack->line = old_lineno;
748 p->next = input_file_stack;
749 p->name = input_filename;
750 input_file_stack = p;
751 input_file_stack_tick++;
752 debug_start_source_file (input_filename);
755 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
757 /* Popping out of a file. */
758 if (input_file_stack->next)
760 struct file_stack *p = input_file_stack;
761 input_file_stack = p->next;
763 input_file_stack_tick++;
764 debug_end_source_file (input_file_stack->line);
767 error ("#-lines for entering and leaving files don't match");
773 /* Now that we've pushed or popped the input stack,
774 update the name in the top element. */
775 if (input_file_stack)
776 input_file_stack->name = input_filename;
778 /* If we have handled a `1' or a `2',
779 see if there is another number to read. */
782 /* Is this the last nonwhite stuff on the line? */
784 while (c == ' ' || c == '\t')
794 /* `3' after file name means this is a system header file. */
796 if (token == CONSTANT
797 && TREE_CODE (yylval.ttype) == INTEGER_CST
798 && TREE_INT_CST_LOW (yylval.ttype) == 3)
799 in_system_header = 1, used_up = 1;
803 /* Is this the last nonwhite stuff on the line? */
805 while (c == ' ' || c == '\t')
812 warning ("unrecognized text at end of #line");
815 error ("invalid #-line");
817 /* skip the rest of this line. */
819 while (c != '\n' && c != EOF)
824 #ifdef HANDLE_SYSV_PRAGMA
826 /* Handle a #pragma directive.
827 TOKEN is the token we read after `#pragma'. Processes the entire input
828 line and returns a character for the caller to reread: either \n or EOF. */
830 /* This function has to be in this file, in order to get at
834 handle_sysv_pragma (token)
847 handle_pragma_token (token_buffer, yylval.ttype);
850 handle_pragma_token (token_buffer, 0);
854 c = nextchar, nextchar = -1;
859 while (c == ' ' || c == '\t')
861 if (c == '\n' || c == EOF)
863 handle_pragma_token (0, 0);
871 #endif /* HANDLE_SYSV_PRAGMA */
873 #define ENDFILE -1 /* token that represents end-of-file */
875 /* Read an escape sequence, returning its equivalent as a character,
876 or store 1 in *ignore_ptr if it is backslash-newline. */
879 readescape (ignore_ptr)
882 register int c = GETC();
884 register unsigned count;
885 unsigned firstdig = 0;
891 if (warn_traditional)
892 warning ("the meaning of `\\x' varies with -traditional");
894 if (flag_traditional)
903 if (!(c >= 'a' && c <= 'f')
904 && !(c >= 'A' && c <= 'F')
905 && !(c >= '0' && c <= '9'))
911 if (c >= 'a' && c <= 'f')
912 code += c - 'a' + 10;
913 if (c >= 'A' && c <= 'F')
914 code += c - 'A' + 10;
915 if (c >= '0' && c <= '9')
917 if (code != 0 || count != 0)
926 error ("\\x used with no following hex digits");
928 /* Digits are all 0's. Ok. */
930 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
932 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
934 pedwarn ("hex escape out of range");
937 case '0': case '1': case '2': case '3': case '4':
938 case '5': case '6': case '7':
941 while ((c <= '7') && (c >= '0') && (count++ < 3))
943 code = (code * 8) + (c - '0');
949 case '\\': case '\'': case '"':
958 return TARGET_NEWLINE;
973 if (warn_traditional)
974 warning ("the meaning of `\\a' varies with -traditional");
976 if (flag_traditional)
981 #if 0 /* Vertical tab is present in common usage compilers. */
982 if (flag_traditional)
990 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
996 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1000 /* `\%' is used to prevent SCCS from getting confused. */
1003 pedwarn ("non-ANSI escape sequence `\\%c'", c);
1006 if (c >= 040 && c < 0177)
1007 pedwarn ("unknown escape sequence `\\%c'", c);
1009 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1019 strcpy (buf, string);
1021 /* We can't print string and character constants well
1022 because the token_buffer contains the result of processing escapes. */
1024 strcat (buf, " at end of input");
1025 else if (token_buffer[0] == 0)
1026 strcat (buf, " at null character");
1027 else if (token_buffer[0] == '"')
1028 strcat (buf, " before string constant");
1029 else if (token_buffer[0] == '\'')
1030 strcat (buf, " before character constant");
1031 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
1032 sprintf (buf + strlen (buf), " before character 0%o",
1033 (unsigned char) token_buffer[0]);
1035 strcat (buf, " before `%s'");
1037 error (buf, token_buffer);
1047 char long_long_flag;
1050 struct try_type type_sequence[] =
1052 { &integer_type_node, 0, 0, 0},
1053 { &unsigned_type_node, 1, 0, 0},
1054 { &long_integer_type_node, 0, 1, 0},
1055 { &long_unsigned_type_node, 1, 1, 0},
1056 { &long_long_integer_type_node, 0, 1, 1},
1057 { &long_long_unsigned_type_node, 1, 1, 1}
1072 c = nextchar, nextchar = -1;
1077 /* Effectively do c = skip_white_space (c)
1078 but do it faster in the usual cases. */
1091 /* Call skip_white_space so we can warn if appropriate. */
1096 c = skip_white_space (c);
1098 goto found_nonwhite;
1102 token_buffer[0] = c;
1103 token_buffer[1] = 0;
1105 /* yylloc.first_line = lineno; */
1111 token_buffer[0] = 0;
1116 /* Capital L may start a wide-string or wide-character constant. */
1118 register int c = GETC();
1127 goto string_constant;
1134 if (!doing_objc_thang)
1141 /* '@' may start a constant string object. */
1142 register int c = GETC ();
1146 goto string_constant;
1149 /* Fall through to treat '@' as the start of an identifier. */
1152 case 'A': case 'B': case 'C': case 'D': case 'E':
1153 case 'F': case 'G': case 'H': case 'I': case 'J':
1154 case 'K': case 'M': case 'N': case 'O':
1155 case 'P': case 'Q': case 'R': case 'S': case 'T':
1156 case 'U': case 'V': case 'W': case 'X': case 'Y':
1158 case 'a': case 'b': case 'c': case 'd': case 'e':
1159 case 'f': case 'g': case 'h': case 'i': case 'j':
1160 case 'k': case 'l': case 'm': case 'n': case 'o':
1161 case 'p': case 'q': case 'r': case 's': case 't':
1162 case 'u': case 'v': case 'w': case 'x': case 'y':
1168 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1170 /* Make sure this char really belongs in an identifier. */
1171 if (c == '@' && ! doing_objc_thang)
1175 if (! dollars_in_ident)
1176 error ("`$' in identifier");
1178 pedwarn ("`$' in identifier");
1181 if (p >= token_buffer + maxtoken)
1182 p = extend_token_buffer (p);
1198 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1201 register struct resword *ptr;
1203 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1206 yylval.ttype = ridpointers[(int) ptr->rid];
1207 value = (int) ptr->token;
1209 /* Only return OBJECTNAME if it is a typedef. */
1210 if (doing_objc_thang && value == OBJECTNAME)
1212 lastiddecl = lookup_name(yylval.ttype);
1214 if (lastiddecl == NULL_TREE
1215 || TREE_CODE (lastiddecl) != TYPE_DECL)
1219 /* Even if we decided to recognize asm, still perhaps warn. */
1221 && (value == ASM_KEYWORD || value == TYPEOF
1222 || ptr->rid == RID_INLINE)
1223 && token_buffer[0] != '_')
1224 pedwarn ("ANSI does not permit the keyword `%s'",
1229 /* If we did not find a keyword, look for an identifier
1232 if (value == IDENTIFIER)
1234 if (token_buffer[0] == '@')
1235 error("invalid identifier `%s'", token_buffer);
1237 yylval.ttype = get_identifier (token_buffer);
1238 lastiddecl = lookup_name (yylval.ttype);
1240 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1242 /* A user-invisible read-only initialized variable
1243 should be replaced by its value.
1244 We handle only strings since that's the only case used in C. */
1245 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1246 && DECL_IGNORED_P (lastiddecl)
1247 && TREE_READONLY (lastiddecl)
1248 && DECL_INITIAL (lastiddecl) != 0
1249 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1251 tree stringval = DECL_INITIAL (lastiddecl);
1253 /* Copy the string value so that we won't clobber anything
1254 if we put something in the TREE_CHAIN of this one. */
1255 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1256 TREE_STRING_POINTER (stringval));
1259 else if (doing_objc_thang)
1261 tree objc_interface_decl = is_class_name (yylval.ttype);
1263 if (objc_interface_decl)
1266 yylval.ttype = objc_interface_decl;
1276 /* Check first for common special case: single-digit 0 or 1. */
1279 UNGETC (next_c); /* Always undo this lookahead. */
1280 if (!isalnum (next_c) && next_c != '.')
1282 token_buffer[0] = (char)c, token_buffer[1] = '\0';
1283 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1289 case '2': case '3': case '4':
1290 case '5': case '6': case '7': case '8': case '9':
1295 int largest_digit = 0;
1297 /* for multi-precision arithmetic,
1298 we actually store only HOST_BITS_PER_CHAR bits in each part.
1299 The number of parts is chosen so as to be sufficient to hold
1300 the enough bits to fit into the two HOST_WIDE_INTs that contain
1301 the integer value (this is always at least as many bits as are
1302 in a target `long long' value, but may be wider). */
1303 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1304 int parts[TOTAL_PARTS];
1307 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1310 for (count = 0; count < TOTAL_PARTS; count++)
1318 *p++ = (c = GETC());
1319 if ((c == 'x') || (c == 'X'))
1322 *p++ = (c = GETC());
1324 /* Leading 0 forces octal unless the 0 is the only digit. */
1325 else if (c >= '0' && c <= '9')
1334 /* Read all the digits-and-decimal-points. */
1337 || (isalnum (c) && c != 'l' && c != 'L'
1338 && c != 'u' && c != 'U'
1339 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1340 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1345 error ("floating constant may not be in radix 16");
1346 if (floatflag == TOO_MANY_POINTS)
1347 /* We have already emitted an error. Don't need another. */
1349 else if (floatflag == AFTER_POINT)
1351 error ("malformed floating constant");
1352 floatflag = TOO_MANY_POINTS;
1353 /* Avoid another error from atof by forcing all characters
1354 from here on to be ignored. */
1358 floatflag = AFTER_POINT;
1362 /* Accept '.' as the start of a floating-point number
1363 only when it is followed by a digit.
1364 Otherwise, unread the following non-digit
1365 and use the '.' as a structural token. */
1366 if (p == token_buffer + 2 && !isdigit (c))
1377 error ("parse error at `..'");
1380 token_buffer[1] = 0;
1387 /* It is not a decimal point.
1388 It should be a digit (perhaps a hex digit). */
1394 else if (base <= 10)
1396 if (c == 'e' || c == 'E')
1399 floatflag = AFTER_POINT;
1400 break; /* start of exponent */
1402 error ("nondigits in number and not hexadecimal");
1413 if (c >= largest_digit)
1417 for (count = 0; count < TOTAL_PARTS; count++)
1419 parts[count] *= base;
1423 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1425 &= (1 << HOST_BITS_PER_CHAR) - 1;
1431 /* If the extra highest-order part ever gets anything in it,
1432 the number is certainly too big. */
1433 if (parts[TOTAL_PARTS - 1] != 0)
1436 if (p >= token_buffer + maxtoken - 3)
1437 p = extend_token_buffer (p);
1438 *p++ = (c = GETC());
1443 error ("numeric constant with no digits");
1445 if (largest_digit >= base)
1446 error ("numeric constant contains digits beyond the radix");
1448 /* Remove terminating char from the token buffer and delimit the string */
1451 if (floatflag != NOT_FLOAT)
1453 tree type = double_type_node;
1454 int exceeds_double = 0;
1456 REAL_VALUE_TYPE value;
1459 /* Read explicit exponent if any, and put it in tokenbuf. */
1461 if ((c == 'e') || (c == 'E'))
1463 if (p >= token_buffer + maxtoken - 3)
1464 p = extend_token_buffer (p);
1467 if ((c == '+') || (c == '-'))
1473 error ("floating constant exponent has no digits");
1476 if (p >= token_buffer + maxtoken - 3)
1477 p = extend_token_buffer (p);
1486 /* Convert string to a double, checking for overflow. */
1487 if (setjmp (handler))
1489 error ("floating constant out of range");
1494 int fflag = 0, lflag = 0;
1495 /* Copy token_buffer now, while it has just the number
1496 and not the suffixes; once we add `f' or `i',
1497 REAL_VALUE_ATOF may not work any more. */
1498 char *copy = (char *) alloca (p - token_buffer + 1);
1499 bcopy (token_buffer, copy, p - token_buffer + 1);
1501 set_float_handler (handler);
1507 /* Read the suffixes to choose a data type. */
1512 error ("more than one `f' in numeric constant");
1518 error ("more than one `l' in numeric constant");
1524 error ("more than one `i' or `j' in numeric constant");
1526 pedwarn ("ANSI C forbids imaginary numeric constants");
1537 if (p >= token_buffer + maxtoken - 3)
1538 p = extend_token_buffer (p);
1544 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1545 tells the desired precision of the binary result
1546 of decimal-to-binary conversion. */
1551 error ("both `f' and `l' in floating constant");
1553 type = float_type_node;
1554 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1555 /* A diagnostic is required here by some ANSI C testsuites.
1556 This is not pedwarn, become some people don't want
1557 an error for this. */
1558 if (REAL_VALUE_ISINF (value) && pedantic)
1559 warning ("floating point number exceeds range of `float'");
1563 type = long_double_type_node;
1564 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1565 if (REAL_VALUE_ISINF (value) && pedantic)
1566 warning ("floating point number exceeds range of `long double'");
1570 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1571 if (REAL_VALUE_ISINF (value) && pedantic)
1572 warning ("floating point number exceeds range of `double'");
1575 set_float_handler (NULL_PTR);
1578 if (errno == ERANGE && !flag_traditional && pedantic)
1580 /* ERANGE is also reported for underflow,
1581 so test the value to distinguish overflow from that. */
1582 if (REAL_VALUES_LESS (dconst1, value)
1583 || REAL_VALUES_LESS (value, dconstm1))
1585 warning ("floating point number exceeds range of `double'");
1591 /* If the result is not a number, assume it must have been
1592 due to some error message above, so silently convert
1594 if (REAL_VALUE_ISNAN (value))
1597 /* Create a node with determined type and value. */
1599 yylval.ttype = build_complex (NULL_TREE,
1600 convert (type, integer_zero_node),
1601 build_real (type, value));
1603 yylval.ttype = build_real (type, value);
1607 tree traditional_type, ansi_type, type;
1608 HOST_WIDE_INT high, low;
1609 int spec_unsigned = 0;
1611 int spec_long_long = 0;
1617 if (c == 'u' || c == 'U')
1620 error ("two `u's in integer constant");
1623 else if (c == 'l' || c == 'L')
1628 error ("three `l's in integer constant");
1630 pedwarn ("ANSI C forbids long long integer constants");
1635 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1638 error ("more than one `i' or `j' in numeric constant");
1640 pedwarn ("ANSI C forbids imaginary numeric constants");
1645 if (p >= token_buffer + maxtoken - 3)
1646 p = extend_token_buffer (p);
1651 /* If the constant is not long long and it won't fit in an
1652 unsigned long, or if the constant is long long and won't fit
1653 in an unsigned long long, then warn that the constant is out
1656 /* ??? This assumes that long long and long integer types are
1657 a multiple of 8 bits. This better than the original code
1658 though which assumed that long was exactly 32 bits and long
1659 long was exactly 64 bits. */
1662 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1664 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1667 for (i = bytes; i < TOTAL_PARTS; i++)
1671 pedwarn ("integer constant out of range");
1673 /* This is simplified by the fact that our constant
1674 is always positive. */
1678 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1680 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1681 / HOST_BITS_PER_CHAR)]
1682 << (i * HOST_BITS_PER_CHAR));
1683 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1686 yylval.ttype = build_int_2 (low, high);
1687 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1689 /* If warn_traditional, calculate both the ANSI type and the
1690 traditional type, then see if they disagree.
1691 Otherwise, calculate only the type for the dialect in use. */
1692 if (warn_traditional || flag_traditional)
1694 /* Calculate the traditional type. */
1695 /* Traditionally, any constant is signed;
1696 but if unsigned is specified explicitly, obey that.
1697 Use the smallest size with the right number of bits,
1698 except for one special case with decimal constants. */
1699 if (! spec_long && base != 10
1700 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1701 traditional_type = (spec_unsigned ? unsigned_type_node
1702 : integer_type_node);
1703 /* A decimal constant must be long
1704 if it does not fit in type int.
1705 I think this is independent of whether
1706 the constant is signed. */
1707 else if (! spec_long && base == 10
1708 && int_fits_type_p (yylval.ttype, integer_type_node))
1709 traditional_type = (spec_unsigned ? unsigned_type_node
1710 : integer_type_node);
1711 else if (! spec_long_long)
1712 traditional_type = (spec_unsigned ? long_unsigned_type_node
1713 : long_integer_type_node);
1715 traditional_type = (spec_unsigned
1716 ? long_long_unsigned_type_node
1717 : long_long_integer_type_node);
1719 if (warn_traditional || ! flag_traditional)
1721 /* Calculate the ANSI type. */
1722 if (! spec_long && ! spec_unsigned
1723 && int_fits_type_p (yylval.ttype, integer_type_node))
1724 ansi_type = integer_type_node;
1725 else if (! spec_long && (base != 10 || spec_unsigned)
1726 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1727 ansi_type = unsigned_type_node;
1728 else if (! spec_unsigned && !spec_long_long
1729 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1730 ansi_type = long_integer_type_node;
1731 else if (! spec_long_long)
1732 ansi_type = long_unsigned_type_node;
1733 else if (! spec_unsigned
1734 /* Verify value does not overflow into sign bit. */
1735 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
1736 && int_fits_type_p (yylval.ttype,
1737 long_long_integer_type_node))
1738 ansi_type = long_long_integer_type_node;
1740 ansi_type = long_long_unsigned_type_node;
1743 type = flag_traditional ? traditional_type : ansi_type;
1745 if (warn_traditional && traditional_type != ansi_type)
1747 if (TYPE_PRECISION (traditional_type)
1748 != TYPE_PRECISION (ansi_type))
1749 warning ("width of integer constant changes with -traditional");
1750 else if (TREE_UNSIGNED (traditional_type)
1751 != TREE_UNSIGNED (ansi_type))
1752 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1754 warning ("width of integer constant may change on other systems with -traditional");
1757 if (!flag_traditional && !int_fits_type_p (yylval.ttype, type)
1759 pedwarn ("integer constant out of range");
1761 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1762 warning ("decimal constant is so large that it is unsigned");
1766 if (TYPE_PRECISION (type)
1767 <= TYPE_PRECISION (integer_type_node))
1769 = build_complex (NULL_TREE, integer_zero_node,
1770 convert (integer_type_node,
1773 error ("complex integer constant is too wide for `complex int'");
1775 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1776 /* The traditional constant 0x80000000 is signed
1777 but doesn't fit in the range of int.
1778 This will change it to -0x80000000, which does fit. */
1780 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1781 yylval.ttype = convert (type, yylval.ttype);
1782 TREE_OVERFLOW (yylval.ttype)
1783 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1786 TREE_TYPE (yylval.ttype) = type;
1792 if (isalnum (c) || c == '.' || c == '_' || c == '$'
1793 || (!flag_traditional && (c == '-' || c == '+')
1794 && (p[-1] == 'e' || p[-1] == 'E')))
1795 error ("missing white space after number `%s'", token_buffer);
1797 value = CONSTANT; break;
1803 register int result = 0;
1804 register int num_chars = 0;
1805 unsigned width = TYPE_PRECISION (char_type_node);
1810 width = WCHAR_TYPE_SIZE;
1811 #ifdef MULTIBYTE_CHARS
1812 max_chars = MB_CUR_MAX;
1818 max_chars = TYPE_PRECISION (integer_type_node) / width;
1826 if (c == '\'' || c == EOF)
1832 c = readescape (&ignore);
1835 if (width < HOST_BITS_PER_INT
1836 && (unsigned) c >= (1 << width))
1837 pedwarn ("escape sequence out of range for character");
1838 #ifdef MAP_CHARACTER
1840 c = MAP_CHARACTER (c);
1846 pedwarn ("ANSI C forbids newline in character constant");
1849 #ifdef MAP_CHARACTER
1851 c = MAP_CHARACTER (c);
1855 if (num_chars > maxtoken - 4)
1856 extend_token_buffer (token_buffer);
1858 token_buffer[num_chars] = c;
1860 /* Merge character into result; ignore excess chars. */
1861 if (num_chars < max_chars + 1)
1863 if (width < HOST_BITS_PER_INT)
1864 result = (result << width) | (c & ((1 << width) - 1));
1870 token_buffer[num_chars + 1] = '\'';
1871 token_buffer[num_chars + 2] = 0;
1874 error ("malformatted character constant");
1875 else if (num_chars == 0)
1876 error ("empty character constant");
1877 else if (num_chars > max_chars)
1879 num_chars = max_chars;
1880 error ("character constant too long");
1882 else if (num_chars != 1 && ! flag_traditional)
1883 warning ("multi-character character constant");
1885 /* If char type is signed, sign-extend the constant. */
1888 int num_bits = num_chars * width;
1890 /* We already got an error; avoid invalid shift. */
1891 yylval.ttype = build_int_2 (0, 0);
1892 else if (TREE_UNSIGNED (char_type_node)
1893 || ((result >> (num_bits - 1)) & 1) == 0)
1895 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1896 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1900 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1901 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1903 TREE_TYPE (yylval.ttype) = integer_type_node;
1907 #ifdef MULTIBYTE_CHARS
1908 /* Set the initial shift state and convert the next sequence. */
1910 /* In all locales L'\0' is zero and mbtowc will return zero,
1913 || (num_chars == 1 && token_buffer[1] != '\0'))
1916 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1917 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1920 warning ("Ignoring invalid multibyte character");
1923 yylval.ttype = build_int_2 (result, 0);
1924 TREE_TYPE (yylval.ttype) = wchar_type_node;
1935 p = token_buffer + 1;
1937 while (c != '"' && c >= 0)
1942 c = readescape (&ignore);
1946 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1947 && c >= (1 << TYPE_PRECISION (char_type_node)))
1948 pedwarn ("escape sequence out of range for character");
1953 pedwarn ("ANSI C forbids newline in string constant");
1957 if (p == token_buffer + maxtoken)
1958 p = extend_token_buffer (p);
1967 error ("Unterminated string constant");
1969 /* We have read the entire constant.
1970 Construct a STRING_CST for the result. */
1974 /* If this is a L"..." wide-string, convert the multibyte string
1975 to a wide character string. */
1976 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1979 #ifdef MULTIBYTE_CHARS
1980 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1981 if (len < 0 || len >= (p - token_buffer))
1983 warning ("Ignoring invalid multibyte string");
1986 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1989 union { long l; char c[sizeof (long)]; } u;
1993 /* Determine whether host is little or big endian. */
1995 big_endian = u.c[sizeof (long) - 1];
1996 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1998 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1999 for (cp = token_buffer + 1; cp < p; cp++)
2000 *wp = *cp, wp += WCHAR_BYTES;
2001 len = p - token_buffer - 1;
2004 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
2005 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2010 extern tree build_objc_string();
2011 /* Return an Objective-C @"..." constant string object. */
2012 yylval.ttype = build_objc_string (p - token_buffer,
2014 TREE_TYPE (yylval.ttype) = char_array_type_node;
2015 value = OBJC_STRING;
2019 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
2020 TREE_TYPE (yylval.ttype) = char_array_type_node;
2051 yylval.code = PLUS_EXPR; break;
2053 yylval.code = MINUS_EXPR; break;
2055 yylval.code = BIT_AND_EXPR; break;
2057 yylval.code = BIT_IOR_EXPR; break;
2059 yylval.code = MULT_EXPR; break;
2061 yylval.code = TRUNC_DIV_EXPR; break;
2063 yylval.code = TRUNC_MOD_EXPR; break;
2065 yylval.code = BIT_XOR_EXPR; break;
2067 yylval.code = LSHIFT_EXPR; break;
2069 yylval.code = RSHIFT_EXPR; break;
2071 yylval.code = LT_EXPR; break;
2073 yylval.code = GT_EXPR; break;
2076 token_buffer[1] = c1 = GETC();
2077 token_buffer[2] = 0;
2084 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2086 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2088 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2090 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2092 value = ASSIGN; goto done;
2098 value = PLUSPLUS; goto done;
2100 value = MINUSMINUS; goto done;
2102 value = ANDAND; goto done;
2104 value = OROR; goto done;
2117 { value = POINTSAT; goto done; }
2121 { value = ']'; goto done; }
2125 { value = '{'; goto done; }
2127 { value = '['; goto done; }
2131 { value = '}'; goto done; }
2135 token_buffer[1] = 0;
2137 if ((c == '<') || (c == '>'))
2138 value = ARITHCOMPARE;
2144 /* Don't make yyparse think this is eof. */
2153 /* yylloc.last_line = lineno; */
2158 /* Sets the value of the 'yydebug' variable to VALUE.
2159 This is a function so we don't have to have YYDEBUG defined
2160 in order to build the compiler. */
2169 warning ("YYDEBUG not defined.");