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
39 #endif /* MULTIBYTE_CHARS */
43 extern cpp_reader parse_in;
44 extern cpp_options parse_options;
46 /* Stream for reading from the input file. */
50 extern void yyprint PROTO((FILE *, int, YYSTYPE));
52 /* The elements of `ridpointers' are identifier nodes
53 for the reserved type names and storage classes.
54 It is indexed by a RID_... value. */
55 tree ridpointers[(int) RID_MAX];
57 /* Cause the `yydebug' variable to be defined. */
61 extern unsigned char *yy_cur, *yy_lim;
63 extern int yy_get_token ();
65 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
66 #define UNGETC(c) ((c), yy_cur--)
68 #define GETC() getc (finput)
69 #define UNGETC(c) ungetc (c, finput)
72 /* the declaration found for the last IDENTIFIER token read in.
73 yylex must look this up to detect typedefs, which get token type TYPENAME,
74 so it is left around in case the identifier is not a typedef but is
75 used in a context which makes it a reference to a variable. */
78 /* Nonzero enables objc features. */
84 /* File used for outputting assembler code. */
85 extern FILE *asm_out_file;
87 #ifndef WCHAR_TYPE_SIZE
89 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
91 #define WCHAR_TYPE_SIZE BITS_PER_WORD
95 /* Number of bytes in a wide character. */
96 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
98 static int maxtoken; /* Current nominal length of token buffer. */
99 char *token_buffer; /* Pointer to token buffer.
100 Actual allocated length is maxtoken + 2.
101 This is not static because objc-parse.y uses it. */
103 static int indent_level = 0; /* Number of { minus number of }. */
105 /* Nonzero if end-of-file has been seen on input. */
106 static int end_of_file;
109 /* Buffered-back input character; faster than using ungetc. */
110 static int nextchar = -1;
113 #ifdef HANDLE_GENERIC_PRAGMAS
114 static int handle_generic_pragma PROTO((int));
115 #endif /* HANDLE_GENERIC_PRAGMAS */
116 static int whitespace_cr PROTO((int));
117 static int skip_white_space PROTO((int));
118 static int skip_white_space_on_line PROTO((void));
119 static char *extend_token_buffer PROTO((char *));
120 static int readescape PROTO((int *));
122 /* Do not insert generated code into the source, instead, include it.
123 This allows us to build gcc automatically even for targets that
124 need to add or modify the reserved keyword lists. */
127 /* Return something to represent absolute declarators containing a *.
128 TARGET is the absolute declarator that the * contains.
129 TYPE_QUALS is a list of modifiers such as const or volatile
130 to apply to the pointer type, represented as identifiers.
132 We return an INDIRECT_REF whose "contents" are TARGET
133 and whose type is the modifier list. */
136 make_pointer_declarator (type_quals, target)
137 tree type_quals, target;
139 return build1 (INDIRECT_REF, type_quals, target);
143 forget_protocol_qualifiers ()
145 int i, n = sizeof wordlist / sizeof (struct resword);
147 for (i = 0; i < n; i++)
148 if ((int) wordlist[i].rid >= (int) RID_IN
149 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
150 wordlist[i].name = "";
154 remember_protocol_qualifiers ()
156 int i, n = sizeof wordlist / sizeof (struct resword);
158 for (i = 0; i < n; i++)
159 if (wordlist[i].rid == RID_IN)
160 wordlist[i].name = "in";
161 else if (wordlist[i].rid == RID_OUT)
162 wordlist[i].name = "out";
163 else if (wordlist[i].rid == RID_INOUT)
164 wordlist[i].name = "inout";
165 else if (wordlist[i].rid == RID_BYCOPY)
166 wordlist[i].name = "bycopy";
167 else if (wordlist[i].rid == RID_BYREF)
168 wordlist[i].name = "byref";
169 else if (wordlist[i].rid == RID_ONEWAY)
170 wordlist[i].name = "oneway";
174 init_parse (filename)
178 /* Open input file. */
179 if (filename == 0 || !strcmp (filename, "-"))
185 finput = fopen (filename, "r");
187 pfatal_with_name (filename);
189 #ifdef IO_BUFFER_SIZE
190 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
192 #endif /* !USE_CPPLIB */
200 parse_in.show_column = 1;
201 if (! cpp_start_read (&parse_in, filename))
212 cpp_finish (&parse_in);
221 /* Make identifier nodes long enough for the language-specific slots. */
222 set_identifier_size (sizeof (struct lang_identifier));
224 /* Start it at 0, because check_newline is called at the very beginning
225 and will increment it to 1. */
228 #ifdef MULTIBYTE_CHARS
229 /* Change to the native locale for multibyte conversions. */
230 setlocale (LC_CTYPE, "");
231 literal_codeset = getenv ("LANG");
235 token_buffer = (char *) xmalloc (maxtoken + 2);
237 ridpointers[(int) RID_INT] = get_identifier ("int");
238 ridpointers[(int) RID_CHAR] = get_identifier ("char");
239 ridpointers[(int) RID_VOID] = get_identifier ("void");
240 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
241 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
242 ridpointers[(int) RID_SHORT] = get_identifier ("short");
243 ridpointers[(int) RID_LONG] = get_identifier ("long");
244 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
245 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
246 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
247 ridpointers[(int) RID_CONST] = get_identifier ("const");
248 ridpointers[(int) RID_RESTRICT] = get_identifier ("restrict");
249 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
250 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
251 ridpointers[(int) RID_STATIC] = get_identifier ("static");
252 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
253 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
254 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
255 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
256 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
257 ridpointers[(int) RID_ID] = get_identifier ("id");
258 ridpointers[(int) RID_IN] = get_identifier ("in");
259 ridpointers[(int) RID_OUT] = get_identifier ("out");
260 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
261 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
262 ridpointers[(int) RID_BYREF] = get_identifier ("byref");
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 ("restrict");
279 UNSET_RESERVED_WORD ("volatile");
280 UNSET_RESERVED_WORD ("typeof");
281 UNSET_RESERVED_WORD ("signed");
282 UNSET_RESERVED_WORD ("inline");
283 UNSET_RESERVED_WORD ("iterator");
284 UNSET_RESERVED_WORD ("complex");
286 else if (!flag_isoc9x)
287 UNSET_RESERVED_WORD ("restrict");
291 UNSET_RESERVED_WORD ("asm");
292 UNSET_RESERVED_WORD ("typeof");
293 UNSET_RESERVED_WORD ("inline");
294 UNSET_RESERVED_WORD ("iterator");
295 UNSET_RESERVED_WORD ("complex");
300 reinit_parse_for_function ()
304 /* Function used when yydebug is set, to print a token in more detail. */
307 yyprint (file, yychar, yylval)
319 if (IDENTIFIER_POINTER (t))
320 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
325 if (TREE_CODE (t) == INTEGER_CST)
327 #if HOST_BITS_PER_WIDE_INT == 64
328 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
331 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
338 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
344 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
349 /* Iff C is a carriage return, warn about it - if appropriate -
350 and return nonzero. */
355 static int newline_warning = 0;
359 /* ANSI C says the effects of a carriage return in a source file
361 if (pedantic && !newline_warning)
363 warning ("carriage return in source file");
364 warning ("(we only warn about the first carriage return)");
372 /* If C is not whitespace, return C.
373 Otherwise skip whitespace and return first nonwhite char read. */
383 /* We don't recognize comments here, because
384 cpp output can include / and * consecutively as operators.
385 Also, there's no need, since cpp removes all comments. */
388 c = check_newline ();
409 error ("stray '\\' in program");
419 /* Skips all of the white space at the current location in the input file.
420 Must use and reset nextchar if it has the next character. */
423 position_after_white_space ()
429 c = nextchar, nextchar = -1;
434 UNGETC (skip_white_space (c));
437 /* Like skip_white_space, but don't advance beyond the end of line.
438 Moreover, we don't get passed a character to start with. */
440 skip_white_space_on_line ()
469 /* Make the token buffer longer, preserving the data in it.
470 P should point to just beyond the last valid character in the old buffer.
471 The value we return is a pointer to the new buffer
472 at a place corresponding to P. */
475 extend_token_buffer (p)
478 int offset = p - token_buffer;
480 maxtoken = maxtoken * 2 + 10;
481 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
483 return token_buffer + offset;
486 #if defined HANDLE_PRAGMA
487 /* Local versions of these macros, that can be passed as function pointers. */
502 /* At the beginning of a line, increment the line number
503 and process any #-directive on this line.
504 If the line is a #-directive, read the entire line and return a newline.
505 Otherwise, return the line's first non-whitespace character. */
515 /* Read first nonwhite char on the line. */
518 while (c == ' ' || c == '\t')
523 /* If not #, return it so caller will use it. */
527 /* Read first nonwhite char after the `#'. */
530 while (c == ' ' || c == '\t')
533 /* If a letter follows, then if the word here is `line', skip
534 it and ignore it; otherwise, ignore the line, with an error
535 if the word isn't `pragma', `ident', `define', or `undef'. */
537 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
546 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'
547 || whitespace_cr (c) ))
549 while (c == ' ' || c == '\t' || whitespace_cr (c))
554 #if defined HANDLE_PRAGMA || defined HANDLE_GENERIC_PRAGMAS
557 if (token != IDENTIFIER)
559 #endif /* HANDLE_PRAGMA || HANDLE_GENERIC_PRAGMAS */
562 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS (if
563 both are defined), in order to give the back end a chance to
564 override the interpretation of generic style pragmas. */
568 c = nextchar, nextchar = -1;
571 #endif /* !USE_CPPLIB */
573 if (TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
576 if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
577 IDENTIFIER_POINTER (yylval.ttype)))
579 #endif /* HANDLE_PRAGMA */
581 #ifdef HANDLE_GENERIC_PRAGMAS
582 if (handle_generic_pragma (token))
584 #endif /* HANDLE_GENERIC_PRAGMAS */
586 /* Issue a warning message if we have been asked to do so.
587 Ignoring unknown pragmas in system header file unless
588 an explcit -Wunknown-pragmas has been given. */
589 if (warn_unknown_pragmas > 1
590 || (warn_unknown_pragmas && ! in_system_header))
591 warning ("ignoring pragma: %s", token_buffer);
604 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
607 debug_define (lineno, GET_DIRECTIVE_LINE ());
617 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
620 debug_undef (lineno, GET_DIRECTIVE_LINE ());
629 && ((c = GETC()) == ' ' || c == '\t'))
638 && ((c = GETC()) == ' ' || c == '\t'))
640 /* #ident. The pedantic warning is now in cccp.c. */
642 /* Here we have just seen `#ident '.
643 A string constant should follow. */
645 c = skip_white_space_on_line ();
647 /* If no argument, ignore the line. */
654 || TREE_CODE (yylval.ttype) != STRING_CST)
656 error ("invalid #ident");
662 #ifdef ASM_OUTPUT_IDENT
663 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
667 /* Skip the rest of this line. */
672 error ("undefined or invalid # directive");
677 /* Here we have either `#line' or `# <nonletter>'.
678 In either case, it should be a line number; a digit should follow. */
680 /* Can't use skip_white_space here, but must handle all whitespace
681 that is not '\n', lest we get a recursion for '\r' '\n' when
684 c = skip_white_space_on_line ();
686 /* If the # is the only nonwhite char on the line,
687 just ignore it. Check the new newline. */
691 /* Something follows the #; read a token. */
696 if (token == CONSTANT
697 && TREE_CODE (yylval.ttype) == INTEGER_CST)
699 int old_lineno = lineno;
701 /* subtract one, because it is the following line that
702 gets the specified number */
704 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
706 /* Is this the last nonwhite stuff on the line? */
707 c = skip_white_space_on_line ();
710 /* No more: store the line number and check following line. */
716 /* More follows: it must be a string constant (filename). */
718 /* Read the string constant. */
721 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
723 error ("invalid #line");
728 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
729 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
732 /* Each change of file name
733 reinitializes whether we are now in a system header. */
734 in_system_header = 0;
736 if (main_input_filename == 0)
737 main_input_filename = input_filename;
739 /* Is this the last nonwhite stuff on the line? */
740 c = skip_white_space_on_line ();
743 /* Update the name in the top element of input_file_stack. */
744 if (input_file_stack)
745 input_file_stack->name = input_filename;
754 /* `1' after file name means entering new file.
755 `2' after file name means just left a file. */
757 if (token == CONSTANT
758 && TREE_CODE (yylval.ttype) == INTEGER_CST)
760 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
762 /* Pushing to a new file. */
764 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
765 input_file_stack->line = old_lineno;
766 p->next = input_file_stack;
767 p->name = input_filename;
768 p->indent_level = indent_level;
769 input_file_stack = p;
770 input_file_stack_tick++;
771 debug_start_source_file (input_filename);
774 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
776 /* Popping out of a file. */
777 if (input_file_stack->next)
779 struct file_stack *p = input_file_stack;
780 if (indent_level != p->indent_level)
782 warning_with_file_and_line
783 (p->name, old_lineno,
784 "This file contains more `%c's than `%c's.",
785 indent_level > p->indent_level ? '{' : '}',
786 indent_level > p->indent_level ? '}' : '{');
788 input_file_stack = p->next;
790 input_file_stack_tick++;
791 debug_end_source_file (input_file_stack->line);
794 error ("#-lines for entering and leaving files don't match");
800 /* Now that we've pushed or popped the input stack,
801 update the name in the top element. */
802 if (input_file_stack)
803 input_file_stack->name = input_filename;
805 /* If we have handled a `1' or a `2',
806 see if there is another number to read. */
809 /* Is this the last nonwhite stuff on the line? */
810 c = skip_white_space_on_line ();
819 /* `3' after file name means this is a system header file. */
821 if (token == CONSTANT
822 && TREE_CODE (yylval.ttype) == INTEGER_CST
823 && TREE_INT_CST_LOW (yylval.ttype) == 3)
824 in_system_header = 1, used_up = 1;
828 /* Is this the last nonwhite stuff on the line? */
829 c = skip_white_space_on_line ();
835 warning ("unrecognized text at end of #line");
838 error ("invalid #-line");
840 /* skip the rest of this line. */
843 if (c != '\n' && c != EOF && nextchar >= 0)
844 c = nextchar, nextchar = -1;
846 while (c != '\n' && c != EOF)
851 #ifdef HANDLE_GENERIC_PRAGMAS
853 /* Handle a #pragma directive.
854 TOKEN is the token we read after `#pragma'. Processes the entire input
855 line and return non-zero iff the pragma has been successfully parsed. */
857 /* This function has to be in this file, in order to get at
861 handle_generic_pragma (token)
874 handle_pragma_token (token_buffer, yylval.ttype);
877 handle_pragma_token (token_buffer, NULL);
881 c = nextchar, nextchar = -1;
886 while (c == ' ' || c == '\t')
890 if (c == '\n' || c == EOF)
891 return handle_pragma_token (NULL, NULL);
897 #endif /* HANDLE_GENERIC_PRAGMAS */
899 #define ENDFILE -1 /* token that represents end-of-file */
901 /* Read an escape sequence, returning its equivalent as a character,
902 or store 1 in *ignore_ptr if it is backslash-newline. */
905 readescape (ignore_ptr)
908 register int c = GETC();
910 register unsigned count;
911 unsigned firstdig = 0;
917 if (warn_traditional)
918 warning ("the meaning of `\\x' varies with -traditional");
920 if (flag_traditional)
929 if (!(c >= 'a' && c <= 'f')
930 && !(c >= 'A' && c <= 'F')
931 && !(c >= '0' && c <= '9'))
937 if (c >= 'a' && c <= 'f')
938 code += c - 'a' + 10;
939 if (c >= 'A' && c <= 'F')
940 code += c - 'A' + 10;
941 if (c >= '0' && c <= '9')
943 if (code != 0 || count != 0)
952 error ("\\x used with no following hex digits");
954 /* Digits are all 0's. Ok. */
956 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
958 && (((unsigned)1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
960 pedwarn ("hex escape out of range");
963 case '0': case '1': case '2': case '3': case '4':
964 case '5': case '6': case '7':
967 while ((c <= '7') && (c >= '0') && (count++ < 3))
969 code = (code * 8) + (c - '0');
975 case '\\': case '\'': case '"':
984 return TARGET_NEWLINE;
999 if (warn_traditional)
1000 warning ("the meaning of `\\a' varies with -traditional");
1002 if (flag_traditional)
1007 #if 0 /* Vertical tab is present in common usage compilers. */
1008 if (flag_traditional)
1016 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1022 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1026 /* `\%' is used to prevent SCCS from getting confused. */
1029 pedwarn ("non-ANSI escape sequence `\\%c'", c);
1032 if (c >= 040 && c < 0177)
1033 pedwarn ("unknown escape sequence `\\%c'", c);
1035 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1045 strcpy (buf, string);
1047 /* We can't print string and character constants well
1048 because the token_buffer contains the result of processing escapes. */
1050 strcat (buf, " at end of input");
1051 else if (token_buffer[0] == 0)
1052 strcat (buf, " at null character");
1053 else if (token_buffer[0] == '"')
1054 strcat (buf, " before string constant");
1055 else if (token_buffer[0] == '\'')
1056 strcat (buf, " before character constant");
1057 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
1058 sprintf (buf + strlen (buf), " before character 0%o",
1059 (unsigned char) token_buffer[0]);
1061 strcat (buf, " before `%s'");
1063 error (buf, token_buffer);
1073 char long_long_flag;
1076 struct try_type type_sequence[] =
1078 { &integer_type_node, 0, 0, 0},
1079 { &unsigned_type_node, 1, 0, 0},
1080 { &long_integer_type_node, 0, 1, 0},
1081 { &long_unsigned_type_node, 1, 1, 0},
1082 { &long_long_integer_type_node, 0, 1, 1},
1083 { &long_long_unsigned_type_node, 1, 1, 1}
1098 c = nextchar, nextchar = -1;
1103 /* Effectively do c = skip_white_space (c)
1104 but do it faster in the usual cases. */
1117 /* Call skip_white_space so we can warn if appropriate. */
1122 c = skip_white_space (c);
1124 goto found_nonwhite;
1128 token_buffer[0] = c;
1129 token_buffer[1] = 0;
1131 /* yylloc.first_line = lineno; */
1137 token_buffer[0] = 0;
1142 /* Capital L may start a wide-string or wide-character constant. */
1144 register int c = GETC();
1153 goto string_constant;
1160 if (!doing_objc_thang)
1167 /* '@' may start a constant string object. */
1168 register int c = GETC ();
1172 goto string_constant;
1175 /* Fall through to treat '@' as the start of an identifier. */
1178 case 'A': case 'B': case 'C': case 'D': case 'E':
1179 case 'F': case 'G': case 'H': case 'I': case 'J':
1180 case 'K': case 'M': case 'N': case 'O':
1181 case 'P': case 'Q': case 'R': case 'S': case 'T':
1182 case 'U': case 'V': case 'W': case 'X': case 'Y':
1184 case 'a': case 'b': case 'c': case 'd': case 'e':
1185 case 'f': case 'g': case 'h': case 'i': case 'j':
1186 case 'k': case 'l': case 'm': case 'n': case 'o':
1187 case 'p': case 'q': case 'r': case 's': case 't':
1188 case 'u': case 'v': case 'w': case 'x': case 'y':
1194 while (ISALNUM (c) || c == '_' || c == '$' || c == '@')
1196 /* Make sure this char really belongs in an identifier. */
1197 if (c == '@' && ! doing_objc_thang)
1201 if (! dollars_in_ident)
1202 error ("`$' in identifier");
1204 pedwarn ("`$' in identifier");
1207 if (p >= token_buffer + maxtoken)
1208 p = extend_token_buffer (p);
1224 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1227 register struct resword *ptr;
1229 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
1232 yylval.ttype = ridpointers[(int) ptr->rid];
1233 value = (int) ptr->token;
1235 /* Only return OBJECTNAME if it is a typedef. */
1236 if (doing_objc_thang && value == OBJECTNAME)
1238 lastiddecl = lookup_name(yylval.ttype);
1240 if (lastiddecl == NULL_TREE
1241 || TREE_CODE (lastiddecl) != TYPE_DECL)
1245 /* Even if we decided to recognize asm, still perhaps warn. */
1247 && (value == ASM_KEYWORD || value == TYPEOF
1248 || ptr->rid == RID_INLINE)
1249 && token_buffer[0] != '_')
1250 pedwarn ("ANSI does not permit the keyword `%s'",
1255 /* If we did not find a keyword, look for an identifier
1258 if (value == IDENTIFIER)
1260 if (token_buffer[0] == '@')
1261 error("invalid identifier `%s'", token_buffer);
1263 yylval.ttype = get_identifier (token_buffer);
1264 lastiddecl = lookup_name (yylval.ttype);
1266 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1268 /* A user-invisible read-only initialized variable
1269 should be replaced by its value.
1270 We handle only strings since that's the only case used in C. */
1271 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1272 && DECL_IGNORED_P (lastiddecl)
1273 && TREE_READONLY (lastiddecl)
1274 && DECL_INITIAL (lastiddecl) != 0
1275 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1277 tree stringval = DECL_INITIAL (lastiddecl);
1279 /* Copy the string value so that we won't clobber anything
1280 if we put something in the TREE_CHAIN of this one. */
1281 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1282 TREE_STRING_POINTER (stringval));
1285 else if (doing_objc_thang)
1287 tree objc_interface_decl = is_class_name (yylval.ttype);
1289 if (objc_interface_decl)
1292 yylval.ttype = objc_interface_decl;
1302 /* Check first for common special case: single-digit 0 or 1. */
1305 UNGETC (next_c); /* Always undo this lookahead. */
1306 if (!ISALNUM (next_c) && next_c != '.')
1308 token_buffer[0] = (char)c, token_buffer[1] = '\0';
1309 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1315 case '2': case '3': case '4':
1316 case '5': case '6': case '7': case '8': case '9':
1321 int largest_digit = 0;
1323 /* for multi-precision arithmetic,
1324 we actually store only HOST_BITS_PER_CHAR bits in each part.
1325 The number of parts is chosen so as to be sufficient to hold
1326 the enough bits to fit into the two HOST_WIDE_INTs that contain
1327 the integer value (this is always at least as many bits as are
1328 in a target `long long' value, but may be wider). */
1329 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1330 int parts[TOTAL_PARTS];
1333 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1336 for (count = 0; count < TOTAL_PARTS; count++)
1344 *p++ = (c = GETC());
1345 if ((c == 'x') || (c == 'X'))
1348 *p++ = (c = GETC());
1350 /* Leading 0 forces octal unless the 0 is the only digit. */
1351 else if (c >= '0' && c <= '9')
1360 /* Read all the digits-and-decimal-points. */
1363 || (ISALNUM (c) && c != 'l' && c != 'L'
1364 && c != 'u' && c != 'U'
1365 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1366 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1371 error ("floating constant may not be in radix 16");
1372 if (floatflag == TOO_MANY_POINTS)
1373 /* We have already emitted an error. Don't need another. */
1375 else if (floatflag == AFTER_POINT)
1377 error ("malformed floating constant");
1378 floatflag = TOO_MANY_POINTS;
1379 /* Avoid another error from atof by forcing all characters
1380 from here on to be ignored. */
1384 floatflag = AFTER_POINT;
1388 /* Accept '.' as the start of a floating-point number
1389 only when it is followed by a digit.
1390 Otherwise, unread the following non-digit
1391 and use the '.' as a structural token. */
1392 if (p == token_buffer + 2 && !ISDIGIT (c))
1403 error ("parse error at `..'");
1406 token_buffer[1] = 0;
1413 /* It is not a decimal point.
1414 It should be a digit (perhaps a hex digit). */
1420 else if (base <= 10)
1422 if (c == 'e' || c == 'E')
1425 floatflag = AFTER_POINT;
1426 break; /* start of exponent */
1428 error ("nondigits in number and not hexadecimal");
1439 if (c >= largest_digit)
1443 for (count = 0; count < TOTAL_PARTS; count++)
1445 parts[count] *= base;
1449 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1451 &= (1 << HOST_BITS_PER_CHAR) - 1;
1457 /* If the extra highest-order part ever gets anything in it,
1458 the number is certainly too big. */
1459 if (parts[TOTAL_PARTS - 1] != 0)
1462 if (p >= token_buffer + maxtoken - 3)
1463 p = extend_token_buffer (p);
1464 *p++ = (c = GETC());
1469 error ("numeric constant with no digits");
1471 if (largest_digit >= base)
1472 error ("numeric constant contains digits beyond the radix");
1474 /* Remove terminating char from the token buffer and delimit the string */
1477 if (floatflag != NOT_FLOAT)
1479 tree type = double_type_node;
1481 int conversion_errno = 0;
1482 REAL_VALUE_TYPE value;
1485 /* Read explicit exponent if any, and put it in tokenbuf. */
1487 if ((c == 'e') || (c == 'E'))
1489 if (p >= token_buffer + maxtoken - 3)
1490 p = extend_token_buffer (p);
1493 if ((c == '+') || (c == '-'))
1499 error ("floating constant exponent has no digits");
1502 if (p >= token_buffer + maxtoken - 3)
1503 p = extend_token_buffer (p);
1511 /* Convert string to a double, checking for overflow. */
1512 if (setjmp (handler))
1514 error ("floating constant out of range");
1519 int fflag = 0, lflag = 0;
1520 /* Copy token_buffer now, while it has just the number
1521 and not the suffixes; once we add `f' or `i',
1522 REAL_VALUE_ATOF may not work any more. */
1523 char *copy = (char *) alloca (p - token_buffer + 1);
1524 bcopy (token_buffer, copy, p - token_buffer + 1);
1526 set_float_handler (handler);
1532 /* Read the suffixes to choose a data type. */
1537 error ("more than one `f' in numeric constant");
1543 error ("more than one `l' in numeric constant");
1549 error ("more than one `i' or `j' in numeric constant");
1551 pedwarn ("ANSI C forbids imaginary numeric constants");
1562 if (p >= token_buffer + maxtoken - 3)
1563 p = extend_token_buffer (p);
1569 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1570 tells the desired precision of the binary result
1571 of decimal-to-binary conversion. */
1576 error ("both `f' and `l' in floating constant");
1578 type = float_type_node;
1580 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1581 conversion_errno = errno;
1582 /* A diagnostic is required here by some ANSI C testsuites.
1583 This is not pedwarn, become some people don't want
1584 an error for this. */
1585 if (REAL_VALUE_ISINF (value) && pedantic)
1586 warning ("floating point number exceeds range of `float'");
1590 type = long_double_type_node;
1592 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1593 conversion_errno = errno;
1594 if (REAL_VALUE_ISINF (value) && pedantic)
1595 warning ("floating point number exceeds range of `long double'");
1600 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1601 conversion_errno = errno;
1602 if (REAL_VALUE_ISINF (value) && pedantic)
1603 warning ("floating point number exceeds range of `double'");
1606 set_float_handler (NULL_PTR);
1609 /* ERANGE is also reported for underflow,
1610 so test the value to distinguish overflow from that. */
1611 if (conversion_errno == ERANGE && !flag_traditional && pedantic
1612 && (REAL_VALUES_LESS (dconst1, value)
1613 || REAL_VALUES_LESS (value, dconstm1)))
1614 warning ("floating point number exceeds range of `double'");
1617 /* If the result is not a number, assume it must have been
1618 due to some error message above, so silently convert
1620 if (REAL_VALUE_ISNAN (value))
1623 /* Create a node with determined type and value. */
1625 yylval.ttype = build_complex (NULL_TREE,
1626 convert (type, integer_zero_node),
1627 build_real (type, value));
1629 yylval.ttype = build_real (type, value);
1633 tree traditional_type, ansi_type, type;
1634 HOST_WIDE_INT high, low;
1635 int spec_unsigned = 0;
1637 int spec_long_long = 0;
1641 traditional_type = ansi_type = type = NULL_TREE;
1644 if (c == 'u' || c == 'U')
1647 error ("two `u's in integer constant");
1650 else if (c == 'l' || c == 'L')
1655 error ("three `l's in integer constant");
1656 else if (pedantic && ! in_system_header && warn_long_long)
1657 pedwarn ("ANSI C forbids long long integer constants");
1662 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1665 error ("more than one `i' or `j' in numeric constant");
1667 pedwarn ("ANSI C forbids imaginary numeric constants");
1672 if (p >= token_buffer + maxtoken - 3)
1673 p = extend_token_buffer (p);
1678 /* If the constant won't fit in an unsigned long long,
1679 then warn that the constant is out of range. */
1681 /* ??? This assumes that long long and long integer types are
1682 a multiple of 8 bits. This better than the original code
1683 though which assumed that long was exactly 32 bits and long
1684 long was exactly 64 bits. */
1686 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1689 for (i = bytes; i < TOTAL_PARTS; i++)
1693 pedwarn ("integer constant out of range");
1695 /* This is simplified by the fact that our constant
1696 is always positive. */
1700 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1702 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1703 / HOST_BITS_PER_CHAR)]
1704 << (i * HOST_BITS_PER_CHAR));
1705 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1708 yylval.ttype = build_int_2 (low, high);
1709 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1711 /* If warn_traditional, calculate both the ANSI type and the
1712 traditional type, then see if they disagree.
1713 Otherwise, calculate only the type for the dialect in use. */
1714 if (warn_traditional || flag_traditional)
1716 /* Calculate the traditional type. */
1717 /* Traditionally, any constant is signed;
1718 but if unsigned is specified explicitly, obey that.
1719 Use the smallest size with the right number of bits,
1720 except for one special case with decimal constants. */
1721 if (! spec_long && base != 10
1722 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1723 traditional_type = (spec_unsigned ? unsigned_type_node
1724 : integer_type_node);
1725 /* A decimal constant must be long
1726 if it does not fit in type int.
1727 I think this is independent of whether
1728 the constant is signed. */
1729 else if (! spec_long && base == 10
1730 && int_fits_type_p (yylval.ttype, integer_type_node))
1731 traditional_type = (spec_unsigned ? unsigned_type_node
1732 : integer_type_node);
1733 else if (! spec_long_long)
1734 traditional_type = (spec_unsigned ? long_unsigned_type_node
1735 : long_integer_type_node);
1737 traditional_type = (spec_unsigned
1738 ? long_long_unsigned_type_node
1739 : long_long_integer_type_node);
1741 if (warn_traditional || ! flag_traditional)
1743 /* Calculate the ANSI type. */
1744 if (! spec_long && ! spec_unsigned
1745 && int_fits_type_p (yylval.ttype, integer_type_node))
1746 ansi_type = integer_type_node;
1747 else if (! spec_long && (base != 10 || spec_unsigned)
1748 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1749 ansi_type = unsigned_type_node;
1750 else if (! spec_unsigned && !spec_long_long
1751 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1752 ansi_type = long_integer_type_node;
1753 else if (! spec_long_long
1754 && int_fits_type_p (yylval.ttype,
1755 long_unsigned_type_node))
1756 ansi_type = long_unsigned_type_node;
1757 else if (! spec_unsigned
1758 && int_fits_type_p (yylval.ttype,
1759 long_long_integer_type_node))
1760 ansi_type = long_long_integer_type_node;
1762 ansi_type = long_long_unsigned_type_node;
1765 type = flag_traditional ? traditional_type : ansi_type;
1767 if (warn_traditional && traditional_type != ansi_type)
1769 if (TYPE_PRECISION (traditional_type)
1770 != TYPE_PRECISION (ansi_type))
1771 warning ("width of integer constant changes with -traditional");
1772 else if (TREE_UNSIGNED (traditional_type)
1773 != TREE_UNSIGNED (ansi_type))
1774 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1776 warning ("width of integer constant may change on other systems with -traditional");
1779 if (pedantic && !flag_traditional && !spec_long_long && !warn
1780 && (TYPE_PRECISION (long_integer_type_node)
1781 < TYPE_PRECISION (type)))
1782 pedwarn ("integer constant out of range");
1784 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1785 warning ("decimal constant is so large that it is unsigned");
1789 if (TYPE_PRECISION (type)
1790 <= TYPE_PRECISION (integer_type_node))
1792 = build_complex (NULL_TREE, integer_zero_node,
1793 convert (integer_type_node,
1796 error ("complex integer constant is too wide for `complex int'");
1798 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1799 /* The traditional constant 0x80000000 is signed
1800 but doesn't fit in the range of int.
1801 This will change it to -0x80000000, which does fit. */
1803 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1804 yylval.ttype = convert (type, yylval.ttype);
1805 TREE_OVERFLOW (yylval.ttype)
1806 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1809 TREE_TYPE (yylval.ttype) = type;
1815 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
1816 || (!flag_traditional && (c == '-' || c == '+')
1817 && (p[-1] == 'e' || p[-1] == 'E')))
1818 error ("missing white space after number `%s'", token_buffer);
1820 value = CONSTANT; break;
1826 register int result = 0;
1827 register int num_chars = 0;
1829 unsigned width = TYPE_PRECISION (char_type_node);
1831 #ifdef MULTIBYTE_CHARS
1832 int longest_char = local_mb_cur_max ();
1833 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
1836 max_chars = TYPE_PRECISION (integer_type_node) / width;
1838 width = WCHAR_TYPE_SIZE;
1845 if (c == '\'' || c == EOF)
1852 c = readescape (&ignore);
1855 if (width < HOST_BITS_PER_INT
1856 && (unsigned) c >= ((unsigned)1 << width))
1857 pedwarn ("escape sequence out of range for character");
1858 #ifdef MAP_CHARACTER
1860 c = MAP_CHARACTER (c);
1866 pedwarn ("ANSI C forbids newline in character constant");
1871 #ifdef MULTIBYTE_CHARS
1875 for (i = 1; i <= longest_char; ++i)
1877 if (i > maxtoken - 4)
1878 extend_token_buffer (token_buffer);
1880 token_buffer[i] = c;
1881 char_len = local_mbtowc (& wc,
1890 /* mbtowc sometimes needs an extra char before accepting */
1895 /* Merge character into result; ignore excess chars. */
1896 for (i = 1; i <= char_len; ++i)
1900 if (width < HOST_BITS_PER_INT)
1901 result = (result << width)
1903 & ((1 << width) - 1));
1905 result = token_buffer[i];
1907 num_chars += char_len;
1915 warning ("Ignoring invalid multibyte character");
1918 #ifdef MAP_CHARACTER
1920 c = MAP_CHARACTER (c);
1923 #else /* ! MULTIBYTE_CHARS */
1924 #ifdef MAP_CHARACTER
1925 c = MAP_CHARACTER (c);
1927 #endif /* ! MULTIBYTE_CHARS */
1932 if (chars_seen == 1) /* only keep the first one */
1937 /* Merge character into result; ignore excess chars. */
1938 num_chars += (width / TYPE_PRECISION (char_type_node));
1939 if (num_chars < max_chars + 1)
1941 if (width < HOST_BITS_PER_INT)
1942 result = (result << width) | (c & ((1 << width) - 1));
1949 error ("malformatted character constant");
1950 else if (chars_seen == 0)
1951 error ("empty character constant");
1952 else if (num_chars > max_chars)
1954 num_chars = max_chars;
1955 error ("character constant too long");
1957 else if (chars_seen != 1 && ! flag_traditional && warn_multichar)
1958 warning ("multi-character character constant");
1960 /* If char type is signed, sign-extend the constant. */
1963 int num_bits = num_chars * width;
1965 /* We already got an error; avoid invalid shift. */
1966 yylval.ttype = build_int_2 (0, 0);
1967 else if (TREE_UNSIGNED (char_type_node)
1968 || ((result >> (num_bits - 1)) & 1) == 0)
1970 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
1971 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1975 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
1976 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1978 TREE_TYPE (yylval.ttype) = integer_type_node;
1982 yylval.ttype = build_int_2 (result, 0);
1983 TREE_TYPE (yylval.ttype) = wchar_type_node;
1993 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
1994 : TYPE_PRECISION (char_type_node);
1995 #ifdef MULTIBYTE_CHARS
1996 int longest_char = local_mb_cur_max ();
1997 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
2000 p = token_buffer + 1;
2002 while (c != '"' && c >= 0)
2007 c = readescape (&ignore);
2010 if (width < HOST_BITS_PER_INT
2011 && (unsigned) c >= ((unsigned)1 << width))
2012 pedwarn ("escape sequence out of range for character");
2017 pedwarn ("ANSI C forbids newline in string constant");
2022 #ifdef MULTIBYTE_CHARS
2026 for (i = 0; i < longest_char; ++i)
2028 if (p + i >= token_buffer + maxtoken)
2029 p = extend_token_buffer (p);
2032 char_len = local_mbtowc (& wc, p, i + 1);
2038 warning ("Ignoring invalid multibyte character");
2041 /* mbtowc sometimes needs an extra char before accepting */
2052 #endif /* MULTIBYTE_CHARS */
2055 /* Add this single character into the buffer either as a wchar_t
2056 or as a single byte. */
2059 unsigned width = TYPE_PRECISION (char_type_node);
2060 unsigned bytemask = (1 << width) - 1;
2063 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2064 p = extend_token_buffer (p);
2066 for (byte = 0; byte < WCHAR_BYTES; ++byte)
2069 if (byte >= (int) sizeof (c))
2072 value = (c >> (byte * width)) & bytemask;
2073 if (BYTES_BIG_ENDIAN)
2074 p[WCHAR_BYTES - byte - 1] = value;
2082 if (p >= token_buffer + maxtoken)
2083 p = extend_token_buffer (p);
2091 /* Terminate the string value, either with a single byte zero
2092 or with a wide zero. */
2095 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2096 p = extend_token_buffer (p);
2097 bzero (p, WCHAR_BYTES);
2102 if (p >= token_buffer + maxtoken)
2103 p = extend_token_buffer (p);
2108 error ("Unterminated string constant");
2110 /* We have read the entire constant.
2111 Construct a STRING_CST for the result. */
2115 yylval.ttype = build_string (p - (token_buffer + 1),
2117 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2122 /* Return an Objective-C @"..." constant string object. */
2123 yylval.ttype = build_objc_string (p - (token_buffer + 1),
2125 TREE_TYPE (yylval.ttype) = char_array_type_node;
2126 value = OBJC_STRING;
2130 yylval.ttype = build_string (p - (token_buffer + 1),
2132 TREE_TYPE (yylval.ttype) = char_array_type_node;
2160 yylval.code = PLUS_EXPR; break;
2162 yylval.code = MINUS_EXPR; break;
2164 yylval.code = BIT_AND_EXPR; break;
2166 yylval.code = BIT_IOR_EXPR; break;
2168 yylval.code = MULT_EXPR; break;
2170 yylval.code = TRUNC_DIV_EXPR; break;
2172 yylval.code = TRUNC_MOD_EXPR; break;
2174 yylval.code = BIT_XOR_EXPR; break;
2176 yylval.code = LSHIFT_EXPR; break;
2178 yylval.code = RSHIFT_EXPR; break;
2180 yylval.code = LT_EXPR; break;
2182 yylval.code = GT_EXPR; break;
2185 token_buffer[1] = c1 = GETC();
2186 token_buffer[2] = 0;
2193 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2195 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2197 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2199 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2201 value = ASSIGN; goto done;
2207 value = PLUSPLUS; goto done;
2209 value = MINUSMINUS; goto done;
2211 value = ANDAND; goto done;
2213 value = OROR; goto done;
2226 { value = POINTSAT; goto done; }
2230 { value = ']'; goto done; }
2234 { value = '{'; indent_level++; goto done; }
2236 { value = '['; goto done; }
2240 { value = '}'; indent_level--; goto done; }
2244 token_buffer[1] = 0;
2246 if ((c == '<') || (c == '>'))
2247 value = ARITHCOMPARE;
2253 /* Don't make yyparse think this is eof. */
2272 /* yylloc.last_line = lineno; */
2277 /* Sets the value of the 'yydebug' variable to VALUE.
2278 This is a function so we don't have to have YYDEBUG defined
2279 in order to build the compiler. */
2288 warning ("YYDEBUG not defined.");