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. */
36 #ifdef MULTIBYTE_CHARS
40 #ifndef GET_ENVIRONMENT
41 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME))
43 #endif /* MULTIBYTE_CHARS */
47 extern cpp_reader parse_in;
48 extern cpp_options parse_options;
50 /* Stream for reading from the input file. */
54 extern void yyprint PROTO((FILE *, int, YYSTYPE));
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 extern unsigned char *yy_cur, *yy_lim;
67 extern int yy_get_token ();
69 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
70 #define UNGETC(c) ((c), yy_cur--)
72 #define GETC() getc (finput)
73 #define UNGETC(c) ungetc (c, finput)
76 /* the declaration found for the last IDENTIFIER token read in.
77 yylex must look this up to detect typedefs, which get token type TYPENAME,
78 so it is left around in case the identifier is not a typedef but is
79 used in a context which makes it a reference to a variable. */
82 /* Nonzero enables objc features. */
88 /* File used for outputting assembler code. */
89 extern FILE *asm_out_file;
91 #ifndef WCHAR_TYPE_SIZE
93 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
95 #define WCHAR_TYPE_SIZE BITS_PER_WORD
99 /* Number of bytes in a wide character. */
100 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
102 static int maxtoken; /* Current nominal length of token buffer. */
103 char *token_buffer; /* Pointer to token buffer.
104 Actual allocated length is maxtoken + 2.
105 This is not static because objc-parse.y uses it. */
107 static int indent_level = 0; /* Number of { minus number of }. */
109 /* Nonzero if end-of-file has been seen on input. */
110 static int end_of_file;
113 /* Buffered-back input character; faster than using ungetc. */
114 static int nextchar = -1;
117 #ifdef HANDLE_SYSV_PRAGMA
118 static int handle_sysv_pragma PROTO((int));
119 #endif /* HANDLE_SYSV_PRAGMA */
120 static int whitespace_cr PROTO((int));
121 static int skip_white_space PROTO((int));
122 static int skip_white_space_on_line PROTO((void));
123 static char *extend_token_buffer PROTO((char *));
124 static int readescape PROTO((int *));
126 /* Do not insert generated code into the source, instead, include it.
127 This allows us to build gcc automatically even for targets that
128 need to add or modify the reserved keyword lists. */
131 /* Return something to represent absolute declarators containing a *.
132 TARGET is the absolute declarator that the * contains.
133 TYPE_QUALS is a list of modifiers such as const or volatile
134 to apply to the pointer type, represented as identifiers.
136 We return an INDIRECT_REF whose "contents" are TARGET
137 and whose type is the modifier list. */
140 make_pointer_declarator (type_quals, target)
141 tree type_quals, target;
143 return build1 (INDIRECT_REF, type_quals, target);
147 forget_protocol_qualifiers ()
149 int i, n = sizeof wordlist / sizeof (struct resword);
151 for (i = 0; i < n; i++)
152 if ((int) wordlist[i].rid >= (int) RID_IN
153 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
154 wordlist[i].name = "";
158 remember_protocol_qualifiers ()
160 int i, n = sizeof wordlist / sizeof (struct resword);
162 for (i = 0; i < n; i++)
163 if (wordlist[i].rid == RID_IN)
164 wordlist[i].name = "in";
165 else if (wordlist[i].rid == RID_OUT)
166 wordlist[i].name = "out";
167 else if (wordlist[i].rid == RID_INOUT)
168 wordlist[i].name = "inout";
169 else if (wordlist[i].rid == RID_BYCOPY)
170 wordlist[i].name = "bycopy";
171 else if (wordlist[i].rid == RID_ONEWAY)
172 wordlist[i].name = "oneway";
176 init_parse (filename)
180 /* Open input file. */
181 if (filename == 0 || !strcmp (filename, "-"))
187 finput = fopen (filename, "r");
189 pfatal_with_name (filename);
191 #ifdef IO_BUFFER_SIZE
192 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
194 #endif /* !USE_CPPLIB */
202 parse_in.show_column = 1;
203 if (! cpp_start_read (&parse_in, filename))
214 cpp_finish (&parse_in);
223 /* Make identifier nodes long enough for the language-specific slots. */
224 set_identifier_size (sizeof (struct lang_identifier));
226 /* Start it at 0, because check_newline is called at the very beginning
227 and will increment it to 1. */
230 #ifdef MULTIBYTE_CHARS
231 /* Change to the native locale for multibyte conversions. */
232 setlocale (LC_CTYPE, "");
233 GET_ENVIRONMENT (literal_codeset, "LANG");
237 token_buffer = (char *) xmalloc (maxtoken + 2);
239 ridpointers[(int) RID_INT] = get_identifier ("int");
240 ridpointers[(int) RID_CHAR] = get_identifier ("char");
241 ridpointers[(int) RID_VOID] = get_identifier ("void");
242 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
243 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
244 ridpointers[(int) RID_SHORT] = get_identifier ("short");
245 ridpointers[(int) RID_LONG] = get_identifier ("long");
246 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
247 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
248 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
249 ridpointers[(int) RID_CONST] = get_identifier ("const");
250 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
251 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
252 ridpointers[(int) RID_STATIC] = get_identifier ("static");
253 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
254 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
255 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
256 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
257 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
258 ridpointers[(int) RID_ID] = get_identifier ("id");
259 ridpointers[(int) RID_IN] = get_identifier ("in");
260 ridpointers[(int) RID_OUT] = get_identifier ("out");
261 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
262 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
263 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
264 forget_protocol_qualifiers();
266 /* Some options inhibit certain reserved words.
267 Clear those words out of the hash table so they won't be recognized. */
268 #define UNSET_RESERVED_WORD(STRING) \
269 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
270 if (s) s->name = ""; } while (0)
272 if (! doing_objc_thang)
273 UNSET_RESERVED_WORD ("id");
275 if (flag_traditional)
277 UNSET_RESERVED_WORD ("const");
278 UNSET_RESERVED_WORD ("volatile");
279 UNSET_RESERVED_WORD ("typeof");
280 UNSET_RESERVED_WORD ("signed");
281 UNSET_RESERVED_WORD ("inline");
282 UNSET_RESERVED_WORD ("iterator");
283 UNSET_RESERVED_WORD ("complex");
287 UNSET_RESERVED_WORD ("asm");
288 UNSET_RESERVED_WORD ("typeof");
289 UNSET_RESERVED_WORD ("inline");
290 UNSET_RESERVED_WORD ("iterator");
291 UNSET_RESERVED_WORD ("complex");
296 reinit_parse_for_function ()
300 /* Function used when yydebug is set, to print a token in more detail. */
303 yyprint (file, yychar, yylval)
315 if (IDENTIFIER_POINTER (t))
316 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
321 if (TREE_CODE (t) == INTEGER_CST)
323 #if HOST_BITS_PER_WIDE_INT == 64
324 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
327 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
334 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
340 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
345 /* Iff C is a carriage return, warn about it - if appropriate -
346 and return nonzero. */
351 static int newline_warning = 0;
355 /* ANSI C says the effects of a carriage return in a source file
357 if (pedantic && !newline_warning)
359 warning ("carriage return in source file");
360 warning ("(we only warn about the first carriage return)");
368 /* If C is not whitespace, return C.
369 Otherwise skip whitespace and return first nonwhite char read. */
379 /* We don't recognize comments here, because
380 cpp output can include / and * consecutively as operators.
381 Also, there's no need, since cpp removes all comments. */
384 c = check_newline ();
405 error ("stray '\\' in program");
415 /* Skips all of the white space at the current location in the input file.
416 Must use and reset nextchar if it has the next character. */
419 position_after_white_space ()
425 c = nextchar, nextchar = -1;
430 UNGETC (skip_white_space (c));
433 /* Like skip_white_space, but don't advance beyond the end of line.
434 Moreover, we don't get passed a character to start with. */
436 skip_white_space_on_line ()
465 /* Make the token buffer longer, preserving the data in it.
466 P should point to just beyond the last valid character in the old buffer.
467 The value we return is a pointer to the new buffer
468 at a place corresponding to P. */
471 extend_token_buffer (p)
474 int offset = p - token_buffer;
476 maxtoken = maxtoken * 2 + 10;
477 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
479 return token_buffer + offset;
482 /* At the beginning of a line, increment the line number
483 and process any #-directive on this line.
484 If the line is a #-directive, read the entire line and return a newline.
485 Otherwise, return the line's first non-whitespace character. */
495 /* Read first nonwhite char on the line. */
498 while (c == ' ' || c == '\t')
503 /* If not #, return it so caller will use it. */
507 /* Read first nonwhite char after the `#'. */
510 while (c == ' ' || c == '\t')
513 /* If a letter follows, then if the word here is `line', skip
514 it and ignore it; otherwise, ignore the line, with an error
515 if the word isn't `pragma', `ident', `define', or `undef'. */
517 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
526 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'
527 || whitespace_cr (c) ))
529 while (c == ' ' || c == '\t' || whitespace_cr (c))
533 #ifdef HANDLE_SYSV_PRAGMA
536 if (token != IDENTIFIER)
538 return handle_sysv_pragma (token);
539 #else /* !HANDLE_SYSV_PRAGMA */
544 if (token != IDENTIFIER)
547 c = nextchar, nextchar = -1;
551 if (HANDLE_PRAGMA (finput, yylval.ttype))
557 ??? do not know what to do ???;
558 #endif /* !USE_CPPLIB */
559 #endif /* HANDLE_PRAGMA */
560 #endif /* !HANDLE_SYSV_PRAGMA */
572 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
575 debug_define (lineno, GET_DIRECTIVE_LINE ());
585 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
588 debug_undef (lineno, GET_DIRECTIVE_LINE ());
597 && ((c = GETC()) == ' ' || c == '\t'))
606 && ((c = GETC()) == ' ' || c == '\t'))
608 /* #ident. The pedantic warning is now in cccp.c. */
610 /* Here we have just seen `#ident '.
611 A string constant should follow. */
613 c = skip_white_space_on_line ();
615 /* If no argument, ignore the line. */
622 || TREE_CODE (yylval.ttype) != STRING_CST)
624 error ("invalid #ident");
630 #ifdef ASM_OUTPUT_IDENT
631 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
635 /* Skip the rest of this line. */
640 error ("undefined or invalid # directive");
645 /* Here we have either `#line' or `# <nonletter>'.
646 In either case, it should be a line number; a digit should follow. */
648 /* Can't use skip_white_space here, but must handle all whitespace
649 that is not '\n', lest we get a recursion for '\r' '\n' when
652 c = skip_white_space_on_line ();
654 /* If the # is the only nonwhite char on the line,
655 just ignore it. Check the new newline. */
659 /* Something follows the #; read a token. */
664 if (token == CONSTANT
665 && TREE_CODE (yylval.ttype) == INTEGER_CST)
667 int old_lineno = lineno;
669 /* subtract one, because it is the following line that
670 gets the specified number */
672 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
674 /* Is this the last nonwhite stuff on the line? */
675 c = skip_white_space_on_line ();
678 /* No more: store the line number and check following line. */
684 /* More follows: it must be a string constant (filename). */
686 /* Read the string constant. */
689 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
691 error ("invalid #line");
696 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
697 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
700 /* Each change of file name
701 reinitializes whether we are now in a system header. */
702 in_system_header = 0;
704 if (main_input_filename == 0)
705 main_input_filename = input_filename;
707 /* Is this the last nonwhite stuff on the line? */
708 c = skip_white_space_on_line ();
711 /* Update the name in the top element of input_file_stack. */
712 if (input_file_stack)
713 input_file_stack->name = input_filename;
722 /* `1' after file name means entering new file.
723 `2' after file name means just left a file. */
725 if (token == CONSTANT
726 && TREE_CODE (yylval.ttype) == INTEGER_CST)
728 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
730 /* Pushing to a new file. */
732 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
733 input_file_stack->line = old_lineno;
734 p->next = input_file_stack;
735 p->name = input_filename;
736 p->indent_level = indent_level;
737 input_file_stack = p;
738 input_file_stack_tick++;
739 debug_start_source_file (input_filename);
742 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
744 /* Popping out of a file. */
745 if (input_file_stack->next)
747 struct file_stack *p = input_file_stack;
748 if (indent_level != p->indent_level)
750 warning_with_file_and_line
751 (p->name, old_lineno,
752 "This file contains more `%c's than `%c's.",
753 indent_level > p->indent_level ? '{' : '}',
754 indent_level > p->indent_level ? '}' : '{');
756 input_file_stack = p->next;
758 input_file_stack_tick++;
759 debug_end_source_file (input_file_stack->line);
762 error ("#-lines for entering and leaving files don't match");
768 /* Now that we've pushed or popped the input stack,
769 update the name in the top element. */
770 if (input_file_stack)
771 input_file_stack->name = input_filename;
773 /* If we have handled a `1' or a `2',
774 see if there is another number to read. */
777 /* Is this the last nonwhite stuff on the line? */
778 c = skip_white_space_on_line ();
787 /* `3' after file name means this is a system header file. */
789 if (token == CONSTANT
790 && TREE_CODE (yylval.ttype) == INTEGER_CST
791 && TREE_INT_CST_LOW (yylval.ttype) == 3)
792 in_system_header = 1, used_up = 1;
796 /* Is this the last nonwhite stuff on the line? */
797 c = skip_white_space_on_line ();
803 warning ("unrecognized text at end of #line");
806 error ("invalid #-line");
808 /* skip the rest of this line. */
811 if (c != '\n' && c != EOF && nextchar >= 0)
812 c = nextchar, nextchar = -1;
814 while (c != '\n' && c != EOF)
819 #ifdef HANDLE_SYSV_PRAGMA
821 /* Handle a #pragma directive.
822 TOKEN is the token we read after `#pragma'. Processes the entire input
823 line and returns a character for the caller to reread: either \n or EOF. */
825 /* This function has to be in this file, in order to get at
829 handle_sysv_pragma (token)
842 handle_pragma_token (token_buffer, yylval.ttype);
845 handle_pragma_token (token_buffer, 0);
849 c = nextchar, nextchar = -1;
854 while (c == ' ' || c == '\t')
856 if (c == '\n' || c == EOF)
858 handle_pragma_token (0, 0);
866 #endif /* HANDLE_SYSV_PRAGMA */
868 #define ENDFILE -1 /* token that represents end-of-file */
870 /* Read an escape sequence, returning its equivalent as a character,
871 or store 1 in *ignore_ptr if it is backslash-newline. */
874 readescape (ignore_ptr)
877 register int c = GETC();
879 register unsigned count;
880 unsigned firstdig = 0;
886 if (warn_traditional)
887 warning ("the meaning of `\\x' varies with -traditional");
889 if (flag_traditional)
898 if (!(c >= 'a' && c <= 'f')
899 && !(c >= 'A' && c <= 'F')
900 && !(c >= '0' && c <= '9'))
906 if (c >= 'a' && c <= 'f')
907 code += c - 'a' + 10;
908 if (c >= 'A' && c <= 'F')
909 code += c - 'A' + 10;
910 if (c >= '0' && c <= '9')
912 if (code != 0 || count != 0)
921 error ("\\x used with no following hex digits");
923 /* Digits are all 0's. Ok. */
925 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
927 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
929 pedwarn ("hex escape out of range");
932 case '0': case '1': case '2': case '3': case '4':
933 case '5': case '6': case '7':
936 while ((c <= '7') && (c >= '0') && (count++ < 3))
938 code = (code * 8) + (c - '0');
944 case '\\': case '\'': case '"':
953 return TARGET_NEWLINE;
968 if (warn_traditional)
969 warning ("the meaning of `\\a' varies with -traditional");
971 if (flag_traditional)
976 #if 0 /* Vertical tab is present in common usage compilers. */
977 if (flag_traditional)
985 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
991 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
995 /* `\%' is used to prevent SCCS from getting confused. */
998 pedwarn ("non-ANSI escape sequence `\\%c'", c);
1001 if (c >= 040 && c < 0177)
1002 pedwarn ("unknown escape sequence `\\%c'", c);
1004 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1014 strcpy (buf, string);
1016 /* We can't print string and character constants well
1017 because the token_buffer contains the result of processing escapes. */
1019 strcat (buf, " at end of input");
1020 else if (token_buffer[0] == 0)
1021 strcat (buf, " at null character");
1022 else if (token_buffer[0] == '"')
1023 strcat (buf, " before string constant");
1024 else if (token_buffer[0] == '\'')
1025 strcat (buf, " before character constant");
1026 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
1027 sprintf (buf + strlen (buf), " before character 0%o",
1028 (unsigned char) token_buffer[0]);
1030 strcat (buf, " before `%s'");
1032 error (buf, token_buffer);
1042 char long_long_flag;
1045 struct try_type type_sequence[] =
1047 { &integer_type_node, 0, 0, 0},
1048 { &unsigned_type_node, 1, 0, 0},
1049 { &long_integer_type_node, 0, 1, 0},
1050 { &long_unsigned_type_node, 1, 1, 0},
1051 { &long_long_integer_type_node, 0, 1, 1},
1052 { &long_long_unsigned_type_node, 1, 1, 1}
1067 c = nextchar, nextchar = -1;
1072 /* Effectively do c = skip_white_space (c)
1073 but do it faster in the usual cases. */
1086 /* Call skip_white_space so we can warn if appropriate. */
1091 c = skip_white_space (c);
1093 goto found_nonwhite;
1097 token_buffer[0] = c;
1098 token_buffer[1] = 0;
1100 /* yylloc.first_line = lineno; */
1106 token_buffer[0] = 0;
1111 /* Capital L may start a wide-string or wide-character constant. */
1113 register int c = GETC();
1122 goto string_constant;
1129 if (!doing_objc_thang)
1136 /* '@' may start a constant string object. */
1137 register int c = GETC ();
1141 goto string_constant;
1144 /* Fall through to treat '@' as the start of an identifier. */
1147 case 'A': case 'B': case 'C': case 'D': case 'E':
1148 case 'F': case 'G': case 'H': case 'I': case 'J':
1149 case 'K': case 'M': case 'N': case 'O':
1150 case 'P': case 'Q': case 'R': case 'S': case 'T':
1151 case 'U': case 'V': case 'W': case 'X': case 'Y':
1153 case 'a': case 'b': case 'c': case 'd': case 'e':
1154 case 'f': case 'g': case 'h': case 'i': case 'j':
1155 case 'k': case 'l': case 'm': case 'n': case 'o':
1156 case 'p': case 'q': case 'r': case 's': case 't':
1157 case 'u': case 'v': case 'w': case 'x': case 'y':
1163 while (ISALNUM (c) || c == '_' || c == '$' || c == '@')
1165 /* Make sure this char really belongs in an identifier. */
1166 if (c == '@' && ! doing_objc_thang)
1170 if (! dollars_in_ident)
1171 error ("`$' in identifier");
1173 pedwarn ("`$' in identifier");
1176 if (p >= token_buffer + maxtoken)
1177 p = extend_token_buffer (p);
1193 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1196 register struct resword *ptr;
1198 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
1201 yylval.ttype = ridpointers[(int) ptr->rid];
1202 value = (int) ptr->token;
1204 /* Only return OBJECTNAME if it is a typedef. */
1205 if (doing_objc_thang && value == OBJECTNAME)
1207 lastiddecl = lookup_name(yylval.ttype);
1209 if (lastiddecl == NULL_TREE
1210 || TREE_CODE (lastiddecl) != TYPE_DECL)
1214 /* Even if we decided to recognize asm, still perhaps warn. */
1216 && (value == ASM_KEYWORD || value == TYPEOF
1217 || ptr->rid == RID_INLINE)
1218 && token_buffer[0] != '_')
1219 pedwarn ("ANSI does not permit the keyword `%s'",
1224 /* If we did not find a keyword, look for an identifier
1227 if (value == IDENTIFIER)
1229 if (token_buffer[0] == '@')
1230 error("invalid identifier `%s'", token_buffer);
1232 yylval.ttype = get_identifier (token_buffer);
1233 lastiddecl = lookup_name (yylval.ttype);
1235 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1237 /* A user-invisible read-only initialized variable
1238 should be replaced by its value.
1239 We handle only strings since that's the only case used in C. */
1240 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1241 && DECL_IGNORED_P (lastiddecl)
1242 && TREE_READONLY (lastiddecl)
1243 && DECL_INITIAL (lastiddecl) != 0
1244 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1246 tree stringval = DECL_INITIAL (lastiddecl);
1248 /* Copy the string value so that we won't clobber anything
1249 if we put something in the TREE_CHAIN of this one. */
1250 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1251 TREE_STRING_POINTER (stringval));
1254 else if (doing_objc_thang)
1256 tree objc_interface_decl = is_class_name (yylval.ttype);
1258 if (objc_interface_decl)
1261 yylval.ttype = objc_interface_decl;
1271 /* Check first for common special case: single-digit 0 or 1. */
1274 UNGETC (next_c); /* Always undo this lookahead. */
1275 if (!ISALNUM (next_c) && next_c != '.')
1277 token_buffer[0] = (char)c, token_buffer[1] = '\0';
1278 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1284 case '2': case '3': case '4':
1285 case '5': case '6': case '7': case '8': case '9':
1290 int largest_digit = 0;
1292 /* for multi-precision arithmetic,
1293 we actually store only HOST_BITS_PER_CHAR bits in each part.
1294 The number of parts is chosen so as to be sufficient to hold
1295 the enough bits to fit into the two HOST_WIDE_INTs that contain
1296 the integer value (this is always at least as many bits as are
1297 in a target `long long' value, but may be wider). */
1298 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1299 int parts[TOTAL_PARTS];
1302 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1305 for (count = 0; count < TOTAL_PARTS; count++)
1313 *p++ = (c = GETC());
1314 if ((c == 'x') || (c == 'X'))
1317 *p++ = (c = GETC());
1319 /* Leading 0 forces octal unless the 0 is the only digit. */
1320 else if (c >= '0' && c <= '9')
1329 /* Read all the digits-and-decimal-points. */
1332 || (ISALNUM (c) && c != 'l' && c != 'L'
1333 && c != 'u' && c != 'U'
1334 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1335 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1340 error ("floating constant may not be in radix 16");
1341 if (floatflag == TOO_MANY_POINTS)
1342 /* We have already emitted an error. Don't need another. */
1344 else if (floatflag == AFTER_POINT)
1346 error ("malformed floating constant");
1347 floatflag = TOO_MANY_POINTS;
1348 /* Avoid another error from atof by forcing all characters
1349 from here on to be ignored. */
1353 floatflag = AFTER_POINT;
1357 /* Accept '.' as the start of a floating-point number
1358 only when it is followed by a digit.
1359 Otherwise, unread the following non-digit
1360 and use the '.' as a structural token. */
1361 if (p == token_buffer + 2 && !ISDIGIT (c))
1372 error ("parse error at `..'");
1375 token_buffer[1] = 0;
1382 /* It is not a decimal point.
1383 It should be a digit (perhaps a hex digit). */
1389 else if (base <= 10)
1391 if (c == 'e' || c == 'E')
1394 floatflag = AFTER_POINT;
1395 break; /* start of exponent */
1397 error ("nondigits in number and not hexadecimal");
1408 if (c >= largest_digit)
1412 for (count = 0; count < TOTAL_PARTS; count++)
1414 parts[count] *= base;
1418 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1420 &= (1 << HOST_BITS_PER_CHAR) - 1;
1426 /* If the extra highest-order part ever gets anything in it,
1427 the number is certainly too big. */
1428 if (parts[TOTAL_PARTS - 1] != 0)
1431 if (p >= token_buffer + maxtoken - 3)
1432 p = extend_token_buffer (p);
1433 *p++ = (c = GETC());
1438 error ("numeric constant with no digits");
1440 if (largest_digit >= base)
1441 error ("numeric constant contains digits beyond the radix");
1443 /* Remove terminating char from the token buffer and delimit the string */
1446 if (floatflag != NOT_FLOAT)
1448 tree type = double_type_node;
1450 int conversion_errno = 0;
1451 REAL_VALUE_TYPE value;
1454 /* Read explicit exponent if any, and put it in tokenbuf. */
1456 if ((c == 'e') || (c == 'E'))
1458 if (p >= token_buffer + maxtoken - 3)
1459 p = extend_token_buffer (p);
1462 if ((c == '+') || (c == '-'))
1468 error ("floating constant exponent has no digits");
1471 if (p >= token_buffer + maxtoken - 3)
1472 p = extend_token_buffer (p);
1480 /* Convert string to a double, checking for overflow. */
1481 if (setjmp (handler))
1483 error ("floating constant out of range");
1488 int fflag = 0, lflag = 0;
1489 /* Copy token_buffer now, while it has just the number
1490 and not the suffixes; once we add `f' or `i',
1491 REAL_VALUE_ATOF may not work any more. */
1492 char *copy = (char *) alloca (p - token_buffer + 1);
1493 bcopy (token_buffer, copy, p - token_buffer + 1);
1495 set_float_handler (handler);
1501 /* Read the suffixes to choose a data type. */
1506 error ("more than one `f' in numeric constant");
1512 error ("more than one `l' in numeric constant");
1518 error ("more than one `i' or `j' in numeric constant");
1520 pedwarn ("ANSI C forbids imaginary numeric constants");
1531 if (p >= token_buffer + maxtoken - 3)
1532 p = extend_token_buffer (p);
1538 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1539 tells the desired precision of the binary result
1540 of decimal-to-binary conversion. */
1545 error ("both `f' and `l' in floating constant");
1547 type = float_type_node;
1549 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1550 conversion_errno = errno;
1551 /* A diagnostic is required here by some ANSI C testsuites.
1552 This is not pedwarn, become some people don't want
1553 an error for this. */
1554 if (REAL_VALUE_ISINF (value) && pedantic)
1555 warning ("floating point number exceeds range of `float'");
1559 type = long_double_type_node;
1561 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1562 conversion_errno = errno;
1563 if (REAL_VALUE_ISINF (value) && pedantic)
1564 warning ("floating point number exceeds range of `long double'");
1569 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1570 conversion_errno = errno;
1571 if (REAL_VALUE_ISINF (value) && pedantic)
1572 warning ("floating point number exceeds range of `double'");
1575 set_float_handler (NULL_PTR);
1578 /* ERANGE is also reported for underflow,
1579 so test the value to distinguish overflow from that. */
1580 if (conversion_errno == ERANGE && !flag_traditional && pedantic
1581 && (REAL_VALUES_LESS (dconst1, value)
1582 || REAL_VALUES_LESS (value, dconstm1)))
1583 warning ("floating point number exceeds range of `double'");
1586 /* If the result is not a number, assume it must have been
1587 due to some error message above, so silently convert
1589 if (REAL_VALUE_ISNAN (value))
1592 /* Create a node with determined type and value. */
1594 yylval.ttype = build_complex (NULL_TREE,
1595 convert (type, integer_zero_node),
1596 build_real (type, value));
1598 yylval.ttype = build_real (type, value);
1602 tree traditional_type, ansi_type, type;
1603 HOST_WIDE_INT high, low;
1604 int spec_unsigned = 0;
1606 int spec_long_long = 0;
1610 traditional_type = ansi_type = type = NULL_TREE;
1613 if (c == 'u' || c == 'U')
1616 error ("two `u's in integer constant");
1619 else if (c == 'l' || c == 'L')
1624 error ("three `l's in integer constant");
1626 pedwarn ("ANSI C forbids long long integer constants");
1631 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1634 error ("more than one `i' or `j' in numeric constant");
1636 pedwarn ("ANSI C forbids imaginary numeric constants");
1641 if (p >= token_buffer + maxtoken - 3)
1642 p = extend_token_buffer (p);
1647 /* If the constant won't fit in an unsigned long long,
1648 then warn that the constant is out of range. */
1650 /* ??? This assumes that long long and long integer types are
1651 a multiple of 8 bits. This better than the original code
1652 though which assumed that long was exactly 32 bits and long
1653 long was exactly 64 bits. */
1655 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1658 for (i = bytes; i < TOTAL_PARTS; i++)
1662 pedwarn ("integer constant out of range");
1664 /* This is simplified by the fact that our constant
1665 is always positive. */
1669 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1671 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1672 / HOST_BITS_PER_CHAR)]
1673 << (i * HOST_BITS_PER_CHAR));
1674 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1677 yylval.ttype = build_int_2 (low, high);
1678 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1680 /* If warn_traditional, calculate both the ANSI type and the
1681 traditional type, then see if they disagree.
1682 Otherwise, calculate only the type for the dialect in use. */
1683 if (warn_traditional || flag_traditional)
1685 /* Calculate the traditional type. */
1686 /* Traditionally, any constant is signed;
1687 but if unsigned is specified explicitly, obey that.
1688 Use the smallest size with the right number of bits,
1689 except for one special case with decimal constants. */
1690 if (! spec_long && base != 10
1691 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1692 traditional_type = (spec_unsigned ? unsigned_type_node
1693 : integer_type_node);
1694 /* A decimal constant must be long
1695 if it does not fit in type int.
1696 I think this is independent of whether
1697 the constant is signed. */
1698 else if (! spec_long && base == 10
1699 && int_fits_type_p (yylval.ttype, integer_type_node))
1700 traditional_type = (spec_unsigned ? unsigned_type_node
1701 : integer_type_node);
1702 else if (! spec_long_long)
1703 traditional_type = (spec_unsigned ? long_unsigned_type_node
1704 : long_integer_type_node);
1706 traditional_type = (spec_unsigned
1707 ? long_long_unsigned_type_node
1708 : long_long_integer_type_node);
1710 if (warn_traditional || ! flag_traditional)
1712 /* Calculate the ANSI type. */
1713 if (! spec_long && ! spec_unsigned
1714 && int_fits_type_p (yylval.ttype, integer_type_node))
1715 ansi_type = integer_type_node;
1716 else if (! spec_long && (base != 10 || spec_unsigned)
1717 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1718 ansi_type = unsigned_type_node;
1719 else if (! spec_unsigned && !spec_long_long
1720 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1721 ansi_type = long_integer_type_node;
1722 else if (! spec_long_long
1723 && int_fits_type_p (yylval.ttype,
1724 long_unsigned_type_node))
1725 ansi_type = long_unsigned_type_node;
1726 else if (! spec_unsigned
1727 && int_fits_type_p (yylval.ttype,
1728 long_long_integer_type_node))
1729 ansi_type = long_long_integer_type_node;
1731 ansi_type = long_long_unsigned_type_node;
1734 type = flag_traditional ? traditional_type : ansi_type;
1736 if (warn_traditional && traditional_type != ansi_type)
1738 if (TYPE_PRECISION (traditional_type)
1739 != TYPE_PRECISION (ansi_type))
1740 warning ("width of integer constant changes with -traditional");
1741 else if (TREE_UNSIGNED (traditional_type)
1742 != TREE_UNSIGNED (ansi_type))
1743 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1745 warning ("width of integer constant may change on other systems with -traditional");
1748 if (pedantic && !flag_traditional && !spec_long_long && !warn
1749 && (TYPE_PRECISION (long_integer_type_node)
1750 < TYPE_PRECISION (type)))
1751 pedwarn ("integer constant out of range");
1753 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1754 warning ("decimal constant is so large that it is unsigned");
1758 if (TYPE_PRECISION (type)
1759 <= TYPE_PRECISION (integer_type_node))
1761 = build_complex (NULL_TREE, integer_zero_node,
1762 convert (integer_type_node,
1765 error ("complex integer constant is too wide for `complex int'");
1767 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1768 /* The traditional constant 0x80000000 is signed
1769 but doesn't fit in the range of int.
1770 This will change it to -0x80000000, which does fit. */
1772 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1773 yylval.ttype = convert (type, yylval.ttype);
1774 TREE_OVERFLOW (yylval.ttype)
1775 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1778 TREE_TYPE (yylval.ttype) = type;
1784 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
1785 || (!flag_traditional && (c == '-' || c == '+')
1786 && (p[-1] == 'e' || p[-1] == 'E')))
1787 error ("missing white space after number `%s'", token_buffer);
1789 value = CONSTANT; break;
1795 register int result = 0;
1796 register int num_chars = 0;
1798 unsigned width = TYPE_PRECISION (char_type_node);
1800 #ifdef MULTIBYTE_CHARS
1801 int longest_char = local_mb_cur_max ();
1802 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
1805 max_chars = TYPE_PRECISION (integer_type_node) / width;
1807 width = WCHAR_TYPE_SIZE;
1814 if (c == '\'' || c == EOF)
1821 c = readescape (&ignore);
1824 if (width < HOST_BITS_PER_INT
1825 && (unsigned) c >= (1 << width))
1826 pedwarn ("escape sequence out of range for character");
1827 #ifdef MAP_CHARACTER
1829 c = MAP_CHARACTER (c);
1835 pedwarn ("ANSI C forbids newline in character constant");
1840 #ifdef MULTIBYTE_CHARS
1844 for (i = 1; i <= longest_char; ++i)
1846 if (i > maxtoken - 4)
1847 extend_token_buffer (token_buffer);
1849 token_buffer[i] = c;
1850 char_len = local_mbtowc (& wc,
1859 /* mbtowc sometimes needs an extra char before accepting */
1864 /* Merge character into result; ignore excess chars. */
1865 for (i = 1; i <= char_len; ++i)
1869 if (width < HOST_BITS_PER_INT)
1870 result = (result << width)
1872 & ((1 << width) - 1));
1874 result = token_buffer[i];
1876 num_chars += char_len;
1884 warning ("Ignoring invalid multibyte character");
1887 #ifdef MAP_CHARACTER
1889 c = MAP_CHARACTER (c);
1892 #else /* ! MULTIBYTE_CHARS */
1893 #ifdef MAP_CHARACTER
1894 c = MAP_CHARACTER (c);
1896 #endif /* ! MULTIBYTE_CHARS */
1901 if (chars_seen == 1) /* only keep the first one */
1906 /* Merge character into result; ignore excess chars. */
1907 num_chars += (width / TYPE_PRECISION (char_type_node));
1908 if (num_chars < max_chars + 1)
1910 if (width < HOST_BITS_PER_INT)
1911 result = (result << width) | (c & ((1 << width) - 1));
1918 error ("malformatted character constant");
1919 else if (chars_seen == 0)
1920 error ("empty character constant");
1921 else if (num_chars > max_chars)
1923 num_chars = max_chars;
1924 error ("character constant too long");
1926 else if (chars_seen != 1 && ! flag_traditional && warn_multichar)
1927 warning ("multi-character character constant");
1929 /* If char type is signed, sign-extend the constant. */
1932 int num_bits = num_chars * width;
1934 /* We already got an error; avoid invalid shift. */
1935 yylval.ttype = build_int_2 (0, 0);
1936 else if (TREE_UNSIGNED (char_type_node)
1937 || ((result >> (num_bits - 1)) & 1) == 0)
1939 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
1940 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1944 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
1945 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1947 TREE_TYPE (yylval.ttype) = integer_type_node;
1951 yylval.ttype = build_int_2 (result, 0);
1952 TREE_TYPE (yylval.ttype) = wchar_type_node;
1962 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
1963 : TYPE_PRECISION (char_type_node);
1964 #ifdef MULTIBYTE_CHARS
1965 int longest_char = local_mb_cur_max ();
1966 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
1969 p = token_buffer + 1;
1971 while (c != '"' && c >= 0)
1976 c = readescape (&ignore);
1979 if (width < HOST_BITS_PER_INT
1980 && (unsigned) c >= (1 << width))
1981 pedwarn ("escape sequence out of range for character");
1986 pedwarn ("ANSI C forbids newline in string constant");
1991 #ifdef MULTIBYTE_CHARS
1995 for (i = 0; i < longest_char; ++i)
1997 if (p + i == token_buffer + maxtoken)
1998 p = extend_token_buffer (p);
2001 char_len = local_mbtowc (& wc, p, i + 1);
2007 warning ("Ignoring invalid multibyte character");
2010 /* mbtowc sometimes needs an extra char before accepting */
2023 #endif /* MULTIBYTE_CHARS */
2026 /* Add this single character into the buffer either as a wchar_t
2027 or as a single byte. */
2030 unsigned width = TYPE_PRECISION (char_type_node);
2031 unsigned bytemask = (1 << width) - 1;
2034 if (p + WCHAR_BYTES >= token_buffer + maxtoken)
2035 p = extend_token_buffer (p);
2037 for (byte = 0; byte < WCHAR_BYTES; ++byte)
2040 if (byte >= sizeof (c))
2043 value = (c >> (byte * width)) & bytemask;
2044 if (BYTES_BIG_ENDIAN)
2045 p[WCHAR_BYTES - byte - 1] = value;
2053 if (p == token_buffer + maxtoken)
2054 p = extend_token_buffer (p);
2062 /* Terminate the string value, either with a single byte zero
2063 or with a wide zero. */
2066 if (p + WCHAR_BYTES >= token_buffer + maxtoken)
2067 p = extend_token_buffer (p);
2068 bzero (p, WCHAR_BYTES);
2073 if (p == token_buffer + maxtoken)
2074 p = extend_token_buffer (p);
2079 error ("Unterminated string constant");
2081 /* We have read the entire constant.
2082 Construct a STRING_CST for the result. */
2086 yylval.ttype = build_string (p - (token_buffer + 1),
2088 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2093 /* Return an Objective-C @"..." constant string object. */
2094 yylval.ttype = build_objc_string (p - (token_buffer + 1),
2096 TREE_TYPE (yylval.ttype) = char_array_type_node;
2097 value = OBJC_STRING;
2101 yylval.ttype = build_string (p - (token_buffer + 1),
2103 TREE_TYPE (yylval.ttype) = char_array_type_node;
2131 yylval.code = PLUS_EXPR; break;
2133 yylval.code = MINUS_EXPR; break;
2135 yylval.code = BIT_AND_EXPR; break;
2137 yylval.code = BIT_IOR_EXPR; break;
2139 yylval.code = MULT_EXPR; break;
2141 yylval.code = TRUNC_DIV_EXPR; break;
2143 yylval.code = TRUNC_MOD_EXPR; break;
2145 yylval.code = BIT_XOR_EXPR; break;
2147 yylval.code = LSHIFT_EXPR; break;
2149 yylval.code = RSHIFT_EXPR; break;
2151 yylval.code = LT_EXPR; break;
2153 yylval.code = GT_EXPR; break;
2156 token_buffer[1] = c1 = GETC();
2157 token_buffer[2] = 0;
2164 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2166 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2168 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2170 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2172 value = ASSIGN; goto done;
2178 value = PLUSPLUS; goto done;
2180 value = MINUSMINUS; goto done;
2182 value = ANDAND; goto done;
2184 value = OROR; goto done;
2197 { value = POINTSAT; goto done; }
2201 { value = ']'; goto done; }
2205 { value = '{'; indent_level++; goto done; }
2207 { value = '['; goto done; }
2211 { value = '}'; indent_level--; goto done; }
2215 token_buffer[1] = 0;
2217 if ((c == '<') || (c == '>'))
2218 value = ARITHCOMPARE;
2224 /* Don't make yyparse think this is eof. */
2243 /* yylloc.last_line = lineno; */
2248 /* Sets the value of the 'yydebug' variable to VALUE.
2249 This is a function so we don't have to have YYDEBUG defined
2250 in order to build the compiler. */
2259 warning ("YYDEBUG not defined.");