1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 88, 89, 92, 94-99, 2000 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. */
38 /* MULTIBYTE_CHARS support only works for native compilers.
39 ??? Ideally what we want is to model widechar support after
40 the current floating point support. */
42 #undef MULTIBYTE_CHARS
45 #ifdef MULTIBYTE_CHARS
48 #endif /* MULTIBYTE_CHARS */
49 #ifndef GET_ENVIRONMENT
50 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME))
55 extern cpp_reader parse_in
;
56 extern cpp_options parse_options
;
58 /* Stream for reading from the input file. */
62 extern void yyprint
PARAMS ((FILE *, int, YYSTYPE
));
64 /* The elements of `ridpointers' are identifier nodes
65 for the reserved type names and storage classes.
66 It is indexed by a RID_... value. */
67 tree ridpointers
[(int) RID_MAX
];
69 /* Cause the `yydebug' variable to be defined. */
73 extern unsigned char *yy_cur
, *yy_lim
;
74 extern enum cpp_token cpp_token
;
76 extern int yy_get_token ();
78 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
79 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
81 #else /* ! USE_CPPLIB */
83 #define GETC() getch ()
84 #define UNGETC(c) put_back (c)
86 struct putback_buffer
{
92 static struct putback_buffer putback
= {NULL
, 0, -1};
94 static inline int getch
PARAMS ((void));
99 if (putback
.index
!= -1)
101 int ch
= putback
.buffer
[putback
.index
];
105 return getc (finput
);
108 static inline void put_back
PARAMS ((int));
116 if (putback
.index
== putback
.buffer_size
- 1)
118 putback
.buffer_size
+= 16;
119 putback
.buffer
= xrealloc (putback
.buffer
, putback
.buffer_size
);
121 putback
.buffer
[++putback
.index
] = ch
;
124 #endif /* ! USE_CPPLIB */
128 /* the declaration found for the last IDENTIFIER token read in.
129 yylex must look this up to detect typedefs, which get token type TYPENAME,
130 so it is left around in case the identifier is not a typedef but is
131 used in a context which makes it a reference to a variable. */
134 /* Nonzero enables objc features. */
136 int doing_objc_thang
;
140 /* File used for outputting assembler code. */
141 extern FILE *asm_out_file
;
143 #undef WCHAR_TYPE_SIZE
144 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
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
PARAMS ((int));
164 #endif /* HANDLE_GENERIC_PRAGMAS */
165 static int whitespace_cr
PARAMS ((int));
166 static int skip_white_space
PARAMS ((int));
167 static char *extend_token_buffer
PARAMS ((const char *));
168 static int readescape
PARAMS ((int *));
169 static void parse_float
PARAMS ((PTR
));
170 static void extend_token_buffer_to
PARAMS ((int));
171 static int read_line_number
PARAMS ((int *));
173 /* Do not insert generated code into the source, instead, include it.
174 This allows us to build gcc automatically even for targets that
175 need to add or modify the reserved keyword lists. */
178 /* Return something to represent absolute declarators containing a *.
179 TARGET is the absolute declarator that the * contains.
180 TYPE_QUALS is a list of modifiers such as const or volatile
181 to apply to the pointer type, represented as identifiers.
183 We return an INDIRECT_REF whose "contents" are TARGET
184 and whose type is the modifier list. */
187 make_pointer_declarator (type_quals
, target
)
188 tree type_quals
, target
;
190 return build1 (INDIRECT_REF
, type_quals
, target
);
194 forget_protocol_qualifiers ()
196 int i
, n
= sizeof wordlist
/ sizeof (struct resword
);
198 for (i
= 0; i
< n
; i
++)
199 if ((int) wordlist
[i
].rid
>= (int) RID_IN
200 && (int) wordlist
[i
].rid
<= (int) RID_ONEWAY
)
201 wordlist
[i
].name
= "";
205 remember_protocol_qualifiers ()
207 int i
, n
= sizeof wordlist
/ sizeof (struct resword
);
209 for (i
= 0; i
< n
; i
++)
210 if (wordlist
[i
].rid
== RID_IN
)
211 wordlist
[i
].name
= "in";
212 else if (wordlist
[i
].rid
== RID_OUT
)
213 wordlist
[i
].name
= "out";
214 else if (wordlist
[i
].rid
== RID_INOUT
)
215 wordlist
[i
].name
= "inout";
216 else if (wordlist
[i
].rid
== RID_BYCOPY
)
217 wordlist
[i
].name
= "bycopy";
218 else if (wordlist
[i
].rid
== RID_BYREF
)
219 wordlist
[i
].name
= "byref";
220 else if (wordlist
[i
].rid
== RID_ONEWAY
)
221 wordlist
[i
].name
= "oneway";
225 init_parse (filename
)
229 /* Open input file. */
230 if (filename
== 0 || !strcmp (filename
, "-"))
236 finput
= fopen (filename
, "r");
238 pfatal_with_name (filename
);
240 #ifdef IO_BUFFER_SIZE
241 setvbuf (finput
, (char *) xmalloc (IO_BUFFER_SIZE
), _IOFBF
, IO_BUFFER_SIZE
);
243 #else /* !USE_CPPLIB */
244 parse_in
.show_column
= 1;
245 if (! cpp_start_read (&parse_in
, filename
))
248 if (filename
== 0 || !strcmp (filename
, "-"))
251 /* cpp_start_read always puts at least one line directive into the
252 token buffer. We must arrange to read it out here. */
253 yy_cur
= parse_in
.token_buffer
;
254 yy_lim
= CPP_PWRITTEN (&parse_in
);
255 cpp_token
= CPP_DIRECTIVE
;
268 cpp_finish (&parse_in
);
269 errorcount
+= parse_in
.errors
;
278 /* Make identifier nodes long enough for the language-specific slots. */
279 set_identifier_size (sizeof (struct lang_identifier
));
281 /* Start it at 0, because check_newline is called at the very beginning
282 and will increment it to 1. */
285 #ifdef MULTIBYTE_CHARS
286 /* Change to the native locale for multibyte conversions. */
287 setlocale (LC_CTYPE
, "");
288 GET_ENVIRONMENT (literal_codeset
, "LANG");
292 token_buffer
= (char *) xmalloc (maxtoken
+ 2);
294 ridpointers
[(int) RID_INT
] = get_identifier ("int");
295 ridpointers
[(int) RID_CHAR
] = get_identifier ("char");
296 ridpointers
[(int) RID_VOID
] = get_identifier ("void");
297 ridpointers
[(int) RID_FLOAT
] = get_identifier ("float");
298 ridpointers
[(int) RID_DOUBLE
] = get_identifier ("double");
299 ridpointers
[(int) RID_SHORT
] = get_identifier ("short");
300 ridpointers
[(int) RID_LONG
] = get_identifier ("long");
301 ridpointers
[(int) RID_UNSIGNED
] = get_identifier ("unsigned");
302 ridpointers
[(int) RID_SIGNED
] = get_identifier ("signed");
303 ridpointers
[(int) RID_INLINE
] = get_identifier ("inline");
304 ridpointers
[(int) RID_CONST
] = get_identifier ("const");
305 ridpointers
[(int) RID_RESTRICT
] = get_identifier ("restrict");
306 ridpointers
[(int) RID_VOLATILE
] = get_identifier ("volatile");
307 ridpointers
[(int) RID_AUTO
] = get_identifier ("auto");
308 ridpointers
[(int) RID_STATIC
] = get_identifier ("static");
309 ridpointers
[(int) RID_EXTERN
] = get_identifier ("extern");
310 ridpointers
[(int) RID_TYPEDEF
] = get_identifier ("typedef");
311 ridpointers
[(int) RID_REGISTER
] = get_identifier ("register");
312 ridpointers
[(int) RID_ITERATOR
] = get_identifier ("iterator");
313 ridpointers
[(int) RID_COMPLEX
] = get_identifier ("complex");
314 ridpointers
[(int) RID_ID
] = get_identifier ("id");
315 ridpointers
[(int) RID_IN
] = get_identifier ("in");
316 ridpointers
[(int) RID_OUT
] = get_identifier ("out");
317 ridpointers
[(int) RID_INOUT
] = get_identifier ("inout");
318 ridpointers
[(int) RID_BYCOPY
] = get_identifier ("bycopy");
319 ridpointers
[(int) RID_BYREF
] = get_identifier ("byref");
320 ridpointers
[(int) RID_ONEWAY
] = get_identifier ("oneway");
321 forget_protocol_qualifiers();
323 /* Some options inhibit certain reserved words.
324 Clear those words out of the hash table so they won't be recognized. */
325 #define UNSET_RESERVED_WORD(STRING) \
326 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
327 if (s) s->name = ""; } while (0)
329 if (! doing_objc_thang
)
330 UNSET_RESERVED_WORD ("id");
332 if (flag_traditional
)
334 UNSET_RESERVED_WORD ("const");
335 UNSET_RESERVED_WORD ("restrict");
336 UNSET_RESERVED_WORD ("volatile");
337 UNSET_RESERVED_WORD ("typeof");
338 UNSET_RESERVED_WORD ("signed");
339 UNSET_RESERVED_WORD ("inline");
340 UNSET_RESERVED_WORD ("iterator");
341 UNSET_RESERVED_WORD ("complex");
343 else if (!flag_isoc9x
)
344 UNSET_RESERVED_WORD ("restrict");
348 UNSET_RESERVED_WORD ("asm");
349 UNSET_RESERVED_WORD ("typeof");
350 UNSET_RESERVED_WORD ("inline");
351 UNSET_RESERVED_WORD ("iterator");
352 UNSET_RESERVED_WORD ("complex");
357 reinit_parse_for_function ()
361 /* Function used when yydebug is set, to print a token in more detail. */
364 yyprint (file
, yychar
, yylval
)
376 if (IDENTIFIER_POINTER (t
))
377 fprintf (file
, " `%s'", IDENTIFIER_POINTER (t
));
382 if (TREE_CODE (t
) == INTEGER_CST
)
384 #if HOST_BITS_PER_WIDE_INT == 64
385 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
388 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
395 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
401 TREE_INT_CST_HIGH (t
), TREE_INT_CST_LOW (t
));
406 /* Iff C is a carriage return, warn about it - if appropriate -
407 and return nonzero. */
412 static int newline_warning
= 0;
416 /* ANSI C says the effects of a carriage return in a source file
418 if (pedantic
&& !newline_warning
)
420 warning ("carriage return in source file");
421 warning ("(we only warn about the first carriage return)");
429 /* If C is not whitespace, return C.
430 Otherwise skip whitespace and return first nonwhite char read. */
440 /* We don't recognize comments here, because
441 cpp output can include / and * consecutively as operators.
442 Also, there's no need, since cpp removes all comments. */
450 c
= check_newline ();
459 /* While processing a # directive we don't get CPP_HSPACE
460 tokens, so we also need to handle whitespace the normal way. */
461 if (cpp_token
== CPP_HSPACE
)
478 error ("stray '\\' in program");
488 /* Skips all of the white space at the current location in the input file. */
491 position_after_white_space ()
497 UNGETC (skip_white_space (c
));
500 /* Make the token buffer longer, preserving the data in it.
501 P should point to just beyond the last valid character in the old buffer.
502 The value we return is a pointer to the new buffer
503 at a place corresponding to P. */
506 extend_token_buffer_to (size
)
510 maxtoken
= maxtoken
* 2 + 10;
511 while (maxtoken
< size
);
512 token_buffer
= (char *) xrealloc (token_buffer
, maxtoken
+ 2);
516 extend_token_buffer (p
)
519 int offset
= p
- token_buffer
;
520 extend_token_buffer_to (offset
);
521 return token_buffer
+ offset
;
524 #if defined HANDLE_PRAGMA
525 /* Local versions of these macros, that can be passed as function pointers. */
541 read_line_number (num
)
544 register int token
= yylex ();
546 if (token
== CONSTANT
547 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
549 *num
= TREE_INT_CST_LOW (yylval
.ttype
);
554 if (token
!= END_OF_LINE
)
555 error ("invalid #-line");
560 /* At the beginning of a line, increment the line number
561 and process any #-directive on this line.
562 If the line is a #-directive, read the entire line and return a newline.
563 Otherwise, return the line's first non-whitespace character.
565 Note that in the case of USE_CPPLIB, we get the whole line as one
566 CPP_DIRECTIVE token. */
574 enum { act_none
, act_push
, act_pop
} action
;
575 int old_lineno
, action_number
, l
;
578 /* Read first nonwhite char on the line. */
582 /* In some cases where we're leaving an include file, we can get multiple
583 CPP_HSPACE tokens in a row, so we need to loop. */
584 while (cpp_token
== CPP_HSPACE
)
589 while (c
== ' ' || c
== '\t');
596 /* Sequences of multiple newlines are very common; optimize them. */
600 /* If not #, return it so caller will use it. */
604 /* Don't read beyond this line. */
609 if (cpp_token
== CPP_VSPACE
)
611 /* Format is "<space> <line number> <filename> <newline>".
612 Only the line number is interesting, and even that
613 we can get more efficiently than scanning the line. */
615 lineno
= parse_in
.lineno
- 1;
622 if (token
== IDENTIFIER
)
624 /* If a letter follows, then if the word here is `line', skip
625 it and ignore it; otherwise, ignore the line, with an error
626 if the word isn't `pragma'. */
628 const char *name
= IDENTIFIER_POINTER (yylval
.ttype
);
630 if (!strcmp (name
, "pragma"))
633 if (token
!= IDENTIFIER
634 || TREE_CODE (yylval
.ttype
) != IDENTIFIER_NODE
)
638 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
639 (if both are defined), in order to give the back
640 end a chance to override the interpretation of
641 SYSV style pragmas. */
642 if (HANDLE_PRAGMA (pragma_getc
, pragma_ungetc
,
643 IDENTIFIER_POINTER (yylval
.ttype
)))
645 #endif /* HANDLE_PRAGMA */
647 #ifdef HANDLE_GENERIC_PRAGMAS
648 if (handle_generic_pragma (token
))
650 #endif /* HANDLE_GENERIC_PRAGMAS */
652 /* Issue a warning message if we have been asked to do so.
653 Ignoring unknown pragmas in system header file unless
654 an explcit -Wunknown-pragmas has been given. */
655 if (warn_unknown_pragmas
> 1
656 || (warn_unknown_pragmas
&& ! in_system_header
))
657 warning ("ignoring pragma: %s", token_buffer
);
661 else if (!strcmp (name
, "define"))
663 debug_define (lineno
, GET_DIRECTIVE_LINE ());
666 else if (!strcmp (name
, "undef"))
668 debug_undef (lineno
, GET_DIRECTIVE_LINE ());
671 else if (!strcmp (name
, "line"))
677 else if (!strcmp (name
, "ident"))
679 /* #ident. The pedantic warning is now in cccp.c. */
681 /* Here we have just seen `#ident '.
682 A string constant should follow. */
685 if (token
== END_OF_LINE
)
688 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
690 error ("invalid #ident");
696 #ifdef ASM_OUTPUT_IDENT
697 ASM_OUTPUT_IDENT (asm_out_file
,
698 TREE_STRING_POINTER (yylval
.ttype
));
702 /* Skip the rest of this line. */
706 error ("undefined or invalid # directive `%s'", name
);
710 /* If the # is the only nonwhite char on the line,
711 just ignore it. Check the new newline. */
712 if (token
== END_OF_LINE
)
716 /* Here we have either `#line' or `# <nonletter>'.
717 In either case, it should be a line number; a digit should follow. */
719 if (token
!= CONSTANT
720 || TREE_CODE (yylval
.ttype
) != INTEGER_CST
)
722 error ("invalid #-line");
726 /* subtract one, because it is the following line that
727 gets the specified number */
729 l
= TREE_INT_CST_LOW (yylval
.ttype
) - 1;
731 /* More follows: it must be a string constant (filename).
732 It would be neat to use cpplib to quickly process the string, but
733 (1) we don't have a handy tokenization of the string, and
734 (2) I don't know how well that would work in the presense
735 of filenames that contain wide characters. */
739 /* Don't treat \ as special if we are processing #line 1 "...".
740 If you want it to be treated specially, use # 1 "...". */
741 ignore_escape_flag
= 1;
744 /* Read the string constant. */
747 ignore_escape_flag
= 0;
749 if (token
== END_OF_LINE
)
751 /* No more: store the line number and check following line. */
756 if (token
!= STRING
|| TREE_CODE (yylval
.ttype
) != STRING_CST
)
758 error ("invalid #line");
762 if (! ggc_p
&& !TREE_PERMANENT (yylval
.ttype
))
765 = (char *) permalloc (TREE_STRING_LENGTH (yylval
.ttype
) + 1);
766 strcpy (input_filename
, TREE_STRING_POINTER (yylval
.ttype
));
769 input_filename
= TREE_STRING_POINTER (yylval
.ttype
);
771 if (main_input_filename
== 0)
772 main_input_filename
= input_filename
;
779 /* Each change of file name
780 reinitializes whether we are now in a system header. */
781 in_system_header
= 0;
783 if (!read_line_number (&action_number
))
785 /* Update the name in the top element of input_file_stack. */
786 if (input_file_stack
)
787 input_file_stack
->name
= input_filename
;
790 /* `1' after file name means entering new file.
791 `2' after file name means just left a file. */
793 if (action_number
== 1)
796 read_line_number (&action_number
);
798 else if (action_number
== 2)
801 read_line_number (&action_number
);
803 if (action_number
== 3)
805 /* `3' after file name means this is a system header file. */
806 in_system_header
= 1;
807 read_line_number (&action_number
);
810 /* Do the actions implied by the preceding numbers. */
812 if (action
== act_push
)
814 /* Pushing to a new file. */
816 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
817 input_file_stack
->line
= old_lineno
;
818 p
->next
= input_file_stack
;
819 p
->name
= input_filename
;
820 p
->indent_level
= indent_level
;
821 input_file_stack
= p
;
822 input_file_stack_tick
++;
823 debug_start_source_file (input_filename
);
825 else if (action
== act_pop
)
827 /* Popping out of a file. */
828 if (input_file_stack
->next
)
830 struct file_stack
*p
= input_file_stack
;
831 if (indent_level
!= p
->indent_level
)
833 warning_with_file_and_line
834 (p
->name
, old_lineno
,
835 "This file contains more `%c's than `%c's.",
836 indent_level
> p
->indent_level
? '{' : '}',
837 indent_level
> p
->indent_level
? '}' : '{');
839 input_file_stack
= p
->next
;
841 input_file_stack_tick
++;
842 debug_end_source_file (input_file_stack
->line
);
845 error ("#-lines for entering and leaving files don't match");
848 /* Now that we've pushed or popped the input stack,
849 update the name in the top element. */
850 if (input_file_stack
)
851 input_file_stack
->name
= input_filename
;
853 /* skip the rest of this line. */
860 while (c
!= '\n' && c
!= EOF
);
864 #ifdef HANDLE_GENERIC_PRAGMAS
866 /* Handle a #pragma directive.
867 TOKEN is the token we read after `#pragma'. Processes the entire input
868 line and return non-zero iff the pragma has been successfully parsed. */
870 /* This function has to be in this file, in order to get at
874 handle_generic_pragma (token
)
885 handle_pragma_token (token_buffer
, yylval
.ttype
);
889 return handle_pragma_token (NULL_PTR
, NULL_TREE
);
892 handle_pragma_token (token_buffer
, NULL
);
899 #endif /* HANDLE_GENERIC_PRAGMAS */
901 #define ENDFILE -1 /* token that represents end-of-file */
903 /* Read an escape sequence, returning its equivalent as a character,
904 or store 1 in *ignore_ptr if it is backslash-newline. */
907 readescape (ignore_ptr
)
910 register int c
= GETC();
912 register unsigned count
;
913 unsigned firstdig
= 0;
919 if (warn_traditional
)
920 warning ("the meaning of `\\x' varies with -traditional");
922 if (flag_traditional
)
937 if (c
>= 'a' && c
<= 'f')
938 code
+= c
- 'a' + 10;
939 if (c
>= 'A' && c
<= 'F')
940 code
+= c
- 'A' + 10;
941 if (c
>= '0' && c
<= '9')
943 if (code
!= 0 || count
!= 0)
952 error ("\\x used with no following hex digits");
954 /* Digits are all 0's. Ok. */
956 else if ((count
- 1) * 4 >= TYPE_PRECISION (integer_type_node
)
959 << (TYPE_PRECISION (integer_type_node
)
962 pedwarn ("hex escape out of range");
965 case '0': case '1': case '2': case '3': case '4':
966 case '5': case '6': case '7':
969 while ((c
<= '7') && (c
>= '0') && (count
++ < 3))
971 code
= (code
* 8) + (c
- '0');
977 case '\\': case '\'': case '"':
986 return TARGET_NEWLINE
;
1001 if (warn_traditional
)
1002 warning ("the meaning of `\\a' varies with -traditional");
1004 if (flag_traditional
)
1009 #if 0 /* Vertical tab is present in common usage compilers. */
1010 if (flag_traditional
)
1018 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c
);
1024 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1028 /* `\%' is used to prevent SCCS from getting confused. */
1031 pedwarn ("unknown escape sequence `\\%c'", c
);
1035 pedwarn ("unknown escape sequence `\\%c'", c
);
1037 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c
);
1045 const char *string
= _(msgid
);
1047 /* We can't print string and character constants well
1048 because the token_buffer contains the result of processing escapes. */
1050 error ("%s at end of input", string
);
1051 else if (token_buffer
[0] == 0)
1052 error ("%s at null character", string
);
1053 else if (token_buffer
[0] == '"')
1054 error ("%s before string constant", string
);
1055 else if (token_buffer
[0] == '\'')
1056 error ("%s before character constant", string
);
1057 else if (!ISGRAPH(token_buffer
[0]))
1058 error ("%s before character 0%o", string
, (unsigned char) token_buffer
[0]);
1060 error ("%s before `%s'", string
, token_buffer
);
1070 char long_long_flag
;
1073 struct try_type type_sequence
[] =
1075 { &integer_type_node
, 0, 0, 0},
1076 { &unsigned_type_node
, 1, 0, 0},
1077 { &long_integer_type_node
, 0, 1, 0},
1078 { &long_unsigned_type_node
, 1, 1, 0},
1079 { &long_long_integer_type_node
, 0, 1, 1},
1080 { &long_long_unsigned_type_node
, 1, 1, 1}
1094 int conversion_errno
;
1095 REAL_VALUE_TYPE value
;
1102 struct pf_args
* args
= (struct pf_args
*) data
;
1103 int fflag
= 0, lflag
= 0;
1104 /* Copy token_buffer now, while it has just the number
1105 and not the suffixes; once we add `f' or `i',
1106 REAL_VALUE_ATOF may not work any more. */
1107 char *copy
= (char *) alloca (args
->p
- token_buffer
+ 1);
1108 bcopy (token_buffer
, copy
, args
->p
- token_buffer
+ 1);
1110 args
->conversion_errno
= 0;
1111 args
->type
= double_type_node
;
1117 /* Read the suffixes to choose a data type. */
1122 error ("more than one `f' in numeric constant");
1128 error ("more than one `l' in numeric constant");
1134 error ("more than one `i' or `j' in numeric constant");
1136 pedwarn ("ANSI C forbids imaginary numeric constants");
1147 if (args
->p
>= token_buffer
+ maxtoken
- 3)
1148 args
->p
= extend_token_buffer (args
->p
);
1149 *(args
->p
++) = args
->c
;
1154 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1155 tells the desired precision of the binary result
1156 of decimal-to-binary conversion. */
1161 error ("both `f' and `l' in floating constant");
1163 args
->type
= float_type_node
;
1165 if (args
->base
== 16)
1166 args
->value
= REAL_VALUE_HTOF (copy
, TYPE_MODE (args
->type
));
1168 args
->value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (args
->type
));
1169 args
->conversion_errno
= errno
;
1170 /* A diagnostic is required here by some ANSI C testsuites.
1171 This is not pedwarn, because some people don't want
1172 an error for this. */
1173 if (REAL_VALUE_ISINF (args
->value
) && pedantic
)
1174 warning ("floating point number exceeds range of `float'");
1178 args
->type
= long_double_type_node
;
1180 if (args
->base
== 16)
1181 args
->value
= REAL_VALUE_HTOF (copy
, TYPE_MODE (args
->type
));
1183 args
->value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (args
->type
));
1184 args
->conversion_errno
= errno
;
1185 if (REAL_VALUE_ISINF (args
->value
) && pedantic
)
1186 warning ("floating point number exceeds range of `long double'");
1191 if (args
->base
== 16)
1192 args
->value
= REAL_VALUE_HTOF (copy
, TYPE_MODE (args
->type
));
1194 args
->value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (args
->type
));
1195 args
->conversion_errno
= errno
;
1196 if (REAL_VALUE_ISINF (args
->value
) && pedantic
)
1197 warning ("floating point number exceeds range of `double'");
1201 /* Get the next character, staying within the current token if possible.
1202 If we're lexing a token, we don't want to look beyond the end of the
1203 token cpplib has prepared for us; otherwise, we end up reading in the
1204 next token, which screws up feed_input. So just return a null
1207 static inline int token_getch
PARAMS ((void));
1213 if (yy_cur
== yy_lim
)
1219 static inline void token_put_back
PARAMS ((int));
1232 /* Read a single token from the input stream, and assign it lexical
1246 /* Effectively do c = skip_white_space (c)
1247 but do it faster in the usual cases. */
1257 if (cpp_token
== CPP_HSPACE
)
1258 c
= yy_get_token ();
1265 /* Call skip_white_space so we can warn if appropriate. */
1270 c
= skip_white_space (c
);
1272 goto found_nonwhite
;
1276 token_buffer
[0] = c
;
1277 token_buffer
[1] = 0;
1279 /* yylloc.first_line = lineno; */
1285 token_buffer
[0] = 0;
1287 value
= END_OF_LINE
;
1294 if (cpp_token
== CPP_NAME
)
1297 /* Capital L may start a wide-string or wide-character constant. */
1299 register int c
= token_getch();
1308 goto string_constant
;
1315 if (!doing_objc_thang
)
1322 /* '@' may start a constant string object. */
1323 register int c
= token_getch ();
1327 goto string_constant
;
1330 /* Fall through to treat '@' as the start of an identifier. */
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 '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':
1339 case 'a': case 'b': case 'c': case 'd': case 'e':
1340 case 'f': case 'g': case 'h': case 'i': case 'j':
1341 case 'k': case 'l': case 'm': case 'n': case 'o':
1342 case 'p': case 'q': case 'r': case 's': case 't':
1343 case 'u': case 'v': case 'w': case 'x': case 'y':
1349 if (cpp_token
== CPP_NAME
)
1351 /* Note that one character has already been read from
1352 yy_cur into token_buffer. Also, cpplib complains about
1353 $ in identifiers, so we don't have to. */
1355 int len
= yy_lim
- yy_cur
+ 1;
1356 if (len
>= maxtoken
)
1357 extend_token_buffer_to (len
+ 1);
1358 memcpy (token_buffer
+ 1, yy_cur
, len
);
1359 p
= token_buffer
+ len
;
1366 while (ISALNUM (c
) || c
== '_' || c
== '$' || c
== '@')
1368 /* Make sure this char really belongs in an identifier. */
1371 if (! dollars_in_ident
)
1372 error ("`$' in identifier");
1374 pedwarn ("`$' in identifier");
1377 if (p
>= token_buffer
+ maxtoken
)
1378 p
= extend_token_buffer (p
);
1391 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1394 register struct resword
*ptr
;
1396 if ((ptr
= is_reserved_word (token_buffer
, p
- token_buffer
)))
1399 yylval
.ttype
= ridpointers
[(int) ptr
->rid
];
1400 value
= (int) ptr
->token
;
1402 /* Only return OBJECTNAME if it is a typedef. */
1403 if (doing_objc_thang
&& value
== OBJECTNAME
)
1405 lastiddecl
= lookup_name(yylval
.ttype
);
1407 if (lastiddecl
== NULL_TREE
1408 || TREE_CODE (lastiddecl
) != TYPE_DECL
)
1412 /* Even if we decided to recognize asm, still perhaps warn. */
1414 && (value
== ASM_KEYWORD
|| value
== TYPEOF
1415 || ptr
->rid
== RID_INLINE
)
1416 && token_buffer
[0] != '_')
1417 pedwarn ("ANSI does not permit the keyword `%s'",
1422 /* If we did not find a keyword, look for an identifier
1425 if (value
== IDENTIFIER
)
1427 if (token_buffer
[0] == '@')
1428 error("invalid identifier `%s'", token_buffer
);
1430 yylval
.ttype
= get_identifier (token_buffer
);
1431 lastiddecl
= lookup_name (yylval
.ttype
);
1433 if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == TYPE_DECL
)
1435 /* A user-invisible read-only initialized variable
1436 should be replaced by its value.
1437 We handle only strings since that's the only case used in C. */
1438 else if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == VAR_DECL
1439 && DECL_IGNORED_P (lastiddecl
)
1440 && TREE_READONLY (lastiddecl
)
1441 && DECL_INITIAL (lastiddecl
) != 0
1442 && TREE_CODE (DECL_INITIAL (lastiddecl
)) == STRING_CST
)
1444 tree stringval
= DECL_INITIAL (lastiddecl
);
1446 /* Copy the string value so that we won't clobber anything
1447 if we put something in the TREE_CHAIN of this one. */
1448 yylval
.ttype
= build_string (TREE_STRING_LENGTH (stringval
),
1449 TREE_STRING_POINTER (stringval
));
1452 else if (doing_objc_thang
)
1454 tree objc_interface_decl
= is_class_name (yylval
.ttype
);
1456 if (objc_interface_decl
)
1459 yylval
.ttype
= objc_interface_decl
;
1468 if (yy_cur
< yy_lim
)
1471 /* It's hard to preserve tokenization on '.' because
1472 it could be a symbol by itself, or it could be the
1473 start of a floating point number and cpp won't tell us. */
1474 register int c1
= token_getch ();
1475 token_buffer
[1] = c1
;
1478 c1
= token_getch ();
1481 token_buffer
[2] = c1
;
1482 token_buffer
[3] = 0;
1486 error ("parse error at `..'");
1490 token_put_back (c1
);
1493 token_put_back (c1
);
1496 token_buffer
[1] = 0;
1500 /* Optimize for most frequent case. */
1505 cond
= (yy_cur
== yy_lim
);
1507 register int c1
= token_getch ();
1508 token_put_back (c1
);
1509 cond
= (! ISALNUM (c1
) && c1
!= '.');
1513 yylval
.ttype
= (c
== '0') ? integer_zero_node
: integer_one_node
;
1519 case '2': case '3': case '4':
1520 case '5': case '6': case '7': case '8': case '9':
1525 int largest_digit
= 0;
1529 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
1530 The code below which fills the parts array assumes that a host
1531 int is at least twice as wide as a host char, and that
1532 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
1533 Two HOST_WIDE_INTs is the largest int literal we can store.
1534 In order to detect overflow below, the number of parts (TOTAL_PARTS)
1535 must be exactly the number of parts needed to hold the bits
1536 of two HOST_WIDE_INTs. */
1537 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
1538 unsigned int parts
[TOTAL_PARTS
];
1540 enum anon1
{ NOT_FLOAT
, AFTER_POINT
, TOO_MANY_POINTS
, AFTER_EXPON
}
1541 floatflag
= NOT_FLOAT
;
1543 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1551 *p
++ = (c
= token_getch());
1552 if ((c
== 'x') || (c
== 'X'))
1555 *p
++ = (c
= token_getch());
1557 /* Leading 0 forces octal unless the 0 is the only digit. */
1558 else if (c
>= '0' && c
<= '9')
1567 /* Read all the digits-and-decimal-points. */
1570 || (ISALNUM (c
) && c
!= 'l' && c
!= 'L'
1571 && c
!= 'u' && c
!= 'U'
1572 && c
!= 'i' && c
!= 'I' && c
!= 'j' && c
!= 'J'
1573 && (floatflag
== NOT_FLOAT
1574 || ((base
!= 16) && (c
!= 'f') && (c
!= 'F'))
1579 if (base
== 16 && pedantic
)
1580 pedwarn ("floating constant may not be in radix 16");
1581 if (floatflag
== TOO_MANY_POINTS
)
1582 /* We have already emitted an error. Don't need another. */
1584 else if (floatflag
== AFTER_POINT
|| floatflag
== AFTER_EXPON
)
1586 error ("malformed floating constant");
1587 floatflag
= TOO_MANY_POINTS
;
1588 /* Avoid another error from atof by forcing all characters
1589 from here on to be ignored. */
1593 floatflag
= AFTER_POINT
;
1597 *p
++ = c
= token_getch();
1598 /* Accept '.' as the start of a floating-point number
1599 only when it is followed by a digit. */
1600 if (p
== token_buffer
+ 2 && !ISDIGIT (c
))
1605 /* It is not a decimal point.
1606 It should be a digit (perhaps a hex digit). */
1612 else if (base
<= 10)
1614 if (c
== 'e' || c
== 'E')
1617 floatflag
= AFTER_EXPON
;
1618 break; /* start of exponent */
1620 error ("nondigits in number and not hexadecimal");
1623 else if (base
== 16 && (c
== 'p' || c
== 'P'))
1625 floatflag
= AFTER_EXPON
;
1626 break; /* start of exponent */
1636 if (c
>= largest_digit
)
1640 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1642 parts
[count
] *= base
;
1646 += (parts
[count
-1] >> HOST_BITS_PER_CHAR
);
1648 &= (1 << HOST_BITS_PER_CHAR
) - 1;
1654 /* If the highest-order part overflows (gets larger than
1655 a host char will hold) then the whole number has
1656 overflowed. Record this and truncate the highest-order
1658 if (parts
[TOTAL_PARTS
- 1] >> HOST_BITS_PER_CHAR
)
1661 parts
[TOTAL_PARTS
- 1] &= (1 << HOST_BITS_PER_CHAR
) - 1;
1664 if (p
>= token_buffer
+ maxtoken
- 3)
1665 p
= extend_token_buffer (p
);
1666 *p
++ = (c
= token_getch());
1670 /* This can happen on input like `int i = 0x;' */
1672 error ("numeric constant with no digits");
1674 if (largest_digit
>= base
)
1675 error ("numeric constant contains digits beyond the radix");
1677 /* Remove terminating char from the token buffer and delimit the
1681 if (floatflag
!= NOT_FLOAT
)
1684 int imag
, conversion_errno
;
1685 REAL_VALUE_TYPE value
;
1686 struct pf_args args
;
1688 /* Read explicit exponent if any, and put it in tokenbuf. */
1690 if ((base
== 10 && ((c
== 'e') || (c
== 'E')))
1691 || (base
== 16 && (c
== 'p' || c
== 'P')))
1693 if (p
>= token_buffer
+ maxtoken
- 3)
1694 p
= extend_token_buffer (p
);
1697 if ((c
== '+') || (c
== '-'))
1702 /* Exponent is decimal, even if string is a hex float. */
1704 error ("floating constant exponent has no digits");
1707 if (p
>= token_buffer
+ maxtoken
- 3)
1708 p
= extend_token_buffer (p
);
1713 if (base
== 16 && floatflag
!= AFTER_EXPON
)
1714 error ("hexadecimal floating constant has no exponent");
1718 /* Setup input for parse_float() */
1723 /* Convert string to a double, checking for overflow. */
1724 if (do_float_handler (parse_float
, (PTR
) &args
))
1726 /* Receive output from parse_float() */
1731 /* We got an exception from parse_float() */
1732 error ("floating constant out of range");
1736 /* Receive output from parse_float() */
1740 conversion_errno
= args
.conversion_errno
;
1743 /* ERANGE is also reported for underflow,
1744 so test the value to distinguish overflow from that. */
1745 if (conversion_errno
== ERANGE
&& !flag_traditional
&& pedantic
1746 && (REAL_VALUES_LESS (dconst1
, value
)
1747 || REAL_VALUES_LESS (value
, dconstm1
)))
1748 warning ("floating point number exceeds range of `double'");
1751 /* If the result is not a number, assume it must have been
1752 due to some error message above, so silently convert
1754 if (REAL_VALUE_ISNAN (value
))
1757 /* Create a node with determined type and value. */
1759 yylval
.ttype
= build_complex (NULL_TREE
,
1760 convert (type
, integer_zero_node
),
1761 build_real (type
, value
));
1763 yylval
.ttype
= build_real (type
, value
);
1767 tree traditional_type
, ansi_type
, type
;
1768 HOST_WIDE_INT high
, low
;
1769 int spec_unsigned
= 0;
1771 int spec_long_long
= 0;
1775 traditional_type
= ansi_type
= type
= NULL_TREE
;
1778 if (c
== 'u' || c
== 'U')
1781 error ("two `u's in integer constant");
1784 else if (c
== 'l' || c
== 'L')
1789 error ("three `l's in integer constant");
1790 else if (pedantic
&& ! in_system_header
&& warn_long_long
)
1791 pedwarn ("ANSI C forbids long long integer constants");
1796 else if (c
== 'i' || c
== 'j' || c
== 'I' || c
== 'J')
1799 error ("more than one `i' or `j' in numeric constant");
1801 pedwarn ("ANSI C forbids imaginary numeric constants");
1806 if (p
>= token_buffer
+ maxtoken
- 3)
1807 p
= extend_token_buffer (p
);
1812 /* If the literal overflowed, pedwarn about it now. */
1816 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT
* 2);
1819 /* This is simplified by the fact that our constant
1820 is always positive. */
1824 for (i
= 0; i
< HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
; i
++)
1826 high
|= ((HOST_WIDE_INT
) parts
[i
+ (HOST_BITS_PER_WIDE_INT
1827 / HOST_BITS_PER_CHAR
)]
1828 << (i
* HOST_BITS_PER_CHAR
));
1829 low
|= (HOST_WIDE_INT
) parts
[i
] << (i
* HOST_BITS_PER_CHAR
);
1832 yylval
.ttype
= build_int_2 (low
, high
);
1833 TREE_TYPE (yylval
.ttype
) = long_long_unsigned_type_node
;
1835 /* If warn_traditional, calculate both the ANSI type and the
1836 traditional type, then see if they disagree.
1837 Otherwise, calculate only the type for the dialect in use. */
1838 if (warn_traditional
|| flag_traditional
)
1840 /* Calculate the traditional type. */
1841 /* Traditionally, any constant is signed;
1842 but if unsigned is specified explicitly, obey that.
1843 Use the smallest size with the right number of bits,
1844 except for one special case with decimal constants. */
1845 if (! spec_long
&& base
!= 10
1846 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1847 traditional_type
= (spec_unsigned
? unsigned_type_node
1848 : integer_type_node
);
1849 /* A decimal constant must be long
1850 if it does not fit in type int.
1851 I think this is independent of whether
1852 the constant is signed. */
1853 else if (! spec_long
&& base
== 10
1854 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1855 traditional_type
= (spec_unsigned
? unsigned_type_node
1856 : integer_type_node
);
1857 else if (! spec_long_long
)
1858 traditional_type
= (spec_unsigned
? long_unsigned_type_node
1859 : long_integer_type_node
);
1860 else if (int_fits_type_p (yylval
.ttype
,
1862 ? long_long_unsigned_type_node
1863 : long_long_integer_type_node
))
1864 traditional_type
= (spec_unsigned
1865 ? long_long_unsigned_type_node
1866 : long_long_integer_type_node
);
1868 traditional_type
= (spec_unsigned
1869 ? widest_unsigned_literal_type_node
1870 : widest_integer_literal_type_node
);
1872 if (warn_traditional
|| ! flag_traditional
)
1874 /* Calculate the ANSI type. */
1875 if (! spec_long
&& ! spec_unsigned
1876 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1877 ansi_type
= integer_type_node
;
1878 else if (! spec_long
&& (base
!= 10 || spec_unsigned
)
1879 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1880 ansi_type
= unsigned_type_node
;
1881 else if (! spec_unsigned
&& !spec_long_long
1882 && int_fits_type_p (yylval
.ttype
, long_integer_type_node
))
1883 ansi_type
= long_integer_type_node
;
1884 else if (! spec_long_long
1885 && int_fits_type_p (yylval
.ttype
,
1886 long_unsigned_type_node
))
1887 ansi_type
= long_unsigned_type_node
;
1888 else if (! spec_unsigned
1889 && int_fits_type_p (yylval
.ttype
,
1890 long_long_integer_type_node
))
1891 ansi_type
= long_long_integer_type_node
;
1892 else if (int_fits_type_p (yylval
.ttype
,
1893 long_long_unsigned_type_node
))
1894 ansi_type
= long_long_unsigned_type_node
;
1895 else if (! spec_unsigned
1896 && int_fits_type_p (yylval
.ttype
,
1897 widest_integer_literal_type_node
))
1898 ansi_type
= widest_integer_literal_type_node
;
1900 ansi_type
= widest_unsigned_literal_type_node
;
1903 type
= flag_traditional
? traditional_type
: ansi_type
;
1905 /* We assume that constants specified in a non-decimal
1906 base are bit patterns, and that the programmer really
1907 meant what they wrote. */
1908 if (warn_traditional
&& base
== 10
1909 && traditional_type
!= ansi_type
)
1911 if (TYPE_PRECISION (traditional_type
)
1912 != TYPE_PRECISION (ansi_type
))
1913 warning ("width of integer constant changes with -traditional");
1914 else if (TREE_UNSIGNED (traditional_type
)
1915 != TREE_UNSIGNED (ansi_type
))
1916 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1918 warning ("width of integer constant may change on other systems with -traditional");
1921 if (pedantic
&& !flag_traditional
&& !spec_long_long
&& !warn
1922 && (TYPE_PRECISION (long_integer_type_node
)
1923 < TYPE_PRECISION (type
)))
1926 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
1929 if (base
== 10 && ! spec_unsigned
&& TREE_UNSIGNED (type
))
1930 warning ("decimal constant is so large that it is unsigned");
1934 if (TYPE_PRECISION (type
)
1935 <= TYPE_PRECISION (integer_type_node
))
1937 = build_complex (NULL_TREE
, integer_zero_node
,
1938 convert (integer_type_node
,
1941 error ("complex integer constant is too wide for `complex int'");
1943 else if (flag_traditional
&& !int_fits_type_p (yylval
.ttype
, type
))
1944 /* The traditional constant 0x80000000 is signed
1945 but doesn't fit in the range of int.
1946 This will change it to -0x80000000, which does fit. */
1948 TREE_TYPE (yylval
.ttype
) = unsigned_type (type
);
1949 yylval
.ttype
= convert (type
, yylval
.ttype
);
1950 TREE_OVERFLOW (yylval
.ttype
)
1951 = TREE_CONSTANT_OVERFLOW (yylval
.ttype
) = 0;
1954 TREE_TYPE (yylval
.ttype
) = type
;
1957 /* If it's still an integer (not a complex), and it doesn't
1958 fit in the type we choose for it, then pedwarn. */
1961 && TREE_CODE (TREE_TYPE (yylval
.ttype
)) == INTEGER_TYPE
1962 && ! int_fits_type_p (yylval
.ttype
, TREE_TYPE (yylval
.ttype
)))
1963 pedwarn ("integer constant is larger than the maximum value for its type");
1969 if (ISALNUM (c
) || c
== '.' || c
== '_' || c
== '$'
1970 || (!flag_traditional
&& (c
== '-' || c
== '+')
1971 && (p
[-1] == 'e' || p
[-1] == 'E')))
1972 error ("missing white space after number `%s'", token_buffer
);
1974 value
= CONSTANT
; break;
1980 register int result
= 0;
1981 register int num_chars
= 0;
1983 unsigned width
= TYPE_PRECISION (char_type_node
);
1985 #ifdef MULTIBYTE_CHARS
1986 int longest_char
= local_mb_cur_max ();
1987 (void) local_mbtowc (NULL_PTR
, NULL_PTR
, 0);
1990 max_chars
= TYPE_PRECISION (integer_type_node
) / width
;
1992 width
= WCHAR_TYPE_SIZE
;
1999 if (c
== '\'' || c
== EOF
)
2006 c
= readescape (&ignore
);
2009 if (width
< HOST_BITS_PER_INT
2010 && (unsigned) c
>= ((unsigned)1 << width
))
2011 pedwarn ("escape sequence out of range for character");
2012 #ifdef MAP_CHARACTER
2014 c
= MAP_CHARACTER (c
);
2020 pedwarn ("ANSI C forbids newline in character constant");
2025 #ifdef MULTIBYTE_CHARS
2029 for (i
= 1; i
<= longest_char
; ++i
)
2031 if (i
> maxtoken
- 4)
2032 extend_token_buffer (token_buffer
);
2034 token_buffer
[i
] = c
;
2035 char_len
= local_mbtowc (& wc
,
2044 /* mbtowc sometimes needs an extra char before accepting */
2049 /* Merge character into result; ignore excess chars. */
2050 for (i
= 1; i
<= char_len
; ++i
)
2054 if (width
< HOST_BITS_PER_INT
)
2055 result
= (result
<< width
)
2057 & ((1 << width
) - 1));
2059 result
= token_buffer
[i
];
2061 num_chars
+= char_len
;
2070 warning ("Ignoring invalid multibyte character");
2071 /* Replace all but the first byte. */
2072 for (--i
; i
> 1; --i
)
2073 token_put_back (token_buffer
[i
]);
2074 wc
= token_buffer
[1];
2076 #ifdef MAP_CHARACTER
2077 c
= MAP_CHARACTER (wc
);
2082 #else /* ! MULTIBYTE_CHARS */
2083 #ifdef MAP_CHARACTER
2084 c
= MAP_CHARACTER (c
);
2086 #endif /* ! MULTIBYTE_CHARS */
2091 if (chars_seen
== 1) /* only keep the first one */
2096 /* Merge character into result; ignore excess chars. */
2097 num_chars
+= (width
/ TYPE_PRECISION (char_type_node
));
2098 if (num_chars
< max_chars
+ 1)
2100 if (width
< HOST_BITS_PER_INT
)
2101 result
= (result
<< width
) | (c
& ((1 << width
) - 1));
2108 error ("malformed character constant");
2109 else if (chars_seen
== 0)
2110 error ("empty character constant");
2111 else if (num_chars
> max_chars
)
2113 num_chars
= max_chars
;
2114 error ("character constant too long");
2116 else if (chars_seen
!= 1 && ! flag_traditional
&& warn_multichar
)
2117 warning ("multi-character character constant");
2119 /* If char type is signed, sign-extend the constant. */
2122 int num_bits
= num_chars
* width
;
2124 /* We already got an error; avoid invalid shift. */
2125 yylval
.ttype
= build_int_2 (0, 0);
2126 else if (TREE_UNSIGNED (char_type_node
)
2127 || ((result
>> (num_bits
- 1)) & 1) == 0)
2129 = build_int_2 (result
& (~(unsigned HOST_WIDE_INT
) 0
2130 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
2134 = build_int_2 (result
| ~(~(unsigned HOST_WIDE_INT
) 0
2135 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
2137 TREE_TYPE (yylval
.ttype
) = integer_type_node
;
2141 yylval
.ttype
= build_int_2 (result
, 0);
2142 TREE_TYPE (yylval
.ttype
) = wchar_type_node
;
2152 unsigned width
= wide_flag
? WCHAR_TYPE_SIZE
2153 : TYPE_PRECISION (char_type_node
);
2154 #ifdef MULTIBYTE_CHARS
2155 int longest_char
= local_mb_cur_max ();
2156 (void) local_mbtowc (NULL_PTR
, NULL_PTR
, 0);
2159 p
= token_buffer
+ 1;
2161 while (c
!= '"' && c
!= EOF
)
2163 /* ignore_escape_flag is set for reading the filename in #line. */
2164 if (!ignore_escape_flag
&& c
== '\\')
2167 c
= readescape (&ignore
);
2170 if (width
< HOST_BITS_PER_INT
2171 && (unsigned) c
>= ((unsigned)1 << width
))
2172 pedwarn ("escape sequence out of range for character");
2177 pedwarn ("ANSI C forbids newline in string constant");
2182 #ifdef MULTIBYTE_CHARS
2186 for (i
= 0; i
< longest_char
; ++i
)
2188 if (p
+ i
>= token_buffer
+ maxtoken
)
2189 p
= extend_token_buffer (p
);
2192 char_len
= local_mbtowc (& wc
, p
, i
+ 1);
2199 warning ("Ignoring invalid multibyte character");
2200 /* Replace all except the first byte. */
2202 for (--i
; i
> 0; --i
)
2203 token_put_back (p
[i
]);
2206 /* mbtowc sometimes needs an extra char before accepting */
2216 #endif /* MULTIBYTE_CHARS */
2219 /* Add this single character into the buffer either as a wchar_t
2220 or as a single byte. */
2223 unsigned width
= TYPE_PRECISION (char_type_node
);
2224 unsigned bytemask
= (1 << width
) - 1;
2227 if (p
+ WCHAR_BYTES
> token_buffer
+ maxtoken
)
2228 p
= extend_token_buffer (p
);
2230 for (byte
= 0; byte
< WCHAR_BYTES
; ++byte
)
2233 if (byte
>= (int) sizeof (c
))
2236 value
= (c
>> (byte
* width
)) & bytemask
;
2237 if (BYTES_BIG_ENDIAN
)
2238 p
[WCHAR_BYTES
- byte
- 1] = value
;
2246 if (p
>= token_buffer
+ maxtoken
)
2247 p
= extend_token_buffer (p
);
2255 /* Terminate the string value, either with a single byte zero
2256 or with a wide zero. */
2259 if (p
+ WCHAR_BYTES
> token_buffer
+ maxtoken
)
2260 p
= extend_token_buffer (p
);
2261 bzero (p
, WCHAR_BYTES
);
2266 if (p
>= token_buffer
+ maxtoken
)
2267 p
= extend_token_buffer (p
);
2272 error ("Unterminated string constant");
2274 /* We have read the entire constant.
2275 Construct a STRING_CST for the result. */
2279 yylval
.ttype
= build_string (p
- (token_buffer
+ 1),
2281 TREE_TYPE (yylval
.ttype
) = wchar_array_type_node
;
2286 /* Return an Objective-C @"..." constant string object. */
2287 yylval
.ttype
= build_objc_string (p
- (token_buffer
+ 1),
2289 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
2290 value
= OBJC_STRING
;
2294 yylval
.ttype
= build_string (p
- (token_buffer
+ 1),
2296 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
2324 yylval
.code
= PLUS_EXPR
; break;
2326 yylval
.code
= MINUS_EXPR
; break;
2328 yylval
.code
= BIT_AND_EXPR
; break;
2330 yylval
.code
= BIT_IOR_EXPR
; break;
2332 yylval
.code
= MULT_EXPR
; break;
2334 yylval
.code
= TRUNC_DIV_EXPR
; break;
2336 yylval
.code
= TRUNC_MOD_EXPR
; break;
2338 yylval
.code
= BIT_XOR_EXPR
; break;
2340 yylval
.code
= LSHIFT_EXPR
; break;
2342 yylval
.code
= RSHIFT_EXPR
; break;
2344 yylval
.code
= LT_EXPR
; break;
2346 yylval
.code
= GT_EXPR
; break;
2349 token_buffer
[1] = c1
= token_getch();
2350 token_buffer
[2] = 0;
2357 value
= ARITHCOMPARE
; yylval
.code
= LE_EXPR
; goto done
;
2359 value
= ARITHCOMPARE
; yylval
.code
= GE_EXPR
; goto done
;
2361 value
= EQCOMPARE
; yylval
.code
= NE_EXPR
; goto done
;
2363 value
= EQCOMPARE
; yylval
.code
= EQ_EXPR
; goto done
;
2365 value
= ASSIGN
; goto done
;
2371 value
= PLUSPLUS
; goto done
;
2373 value
= MINUSMINUS
; goto done
;
2375 value
= ANDAND
; goto done
;
2377 value
= OROR
; goto done
;
2390 { value
= POINTSAT
; goto done
; }
2396 { value
= ']'; goto done
; }
2400 { value
= '{'; indent_level
++; goto done
; }
2402 { value
= '['; goto done
; }
2406 { value
= '}'; indent_level
--; goto done
; }
2410 token_put_back (c1
);
2411 token_buffer
[1] = 0;
2413 if ((c
== '<') || (c
== '>'))
2414 value
= ARITHCOMPARE
;
2420 /* Don't make yyparse think this is eof. */
2439 /* yylloc.last_line = lineno; */
2444 /* Sets the value of the 'yydebug' variable to VALUE.
2445 This is a function so we don't have to have YYDEBUG defined
2446 in order to build the compiler. */
2455 warning ("YYDEBUG not defined.");