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 #else /* !USE_CPPLIB */
193 parse_in.show_column = 1;
194 if (! cpp_start_read (&parse_in, filename))
197 if (filename == 0 || !strcmp (filename, "-"))
200 /* cpp_start_read always puts at least one line directive into the
201 token buffer. We must arrange to read it out here. */
202 yy_cur = parse_in.token_buffer;
203 yy_lim = CPP_PWRITTEN (&parse_in);
215 cpp_finish (&parse_in);
224 /* Make identifier nodes long enough for the language-specific slots. */
225 set_identifier_size (sizeof (struct lang_identifier));
227 /* Start it at 0, because check_newline is called at the very beginning
228 and will increment it to 1. */
231 #ifdef MULTIBYTE_CHARS
232 /* Change to the native locale for multibyte conversions. */
233 setlocale (LC_CTYPE, "");
234 literal_codeset = getenv ("LANG");
238 token_buffer = (char *) xmalloc (maxtoken + 2);
240 ridpointers[(int) RID_INT] = get_identifier ("int");
241 ridpointers[(int) RID_CHAR] = get_identifier ("char");
242 ridpointers[(int) RID_VOID] = get_identifier ("void");
243 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
244 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
245 ridpointers[(int) RID_SHORT] = get_identifier ("short");
246 ridpointers[(int) RID_LONG] = get_identifier ("long");
247 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
248 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
249 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
250 ridpointers[(int) RID_CONST] = get_identifier ("const");
251 ridpointers[(int) RID_RESTRICT] = get_identifier ("restrict");
252 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
253 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
254 ridpointers[(int) RID_STATIC] = get_identifier ("static");
255 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
256 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
257 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
258 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
259 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
260 ridpointers[(int) RID_ID] = get_identifier ("id");
261 ridpointers[(int) RID_IN] = get_identifier ("in");
262 ridpointers[(int) RID_OUT] = get_identifier ("out");
263 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
264 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
265 ridpointers[(int) RID_BYREF] = get_identifier ("byref");
266 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
267 forget_protocol_qualifiers();
269 /* Some options inhibit certain reserved words.
270 Clear those words out of the hash table so they won't be recognized. */
271 #define UNSET_RESERVED_WORD(STRING) \
272 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
273 if (s) s->name = ""; } while (0)
275 if (! doing_objc_thang)
276 UNSET_RESERVED_WORD ("id");
278 if (flag_traditional)
280 UNSET_RESERVED_WORD ("const");
281 UNSET_RESERVED_WORD ("restrict");
282 UNSET_RESERVED_WORD ("volatile");
283 UNSET_RESERVED_WORD ("typeof");
284 UNSET_RESERVED_WORD ("signed");
285 UNSET_RESERVED_WORD ("inline");
286 UNSET_RESERVED_WORD ("iterator");
287 UNSET_RESERVED_WORD ("complex");
289 else if (!flag_isoc9x)
290 UNSET_RESERVED_WORD ("restrict");
294 UNSET_RESERVED_WORD ("asm");
295 UNSET_RESERVED_WORD ("typeof");
296 UNSET_RESERVED_WORD ("inline");
297 UNSET_RESERVED_WORD ("iterator");
298 UNSET_RESERVED_WORD ("complex");
303 reinit_parse_for_function ()
307 /* Function used when yydebug is set, to print a token in more detail. */
310 yyprint (file, yychar, yylval)
322 if (IDENTIFIER_POINTER (t))
323 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
328 if (TREE_CODE (t) == INTEGER_CST)
330 #if HOST_BITS_PER_WIDE_INT == 64
331 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
334 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
341 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
347 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
352 /* Iff C is a carriage return, warn about it - if appropriate -
353 and return nonzero. */
358 static int newline_warning = 0;
362 /* ANSI C says the effects of a carriage return in a source file
364 if (pedantic && !newline_warning)
366 warning ("carriage return in source file");
367 warning ("(we only warn about the first carriage return)");
375 /* If C is not whitespace, return C.
376 Otherwise skip whitespace and return first nonwhite char read. */
386 /* We don't recognize comments here, because
387 cpp output can include / and * consecutively as operators.
388 Also, there's no need, since cpp removes all comments. */
391 c = check_newline ();
412 error ("stray '\\' in program");
422 /* Skips all of the white space at the current location in the input file.
423 Must use and reset nextchar if it has the next character. */
426 position_after_white_space ()
432 c = nextchar, nextchar = -1;
437 UNGETC (skip_white_space (c));
440 /* Like skip_white_space, but don't advance beyond the end of line.
441 Moreover, we don't get passed a character to start with. */
443 skip_white_space_on_line ()
472 /* Make the token buffer longer, preserving the data in it.
473 P should point to just beyond the last valid character in the old buffer.
474 The value we return is a pointer to the new buffer
475 at a place corresponding to P. */
478 extend_token_buffer (p)
481 int offset = p - token_buffer;
483 maxtoken = maxtoken * 2 + 10;
484 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
486 return token_buffer + offset;
489 #if defined HANDLE_PRAGMA
490 /* Local versions of these macros, that can be passed as function pointers. */
505 /* At the beginning of a line, increment the line number
506 and process any #-directive on this line.
507 If the line is a #-directive, read the entire line and return a newline.
508 Otherwise, return the line's first non-whitespace character. */
518 /* Read first nonwhite char on the line. */
521 while (c == ' ' || c == '\t')
526 /* If not #, return it so caller will use it. */
530 /* Read first nonwhite char after the `#'. */
533 while (c == ' ' || c == '\t')
536 /* If a letter follows, then if the word here is `line', skip
537 it and ignore it; otherwise, ignore the line, with an error
538 if the word isn't `pragma', `ident', `define', or `undef'. */
540 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
549 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'
550 || whitespace_cr (c) ))
552 while (c == ' ' || c == '\t' || whitespace_cr (c))
557 #if defined HANDLE_PRAGMA || defined HANDLE_GENERIC_PRAGMAS
560 if (token != IDENTIFIER)
562 #endif /* HANDLE_PRAGMA || HANDLE_GENERIC_PRAGMAS */
565 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS (if
566 both are defined), in order to give the back end a chance to
567 override the interpretation of generic style pragmas. */
571 c = nextchar, nextchar = -1;
574 #endif /* !USE_CPPLIB */
576 if (TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
579 if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
580 IDENTIFIER_POINTER (yylval.ttype)))
582 #endif /* HANDLE_PRAGMA */
584 #ifdef HANDLE_GENERIC_PRAGMAS
585 if (handle_generic_pragma (token))
587 #endif /* HANDLE_GENERIC_PRAGMAS */
589 /* Issue a warning message if we have been asked to do so.
590 Ignoring unknown pragmas in system header file unless
591 an explcit -Wunknown-pragmas has been given. */
592 if (warn_unknown_pragmas > 1
593 || (warn_unknown_pragmas && ! in_system_header))
594 warning ("ignoring pragma: %s", token_buffer);
607 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
610 debug_define (lineno, GET_DIRECTIVE_LINE ());
620 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
623 debug_undef (lineno, GET_DIRECTIVE_LINE ());
632 && ((c = GETC()) == ' ' || c == '\t'))
641 && ((c = GETC()) == ' ' || c == '\t'))
643 /* #ident. The pedantic warning is now in cccp.c. */
645 /* Here we have just seen `#ident '.
646 A string constant should follow. */
648 c = skip_white_space_on_line ();
650 /* If no argument, ignore the line. */
657 || TREE_CODE (yylval.ttype) != STRING_CST)
659 error ("invalid #ident");
665 #ifdef ASM_OUTPUT_IDENT
666 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
670 /* Skip the rest of this line. */
675 error ("undefined or invalid # directive");
680 /* Here we have either `#line' or `# <nonletter>'.
681 In either case, it should be a line number; a digit should follow. */
683 /* Can't use skip_white_space here, but must handle all whitespace
684 that is not '\n', lest we get a recursion for '\r' '\n' when
687 c = skip_white_space_on_line ();
689 /* If the # is the only nonwhite char on the line,
690 just ignore it. Check the new newline. */
694 /* Something follows the #; read a token. */
699 if (token == CONSTANT
700 && TREE_CODE (yylval.ttype) == INTEGER_CST)
702 int old_lineno = lineno;
704 /* subtract one, because it is the following line that
705 gets the specified number */
707 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
709 /* Is this the last nonwhite stuff on the line? */
710 c = skip_white_space_on_line ();
713 /* No more: store the line number and check following line. */
719 /* More follows: it must be a string constant (filename). */
721 /* Read the string constant. */
724 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
726 error ("invalid #line");
731 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
732 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
735 /* Each change of file name
736 reinitializes whether we are now in a system header. */
737 in_system_header = 0;
739 if (main_input_filename == 0)
740 main_input_filename = input_filename;
742 /* Is this the last nonwhite stuff on the line? */
743 c = skip_white_space_on_line ();
746 /* Update the name in the top element of input_file_stack. */
747 if (input_file_stack)
748 input_file_stack->name = input_filename;
757 /* `1' after file name means entering new file.
758 `2' after file name means just left a file. */
760 if (token == CONSTANT
761 && TREE_CODE (yylval.ttype) == INTEGER_CST)
763 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
765 /* Pushing to a new file. */
767 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
768 input_file_stack->line = old_lineno;
769 p->next = input_file_stack;
770 p->name = input_filename;
771 p->indent_level = indent_level;
772 input_file_stack = p;
773 input_file_stack_tick++;
774 debug_start_source_file (input_filename);
777 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
779 /* Popping out of a file. */
780 if (input_file_stack->next)
782 struct file_stack *p = input_file_stack;
783 if (indent_level != p->indent_level)
785 warning_with_file_and_line
786 (p->name, old_lineno,
787 "This file contains more `%c's than `%c's.",
788 indent_level > p->indent_level ? '{' : '}',
789 indent_level > p->indent_level ? '}' : '{');
791 input_file_stack = p->next;
793 input_file_stack_tick++;
794 debug_end_source_file (input_file_stack->line);
797 error ("#-lines for entering and leaving files don't match");
803 /* Now that we've pushed or popped the input stack,
804 update the name in the top element. */
805 if (input_file_stack)
806 input_file_stack->name = input_filename;
808 /* If we have handled a `1' or a `2',
809 see if there is another number to read. */
812 /* Is this the last nonwhite stuff on the line? */
813 c = skip_white_space_on_line ();
822 /* `3' after file name means this is a system header file. */
824 if (token == CONSTANT
825 && TREE_CODE (yylval.ttype) == INTEGER_CST
826 && TREE_INT_CST_LOW (yylval.ttype) == 3)
827 in_system_header = 1, used_up = 1;
831 /* Is this the last nonwhite stuff on the line? */
832 c = skip_white_space_on_line ();
838 warning ("unrecognized text at end of #line");
841 error ("invalid #-line");
843 /* skip the rest of this line. */
846 if (c != '\n' && c != EOF && nextchar >= 0)
847 c = nextchar, nextchar = -1;
849 while (c != '\n' && c != EOF)
854 #ifdef HANDLE_GENERIC_PRAGMAS
856 /* Handle a #pragma directive.
857 TOKEN is the token we read after `#pragma'. Processes the entire input
858 line and return non-zero iff the pragma has been successfully parsed. */
860 /* This function has to be in this file, in order to get at
864 handle_generic_pragma (token)
877 handle_pragma_token (token_buffer, yylval.ttype);
880 handle_pragma_token (token_buffer, NULL);
884 c = nextchar, nextchar = -1;
889 while (c == ' ' || c == '\t')
893 if (c == '\n' || c == EOF)
894 return handle_pragma_token (NULL, NULL);
900 #endif /* HANDLE_GENERIC_PRAGMAS */
902 #define ENDFILE -1 /* token that represents end-of-file */
904 /* Read an escape sequence, returning its equivalent as a character,
905 or store 1 in *ignore_ptr if it is backslash-newline. */
908 readescape (ignore_ptr)
911 register int c = GETC();
913 register unsigned count;
914 unsigned firstdig = 0;
920 if (warn_traditional)
921 warning ("the meaning of `\\x' varies with -traditional");
923 if (flag_traditional)
932 if (!(c >= 'a' && c <= 'f')
933 && !(c >= 'A' && c <= 'F')
934 && !(c >= '0' && c <= '9'))
940 if (c >= 'a' && c <= 'f')
941 code += c - 'a' + 10;
942 if (c >= 'A' && c <= 'F')
943 code += c - 'A' + 10;
944 if (c >= '0' && c <= '9')
946 if (code != 0 || count != 0)
955 error ("\\x used with no following hex digits");
957 /* Digits are all 0's. Ok. */
959 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
961 && (((unsigned)1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
963 pedwarn ("hex escape out of range");
966 case '0': case '1': case '2': case '3': case '4':
967 case '5': case '6': case '7':
970 while ((c <= '7') && (c >= '0') && (count++ < 3))
972 code = (code * 8) + (c - '0');
978 case '\\': case '\'': case '"':
987 return TARGET_NEWLINE;
1002 if (warn_traditional)
1003 warning ("the meaning of `\\a' varies with -traditional");
1005 if (flag_traditional)
1010 #if 0 /* Vertical tab is present in common usage compilers. */
1011 if (flag_traditional)
1019 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1025 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1029 /* `\%' is used to prevent SCCS from getting confused. */
1032 pedwarn ("non-ANSI escape sequence `\\%c'", c);
1035 if (c >= 040 && c < 0177)
1036 pedwarn ("unknown escape sequence `\\%c'", c);
1038 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1048 strcpy (buf, string);
1050 /* We can't print string and character constants well
1051 because the token_buffer contains the result of processing escapes. */
1053 strcat (buf, " at end of input");
1054 else if (token_buffer[0] == 0)
1055 strcat (buf, " at null character");
1056 else if (token_buffer[0] == '"')
1057 strcat (buf, " before string constant");
1058 else if (token_buffer[0] == '\'')
1059 strcat (buf, " before character constant");
1060 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
1061 sprintf (buf + strlen (buf), " before character 0%o",
1062 (unsigned char) token_buffer[0]);
1064 strcat (buf, " before `%s'");
1066 error (buf, token_buffer);
1076 char long_long_flag;
1079 struct try_type type_sequence[] =
1081 { &integer_type_node, 0, 0, 0},
1082 { &unsigned_type_node, 1, 0, 0},
1083 { &long_integer_type_node, 0, 1, 0},
1084 { &long_unsigned_type_node, 1, 1, 0},
1085 { &long_long_integer_type_node, 0, 1, 1},
1086 { &long_long_unsigned_type_node, 1, 1, 1}
1101 c = nextchar, nextchar = -1;
1106 /* Effectively do c = skip_white_space (c)
1107 but do it faster in the usual cases. */
1120 /* Call skip_white_space so we can warn if appropriate. */
1125 c = skip_white_space (c);
1127 goto found_nonwhite;
1131 token_buffer[0] = c;
1132 token_buffer[1] = 0;
1134 /* yylloc.first_line = lineno; */
1140 token_buffer[0] = 0;
1145 /* Capital L may start a wide-string or wide-character constant. */
1147 register int c = GETC();
1156 goto string_constant;
1163 if (!doing_objc_thang)
1170 /* '@' may start a constant string object. */
1171 register int c = GETC ();
1175 goto string_constant;
1178 /* Fall through to treat '@' as the start of an identifier. */
1181 case 'A': case 'B': case 'C': case 'D': case 'E':
1182 case 'F': case 'G': case 'H': case 'I': case 'J':
1183 case 'K': case 'M': case 'N': case 'O':
1184 case 'P': case 'Q': case 'R': case 'S': case 'T':
1185 case 'U': case 'V': case 'W': case 'X': case 'Y':
1187 case 'a': case 'b': case 'c': case 'd': case 'e':
1188 case 'f': case 'g': case 'h': case 'i': case 'j':
1189 case 'k': case 'l': case 'm': case 'n': case 'o':
1190 case 'p': case 'q': case 'r': case 's': case 't':
1191 case 'u': case 'v': case 'w': case 'x': case 'y':
1197 while (ISALNUM (c) || c == '_' || c == '$' || c == '@')
1199 /* Make sure this char really belongs in an identifier. */
1200 if (c == '@' && ! doing_objc_thang)
1204 if (! dollars_in_ident)
1205 error ("`$' in identifier");
1207 pedwarn ("`$' in identifier");
1210 if (p >= token_buffer + maxtoken)
1211 p = extend_token_buffer (p);
1227 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1230 register struct resword *ptr;
1232 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
1235 yylval.ttype = ridpointers[(int) ptr->rid];
1236 value = (int) ptr->token;
1238 /* Only return OBJECTNAME if it is a typedef. */
1239 if (doing_objc_thang && value == OBJECTNAME)
1241 lastiddecl = lookup_name(yylval.ttype);
1243 if (lastiddecl == NULL_TREE
1244 || TREE_CODE (lastiddecl) != TYPE_DECL)
1248 /* Even if we decided to recognize asm, still perhaps warn. */
1250 && (value == ASM_KEYWORD || value == TYPEOF
1251 || ptr->rid == RID_INLINE)
1252 && token_buffer[0] != '_')
1253 pedwarn ("ANSI does not permit the keyword `%s'",
1258 /* If we did not find a keyword, look for an identifier
1261 if (value == IDENTIFIER)
1263 if (token_buffer[0] == '@')
1264 error("invalid identifier `%s'", token_buffer);
1266 yylval.ttype = get_identifier (token_buffer);
1267 lastiddecl = lookup_name (yylval.ttype);
1269 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1271 /* A user-invisible read-only initialized variable
1272 should be replaced by its value.
1273 We handle only strings since that's the only case used in C. */
1274 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1275 && DECL_IGNORED_P (lastiddecl)
1276 && TREE_READONLY (lastiddecl)
1277 && DECL_INITIAL (lastiddecl) != 0
1278 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1280 tree stringval = DECL_INITIAL (lastiddecl);
1282 /* Copy the string value so that we won't clobber anything
1283 if we put something in the TREE_CHAIN of this one. */
1284 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1285 TREE_STRING_POINTER (stringval));
1288 else if (doing_objc_thang)
1290 tree objc_interface_decl = is_class_name (yylval.ttype);
1292 if (objc_interface_decl)
1295 yylval.ttype = objc_interface_decl;
1305 /* Check first for common special case: single-digit 0 or 1. */
1308 UNGETC (next_c); /* Always undo this lookahead. */
1309 if (!ISALNUM (next_c) && next_c != '.')
1311 token_buffer[0] = (char)c, token_buffer[1] = '\0';
1312 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1318 case '2': case '3': case '4':
1319 case '5': case '6': case '7': case '8': case '9':
1324 int largest_digit = 0;
1326 /* for multi-precision arithmetic,
1327 we actually store only HOST_BITS_PER_CHAR bits in each part.
1328 The number of parts is chosen so as to be sufficient to hold
1329 the enough bits to fit into the two HOST_WIDE_INTs that contain
1330 the integer value (this is always at least as many bits as are
1331 in a target `long long' value, but may be wider). */
1332 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1333 int parts[TOTAL_PARTS];
1336 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1339 for (count = 0; count < TOTAL_PARTS; count++)
1347 *p++ = (c = GETC());
1348 if ((c == 'x') || (c == 'X'))
1351 *p++ = (c = GETC());
1353 /* Leading 0 forces octal unless the 0 is the only digit. */
1354 else if (c >= '0' && c <= '9')
1363 /* Read all the digits-and-decimal-points. */
1366 || (ISALNUM (c) && c != 'l' && c != 'L'
1367 && c != 'u' && c != 'U'
1368 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1369 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1374 error ("floating constant may not be in radix 16");
1375 if (floatflag == TOO_MANY_POINTS)
1376 /* We have already emitted an error. Don't need another. */
1378 else if (floatflag == AFTER_POINT)
1380 error ("malformed floating constant");
1381 floatflag = TOO_MANY_POINTS;
1382 /* Avoid another error from atof by forcing all characters
1383 from here on to be ignored. */
1387 floatflag = AFTER_POINT;
1391 /* Accept '.' as the start of a floating-point number
1392 only when it is followed by a digit.
1393 Otherwise, unread the following non-digit
1394 and use the '.' as a structural token. */
1395 if (p == token_buffer + 2 && !ISDIGIT (c))
1406 error ("parse error at `..'");
1409 token_buffer[1] = 0;
1416 /* It is not a decimal point.
1417 It should be a digit (perhaps a hex digit). */
1423 else if (base <= 10)
1425 if (c == 'e' || c == 'E')
1428 floatflag = AFTER_POINT;
1429 break; /* start of exponent */
1431 error ("nondigits in number and not hexadecimal");
1442 if (c >= largest_digit)
1446 for (count = 0; count < TOTAL_PARTS; count++)
1448 parts[count] *= base;
1452 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1454 &= (1 << HOST_BITS_PER_CHAR) - 1;
1460 /* If the extra highest-order part ever gets anything in it,
1461 the number is certainly too big. */
1462 if (parts[TOTAL_PARTS - 1] != 0)
1465 if (p >= token_buffer + maxtoken - 3)
1466 p = extend_token_buffer (p);
1467 *p++ = (c = GETC());
1472 error ("numeric constant with no digits");
1474 if (largest_digit >= base)
1475 error ("numeric constant contains digits beyond the radix");
1477 /* Remove terminating char from the token buffer and delimit the string */
1480 if (floatflag != NOT_FLOAT)
1482 tree type = double_type_node;
1484 int conversion_errno = 0;
1485 REAL_VALUE_TYPE value;
1488 /* Read explicit exponent if any, and put it in tokenbuf. */
1490 if ((c == 'e') || (c == 'E'))
1492 if (p >= token_buffer + maxtoken - 3)
1493 p = extend_token_buffer (p);
1496 if ((c == '+') || (c == '-'))
1502 error ("floating constant exponent has no digits");
1505 if (p >= token_buffer + maxtoken - 3)
1506 p = extend_token_buffer (p);
1514 /* Convert string to a double, checking for overflow. */
1515 if (setjmp (handler))
1517 error ("floating constant out of range");
1522 int fflag = 0, lflag = 0;
1523 /* Copy token_buffer now, while it has just the number
1524 and not the suffixes; once we add `f' or `i',
1525 REAL_VALUE_ATOF may not work any more. */
1526 char *copy = (char *) alloca (p - token_buffer + 1);
1527 bcopy (token_buffer, copy, p - token_buffer + 1);
1529 set_float_handler (handler);
1535 /* Read the suffixes to choose a data type. */
1540 error ("more than one `f' in numeric constant");
1546 error ("more than one `l' in numeric constant");
1552 error ("more than one `i' or `j' in numeric constant");
1554 pedwarn ("ANSI C forbids imaginary numeric constants");
1565 if (p >= token_buffer + maxtoken - 3)
1566 p = extend_token_buffer (p);
1572 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1573 tells the desired precision of the binary result
1574 of decimal-to-binary conversion. */
1579 error ("both `f' and `l' in floating constant");
1581 type = float_type_node;
1583 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1584 conversion_errno = errno;
1585 /* A diagnostic is required here by some ANSI C testsuites.
1586 This is not pedwarn, become some people don't want
1587 an error for this. */
1588 if (REAL_VALUE_ISINF (value) && pedantic)
1589 warning ("floating point number exceeds range of `float'");
1593 type = long_double_type_node;
1595 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1596 conversion_errno = errno;
1597 if (REAL_VALUE_ISINF (value) && pedantic)
1598 warning ("floating point number exceeds range of `long double'");
1603 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1604 conversion_errno = errno;
1605 if (REAL_VALUE_ISINF (value) && pedantic)
1606 warning ("floating point number exceeds range of `double'");
1609 set_float_handler (NULL_PTR);
1612 /* ERANGE is also reported for underflow,
1613 so test the value to distinguish overflow from that. */
1614 if (conversion_errno == ERANGE && !flag_traditional && pedantic
1615 && (REAL_VALUES_LESS (dconst1, value)
1616 || REAL_VALUES_LESS (value, dconstm1)))
1617 warning ("floating point number exceeds range of `double'");
1620 /* If the result is not a number, assume it must have been
1621 due to some error message above, so silently convert
1623 if (REAL_VALUE_ISNAN (value))
1626 /* Create a node with determined type and value. */
1628 yylval.ttype = build_complex (NULL_TREE,
1629 convert (type, integer_zero_node),
1630 build_real (type, value));
1632 yylval.ttype = build_real (type, value);
1636 tree traditional_type, ansi_type, type;
1637 HOST_WIDE_INT high, low;
1638 int spec_unsigned = 0;
1640 int spec_long_long = 0;
1644 traditional_type = ansi_type = type = NULL_TREE;
1647 if (c == 'u' || c == 'U')
1650 error ("two `u's in integer constant");
1653 else if (c == 'l' || c == 'L')
1658 error ("three `l's in integer constant");
1659 else if (pedantic && ! in_system_header && warn_long_long)
1660 pedwarn ("ANSI C forbids long long integer constants");
1665 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1668 error ("more than one `i' or `j' in numeric constant");
1670 pedwarn ("ANSI C forbids imaginary numeric constants");
1675 if (p >= token_buffer + maxtoken - 3)
1676 p = extend_token_buffer (p);
1681 /* If the constant won't fit in an unsigned long long,
1682 then warn that the constant is out of range. */
1684 /* ??? This assumes that long long and long integer types are
1685 a multiple of 8 bits. This better than the original code
1686 though which assumed that long was exactly 32 bits and long
1687 long was exactly 64 bits. */
1689 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1692 for (i = bytes; i < TOTAL_PARTS; i++)
1696 pedwarn ("integer constant out of range");
1698 /* This is simplified by the fact that our constant
1699 is always positive. */
1703 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1705 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1706 / HOST_BITS_PER_CHAR)]
1707 << (i * HOST_BITS_PER_CHAR));
1708 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1711 yylval.ttype = build_int_2 (low, high);
1712 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1714 /* If warn_traditional, calculate both the ANSI type and the
1715 traditional type, then see if they disagree.
1716 Otherwise, calculate only the type for the dialect in use. */
1717 if (warn_traditional || flag_traditional)
1719 /* Calculate the traditional type. */
1720 /* Traditionally, any constant is signed;
1721 but if unsigned is specified explicitly, obey that.
1722 Use the smallest size with the right number of bits,
1723 except for one special case with decimal constants. */
1724 if (! spec_long && base != 10
1725 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1726 traditional_type = (spec_unsigned ? unsigned_type_node
1727 : integer_type_node);
1728 /* A decimal constant must be long
1729 if it does not fit in type int.
1730 I think this is independent of whether
1731 the constant is signed. */
1732 else if (! spec_long && base == 10
1733 && int_fits_type_p (yylval.ttype, integer_type_node))
1734 traditional_type = (spec_unsigned ? unsigned_type_node
1735 : integer_type_node);
1736 else if (! spec_long_long)
1737 traditional_type = (spec_unsigned ? long_unsigned_type_node
1738 : long_integer_type_node);
1740 traditional_type = (spec_unsigned
1741 ? long_long_unsigned_type_node
1742 : long_long_integer_type_node);
1744 if (warn_traditional || ! flag_traditional)
1746 /* Calculate the ANSI type. */
1747 if (! spec_long && ! spec_unsigned
1748 && int_fits_type_p (yylval.ttype, integer_type_node))
1749 ansi_type = integer_type_node;
1750 else if (! spec_long && (base != 10 || spec_unsigned)
1751 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1752 ansi_type = unsigned_type_node;
1753 else if (! spec_unsigned && !spec_long_long
1754 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1755 ansi_type = long_integer_type_node;
1756 else if (! spec_long_long
1757 && int_fits_type_p (yylval.ttype,
1758 long_unsigned_type_node))
1759 ansi_type = long_unsigned_type_node;
1760 else if (! spec_unsigned
1761 && int_fits_type_p (yylval.ttype,
1762 long_long_integer_type_node))
1763 ansi_type = long_long_integer_type_node;
1765 ansi_type = long_long_unsigned_type_node;
1768 type = flag_traditional ? traditional_type : ansi_type;
1770 if (warn_traditional && traditional_type != ansi_type)
1772 if (TYPE_PRECISION (traditional_type)
1773 != TYPE_PRECISION (ansi_type))
1774 warning ("width of integer constant changes with -traditional");
1775 else if (TREE_UNSIGNED (traditional_type)
1776 != TREE_UNSIGNED (ansi_type))
1777 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1779 warning ("width of integer constant may change on other systems with -traditional");
1782 if (pedantic && !flag_traditional && !spec_long_long && !warn
1783 && (TYPE_PRECISION (long_integer_type_node)
1784 < TYPE_PRECISION (type)))
1785 pedwarn ("integer constant out of range");
1787 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1788 warning ("decimal constant is so large that it is unsigned");
1792 if (TYPE_PRECISION (type)
1793 <= TYPE_PRECISION (integer_type_node))
1795 = build_complex (NULL_TREE, integer_zero_node,
1796 convert (integer_type_node,
1799 error ("complex integer constant is too wide for `complex int'");
1801 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1802 /* The traditional constant 0x80000000 is signed
1803 but doesn't fit in the range of int.
1804 This will change it to -0x80000000, which does fit. */
1806 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1807 yylval.ttype = convert (type, yylval.ttype);
1808 TREE_OVERFLOW (yylval.ttype)
1809 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1812 TREE_TYPE (yylval.ttype) = type;
1818 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
1819 || (!flag_traditional && (c == '-' || c == '+')
1820 && (p[-1] == 'e' || p[-1] == 'E')))
1821 error ("missing white space after number `%s'", token_buffer);
1823 value = CONSTANT; break;
1829 register int result = 0;
1830 register int num_chars = 0;
1832 unsigned width = TYPE_PRECISION (char_type_node);
1834 #ifdef MULTIBYTE_CHARS
1835 int longest_char = local_mb_cur_max ();
1836 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
1839 max_chars = TYPE_PRECISION (integer_type_node) / width;
1841 width = WCHAR_TYPE_SIZE;
1848 if (c == '\'' || c == EOF)
1855 c = readescape (&ignore);
1858 if (width < HOST_BITS_PER_INT
1859 && (unsigned) c >= ((unsigned)1 << width))
1860 pedwarn ("escape sequence out of range for character");
1861 #ifdef MAP_CHARACTER
1863 c = MAP_CHARACTER (c);
1869 pedwarn ("ANSI C forbids newline in character constant");
1874 #ifdef MULTIBYTE_CHARS
1878 for (i = 1; i <= longest_char; ++i)
1880 if (i > maxtoken - 4)
1881 extend_token_buffer (token_buffer);
1883 token_buffer[i] = c;
1884 char_len = local_mbtowc (& wc,
1893 /* mbtowc sometimes needs an extra char before accepting */
1898 /* Merge character into result; ignore excess chars. */
1899 for (i = 1; i <= char_len; ++i)
1903 if (width < HOST_BITS_PER_INT)
1904 result = (result << width)
1906 & ((1 << width) - 1));
1908 result = token_buffer[i];
1910 num_chars += char_len;
1918 warning ("Ignoring invalid multibyte character");
1921 #ifdef MAP_CHARACTER
1923 c = MAP_CHARACTER (c);
1926 #else /* ! MULTIBYTE_CHARS */
1927 #ifdef MAP_CHARACTER
1928 c = MAP_CHARACTER (c);
1930 #endif /* ! MULTIBYTE_CHARS */
1935 if (chars_seen == 1) /* only keep the first one */
1940 /* Merge character into result; ignore excess chars. */
1941 num_chars += (width / TYPE_PRECISION (char_type_node));
1942 if (num_chars < max_chars + 1)
1944 if (width < HOST_BITS_PER_INT)
1945 result = (result << width) | (c & ((1 << width) - 1));
1952 error ("malformatted character constant");
1953 else if (chars_seen == 0)
1954 error ("empty character constant");
1955 else if (num_chars > max_chars)
1957 num_chars = max_chars;
1958 error ("character constant too long");
1960 else if (chars_seen != 1 && ! flag_traditional && warn_multichar)
1961 warning ("multi-character character constant");
1963 /* If char type is signed, sign-extend the constant. */
1966 int num_bits = num_chars * width;
1968 /* We already got an error; avoid invalid shift. */
1969 yylval.ttype = build_int_2 (0, 0);
1970 else if (TREE_UNSIGNED (char_type_node)
1971 || ((result >> (num_bits - 1)) & 1) == 0)
1973 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
1974 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1978 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
1979 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1981 TREE_TYPE (yylval.ttype) = integer_type_node;
1985 yylval.ttype = build_int_2 (result, 0);
1986 TREE_TYPE (yylval.ttype) = wchar_type_node;
1996 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
1997 : TYPE_PRECISION (char_type_node);
1998 #ifdef MULTIBYTE_CHARS
1999 int longest_char = local_mb_cur_max ();
2000 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
2003 p = token_buffer + 1;
2005 while (c != '"' && c >= 0)
2010 c = readescape (&ignore);
2013 if (width < HOST_BITS_PER_INT
2014 && (unsigned) c >= ((unsigned)1 << width))
2015 pedwarn ("escape sequence out of range for character");
2020 pedwarn ("ANSI C forbids newline in string constant");
2025 #ifdef MULTIBYTE_CHARS
2029 for (i = 0; i < longest_char; ++i)
2031 if (p + i >= token_buffer + maxtoken)
2032 p = extend_token_buffer (p);
2035 char_len = local_mbtowc (& wc, p, i + 1);
2041 warning ("Ignoring invalid multibyte character");
2044 /* mbtowc sometimes needs an extra char before accepting */
2055 #endif /* MULTIBYTE_CHARS */
2058 /* Add this single character into the buffer either as a wchar_t
2059 or as a single byte. */
2062 unsigned width = TYPE_PRECISION (char_type_node);
2063 unsigned bytemask = (1 << width) - 1;
2066 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2067 p = extend_token_buffer (p);
2069 for (byte = 0; byte < WCHAR_BYTES; ++byte)
2072 if (byte >= (int) sizeof (c))
2075 value = (c >> (byte * width)) & bytemask;
2076 if (BYTES_BIG_ENDIAN)
2077 p[WCHAR_BYTES - byte - 1] = value;
2085 if (p >= token_buffer + maxtoken)
2086 p = extend_token_buffer (p);
2094 /* Terminate the string value, either with a single byte zero
2095 or with a wide zero. */
2098 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2099 p = extend_token_buffer (p);
2100 bzero (p, WCHAR_BYTES);
2105 if (p >= token_buffer + maxtoken)
2106 p = extend_token_buffer (p);
2111 error ("Unterminated string constant");
2113 /* We have read the entire constant.
2114 Construct a STRING_CST for the result. */
2118 yylval.ttype = build_string (p - (token_buffer + 1),
2120 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2125 /* Return an Objective-C @"..." constant string object. */
2126 yylval.ttype = build_objc_string (p - (token_buffer + 1),
2128 TREE_TYPE (yylval.ttype) = char_array_type_node;
2129 value = OBJC_STRING;
2133 yylval.ttype = build_string (p - (token_buffer + 1),
2135 TREE_TYPE (yylval.ttype) = char_array_type_node;
2163 yylval.code = PLUS_EXPR; break;
2165 yylval.code = MINUS_EXPR; break;
2167 yylval.code = BIT_AND_EXPR; break;
2169 yylval.code = BIT_IOR_EXPR; break;
2171 yylval.code = MULT_EXPR; break;
2173 yylval.code = TRUNC_DIV_EXPR; break;
2175 yylval.code = TRUNC_MOD_EXPR; break;
2177 yylval.code = BIT_XOR_EXPR; break;
2179 yylval.code = LSHIFT_EXPR; break;
2181 yylval.code = RSHIFT_EXPR; break;
2183 yylval.code = LT_EXPR; break;
2185 yylval.code = GT_EXPR; break;
2188 token_buffer[1] = c1 = GETC();
2189 token_buffer[2] = 0;
2196 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2198 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2200 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2202 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2204 value = ASSIGN; goto done;
2210 value = PLUSPLUS; goto done;
2212 value = MINUSMINUS; goto done;
2214 value = ANDAND; goto done;
2216 value = OROR; goto done;
2229 { value = POINTSAT; goto done; }
2233 { value = ']'; goto done; }
2237 { value = '{'; indent_level++; goto done; }
2239 { value = '['; goto done; }
2243 { value = '}'; indent_level--; goto done; }
2247 token_buffer[1] = 0;
2249 if ((c == '<') || (c == '>'))
2250 value = ARITHCOMPARE;
2256 /* Don't make yyparse think this is eof. */
2275 /* yylloc.last_line = lineno; */
2280 /* Sets the value of the 'yydebug' variable to VALUE.
2281 This is a function so we don't have to have YYDEBUG defined
2282 in order to build the compiler. */
2291 warning ("YYDEBUG not defined.");