1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 88, 89, 92, 94-98, 1999 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. */
37 /* MULTIBYTE_CHARS support only works for native compilers.
38 ??? Ideally what we want is to model widechar support after
39 the current floating point support. */
41 #undef MULTIBYTE_CHARS
44 #ifdef MULTIBYTE_CHARS
47 #endif /* MULTIBYTE_CHARS */
48 #ifndef GET_ENVIRONMENT
49 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME))
54 extern cpp_reader parse_in
;
55 extern cpp_options parse_options
;
57 /* Stream for reading from the input file. */
61 extern void yyprint
PROTO((FILE *, int, YYSTYPE
));
63 /* The elements of `ridpointers' are identifier nodes
64 for the reserved type names and storage classes.
65 It is indexed by a RID_... value. */
66 tree ridpointers
[(int) RID_MAX
];
68 /* Cause the `yydebug' variable to be defined. */
72 extern unsigned char *yy_cur
, *yy_lim
;
73 extern enum cpp_token cpp_token
;
75 extern int yy_get_token ();
77 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
78 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
80 #else /* ! USE_CPPLIB */
82 #define GETC() getch ()
83 #define UNGETC(c) put_back (c)
85 struct putback_buffer
{
91 static struct putback_buffer putback
= {NULL
, 0, -1};
96 if (putback
.index
!= -1)
98 int ch
= putback
.buffer
[putback
.index
];
102 return getc (finput
);
111 if (putback
.index
== putback
.buffer_size
- 1)
113 putback
.buffer_size
+= 16;
114 putback
.buffer
= xrealloc (putback
.buffer
, putback
.buffer_size
);
116 putback
.buffer
[++putback
.index
] = ch
;
119 #endif /* ! USE_CPPLIB */
123 /* the declaration found for the last IDENTIFIER token read in.
124 yylex must look this up to detect typedefs, which get token type TYPENAME,
125 so it is left around in case the identifier is not a typedef but is
126 used in a context which makes it a reference to a variable. */
129 /* Nonzero enables objc features. */
131 int doing_objc_thang
;
135 /* File used for outputting assembler code. */
136 extern FILE *asm_out_file
;
138 #ifndef WCHAR_TYPE_SIZE
140 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
142 #define WCHAR_TYPE_SIZE BITS_PER_WORD
146 /* Number of bytes in a wide character. */
147 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
149 static int maxtoken
; /* Current nominal length of token buffer. */
150 char *token_buffer
; /* Pointer to token buffer.
151 Actual allocated length is maxtoken + 2.
152 This is not static because objc-parse.y uses it. */
154 static int indent_level
; /* Number of { minus number of }. */
156 /* Nonzero tells yylex to ignore \ in string constants. */
157 static int ignore_escape_flag
;
159 /* Nonzero if end-of-file has been seen on input. */
160 static int end_of_file
;
162 #ifdef HANDLE_GENERIC_PRAGMAS
163 static int handle_generic_pragma
PROTO((int));
164 #endif /* HANDLE_GENERIC_PRAGMAS */
165 static int whitespace_cr
PROTO((int));
166 static int skip_white_space
PROTO((int));
167 static char *extend_token_buffer
PROTO((const char *));
168 static int readescape
PROTO((int *));
169 static void parse_float
PROTO((PTR
));
171 /* Do not insert generated code into the source, instead, include it.
172 This allows us to build gcc automatically even for targets that
173 need to add or modify the reserved keyword lists. */
176 /* Return something to represent absolute declarators containing a *.
177 TARGET is the absolute declarator that the * contains.
178 TYPE_QUALS is a list of modifiers such as const or volatile
179 to apply to the pointer type, represented as identifiers.
181 We return an INDIRECT_REF whose "contents" are TARGET
182 and whose type is the modifier list. */
185 make_pointer_declarator (type_quals
, target
)
186 tree type_quals
, target
;
188 return build1 (INDIRECT_REF
, type_quals
, target
);
192 forget_protocol_qualifiers ()
194 int i
, n
= sizeof wordlist
/ sizeof (struct resword
);
196 for (i
= 0; i
< n
; i
++)
197 if ((int) wordlist
[i
].rid
>= (int) RID_IN
198 && (int) wordlist
[i
].rid
<= (int) RID_ONEWAY
)
199 wordlist
[i
].name
= "";
203 remember_protocol_qualifiers ()
205 int i
, n
= sizeof wordlist
/ sizeof (struct resword
);
207 for (i
= 0; i
< n
; i
++)
208 if (wordlist
[i
].rid
== RID_IN
)
209 wordlist
[i
].name
= "in";
210 else if (wordlist
[i
].rid
== RID_OUT
)
211 wordlist
[i
].name
= "out";
212 else if (wordlist
[i
].rid
== RID_INOUT
)
213 wordlist
[i
].name
= "inout";
214 else if (wordlist
[i
].rid
== RID_BYCOPY
)
215 wordlist
[i
].name
= "bycopy";
216 else if (wordlist
[i
].rid
== RID_BYREF
)
217 wordlist
[i
].name
= "byref";
218 else if (wordlist
[i
].rid
== RID_ONEWAY
)
219 wordlist
[i
].name
= "oneway";
223 init_parse (filename
)
227 /* Open input file. */
228 if (filename
== 0 || !strcmp (filename
, "-"))
234 finput
= fopen (filename
, "r");
236 pfatal_with_name (filename
);
238 #ifdef IO_BUFFER_SIZE
239 setvbuf (finput
, (char *) xmalloc (IO_BUFFER_SIZE
), _IOFBF
, IO_BUFFER_SIZE
);
241 #else /* !USE_CPPLIB */
242 parse_in
.show_column
= 1;
243 if (! cpp_start_read (&parse_in
, filename
))
246 if (filename
== 0 || !strcmp (filename
, "-"))
249 /* cpp_start_read always puts at least one line directive into the
250 token buffer. We must arrange to read it out here. */
251 yy_cur
= parse_in
.token_buffer
;
252 yy_lim
= CPP_PWRITTEN (&parse_in
);
253 cpp_token
= CPP_DIRECTIVE
;
266 cpp_finish (&parse_in
);
267 errorcount
+= parse_in
.errors
;
276 /* Make identifier nodes long enough for the language-specific slots. */
277 set_identifier_size (sizeof (struct lang_identifier
));
279 /* Start it at 0, because check_newline is called at the very beginning
280 and will increment it to 1. */
283 #ifdef MULTIBYTE_CHARS
284 /* Change to the native locale for multibyte conversions. */
285 setlocale (LC_CTYPE
, "");
286 GET_ENVIRONMENT (literal_codeset
, "LANG");
290 token_buffer
= (char *) xmalloc (maxtoken
+ 2);
292 ridpointers
[(int) RID_INT
] = get_identifier ("int");
293 ridpointers
[(int) RID_CHAR
] = get_identifier ("char");
294 ridpointers
[(int) RID_VOID
] = get_identifier ("void");
295 ridpointers
[(int) RID_FLOAT
] = get_identifier ("float");
296 ridpointers
[(int) RID_DOUBLE
] = get_identifier ("double");
297 ridpointers
[(int) RID_SHORT
] = get_identifier ("short");
298 ridpointers
[(int) RID_LONG
] = get_identifier ("long");
299 ridpointers
[(int) RID_UNSIGNED
] = get_identifier ("unsigned");
300 ridpointers
[(int) RID_SIGNED
] = get_identifier ("signed");
301 ridpointers
[(int) RID_INLINE
] = get_identifier ("inline");
302 ridpointers
[(int) RID_CONST
] = get_identifier ("const");
303 ridpointers
[(int) RID_RESTRICT
] = get_identifier ("restrict");
304 ridpointers
[(int) RID_VOLATILE
] = get_identifier ("volatile");
305 ridpointers
[(int) RID_AUTO
] = get_identifier ("auto");
306 ridpointers
[(int) RID_STATIC
] = get_identifier ("static");
307 ridpointers
[(int) RID_EXTERN
] = get_identifier ("extern");
308 ridpointers
[(int) RID_TYPEDEF
] = get_identifier ("typedef");
309 ridpointers
[(int) RID_REGISTER
] = get_identifier ("register");
310 ridpointers
[(int) RID_ITERATOR
] = get_identifier ("iterator");
311 ridpointers
[(int) RID_COMPLEX
] = get_identifier ("complex");
312 ridpointers
[(int) RID_ID
] = get_identifier ("id");
313 ridpointers
[(int) RID_IN
] = get_identifier ("in");
314 ridpointers
[(int) RID_OUT
] = get_identifier ("out");
315 ridpointers
[(int) RID_INOUT
] = get_identifier ("inout");
316 ridpointers
[(int) RID_BYCOPY
] = get_identifier ("bycopy");
317 ridpointers
[(int) RID_BYREF
] = get_identifier ("byref");
318 ridpointers
[(int) RID_ONEWAY
] = get_identifier ("oneway");
319 forget_protocol_qualifiers();
321 /* Some options inhibit certain reserved words.
322 Clear those words out of the hash table so they won't be recognized. */
323 #define UNSET_RESERVED_WORD(STRING) \
324 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
325 if (s) s->name = ""; } while (0)
327 if (! doing_objc_thang
)
328 UNSET_RESERVED_WORD ("id");
330 if (flag_traditional
)
332 UNSET_RESERVED_WORD ("const");
333 UNSET_RESERVED_WORD ("restrict");
334 UNSET_RESERVED_WORD ("volatile");
335 UNSET_RESERVED_WORD ("typeof");
336 UNSET_RESERVED_WORD ("signed");
337 UNSET_RESERVED_WORD ("inline");
338 UNSET_RESERVED_WORD ("iterator");
339 UNSET_RESERVED_WORD ("complex");
341 else if (!flag_isoc9x
)
342 UNSET_RESERVED_WORD ("restrict");
346 UNSET_RESERVED_WORD ("asm");
347 UNSET_RESERVED_WORD ("typeof");
348 UNSET_RESERVED_WORD ("inline");
349 UNSET_RESERVED_WORD ("iterator");
350 UNSET_RESERVED_WORD ("complex");
355 reinit_parse_for_function ()
359 /* Function used when yydebug is set, to print a token in more detail. */
362 yyprint (file
, yychar
, yylval
)
374 if (IDENTIFIER_POINTER (t
))
375 fprintf (file
, " `%s'", IDENTIFIER_POINTER (t
));
380 if (TREE_CODE (t
) == INTEGER_CST
)
382 #if HOST_BITS_PER_WIDE_INT == 64
383 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
386 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
393 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
399 TREE_INT_CST_HIGH (t
), TREE_INT_CST_LOW (t
));
404 /* Iff C is a carriage return, warn about it - if appropriate -
405 and return nonzero. */
410 static int newline_warning
= 0;
414 /* ANSI C says the effects of a carriage return in a source file
416 if (pedantic
&& !newline_warning
)
418 warning ("carriage return in source file");
419 warning ("(we only warn about the first carriage return)");
427 /* If C is not whitespace, return C.
428 Otherwise skip whitespace and return first nonwhite char read. */
438 /* We don't recognize comments here, because
439 cpp output can include / and * consecutively as operators.
440 Also, there's no need, since cpp removes all comments. */
448 c
= check_newline ();
457 /* While processing a # directive we don't get CPP_HSPACE
458 tokens, so we also need to handle whitespace the normal way. */
459 if (cpp_token
== CPP_HSPACE
)
476 error ("stray '\\' in program");
486 /* Skips all of the white space at the current location in the input file. */
489 position_after_white_space ()
495 UNGETC (skip_white_space (c
));
498 /* Make the token buffer longer, preserving the data in it.
499 P should point to just beyond the last valid character in the old buffer.
500 The value we return is a pointer to the new buffer
501 at a place corresponding to P. */
504 extend_token_buffer_to (size
)
508 maxtoken
= maxtoken
* 2 + 10;
509 while (maxtoken
< size
);
510 token_buffer
= (char *) xrealloc (token_buffer
, maxtoken
+ 2);
514 extend_token_buffer (p
)
517 int offset
= p
- token_buffer
;
518 extend_token_buffer_to (offset
);
519 return token_buffer
+ offset
;
522 #if defined HANDLE_PRAGMA
523 /* Local versions of these macros, that can be passed as function pointers. */
539 read_line_number (num
)
542 register int token
= yylex ();
544 if (token
== CONSTANT
545 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
547 *num
= TREE_INT_CST_LOW (yylval
.ttype
);
552 if (token
!= END_OF_LINE
)
553 error ("invalid #-line");
558 /* At the beginning of a line, increment the line number
559 and process any #-directive on this line.
560 If the line is a #-directive, read the entire line and return a newline.
561 Otherwise, return the line's first non-whitespace character.
563 Note that in the case of USE_CPPLIB, we get the whole line as one
564 CPP_DIRECTIVE token. */
572 enum { act_none
, act_push
, act_pop
} action
;
573 int old_lineno
, action_number
, l
;
576 /* Read first nonwhite char on the line. */
580 /* In some cases where we're leaving an include file, we can get multiple
581 CPP_HSPACE tokens in a row, so we need to loop. */
582 while (cpp_token
== CPP_HSPACE
)
587 while (c
== ' ' || c
== '\t');
594 /* Sequences of multiple newlines are very common; optimize them. */
598 /* If not #, return it so caller will use it. */
602 /* Don't read beyond this line. */
607 if (cpp_token
== CPP_VSPACE
)
609 /* Format is "<space> <line number> <filename> <newline>".
610 Only the line number is interesting, and even that
611 we can get more efficiently than scanning the line. */
613 lineno
= parse_in
.lineno
- 1;
620 if (token
== IDENTIFIER
)
622 /* If a letter follows, then if the word here is `line', skip
623 it and ignore it; otherwise, ignore the line, with an error
624 if the word isn't `pragma'. */
626 const char *name
= IDENTIFIER_POINTER (yylval
.ttype
);
628 if (!strcmp (name
, "pragma"))
631 if (token
!= IDENTIFIER
632 || TREE_CODE (yylval
.ttype
) != IDENTIFIER_NODE
)
636 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
637 (if both are defined), in order to give the back
638 end a chance to override the interpretation of
639 SYSV style pragmas. */
640 if (HANDLE_PRAGMA (getch
, put_back
,
641 IDENTIFIER_POINTER (yylval
.ttype
)))
643 #endif /* HANDLE_PRAGMA */
645 #ifdef HANDLE_GENERIC_PRAGMAS
646 if (handle_generic_pragma (token
))
648 #endif /* HANDLE_GENERIC_PRAGMAS */
650 /* Issue a warning message if we have been asked to do so.
651 Ignoring unknown pragmas in system header file unless
652 an explcit -Wunknown-pragmas has been given. */
653 if (warn_unknown_pragmas
> 1
654 || (warn_unknown_pragmas
&& ! in_system_header
))
655 warning ("ignoring pragma: %s", token_buffer
);
659 else if (!strcmp (name
, "define"))
661 debug_define (lineno
, GET_DIRECTIVE_LINE ());
664 else if (!strcmp (name
, "undef"))
666 debug_undef (lineno
, GET_DIRECTIVE_LINE ());
669 else if (!strcmp (name
, "line"))
675 else if (!strcmp (name
, "ident"))
677 /* #ident. The pedantic warning is now in cccp.c. */
679 /* Here we have just seen `#ident '.
680 A string constant should follow. */
683 if (token
== END_OF_LINE
)
686 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
688 error ("invalid #ident");
694 #ifdef ASM_OUTPUT_IDENT
695 ASM_OUTPUT_IDENT (asm_out_file
,
696 TREE_STRING_POINTER (yylval
.ttype
));
700 /* Skip the rest of this line. */
704 error ("undefined or invalid # directive `%s'", name
);
708 /* If the # is the only nonwhite char on the line,
709 just ignore it. Check the new newline. */
710 if (token
== END_OF_LINE
)
714 /* Here we have either `#line' or `# <nonletter>'.
715 In either case, it should be a line number; a digit should follow. */
717 if (token
!= CONSTANT
718 || TREE_CODE (yylval
.ttype
) != INTEGER_CST
)
720 error ("invalid #-line");
724 /* subtract one, because it is the following line that
725 gets the specified number */
727 l
= TREE_INT_CST_LOW (yylval
.ttype
) - 1;
729 /* More follows: it must be a string constant (filename).
730 It would be neat to use cpplib to quickly process the string, but
731 (1) we don't have a handy tokenization of the string, and
732 (2) I don't know how well that would work in the presense
733 of filenames that contain wide characters. */
737 /* Don't treat \ as special if we are processing #line 1 "...".
738 If you want it to be treated specially, use # 1 "...". */
739 ignore_escape_flag
= 1;
742 /* Read the string constant. */
745 ignore_escape_flag
= 0;
747 if (token
== END_OF_LINE
)
749 /* No more: store the line number and check following line. */
754 if (token
!= STRING
|| TREE_CODE (yylval
.ttype
) != STRING_CST
)
756 error ("invalid #line");
760 if (! ggc_p
&& !TREE_PERMANENT (yylval
.ttype
))
763 = (char *) permalloc (TREE_STRING_LENGTH (yylval
.ttype
) + 1);
764 strcpy (input_filename
, TREE_STRING_POINTER (yylval
.ttype
));
767 input_filename
= TREE_STRING_POINTER (yylval
.ttype
);
769 if (main_input_filename
== 0)
770 main_input_filename
= input_filename
;
777 /* Each change of file name
778 reinitializes whether we are now in a system header. */
779 in_system_header
= 0;
781 if (!read_line_number (&action_number
))
783 /* Update the name in the top element of input_file_stack. */
784 if (input_file_stack
)
785 input_file_stack
->name
= input_filename
;
788 /* `1' after file name means entering new file.
789 `2' after file name means just left a file. */
791 if (action_number
== 1)
794 read_line_number (&action_number
);
796 else if (action_number
== 2)
799 read_line_number (&action_number
);
801 if (action_number
== 3)
803 /* `3' after file name means this is a system header file. */
804 in_system_header
= 1;
805 read_line_number (&action_number
);
808 /* Do the actions implied by the preceding numbers. */
810 if (action
== act_push
)
812 /* Pushing to a new file. */
814 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
815 input_file_stack
->line
= old_lineno
;
816 p
->next
= input_file_stack
;
817 p
->name
= input_filename
;
818 p
->indent_level
= indent_level
;
819 input_file_stack
= p
;
820 input_file_stack_tick
++;
821 debug_start_source_file (input_filename
);
823 else if (action
== act_pop
)
825 /* Popping out of a file. */
826 if (input_file_stack
->next
)
828 struct file_stack
*p
= input_file_stack
;
829 if (indent_level
!= p
->indent_level
)
831 warning_with_file_and_line
832 (p
->name
, old_lineno
,
833 "This file contains more `%c's than `%c's.",
834 indent_level
> p
->indent_level
? '{' : '}',
835 indent_level
> p
->indent_level
? '}' : '{');
837 input_file_stack
= p
->next
;
839 input_file_stack_tick
++;
840 debug_end_source_file (input_file_stack
->line
);
843 error ("#-lines for entering and leaving files don't match");
846 /* Now that we've pushed or popped the input stack,
847 update the name in the top element. */
848 if (input_file_stack
)
849 input_file_stack
->name
= input_filename
;
851 /* skip the rest of this line. */
858 while (c
!= '\n' && c
!= EOF
);
862 #ifdef HANDLE_GENERIC_PRAGMAS
864 /* Handle a #pragma directive.
865 TOKEN is the token we read after `#pragma'. Processes the entire input
866 line and return non-zero iff the pragma has been successfully parsed. */
868 /* This function has to be in this file, in order to get at
872 handle_generic_pragma (token
)
883 handle_pragma_token (token_buffer
, yylval
.ttype
);
887 return handle_pragma_token (NULL_PTR
, NULL_TREE
);
890 handle_pragma_token (token_buffer
, 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
)
935 if (c
>= 'a' && c
<= 'f')
936 code
+= c
- 'a' + 10;
937 if (c
>= 'A' && c
<= 'F')
938 code
+= c
- 'A' + 10;
939 if (c
>= '0' && c
<= '9')
941 if (code
!= 0 || count
!= 0)
950 error ("\\x used with no following hex digits");
952 /* Digits are all 0's. Ok. */
954 else if ((count
- 1) * 4 >= TYPE_PRECISION (integer_type_node
)
957 << (TYPE_PRECISION (integer_type_node
)
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 ("unknown escape sequence `\\%c'", c
);
1033 pedwarn ("unknown escape sequence `\\%c'", c
);
1035 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c
);
1043 const char *string
= _(msgid
);
1045 /* We can't print string and character constants well
1046 because the token_buffer contains the result of processing escapes. */
1048 error ("%s at end of input", string
);
1049 else if (token_buffer
[0] == 0)
1050 error ("%s at null character", string
);
1051 else if (token_buffer
[0] == '"')
1052 error ("%s before string constant", string
);
1053 else if (token_buffer
[0] == '\'')
1054 error ("%s before character constant", string
);
1055 else if (!ISGRAPH(token_buffer
[0]))
1056 error ("%s before character 0%o", string
, (unsigned char) token_buffer
[0]);
1058 error ("%s before `%s'", string
, token_buffer
);
1068 char long_long_flag
;
1071 struct try_type type_sequence
[] =
1073 { &integer_type_node
, 0, 0, 0},
1074 { &unsigned_type_node
, 1, 0, 0},
1075 { &long_integer_type_node
, 0, 1, 0},
1076 { &long_unsigned_type_node
, 1, 1, 0},
1077 { &long_long_integer_type_node
, 0, 1, 1},
1078 { &long_long_unsigned_type_node
, 1, 1, 1}
1092 int conversion_errno
;
1093 REAL_VALUE_TYPE value
;
1100 struct pf_args
* args
= (struct pf_args
*) data
;
1101 int fflag
= 0, lflag
= 0;
1102 /* Copy token_buffer now, while it has just the number
1103 and not the suffixes; once we add `f' or `i',
1104 REAL_VALUE_ATOF may not work any more. */
1105 char *copy
= (char *) alloca (args
->p
- token_buffer
+ 1);
1106 bcopy (token_buffer
, copy
, args
->p
- token_buffer
+ 1);
1108 args
->conversion_errno
= 0;
1109 args
->type
= double_type_node
;
1115 /* Read the suffixes to choose a data type. */
1120 error ("more than one `f' in numeric constant");
1126 error ("more than one `l' in numeric constant");
1132 error ("more than one `i' or `j' in numeric constant");
1134 pedwarn ("ANSI C forbids imaginary numeric constants");
1145 if (args
->p
>= token_buffer
+ maxtoken
- 3)
1146 args
->p
= extend_token_buffer (args
->p
);
1147 *(args
->p
++) = args
->c
;
1152 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1153 tells the desired precision of the binary result
1154 of decimal-to-binary conversion. */
1159 error ("both `f' and `l' in floating constant");
1161 args
->type
= float_type_node
;
1163 if (args
->base
== 16)
1164 args
->value
= REAL_VALUE_HTOF (copy
, TYPE_MODE (args
->type
));
1166 args
->value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (args
->type
));
1167 args
->conversion_errno
= errno
;
1168 /* A diagnostic is required here by some ANSI C testsuites.
1169 This is not pedwarn, because some people don't want
1170 an error for this. */
1171 if (REAL_VALUE_ISINF (args
->value
) && pedantic
)
1172 warning ("floating point number exceeds range of `float'");
1176 args
->type
= long_double_type_node
;
1178 if (args
->base
== 16)
1179 args
->value
= REAL_VALUE_HTOF (copy
, TYPE_MODE (args
->type
));
1181 args
->value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (args
->type
));
1182 args
->conversion_errno
= errno
;
1183 if (REAL_VALUE_ISINF (args
->value
) && pedantic
)
1184 warning ("floating point number exceeds range of `long double'");
1189 if (args
->base
== 16)
1190 args
->value
= REAL_VALUE_HTOF (copy
, TYPE_MODE (args
->type
));
1192 args
->value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (args
->type
));
1193 args
->conversion_errno
= errno
;
1194 if (REAL_VALUE_ISINF (args
->value
) && pedantic
)
1195 warning ("floating point number exceeds range of `double'");
1199 /* Get the next character, staying within the current token if possible.
1200 If we're lexing a token, we don't want to look beyond the end of the
1201 token cpplib has prepared for us; otherwise, we end up reading in the
1202 next token, which screws up feed_input. So just return a null
1209 if (yy_cur
== yy_lim
)
1226 /* Read a single token from the input stream, and assign it lexical
1240 /* Effectively do c = skip_white_space (c)
1241 but do it faster in the usual cases. */
1251 if (cpp_token
== CPP_HSPACE
)
1252 c
= yy_get_token ();
1259 /* Call skip_white_space so we can warn if appropriate. */
1264 c
= skip_white_space (c
);
1266 goto found_nonwhite
;
1270 token_buffer
[0] = c
;
1271 token_buffer
[1] = 0;
1273 /* yylloc.first_line = lineno; */
1279 token_buffer
[0] = 0;
1281 value
= END_OF_LINE
;
1288 if (cpp_token
== CPP_NAME
)
1291 /* Capital L may start a wide-string or wide-character constant. */
1293 register int c
= token_getch();
1302 goto string_constant
;
1309 if (!doing_objc_thang
)
1316 /* '@' may start a constant string object. */
1317 register int c
= token_getch ();
1321 goto string_constant
;
1324 /* Fall through to treat '@' as the start of an identifier. */
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 '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':
1333 case 'a': case 'b': case 'c': case 'd': case 'e':
1334 case 'f': case 'g': case 'h': case 'i': case 'j':
1335 case 'k': case 'l': case 'm': case 'n': case 'o':
1336 case 'p': case 'q': case 'r': case 's': case 't':
1337 case 'u': case 'v': case 'w': case 'x': case 'y':
1343 if (cpp_token
== CPP_NAME
)
1345 /* Note that one character has already been read from
1346 yy_cur into token_buffer. Also, cpplib complains about
1347 $ in identifiers, so we don't have to. */
1349 int len
= yy_lim
- yy_cur
+ 1;
1350 if (len
>= maxtoken
)
1351 extend_token_buffer_to (len
+ 1);
1352 memcpy (token_buffer
+ 1, yy_cur
, len
);
1353 p
= token_buffer
+ len
;
1360 while (ISALNUM (c
) || c
== '_' || c
== '$' || c
== '@')
1362 /* Make sure this char really belongs in an identifier. */
1365 if (! dollars_in_ident
)
1366 error ("`$' in identifier");
1368 pedwarn ("`$' in identifier");
1371 if (p
>= token_buffer
+ maxtoken
)
1372 p
= extend_token_buffer (p
);
1385 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1388 register struct resword
*ptr
;
1390 if ((ptr
= is_reserved_word (token_buffer
, p
- token_buffer
)))
1393 yylval
.ttype
= ridpointers
[(int) ptr
->rid
];
1394 value
= (int) ptr
->token
;
1396 /* Only return OBJECTNAME if it is a typedef. */
1397 if (doing_objc_thang
&& value
== OBJECTNAME
)
1399 lastiddecl
= lookup_name(yylval
.ttype
);
1401 if (lastiddecl
== NULL_TREE
1402 || TREE_CODE (lastiddecl
) != TYPE_DECL
)
1406 /* Even if we decided to recognize asm, still perhaps warn. */
1408 && (value
== ASM_KEYWORD
|| value
== TYPEOF
1409 || ptr
->rid
== RID_INLINE
)
1410 && token_buffer
[0] != '_')
1411 pedwarn ("ANSI does not permit the keyword `%s'",
1416 /* If we did not find a keyword, look for an identifier
1419 if (value
== IDENTIFIER
)
1421 if (token_buffer
[0] == '@')
1422 error("invalid identifier `%s'", token_buffer
);
1424 yylval
.ttype
= get_identifier (token_buffer
);
1425 lastiddecl
= lookup_name (yylval
.ttype
);
1427 if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == TYPE_DECL
)
1429 /* A user-invisible read-only initialized variable
1430 should be replaced by its value.
1431 We handle only strings since that's the only case used in C. */
1432 else if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == VAR_DECL
1433 && DECL_IGNORED_P (lastiddecl
)
1434 && TREE_READONLY (lastiddecl
)
1435 && DECL_INITIAL (lastiddecl
) != 0
1436 && TREE_CODE (DECL_INITIAL (lastiddecl
)) == STRING_CST
)
1438 tree stringval
= DECL_INITIAL (lastiddecl
);
1440 /* Copy the string value so that we won't clobber anything
1441 if we put something in the TREE_CHAIN of this one. */
1442 yylval
.ttype
= build_string (TREE_STRING_LENGTH (stringval
),
1443 TREE_STRING_POINTER (stringval
));
1446 else if (doing_objc_thang
)
1448 tree objc_interface_decl
= is_class_name (yylval
.ttype
);
1450 if (objc_interface_decl
)
1453 yylval
.ttype
= objc_interface_decl
;
1462 if (yy_cur
< yy_lim
)
1465 /* It's hard to preserve tokenization on '.' because
1466 it could be a symbol by itself, or it could be the
1467 start of a floating point number and cpp won't tell us. */
1468 register int c1
= token_getch ();
1469 token_buffer
[1] = c1
;
1472 c1
= token_getch ();
1475 token_buffer
[2] = c1
;
1476 token_buffer
[3] = 0;
1480 error ("parse error at `..'");
1484 token_put_back (c1
);
1487 token_put_back (c1
);
1490 token_buffer
[1] = 0;
1494 /* Optimize for most frequent case. */
1499 cond
= (yy_cur
== yy_lim
);
1501 register int c1
= token_getch ();
1502 token_put_back (c1
);
1503 cond
= (! ISALNUM (c1
) && c1
!= '.');
1507 yylval
.ttype
= (c
== '0') ? integer_zero_node
: integer_one_node
;
1513 case '2': case '3': case '4':
1514 case '5': case '6': case '7': case '8': case '9':
1519 int largest_digit
= 0;
1523 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
1524 The code below which fills the parts array assumes that a host
1525 int is at least twice as wide as a host char, and that
1526 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
1527 Two HOST_WIDE_INTs is the largest int literal we can store.
1528 In order to detect overflow below, the number of parts (TOTAL_PARTS)
1529 must be exactly the number of parts needed to hold the bits
1530 of two HOST_WIDE_INTs. */
1531 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
1532 unsigned int parts
[TOTAL_PARTS
];
1534 enum anon1
{ NOT_FLOAT
, AFTER_POINT
, TOO_MANY_POINTS
, AFTER_EXPON
}
1535 floatflag
= NOT_FLOAT
;
1537 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1545 *p
++ = (c
= token_getch());
1546 if ((c
== 'x') || (c
== 'X'))
1549 *p
++ = (c
= token_getch());
1551 /* Leading 0 forces octal unless the 0 is the only digit. */
1552 else if (c
>= '0' && c
<= '9')
1561 /* Read all the digits-and-decimal-points. */
1564 || (ISALNUM (c
) && c
!= 'l' && c
!= 'L'
1565 && c
!= 'u' && c
!= 'U'
1566 && c
!= 'i' && c
!= 'I' && c
!= 'j' && c
!= 'J'
1567 && (floatflag
== NOT_FLOAT
|| ((c
!= 'f') && (c
!= 'F')))))
1571 if (base
== 16 && pedantic
)
1572 pedwarn ("floating constant may not be in radix 16");
1573 if (floatflag
== TOO_MANY_POINTS
)
1574 /* We have already emitted an error. Don't need another. */
1576 else if (floatflag
== AFTER_POINT
|| floatflag
== AFTER_EXPON
)
1578 error ("malformed floating constant");
1579 floatflag
= TOO_MANY_POINTS
;
1580 /* Avoid another error from atof by forcing all characters
1581 from here on to be ignored. */
1585 floatflag
= AFTER_POINT
;
1589 *p
++ = c
= token_getch();
1590 /* Accept '.' as the start of a floating-point number
1591 only when it is followed by a digit. */
1592 if (p
== token_buffer
+ 2 && !ISDIGIT (c
))
1597 /* It is not a decimal point.
1598 It should be a digit (perhaps a hex digit). */
1604 else if (base
<= 10)
1606 if (c
== 'e' || c
== 'E')
1609 floatflag
= AFTER_EXPON
;
1610 break; /* start of exponent */
1612 error ("nondigits in number and not hexadecimal");
1615 else if (base
== 16 && (c
== 'p' || c
== 'P'))
1617 floatflag
= AFTER_EXPON
;
1618 break; /* start of exponent */
1628 if (c
>= largest_digit
)
1632 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1634 parts
[count
] *= base
;
1638 += (parts
[count
-1] >> HOST_BITS_PER_CHAR
);
1640 &= (1 << HOST_BITS_PER_CHAR
) - 1;
1646 /* If the highest-order part overflows (gets larger than
1647 a host char will hold) then the whole number has
1648 overflowed. Record this and truncate the highest-order
1650 if (parts
[TOTAL_PARTS
- 1] >> HOST_BITS_PER_CHAR
)
1653 parts
[TOTAL_PARTS
- 1] &= (1 << HOST_BITS_PER_CHAR
) - 1;
1656 if (p
>= token_buffer
+ maxtoken
- 3)
1657 p
= extend_token_buffer (p
);
1658 *p
++ = (c
= token_getch());
1662 /* This can happen on input like `int i = 0x;' */
1664 error ("numeric constant with no digits");
1666 if (largest_digit
>= base
)
1667 error ("numeric constant contains digits beyond the radix");
1669 /* Remove terminating char from the token buffer and delimit the
1673 if (floatflag
!= NOT_FLOAT
)
1676 int imag
, conversion_errno
;
1677 REAL_VALUE_TYPE value
;
1678 struct pf_args args
;
1680 /* Read explicit exponent if any, and put it in tokenbuf. */
1682 if ((base
== 10 && ((c
== 'e') || (c
== 'E')))
1683 || (base
== 16 && (c
== 'p' || c
== 'P')))
1685 if (p
>= token_buffer
+ maxtoken
- 3)
1686 p
= extend_token_buffer (p
);
1689 if ((c
== '+') || (c
== '-'))
1694 /* Exponent is decimal, even if string is a hex float. */
1696 error ("floating constant exponent has no digits");
1699 if (p
>= token_buffer
+ maxtoken
- 3)
1700 p
= extend_token_buffer (p
);
1705 if (base
== 16 && floatflag
!= AFTER_EXPON
)
1706 error ("hexadecimal floating constant has no exponent");
1710 /* Setup input for parse_float() */
1715 /* Convert string to a double, checking for overflow. */
1716 if (do_float_handler (parse_float
, (PTR
) &args
))
1718 /* Receive output from parse_float() */
1723 /* We got an exception from parse_float() */
1724 error ("floating constant out of range");
1728 /* Receive output from parse_float() */
1732 conversion_errno
= args
.conversion_errno
;
1735 /* ERANGE is also reported for underflow,
1736 so test the value to distinguish overflow from that. */
1737 if (conversion_errno
== ERANGE
&& !flag_traditional
&& pedantic
1738 && (REAL_VALUES_LESS (dconst1
, value
)
1739 || REAL_VALUES_LESS (value
, dconstm1
)))
1740 warning ("floating point number exceeds range of `double'");
1743 /* If the result is not a number, assume it must have been
1744 due to some error message above, so silently convert
1746 if (REAL_VALUE_ISNAN (value
))
1749 /* Create a node with determined type and value. */
1751 yylval
.ttype
= build_complex (NULL_TREE
,
1752 convert (type
, integer_zero_node
),
1753 build_real (type
, value
));
1755 yylval
.ttype
= build_real (type
, value
);
1759 tree traditional_type
, ansi_type
, type
;
1760 HOST_WIDE_INT high
, low
;
1761 int spec_unsigned
= 0;
1763 int spec_long_long
= 0;
1767 traditional_type
= ansi_type
= type
= NULL_TREE
;
1770 if (c
== 'u' || c
== 'U')
1773 error ("two `u's in integer constant");
1776 else if (c
== 'l' || c
== 'L')
1781 error ("three `l's in integer constant");
1782 else if (pedantic
&& ! in_system_header
&& warn_long_long
)
1783 pedwarn ("ANSI C forbids long long integer constants");
1788 else if (c
== 'i' || c
== 'j' || c
== 'I' || c
== 'J')
1791 error ("more than one `i' or `j' in numeric constant");
1793 pedwarn ("ANSI C forbids imaginary numeric constants");
1798 if (p
>= token_buffer
+ maxtoken
- 3)
1799 p
= extend_token_buffer (p
);
1804 /* If the literal overflowed, pedwarn about it now. */
1808 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT
* 2);
1811 /* This is simplified by the fact that our constant
1812 is always positive. */
1816 for (i
= 0; i
< HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
; i
++)
1818 high
|= ((HOST_WIDE_INT
) parts
[i
+ (HOST_BITS_PER_WIDE_INT
1819 / HOST_BITS_PER_CHAR
)]
1820 << (i
* HOST_BITS_PER_CHAR
));
1821 low
|= (HOST_WIDE_INT
) parts
[i
] << (i
* HOST_BITS_PER_CHAR
);
1824 yylval
.ttype
= build_int_2 (low
, high
);
1825 TREE_TYPE (yylval
.ttype
) = long_long_unsigned_type_node
;
1827 /* If warn_traditional, calculate both the ANSI type and the
1828 traditional type, then see if they disagree.
1829 Otherwise, calculate only the type for the dialect in use. */
1830 if (warn_traditional
|| flag_traditional
)
1832 /* Calculate the traditional type. */
1833 /* Traditionally, any constant is signed;
1834 but if unsigned is specified explicitly, obey that.
1835 Use the smallest size with the right number of bits,
1836 except for one special case with decimal constants. */
1837 if (! spec_long
&& base
!= 10
1838 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1839 traditional_type
= (spec_unsigned
? unsigned_type_node
1840 : integer_type_node
);
1841 /* A decimal constant must be long
1842 if it does not fit in type int.
1843 I think this is independent of whether
1844 the constant is signed. */
1845 else if (! spec_long
&& base
== 10
1846 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1847 traditional_type
= (spec_unsigned
? unsigned_type_node
1848 : integer_type_node
);
1849 else if (! spec_long_long
)
1850 traditional_type
= (spec_unsigned
? long_unsigned_type_node
1851 : long_integer_type_node
);
1852 else if (int_fits_type_p (yylval
.ttype
,
1854 ? long_long_unsigned_type_node
1855 : long_long_integer_type_node
))
1856 traditional_type
= (spec_unsigned
1857 ? long_long_unsigned_type_node
1858 : long_long_integer_type_node
);
1860 traditional_type
= (spec_unsigned
1861 ? widest_unsigned_literal_type_node
1862 : widest_integer_literal_type_node
);
1864 if (warn_traditional
|| ! flag_traditional
)
1866 /* Calculate the ANSI type. */
1867 if (! spec_long
&& ! spec_unsigned
1868 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1869 ansi_type
= integer_type_node
;
1870 else if (! spec_long
&& (base
!= 10 || spec_unsigned
)
1871 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1872 ansi_type
= unsigned_type_node
;
1873 else if (! spec_unsigned
&& !spec_long_long
1874 && int_fits_type_p (yylval
.ttype
, long_integer_type_node
))
1875 ansi_type
= long_integer_type_node
;
1876 else if (! spec_long_long
1877 && int_fits_type_p (yylval
.ttype
,
1878 long_unsigned_type_node
))
1879 ansi_type
= long_unsigned_type_node
;
1880 else if (! spec_unsigned
1881 && int_fits_type_p (yylval
.ttype
,
1882 long_long_integer_type_node
))
1883 ansi_type
= long_long_integer_type_node
;
1884 else if (int_fits_type_p (yylval
.ttype
,
1885 long_long_unsigned_type_node
))
1886 ansi_type
= long_long_unsigned_type_node
;
1887 else if (! spec_unsigned
1888 && int_fits_type_p (yylval
.ttype
,
1889 widest_integer_literal_type_node
))
1890 ansi_type
= widest_integer_literal_type_node
;
1892 ansi_type
= widest_unsigned_literal_type_node
;
1895 type
= flag_traditional
? traditional_type
: ansi_type
;
1897 if (warn_traditional
&& traditional_type
!= ansi_type
)
1899 if (TYPE_PRECISION (traditional_type
)
1900 != TYPE_PRECISION (ansi_type
))
1901 warning ("width of integer constant changes with -traditional");
1902 else if (TREE_UNSIGNED (traditional_type
)
1903 != TREE_UNSIGNED (ansi_type
))
1904 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1906 warning ("width of integer constant may change on other systems with -traditional");
1909 if (pedantic
&& !flag_traditional
&& !spec_long_long
&& !warn
1910 && (TYPE_PRECISION (long_integer_type_node
)
1911 < TYPE_PRECISION (type
)))
1914 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
1917 if (base
== 10 && ! spec_unsigned
&& TREE_UNSIGNED (type
))
1918 warning ("decimal constant is so large that it is unsigned");
1922 if (TYPE_PRECISION (type
)
1923 <= TYPE_PRECISION (integer_type_node
))
1925 = build_complex (NULL_TREE
, integer_zero_node
,
1926 convert (integer_type_node
,
1929 error ("complex integer constant is too wide for `complex int'");
1931 else if (flag_traditional
&& !int_fits_type_p (yylval
.ttype
, type
))
1932 /* The traditional constant 0x80000000 is signed
1933 but doesn't fit in the range of int.
1934 This will change it to -0x80000000, which does fit. */
1936 TREE_TYPE (yylval
.ttype
) = unsigned_type (type
);
1937 yylval
.ttype
= convert (type
, yylval
.ttype
);
1938 TREE_OVERFLOW (yylval
.ttype
)
1939 = TREE_CONSTANT_OVERFLOW (yylval
.ttype
) = 0;
1942 TREE_TYPE (yylval
.ttype
) = type
;
1945 /* If it's still an integer (not a complex), and it doesn't
1946 fit in the type we choose for it, then pedwarn. */
1949 && TREE_CODE (TREE_TYPE (yylval
.ttype
)) == INTEGER_TYPE
1950 && ! int_fits_type_p (yylval
.ttype
, TREE_TYPE (yylval
.ttype
)))
1951 pedwarn ("integer constant is larger than the maximum value for its type");
1957 if (ISALNUM (c
) || c
== '.' || c
== '_' || c
== '$'
1958 || (!flag_traditional
&& (c
== '-' || c
== '+')
1959 && (p
[-1] == 'e' || p
[-1] == 'E')))
1960 error ("missing white space after number `%s'", token_buffer
);
1962 value
= CONSTANT
; break;
1968 register int result
= 0;
1969 register int num_chars
= 0;
1971 unsigned width
= TYPE_PRECISION (char_type_node
);
1973 #ifdef MULTIBYTE_CHARS
1974 int longest_char
= local_mb_cur_max ();
1975 (void) local_mbtowc (NULL_PTR
, NULL_PTR
, 0);
1978 max_chars
= TYPE_PRECISION (integer_type_node
) / width
;
1980 width
= WCHAR_TYPE_SIZE
;
1987 if (c
== '\'' || c
== EOF
)
1994 c
= readescape (&ignore
);
1997 if (width
< HOST_BITS_PER_INT
1998 && (unsigned) c
>= ((unsigned)1 << width
))
1999 pedwarn ("escape sequence out of range for character");
2000 #ifdef MAP_CHARACTER
2002 c
= MAP_CHARACTER (c
);
2008 pedwarn ("ANSI C forbids newline in character constant");
2013 #ifdef MULTIBYTE_CHARS
2017 for (i
= 1; i
<= longest_char
; ++i
)
2019 if (i
> maxtoken
- 4)
2020 extend_token_buffer (token_buffer
);
2022 token_buffer
[i
] = c
;
2023 char_len
= local_mbtowc (& wc
,
2032 /* mbtowc sometimes needs an extra char before accepting */
2037 /* Merge character into result; ignore excess chars. */
2038 for (i
= 1; i
<= char_len
; ++i
)
2042 if (width
< HOST_BITS_PER_INT
)
2043 result
= (result
<< width
)
2045 & ((1 << width
) - 1));
2047 result
= token_buffer
[i
];
2049 num_chars
+= char_len
;
2058 warning ("Ignoring invalid multibyte character");
2059 /* Replace all but the first byte. */
2060 for (--i
; i
> 1; --i
)
2061 token_put_back (token_buffer
[i
]);
2062 wc
= token_buffer
[1];
2064 #ifdef MAP_CHARACTER
2065 c
= MAP_CHARACTER (wc
);
2070 #else /* ! MULTIBYTE_CHARS */
2071 #ifdef MAP_CHARACTER
2072 c
= MAP_CHARACTER (c
);
2074 #endif /* ! MULTIBYTE_CHARS */
2079 if (chars_seen
== 1) /* only keep the first one */
2084 /* Merge character into result; ignore excess chars. */
2085 num_chars
+= (width
/ TYPE_PRECISION (char_type_node
));
2086 if (num_chars
< max_chars
+ 1)
2088 if (width
< HOST_BITS_PER_INT
)
2089 result
= (result
<< width
) | (c
& ((1 << width
) - 1));
2096 error ("malformed character constant");
2097 else if (chars_seen
== 0)
2098 error ("empty character constant");
2099 else if (num_chars
> max_chars
)
2101 num_chars
= max_chars
;
2102 error ("character constant too long");
2104 else if (chars_seen
!= 1 && ! flag_traditional
&& warn_multichar
)
2105 warning ("multi-character character constant");
2107 /* If char type is signed, sign-extend the constant. */
2110 int num_bits
= num_chars
* width
;
2112 /* We already got an error; avoid invalid shift. */
2113 yylval
.ttype
= build_int_2 (0, 0);
2114 else if (TREE_UNSIGNED (char_type_node
)
2115 || ((result
>> (num_bits
- 1)) & 1) == 0)
2117 = build_int_2 (result
& (~(unsigned HOST_WIDE_INT
) 0
2118 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
2122 = build_int_2 (result
| ~(~(unsigned HOST_WIDE_INT
) 0
2123 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
2125 TREE_TYPE (yylval
.ttype
) = integer_type_node
;
2129 yylval
.ttype
= build_int_2 (result
, 0);
2130 TREE_TYPE (yylval
.ttype
) = wchar_type_node
;
2140 unsigned width
= wide_flag
? WCHAR_TYPE_SIZE
2141 : TYPE_PRECISION (char_type_node
);
2142 #ifdef MULTIBYTE_CHARS
2143 int longest_char
= local_mb_cur_max ();
2144 (void) local_mbtowc (NULL_PTR
, NULL_PTR
, 0);
2147 p
= token_buffer
+ 1;
2149 while (c
!= '"' && c
!= EOF
)
2151 /* ignore_escape_flag is set for reading the filename in #line. */
2152 if (!ignore_escape_flag
&& c
== '\\')
2155 c
= readescape (&ignore
);
2158 if (width
< HOST_BITS_PER_INT
2159 && (unsigned) c
>= ((unsigned)1 << width
))
2160 pedwarn ("escape sequence out of range for character");
2165 pedwarn ("ANSI C forbids newline in string constant");
2170 #ifdef MULTIBYTE_CHARS
2174 for (i
= 0; i
< longest_char
; ++i
)
2176 if (p
+ i
>= token_buffer
+ maxtoken
)
2177 p
= extend_token_buffer (p
);
2180 char_len
= local_mbtowc (& wc
, p
, i
+ 1);
2187 warning ("Ignoring invalid multibyte character");
2188 /* Replace all except the first byte. */
2190 for (--i
; i
> 0; --i
)
2191 token_put_back (p
[i
]);
2194 /* mbtowc sometimes needs an extra char before accepting */
2204 #endif /* MULTIBYTE_CHARS */
2207 /* Add this single character into the buffer either as a wchar_t
2208 or as a single byte. */
2211 unsigned width
= TYPE_PRECISION (char_type_node
);
2212 unsigned bytemask
= (1 << width
) - 1;
2215 if (p
+ WCHAR_BYTES
> token_buffer
+ maxtoken
)
2216 p
= extend_token_buffer (p
);
2218 for (byte
= 0; byte
< WCHAR_BYTES
; ++byte
)
2221 if (byte
>= (int) sizeof (c
))
2224 value
= (c
>> (byte
* width
)) & bytemask
;
2225 if (BYTES_BIG_ENDIAN
)
2226 p
[WCHAR_BYTES
- byte
- 1] = value
;
2234 if (p
>= token_buffer
+ maxtoken
)
2235 p
= extend_token_buffer (p
);
2243 /* Terminate the string value, either with a single byte zero
2244 or with a wide zero. */
2247 if (p
+ WCHAR_BYTES
> token_buffer
+ maxtoken
)
2248 p
= extend_token_buffer (p
);
2249 bzero (p
, WCHAR_BYTES
);
2254 if (p
>= token_buffer
+ maxtoken
)
2255 p
= extend_token_buffer (p
);
2260 error ("Unterminated string constant");
2262 /* We have read the entire constant.
2263 Construct a STRING_CST for the result. */
2267 yylval
.ttype
= build_string (p
- (token_buffer
+ 1),
2269 TREE_TYPE (yylval
.ttype
) = wchar_array_type_node
;
2274 /* Return an Objective-C @"..." constant string object. */
2275 yylval
.ttype
= build_objc_string (p
- (token_buffer
+ 1),
2277 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
2278 value
= OBJC_STRING
;
2282 yylval
.ttype
= build_string (p
- (token_buffer
+ 1),
2284 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
2312 yylval
.code
= PLUS_EXPR
; break;
2314 yylval
.code
= MINUS_EXPR
; break;
2316 yylval
.code
= BIT_AND_EXPR
; break;
2318 yylval
.code
= BIT_IOR_EXPR
; break;
2320 yylval
.code
= MULT_EXPR
; break;
2322 yylval
.code
= TRUNC_DIV_EXPR
; break;
2324 yylval
.code
= TRUNC_MOD_EXPR
; break;
2326 yylval
.code
= BIT_XOR_EXPR
; break;
2328 yylval
.code
= LSHIFT_EXPR
; break;
2330 yylval
.code
= RSHIFT_EXPR
; break;
2332 yylval
.code
= LT_EXPR
; break;
2334 yylval
.code
= GT_EXPR
; break;
2337 token_buffer
[1] = c1
= token_getch();
2338 token_buffer
[2] = 0;
2345 value
= ARITHCOMPARE
; yylval
.code
= LE_EXPR
; goto done
;
2347 value
= ARITHCOMPARE
; yylval
.code
= GE_EXPR
; goto done
;
2349 value
= EQCOMPARE
; yylval
.code
= NE_EXPR
; goto done
;
2351 value
= EQCOMPARE
; yylval
.code
= EQ_EXPR
; goto done
;
2353 value
= ASSIGN
; goto done
;
2359 value
= PLUSPLUS
; goto done
;
2361 value
= MINUSMINUS
; goto done
;
2363 value
= ANDAND
; goto done
;
2365 value
= OROR
; goto done
;
2378 { value
= POINTSAT
; goto done
; }
2384 { value
= ']'; goto done
; }
2388 { value
= '{'; indent_level
++; goto done
; }
2390 { value
= '['; goto done
; }
2394 { value
= '}'; indent_level
--; goto done
; }
2398 token_put_back (c1
);
2399 token_buffer
[1] = 0;
2401 if ((c
== '<') || (c
== '>'))
2402 value
= ARITHCOMPARE
;
2408 /* Don't make yyparse think this is eof. */
2427 /* yylloc.last_line = lineno; */
2432 /* Sets the value of the 'yydebug' variable to VALUE.
2433 This is a function so we don't have to have YYDEBUG defined
2434 in order to build the compiler. */
2443 warning ("YYDEBUG not defined.");