1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
3 1998, 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
39 /* MULTIBYTE_CHARS support only works for native compilers.
40 ??? Ideally what we want is to model widechar support after
41 the current floating point support. */
43 #undef MULTIBYTE_CHARS
46 #ifdef MULTIBYTE_CHARS
49 #endif /* MULTIBYTE_CHARS */
50 #ifndef GET_ENVIRONMENT
51 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME))
56 extern cpp_reader parse_in;
57 extern cpp_options parse_options;
59 /* Stream for reading from the input file. */
63 extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
65 /* Cause the `yydebug' variable to be defined. */
69 extern unsigned char *yy_cur, *yy_lim;
70 extern enum cpp_token cpp_token;
72 extern int yy_get_token ();
74 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
75 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
77 #else /* ! USE_CPPLIB */
79 #define GETC() getch ()
80 #define UNGETC(c) put_back (c)
82 struct putback_buffer {
83 unsigned char *buffer;
88 static struct putback_buffer putback = {NULL, 0, -1};
90 static inline int getch PARAMS ((void));
95 if (putback.index != -1)
97 int ch = putback.buffer[putback.index];
101 return getc (finput);
104 static inline void put_back PARAMS ((int));
112 if (putback.index == putback.buffer_size - 1)
114 putback.buffer_size += 16;
115 putback.buffer = xrealloc (putback.buffer, putback.buffer_size);
117 putback.buffer[++putback.index] = ch;
120 #endif /* ! USE_CPPLIB */
126 /* File used for outputting assembler code. */
127 extern FILE *asm_out_file;
129 #undef WCHAR_TYPE_SIZE
130 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
132 /* Number of bytes in a wide character. */
133 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
135 static int maxtoken; /* Current nominal length of token buffer. */
136 char *token_buffer; /* Pointer to token buffer.
137 Actual allocated length is maxtoken + 2.
138 This is not static because objc-parse.y uses it. */
140 static int indent_level; /* Number of { minus number of }. */
142 /* Nonzero tells yylex to ignore \ in string constants. */
143 static int ignore_escape_flag;
145 /* Nonzero if end-of-file has been seen on input. */
146 static int end_of_file;
148 #ifdef HANDLE_GENERIC_PRAGMAS
149 static int handle_generic_pragma PARAMS ((int));
150 #endif /* HANDLE_GENERIC_PRAGMAS */
151 static int whitespace_cr PARAMS ((int));
152 static int skip_white_space PARAMS ((int));
153 static char *extend_token_buffer PARAMS ((const char *));
154 static int readescape PARAMS ((int *));
155 static void parse_float PARAMS ((PTR));
156 static void extend_token_buffer_to PARAMS ((int));
157 static int read_line_number PARAMS ((int *));
159 /* Do not insert generated code into the source, instead, include it.
160 This allows us to build gcc automatically even for targets that
161 need to add or modify the reserved keyword lists. */
164 /* Return something to represent absolute declarators containing a *.
165 TARGET is the absolute declarator that the * contains.
166 TYPE_QUALS is a list of modifiers such as const or volatile
167 to apply to the pointer type, represented as identifiers.
169 We return an INDIRECT_REF whose "contents" are TARGET
170 and whose type is the modifier list. */
173 make_pointer_declarator (type_quals, target)
174 tree type_quals, target;
176 return build1 (INDIRECT_REF, type_quals, target);
180 forget_protocol_qualifiers ()
182 int i, n = sizeof wordlist / sizeof (struct resword);
184 for (i = 0; i < n; i++)
185 if ((int) wordlist[i].rid >= (int) RID_IN
186 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
187 wordlist[i].name = "";
191 remember_protocol_qualifiers ()
193 int i, n = sizeof wordlist / sizeof (struct resword);
195 for (i = 0; i < n; i++)
196 if (wordlist[i].rid == RID_IN)
197 wordlist[i].name = "in";
198 else if (wordlist[i].rid == RID_OUT)
199 wordlist[i].name = "out";
200 else if (wordlist[i].rid == RID_INOUT)
201 wordlist[i].name = "inout";
202 else if (wordlist[i].rid == RID_BYCOPY)
203 wordlist[i].name = "bycopy";
204 else if (wordlist[i].rid == RID_BYREF)
205 wordlist[i].name = "byref";
206 else if (wordlist[i].rid == RID_ONEWAY)
207 wordlist[i].name = "oneway";
211 init_parse (filename)
212 const char *filename;
215 /* Open input file. */
216 if (filename == 0 || !strcmp (filename, "-"))
222 finput = fopen (filename, "r");
224 pfatal_with_name (filename);
226 #ifdef IO_BUFFER_SIZE
227 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
229 #else /* !USE_CPPLIB */
230 parse_in.show_column = 1;
231 if (! cpp_start_read (&parse_in, filename))
234 if (filename == 0 || !strcmp (filename, "-"))
237 /* cpp_start_read always puts at least one line directive into the
238 token buffer. We must arrange to read it out here. */
239 yy_cur = parse_in.token_buffer;
240 yy_lim = CPP_PWRITTEN (&parse_in);
241 cpp_token = CPP_DIRECTIVE;
256 cpp_finish (&parse_in);
257 errorcount += parse_in.errors;
266 /* Make identifier nodes long enough for the language-specific slots. */
267 set_identifier_size (sizeof (struct lang_identifier));
269 /* Start it at 0, because check_newline is called at the very beginning
270 and will increment it to 1. */
273 #ifdef MULTIBYTE_CHARS
274 /* Change to the native locale for multibyte conversions. */
275 setlocale (LC_CTYPE, "");
276 GET_ENVIRONMENT (literal_codeset, "LANG");
280 token_buffer = (char *) xmalloc (maxtoken + 2);
282 ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
283 ridpointers[(int) RID_INT] = get_identifier ("int");
284 ridpointers[(int) RID_CHAR] = get_identifier ("char");
285 ridpointers[(int) RID_VOID] = get_identifier ("void");
286 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
287 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
288 ridpointers[(int) RID_SHORT] = get_identifier ("short");
289 ridpointers[(int) RID_LONG] = get_identifier ("long");
290 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
291 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
292 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
293 ridpointers[(int) RID_CONST] = get_identifier ("const");
294 ridpointers[(int) RID_RESTRICT] = get_identifier ("restrict");
295 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
296 ridpointers[(int) RID_BOUNDED] = get_identifier ("__bounded");
297 ridpointers[(int) RID_UNBOUNDED] = get_identifier ("__unbounded");
298 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
299 ridpointers[(int) RID_STATIC] = get_identifier ("static");
300 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
301 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
302 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
303 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
304 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
305 ridpointers[(int) RID_ID] = get_identifier ("id");
306 ridpointers[(int) RID_IN] = get_identifier ("in");
307 ridpointers[(int) RID_OUT] = get_identifier ("out");
308 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
309 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
310 ridpointers[(int) RID_BYREF] = get_identifier ("byref");
311 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
312 forget_protocol_qualifiers();
314 /* Some options inhibit certain reserved words.
315 Clear those words out of the hash table so they won't be recognized. */
316 #define UNSET_RESERVED_WORD(STRING) \
317 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
318 if (s) s->name = ""; } while (0)
320 if (! doing_objc_thang)
321 UNSET_RESERVED_WORD ("id");
323 if (flag_traditional)
325 UNSET_RESERVED_WORD ("const");
326 UNSET_RESERVED_WORD ("restrict");
327 UNSET_RESERVED_WORD ("volatile");
328 UNSET_RESERVED_WORD ("typeof");
329 UNSET_RESERVED_WORD ("signed");
330 UNSET_RESERVED_WORD ("inline");
331 UNSET_RESERVED_WORD ("iterator");
332 UNSET_RESERVED_WORD ("complex");
334 else if (!flag_isoc99)
335 UNSET_RESERVED_WORD ("restrict");
339 UNSET_RESERVED_WORD ("asm");
340 UNSET_RESERVED_WORD ("typeof");
341 UNSET_RESERVED_WORD ("inline");
342 UNSET_RESERVED_WORD ("iterator");
343 UNSET_RESERVED_WORD ("complex");
348 reinit_parse_for_function ()
352 /* Function used when yydebug is set, to print a token in more detail. */
355 yyprint (file, yychar, yylval)
367 if (IDENTIFIER_POINTER (t))
368 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
373 if (TREE_CODE (t) == INTEGER_CST)
375 #if HOST_BITS_PER_WIDE_INT == 64
376 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
379 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
386 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
392 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
397 /* Iff C is a carriage return, warn about it - if appropriate -
398 and return nonzero. */
404 static int newline_warning = 0;
408 /* ANSI C says the effects of a carriage return in a source file
410 if (pedantic && !newline_warning)
412 warning ("carriage return in source file");
413 warning ("(we only warn about the first carriage return)");
421 /* If C is not whitespace, return C.
422 Otherwise skip whitespace and return first nonwhite char read. */
432 /* We don't recognize comments here, because
433 cpp output can include / and * consecutively as operators.
434 Also, there's no need, since cpp removes all comments. */
442 c = check_newline ();
451 /* While processing a # directive we don't get CPP_HSPACE
452 tokens, so we also need to handle whitespace the normal way. */
453 if (cpp_token == CPP_HSPACE)
470 error ("stray '\\' in program");
480 /* Skips all of the white space at the current location in the input file. */
483 position_after_white_space ()
489 UNGETC (skip_white_space (c));
492 /* Make the token buffer longer, preserving the data in it.
493 P should point to just beyond the last valid character in the old buffer.
494 The value we return is a pointer to the new buffer
495 at a place corresponding to P. */
498 extend_token_buffer_to (size)
502 maxtoken = maxtoken * 2 + 10;
503 while (maxtoken < size);
504 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
508 extend_token_buffer (p)
511 int offset = p - token_buffer;
512 extend_token_buffer_to (offset);
513 return token_buffer + offset;
516 #if defined HANDLE_PRAGMA
517 /* Local versions of these macros, that can be passed as function pointers. */
533 read_line_number (num)
536 register int token = yylex ();
538 if (token == CONSTANT
539 && TREE_CODE (yylval.ttype) == INTEGER_CST)
541 *num = TREE_INT_CST_LOW (yylval.ttype);
546 if (token != END_OF_LINE)
547 error ("invalid #-line");
552 /* At the beginning of a line, increment the line number
553 and process any #-directive on this line.
554 If the line is a #-directive, read the entire line and return a newline.
555 Otherwise, return the line's first non-whitespace character.
557 Note that in the case of USE_CPPLIB, we get the whole line as one
558 CPP_DIRECTIVE token. */
566 enum { act_none, act_push, act_pop } action;
567 int old_lineno, action_number, l;
570 /* Read first nonwhite char on the line. */
574 /* In some cases where we're leaving an include file, we can get multiple
575 CPP_HSPACE tokens in a row, so we need to loop. */
576 while (cpp_token == CPP_HSPACE)
581 while (c == ' ' || c == '\t');
588 /* Sequences of multiple newlines are very common; optimize them. */
592 /* If not #, return it so caller will use it. */
596 /* Don't read beyond this line. */
601 if (cpp_token == CPP_VSPACE)
603 /* Format is "<space> <line number> <filename> <newline>".
604 Only the line number is interesting, and even that
605 we can get more efficiently than scanning the line. */
607 lineno = parse_in.lineno - 1;
614 if (token == IDENTIFIER)
616 /* If a letter follows, then if the word here is `line', skip
617 it and ignore it; otherwise, ignore the line, with an error
618 if the word isn't `pragma'. */
620 const char *name = IDENTIFIER_POINTER (yylval.ttype);
622 if (!strcmp (name, "pragma"))
625 if (token != IDENTIFIER
626 || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
630 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
631 (if both are defined), in order to give the back
632 end a chance to override the interpretation of
633 SYSV style pragmas. */
634 if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
635 IDENTIFIER_POINTER (yylval.ttype)))
637 #endif /* HANDLE_PRAGMA */
639 #ifdef HANDLE_GENERIC_PRAGMAS
640 if (handle_generic_pragma (token))
642 #endif /* HANDLE_GENERIC_PRAGMAS */
644 /* Issue a warning message if we have been asked to do so.
645 Ignoring unknown pragmas in system header file unless
646 an explcit -Wunknown-pragmas has been given. */
647 if (warn_unknown_pragmas > 1
648 || (warn_unknown_pragmas && ! in_system_header))
649 warning ("ignoring pragma: %s", token_buffer);
653 else if (!strcmp (name, "define"))
655 debug_define (lineno, GET_DIRECTIVE_LINE ());
658 else if (!strcmp (name, "undef"))
660 debug_undef (lineno, GET_DIRECTIVE_LINE ());
663 else if (!strcmp (name, "line"))
669 else if (!strcmp (name, "ident"))
671 /* #ident. The pedantic warning is now in cpp. */
673 /* Here we have just seen `#ident '.
674 A string constant should follow. */
677 if (token == END_OF_LINE)
680 || TREE_CODE (yylval.ttype) != STRING_CST)
682 error ("invalid #ident");
688 #ifdef ASM_OUTPUT_IDENT
689 ASM_OUTPUT_IDENT (asm_out_file,
690 TREE_STRING_POINTER (yylval.ttype));
694 /* Skip the rest of this line. */
698 error ("undefined or invalid # directive `%s'", name);
702 /* If the # is the only nonwhite char on the line,
703 just ignore it. Check the new newline. */
704 if (token == END_OF_LINE)
708 /* Here we have either `#line' or `# <nonletter>'.
709 In either case, it should be a line number; a digit should follow. */
711 if (token != CONSTANT
712 || TREE_CODE (yylval.ttype) != INTEGER_CST)
714 error ("invalid #-line");
718 /* subtract one, because it is the following line that
719 gets the specified number */
721 l = TREE_INT_CST_LOW (yylval.ttype) - 1;
723 /* More follows: it must be a string constant (filename).
724 It would be neat to use cpplib to quickly process the string, but
725 (1) we don't have a handy tokenization of the string, and
726 (2) I don't know how well that would work in the presense
727 of filenames that contain wide characters. */
731 /* Don't treat \ as special if we are processing #line 1 "...".
732 If you want it to be treated specially, use # 1 "...". */
733 ignore_escape_flag = 1;
736 /* Read the string constant. */
739 ignore_escape_flag = 0;
741 if (token == END_OF_LINE)
743 /* No more: store the line number and check following line. */
748 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
750 error ("invalid #line");
754 input_filename = TREE_STRING_POINTER (yylval.ttype);
756 if (main_input_filename == 0)
757 main_input_filename = input_filename;
764 /* Each change of file name
765 reinitializes whether we are now in a system header. */
766 in_system_header = 0;
768 if (!read_line_number (&action_number))
770 /* Update the name in the top element of input_file_stack. */
771 if (input_file_stack)
772 input_file_stack->name = input_filename;
775 /* `1' after file name means entering new file.
776 `2' after file name means just left a file. */
778 if (action_number == 1)
781 read_line_number (&action_number);
783 else if (action_number == 2)
786 read_line_number (&action_number);
788 if (action_number == 3)
790 /* `3' after file name means this is a system header file. */
791 in_system_header = 1;
792 read_line_number (&action_number);
795 /* Do the actions implied by the preceding numbers. */
797 if (action == act_push)
799 /* Pushing to a new file. */
801 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
802 input_file_stack->line = old_lineno;
803 p->next = input_file_stack;
804 p->name = input_filename;
805 p->indent_level = indent_level;
806 input_file_stack = p;
807 input_file_stack_tick++;
808 debug_start_source_file (input_filename);
810 else if (action == act_pop)
812 /* Popping out of a file. */
813 if (input_file_stack->next)
815 struct file_stack *p = input_file_stack;
816 if (indent_level != p->indent_level)
818 warning_with_file_and_line
819 (p->name, old_lineno,
820 "This file contains more `%c's than `%c's.",
821 indent_level > p->indent_level ? '{' : '}',
822 indent_level > p->indent_level ? '}' : '{');
824 input_file_stack = p->next;
826 input_file_stack_tick++;
827 debug_end_source_file (input_file_stack->line);
830 error ("#-lines for entering and leaving files don't match");
833 /* Now that we've pushed or popped the input stack,
834 update the name in the top element. */
835 if (input_file_stack)
836 input_file_stack->name = input_filename;
838 /* skip the rest of this line. */
845 while (c != '\n' && c != EOF);
849 #ifdef HANDLE_GENERIC_PRAGMAS
851 /* Handle a #pragma directive.
852 TOKEN is the token we read after `#pragma'. Processes the entire input
853 line and return non-zero iff the pragma has been successfully parsed. */
855 /* This function has to be in this file, in order to get at
859 handle_generic_pragma (token)
870 handle_pragma_token (token_buffer, yylval.ttype);
874 return handle_pragma_token (NULL_PTR, NULL_TREE);
877 handle_pragma_token (token_buffer, NULL);
884 #endif /* HANDLE_GENERIC_PRAGMAS */
886 #define ENDFILE -1 /* token that represents end-of-file */
888 /* Read an escape sequence, returning its equivalent as a character,
889 or store 1 in *ignore_ptr if it is backslash-newline. */
892 readescape (ignore_ptr)
895 register int c = GETC();
897 register unsigned count;
898 unsigned firstdig = 0;
904 if (warn_traditional)
905 warning ("the meaning of `\\x' varies with -traditional");
907 if (flag_traditional)
922 if (c >= 'a' && c <= 'f')
923 code += c - 'a' + 10;
924 if (c >= 'A' && c <= 'F')
925 code += c - 'A' + 10;
926 if (c >= '0' && c <= '9')
928 if (code != 0 || count != 0)
938 warning ("\\x used with no following hex digits");
942 /* Digits are all 0's. Ok. */
944 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
947 << (TYPE_PRECISION (integer_type_node)
950 pedwarn ("hex escape out of range");
953 case '0': case '1': case '2': case '3': case '4':
954 case '5': case '6': case '7':
957 while ((c <= '7') && (c >= '0') && (count++ < 3))
959 code = (code * 8) + (c - '0');
965 case '\\': case '\'': case '"':
974 return TARGET_NEWLINE;
989 if (warn_traditional)
990 warning ("the meaning of `\\a' varies with -traditional");
992 if (flag_traditional)
997 #if 0 /* Vertical tab is present in common usage compilers. */
998 if (flag_traditional)
1006 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1012 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1016 /* `\%' is used to prevent SCCS from getting confused. */
1019 pedwarn ("unknown escape sequence `\\%c'", c);
1023 pedwarn ("unknown escape sequence `\\%c'", c);
1025 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1033 const char *string = _(msgid);
1035 /* We can't print string and character constants well
1036 because the token_buffer contains the result of processing escapes. */
1038 error ("%s at end of input", string);
1039 else if (token_buffer[0] == 0)
1040 error ("%s at null character", string);
1041 else if (token_buffer[0] == '"')
1042 error ("%s before string constant", string);
1043 else if (token_buffer[0] == '\'')
1044 error ("%s before character constant", string);
1045 else if (!ISGRAPH(token_buffer[0]))
1046 error ("%s before character 0%o", string, (unsigned char) token_buffer[0]);
1048 error ("%s before `%s'", string, token_buffer);
1058 char long_long_flag;
1061 struct try_type type_sequence[] =
1063 { &integer_type_node, 0, 0, 0},
1064 { &unsigned_type_node, 1, 0, 0},
1065 { &long_integer_type_node, 0, 1, 0},
1066 { &long_unsigned_type_node, 1, 1, 0},
1067 { &long_long_integer_type_node, 0, 1, 1},
1068 { &long_long_unsigned_type_node, 1, 1, 1}
1082 int conversion_errno;
1083 REAL_VALUE_TYPE value;
1090 struct pf_args * args = (struct pf_args *) data;
1091 int fflag = 0, lflag = 0;
1092 /* Copy token_buffer now, while it has just the number
1093 and not the suffixes; once we add `f' or `i',
1094 REAL_VALUE_ATOF may not work any more. */
1095 char *copy = (char *) alloca (args->p - token_buffer + 1);
1096 bcopy (token_buffer, copy, args->p - token_buffer + 1);
1098 args->conversion_errno = 0;
1099 args->type = double_type_node;
1105 /* Read the suffixes to choose a data type. */
1110 error ("more than one `f' in numeric constant");
1116 error ("more than one `l' in numeric constant");
1122 error ("more than one `i' or `j' in numeric constant");
1124 pedwarn ("ANSI C forbids imaginary numeric constants");
1135 if (args->p >= token_buffer + maxtoken - 3)
1136 args->p = extend_token_buffer (args->p);
1137 *(args->p++) = args->c;
1142 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1143 tells the desired precision of the binary result
1144 of decimal-to-binary conversion. */
1149 error ("both `f' and `l' in floating constant");
1151 args->type = float_type_node;
1153 if (args->base == 16)
1154 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
1156 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
1157 args->conversion_errno = errno;
1158 /* A diagnostic is required here by some ANSI C testsuites.
1159 This is not pedwarn, because some people don't want
1160 an error for this. */
1161 if (REAL_VALUE_ISINF (args->value) && pedantic)
1162 warning ("floating point number exceeds range of `float'");
1166 args->type = long_double_type_node;
1168 if (args->base == 16)
1169 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
1171 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
1172 args->conversion_errno = errno;
1173 if (REAL_VALUE_ISINF (args->value) && pedantic)
1174 warning ("floating point number exceeds range of `long double'");
1179 if (args->base == 16)
1180 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
1182 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
1183 args->conversion_errno = errno;
1184 if (REAL_VALUE_ISINF (args->value) && pedantic)
1185 warning ("floating point number exceeds range of `double'");
1189 /* Get the next character, staying within the current token if possible.
1190 If we're lexing a token, we don't want to look beyond the end of the
1191 token cpplib has prepared for us; otherwise, we end up reading in the
1192 next token, which screws up feed_input. So just return a null
1195 static inline int token_getch PARAMS ((void));
1201 if (yy_cur == yy_lim)
1207 static inline void token_put_back PARAMS ((int));
1220 /* Read a single token from the input stream, and assign it lexical
1234 /* Effectively do c = skip_white_space (c)
1235 but do it faster in the usual cases. */
1245 if (cpp_token == CPP_HSPACE)
1246 c = yy_get_token ();
1253 /* Call skip_white_space so we can warn if appropriate. */
1258 c = skip_white_space (c);
1260 goto found_nonwhite;
1264 token_buffer[0] = c;
1265 token_buffer[1] = 0;
1267 /* yylloc.first_line = lineno; */
1273 token_buffer[0] = 0;
1275 value = END_OF_LINE;
1282 if (cpp_token == CPP_NAME)
1285 /* Capital L may start a wide-string or wide-character constant. */
1287 register int c = token_getch();
1296 goto string_constant;
1303 if (!doing_objc_thang)
1310 /* '@' may start a constant string object. */
1311 register int c = token_getch ();
1315 goto string_constant;
1318 /* Fall through to treat '@' as the start of an identifier. */
1321 case 'A': case 'B': case 'C': case 'D': case 'E':
1322 case 'F': case 'G': case 'H': case 'I': case 'J':
1323 case 'K': case 'M': case 'N': case 'O':
1324 case 'P': case 'Q': case 'R': case 'S': case 'T':
1325 case 'U': case 'V': case 'W': case 'X': case 'Y':
1327 case 'a': case 'b': case 'c': case 'd': case 'e':
1328 case 'f': case 'g': case 'h': case 'i': case 'j':
1329 case 'k': case 'l': case 'm': case 'n': case 'o':
1330 case 'p': case 'q': case 'r': case 's': case 't':
1331 case 'u': case 'v': case 'w': case 'x': case 'y':
1337 if (cpp_token == CPP_NAME)
1339 /* Note that one character has already been read from
1340 yy_cur into token_buffer. Also, cpplib complains about
1341 $ in identifiers, so we don't have to. */
1343 int len = yy_lim - yy_cur + 1;
1344 if (len >= maxtoken)
1345 extend_token_buffer_to (len + 1);
1346 memcpy (token_buffer + 1, yy_cur, len);
1347 p = token_buffer + len;
1354 while (ISALNUM (c) || c == '_' || c == '$' || c == '@')
1356 /* Make sure this char really belongs in an identifier. */
1359 if (! dollars_in_ident)
1360 error ("`$' in identifier");
1362 pedwarn ("`$' in identifier");
1365 if (p >= token_buffer + maxtoken)
1366 p = extend_token_buffer (p);
1379 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1382 register struct resword *ptr;
1384 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
1387 yylval.ttype = ridpointers[(int) ptr->rid];
1388 value = (int) ptr->token;
1390 /* Only return OBJECTNAME if it is a typedef. */
1391 if (doing_objc_thang && value == OBJECTNAME)
1393 tree decl = lookup_name(yylval.ttype);
1395 if (decl == NULL_TREE
1396 || TREE_CODE (decl) != TYPE_DECL)
1400 /* Even if we decided to recognize asm, still perhaps warn. */
1402 && (value == ASM_KEYWORD || value == TYPEOF
1403 || ptr->rid == RID_INLINE)
1404 && token_buffer[0] != '_')
1405 pedwarn ("ANSI does not permit the keyword `%s'",
1410 /* If we did not find a keyword, look for an identifier
1413 if (value == IDENTIFIER)
1417 if (token_buffer[0] == '@')
1418 error("invalid identifier `%s'", token_buffer);
1420 yylval.ttype = get_identifier (token_buffer);
1421 decl = lookup_name (yylval.ttype);
1423 if (decl != 0 && TREE_CODE (decl) == TYPE_DECL)
1425 /* A user-invisible read-only initialized variable
1426 should be replaced by its value.
1427 We handle only strings since that's the only case used in C. */
1428 else if (decl != 0 && TREE_CODE (decl) == VAR_DECL
1429 && DECL_IGNORED_P (decl)
1430 && TREE_READONLY (decl)
1431 && DECL_INITIAL (decl) != 0
1432 && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
1434 tree stringval = DECL_INITIAL (decl);
1436 /* Copy the string value so that we won't clobber anything
1437 if we put something in the TREE_CHAIN of this one. */
1438 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1439 TREE_STRING_POINTER (stringval));
1442 else if (doing_objc_thang)
1444 tree objc_interface_decl = is_class_name (yylval.ttype);
1446 if (objc_interface_decl)
1449 yylval.ttype = objc_interface_decl;
1458 if (yy_cur < yy_lim)
1461 /* It's hard to preserve tokenization on '.' because
1462 it could be a symbol by itself, or it could be the
1463 start of a floating point number and cpp won't tell us. */
1464 register int c1 = token_getch ();
1465 token_buffer[1] = c1;
1468 c1 = token_getch ();
1471 token_buffer[2] = c1;
1472 token_buffer[3] = 0;
1476 error ("parse error at `..'");
1480 token_put_back (c1);
1483 token_put_back (c1);
1486 token_buffer[1] = 0;
1490 /* Optimize for most frequent case. */
1495 cond = (yy_cur == yy_lim);
1497 register int c1 = token_getch ();
1498 token_put_back (c1);
1499 cond = (! ISALNUM (c1) && c1 != '.');
1503 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1509 case '2': case '3': case '4':
1510 case '5': case '6': case '7': case '8': case '9':
1515 int largest_digit = 0;
1519 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
1520 The code below which fills the parts array assumes that a host
1521 int is at least twice as wide as a host char, and that
1522 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
1523 Two HOST_WIDE_INTs is the largest int literal we can store.
1524 In order to detect overflow below, the number of parts (TOTAL_PARTS)
1525 must be exactly the number of parts needed to hold the bits
1526 of two HOST_WIDE_INTs. */
1527 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
1528 unsigned int parts[TOTAL_PARTS];
1530 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON}
1531 floatflag = NOT_FLOAT;
1533 for (count = 0; count < TOTAL_PARTS; count++)
1541 *p++ = (c = token_getch());
1542 if ((c == 'x') || (c == 'X'))
1545 *p++ = (c = token_getch());
1547 /* Leading 0 forces octal unless the 0 is the only digit. */
1548 else if (c >= '0' && c <= '9')
1557 /* Read all the digits-and-decimal-points. */
1560 || (ISALNUM (c) && c != 'l' && c != 'L'
1561 && c != 'u' && c != 'U'
1562 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1563 && (floatflag == NOT_FLOAT
1564 || ((base != 16) && (c != 'f') && (c != 'F'))
1569 if (base == 16 && pedantic)
1570 pedwarn ("floating constant may not be in radix 16");
1571 if (floatflag == TOO_MANY_POINTS)
1572 /* We have already emitted an error. Don't need another. */
1574 else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON)
1576 error ("malformed floating constant");
1577 floatflag = TOO_MANY_POINTS;
1578 /* Avoid another error from atof by forcing all characters
1579 from here on to be ignored. */
1583 floatflag = AFTER_POINT;
1587 *p++ = c = token_getch();
1588 /* Accept '.' as the start of a floating-point number
1589 only when it is followed by a digit. */
1590 if (p == token_buffer + 2 && !ISDIGIT (c))
1595 /* It is not a decimal point.
1596 It should be a digit (perhaps a hex digit). */
1602 else if (base <= 10)
1604 if (c == 'e' || c == 'E')
1607 floatflag = AFTER_EXPON;
1608 break; /* start of exponent */
1610 error ("nondigits in number and not hexadecimal");
1613 else if (base == 16 && (c == 'p' || c == 'P'))
1615 floatflag = AFTER_EXPON;
1616 break; /* start of exponent */
1618 else if (c >= 'a' && c <= 'f')
1626 if (c >= largest_digit)
1630 for (count = 0; count < TOTAL_PARTS; count++)
1632 parts[count] *= base;
1636 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1638 &= (1 << HOST_BITS_PER_CHAR) - 1;
1644 /* If the highest-order part overflows (gets larger than
1645 a host char will hold) then the whole number has
1646 overflowed. Record this and truncate the highest-order
1648 if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
1651 parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
1654 if (p >= token_buffer + maxtoken - 3)
1655 p = extend_token_buffer (p);
1656 *p++ = (c = token_getch());
1660 /* This can happen on input like `int i = 0x;' */
1662 error ("numeric constant with no digits");
1664 if (largest_digit >= base)
1665 error ("numeric constant contains digits beyond the radix");
1667 /* Remove terminating char from the token buffer and delimit the
1671 if (floatflag != NOT_FLOAT)
1674 int imag, conversion_errno;
1675 REAL_VALUE_TYPE value;
1676 struct pf_args args;
1678 /* Read explicit exponent if any, and put it in tokenbuf. */
1680 if ((base == 10 && ((c == 'e') || (c == 'E')))
1681 || (base == 16 && (c == 'p' || c == 'P')))
1683 if (p >= token_buffer + maxtoken - 3)
1684 p = extend_token_buffer (p);
1687 if ((c == '+') || (c == '-'))
1692 /* Exponent is decimal, even if string is a hex float. */
1694 error ("floating constant exponent has no digits");
1697 if (p >= token_buffer + maxtoken - 3)
1698 p = extend_token_buffer (p);
1703 if (base == 16 && floatflag != AFTER_EXPON)
1704 error ("hexadecimal floating constant has no exponent");
1708 /* Setup input for parse_float() */
1713 /* Convert string to a double, checking for overflow. */
1714 if (do_float_handler (parse_float, (PTR) &args))
1716 /* Receive output from parse_float() */
1721 /* We got an exception from parse_float() */
1722 error ("floating constant out of range");
1726 /* Receive output from parse_float() */
1730 conversion_errno = args.conversion_errno;
1733 /* ERANGE is also reported for underflow,
1734 so test the value to distinguish overflow from that. */
1735 if (conversion_errno == ERANGE && !flag_traditional && pedantic
1736 && (REAL_VALUES_LESS (dconst1, value)
1737 || REAL_VALUES_LESS (value, dconstm1)))
1738 warning ("floating point number exceeds range of `double'");
1741 /* If the result is not a number, assume it must have been
1742 due to some error message above, so silently convert
1744 if (REAL_VALUE_ISNAN (value))
1747 /* Create a node with determined type and value. */
1749 yylval.ttype = build_complex (NULL_TREE,
1750 convert (type, integer_zero_node),
1751 build_real (type, value));
1753 yylval.ttype = build_real (type, value);
1757 tree traditional_type, ansi_type, type;
1758 HOST_WIDE_INT high, low;
1759 int spec_unsigned = 0;
1761 int spec_long_long = 0;
1765 traditional_type = ansi_type = type = NULL_TREE;
1768 if (c == 'u' || c == 'U')
1771 error ("two `u's in integer constant");
1774 else if (c == 'l' || c == 'L')
1779 error ("three `l's in integer constant");
1780 else if (pedantic && ! flag_isoc99
1781 && ! in_system_header && warn_long_long)
1782 pedwarn ("ANSI C forbids long long integer constants");
1787 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1790 error ("more than one `i' or `j' in numeric constant");
1792 pedwarn ("ANSI C forbids imaginary numeric constants");
1797 if (p >= token_buffer + maxtoken - 3)
1798 p = extend_token_buffer (p);
1803 /* If the literal overflowed, pedwarn about it now. */
1807 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2);
1810 /* This is simplified by the fact that our constant
1811 is always positive. */
1815 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1817 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1818 / HOST_BITS_PER_CHAR)]
1819 << (i * HOST_BITS_PER_CHAR));
1820 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1823 yylval.ttype = build_int_2 (low, high);
1824 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1826 /* If warn_traditional, calculate both the ANSI type and the
1827 traditional type, then see if they disagree.
1828 Otherwise, calculate only the type for the dialect in use. */
1829 if (warn_traditional || flag_traditional)
1831 /* Calculate the traditional type. */
1832 /* Traditionally, any constant is signed;
1833 but if unsigned is specified explicitly, obey that.
1834 Use the smallest size with the right number of bits,
1835 except for one special case with decimal constants. */
1836 if (! spec_long && base != 10
1837 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1838 traditional_type = (spec_unsigned ? unsigned_type_node
1839 : integer_type_node);
1840 /* A decimal constant must be long
1841 if it does not fit in type int.
1842 I think this is independent of whether
1843 the constant is signed. */
1844 else if (! spec_long && base == 10
1845 && int_fits_type_p (yylval.ttype, integer_type_node))
1846 traditional_type = (spec_unsigned ? unsigned_type_node
1847 : integer_type_node);
1848 else if (! spec_long_long)
1849 traditional_type = (spec_unsigned ? long_unsigned_type_node
1850 : long_integer_type_node);
1851 else if (int_fits_type_p (yylval.ttype,
1853 ? long_long_unsigned_type_node
1854 : long_long_integer_type_node))
1855 traditional_type = (spec_unsigned
1856 ? long_long_unsigned_type_node
1857 : long_long_integer_type_node);
1859 traditional_type = (spec_unsigned
1860 ? widest_unsigned_literal_type_node
1861 : widest_integer_literal_type_node);
1863 if (warn_traditional || ! flag_traditional)
1865 /* Calculate the ANSI type. */
1866 if (! spec_long && ! spec_unsigned
1867 && int_fits_type_p (yylval.ttype, integer_type_node))
1868 ansi_type = integer_type_node;
1869 else if (! spec_long && (base != 10 || spec_unsigned)
1870 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1871 ansi_type = unsigned_type_node;
1872 else if (! spec_unsigned && !spec_long_long
1873 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1874 ansi_type = long_integer_type_node;
1875 else if (! spec_long_long
1876 && int_fits_type_p (yylval.ttype,
1877 long_unsigned_type_node))
1878 ansi_type = long_unsigned_type_node;
1879 else if (! spec_unsigned
1880 && int_fits_type_p (yylval.ttype,
1881 long_long_integer_type_node))
1882 ansi_type = long_long_integer_type_node;
1883 else if (int_fits_type_p (yylval.ttype,
1884 long_long_unsigned_type_node))
1885 ansi_type = long_long_unsigned_type_node;
1886 else if (! spec_unsigned
1887 && int_fits_type_p (yylval.ttype,
1888 widest_integer_literal_type_node))
1889 ansi_type = widest_integer_literal_type_node;
1891 ansi_type = widest_unsigned_literal_type_node;
1894 type = flag_traditional ? traditional_type : ansi_type;
1896 /* We assume that constants specified in a non-decimal
1897 base are bit patterns, and that the programmer really
1898 meant what they wrote. */
1899 if (warn_traditional && base == 10
1900 && traditional_type != ansi_type)
1902 if (TYPE_PRECISION (traditional_type)
1903 != TYPE_PRECISION (ansi_type))
1904 warning ("width of integer constant changes with -traditional");
1905 else if (TREE_UNSIGNED (traditional_type)
1906 != TREE_UNSIGNED (ansi_type))
1907 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1909 warning ("width of integer constant may change on other systems with -traditional");
1912 if (pedantic && !flag_traditional && !spec_long_long && !warn
1913 && (TYPE_PRECISION (long_integer_type_node)
1914 < TYPE_PRECISION (type)))
1917 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
1920 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1921 warning ("decimal constant is so large that it is unsigned");
1925 if (TYPE_PRECISION (type)
1926 <= TYPE_PRECISION (integer_type_node))
1928 = build_complex (NULL_TREE, integer_zero_node,
1929 convert (integer_type_node,
1932 error ("complex integer constant is too wide for `complex int'");
1934 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1935 /* The traditional constant 0x80000000 is signed
1936 but doesn't fit in the range of int.
1937 This will change it to -0x80000000, which does fit. */
1939 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1940 yylval.ttype = convert (type, yylval.ttype);
1941 TREE_OVERFLOW (yylval.ttype)
1942 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1945 TREE_TYPE (yylval.ttype) = type;
1948 /* If it's still an integer (not a complex), and it doesn't
1949 fit in the type we choose for it, then pedwarn. */
1952 && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE
1953 && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype)))
1954 pedwarn ("integer constant is larger than the maximum value for its type");
1960 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
1961 || (!flag_traditional && (c == '-' || c == '+')
1962 && (p[-1] == 'e' || p[-1] == 'E')))
1963 error ("missing white space after number `%s'", token_buffer);
1965 value = CONSTANT; break;
1971 register int result = 0;
1972 register int num_chars = 0;
1974 unsigned width = TYPE_PRECISION (char_type_node);
1976 #ifdef MULTIBYTE_CHARS
1977 int longest_char = local_mb_cur_max ();
1978 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
1981 max_chars = TYPE_PRECISION (integer_type_node) / width;
1983 width = WCHAR_TYPE_SIZE;
1990 if (c == '\'' || c == EOF)
1997 c = readescape (&ignore);
2000 if (width < HOST_BITS_PER_INT
2001 && (unsigned) c >= ((unsigned)1 << width))
2002 pedwarn ("escape sequence out of range for character");
2003 #ifdef MAP_CHARACTER
2005 c = MAP_CHARACTER (c);
2011 pedwarn ("ANSI C forbids newline in character constant");
2016 #ifdef MULTIBYTE_CHARS
2020 for (i = 1; i <= longest_char; ++i)
2022 if (i > maxtoken - 4)
2023 extend_token_buffer (token_buffer);
2025 token_buffer[i] = c;
2026 char_len = local_mbtowc (& wc,
2035 /* mbtowc sometimes needs an extra char before accepting */
2040 /* Merge character into result; ignore excess chars. */
2041 for (i = 1; i <= char_len; ++i)
2045 if (width < HOST_BITS_PER_INT)
2046 result = (result << width)
2048 & ((1 << width) - 1));
2050 result = token_buffer[i];
2052 num_chars += char_len;
2061 warning ("Ignoring invalid multibyte character");
2062 /* Replace all but the first byte. */
2063 for (--i; i > 1; --i)
2064 token_put_back (token_buffer[i]);
2065 wc = token_buffer[1];
2067 #ifdef MAP_CHARACTER
2068 c = MAP_CHARACTER (wc);
2073 #else /* ! MULTIBYTE_CHARS */
2074 #ifdef MAP_CHARACTER
2075 c = MAP_CHARACTER (c);
2077 #endif /* ! MULTIBYTE_CHARS */
2082 if (chars_seen == 1) /* only keep the first one */
2087 /* Merge character into result; ignore excess chars. */
2088 num_chars += (width / TYPE_PRECISION (char_type_node));
2089 if (num_chars < max_chars + 1)
2091 if (width < HOST_BITS_PER_INT)
2092 result = (result << width) | (c & ((1 << width) - 1));
2099 error ("malformed character constant");
2100 else if (chars_seen == 0)
2101 error ("empty character constant");
2102 else if (num_chars > max_chars)
2104 num_chars = max_chars;
2105 error ("character constant too long");
2107 else if (chars_seen != 1 && ! flag_traditional && warn_multichar)
2108 warning ("multi-character character constant");
2110 /* If char type is signed, sign-extend the constant. */
2113 int num_bits = num_chars * width;
2115 /* We already got an error; avoid invalid shift. */
2116 yylval.ttype = build_int_2 (0, 0);
2117 else if (TREE_UNSIGNED (char_type_node)
2118 || ((result >> (num_bits - 1)) & 1) == 0)
2120 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
2121 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
2125 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
2126 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
2128 TREE_TYPE (yylval.ttype) = integer_type_node;
2132 yylval.ttype = build_int_2 (result, 0);
2133 TREE_TYPE (yylval.ttype) = wchar_type_node;
2143 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
2144 : TYPE_PRECISION (char_type_node);
2145 #ifdef MULTIBYTE_CHARS
2146 int longest_char = local_mb_cur_max ();
2147 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
2150 p = token_buffer + 1;
2152 while (c != '"' && c != EOF)
2154 /* ignore_escape_flag is set for reading the filename in #line. */
2155 if (!ignore_escape_flag && c == '\\')
2158 c = readescape (&ignore);
2161 if (width < HOST_BITS_PER_INT
2162 && (unsigned) c >= ((unsigned)1 << width))
2163 pedwarn ("escape sequence out of range for character");
2168 pedwarn ("ANSI C forbids newline in string constant");
2173 #ifdef MULTIBYTE_CHARS
2177 for (i = 0; i < longest_char; ++i)
2179 if (p + i >= token_buffer + maxtoken)
2180 p = extend_token_buffer (p);
2183 char_len = local_mbtowc (& wc, p, i + 1);
2190 warning ("Ignoring invalid multibyte character");
2191 /* Replace all except the first byte. */
2193 for (--i; i > 0; --i)
2194 token_put_back (p[i]);
2197 /* mbtowc sometimes needs an extra char before accepting */
2207 #endif /* MULTIBYTE_CHARS */
2210 /* Add this single character into the buffer either as a wchar_t
2211 or as a single byte. */
2214 unsigned width = TYPE_PRECISION (char_type_node);
2215 unsigned bytemask = (1 << width) - 1;
2218 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2219 p = extend_token_buffer (p);
2221 for (byte = 0; byte < WCHAR_BYTES; ++byte)
2224 if (byte >= (int) sizeof (c))
2227 value = (c >> (byte * width)) & bytemask;
2228 if (BYTES_BIG_ENDIAN)
2229 p[WCHAR_BYTES - byte - 1] = value;
2237 if (p >= token_buffer + maxtoken)
2238 p = extend_token_buffer (p);
2246 /* Terminate the string value, either with a single byte zero
2247 or with a wide zero. */
2250 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2251 p = extend_token_buffer (p);
2252 bzero (p, WCHAR_BYTES);
2257 if (p >= token_buffer + maxtoken)
2258 p = extend_token_buffer (p);
2263 error ("Unterminated string constant");
2265 /* We have read the entire constant.
2266 Construct a STRING_CST for the result. */
2270 yylval.ttype = build_string (p - (token_buffer + 1),
2272 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2277 /* Return an Objective-C @"..." constant string object. */
2278 yylval.ttype = build_objc_string (p - (token_buffer + 1),
2280 TREE_TYPE (yylval.ttype) = char_array_type_node;
2281 value = OBJC_STRING;
2285 yylval.ttype = build_string (p - (token_buffer + 1),
2287 TREE_TYPE (yylval.ttype) = char_array_type_node;
2315 yylval.code = PLUS_EXPR; break;
2317 yylval.code = MINUS_EXPR; break;
2319 yylval.code = BIT_AND_EXPR; break;
2321 yylval.code = BIT_IOR_EXPR; break;
2323 yylval.code = MULT_EXPR; break;
2325 yylval.code = TRUNC_DIV_EXPR; break;
2327 yylval.code = TRUNC_MOD_EXPR; break;
2329 yylval.code = BIT_XOR_EXPR; break;
2331 yylval.code = LSHIFT_EXPR; break;
2333 yylval.code = RSHIFT_EXPR; break;
2335 yylval.code = LT_EXPR; break;
2337 yylval.code = GT_EXPR; break;
2340 token_buffer[1] = c1 = token_getch();
2341 token_buffer[2] = 0;
2348 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2350 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2352 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2354 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2356 value = ASSIGN; goto done;
2362 value = PLUSPLUS; goto done;
2364 value = MINUSMINUS; goto done;
2366 value = ANDAND; goto done;
2368 value = OROR; goto done;
2381 { value = POINTSAT; goto done; }
2387 { value = ']'; goto done; }
2391 { value = '{'; indent_level++; goto done; }
2393 { value = '['; goto done; }
2397 { value = '}'; indent_level--; goto done; }
2401 token_put_back (c1);
2402 token_buffer[1] = 0;
2404 if ((c == '<') || (c == '>'))
2405 value = ARITHCOMPARE;
2411 /* Don't make yyparse think this is eof. */
2430 /* yylloc.last_line = lineno; */
2435 /* Sets the value of the 'yydebug' variable to VALUE.
2436 This is a function so we don't have to have YYDEBUG defined
2437 in order to build the compiler. */
2446 warning ("YYDEBUG not defined.");