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)
828 /* the beginning of the file is a new line; check for # */
829 /* With luck, we discover the real source file's name from that
830 and put it in input_filename. */
831 UNGETC (check_newline ());
835 #ifdef HANDLE_SYSV_PRAGMA
837 /* Handle a #pragma directive.
838 TOKEN is the token we read after `#pragma'. Processes the entire input
839 line and returns a character for the caller to reread: either \n or EOF. */
841 /* This function has to be in this file, in order to get at
845 handle_sysv_pragma (token)
858 handle_pragma_token (token_buffer, yylval.ttype);
861 handle_pragma_token (token_buffer, 0);
865 c = nextchar, nextchar = -1;
870 while (c == ' ' || c == '\t')
872 if (c == '\n' || c == EOF)
874 handle_pragma_token (0, 0);
882 #endif /* HANDLE_SYSV_PRAGMA */
884 #define ENDFILE -1 /* token that represents end-of-file */
886 /* Read an escape sequence, returning its equivalent as a character,
887 or store 1 in *ignore_ptr if it is backslash-newline. */
890 readescape (ignore_ptr)
893 register int c = GETC();
895 register unsigned count;
896 unsigned firstdig = 0;
902 if (warn_traditional)
903 warning ("the meaning of `\\x' varies with -traditional");
905 if (flag_traditional)
914 if (!(c >= 'a' && c <= 'f')
915 && !(c >= 'A' && c <= 'F')
916 && !(c >= '0' && c <= '9'))
922 if (c >= 'a' && c <= 'f')
923 code += c - 'a' + 10;
924 if (c >= 'A' && c <= 'F')
925 code += c - 'A' + 10;
926 if (c >= '0' && c <= '9')
928 if (code != 0 || count != 0)
937 error ("\\x used with no following hex digits");
939 /* Digits are all 0's. Ok. */
941 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
943 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
945 pedwarn ("hex escape out of range");
948 case '0': case '1': case '2': case '3': case '4':
949 case '5': case '6': case '7':
952 while ((c <= '7') && (c >= '0') && (count++ < 3))
954 code = (code * 8) + (c - '0');
960 case '\\': case '\'': case '"':
969 return TARGET_NEWLINE;
984 if (warn_traditional)
985 warning ("the meaning of `\\a' varies with -traditional");
987 if (flag_traditional)
992 #if 0 /* Vertical tab is present in common usage compilers. */
993 if (flag_traditional)
1001 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1007 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1011 /* `\%' is used to prevent SCCS from getting confused. */
1014 pedwarn ("non-ANSI escape sequence `\\%c'", c);
1017 if (c >= 040 && c < 0177)
1018 pedwarn ("unknown escape sequence `\\%c'", c);
1020 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1030 strcpy (buf, string);
1032 /* We can't print string and character constants well
1033 because the token_buffer contains the result of processing escapes. */
1035 strcat (buf, " at end of input");
1036 else if (token_buffer[0] == 0)
1037 strcat (buf, " at null character");
1038 else if (token_buffer[0] == '"')
1039 strcat (buf, " before string constant");
1040 else if (token_buffer[0] == '\'')
1041 strcat (buf, " before character constant");
1042 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
1043 sprintf (buf + strlen (buf), " before character 0%o",
1044 (unsigned char) token_buffer[0]);
1046 strcat (buf, " before `%s'");
1048 error (buf, token_buffer);
1058 char long_long_flag;
1061 struct try_type type_sequence[] =
1063 { &integer_type_node, 0, 0, 0},
1064 { &unsigned_type_node, 1, 0, 0},
1065 { &long_integer_type_node, 0, 1, 0},
1066 { &long_unsigned_type_node, 1, 1, 0},
1067 { &long_long_integer_type_node, 0, 1, 1},
1068 { &long_long_unsigned_type_node, 1, 1, 1}
1083 c = nextchar, nextchar = -1;
1088 /* Effectively do c = skip_white_space (c)
1089 but do it faster in the usual cases. */
1102 /* Call skip_white_space so we can warn if appropriate. */
1107 c = skip_white_space (c);
1109 goto found_nonwhite;
1113 token_buffer[0] = c;
1114 token_buffer[1] = 0;
1116 /* yylloc.first_line = lineno; */
1122 token_buffer[0] = 0;
1127 /* Capital L may start a wide-string or wide-character constant. */
1129 register int c = GETC();
1138 goto string_constant;
1145 if (!doing_objc_thang)
1152 /* '@' may start a constant string object. */
1153 register int c = GETC ();
1157 goto string_constant;
1160 /* Fall through to treat '@' as the start of an identifier. */
1163 case 'A': case 'B': case 'C': case 'D': case 'E':
1164 case 'F': case 'G': case 'H': case 'I': case 'J':
1165 case 'K': case 'M': case 'N': case 'O':
1166 case 'P': case 'Q': case 'R': case 'S': case 'T':
1167 case 'U': case 'V': case 'W': case 'X': case 'Y':
1169 case 'a': case 'b': case 'c': case 'd': case 'e':
1170 case 'f': case 'g': case 'h': case 'i': case 'j':
1171 case 'k': case 'l': case 'm': case 'n': case 'o':
1172 case 'p': case 'q': case 'r': case 's': case 't':
1173 case 'u': case 'v': case 'w': case 'x': case 'y':
1179 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1181 /* Make sure this char really belongs in an identifier. */
1182 if (c == '@' && ! doing_objc_thang)
1186 if (! dollars_in_ident)
1187 error ("`$' in identifier");
1189 pedwarn ("`$' in identifier");
1192 if (p >= token_buffer + maxtoken)
1193 p = extend_token_buffer (p);
1209 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1212 register struct resword *ptr;
1214 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1217 yylval.ttype = ridpointers[(int) ptr->rid];
1218 value = (int) ptr->token;
1220 /* Only return OBJECTNAME if it is a typedef. */
1221 if (doing_objc_thang && value == OBJECTNAME)
1223 lastiddecl = lookup_name(yylval.ttype);
1225 if (lastiddecl == NULL_TREE
1226 || TREE_CODE (lastiddecl) != TYPE_DECL)
1230 /* Even if we decided to recognize asm, still perhaps warn. */
1232 && (value == ASM_KEYWORD || value == TYPEOF
1233 || ptr->rid == RID_INLINE)
1234 && token_buffer[0] != '_')
1235 pedwarn ("ANSI does not permit the keyword `%s'",
1240 /* If we did not find a keyword, look for an identifier
1243 if (value == IDENTIFIER)
1245 if (token_buffer[0] == '@')
1246 error("invalid identifier `%s'", token_buffer);
1248 yylval.ttype = get_identifier (token_buffer);
1249 lastiddecl = lookup_name (yylval.ttype);
1251 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1253 /* A user-invisible read-only initialized variable
1254 should be replaced by its value.
1255 We handle only strings since that's the only case used in C. */
1256 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1257 && DECL_IGNORED_P (lastiddecl)
1258 && TREE_READONLY (lastiddecl)
1259 && DECL_INITIAL (lastiddecl) != 0
1260 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1262 tree stringval = DECL_INITIAL (lastiddecl);
1264 /* Copy the string value so that we won't clobber anything
1265 if we put something in the TREE_CHAIN of this one. */
1266 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1267 TREE_STRING_POINTER (stringval));
1270 else if (doing_objc_thang)
1272 tree objc_interface_decl = is_class_name (yylval.ttype);
1274 if (objc_interface_decl)
1277 yylval.ttype = objc_interface_decl;
1287 /* Check first for common special case: single-digit 0 or 1. */
1290 UNGETC (next_c); /* Always undo this lookahead. */
1291 if (!isalnum (next_c) && next_c != '.')
1293 token_buffer[0] = (char)c, token_buffer[1] = '\0';
1294 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1300 case '2': case '3': case '4':
1301 case '5': case '6': case '7': case '8': case '9':
1306 int largest_digit = 0;
1308 /* for multi-precision arithmetic,
1309 we actually store only HOST_BITS_PER_CHAR bits in each part.
1310 The number of parts is chosen so as to be sufficient to hold
1311 the enough bits to fit into the two HOST_WIDE_INTs that contain
1312 the integer value (this is always at least as many bits as are
1313 in a target `long long' value, but may be wider). */
1314 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1315 int parts[TOTAL_PARTS];
1318 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1321 for (count = 0; count < TOTAL_PARTS; count++)
1329 *p++ = (c = GETC());
1330 if ((c == 'x') || (c == 'X'))
1333 *p++ = (c = GETC());
1335 /* Leading 0 forces octal unless the 0 is the only digit. */
1336 else if (c >= '0' && c <= '9')
1345 /* Read all the digits-and-decimal-points. */
1348 || (isalnum (c) && c != 'l' && c != 'L'
1349 && c != 'u' && c != 'U'
1350 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1351 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1356 error ("floating constant may not be in radix 16");
1357 if (floatflag == TOO_MANY_POINTS)
1358 /* We have already emitted an error. Don't need another. */
1360 else if (floatflag == AFTER_POINT)
1362 error ("malformed floating constant");
1363 floatflag = TOO_MANY_POINTS;
1364 /* Avoid another error from atof by forcing all characters
1365 from here on to be ignored. */
1369 floatflag = AFTER_POINT;
1373 /* Accept '.' as the start of a floating-point number
1374 only when it is followed by a digit.
1375 Otherwise, unread the following non-digit
1376 and use the '.' as a structural token. */
1377 if (p == token_buffer + 2 && !isdigit (c))
1388 error ("parse error at `..'");
1391 token_buffer[1] = 0;
1398 /* It is not a decimal point.
1399 It should be a digit (perhaps a hex digit). */
1405 else if (base <= 10)
1407 if (c == 'e' || c == 'E')
1410 floatflag = AFTER_POINT;
1411 break; /* start of exponent */
1413 error ("nondigits in number and not hexadecimal");
1424 if (c >= largest_digit)
1428 for (count = 0; count < TOTAL_PARTS; count++)
1430 parts[count] *= base;
1434 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1436 &= (1 << HOST_BITS_PER_CHAR) - 1;
1442 /* If the extra highest-order part ever gets anything in it,
1443 the number is certainly too big. */
1444 if (parts[TOTAL_PARTS - 1] != 0)
1447 if (p >= token_buffer + maxtoken - 3)
1448 p = extend_token_buffer (p);
1449 *p++ = (c = GETC());
1454 error ("numeric constant with no digits");
1456 if (largest_digit >= base)
1457 error ("numeric constant contains digits beyond the radix");
1459 /* Remove terminating char from the token buffer and delimit the string */
1462 if (floatflag != NOT_FLOAT)
1464 tree type = double_type_node;
1465 int exceeds_double = 0;
1467 REAL_VALUE_TYPE value;
1470 /* Read explicit exponent if any, and put it in tokenbuf. */
1472 if ((c == 'e') || (c == 'E'))
1474 if (p >= token_buffer + maxtoken - 3)
1475 p = extend_token_buffer (p);
1478 if ((c == '+') || (c == '-'))
1484 error ("floating constant exponent has no digits");
1487 if (p >= token_buffer + maxtoken - 3)
1488 p = extend_token_buffer (p);
1497 /* Convert string to a double, checking for overflow. */
1498 if (setjmp (handler))
1500 error ("floating constant out of range");
1505 int fflag = 0, lflag = 0;
1506 /* Copy token_buffer now, while it has just the number
1507 and not the suffixes; once we add `f' or `i',
1508 REAL_VALUE_ATOF may not work any more. */
1509 char *copy = (char *) alloca (p - token_buffer + 1);
1510 bcopy (token_buffer, copy, p - token_buffer + 1);
1512 set_float_handler (handler);
1518 /* Read the suffixes to choose a data type. */
1523 error ("more than one `f' in numeric constant");
1529 error ("more than one `l' in numeric constant");
1535 error ("more than one `i' or `j' in numeric constant");
1537 pedwarn ("ANSI C forbids imaginary numeric constants");
1548 if (p >= token_buffer + maxtoken - 3)
1549 p = extend_token_buffer (p);
1555 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1556 tells the desired precision of the binary result
1557 of decimal-to-binary conversion. */
1562 error ("both `f' and `l' in floating constant");
1564 type = float_type_node;
1565 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1566 /* A diagnostic is required here by some ANSI C testsuites.
1567 This is not pedwarn, become some people don't want
1568 an error for this. */
1569 if (REAL_VALUE_ISINF (value) && pedantic)
1570 warning ("floating point number exceeds range of `float'");
1574 type = long_double_type_node;
1575 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1576 if (REAL_VALUE_ISINF (value) && pedantic)
1577 warning ("floating point number exceeds range of `long double'");
1581 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1582 if (REAL_VALUE_ISINF (value) && pedantic)
1583 warning ("floating point number exceeds range of `double'");
1586 set_float_handler (NULL_PTR);
1589 if (errno == ERANGE && !flag_traditional && pedantic)
1591 /* ERANGE is also reported for underflow,
1592 so test the value to distinguish overflow from that. */
1593 if (REAL_VALUES_LESS (dconst1, value)
1594 || REAL_VALUES_LESS (value, dconstm1))
1596 warning ("floating point number exceeds range of `double'");
1602 /* If the result is not a number, assume it must have been
1603 due to some error message above, so silently convert
1605 if (REAL_VALUE_ISNAN (value))
1608 /* Create a node with determined type and value. */
1610 yylval.ttype = build_complex (NULL_TREE,
1611 convert (type, integer_zero_node),
1612 build_real (type, value));
1614 yylval.ttype = build_real (type, value);
1618 tree traditional_type, ansi_type, type;
1619 HOST_WIDE_INT high, low;
1620 int spec_unsigned = 0;
1622 int spec_long_long = 0;
1628 if (c == 'u' || c == 'U')
1631 error ("two `u's in integer constant");
1634 else if (c == 'l' || c == 'L')
1639 error ("three `l's in integer constant");
1641 pedwarn ("ANSI C forbids long long integer constants");
1646 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1649 error ("more than one `i' or `j' in numeric constant");
1651 pedwarn ("ANSI C forbids imaginary numeric constants");
1656 if (p >= token_buffer + maxtoken - 3)
1657 p = extend_token_buffer (p);
1662 /* If the constant is not long long and it won't fit in an
1663 unsigned long, or if the constant is long long and won't fit
1664 in an unsigned long long, then warn that the constant is out
1667 /* ??? This assumes that long long and long integer types are
1668 a multiple of 8 bits. This better than the original code
1669 though which assumed that long was exactly 32 bits and long
1670 long was exactly 64 bits. */
1673 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1675 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1678 for (i = bytes; i < TOTAL_PARTS; i++)
1682 pedwarn ("integer constant out of range");
1684 /* This is simplified by the fact that our constant
1685 is always positive. */
1689 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1691 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1692 / HOST_BITS_PER_CHAR)]
1693 << (i * HOST_BITS_PER_CHAR));
1694 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1697 yylval.ttype = build_int_2 (low, high);
1698 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1700 /* If warn_traditional, calculate both the ANSI type and the
1701 traditional type, then see if they disagree.
1702 Otherwise, calculate only the type for the dialect in use. */
1703 if (warn_traditional || flag_traditional)
1705 /* Calculate the traditional type. */
1706 /* Traditionally, any constant is signed;
1707 but if unsigned is specified explicitly, obey that.
1708 Use the smallest size with the right number of bits,
1709 except for one special case with decimal constants. */
1710 if (! spec_long && base != 10
1711 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1712 traditional_type = (spec_unsigned ? unsigned_type_node
1713 : integer_type_node);
1714 /* A decimal constant must be long
1715 if it does not fit in type int.
1716 I think this is independent of whether
1717 the constant is signed. */
1718 else if (! spec_long && base == 10
1719 && int_fits_type_p (yylval.ttype, integer_type_node))
1720 traditional_type = (spec_unsigned ? unsigned_type_node
1721 : integer_type_node);
1722 else if (! spec_long_long)
1723 traditional_type = (spec_unsigned ? long_unsigned_type_node
1724 : long_integer_type_node);
1726 traditional_type = (spec_unsigned
1727 ? long_long_unsigned_type_node
1728 : long_long_integer_type_node);
1730 if (warn_traditional || ! flag_traditional)
1732 /* Calculate the ANSI type. */
1733 if (! spec_long && ! spec_unsigned
1734 && int_fits_type_p (yylval.ttype, integer_type_node))
1735 ansi_type = integer_type_node;
1736 else if (! spec_long && (base != 10 || spec_unsigned)
1737 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1738 ansi_type = unsigned_type_node;
1739 else if (! spec_unsigned && !spec_long_long
1740 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1741 ansi_type = long_integer_type_node;
1742 else if (! spec_long_long)
1743 ansi_type = long_unsigned_type_node;
1744 else if (! spec_unsigned
1745 /* Verify value does not overflow into sign bit. */
1746 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
1747 && int_fits_type_p (yylval.ttype,
1748 long_long_integer_type_node))
1749 ansi_type = long_long_integer_type_node;
1751 ansi_type = long_long_unsigned_type_node;
1754 type = flag_traditional ? traditional_type : ansi_type;
1756 if (warn_traditional && traditional_type != ansi_type)
1758 if (TYPE_PRECISION (traditional_type)
1759 != TYPE_PRECISION (ansi_type))
1760 warning ("width of integer constant changes with -traditional");
1761 else if (TREE_UNSIGNED (traditional_type)
1762 != TREE_UNSIGNED (ansi_type))
1763 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1765 warning ("width of integer constant may change on other systems with -traditional");
1768 if (!flag_traditional && !int_fits_type_p (yylval.ttype, type)
1770 pedwarn ("integer constant out of range");
1772 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1773 warning ("decimal constant is so large that it is unsigned");
1777 if (TYPE_PRECISION (type)
1778 <= TYPE_PRECISION (integer_type_node))
1780 = build_complex (NULL_TREE, integer_zero_node,
1781 convert (integer_type_node,
1784 error ("complex integer constant is too wide for `complex int'");
1786 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1787 /* The traditional constant 0x80000000 is signed
1788 but doesn't fit in the range of int.
1789 This will change it to -0x80000000, which does fit. */
1791 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1792 yylval.ttype = convert (type, yylval.ttype);
1793 TREE_OVERFLOW (yylval.ttype)
1794 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1797 TREE_TYPE (yylval.ttype) = type;
1803 if (isalnum (c) || c == '.' || c == '_' || c == '$'
1804 || (!flag_traditional && (c == '-' || c == '+')
1805 && (p[-1] == 'e' || p[-1] == 'E')))
1806 error ("missing white space after number `%s'", token_buffer);
1808 value = CONSTANT; break;
1814 register int result = 0;
1815 register int num_chars = 0;
1816 unsigned width = TYPE_PRECISION (char_type_node);
1821 width = WCHAR_TYPE_SIZE;
1822 #ifdef MULTIBYTE_CHARS
1823 max_chars = MB_CUR_MAX;
1829 max_chars = TYPE_PRECISION (integer_type_node) / width;
1837 if (c == '\'' || c == EOF)
1843 c = readescape (&ignore);
1846 if (width < HOST_BITS_PER_INT
1847 && (unsigned) c >= (1 << width))
1848 pedwarn ("escape sequence out of range for character");
1849 #ifdef MAP_CHARACTER
1851 c = MAP_CHARACTER (c);
1857 pedwarn ("ANSI C forbids newline in character constant");
1860 #ifdef MAP_CHARACTER
1862 c = MAP_CHARACTER (c);
1866 if (num_chars > maxtoken - 4)
1867 extend_token_buffer (token_buffer);
1869 token_buffer[num_chars] = c;
1871 /* Merge character into result; ignore excess chars. */
1872 if (num_chars < max_chars + 1)
1874 if (width < HOST_BITS_PER_INT)
1875 result = (result << width) | (c & ((1 << width) - 1));
1881 token_buffer[num_chars + 1] = '\'';
1882 token_buffer[num_chars + 2] = 0;
1885 error ("malformatted character constant");
1886 else if (num_chars == 0)
1887 error ("empty character constant");
1888 else if (num_chars > max_chars)
1890 num_chars = max_chars;
1891 error ("character constant too long");
1893 else if (num_chars != 1 && ! flag_traditional)
1894 warning ("multi-character character constant");
1896 /* If char type is signed, sign-extend the constant. */
1899 int num_bits = num_chars * width;
1901 /* We already got an error; avoid invalid shift. */
1902 yylval.ttype = build_int_2 (0, 0);
1903 else if (TREE_UNSIGNED (char_type_node)
1904 || ((result >> (num_bits - 1)) & 1) == 0)
1906 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1907 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1911 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1912 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1914 TREE_TYPE (yylval.ttype) = integer_type_node;
1918 #ifdef MULTIBYTE_CHARS
1919 /* Set the initial shift state and convert the next sequence. */
1921 /* In all locales L'\0' is zero and mbtowc will return zero,
1924 || (num_chars == 1 && token_buffer[1] != '\0'))
1927 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1928 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1931 warning ("Ignoring invalid multibyte character");
1934 yylval.ttype = build_int_2 (result, 0);
1935 TREE_TYPE (yylval.ttype) = wchar_type_node;
1946 p = token_buffer + 1;
1948 while (c != '"' && c >= 0)
1953 c = readescape (&ignore);
1957 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1958 && c >= (1 << TYPE_PRECISION (char_type_node)))
1959 pedwarn ("escape sequence out of range for character");
1964 pedwarn ("ANSI C forbids newline in string constant");
1968 if (p == token_buffer + maxtoken)
1969 p = extend_token_buffer (p);
1978 error ("Unterminated string constant");
1980 /* We have read the entire constant.
1981 Construct a STRING_CST for the result. */
1985 /* If this is a L"..." wide-string, convert the multibyte string
1986 to a wide character string. */
1987 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1990 #ifdef MULTIBYTE_CHARS
1991 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1992 if (len < 0 || len >= (p - token_buffer))
1994 warning ("Ignoring invalid multibyte string");
1997 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
2000 union { long l; char c[sizeof (long)]; } u;
2004 /* Determine whether host is little or big endian. */
2006 big_endian = u.c[sizeof (long) - 1];
2007 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
2009 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
2010 for (cp = token_buffer + 1; cp < p; cp++)
2011 *wp = *cp, wp += WCHAR_BYTES;
2012 len = p - token_buffer - 1;
2015 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
2016 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2021 extern tree build_objc_string();
2022 /* Return an Objective-C @"..." constant string object. */
2023 yylval.ttype = build_objc_string (p - token_buffer,
2025 TREE_TYPE (yylval.ttype) = char_array_type_node;
2026 value = OBJC_STRING;
2030 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
2031 TREE_TYPE (yylval.ttype) = char_array_type_node;
2062 yylval.code = PLUS_EXPR; break;
2064 yylval.code = MINUS_EXPR; break;
2066 yylval.code = BIT_AND_EXPR; break;
2068 yylval.code = BIT_IOR_EXPR; break;
2070 yylval.code = MULT_EXPR; break;
2072 yylval.code = TRUNC_DIV_EXPR; break;
2074 yylval.code = TRUNC_MOD_EXPR; break;
2076 yylval.code = BIT_XOR_EXPR; break;
2078 yylval.code = LSHIFT_EXPR; break;
2080 yylval.code = RSHIFT_EXPR; break;
2082 yylval.code = LT_EXPR; break;
2084 yylval.code = GT_EXPR; break;
2087 token_buffer[1] = c1 = GETC();
2088 token_buffer[2] = 0;
2095 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2097 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2099 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2101 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2103 value = ASSIGN; goto done;
2109 value = PLUSPLUS; goto done;
2111 value = MINUSMINUS; goto done;
2113 value = ANDAND; goto done;
2115 value = OROR; goto done;
2128 { value = POINTSAT; goto done; }
2132 { value = ']'; goto done; }
2136 { value = '{'; goto done; }
2138 { value = '['; goto done; }
2142 { value = '}'; goto done; }
2146 token_buffer[1] = 0;
2148 if ((c == '<') || (c == '>'))
2149 value = ARITHCOMPARE;
2155 /* Don't make yyparse think this is eof. */
2164 /* yylloc.last_line = lineno; */
2169 /* Sets the value of the 'yydebug' variable to VALUE.
2170 This is a function so we don't have to have YYDEBUG defined
2171 in order to build the compiler. */
2180 warning ("YYDEBUG not defined.");