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 /* The elements of `ridpointers' are identifier nodes
66 for the reserved type names and storage classes.
67 It is indexed by a RID_... value. */
68 tree ridpointers
[(int) RID_MAX
];
70 /* Cause the `yydebug' variable to be defined. */
74 extern unsigned char *yy_cur
, *yy_lim
;
75 extern enum cpp_token cpp_token
;
77 extern int yy_get_token ();
79 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
80 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
82 #else /* ! USE_CPPLIB */
84 #define GETC() getch ()
85 #define UNGETC(c) put_back (c)
87 struct putback_buffer
{
88 unsigned char *buffer
;
93 static struct putback_buffer putback
= {NULL
, 0, -1};
95 static inline int getch
PARAMS ((void));
100 if (putback
.index
!= -1)
102 int ch
= putback
.buffer
[putback
.index
];
106 return getc (finput
);
109 static inline void put_back
PARAMS ((int));
117 if (putback
.index
== putback
.buffer_size
- 1)
119 putback
.buffer_size
+= 16;
120 putback
.buffer
= xrealloc (putback
.buffer
, putback
.buffer_size
);
122 putback
.buffer
[++putback
.index
] = ch
;
125 #endif /* ! USE_CPPLIB */
129 /* the declaration found for the last IDENTIFIER token read in.
130 yylex must look this up to detect typedefs, which get token type TYPENAME,
131 so it is left around in case the identifier is not a typedef but is
132 used in a context which makes it a reference to a variable. */
135 /* Nonzero enables objc features. */
137 int doing_objc_thang
;
141 /* File used for outputting assembler code. */
142 extern FILE *asm_out_file
;
144 #undef WCHAR_TYPE_SIZE
145 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
147 /* Number of bytes in a wide character. */
148 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
150 static int maxtoken
; /* Current nominal length of token buffer. */
151 char *token_buffer
; /* Pointer to token buffer.
152 Actual allocated length is maxtoken + 2.
153 This is not static because objc-parse.y uses it. */
155 static int indent_level
; /* Number of { minus number of }. */
157 /* Nonzero tells yylex to ignore \ in string constants. */
158 static int ignore_escape_flag
;
160 /* Nonzero if end-of-file has been seen on input. */
161 static int end_of_file
;
163 #ifdef HANDLE_GENERIC_PRAGMAS
164 static int handle_generic_pragma
PARAMS ((int));
165 #endif /* HANDLE_GENERIC_PRAGMAS */
166 static int whitespace_cr
PARAMS ((int));
167 static int skip_white_space
PARAMS ((int));
168 static char *extend_token_buffer
PARAMS ((const char *));
169 static int readescape
PARAMS ((int *));
170 static void parse_float
PARAMS ((PTR
));
171 static void extend_token_buffer_to
PARAMS ((int));
172 static int read_line_number
PARAMS ((int *));
174 /* Do not insert generated code into the source, instead, include it.
175 This allows us to build gcc automatically even for targets that
176 need to add or modify the reserved keyword lists. */
179 /* Return something to represent absolute declarators containing a *.
180 TARGET is the absolute declarator that the * contains.
181 TYPE_QUALS is a list of modifiers such as const or volatile
182 to apply to the pointer type, represented as identifiers.
184 We return an INDIRECT_REF whose "contents" are TARGET
185 and whose type is the modifier list. */
188 make_pointer_declarator (type_quals
, target
)
189 tree type_quals
, target
;
191 return build1 (INDIRECT_REF
, type_quals
, target
);
195 forget_protocol_qualifiers ()
197 int i
, n
= sizeof wordlist
/ sizeof (struct resword
);
199 for (i
= 0; i
< n
; i
++)
200 if ((int) wordlist
[i
].rid
>= (int) RID_IN
201 && (int) wordlist
[i
].rid
<= (int) RID_ONEWAY
)
202 wordlist
[i
].name
= "";
206 remember_protocol_qualifiers ()
208 int i
, n
= sizeof wordlist
/ sizeof (struct resword
);
210 for (i
= 0; i
< n
; i
++)
211 if (wordlist
[i
].rid
== RID_IN
)
212 wordlist
[i
].name
= "in";
213 else if (wordlist
[i
].rid
== RID_OUT
)
214 wordlist
[i
].name
= "out";
215 else if (wordlist
[i
].rid
== RID_INOUT
)
216 wordlist
[i
].name
= "inout";
217 else if (wordlist
[i
].rid
== RID_BYCOPY
)
218 wordlist
[i
].name
= "bycopy";
219 else if (wordlist
[i
].rid
== RID_BYREF
)
220 wordlist
[i
].name
= "byref";
221 else if (wordlist
[i
].rid
== RID_ONEWAY
)
222 wordlist
[i
].name
= "oneway";
226 init_parse (filename
)
230 /* Open input file. */
231 if (filename
== 0 || !strcmp (filename
, "-"))
237 finput
= fopen (filename
, "r");
239 pfatal_with_name (filename
);
241 #ifdef IO_BUFFER_SIZE
242 setvbuf (finput
, (char *) xmalloc (IO_BUFFER_SIZE
), _IOFBF
, IO_BUFFER_SIZE
);
244 #else /* !USE_CPPLIB */
245 parse_in
.show_column
= 1;
246 if (! cpp_start_read (&parse_in
, filename
))
249 if (filename
== 0 || !strcmp (filename
, "-"))
252 /* cpp_start_read always puts at least one line directive into the
253 token buffer. We must arrange to read it out here. */
254 yy_cur
= parse_in
.token_buffer
;
255 yy_lim
= CPP_PWRITTEN (&parse_in
);
256 cpp_token
= CPP_DIRECTIVE
;
269 cpp_finish (&parse_in
);
270 errorcount
+= parse_in
.errors
;
279 /* Make identifier nodes long enough for the language-specific slots. */
280 set_identifier_size (sizeof (struct lang_identifier
));
282 /* Start it at 0, because check_newline is called at the very beginning
283 and will increment it to 1. */
286 #ifdef MULTIBYTE_CHARS
287 /* Change to the native locale for multibyte conversions. */
288 setlocale (LC_CTYPE
, "");
289 GET_ENVIRONMENT (literal_codeset
, "LANG");
293 token_buffer
= (char *) xmalloc (maxtoken
+ 2);
295 ridpointers
[(int) RID_INT
] = get_identifier ("int");
296 ridpointers
[(int) RID_CHAR
] = get_identifier ("char");
297 ridpointers
[(int) RID_VOID
] = get_identifier ("void");
298 ridpointers
[(int) RID_FLOAT
] = get_identifier ("float");
299 ridpointers
[(int) RID_DOUBLE
] = get_identifier ("double");
300 ridpointers
[(int) RID_SHORT
] = get_identifier ("short");
301 ridpointers
[(int) RID_LONG
] = get_identifier ("long");
302 ridpointers
[(int) RID_UNSIGNED
] = get_identifier ("unsigned");
303 ridpointers
[(int) RID_SIGNED
] = get_identifier ("signed");
304 ridpointers
[(int) RID_INLINE
] = get_identifier ("inline");
305 ridpointers
[(int) RID_CONST
] = get_identifier ("const");
306 ridpointers
[(int) RID_RESTRICT
] = get_identifier ("restrict");
307 ridpointers
[(int) RID_VOLATILE
] = get_identifier ("volatile");
308 ridpointers
[(int) RID_AUTO
] = get_identifier ("auto");
309 ridpointers
[(int) RID_STATIC
] = get_identifier ("static");
310 ridpointers
[(int) RID_EXTERN
] = get_identifier ("extern");
311 ridpointers
[(int) RID_TYPEDEF
] = get_identifier ("typedef");
312 ridpointers
[(int) RID_REGISTER
] = get_identifier ("register");
313 ridpointers
[(int) RID_ITERATOR
] = get_identifier ("iterator");
314 ridpointers
[(int) RID_COMPLEX
] = get_identifier ("complex");
315 ridpointers
[(int) RID_ID
] = get_identifier ("id");
316 ridpointers
[(int) RID_IN
] = get_identifier ("in");
317 ridpointers
[(int) RID_OUT
] = get_identifier ("out");
318 ridpointers
[(int) RID_INOUT
] = get_identifier ("inout");
319 ridpointers
[(int) RID_BYCOPY
] = get_identifier ("bycopy");
320 ridpointers
[(int) RID_BYREF
] = get_identifier ("byref");
321 ridpointers
[(int) RID_ONEWAY
] = get_identifier ("oneway");
322 forget_protocol_qualifiers();
324 /* Some options inhibit certain reserved words.
325 Clear those words out of the hash table so they won't be recognized. */
326 #define UNSET_RESERVED_WORD(STRING) \
327 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
328 if (s) s->name = ""; } while (0)
330 if (! doing_objc_thang
)
331 UNSET_RESERVED_WORD ("id");
333 if (flag_traditional
)
335 UNSET_RESERVED_WORD ("const");
336 UNSET_RESERVED_WORD ("restrict");
337 UNSET_RESERVED_WORD ("volatile");
338 UNSET_RESERVED_WORD ("typeof");
339 UNSET_RESERVED_WORD ("signed");
340 UNSET_RESERVED_WORD ("inline");
341 UNSET_RESERVED_WORD ("iterator");
342 UNSET_RESERVED_WORD ("complex");
344 else if (!flag_isoc99
)
345 UNSET_RESERVED_WORD ("restrict");
349 UNSET_RESERVED_WORD ("asm");
350 UNSET_RESERVED_WORD ("typeof");
351 UNSET_RESERVED_WORD ("inline");
352 UNSET_RESERVED_WORD ("iterator");
353 UNSET_RESERVED_WORD ("complex");
358 reinit_parse_for_function ()
362 /* Function used when yydebug is set, to print a token in more detail. */
365 yyprint (file
, yychar
, yylval
)
377 if (IDENTIFIER_POINTER (t
))
378 fprintf (file
, " `%s'", IDENTIFIER_POINTER (t
));
383 if (TREE_CODE (t
) == INTEGER_CST
)
385 #if HOST_BITS_PER_WIDE_INT == 64
386 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
389 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
396 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
402 TREE_INT_CST_HIGH (t
), TREE_INT_CST_LOW (t
));
407 /* Iff C is a carriage return, warn about it - if appropriate -
408 and return nonzero. */
414 static int newline_warning
= 0;
418 /* ANSI C says the effects of a carriage return in a source file
420 if (pedantic
&& !newline_warning
)
422 warning ("carriage return in source file");
423 warning ("(we only warn about the first carriage return)");
431 /* If C is not whitespace, return C.
432 Otherwise skip whitespace and return first nonwhite char read. */
442 /* We don't recognize comments here, because
443 cpp output can include / and * consecutively as operators.
444 Also, there's no need, since cpp removes all comments. */
452 c
= check_newline ();
461 /* While processing a # directive we don't get CPP_HSPACE
462 tokens, so we also need to handle whitespace the normal way. */
463 if (cpp_token
== CPP_HSPACE
)
480 error ("stray '\\' in program");
490 /* Skips all of the white space at the current location in the input file. */
493 position_after_white_space ()
499 UNGETC (skip_white_space (c
));
502 /* Make the token buffer longer, preserving the data in it.
503 P should point to just beyond the last valid character in the old buffer.
504 The value we return is a pointer to the new buffer
505 at a place corresponding to P. */
508 extend_token_buffer_to (size
)
512 maxtoken
= maxtoken
* 2 + 10;
513 while (maxtoken
< size
);
514 token_buffer
= (char *) xrealloc (token_buffer
, maxtoken
+ 2);
518 extend_token_buffer (p
)
521 int offset
= p
- token_buffer
;
522 extend_token_buffer_to (offset
);
523 return token_buffer
+ offset
;
526 #if defined HANDLE_PRAGMA
527 /* Local versions of these macros, that can be passed as function pointers. */
543 read_line_number (num
)
546 register int token
= yylex ();
548 if (token
== CONSTANT
549 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
551 *num
= TREE_INT_CST_LOW (yylval
.ttype
);
556 if (token
!= END_OF_LINE
)
557 error ("invalid #-line");
562 /* At the beginning of a line, increment the line number
563 and process any #-directive on this line.
564 If the line is a #-directive, read the entire line and return a newline.
565 Otherwise, return the line's first non-whitespace character.
567 Note that in the case of USE_CPPLIB, we get the whole line as one
568 CPP_DIRECTIVE token. */
576 enum { act_none
, act_push
, act_pop
} action
;
577 int old_lineno
, action_number
, l
;
580 /* Read first nonwhite char on the line. */
584 /* In some cases where we're leaving an include file, we can get multiple
585 CPP_HSPACE tokens in a row, so we need to loop. */
586 while (cpp_token
== CPP_HSPACE
)
591 while (c
== ' ' || c
== '\t');
598 /* Sequences of multiple newlines are very common; optimize them. */
602 /* If not #, return it so caller will use it. */
606 /* Don't read beyond this line. */
611 if (cpp_token
== CPP_VSPACE
)
613 /* Format is "<space> <line number> <filename> <newline>".
614 Only the line number is interesting, and even that
615 we can get more efficiently than scanning the line. */
617 lineno
= parse_in
.lineno
- 1;
624 if (token
== IDENTIFIER
)
626 /* If a letter follows, then if the word here is `line', skip
627 it and ignore it; otherwise, ignore the line, with an error
628 if the word isn't `pragma'. */
630 const char *name
= IDENTIFIER_POINTER (yylval
.ttype
);
632 if (!strcmp (name
, "pragma"))
635 if (token
!= IDENTIFIER
636 || TREE_CODE (yylval
.ttype
) != IDENTIFIER_NODE
)
640 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
641 (if both are defined), in order to give the back
642 end a chance to override the interpretation of
643 SYSV style pragmas. */
644 if (HANDLE_PRAGMA (pragma_getc
, pragma_ungetc
,
645 IDENTIFIER_POINTER (yylval
.ttype
)))
647 #endif /* HANDLE_PRAGMA */
649 #ifdef HANDLE_GENERIC_PRAGMAS
650 if (handle_generic_pragma (token
))
652 #endif /* HANDLE_GENERIC_PRAGMAS */
654 /* Issue a warning message if we have been asked to do so.
655 Ignoring unknown pragmas in system header file unless
656 an explcit -Wunknown-pragmas has been given. */
657 if (warn_unknown_pragmas
> 1
658 || (warn_unknown_pragmas
&& ! in_system_header
))
659 warning ("ignoring pragma: %s", token_buffer
);
663 else if (!strcmp (name
, "define"))
665 debug_define (lineno
, GET_DIRECTIVE_LINE ());
668 else if (!strcmp (name
, "undef"))
670 debug_undef (lineno
, GET_DIRECTIVE_LINE ());
673 else if (!strcmp (name
, "line"))
679 else if (!strcmp (name
, "ident"))
681 /* #ident. The pedantic warning is now in cccp.c. */
683 /* Here we have just seen `#ident '.
684 A string constant should follow. */
687 if (token
== END_OF_LINE
)
690 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
692 error ("invalid #ident");
698 #ifdef ASM_OUTPUT_IDENT
699 ASM_OUTPUT_IDENT (asm_out_file
,
700 TREE_STRING_POINTER (yylval
.ttype
));
704 /* Skip the rest of this line. */
708 error ("undefined or invalid # directive `%s'", name
);
712 /* If the # is the only nonwhite char on the line,
713 just ignore it. Check the new newline. */
714 if (token
== END_OF_LINE
)
718 /* Here we have either `#line' or `# <nonletter>'.
719 In either case, it should be a line number; a digit should follow. */
721 if (token
!= CONSTANT
722 || TREE_CODE (yylval
.ttype
) != INTEGER_CST
)
724 error ("invalid #-line");
728 /* subtract one, because it is the following line that
729 gets the specified number */
731 l
= TREE_INT_CST_LOW (yylval
.ttype
) - 1;
733 /* More follows: it must be a string constant (filename).
734 It would be neat to use cpplib to quickly process the string, but
735 (1) we don't have a handy tokenization of the string, and
736 (2) I don't know how well that would work in the presense
737 of filenames that contain wide characters. */
741 /* Don't treat \ as special if we are processing #line 1 "...".
742 If you want it to be treated specially, use # 1 "...". */
743 ignore_escape_flag
= 1;
746 /* Read the string constant. */
749 ignore_escape_flag
= 0;
751 if (token
== END_OF_LINE
)
753 /* No more: store the line number and check following line. */
758 if (token
!= STRING
|| TREE_CODE (yylval
.ttype
) != STRING_CST
)
760 error ("invalid #line");
764 input_filename
= TREE_STRING_POINTER (yylval
.ttype
);
766 if (main_input_filename
== 0)
767 main_input_filename
= input_filename
;
774 /* Each change of file name
775 reinitializes whether we are now in a system header. */
776 in_system_header
= 0;
778 if (!read_line_number (&action_number
))
780 /* Update the name in the top element of input_file_stack. */
781 if (input_file_stack
)
782 input_file_stack
->name
= input_filename
;
785 /* `1' after file name means entering new file.
786 `2' after file name means just left a file. */
788 if (action_number
== 1)
791 read_line_number (&action_number
);
793 else if (action_number
== 2)
796 read_line_number (&action_number
);
798 if (action_number
== 3)
800 /* `3' after file name means this is a system header file. */
801 in_system_header
= 1;
802 read_line_number (&action_number
);
805 /* Do the actions implied by the preceding numbers. */
807 if (action
== act_push
)
809 /* Pushing to a new file. */
811 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
812 input_file_stack
->line
= old_lineno
;
813 p
->next
= input_file_stack
;
814 p
->name
= input_filename
;
815 p
->indent_level
= indent_level
;
816 input_file_stack
= p
;
817 input_file_stack_tick
++;
818 debug_start_source_file (input_filename
);
820 else if (action
== act_pop
)
822 /* Popping out of a file. */
823 if (input_file_stack
->next
)
825 struct file_stack
*p
= input_file_stack
;
826 if (indent_level
!= p
->indent_level
)
828 warning_with_file_and_line
829 (p
->name
, old_lineno
,
830 "This file contains more `%c's than `%c's.",
831 indent_level
> p
->indent_level
? '{' : '}',
832 indent_level
> p
->indent_level
? '}' : '{');
834 input_file_stack
= p
->next
;
836 input_file_stack_tick
++;
837 debug_end_source_file (input_file_stack
->line
);
840 error ("#-lines for entering and leaving files don't match");
843 /* Now that we've pushed or popped the input stack,
844 update the name in the top element. */
845 if (input_file_stack
)
846 input_file_stack
->name
= input_filename
;
848 /* skip the rest of this line. */
855 while (c
!= '\n' && c
!= EOF
);
859 #ifdef HANDLE_GENERIC_PRAGMAS
861 /* Handle a #pragma directive.
862 TOKEN is the token we read after `#pragma'. Processes the entire input
863 line and return non-zero iff the pragma has been successfully parsed. */
865 /* This function has to be in this file, in order to get at
869 handle_generic_pragma (token
)
880 handle_pragma_token (token_buffer
, yylval
.ttype
);
884 return handle_pragma_token (NULL_PTR
, NULL_TREE
);
887 handle_pragma_token (token_buffer
, NULL
);
894 #endif /* HANDLE_GENERIC_PRAGMAS */
896 #define ENDFILE -1 /* token that represents end-of-file */
898 /* Read an escape sequence, returning its equivalent as a character,
899 or store 1 in *ignore_ptr if it is backslash-newline. */
902 readescape (ignore_ptr
)
905 register int c
= GETC();
907 register unsigned count
;
908 unsigned firstdig
= 0;
914 if (warn_traditional
)
915 warning ("the meaning of `\\x' varies with -traditional");
917 if (flag_traditional
)
932 if (c
>= 'a' && c
<= 'f')
933 code
+= c
- 'a' + 10;
934 if (c
>= 'A' && c
<= 'F')
935 code
+= c
- 'A' + 10;
936 if (c
>= '0' && c
<= '9')
938 if (code
!= 0 || count
!= 0)
948 warning ("\\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
1205 static inline int token_getch
PARAMS ((void));
1211 if (yy_cur
== yy_lim
)
1217 static inline void token_put_back
PARAMS ((int));
1230 /* Read a single token from the input stream, and assign it lexical
1244 /* Effectively do c = skip_white_space (c)
1245 but do it faster in the usual cases. */
1255 if (cpp_token
== CPP_HSPACE
)
1256 c
= yy_get_token ();
1263 /* Call skip_white_space so we can warn if appropriate. */
1268 c
= skip_white_space (c
);
1270 goto found_nonwhite
;
1274 token_buffer
[0] = c
;
1275 token_buffer
[1] = 0;
1277 /* yylloc.first_line = lineno; */
1283 token_buffer
[0] = 0;
1285 value
= END_OF_LINE
;
1292 if (cpp_token
== CPP_NAME
)
1295 /* Capital L may start a wide-string or wide-character constant. */
1297 register int c
= token_getch();
1306 goto string_constant
;
1313 if (!doing_objc_thang
)
1320 /* '@' may start a constant string object. */
1321 register int c
= token_getch ();
1325 goto string_constant
;
1328 /* Fall through to treat '@' as the start of an identifier. */
1331 case 'A': case 'B': case 'C': case 'D': case 'E':
1332 case 'F': case 'G': case 'H': case 'I': case 'J':
1333 case 'K': case 'M': case 'N': case 'O':
1334 case 'P': case 'Q': case 'R': case 'S': case 'T':
1335 case 'U': case 'V': case 'W': case 'X': case 'Y':
1337 case 'a': case 'b': case 'c': case 'd': case 'e':
1338 case 'f': case 'g': case 'h': case 'i': case 'j':
1339 case 'k': case 'l': case 'm': case 'n': case 'o':
1340 case 'p': case 'q': case 'r': case 's': case 't':
1341 case 'u': case 'v': case 'w': case 'x': case 'y':
1347 if (cpp_token
== CPP_NAME
)
1349 /* Note that one character has already been read from
1350 yy_cur into token_buffer. Also, cpplib complains about
1351 $ in identifiers, so we don't have to. */
1353 int len
= yy_lim
- yy_cur
+ 1;
1354 if (len
>= maxtoken
)
1355 extend_token_buffer_to (len
+ 1);
1356 memcpy (token_buffer
+ 1, yy_cur
, len
);
1357 p
= token_buffer
+ len
;
1364 while (ISALNUM (c
) || c
== '_' || c
== '$' || c
== '@')
1366 /* Make sure this char really belongs in an identifier. */
1369 if (! dollars_in_ident
)
1370 error ("`$' in identifier");
1372 pedwarn ("`$' in identifier");
1375 if (p
>= token_buffer
+ maxtoken
)
1376 p
= extend_token_buffer (p
);
1389 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1392 register struct resword
*ptr
;
1394 if ((ptr
= is_reserved_word (token_buffer
, p
- token_buffer
)))
1397 yylval
.ttype
= ridpointers
[(int) ptr
->rid
];
1398 value
= (int) ptr
->token
;
1400 /* Only return OBJECTNAME if it is a typedef. */
1401 if (doing_objc_thang
&& value
== OBJECTNAME
)
1403 lastiddecl
= lookup_name(yylval
.ttype
);
1405 if (lastiddecl
== NULL_TREE
1406 || TREE_CODE (lastiddecl
) != TYPE_DECL
)
1410 /* Even if we decided to recognize asm, still perhaps warn. */
1412 && (value
== ASM_KEYWORD
|| value
== TYPEOF
1413 || ptr
->rid
== RID_INLINE
)
1414 && token_buffer
[0] != '_')
1415 pedwarn ("ANSI does not permit the keyword `%s'",
1420 /* If we did not find a keyword, look for an identifier
1423 if (value
== IDENTIFIER
)
1425 if (token_buffer
[0] == '@')
1426 error("invalid identifier `%s'", token_buffer
);
1428 yylval
.ttype
= get_identifier (token_buffer
);
1429 lastiddecl
= lookup_name (yylval
.ttype
);
1431 if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == TYPE_DECL
)
1433 /* A user-invisible read-only initialized variable
1434 should be replaced by its value.
1435 We handle only strings since that's the only case used in C. */
1436 else if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == VAR_DECL
1437 && DECL_IGNORED_P (lastiddecl
)
1438 && TREE_READONLY (lastiddecl
)
1439 && DECL_INITIAL (lastiddecl
) != 0
1440 && TREE_CODE (DECL_INITIAL (lastiddecl
)) == STRING_CST
)
1442 tree stringval
= DECL_INITIAL (lastiddecl
);
1444 /* Copy the string value so that we won't clobber anything
1445 if we put something in the TREE_CHAIN of this one. */
1446 yylval
.ttype
= build_string (TREE_STRING_LENGTH (stringval
),
1447 TREE_STRING_POINTER (stringval
));
1450 else if (doing_objc_thang
)
1452 tree objc_interface_decl
= is_class_name (yylval
.ttype
);
1454 if (objc_interface_decl
)
1457 yylval
.ttype
= objc_interface_decl
;
1466 if (yy_cur
< yy_lim
)
1469 /* It's hard to preserve tokenization on '.' because
1470 it could be a symbol by itself, or it could be the
1471 start of a floating point number and cpp won't tell us. */
1472 register int c1
= token_getch ();
1473 token_buffer
[1] = c1
;
1476 c1
= token_getch ();
1479 token_buffer
[2] = c1
;
1480 token_buffer
[3] = 0;
1484 error ("parse error at `..'");
1488 token_put_back (c1
);
1491 token_put_back (c1
);
1494 token_buffer
[1] = 0;
1498 /* Optimize for most frequent case. */
1503 cond
= (yy_cur
== yy_lim
);
1505 register int c1
= token_getch ();
1506 token_put_back (c1
);
1507 cond
= (! ISALNUM (c1
) && c1
!= '.');
1511 yylval
.ttype
= (c
== '0') ? integer_zero_node
: integer_one_node
;
1517 case '2': case '3': case '4':
1518 case '5': case '6': case '7': case '8': case '9':
1523 int largest_digit
= 0;
1527 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
1528 The code below which fills the parts array assumes that a host
1529 int is at least twice as wide as a host char, and that
1530 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
1531 Two HOST_WIDE_INTs is the largest int literal we can store.
1532 In order to detect overflow below, the number of parts (TOTAL_PARTS)
1533 must be exactly the number of parts needed to hold the bits
1534 of two HOST_WIDE_INTs. */
1535 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
1536 unsigned int parts
[TOTAL_PARTS
];
1538 enum anon1
{ NOT_FLOAT
, AFTER_POINT
, TOO_MANY_POINTS
, AFTER_EXPON
}
1539 floatflag
= NOT_FLOAT
;
1541 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1549 *p
++ = (c
= token_getch());
1550 if ((c
== 'x') || (c
== 'X'))
1553 *p
++ = (c
= token_getch());
1555 /* Leading 0 forces octal unless the 0 is the only digit. */
1556 else if (c
>= '0' && c
<= '9')
1565 /* Read all the digits-and-decimal-points. */
1568 || (ISALNUM (c
) && c
!= 'l' && c
!= 'L'
1569 && c
!= 'u' && c
!= 'U'
1570 && c
!= 'i' && c
!= 'I' && c
!= 'j' && c
!= 'J'
1571 && (floatflag
== NOT_FLOAT
1572 || ((base
!= 16) && (c
!= 'f') && (c
!= 'F'))
1577 if (base
== 16 && pedantic
)
1578 pedwarn ("floating constant may not be in radix 16");
1579 if (floatflag
== TOO_MANY_POINTS
)
1580 /* We have already emitted an error. Don't need another. */
1582 else if (floatflag
== AFTER_POINT
|| floatflag
== AFTER_EXPON
)
1584 error ("malformed floating constant");
1585 floatflag
= TOO_MANY_POINTS
;
1586 /* Avoid another error from atof by forcing all characters
1587 from here on to be ignored. */
1591 floatflag
= AFTER_POINT
;
1595 *p
++ = c
= token_getch();
1596 /* Accept '.' as the start of a floating-point number
1597 only when it is followed by a digit. */
1598 if (p
== token_buffer
+ 2 && !ISDIGIT (c
))
1603 /* It is not a decimal point.
1604 It should be a digit (perhaps a hex digit). */
1610 else if (base
<= 10)
1612 if (c
== 'e' || c
== 'E')
1615 floatflag
= AFTER_EXPON
;
1616 break; /* start of exponent */
1618 error ("nondigits in number and not hexadecimal");
1621 else if (base
== 16 && (c
== 'p' || c
== 'P'))
1623 floatflag
= AFTER_EXPON
;
1624 break; /* start of exponent */
1634 if (c
>= largest_digit
)
1638 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1640 parts
[count
] *= base
;
1644 += (parts
[count
-1] >> HOST_BITS_PER_CHAR
);
1646 &= (1 << HOST_BITS_PER_CHAR
) - 1;
1652 /* If the highest-order part overflows (gets larger than
1653 a host char will hold) then the whole number has
1654 overflowed. Record this and truncate the highest-order
1656 if (parts
[TOTAL_PARTS
- 1] >> HOST_BITS_PER_CHAR
)
1659 parts
[TOTAL_PARTS
- 1] &= (1 << HOST_BITS_PER_CHAR
) - 1;
1662 if (p
>= token_buffer
+ maxtoken
- 3)
1663 p
= extend_token_buffer (p
);
1664 *p
++ = (c
= token_getch());
1668 /* This can happen on input like `int i = 0x;' */
1670 error ("numeric constant with no digits");
1672 if (largest_digit
>= base
)
1673 error ("numeric constant contains digits beyond the radix");
1675 /* Remove terminating char from the token buffer and delimit the
1679 if (floatflag
!= NOT_FLOAT
)
1682 int imag
, conversion_errno
;
1683 REAL_VALUE_TYPE value
;
1684 struct pf_args args
;
1686 /* Read explicit exponent if any, and put it in tokenbuf. */
1688 if ((base
== 10 && ((c
== 'e') || (c
== 'E')))
1689 || (base
== 16 && (c
== 'p' || c
== 'P')))
1691 if (p
>= token_buffer
+ maxtoken
- 3)
1692 p
= extend_token_buffer (p
);
1695 if ((c
== '+') || (c
== '-'))
1700 /* Exponent is decimal, even if string is a hex float. */
1702 error ("floating constant exponent has no digits");
1705 if (p
>= token_buffer
+ maxtoken
- 3)
1706 p
= extend_token_buffer (p
);
1711 if (base
== 16 && floatflag
!= AFTER_EXPON
)
1712 error ("hexadecimal floating constant has no exponent");
1716 /* Setup input for parse_float() */
1721 /* Convert string to a double, checking for overflow. */
1722 if (do_float_handler (parse_float
, (PTR
) &args
))
1724 /* Receive output from parse_float() */
1729 /* We got an exception from parse_float() */
1730 error ("floating constant out of range");
1734 /* Receive output from parse_float() */
1738 conversion_errno
= args
.conversion_errno
;
1741 /* ERANGE is also reported for underflow,
1742 so test the value to distinguish overflow from that. */
1743 if (conversion_errno
== ERANGE
&& !flag_traditional
&& pedantic
1744 && (REAL_VALUES_LESS (dconst1
, value
)
1745 || REAL_VALUES_LESS (value
, dconstm1
)))
1746 warning ("floating point number exceeds range of `double'");
1749 /* If the result is not a number, assume it must have been
1750 due to some error message above, so silently convert
1752 if (REAL_VALUE_ISNAN (value
))
1755 /* Create a node with determined type and value. */
1757 yylval
.ttype
= build_complex (NULL_TREE
,
1758 convert (type
, integer_zero_node
),
1759 build_real (type
, value
));
1761 yylval
.ttype
= build_real (type
, value
);
1765 tree traditional_type
, ansi_type
, type
;
1766 HOST_WIDE_INT high
, low
;
1767 int spec_unsigned
= 0;
1769 int spec_long_long
= 0;
1773 traditional_type
= ansi_type
= type
= NULL_TREE
;
1776 if (c
== 'u' || c
== 'U')
1779 error ("two `u's in integer constant");
1782 else if (c
== 'l' || c
== 'L')
1787 error ("three `l's in integer constant");
1788 else if (pedantic
&& ! in_system_header
&& warn_long_long
)
1789 pedwarn ("ANSI C forbids long long integer constants");
1794 else if (c
== 'i' || c
== 'j' || c
== 'I' || c
== 'J')
1797 error ("more than one `i' or `j' in numeric constant");
1799 pedwarn ("ANSI C forbids imaginary numeric constants");
1804 if (p
>= token_buffer
+ maxtoken
- 3)
1805 p
= extend_token_buffer (p
);
1810 /* If the literal overflowed, pedwarn about it now. */
1814 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT
* 2);
1817 /* This is simplified by the fact that our constant
1818 is always positive. */
1822 for (i
= 0; i
< HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
; i
++)
1824 high
|= ((HOST_WIDE_INT
) parts
[i
+ (HOST_BITS_PER_WIDE_INT
1825 / HOST_BITS_PER_CHAR
)]
1826 << (i
* HOST_BITS_PER_CHAR
));
1827 low
|= (HOST_WIDE_INT
) parts
[i
] << (i
* HOST_BITS_PER_CHAR
);
1830 yylval
.ttype
= build_int_2 (low
, high
);
1831 TREE_TYPE (yylval
.ttype
) = long_long_unsigned_type_node
;
1833 /* If warn_traditional, calculate both the ANSI type and the
1834 traditional type, then see if they disagree.
1835 Otherwise, calculate only the type for the dialect in use. */
1836 if (warn_traditional
|| flag_traditional
)
1838 /* Calculate the traditional type. */
1839 /* Traditionally, any constant is signed;
1840 but if unsigned is specified explicitly, obey that.
1841 Use the smallest size with the right number of bits,
1842 except for one special case with decimal constants. */
1843 if (! spec_long
&& base
!= 10
1844 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1845 traditional_type
= (spec_unsigned
? unsigned_type_node
1846 : integer_type_node
);
1847 /* A decimal constant must be long
1848 if it does not fit in type int.
1849 I think this is independent of whether
1850 the constant is signed. */
1851 else if (! spec_long
&& base
== 10
1852 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1853 traditional_type
= (spec_unsigned
? unsigned_type_node
1854 : integer_type_node
);
1855 else if (! spec_long_long
)
1856 traditional_type
= (spec_unsigned
? long_unsigned_type_node
1857 : long_integer_type_node
);
1858 else if (int_fits_type_p (yylval
.ttype
,
1860 ? long_long_unsigned_type_node
1861 : long_long_integer_type_node
))
1862 traditional_type
= (spec_unsigned
1863 ? long_long_unsigned_type_node
1864 : long_long_integer_type_node
);
1866 traditional_type
= (spec_unsigned
1867 ? widest_unsigned_literal_type_node
1868 : widest_integer_literal_type_node
);
1870 if (warn_traditional
|| ! flag_traditional
)
1872 /* Calculate the ANSI type. */
1873 if (! spec_long
&& ! spec_unsigned
1874 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1875 ansi_type
= integer_type_node
;
1876 else if (! spec_long
&& (base
!= 10 || spec_unsigned
)
1877 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1878 ansi_type
= unsigned_type_node
;
1879 else if (! spec_unsigned
&& !spec_long_long
1880 && int_fits_type_p (yylval
.ttype
, long_integer_type_node
))
1881 ansi_type
= long_integer_type_node
;
1882 else if (! spec_long_long
1883 && int_fits_type_p (yylval
.ttype
,
1884 long_unsigned_type_node
))
1885 ansi_type
= long_unsigned_type_node
;
1886 else if (! spec_unsigned
1887 && int_fits_type_p (yylval
.ttype
,
1888 long_long_integer_type_node
))
1889 ansi_type
= long_long_integer_type_node
;
1890 else if (int_fits_type_p (yylval
.ttype
,
1891 long_long_unsigned_type_node
))
1892 ansi_type
= long_long_unsigned_type_node
;
1893 else if (! spec_unsigned
1894 && int_fits_type_p (yylval
.ttype
,
1895 widest_integer_literal_type_node
))
1896 ansi_type
= widest_integer_literal_type_node
;
1898 ansi_type
= widest_unsigned_literal_type_node
;
1901 type
= flag_traditional
? traditional_type
: ansi_type
;
1903 /* We assume that constants specified in a non-decimal
1904 base are bit patterns, and that the programmer really
1905 meant what they wrote. */
1906 if (warn_traditional
&& base
== 10
1907 && traditional_type
!= ansi_type
)
1909 if (TYPE_PRECISION (traditional_type
)
1910 != TYPE_PRECISION (ansi_type
))
1911 warning ("width of integer constant changes with -traditional");
1912 else if (TREE_UNSIGNED (traditional_type
)
1913 != TREE_UNSIGNED (ansi_type
))
1914 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1916 warning ("width of integer constant may change on other systems with -traditional");
1919 if (pedantic
&& !flag_traditional
&& !spec_long_long
&& !warn
1920 && (TYPE_PRECISION (long_integer_type_node
)
1921 < TYPE_PRECISION (type
)))
1924 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
1927 if (base
== 10 && ! spec_unsigned
&& TREE_UNSIGNED (type
))
1928 warning ("decimal constant is so large that it is unsigned");
1932 if (TYPE_PRECISION (type
)
1933 <= TYPE_PRECISION (integer_type_node
))
1935 = build_complex (NULL_TREE
, integer_zero_node
,
1936 convert (integer_type_node
,
1939 error ("complex integer constant is too wide for `complex int'");
1941 else if (flag_traditional
&& !int_fits_type_p (yylval
.ttype
, type
))
1942 /* The traditional constant 0x80000000 is signed
1943 but doesn't fit in the range of int.
1944 This will change it to -0x80000000, which does fit. */
1946 TREE_TYPE (yylval
.ttype
) = unsigned_type (type
);
1947 yylval
.ttype
= convert (type
, yylval
.ttype
);
1948 TREE_OVERFLOW (yylval
.ttype
)
1949 = TREE_CONSTANT_OVERFLOW (yylval
.ttype
) = 0;
1952 TREE_TYPE (yylval
.ttype
) = type
;
1955 /* If it's still an integer (not a complex), and it doesn't
1956 fit in the type we choose for it, then pedwarn. */
1959 && TREE_CODE (TREE_TYPE (yylval
.ttype
)) == INTEGER_TYPE
1960 && ! int_fits_type_p (yylval
.ttype
, TREE_TYPE (yylval
.ttype
)))
1961 pedwarn ("integer constant is larger than the maximum value for its type");
1967 if (ISALNUM (c
) || c
== '.' || c
== '_' || c
== '$'
1968 || (!flag_traditional
&& (c
== '-' || c
== '+')
1969 && (p
[-1] == 'e' || p
[-1] == 'E')))
1970 error ("missing white space after number `%s'", token_buffer
);
1972 value
= CONSTANT
; break;
1978 register int result
= 0;
1979 register int num_chars
= 0;
1981 unsigned width
= TYPE_PRECISION (char_type_node
);
1983 #ifdef MULTIBYTE_CHARS
1984 int longest_char
= local_mb_cur_max ();
1985 (void) local_mbtowc (NULL_PTR
, NULL_PTR
, 0);
1988 max_chars
= TYPE_PRECISION (integer_type_node
) / width
;
1990 width
= WCHAR_TYPE_SIZE
;
1997 if (c
== '\'' || c
== EOF
)
2004 c
= readescape (&ignore
);
2007 if (width
< HOST_BITS_PER_INT
2008 && (unsigned) c
>= ((unsigned)1 << width
))
2009 pedwarn ("escape sequence out of range for character");
2010 #ifdef MAP_CHARACTER
2012 c
= MAP_CHARACTER (c
);
2018 pedwarn ("ANSI C forbids newline in character constant");
2023 #ifdef MULTIBYTE_CHARS
2027 for (i
= 1; i
<= longest_char
; ++i
)
2029 if (i
> maxtoken
- 4)
2030 extend_token_buffer (token_buffer
);
2032 token_buffer
[i
] = c
;
2033 char_len
= local_mbtowc (& wc
,
2042 /* mbtowc sometimes needs an extra char before accepting */
2047 /* Merge character into result; ignore excess chars. */
2048 for (i
= 1; i
<= char_len
; ++i
)
2052 if (width
< HOST_BITS_PER_INT
)
2053 result
= (result
<< width
)
2055 & ((1 << width
) - 1));
2057 result
= token_buffer
[i
];
2059 num_chars
+= char_len
;
2068 warning ("Ignoring invalid multibyte character");
2069 /* Replace all but the first byte. */
2070 for (--i
; i
> 1; --i
)
2071 token_put_back (token_buffer
[i
]);
2072 wc
= token_buffer
[1];
2074 #ifdef MAP_CHARACTER
2075 c
= MAP_CHARACTER (wc
);
2080 #else /* ! MULTIBYTE_CHARS */
2081 #ifdef MAP_CHARACTER
2082 c
= MAP_CHARACTER (c
);
2084 #endif /* ! MULTIBYTE_CHARS */
2089 if (chars_seen
== 1) /* only keep the first one */
2094 /* Merge character into result; ignore excess chars. */
2095 num_chars
+= (width
/ TYPE_PRECISION (char_type_node
));
2096 if (num_chars
< max_chars
+ 1)
2098 if (width
< HOST_BITS_PER_INT
)
2099 result
= (result
<< width
) | (c
& ((1 << width
) - 1));
2106 error ("malformed character constant");
2107 else if (chars_seen
== 0)
2108 error ("empty character constant");
2109 else if (num_chars
> max_chars
)
2111 num_chars
= max_chars
;
2112 error ("character constant too long");
2114 else if (chars_seen
!= 1 && ! flag_traditional
&& warn_multichar
)
2115 warning ("multi-character character constant");
2117 /* If char type is signed, sign-extend the constant. */
2120 int num_bits
= num_chars
* width
;
2122 /* We already got an error; avoid invalid shift. */
2123 yylval
.ttype
= build_int_2 (0, 0);
2124 else if (TREE_UNSIGNED (char_type_node
)
2125 || ((result
>> (num_bits
- 1)) & 1) == 0)
2127 = build_int_2 (result
& (~(unsigned HOST_WIDE_INT
) 0
2128 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
2132 = build_int_2 (result
| ~(~(unsigned HOST_WIDE_INT
) 0
2133 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
2135 TREE_TYPE (yylval
.ttype
) = integer_type_node
;
2139 yylval
.ttype
= build_int_2 (result
, 0);
2140 TREE_TYPE (yylval
.ttype
) = wchar_type_node
;
2150 unsigned width
= wide_flag
? WCHAR_TYPE_SIZE
2151 : TYPE_PRECISION (char_type_node
);
2152 #ifdef MULTIBYTE_CHARS
2153 int longest_char
= local_mb_cur_max ();
2154 (void) local_mbtowc (NULL_PTR
, NULL_PTR
, 0);
2157 p
= token_buffer
+ 1;
2159 while (c
!= '"' && c
!= EOF
)
2161 /* ignore_escape_flag is set for reading the filename in #line. */
2162 if (!ignore_escape_flag
&& c
== '\\')
2165 c
= readescape (&ignore
);
2168 if (width
< HOST_BITS_PER_INT
2169 && (unsigned) c
>= ((unsigned)1 << width
))
2170 pedwarn ("escape sequence out of range for character");
2175 pedwarn ("ANSI C forbids newline in string constant");
2180 #ifdef MULTIBYTE_CHARS
2184 for (i
= 0; i
< longest_char
; ++i
)
2186 if (p
+ i
>= token_buffer
+ maxtoken
)
2187 p
= extend_token_buffer (p
);
2190 char_len
= local_mbtowc (& wc
, p
, i
+ 1);
2197 warning ("Ignoring invalid multibyte character");
2198 /* Replace all except the first byte. */
2200 for (--i
; i
> 0; --i
)
2201 token_put_back (p
[i
]);
2204 /* mbtowc sometimes needs an extra char before accepting */
2214 #endif /* MULTIBYTE_CHARS */
2217 /* Add this single character into the buffer either as a wchar_t
2218 or as a single byte. */
2221 unsigned width
= TYPE_PRECISION (char_type_node
);
2222 unsigned bytemask
= (1 << width
) - 1;
2225 if (p
+ WCHAR_BYTES
> token_buffer
+ maxtoken
)
2226 p
= extend_token_buffer (p
);
2228 for (byte
= 0; byte
< WCHAR_BYTES
; ++byte
)
2231 if (byte
>= (int) sizeof (c
))
2234 value
= (c
>> (byte
* width
)) & bytemask
;
2235 if (BYTES_BIG_ENDIAN
)
2236 p
[WCHAR_BYTES
- byte
- 1] = value
;
2244 if (p
>= token_buffer
+ maxtoken
)
2245 p
= extend_token_buffer (p
);
2253 /* Terminate the string value, either with a single byte zero
2254 or with a wide zero. */
2257 if (p
+ WCHAR_BYTES
> token_buffer
+ maxtoken
)
2258 p
= extend_token_buffer (p
);
2259 bzero (p
, WCHAR_BYTES
);
2264 if (p
>= token_buffer
+ maxtoken
)
2265 p
= extend_token_buffer (p
);
2270 error ("Unterminated string constant");
2272 /* We have read the entire constant.
2273 Construct a STRING_CST for the result. */
2277 yylval
.ttype
= build_string (p
- (token_buffer
+ 1),
2279 TREE_TYPE (yylval
.ttype
) = wchar_array_type_node
;
2284 /* Return an Objective-C @"..." constant string object. */
2285 yylval
.ttype
= build_objc_string (p
- (token_buffer
+ 1),
2287 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
2288 value
= OBJC_STRING
;
2292 yylval
.ttype
= build_string (p
- (token_buffer
+ 1),
2294 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
2322 yylval
.code
= PLUS_EXPR
; break;
2324 yylval
.code
= MINUS_EXPR
; break;
2326 yylval
.code
= BIT_AND_EXPR
; break;
2328 yylval
.code
= BIT_IOR_EXPR
; break;
2330 yylval
.code
= MULT_EXPR
; break;
2332 yylval
.code
= TRUNC_DIV_EXPR
; break;
2334 yylval
.code
= TRUNC_MOD_EXPR
; break;
2336 yylval
.code
= BIT_XOR_EXPR
; break;
2338 yylval
.code
= LSHIFT_EXPR
; break;
2340 yylval
.code
= RSHIFT_EXPR
; break;
2342 yylval
.code
= LT_EXPR
; break;
2344 yylval
.code
= GT_EXPR
; break;
2347 token_buffer
[1] = c1
= token_getch();
2348 token_buffer
[2] = 0;
2355 value
= ARITHCOMPARE
; yylval
.code
= LE_EXPR
; goto done
;
2357 value
= ARITHCOMPARE
; yylval
.code
= GE_EXPR
; goto done
;
2359 value
= EQCOMPARE
; yylval
.code
= NE_EXPR
; goto done
;
2361 value
= EQCOMPARE
; yylval
.code
= EQ_EXPR
; goto done
;
2363 value
= ASSIGN
; goto done
;
2369 value
= PLUSPLUS
; goto done
;
2371 value
= MINUSMINUS
; goto done
;
2373 value
= ANDAND
; goto done
;
2375 value
= OROR
; goto done
;
2388 { value
= POINTSAT
; goto done
; }
2394 { value
= ']'; goto done
; }
2398 { value
= '{'; indent_level
++; goto done
; }
2400 { value
= '['; goto done
; }
2404 { value
= '}'; indent_level
--; goto done
; }
2408 token_put_back (c1
);
2409 token_buffer
[1] = 0;
2411 if ((c
== '<') || (c
== '>'))
2412 value
= ARITHCOMPARE
;
2418 /* Don't make yyparse think this is eof. */
2437 /* yylloc.last_line = lineno; */
2442 /* Sets the value of the 'yydebug' variable to VALUE.
2443 This is a function so we don't have to have YYDEBUG defined
2444 in order to build the compiler. */
2453 warning ("YYDEBUG not defined.");