]>
Commit | Line | Data |
---|---|---|
d45cf215 | 1 | /* Lexical analyzer for C and Objective C. |
517cbe13 JL |
2 | Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997 |
3 | 1998, 1999, 2000 Free Software Foundation, Inc. | |
e8bbfc4e RK |
4 | |
5 | This file is part of GNU CC. | |
6 | ||
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) | |
10 | any later version. | |
11 | ||
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. | |
16 | ||
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 | |
940d9d63 RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
e8bbfc4e | 21 | |
e9a25f70 | 22 | #include "config.h" |
670ee920 | 23 | #include "system.h" |
e8bbfc4e | 24 | |
e8bbfc4e RK |
25 | #include "rtl.h" |
26 | #include "tree.h" | |
27 | #include "input.h" | |
d6f4ec51 | 28 | #include "output.h" |
e8bbfc4e RK |
29 | #include "c-lex.h" |
30 | #include "c-tree.h" | |
31 | #include "flags.h" | |
32 | #include "c-parse.h" | |
3d6f7931 | 33 | #include "c-pragma.h" |
5f6da302 | 34 | #include "toplev.h" |
ab87f8c8 | 35 | #include "intl.h" |
1526a060 | 36 | #include "ggc.h" |
7bdb32b9 | 37 | #include "tm_p.h" |
ab87f8c8 | 38 | |
ab87f8c8 JL |
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. */ | |
42 | #ifdef CROSS_COMPILE | |
43 | #undef MULTIBYTE_CHARS | |
44 | #endif | |
e8bbfc4e RK |
45 | |
46 | #ifdef MULTIBYTE_CHARS | |
56f48ce9 | 47 | #include "mbchar.h" |
e8bbfc4e | 48 | #include <locale.h> |
56f48ce9 | 49 | #endif /* MULTIBYTE_CHARS */ |
c5c76735 JL |
50 | #ifndef GET_ENVIRONMENT |
51 | #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME)) | |
52 | #endif | |
e8bbfc4e | 53 | |
e3d1fd32 PB |
54 | #if USE_CPPLIB |
55 | #include "cpplib.h" | |
c8724862 DB |
56 | extern cpp_reader parse_in; |
57 | extern cpp_options parse_options; | |
e56e519d DB |
58 | #else |
59 | /* Stream for reading from the input file. */ | |
60 | FILE *finput; | |
e3d1fd32 PB |
61 | #endif |
62 | ||
6e090c76 | 63 | extern void yyprint PARAMS ((FILE *, int, YYSTYPE)); |
3ab6dd7c | 64 | |
e8bbfc4e RK |
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]; | |
69 | ||
70 | /* Cause the `yydebug' variable to be defined. */ | |
71 | #define YYDEBUG 1 | |
72 | ||
e3d1fd32 | 73 | #if USE_CPPLIB |
c8724862 | 74 | extern unsigned char *yy_cur, *yy_lim; |
fbb18613 | 75 | extern enum cpp_token cpp_token; |
75cb8865 | 76 | |
c8724862 | 77 | extern int yy_get_token (); |
75cb8865 | 78 | |
e3d1fd32 | 79 | #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ()) |
4d9a1b48 | 80 | #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--) |
505e0385 DB |
81 | |
82 | #else /* ! USE_CPPLIB */ | |
83 | ||
84 | #define GETC() getch () | |
85 | #define UNGETC(c) put_back (c) | |
86 | ||
87 | struct putback_buffer { | |
69f21756 | 88 | unsigned char *buffer; |
505e0385 DB |
89 | int buffer_size; |
90 | int index; | |
91 | }; | |
92 | ||
93 | static struct putback_buffer putback = {NULL, 0, -1}; | |
94 | ||
6e090c76 | 95 | static inline int getch PARAMS ((void)); |
93868d11 | 96 | |
505e0385 DB |
97 | static inline int |
98 | getch () | |
99 | { | |
100 | if (putback.index != -1) | |
101 | { | |
102 | int ch = putback.buffer[putback.index]; | |
103 | --putback.index; | |
104 | return ch; | |
105 | } | |
106 | return getc (finput); | |
107 | } | |
108 | ||
6e090c76 | 109 | static inline void put_back PARAMS ((int)); |
93868d11 | 110 | |
505e0385 DB |
111 | static inline void |
112 | put_back (ch) | |
113 | int ch; | |
114 | { | |
115 | if (ch != EOF) | |
116 | { | |
117 | if (putback.index == putback.buffer_size - 1) | |
118 | { | |
119 | putback.buffer_size += 16; | |
120 | putback.buffer = xrealloc (putback.buffer, putback.buffer_size); | |
121 | } | |
122 | putback.buffer[++putback.index] = ch; | |
123 | } | |
124 | } | |
125 | #endif /* ! USE_CPPLIB */ | |
e3d1fd32 | 126 | |
fbb18613 JM |
127 | int linemode; |
128 | ||
e8bbfc4e RK |
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. */ | |
133 | tree lastiddecl; | |
134 | ||
135 | /* Nonzero enables objc features. */ | |
136 | ||
137 | int doing_objc_thang; | |
138 | ||
e8bbfc4e RK |
139 | extern int yydebug; |
140 | ||
141 | /* File used for outputting assembler code. */ | |
142 | extern FILE *asm_out_file; | |
143 | ||
12a39b12 JM |
144 | #undef WCHAR_TYPE_SIZE |
145 | #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node) | |
e8bbfc4e RK |
146 | |
147 | /* Number of bytes in a wide character. */ | |
148 | #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT) | |
149 | ||
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. */ | |
154 | ||
fbb18613 JM |
155 | static int indent_level; /* Number of { minus number of }. */ |
156 | ||
157 | /* Nonzero tells yylex to ignore \ in string constants. */ | |
158 | static int ignore_escape_flag; | |
e9a25f70 | 159 | |
e8bbfc4e RK |
160 | /* Nonzero if end-of-file has been seen on input. */ |
161 | static int end_of_file; | |
162 | ||
e2af664c | 163 | #ifdef HANDLE_GENERIC_PRAGMAS |
6e090c76 | 164 | static int handle_generic_pragma PARAMS ((int)); |
e2af664c | 165 | #endif /* HANDLE_GENERIC_PRAGMAS */ |
6e090c76 KG |
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 *)); | |
e8bbfc4e | 173 | \f |
877eef6d RK |
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. */ | |
177 | #include "c-gperf.h" | |
e8bbfc4e RK |
178 | \f |
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. | |
183 | ||
184 | We return an INDIRECT_REF whose "contents" are TARGET | |
185 | and whose type is the modifier list. */ | |
186 | ||
187 | tree | |
188 | make_pointer_declarator (type_quals, target) | |
189 | tree type_quals, target; | |
190 | { | |
191 | return build1 (INDIRECT_REF, type_quals, target); | |
192 | } | |
193 | \f | |
194 | void | |
e31c7eec TW |
195 | forget_protocol_qualifiers () |
196 | { | |
197 | int i, n = sizeof wordlist / sizeof (struct resword); | |
198 | ||
199 | for (i = 0; i < n; i++) | |
ea64849e RK |
200 | if ((int) wordlist[i].rid >= (int) RID_IN |
201 | && (int) wordlist[i].rid <= (int) RID_ONEWAY) | |
e31c7eec TW |
202 | wordlist[i].name = ""; |
203 | } | |
204 | ||
205 | void | |
206 | remember_protocol_qualifiers () | |
207 | { | |
208 | int i, n = sizeof wordlist / sizeof (struct resword); | |
209 | ||
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"; | |
f1488aba RFM |
219 | else if (wordlist[i].rid == RID_BYREF) |
220 | wordlist[i].name = "byref"; | |
e31c7eec | 221 | else if (wordlist[i].rid == RID_ONEWAY) |
75cb8865 | 222 | wordlist[i].name = "oneway"; |
e31c7eec TW |
223 | } |
224 | \f | |
5c60e5c0 | 225 | char * |
e3d1fd32 PB |
226 | init_parse (filename) |
227 | char *filename; | |
228 | { | |
e56e519d DB |
229 | #if !USE_CPPLIB |
230 | /* Open input file. */ | |
231 | if (filename == 0 || !strcmp (filename, "-")) | |
232 | { | |
233 | finput = stdin; | |
234 | filename = "stdin"; | |
235 | } | |
236 | else | |
237 | finput = fopen (filename, "r"); | |
238 | if (finput == 0) | |
239 | pfatal_with_name (filename); | |
240 | ||
241 | #ifdef IO_BUFFER_SIZE | |
242 | setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE); | |
243 | #endif | |
b12da25e | 244 | #else /* !USE_CPPLIB */ |
e3d1fd32 PB |
245 | parse_in.show_column = 1; |
246 | if (! cpp_start_read (&parse_in, filename)) | |
247 | abort (); | |
add7091b | 248 | |
b12da25e ZW |
249 | if (filename == 0 || !strcmp (filename, "-")) |
250 | filename = "stdin"; | |
251 | ||
add7091b ZW |
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); | |
fbb18613 | 256 | cpp_token = CPP_DIRECTIVE; |
e56e519d | 257 | #endif |
5c60e5c0 | 258 | |
b12da25e | 259 | init_lex (); |
568767a6 | 260 | init_pragma (); |
b12da25e | 261 | |
5c60e5c0 | 262 | return filename; |
e3d1fd32 PB |
263 | } |
264 | ||
265 | void | |
266 | finish_parse () | |
267 | { | |
e56e519d | 268 | #if USE_CPPLIB |
e3d1fd32 | 269 | cpp_finish (&parse_in); |
d2164ac2 | 270 | errorcount += parse_in.errors; |
e56e519d DB |
271 | #else |
272 | fclose (finput); | |
e3d1fd32 | 273 | #endif |
e56e519d | 274 | } |
e3d1fd32 | 275 | |
e31c7eec | 276 | void |
e8bbfc4e RK |
277 | init_lex () |
278 | { | |
279 | /* Make identifier nodes long enough for the language-specific slots. */ | |
280 | set_identifier_size (sizeof (struct lang_identifier)); | |
281 | ||
282 | /* Start it at 0, because check_newline is called at the very beginning | |
283 | and will increment it to 1. */ | |
284 | lineno = 0; | |
285 | ||
286 | #ifdef MULTIBYTE_CHARS | |
287 | /* Change to the native locale for multibyte conversions. */ | |
288 | setlocale (LC_CTYPE, ""); | |
c5c76735 | 289 | GET_ENVIRONMENT (literal_codeset, "LANG"); |
e8bbfc4e RK |
290 | #endif |
291 | ||
292 | maxtoken = 40; | |
293 | token_buffer = (char *) xmalloc (maxtoken + 2); | |
294 | ||
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"); | |
3932261a | 306 | ridpointers[(int) RID_RESTRICT] = get_identifier ("restrict"); |
e8bbfc4e | 307 | ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile"); |
4b4f19ec GM |
308 | ridpointers[(int) RID_BOUNDED] = get_identifier ("__bounded"); |
309 | ridpointers[(int) RID_UNBOUNDED] = get_identifier ("__unbounded"); | |
e8bbfc4e RK |
310 | ridpointers[(int) RID_AUTO] = get_identifier ("auto"); |
311 | ridpointers[(int) RID_STATIC] = get_identifier ("static"); | |
312 | ridpointers[(int) RID_EXTERN] = get_identifier ("extern"); | |
313 | ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef"); | |
314 | ridpointers[(int) RID_REGISTER] = get_identifier ("register"); | |
6506ecd7 | 315 | ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator"); |
122026c0 | 316 | ridpointers[(int) RID_COMPLEX] = get_identifier ("complex"); |
e31c7eec TW |
317 | ridpointers[(int) RID_ID] = get_identifier ("id"); |
318 | ridpointers[(int) RID_IN] = get_identifier ("in"); | |
319 | ridpointers[(int) RID_OUT] = get_identifier ("out"); | |
320 | ridpointers[(int) RID_INOUT] = get_identifier ("inout"); | |
321 | ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy"); | |
f1488aba | 322 | ridpointers[(int) RID_BYREF] = get_identifier ("byref"); |
e31c7eec TW |
323 | ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway"); |
324 | forget_protocol_qualifiers(); | |
e8bbfc4e RK |
325 | |
326 | /* Some options inhibit certain reserved words. | |
327 | Clear those words out of the hash table so they won't be recognized. */ | |
328 | #define UNSET_RESERVED_WORD(STRING) \ | |
329 | do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \ | |
330 | if (s) s->name = ""; } while (0) | |
331 | ||
e31c7eec TW |
332 | if (! doing_objc_thang) |
333 | UNSET_RESERVED_WORD ("id"); | |
334 | ||
e8bbfc4e RK |
335 | if (flag_traditional) |
336 | { | |
337 | UNSET_RESERVED_WORD ("const"); | |
3932261a | 338 | UNSET_RESERVED_WORD ("restrict"); |
e8bbfc4e RK |
339 | UNSET_RESERVED_WORD ("volatile"); |
340 | UNSET_RESERVED_WORD ("typeof"); | |
341 | UNSET_RESERVED_WORD ("signed"); | |
342 | UNSET_RESERVED_WORD ("inline"); | |
6f2f09cd | 343 | UNSET_RESERVED_WORD ("iterator"); |
122026c0 | 344 | UNSET_RESERVED_WORD ("complex"); |
e8bbfc4e | 345 | } |
31948547 | 346 | else if (!flag_isoc99) |
3932261a MM |
347 | UNSET_RESERVED_WORD ("restrict"); |
348 | ||
e8bbfc4e RK |
349 | if (flag_no_asm) |
350 | { | |
351 | UNSET_RESERVED_WORD ("asm"); | |
352 | UNSET_RESERVED_WORD ("typeof"); | |
353 | UNSET_RESERVED_WORD ("inline"); | |
6f2f09cd | 354 | UNSET_RESERVED_WORD ("iterator"); |
122026c0 | 355 | UNSET_RESERVED_WORD ("complex"); |
e8bbfc4e RK |
356 | } |
357 | } | |
358 | ||
359 | void | |
360 | reinit_parse_for_function () | |
361 | { | |
362 | } | |
363 | \f | |
364 | /* Function used when yydebug is set, to print a token in more detail. */ | |
365 | ||
366 | void | |
367 | yyprint (file, yychar, yylval) | |
368 | FILE *file; | |
369 | int yychar; | |
370 | YYSTYPE yylval; | |
371 | { | |
372 | tree t; | |
373 | switch (yychar) | |
374 | { | |
375 | case IDENTIFIER: | |
376 | case TYPENAME: | |
e31c7eec | 377 | case OBJECTNAME: |
e8bbfc4e RK |
378 | t = yylval.ttype; |
379 | if (IDENTIFIER_POINTER (t)) | |
380 | fprintf (file, " `%s'", IDENTIFIER_POINTER (t)); | |
381 | break; | |
382 | ||
383 | case CONSTANT: | |
384 | t = yylval.ttype; | |
385 | if (TREE_CODE (t) == INTEGER_CST) | |
8d9bfdc5 RK |
386 | fprintf (file, |
387 | #if HOST_BITS_PER_WIDE_INT == 64 | |
76d31c63 JL |
388 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT |
389 | " 0x%x%016x", | |
390 | #else | |
391 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG | |
8d9bfdc5 RK |
392 | " 0x%lx%016lx", |
393 | #else | |
76d31c63 JL |
394 | " 0x%llx%016llx", |
395 | #endif | |
8d9bfdc5 RK |
396 | #endif |
397 | #else | |
398 | #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT | |
399 | " 0x%lx%08lx", | |
400 | #else | |
401 | " 0x%x%08x", | |
402 | #endif | |
403 | #endif | |
404 | TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t)); | |
e8bbfc4e RK |
405 | break; |
406 | } | |
407 | } | |
e8bbfc4e | 408 | \f |
a6124a42 R |
409 | /* Iff C is a carriage return, warn about it - if appropriate - |
410 | and return nonzero. */ | |
05bccae2 | 411 | |
56c0e996 | 412 | static int |
a6124a42 R |
413 | whitespace_cr (c) |
414 | int c; | |
415 | { | |
416 | static int newline_warning = 0; | |
417 | ||
418 | if (c == '\r') | |
419 | { | |
420 | /* ANSI C says the effects of a carriage return in a source file | |
421 | are undefined. */ | |
422 | if (pedantic && !newline_warning) | |
423 | { | |
424 | warning ("carriage return in source file"); | |
425 | warning ("(we only warn about the first carriage return)"); | |
426 | newline_warning = 1; | |
427 | } | |
428 | return 1; | |
429 | } | |
430 | return 0; | |
431 | } | |
432 | ||
e8bbfc4e RK |
433 | /* If C is not whitespace, return C. |
434 | Otherwise skip whitespace and return first nonwhite char read. */ | |
435 | ||
436 | static int | |
437 | skip_white_space (c) | |
438 | register int c; | |
439 | { | |
e8bbfc4e RK |
440 | for (;;) |
441 | { | |
442 | switch (c) | |
443 | { | |
0dcd8cee RS |
444 | /* We don't recognize comments here, because |
445 | cpp output can include / and * consecutively as operators. | |
446 | Also, there's no need, since cpp removes all comments. */ | |
e8bbfc4e RK |
447 | |
448 | case '\n': | |
fbb18613 JM |
449 | if (linemode) |
450 | { | |
451 | UNGETC (c); | |
452 | return EOF; | |
453 | } | |
e8bbfc4e RK |
454 | c = check_newline (); |
455 | break; | |
456 | ||
457 | case ' ': | |
458 | case '\t': | |
459 | case '\f': | |
e8bbfc4e RK |
460 | case '\v': |
461 | case '\b': | |
fbb18613 JM |
462 | #if USE_CPPLIB |
463 | /* While processing a # directive we don't get CPP_HSPACE | |
464 | tokens, so we also need to handle whitespace the normal way. */ | |
465 | if (cpp_token == CPP_HSPACE) | |
466 | c = yy_get_token (); | |
467 | else | |
468 | #endif | |
469 | c = GETC(); | |
e8bbfc4e RK |
470 | break; |
471 | ||
0dcd8cee | 472 | case '\r': |
a6124a42 | 473 | whitespace_cr (c); |
e3d1fd32 | 474 | c = GETC(); |
0dcd8cee RS |
475 | break; |
476 | ||
e8bbfc4e | 477 | case '\\': |
e3d1fd32 | 478 | c = GETC(); |
e8bbfc4e RK |
479 | if (c == '\n') |
480 | lineno++; | |
481 | else | |
482 | error ("stray '\\' in program"); | |
e3d1fd32 | 483 | c = GETC(); |
e8bbfc4e RK |
484 | break; |
485 | ||
486 | default: | |
487 | return (c); | |
488 | } | |
489 | } | |
490 | } | |
491 | ||
fbb18613 | 492 | /* Skips all of the white space at the current location in the input file. */ |
e8bbfc4e RK |
493 | |
494 | void | |
495 | position_after_white_space () | |
496 | { | |
497 | register int c; | |
498 | ||
fbb18613 | 499 | c = GETC(); |
e8bbfc4e | 500 | |
e3d1fd32 | 501 | UNGETC (skip_white_space (c)); |
e8bbfc4e RK |
502 | } |
503 | ||
504 | /* Make the token buffer longer, preserving the data in it. | |
505 | P should point to just beyond the last valid character in the old buffer. | |
506 | The value we return is a pointer to the new buffer | |
507 | at a place corresponding to P. */ | |
508 | ||
fbb18613 JM |
509 | static void |
510 | extend_token_buffer_to (size) | |
511 | int size; | |
512 | { | |
513 | do | |
514 | maxtoken = maxtoken * 2 + 10; | |
515 | while (maxtoken < size); | |
516 | token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2); | |
517 | } | |
518 | ||
e8bbfc4e RK |
519 | static char * |
520 | extend_token_buffer (p) | |
5d5993dd | 521 | const char *p; |
e8bbfc4e RK |
522 | { |
523 | int offset = p - token_buffer; | |
fbb18613 | 524 | extend_token_buffer_to (offset); |
e8bbfc4e RK |
525 | return token_buffer + offset; |
526 | } | |
e3d1fd32 | 527 | \f |
75cb8865 | 528 | #if defined HANDLE_PRAGMA |
f09db6e0 NC |
529 | /* Local versions of these macros, that can be passed as function pointers. */ |
530 | static int | |
531 | pragma_getc () | |
532 | { | |
94f9afc2 | 533 | return GETC (); |
f09db6e0 NC |
534 | } |
535 | ||
536 | static void | |
537 | pragma_ungetc (arg) | |
538 | int arg; | |
539 | { | |
540 | UNGETC (arg); | |
541 | } | |
542 | #endif | |
543 | ||
fbb18613 JM |
544 | static int |
545 | read_line_number (num) | |
546 | int *num; | |
547 | { | |
548 | register int token = yylex (); | |
549 | ||
550 | if (token == CONSTANT | |
551 | && TREE_CODE (yylval.ttype) == INTEGER_CST) | |
552 | { | |
553 | *num = TREE_INT_CST_LOW (yylval.ttype); | |
554 | return 1; | |
555 | } | |
556 | else | |
557 | { | |
558 | if (token != END_OF_LINE) | |
559 | error ("invalid #-line"); | |
560 | return 0; | |
561 | } | |
562 | } | |
563 | ||
e8bbfc4e RK |
564 | /* At the beginning of a line, increment the line number |
565 | and process any #-directive on this line. | |
566 | If the line is a #-directive, read the entire line and return a newline. | |
fbb18613 JM |
567 | Otherwise, return the line's first non-whitespace character. |
568 | ||
569 | Note that in the case of USE_CPPLIB, we get the whole line as one | |
570 | CPP_DIRECTIVE token. */ | |
e8bbfc4e RK |
571 | |
572 | int | |
573 | check_newline () | |
574 | { | |
575 | register int c; | |
576 | register int token; | |
fbb18613 JM |
577 | int saw_line; |
578 | enum { act_none, act_push, act_pop } action; | |
579 | int old_lineno, action_number, l; | |
e8bbfc4e | 580 | |
fbb18613 | 581 | restart: |
e8bbfc4e RK |
582 | /* Read first nonwhite char on the line. */ |
583 | ||
fbb18613 JM |
584 | #ifdef USE_CPPLIB |
585 | c = GETC (); | |
586 | /* In some cases where we're leaving an include file, we can get multiple | |
587 | CPP_HSPACE tokens in a row, so we need to loop. */ | |
588 | while (cpp_token == CPP_HSPACE) | |
589 | c = yy_get_token (); | |
590 | #else | |
591 | do | |
592 | c = GETC (); | |
593 | while (c == ' ' || c == '\t'); | |
594 | #endif | |
595 | ||
596 | lineno++; | |
e8bbfc4e RK |
597 | |
598 | if (c != '#') | |
599 | { | |
fbb18613 JM |
600 | /* Sequences of multiple newlines are very common; optimize them. */ |
601 | if (c == '\n') | |
602 | goto restart; | |
603 | ||
e8bbfc4e RK |
604 | /* If not #, return it so caller will use it. */ |
605 | return c; | |
606 | } | |
607 | ||
fbb18613 JM |
608 | /* Don't read beyond this line. */ |
609 | saw_line = 0; | |
610 | linemode = 1; | |
611 | ||
612 | #if USE_CPPLIB | |
613 | if (cpp_token == CPP_VSPACE) | |
614 | { | |
615 | /* Format is "<space> <line number> <filename> <newline>". | |
616 | Only the line number is interesting, and even that | |
617 | we can get more efficiently than scanning the line. */ | |
618 | yy_cur = yy_lim - 1; | |
619 | lineno = parse_in.lineno - 1; | |
620 | goto skipline; | |
621 | } | |
622 | #endif | |
e8bbfc4e | 623 | |
fbb18613 | 624 | token = yylex (); |
e8bbfc4e | 625 | |
fbb18613 | 626 | if (token == IDENTIFIER) |
e8bbfc4e | 627 | { |
fbb18613 JM |
628 | /* If a letter follows, then if the word here is `line', skip |
629 | it and ignore it; otherwise, ignore the line, with an error | |
630 | if the word isn't `pragma'. */ | |
75cb8865 | 631 | |
fbb18613 | 632 | const char *name = IDENTIFIER_POINTER (yylval.ttype); |
75cb8865 | 633 | |
fbb18613 JM |
634 | if (!strcmp (name, "pragma")) |
635 | { | |
636 | token = yylex (); | |
637 | if (token != IDENTIFIER | |
638 | || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE) | |
639 | goto skipline; | |
e2af664c | 640 | |
fbb18613 JM |
641 | #ifdef HANDLE_PRAGMA |
642 | /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS | |
643 | (if both are defined), in order to give the back | |
644 | end a chance to override the interpretation of | |
645 | SYSV style pragmas. */ | |
94f9afc2 | 646 | if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc, |
fbb18613 JM |
647 | IDENTIFIER_POINTER (yylval.ttype))) |
648 | goto skipline; | |
e8bbfc4e | 649 | #endif /* HANDLE_PRAGMA */ |
fbb18613 | 650 | |
e2af664c | 651 | #ifdef HANDLE_GENERIC_PRAGMAS |
fbb18613 JM |
652 | if (handle_generic_pragma (token)) |
653 | goto skipline; | |
e2af664c | 654 | #endif /* HANDLE_GENERIC_PRAGMAS */ |
75cb8865 | 655 | |
fbb18613 JM |
656 | /* Issue a warning message if we have been asked to do so. |
657 | Ignoring unknown pragmas in system header file unless | |
658 | an explcit -Wunknown-pragmas has been given. */ | |
659 | if (warn_unknown_pragmas > 1 | |
660 | || (warn_unknown_pragmas && ! in_system_header)) | |
661 | warning ("ignoring pragma: %s", token_buffer); | |
75cb8865 | 662 | |
fbb18613 | 663 | goto skipline; |
e8bbfc4e | 664 | } |
fbb18613 | 665 | else if (!strcmp (name, "define")) |
e8bbfc4e | 666 | { |
fbb18613 JM |
667 | debug_define (lineno, GET_DIRECTIVE_LINE ()); |
668 | goto skipline; | |
e8bbfc4e | 669 | } |
fbb18613 | 670 | else if (!strcmp (name, "undef")) |
e8bbfc4e | 671 | { |
fbb18613 JM |
672 | debug_undef (lineno, GET_DIRECTIVE_LINE ()); |
673 | goto skipline; | |
e8bbfc4e | 674 | } |
fbb18613 | 675 | else if (!strcmp (name, "line")) |
e8bbfc4e | 676 | { |
fbb18613 JM |
677 | saw_line = 1; |
678 | token = yylex (); | |
679 | goto linenum; | |
e8bbfc4e | 680 | } |
fbb18613 | 681 | else if (!strcmp (name, "ident")) |
e8bbfc4e | 682 | { |
86702e31 | 683 | /* #ident. The pedantic warning is now in cpp. */ |
e8bbfc4e | 684 | |
fbb18613 JM |
685 | /* Here we have just seen `#ident '. |
686 | A string constant should follow. */ | |
e8bbfc4e | 687 | |
fbb18613 JM |
688 | token = yylex (); |
689 | if (token == END_OF_LINE) | |
690 | goto skipline; | |
691 | if (token != STRING | |
692 | || TREE_CODE (yylval.ttype) != STRING_CST) | |
693 | { | |
694 | error ("invalid #ident"); | |
695 | goto skipline; | |
696 | } | |
e8bbfc4e | 697 | |
fbb18613 JM |
698 | if (! flag_no_ident) |
699 | { | |
e8bbfc4e | 700 | #ifdef ASM_OUTPUT_IDENT |
fbb18613 JM |
701 | ASM_OUTPUT_IDENT (asm_out_file, |
702 | TREE_STRING_POINTER (yylval.ttype)); | |
e8bbfc4e | 703 | #endif |
e8bbfc4e | 704 | } |
fbb18613 JM |
705 | |
706 | /* Skip the rest of this line. */ | |
707 | goto skipline; | |
e8bbfc4e RK |
708 | } |
709 | ||
fbb18613 | 710 | error ("undefined or invalid # directive `%s'", name); |
e8bbfc4e RK |
711 | goto skipline; |
712 | } | |
713 | ||
fbb18613 JM |
714 | /* If the # is the only nonwhite char on the line, |
715 | just ignore it. Check the new newline. */ | |
716 | if (token == END_OF_LINE) | |
717 | goto skipline; | |
718 | ||
e8bbfc4e RK |
719 | linenum: |
720 | /* Here we have either `#line' or `# <nonletter>'. | |
721 | In either case, it should be a line number; a digit should follow. */ | |
722 | ||
fbb18613 JM |
723 | if (token != CONSTANT |
724 | || TREE_CODE (yylval.ttype) != INTEGER_CST) | |
725 | { | |
726 | error ("invalid #-line"); | |
727 | goto skipline; | |
728 | } | |
e8bbfc4e | 729 | |
fbb18613 JM |
730 | /* subtract one, because it is the following line that |
731 | gets the specified number */ | |
e8bbfc4e | 732 | |
fbb18613 | 733 | l = TREE_INT_CST_LOW (yylval.ttype) - 1; |
e8bbfc4e | 734 | |
fbb18613 JM |
735 | /* More follows: it must be a string constant (filename). |
736 | It would be neat to use cpplib to quickly process the string, but | |
737 | (1) we don't have a handy tokenization of the string, and | |
738 | (2) I don't know how well that would work in the presense | |
739 | of filenames that contain wide characters. */ | |
e8bbfc4e | 740 | |
fbb18613 | 741 | if (saw_line) |
e8bbfc4e | 742 | { |
fbb18613 JM |
743 | /* Don't treat \ as special if we are processing #line 1 "...". |
744 | If you want it to be treated specially, use # 1 "...". */ | |
745 | ignore_escape_flag = 1; | |
746 | } | |
e8bbfc4e | 747 | |
fbb18613 JM |
748 | /* Read the string constant. */ |
749 | token = yylex (); | |
e8bbfc4e | 750 | |
fbb18613 | 751 | ignore_escape_flag = 0; |
e8bbfc4e | 752 | |
fbb18613 JM |
753 | if (token == END_OF_LINE) |
754 | { | |
755 | /* No more: store the line number and check following line. */ | |
756 | lineno = l; | |
757 | goto skipline; | |
758 | } | |
e8bbfc4e | 759 | |
fbb18613 JM |
760 | if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) |
761 | { | |
762 | error ("invalid #line"); | |
763 | goto skipline; | |
764 | } | |
e8bbfc4e | 765 | |
4dd7201e | 766 | input_filename = TREE_STRING_POINTER (yylval.ttype); |
e8bbfc4e | 767 | |
fbb18613 JM |
768 | if (main_input_filename == 0) |
769 | main_input_filename = input_filename; | |
e8bbfc4e | 770 | |
fbb18613 JM |
771 | old_lineno = lineno; |
772 | action = act_none; | |
773 | action_number = 0; | |
774 | lineno = l; | |
e8bbfc4e | 775 | |
fbb18613 JM |
776 | /* Each change of file name |
777 | reinitializes whether we are now in a system header. */ | |
778 | in_system_header = 0; | |
e8bbfc4e | 779 | |
fbb18613 JM |
780 | if (!read_line_number (&action_number)) |
781 | { | |
782 | /* Update the name in the top element of input_file_stack. */ | |
5b450ae5 RS |
783 | if (input_file_stack) |
784 | input_file_stack->name = input_filename; | |
fbb18613 | 785 | } |
5b450ae5 | 786 | |
fbb18613 JM |
787 | /* `1' after file name means entering new file. |
788 | `2' after file name means just left a file. */ | |
e8bbfc4e | 789 | |
fbb18613 JM |
790 | if (action_number == 1) |
791 | { | |
792 | action = act_push; | |
793 | read_line_number (&action_number); | |
794 | } | |
795 | else if (action_number == 2) | |
796 | { | |
797 | action = act_pop; | |
798 | read_line_number (&action_number); | |
799 | } | |
800 | if (action_number == 3) | |
801 | { | |
e8bbfc4e | 802 | /* `3' after file name means this is a system header file. */ |
fbb18613 JM |
803 | in_system_header = 1; |
804 | read_line_number (&action_number); | |
805 | } | |
e8bbfc4e | 806 | |
fbb18613 | 807 | /* Do the actions implied by the preceding numbers. */ |
0468bc75 | 808 | |
fbb18613 JM |
809 | if (action == act_push) |
810 | { | |
811 | /* Pushing to a new file. */ | |
812 | struct file_stack *p | |
813 | = (struct file_stack *) xmalloc (sizeof (struct file_stack)); | |
814 | input_file_stack->line = old_lineno; | |
815 | p->next = input_file_stack; | |
816 | p->name = input_filename; | |
817 | p->indent_level = indent_level; | |
818 | input_file_stack = p; | |
819 | input_file_stack_tick++; | |
820 | debug_start_source_file (input_filename); | |
821 | } | |
822 | else if (action == act_pop) | |
823 | { | |
824 | /* Popping out of a file. */ | |
825 | if (input_file_stack->next) | |
0468bc75 | 826 | { |
fbb18613 JM |
827 | struct file_stack *p = input_file_stack; |
828 | if (indent_level != p->indent_level) | |
829 | { | |
830 | warning_with_file_and_line | |
831 | (p->name, old_lineno, | |
832 | "This file contains more `%c's than `%c's.", | |
833 | indent_level > p->indent_level ? '{' : '}', | |
834 | indent_level > p->indent_level ? '}' : '{'); | |
835 | } | |
836 | input_file_stack = p->next; | |
837 | free (p); | |
838 | input_file_stack_tick++; | |
839 | debug_end_source_file (input_file_stack->line); | |
0468bc75 | 840 | } |
fbb18613 JM |
841 | else |
842 | error ("#-lines for entering and leaving files don't match"); | |
e8bbfc4e | 843 | } |
fbb18613 JM |
844 | |
845 | /* Now that we've pushed or popped the input stack, | |
846 | update the name in the top element. */ | |
847 | if (input_file_stack) | |
848 | input_file_stack->name = input_filename; | |
e8bbfc4e RK |
849 | |
850 | /* skip the rest of this line. */ | |
851 | skipline: | |
fbb18613 JM |
852 | linemode = 0; |
853 | end_of_file = 0; | |
854 | ||
855 | do | |
e3d1fd32 | 856 | c = GETC(); |
fbb18613 | 857 | while (c != '\n' && c != EOF); |
e8bbfc4e RK |
858 | return c; |
859 | } | |
860 | \f | |
e2af664c | 861 | #ifdef HANDLE_GENERIC_PRAGMAS |
ca5b800a | 862 | |
e3d1fd32 PB |
863 | /* Handle a #pragma directive. |
864 | TOKEN is the token we read after `#pragma'. Processes the entire input | |
e2af664c | 865 | line and return non-zero iff the pragma has been successfully parsed. */ |
ca5b800a RS |
866 | |
867 | /* This function has to be in this file, in order to get at | |
868 | the token types. */ | |
869 | ||
9870475c | 870 | static int |
e2af664c | 871 | handle_generic_pragma (token) |
141713de | 872 | register int token; |
ca5b800a | 873 | { |
a3100298 | 874 | for (;;) |
ca5b800a | 875 | { |
141713de | 876 | switch (token) |
a3100298 TW |
877 | { |
878 | case IDENTIFIER: | |
879 | case TYPENAME: | |
880 | case STRING: | |
881 | case CONSTANT: | |
882 | handle_pragma_token (token_buffer, yylval.ttype); | |
883 | break; | |
fbb18613 JM |
884 | |
885 | case END_OF_LINE: | |
886 | return handle_pragma_token (NULL_PTR, NULL_TREE); | |
887 | ||
a3100298 | 888 | default: |
f09db6e0 | 889 | handle_pragma_token (token_buffer, NULL); |
a3100298 | 890 | } |
f09db6e0 | 891 | |
141713de | 892 | token = yylex (); |
ca5b800a | 893 | } |
ca5b800a RS |
894 | } |
895 | ||
e2af664c | 896 | #endif /* HANDLE_GENERIC_PRAGMAS */ |
ca5b800a | 897 | \f |
e8bbfc4e RK |
898 | #define ENDFILE -1 /* token that represents end-of-file */ |
899 | ||
900 | /* Read an escape sequence, returning its equivalent as a character, | |
b70af677 | 901 | or store 1 in *ignore_ptr if it is backslash-newline. */ |
e8bbfc4e RK |
902 | |
903 | static int | |
b70af677 RS |
904 | readescape (ignore_ptr) |
905 | int *ignore_ptr; | |
e8bbfc4e | 906 | { |
e3d1fd32 | 907 | register int c = GETC(); |
e8bbfc4e RK |
908 | register int code; |
909 | register unsigned count; | |
1c7b145e | 910 | unsigned firstdig = 0; |
8696da34 | 911 | int nonnull; |
e8bbfc4e RK |
912 | |
913 | switch (c) | |
914 | { | |
915 | case 'x': | |
916 | if (warn_traditional) | |
917 | warning ("the meaning of `\\x' varies with -traditional"); | |
918 | ||
919 | if (flag_traditional) | |
920 | return c; | |
921 | ||
922 | code = 0; | |
923 | count = 0; | |
8696da34 | 924 | nonnull = 0; |
e8bbfc4e RK |
925 | while (1) |
926 | { | |
e3d1fd32 | 927 | c = GETC(); |
fbb18613 | 928 | if (! ISXDIGIT (c)) |
e8bbfc4e | 929 | { |
e3d1fd32 | 930 | UNGETC (c); |
e8bbfc4e RK |
931 | break; |
932 | } | |
933 | code *= 16; | |
934 | if (c >= 'a' && c <= 'f') | |
935 | code += c - 'a' + 10; | |
936 | if (c >= 'A' && c <= 'F') | |
937 | code += c - 'A' + 10; | |
938 | if (c >= '0' && c <= '9') | |
939 | code += c - '0'; | |
8696da34 RS |
940 | if (code != 0 || count != 0) |
941 | { | |
942 | if (count == 0) | |
943 | firstdig = code; | |
944 | count++; | |
945 | } | |
946 | nonnull = 1; | |
e8bbfc4e | 947 | } |
8696da34 | 948 | if (! nonnull) |
4082292a AO |
949 | { |
950 | warning ("\\x used with no following hex digits"); | |
951 | return 'x'; | |
952 | } | |
be63d912 RS |
953 | else if (count == 0) |
954 | /* Digits are all 0's. Ok. */ | |
955 | ; | |
e8bbfc4e RK |
956 | else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node) |
957 | || (count > 1 | |
fbb18613 JM |
958 | && (((unsigned)1 |
959 | << (TYPE_PRECISION (integer_type_node) | |
960 | - (count - 1) * 4)) | |
e8bbfc4e RK |
961 | <= firstdig))) |
962 | pedwarn ("hex escape out of range"); | |
963 | return code; | |
964 | ||
965 | case '0': case '1': case '2': case '3': case '4': | |
966 | case '5': case '6': case '7': | |
967 | code = 0; | |
968 | count = 0; | |
969 | while ((c <= '7') && (c >= '0') && (count++ < 3)) | |
970 | { | |
971 | code = (code * 8) + (c - '0'); | |
e3d1fd32 | 972 | c = GETC(); |
e8bbfc4e | 973 | } |
e3d1fd32 | 974 | UNGETC (c); |
e8bbfc4e RK |
975 | return code; |
976 | ||
977 | case '\\': case '\'': case '"': | |
978 | return c; | |
979 | ||
980 | case '\n': | |
981 | lineno++; | |
b70af677 RS |
982 | *ignore_ptr = 1; |
983 | return 0; | |
e8bbfc4e RK |
984 | |
985 | case 'n': | |
986 | return TARGET_NEWLINE; | |
987 | ||
988 | case 't': | |
989 | return TARGET_TAB; | |
990 | ||
991 | case 'r': | |
992 | return TARGET_CR; | |
993 | ||
994 | case 'f': | |
995 | return TARGET_FF; | |
996 | ||
997 | case 'b': | |
998 | return TARGET_BS; | |
999 | ||
1000 | case 'a': | |
1001 | if (warn_traditional) | |
1002 | warning ("the meaning of `\\a' varies with -traditional"); | |
1003 | ||
1004 | if (flag_traditional) | |
1005 | return c; | |
1006 | return TARGET_BELL; | |
1007 | ||
1008 | case 'v': | |
1009 | #if 0 /* Vertical tab is present in common usage compilers. */ | |
1010 | if (flag_traditional) | |
1011 | return c; | |
1012 | #endif | |
1013 | return TARGET_VT; | |
1014 | ||
dad112ca | 1015 | case 'e': |
e8bbfc4e | 1016 | case 'E': |
dad112ca RS |
1017 | if (pedantic) |
1018 | pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c); | |
f3ad1f9c | 1019 | return TARGET_ESC; |
e8bbfc4e RK |
1020 | |
1021 | case '?': | |
1022 | return c; | |
1023 | ||
1024 | /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */ | |
1025 | case '(': | |
1026 | case '{': | |
1027 | case '[': | |
3285fe92 RS |
1028 | /* `\%' is used to prevent SCCS from getting confused. */ |
1029 | case '%': | |
e8bbfc4e | 1030 | if (pedantic) |
fbb18613 | 1031 | pedwarn ("unknown escape sequence `\\%c'", c); |
e8bbfc4e RK |
1032 | return c; |
1033 | } | |
fbb18613 | 1034 | if (ISGRAPH (c)) |
e8bbfc4e RK |
1035 | pedwarn ("unknown escape sequence `\\%c'", c); |
1036 | else | |
1037 | pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c); | |
1038 | return c; | |
1039 | } | |
1040 | \f | |
1041 | void | |
ab87f8c8 | 1042 | yyerror (msgid) |
5d5993dd | 1043 | const char *msgid; |
e8bbfc4e | 1044 | { |
5d5993dd | 1045 | const char *string = _(msgid); |
e8bbfc4e RK |
1046 | |
1047 | /* We can't print string and character constants well | |
1048 | because the token_buffer contains the result of processing escapes. */ | |
1049 | if (end_of_file) | |
ab87f8c8 | 1050 | error ("%s at end of input", string); |
e8bbfc4e | 1051 | else if (token_buffer[0] == 0) |
ab87f8c8 | 1052 | error ("%s at null character", string); |
e8bbfc4e | 1053 | else if (token_buffer[0] == '"') |
ab87f8c8 | 1054 | error ("%s before string constant", string); |
e8bbfc4e | 1055 | else if (token_buffer[0] == '\'') |
ab87f8c8 | 1056 | error ("%s before character constant", string); |
f3ad1f9c | 1057 | else if (!ISGRAPH(token_buffer[0])) |
ab87f8c8 | 1058 | error ("%s before character 0%o", string, (unsigned char) token_buffer[0]); |
e8bbfc4e | 1059 | else |
ab87f8c8 | 1060 | error ("%s before `%s'", string, token_buffer); |
e8bbfc4e RK |
1061 | } |
1062 | ||
1063 | #if 0 | |
1064 | ||
1065 | struct try_type | |
1066 | { | |
1067 | tree *node_var; | |
1068 | char unsigned_flag; | |
1069 | char long_flag; | |
1070 | char long_long_flag; | |
1071 | }; | |
1072 | ||
75cb8865 | 1073 | struct try_type type_sequence[] = |
e8bbfc4e RK |
1074 | { |
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} | |
1081 | }; | |
1082 | #endif /* 0 */ | |
1083 | \f | |
ed513abf KG |
1084 | struct pf_args |
1085 | { | |
1086 | /* Input */ | |
1087 | int base; | |
1088 | char * p; | |
1089 | /* I/O */ | |
1090 | int c; | |
fbb18613 | 1091 | /* Output */ |
ed513abf KG |
1092 | int imag; |
1093 | tree type; | |
1094 | int conversion_errno; | |
ed513abf KG |
1095 | REAL_VALUE_TYPE value; |
1096 | }; | |
1097 | ||
1098 | static void | |
1099 | parse_float (data) | |
1100 | PTR data; | |
1101 | { | |
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); | |
fbb18613 JM |
1109 | args->imag = 0; |
1110 | args->conversion_errno = 0; | |
1111 | args->type = double_type_node; | |
ed513abf KG |
1112 | |
1113 | while (1) | |
1114 | { | |
1115 | int lose = 0; | |
1116 | ||
1117 | /* Read the suffixes to choose a data type. */ | |
1118 | switch (args->c) | |
1119 | { | |
1120 | case 'f': case 'F': | |
1121 | if (fflag) | |
1122 | error ("more than one `f' in numeric constant"); | |
1123 | fflag = 1; | |
1124 | break; | |
1125 | ||
1126 | case 'l': case 'L': | |
1127 | if (lflag) | |
1128 | error ("more than one `l' in numeric constant"); | |
1129 | lflag = 1; | |
1130 | break; | |
1131 | ||
1132 | case 'i': case 'I': | |
1133 | if (args->imag) | |
1134 | error ("more than one `i' or `j' in numeric constant"); | |
1135 | else if (pedantic) | |
1136 | pedwarn ("ANSI C forbids imaginary numeric constants"); | |
1137 | args->imag = 1; | |
1138 | break; | |
1139 | ||
1140 | default: | |
1141 | lose = 1; | |
1142 | } | |
1143 | ||
1144 | if (lose) | |
1145 | break; | |
1146 | ||
1147 | if (args->p >= token_buffer + maxtoken - 3) | |
1148 | args->p = extend_token_buffer (args->p); | |
1149 | *(args->p++) = args->c; | |
1150 | *(args->p) = 0; | |
1151 | args->c = GETC(); | |
1152 | } | |
1153 | ||
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. */ | |
1157 | ||
1158 | if (fflag) | |
1159 | { | |
1160 | if (lflag) | |
1161 | error ("both `f' and `l' in floating constant"); | |
1162 | ||
1163 | args->type = float_type_node; | |
1164 | errno = 0; | |
1165 | if (args->base == 16) | |
1166 | args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type)); | |
1167 | else | |
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'"); | |
1175 | } | |
1176 | else if (lflag) | |
1177 | { | |
1178 | args->type = long_double_type_node; | |
1179 | errno = 0; | |
1180 | if (args->base == 16) | |
1181 | args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type)); | |
1182 | else | |
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'"); | |
1187 | } | |
1188 | else | |
1189 | { | |
1190 | errno = 0; | |
1191 | if (args->base == 16) | |
1192 | args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type)); | |
1193 | else | |
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'"); | |
1198 | } | |
1199 | } | |
1200 | ||
fbb18613 JM |
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 | |
1205 | character. */ | |
1206 | ||
6e090c76 | 1207 | static inline int token_getch PARAMS ((void)); |
93868d11 KG |
1208 | |
1209 | static inline int | |
fbb18613 JM |
1210 | token_getch () |
1211 | { | |
1212 | #if USE_CPPLIB | |
1213 | if (yy_cur == yy_lim) | |
1214 | return '\0'; | |
1215 | #endif | |
1216 | return GETC (); | |
1217 | } | |
1218 | ||
6e090c76 | 1219 | static inline void token_put_back PARAMS ((int)); |
93868d11 KG |
1220 | |
1221 | static inline void | |
fbb18613 JM |
1222 | token_put_back (ch) |
1223 | int ch; | |
1224 | { | |
1225 | #if USE_CPPLIB | |
1226 | if (ch == '\0') | |
1227 | return; | |
1228 | #endif | |
1229 | UNGETC (ch); | |
1230 | } | |
1231 | ||
1232 | /* Read a single token from the input stream, and assign it lexical | |
1233 | semantics. */ | |
1234 | ||
e8bbfc4e RK |
1235 | int |
1236 | yylex () | |
1237 | { | |
1238 | register int c; | |
1239 | register char *p; | |
1240 | register int value; | |
1241 | int wide_flag = 0; | |
e31c7eec | 1242 | int objc_flag = 0; |
e8bbfc4e | 1243 | |
fbb18613 | 1244 | c = GETC(); |
e8bbfc4e RK |
1245 | |
1246 | /* Effectively do c = skip_white_space (c) | |
1247 | but do it faster in the usual cases. */ | |
1248 | while (1) | |
1249 | switch (c) | |
1250 | { | |
e8bbfc4e RK |
1251 | case ' ': |
1252 | case '\t': | |
1253 | case '\f': | |
1254 | case '\v': | |
1255 | case '\b': | |
fbb18613 JM |
1256 | #if USE_CPPLIB |
1257 | if (cpp_token == CPP_HSPACE) | |
1258 | c = yy_get_token (); | |
1259 | else | |
1260 | #endif | |
1261 | c = GETC(); | |
e8bbfc4e RK |
1262 | break; |
1263 | ||
80f5b9d8 RS |
1264 | case '\r': |
1265 | /* Call skip_white_space so we can warn if appropriate. */ | |
1266 | ||
e8bbfc4e RK |
1267 | case '\n': |
1268 | case '/': | |
1269 | case '\\': | |
1270 | c = skip_white_space (c); | |
1271 | default: | |
1272 | goto found_nonwhite; | |
1273 | } | |
1274 | found_nonwhite: | |
1275 | ||
1276 | token_buffer[0] = c; | |
1277 | token_buffer[1] = 0; | |
1278 | ||
1279 | /* yylloc.first_line = lineno; */ | |
1280 | ||
1281 | switch (c) | |
1282 | { | |
1283 | case EOF: | |
1284 | end_of_file = 1; | |
1285 | token_buffer[0] = 0; | |
fbb18613 JM |
1286 | if (linemode) |
1287 | value = END_OF_LINE; | |
1288 | else | |
1289 | value = ENDFILE; | |
e8bbfc4e RK |
1290 | break; |
1291 | ||
e8bbfc4e | 1292 | case 'L': |
fbb18613 JM |
1293 | #if USE_CPPLIB |
1294 | if (cpp_token == CPP_NAME) | |
1295 | goto letter; | |
1296 | #endif | |
e8bbfc4e RK |
1297 | /* Capital L may start a wide-string or wide-character constant. */ |
1298 | { | |
fbb18613 | 1299 | register int c = token_getch(); |
e8bbfc4e RK |
1300 | if (c == '\'') |
1301 | { | |
1302 | wide_flag = 1; | |
1303 | goto char_constant; | |
1304 | } | |
1305 | if (c == '"') | |
1306 | { | |
1307 | wide_flag = 1; | |
1308 | goto string_constant; | |
1309 | } | |
fbb18613 | 1310 | token_put_back (c); |
e8bbfc4e RK |
1311 | } |
1312 | goto letter; | |
1313 | ||
1314 | case '@': | |
1315 | if (!doing_objc_thang) | |
1316 | { | |
1317 | value = c; | |
1318 | break; | |
1319 | } | |
e31c7eec | 1320 | else |
e8bbfc4e | 1321 | { |
e31c7eec | 1322 | /* '@' may start a constant string object. */ |
fbb18613 | 1323 | register int c = token_getch (); |
e31c7eec TW |
1324 | if (c == '"') |
1325 | { | |
1326 | objc_flag = 1; | |
1327 | goto string_constant; | |
1328 | } | |
fbb18613 | 1329 | token_put_back (c); |
ddd5a7c1 | 1330 | /* Fall through to treat '@' as the start of an identifier. */ |
e8bbfc4e RK |
1331 | } |
1332 | ||
e8bbfc4e RK |
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': | |
1338 | case 'Z': | |
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': | |
1344 | case 'z': | |
1345 | case '_': | |
f84cddb9 | 1346 | case '$': |
e8bbfc4e | 1347 | letter: |
fbb18613 JM |
1348 | #if USE_CPPLIB |
1349 | if (cpp_token == CPP_NAME) | |
1350 | { | |
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. */ | |
1354 | ||
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; | |
1360 | yy_cur = yy_lim; | |
1361 | } | |
1362 | else | |
1363 | #endif | |
e8bbfc4e | 1364 | { |
fbb18613 JM |
1365 | p = token_buffer; |
1366 | while (ISALNUM (c) || c == '_' || c == '$' || c == '@') | |
f84cddb9 | 1367 | { |
fbb18613 JM |
1368 | /* Make sure this char really belongs in an identifier. */ |
1369 | if (c == '$') | |
1370 | { | |
1371 | if (! dollars_in_ident) | |
1372 | error ("`$' in identifier"); | |
1373 | else if (pedantic) | |
1374 | pedwarn ("`$' in identifier"); | |
1375 | } | |
e8bbfc4e | 1376 | |
fbb18613 JM |
1377 | if (p >= token_buffer + maxtoken) |
1378 | p = extend_token_buffer (p); | |
8355fc27 | 1379 | |
fbb18613 JM |
1380 | *p++ = c; |
1381 | c = token_getch(); | |
1382 | } | |
e8bbfc4e | 1383 | |
fbb18613 JM |
1384 | *p = 0; |
1385 | token_put_back (c); | |
1386 | } | |
e8bbfc4e RK |
1387 | |
1388 | value = IDENTIFIER; | |
1389 | yylval.itype = 0; | |
1390 | ||
1391 | /* Try to recognize a keyword. Uses minimum-perfect hash function */ | |
1392 | ||
1393 | { | |
1394 | register struct resword *ptr; | |
1395 | ||
9870475c | 1396 | if ((ptr = is_reserved_word (token_buffer, p - token_buffer))) |
e8bbfc4e RK |
1397 | { |
1398 | if (ptr->rid) | |
1399 | yylval.ttype = ridpointers[(int) ptr->rid]; | |
1400 | value = (int) ptr->token; | |
1401 | ||
e31c7eec TW |
1402 | /* Only return OBJECTNAME if it is a typedef. */ |
1403 | if (doing_objc_thang && value == OBJECTNAME) | |
1404 | { | |
1405 | lastiddecl = lookup_name(yylval.ttype); | |
1406 | ||
1407 | if (lastiddecl == NULL_TREE | |
1408 | || TREE_CODE (lastiddecl) != TYPE_DECL) | |
1409 | value = IDENTIFIER; | |
1410 | } | |
1411 | ||
e8bbfc4e RK |
1412 | /* Even if we decided to recognize asm, still perhaps warn. */ |
1413 | if (pedantic | |
d45cf215 | 1414 | && (value == ASM_KEYWORD || value == TYPEOF |
e8bbfc4e RK |
1415 | || ptr->rid == RID_INLINE) |
1416 | && token_buffer[0] != '_') | |
1417 | pedwarn ("ANSI does not permit the keyword `%s'", | |
1418 | token_buffer); | |
1419 | } | |
1420 | } | |
1421 | ||
1422 | /* If we did not find a keyword, look for an identifier | |
1423 | (or a typename). */ | |
1424 | ||
1425 | if (value == IDENTIFIER) | |
1426 | { | |
e31c7eec TW |
1427 | if (token_buffer[0] == '@') |
1428 | error("invalid identifier `%s'", token_buffer); | |
1429 | ||
e8bbfc4e RK |
1430 | yylval.ttype = get_identifier (token_buffer); |
1431 | lastiddecl = lookup_name (yylval.ttype); | |
1432 | ||
1433 | if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL) | |
1434 | value = TYPENAME; | |
6dbf678a RS |
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) | |
1443 | { | |
8f7ac220 | 1444 | tree stringval = DECL_INITIAL (lastiddecl); |
75cb8865 | 1445 | |
8f7ac220 RS |
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)); | |
6dbf678a RS |
1450 | value = STRING; |
1451 | } | |
e8bbfc4e RK |
1452 | else if (doing_objc_thang) |
1453 | { | |
e31c7eec | 1454 | tree objc_interface_decl = is_class_name (yylval.ttype); |
e8bbfc4e RK |
1455 | |
1456 | if (objc_interface_decl) | |
1457 | { | |
1458 | value = CLASSNAME; | |
1459 | yylval.ttype = objc_interface_decl; | |
1460 | } | |
1461 | } | |
1462 | } | |
1463 | ||
1464 | break; | |
1465 | ||
fbb18613 JM |
1466 | case '.': |
1467 | #if USE_CPPLIB | |
1468 | if (yy_cur < yy_lim) | |
1469 | #endif | |
1470 | { | |
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; | |
1476 | if (c1 == '.') | |
1477 | { | |
1478 | c1 = token_getch (); | |
1479 | if (c1 == '.') | |
1480 | { | |
1481 | token_buffer[2] = c1; | |
1482 | token_buffer[3] = 0; | |
1483 | value = ELLIPSIS; | |
1484 | goto done; | |
1485 | } | |
1486 | error ("parse error at `..'"); | |
1487 | } | |
1488 | if (ISDIGIT (c1)) | |
1489 | { | |
1490 | token_put_back (c1); | |
1491 | goto number; | |
1492 | } | |
1493 | token_put_back (c1); | |
1494 | } | |
1495 | value = '.'; | |
1496 | token_buffer[1] = 0; | |
1497 | break; | |
1498 | ||
d669f5da | 1499 | case '0': case '1': |
fbb18613 | 1500 | /* Optimize for most frequent case. */ |
d669f5da | 1501 | { |
fbb18613 | 1502 | register int cond; |
d669f5da | 1503 | |
fbb18613 JM |
1504 | #if USE_CPPLIB |
1505 | cond = (yy_cur == yy_lim); | |
1506 | #else | |
1507 | register int c1 = token_getch (); | |
1508 | token_put_back (c1); | |
1509 | cond = (! ISALNUM (c1) && c1 != '.'); | |
1510 | #endif | |
1511 | if (cond) | |
d669f5da | 1512 | { |
d669f5da RK |
1513 | yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node; |
1514 | value = CONSTANT; | |
1515 | break; | |
1516 | } | |
1517 | /*FALLTHRU*/ | |
1518 | } | |
1519 | case '2': case '3': case '4': | |
e8bbfc4e | 1520 | case '5': case '6': case '7': case '8': case '9': |
fbb18613 | 1521 | number: |
e8bbfc4e RK |
1522 | { |
1523 | int base = 10; | |
1524 | int count = 0; | |
1525 | int largest_digit = 0; | |
1526 | int numdigits = 0; | |
e8bbfc4e RK |
1527 | int overflow = 0; |
1528 | ||
cc144655 GRK |
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]; | |
1539 | ||
c5c76735 | 1540 | enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON} |
6f4d7222 | 1541 | floatflag = NOT_FLOAT; |
e8bbfc4e | 1542 | |
4ca827d0 RS |
1543 | for (count = 0; count < TOTAL_PARTS; count++) |
1544 | parts[count] = 0; | |
e8bbfc4e RK |
1545 | |
1546 | p = token_buffer; | |
1547 | *p++ = c; | |
1548 | ||
1549 | if (c == '0') | |
1550 | { | |
fbb18613 | 1551 | *p++ = (c = token_getch()); |
e8bbfc4e RK |
1552 | if ((c == 'x') || (c == 'X')) |
1553 | { | |
1554 | base = 16; | |
fbb18613 | 1555 | *p++ = (c = token_getch()); |
e8bbfc4e RK |
1556 | } |
1557 | /* Leading 0 forces octal unless the 0 is the only digit. */ | |
1558 | else if (c >= '0' && c <= '9') | |
1559 | { | |
1560 | base = 8; | |
1561 | numdigits++; | |
1562 | } | |
1563 | else | |
1564 | numdigits++; | |
1565 | } | |
1566 | ||
1567 | /* Read all the digits-and-decimal-points. */ | |
1568 | ||
1569 | while (c == '.' | |
e9a780ec | 1570 | || (ISALNUM (c) && c != 'l' && c != 'L' |
122026c0 RS |
1571 | && c != 'u' && c != 'U' |
1572 | && c != 'i' && c != 'I' && c != 'j' && c != 'J' | |
2949a9b6 SM |
1573 | && (floatflag == NOT_FLOAT |
1574 | || ((base != 16) && (c != 'f') && (c != 'F')) | |
1575 | || base == 16))) | |
e8bbfc4e RK |
1576 | { |
1577 | if (c == '.') | |
1578 | { | |
6f4d7222 | 1579 | if (base == 16 && pedantic) |
fbb18613 | 1580 | pedwarn ("floating constant may not be in radix 16"); |
b408c3fd JW |
1581 | if (floatflag == TOO_MANY_POINTS) |
1582 | /* We have already emitted an error. Don't need another. */ | |
1583 | ; | |
6f4d7222 | 1584 | else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON) |
e8bbfc4e RK |
1585 | { |
1586 | error ("malformed floating constant"); | |
1587 | floatflag = TOO_MANY_POINTS; | |
b408c3fd JW |
1588 | /* Avoid another error from atof by forcing all characters |
1589 | from here on to be ignored. */ | |
1590 | p[-1] = '\0'; | |
e8bbfc4e RK |
1591 | } |
1592 | else | |
1593 | floatflag = AFTER_POINT; | |
1594 | ||
6f4d7222 | 1595 | if (base == 8) |
75cb8865 | 1596 | base = 10; |
fbb18613 | 1597 | *p++ = c = token_getch(); |
e8bbfc4e | 1598 | /* Accept '.' as the start of a floating-point number |
fbb18613 | 1599 | only when it is followed by a digit. */ |
e9a780ec | 1600 | if (p == token_buffer + 2 && !ISDIGIT (c)) |
fbb18613 | 1601 | abort (); |
e8bbfc4e RK |
1602 | } |
1603 | else | |
1604 | { | |
1605 | /* It is not a decimal point. | |
1606 | It should be a digit (perhaps a hex digit). */ | |
1607 | ||
e9a780ec | 1608 | if (ISDIGIT (c)) |
e8bbfc4e RK |
1609 | { |
1610 | c = c - '0'; | |
1611 | } | |
1612 | else if (base <= 10) | |
1613 | { | |
f3acae4d | 1614 | if (c == 'e' || c == 'E') |
e8bbfc4e RK |
1615 | { |
1616 | base = 10; | |
6f4d7222 | 1617 | floatflag = AFTER_EXPON; |
e8bbfc4e RK |
1618 | break; /* start of exponent */ |
1619 | } | |
1620 | error ("nondigits in number and not hexadecimal"); | |
1621 | c = 0; | |
1622 | } | |
6f4d7222 UD |
1623 | else if (base == 16 && (c == 'p' || c == 'P')) |
1624 | { | |
1625 | floatflag = AFTER_EXPON; | |
1626 | break; /* start of exponent */ | |
1627 | } | |
5f6d3823 | 1628 | else if (c >= 'a' && c <= 'f') |
e8bbfc4e RK |
1629 | { |
1630 | c = c - 'a' + 10; | |
1631 | } | |
1632 | else | |
1633 | { | |
1634 | c = c - 'A' + 10; | |
1635 | } | |
1636 | if (c >= largest_digit) | |
1637 | largest_digit = c; | |
1638 | numdigits++; | |
1639 | ||
4ca827d0 | 1640 | for (count = 0; count < TOTAL_PARTS; count++) |
e8bbfc4e | 1641 | { |
4ca827d0 | 1642 | parts[count] *= base; |
e8bbfc4e RK |
1643 | if (count) |
1644 | { | |
4ca827d0 RS |
1645 | parts[count] |
1646 | += (parts[count-1] >> HOST_BITS_PER_CHAR); | |
1647 | parts[count-1] | |
1648 | &= (1 << HOST_BITS_PER_CHAR) - 1; | |
e8bbfc4e | 1649 | } |
4ca827d0 RS |
1650 | else |
1651 | parts[0] += c; | |
e8bbfc4e | 1652 | } |
fbb18613 | 1653 | |
cc144655 GRK |
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 | |
1657 | part. */ | |
1658 | if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR) | |
1659 | { | |
1660 | overflow = 1; | |
1661 | parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1; | |
1662 | } | |
e8bbfc4e RK |
1663 | |
1664 | if (p >= token_buffer + maxtoken - 3) | |
1665 | p = extend_token_buffer (p); | |
fbb18613 | 1666 | *p++ = (c = token_getch()); |
e8bbfc4e RK |
1667 | } |
1668 | } | |
1669 | ||
adace600 | 1670 | /* This can happen on input like `int i = 0x;' */ |
e8bbfc4e | 1671 | if (numdigits == 0) |
adace600 | 1672 | error ("numeric constant with no digits"); |
e8bbfc4e RK |
1673 | |
1674 | if (largest_digit >= base) | |
1675 | error ("numeric constant contains digits beyond the radix"); | |
1676 | ||
fbb18613 JM |
1677 | /* Remove terminating char from the token buffer and delimit the |
1678 | string. */ | |
e8bbfc4e RK |
1679 | *--p = 0; |
1680 | ||
1681 | if (floatflag != NOT_FLOAT) | |
1682 | { | |
fbb18613 JM |
1683 | tree type; |
1684 | int imag, conversion_errno; | |
e8bbfc4e | 1685 | REAL_VALUE_TYPE value; |
ed513abf | 1686 | struct pf_args args; |
e8bbfc4e RK |
1687 | |
1688 | /* Read explicit exponent if any, and put it in tokenbuf. */ | |
1689 | ||
6f4d7222 UD |
1690 | if ((base == 10 && ((c == 'e') || (c == 'E'))) |
1691 | || (base == 16 && (c == 'p' || c == 'P'))) | |
e8bbfc4e RK |
1692 | { |
1693 | if (p >= token_buffer + maxtoken - 3) | |
1694 | p = extend_token_buffer (p); | |
1695 | *p++ = c; | |
fbb18613 | 1696 | c = token_getch(); |
e8bbfc4e RK |
1697 | if ((c == '+') || (c == '-')) |
1698 | { | |
1699 | *p++ = c; | |
fbb18613 | 1700 | c = token_getch(); |
e8bbfc4e | 1701 | } |
6f4d7222 | 1702 | /* Exponent is decimal, even if string is a hex float. */ |
e9a780ec | 1703 | if (! ISDIGIT (c)) |
e8bbfc4e | 1704 | error ("floating constant exponent has no digits"); |
75cb8865 | 1705 | while (ISDIGIT (c)) |
e8bbfc4e RK |
1706 | { |
1707 | if (p >= token_buffer + maxtoken - 3) | |
1708 | p = extend_token_buffer (p); | |
1709 | *p++ = c; | |
fbb18613 | 1710 | c = token_getch (); |
e8bbfc4e RK |
1711 | } |
1712 | } | |
6f4d7222 UD |
1713 | if (base == 16 && floatflag != AFTER_EXPON) |
1714 | error ("hexadecimal floating constant has no exponent"); | |
e8bbfc4e RK |
1715 | |
1716 | *p = 0; | |
e8bbfc4e | 1717 | |
ed513abf KG |
1718 | /* Setup input for parse_float() */ |
1719 | args.base = base; | |
1720 | args.p = p; | |
1721 | args.c = c; | |
ed513abf | 1722 | |
e8bbfc4e | 1723 | /* Convert string to a double, checking for overflow. */ |
ed513abf | 1724 | if (do_float_handler (parse_float, (PTR) &args)) |
e8bbfc4e | 1725 | { |
ed513abf KG |
1726 | /* Receive output from parse_float() */ |
1727 | value = args.value; | |
e8bbfc4e RK |
1728 | } |
1729 | else | |
1730 | { | |
ed513abf KG |
1731 | /* We got an exception from parse_float() */ |
1732 | error ("floating constant out of range"); | |
1733 | value = dconst0; | |
1734 | } | |
e26ceb28 | 1735 | |
ed513abf KG |
1736 | /* Receive output from parse_float() */ |
1737 | c = args.c; | |
1738 | imag = args.imag; | |
1739 | type = args.type; | |
1740 | conversion_errno = args.conversion_errno; | |
1741 | ||
1454a5ba | 1742 | #ifdef ERANGE |
e5e809f4 JL |
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'"); | |
1454a5ba | 1749 | #endif |
e8bbfc4e | 1750 | |
a47a0ed5 RK |
1751 | /* If the result is not a number, assume it must have been |
1752 | due to some error message above, so silently convert | |
1753 | it to a zero. */ | |
1754 | if (REAL_VALUE_ISNAN (value)) | |
1755 | value = dconst0; | |
1756 | ||
e8bbfc4e | 1757 | /* Create a node with determined type and value. */ |
122026c0 | 1758 | if (imag) |
77912476 RK |
1759 | yylval.ttype = build_complex (NULL_TREE, |
1760 | convert (type, integer_zero_node), | |
122026c0 RS |
1761 | build_real (type, value)); |
1762 | else | |
1763 | yylval.ttype = build_real (type, value); | |
e8bbfc4e RK |
1764 | } |
1765 | else | |
1766 | { | |
1767 | tree traditional_type, ansi_type, type; | |
8d9bfdc5 | 1768 | HOST_WIDE_INT high, low; |
e8bbfc4e RK |
1769 | int spec_unsigned = 0; |
1770 | int spec_long = 0; | |
1771 | int spec_long_long = 0; | |
122026c0 | 1772 | int spec_imag = 0; |
637194e6 | 1773 | int warn = 0, i; |
e8bbfc4e | 1774 | |
aefdd5ab | 1775 | traditional_type = ansi_type = type = NULL_TREE; |
e8bbfc4e RK |
1776 | while (1) |
1777 | { | |
1778 | if (c == 'u' || c == 'U') | |
1779 | { | |
1780 | if (spec_unsigned) | |
1781 | error ("two `u's in integer constant"); | |
1782 | spec_unsigned = 1; | |
1783 | } | |
1784 | else if (c == 'l' || c == 'L') | |
1785 | { | |
1786 | if (spec_long) | |
1787 | { | |
1788 | if (spec_long_long) | |
1789 | error ("three `l's in integer constant"); | |
520c987d | 1790 | else if (pedantic && ! in_system_header && warn_long_long) |
e8bbfc4e RK |
1791 | pedwarn ("ANSI C forbids long long integer constants"); |
1792 | spec_long_long = 1; | |
1793 | } | |
1794 | spec_long = 1; | |
1795 | } | |
122026c0 RS |
1796 | else if (c == 'i' || c == 'j' || c == 'I' || c == 'J') |
1797 | { | |
1798 | if (spec_imag) | |
1799 | error ("more than one `i' or `j' in numeric constant"); | |
b8bdbf16 JW |
1800 | else if (pedantic) |
1801 | pedwarn ("ANSI C forbids imaginary numeric constants"); | |
122026c0 RS |
1802 | spec_imag = 1; |
1803 | } | |
e8bbfc4e | 1804 | else |
91b0989e | 1805 | break; |
e8bbfc4e RK |
1806 | if (p >= token_buffer + maxtoken - 3) |
1807 | p = extend_token_buffer (p); | |
1808 | *p++ = c; | |
fbb18613 | 1809 | c = token_getch(); |
e8bbfc4e RK |
1810 | } |
1811 | ||
cc144655 GRK |
1812 | /* If the literal overflowed, pedwarn about it now. */ |
1813 | if (overflow) | |
1814 | { | |
1815 | warn = 1; | |
1816 | pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2); | |
1817 | } | |
e8bbfc4e RK |
1818 | |
1819 | /* This is simplified by the fact that our constant | |
1820 | is always positive. */ | |
8d9bfdc5 RK |
1821 | |
1822 | high = low = 0; | |
1823 | ||
1824 | for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++) | |
1825 | { | |
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); | |
1830 | } | |
75cb8865 | 1831 | |
8d9bfdc5 | 1832 | yylval.ttype = build_int_2 (low, high); |
5a9085c7 | 1833 | TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node; |
e8bbfc4e | 1834 | |
e8bbfc4e RK |
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) | |
1839 | { | |
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); | |
4ca827d0 | 1857 | else if (! spec_long_long) |
e8bbfc4e RK |
1858 | traditional_type = (spec_unsigned ? long_unsigned_type_node |
1859 | : long_integer_type_node); | |
835f9b4d GRK |
1860 | else if (int_fits_type_p (yylval.ttype, |
1861 | spec_unsigned | |
1862 | ? long_long_unsigned_type_node | |
1863 | : long_long_integer_type_node)) | |
e8bbfc4e RK |
1864 | traditional_type = (spec_unsigned |
1865 | ? long_long_unsigned_type_node | |
1866 | : long_long_integer_type_node); | |
835f9b4d GRK |
1867 | else |
1868 | traditional_type = (spec_unsigned | |
1869 | ? widest_unsigned_literal_type_node | |
1870 | : widest_integer_literal_type_node); | |
e8bbfc4e RK |
1871 | } |
1872 | if (warn_traditional || ! flag_traditional) | |
1873 | { | |
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; | |
956d6950 JL |
1884 | else if (! spec_long_long |
1885 | && int_fits_type_p (yylval.ttype, | |
1886 | long_unsigned_type_node)) | |
e8bbfc4e RK |
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; | |
835f9b4d GRK |
1892 | else if (int_fits_type_p (yylval.ttype, |
1893 | long_long_unsigned_type_node)) | |
e8bbfc4e | 1894 | ansi_type = long_long_unsigned_type_node; |
835f9b4d GRK |
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; | |
1899 | else | |
1900 | ansi_type = widest_unsigned_literal_type_node; | |
e8bbfc4e RK |
1901 | } |
1902 | ||
1903 | type = flag_traditional ? traditional_type : ansi_type; | |
1904 | ||
48776cde KG |
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) | |
e8bbfc4e RK |
1910 | { |
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"); | |
a3ee5899 JW |
1917 | else |
1918 | warning ("width of integer constant may change on other systems with -traditional"); | |
e8bbfc4e | 1919 | } |
e8bbfc4e | 1920 | |
956d6950 JL |
1921 | if (pedantic && !flag_traditional && !spec_long_long && !warn |
1922 | && (TYPE_PRECISION (long_integer_type_node) | |
1923 | < TYPE_PRECISION (type))) | |
0e0fda0d GRK |
1924 | { |
1925 | warn = 1; | |
ed534bdd | 1926 | pedwarn ("integer constant larger than the maximum value of an unsigned long int"); |
0e0fda0d | 1927 | } |
88d92ca5 | 1928 | |
c832a30e | 1929 | if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type)) |
ba99333a | 1930 | warning ("decimal constant is so large that it is unsigned"); |
c832a30e | 1931 | |
122026c0 RS |
1932 | if (spec_imag) |
1933 | { | |
1934 | if (TYPE_PRECISION (type) | |
1935 | <= TYPE_PRECISION (integer_type_node)) | |
1936 | yylval.ttype | |
77912476 RK |
1937 | = build_complex (NULL_TREE, integer_zero_node, |
1938 | convert (integer_type_node, | |
1939 | yylval.ttype)); | |
122026c0 RS |
1940 | else |
1941 | error ("complex integer constant is too wide for `complex int'"); | |
1942 | } | |
1943 | else if (flag_traditional && !int_fits_type_p (yylval.ttype, type)) | |
88dd95c1 RS |
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. */ | |
1947 | { | |
1948 | TREE_TYPE (yylval.ttype) = unsigned_type (type); | |
1949 | yylval.ttype = convert (type, yylval.ttype); | |
ba85b2e4 RK |
1950 | TREE_OVERFLOW (yylval.ttype) |
1951 | = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0; | |
88dd95c1 RS |
1952 | } |
1953 | else | |
1954 | TREE_TYPE (yylval.ttype) = type; | |
0e0fda0d GRK |
1955 | |
1956 | ||
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. */ | |
1959 | ||
1960 | if (! warn | |
1961 | && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE | |
1962 | && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype))) | |
ed534bdd | 1963 | pedwarn ("integer constant is larger than the maximum value for its type"); |
e8bbfc4e RK |
1964 | } |
1965 | ||
fbb18613 | 1966 | token_put_back (c); |
91b0989e RK |
1967 | *p = 0; |
1968 | ||
e9a780ec | 1969 | if (ISALNUM (c) || c == '.' || c == '_' || c == '$' |
91b0989e RK |
1970 | || (!flag_traditional && (c == '-' || c == '+') |
1971 | && (p[-1] == 'e' || p[-1] == 'E'))) | |
1972 | error ("missing white space after number `%s'", token_buffer); | |
1973 | ||
e8bbfc4e RK |
1974 | value = CONSTANT; break; |
1975 | } | |
1976 | ||
1977 | case '\'': | |
1978 | char_constant: | |
1979 | { | |
1980 | register int result = 0; | |
a2543283 | 1981 | register int num_chars = 0; |
56f48ce9 | 1982 | int chars_seen = 0; |
e8bbfc4e RK |
1983 | unsigned width = TYPE_PRECISION (char_type_node); |
1984 | int max_chars; | |
e8bbfc4e | 1985 | #ifdef MULTIBYTE_CHARS |
56f48ce9 | 1986 | int longest_char = local_mb_cur_max (); |
c5c76735 | 1987 | (void) local_mbtowc (NULL_PTR, NULL_PTR, 0); |
e8bbfc4e | 1988 | #endif |
56f48ce9 DB |
1989 | |
1990 | max_chars = TYPE_PRECISION (integer_type_node) / width; | |
1991 | if (wide_flag) | |
1992 | width = WCHAR_TYPE_SIZE; | |
e8bbfc4e RK |
1993 | |
1994 | while (1) | |
1995 | { | |
1996 | tryagain: | |
fbb18613 | 1997 | c = token_getch(); |
e8bbfc4e RK |
1998 | |
1999 | if (c == '\'' || c == EOF) | |
2000 | break; | |
2001 | ||
56f48ce9 | 2002 | ++chars_seen; |
e8bbfc4e RK |
2003 | if (c == '\\') |
2004 | { | |
b70af677 RS |
2005 | int ignore = 0; |
2006 | c = readescape (&ignore); | |
2007 | if (ignore) | |
e8bbfc4e RK |
2008 | goto tryagain; |
2009 | if (width < HOST_BITS_PER_INT | |
c84e2712 | 2010 | && (unsigned) c >= ((unsigned)1 << width)) |
e8bbfc4e | 2011 | pedwarn ("escape sequence out of range for character"); |
f6cb3487 | 2012 | #ifdef MAP_CHARACTER |
e9a780ec | 2013 | if (ISPRINT (c)) |
f6cb3487 RS |
2014 | c = MAP_CHARACTER (c); |
2015 | #endif | |
e8bbfc4e RK |
2016 | } |
2017 | else if (c == '\n') | |
2018 | { | |
2019 | if (pedantic) | |
2020 | pedwarn ("ANSI C forbids newline in character constant"); | |
2021 | lineno++; | |
2022 | } | |
b539a651 | 2023 | else |
56f48ce9 DB |
2024 | { |
2025 | #ifdef MULTIBYTE_CHARS | |
2026 | wchar_t wc; | |
2027 | int i; | |
2028 | int char_len = -1; | |
2029 | for (i = 1; i <= longest_char; ++i) | |
2030 | { | |
2031 | if (i > maxtoken - 4) | |
2032 | extend_token_buffer (token_buffer); | |
2033 | ||
2034 | token_buffer[i] = c; | |
2035 | char_len = local_mbtowc (& wc, | |
2036 | token_buffer + 1, | |
2037 | i); | |
2038 | if (char_len != -1) | |
2039 | break; | |
fbb18613 | 2040 | c = token_getch (); |
56f48ce9 DB |
2041 | } |
2042 | if (char_len > 1) | |
2043 | { | |
2044 | /* mbtowc sometimes needs an extra char before accepting */ | |
2045 | if (char_len < i) | |
fbb18613 | 2046 | token_put_back (c); |
56f48ce9 DB |
2047 | if (! wide_flag) |
2048 | { | |
2049 | /* Merge character into result; ignore excess chars. */ | |
2050 | for (i = 1; i <= char_len; ++i) | |
2051 | { | |
2052 | if (i > max_chars) | |
2053 | break; | |
2054 | if (width < HOST_BITS_PER_INT) | |
2055 | result = (result << width) | |
2056 | | (token_buffer[i] | |
2057 | & ((1 << width) - 1)); | |
2058 | else | |
2059 | result = token_buffer[i]; | |
2060 | } | |
2061 | num_chars += char_len; | |
2062 | goto tryagain; | |
2063 | } | |
2064 | c = wc; | |
2065 | } | |
2066 | else | |
2067 | { | |
2068 | if (char_len == -1) | |
505e0385 DB |
2069 | { |
2070 | warning ("Ignoring invalid multibyte character"); | |
2071 | /* Replace all but the first byte. */ | |
2072 | for (--i; i > 1; --i) | |
fbb18613 | 2073 | token_put_back (token_buffer[i]); |
505e0385 DB |
2074 | wc = token_buffer[1]; |
2075 | } | |
56f48ce9 | 2076 | #ifdef MAP_CHARACTER |
505e0385 DB |
2077 | c = MAP_CHARACTER (wc); |
2078 | #else | |
2079 | c = wc; | |
b539a651 | 2080 | #endif |
56f48ce9 DB |
2081 | } |
2082 | #else /* ! MULTIBYTE_CHARS */ | |
2083 | #ifdef MAP_CHARACTER | |
2084 | c = MAP_CHARACTER (c); | |
2085 | #endif | |
2086 | #endif /* ! MULTIBYTE_CHARS */ | |
2087 | } | |
e8bbfc4e | 2088 | |
56f48ce9 DB |
2089 | if (wide_flag) |
2090 | { | |
2091 | if (chars_seen == 1) /* only keep the first one */ | |
2092 | result = c; | |
2093 | goto tryagain; | |
2094 | } | |
e8bbfc4e RK |
2095 | |
2096 | /* Merge character into result; ignore excess chars. */ | |
56f48ce9 | 2097 | num_chars += (width / TYPE_PRECISION (char_type_node)); |
e8bbfc4e RK |
2098 | if (num_chars < max_chars + 1) |
2099 | { | |
2100 | if (width < HOST_BITS_PER_INT) | |
2101 | result = (result << width) | (c & ((1 << width) - 1)); | |
2102 | else | |
2103 | result = c; | |
2104 | } | |
2105 | } | |
2106 | ||
e8bbfc4e | 2107 | if (c != '\'') |
c5c76735 | 2108 | error ("malformed character constant"); |
56f48ce9 | 2109 | else if (chars_seen == 0) |
e8bbfc4e RK |
2110 | error ("empty character constant"); |
2111 | else if (num_chars > max_chars) | |
2112 | { | |
2113 | num_chars = max_chars; | |
2114 | error ("character constant too long"); | |
2115 | } | |
56f48ce9 | 2116 | else if (chars_seen != 1 && ! flag_traditional && warn_multichar) |
e8bbfc4e RK |
2117 | warning ("multi-character character constant"); |
2118 | ||
2119 | /* If char type is signed, sign-extend the constant. */ | |
2120 | if (! wide_flag) | |
2121 | { | |
2122 | int num_bits = num_chars * width; | |
5f0abdc3 RS |
2123 | if (num_bits == 0) |
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) | |
e8bbfc4e | 2128 | yylval.ttype |
76d31c63 | 2129 | = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0 |
8d9bfdc5 | 2130 | >> (HOST_BITS_PER_WIDE_INT - num_bits)), |
e8bbfc4e RK |
2131 | 0); |
2132 | else | |
2133 | yylval.ttype | |
76d31c63 | 2134 | = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0 |
8d9bfdc5 | 2135 | >> (HOST_BITS_PER_WIDE_INT - num_bits)), |
e8bbfc4e | 2136 | -1); |
f3acae4d | 2137 | TREE_TYPE (yylval.ttype) = integer_type_node; |
e8bbfc4e RK |
2138 | } |
2139 | else | |
2140 | { | |
e8bbfc4e | 2141 | yylval.ttype = build_int_2 (result, 0); |
f3acae4d | 2142 | TREE_TYPE (yylval.ttype) = wchar_type_node; |
e8bbfc4e RK |
2143 | } |
2144 | ||
e8bbfc4e RK |
2145 | value = CONSTANT; |
2146 | break; | |
2147 | } | |
2148 | ||
2149 | case '"': | |
2150 | string_constant: | |
2151 | { | |
56f48ce9 DB |
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 (); | |
c5c76735 | 2156 | (void) local_mbtowc (NULL_PTR, NULL_PTR, 0); |
56f48ce9 | 2157 | #endif |
fbb18613 | 2158 | c = token_getch (); |
e8bbfc4e RK |
2159 | p = token_buffer + 1; |
2160 | ||
fbb18613 | 2161 | while (c != '"' && c != EOF) |
e8bbfc4e | 2162 | { |
fbb18613 JM |
2163 | /* ignore_escape_flag is set for reading the filename in #line. */ |
2164 | if (!ignore_escape_flag && c == '\\') | |
e8bbfc4e | 2165 | { |
fad04099 | 2166 | int ignore = 0; |
b70af677 RS |
2167 | c = readescape (&ignore); |
2168 | if (ignore) | |
e8bbfc4e | 2169 | goto skipnewline; |
56f48ce9 | 2170 | if (width < HOST_BITS_PER_INT |
c84e2712 | 2171 | && (unsigned) c >= ((unsigned)1 << width)) |
e8bbfc4e RK |
2172 | pedwarn ("escape sequence out of range for character"); |
2173 | } | |
2174 | else if (c == '\n') | |
2175 | { | |
2176 | if (pedantic) | |
2177 | pedwarn ("ANSI C forbids newline in string constant"); | |
2178 | lineno++; | |
2179 | } | |
56f48ce9 DB |
2180 | else |
2181 | { | |
2182 | #ifdef MULTIBYTE_CHARS | |
2183 | wchar_t wc; | |
2184 | int i; | |
2185 | int char_len = -1; | |
2186 | for (i = 0; i < longest_char; ++i) | |
2187 | { | |
45e0984c | 2188 | if (p + i >= token_buffer + maxtoken) |
56f48ce9 DB |
2189 | p = extend_token_buffer (p); |
2190 | p[i] = c; | |
e8bbfc4e | 2191 | |
56f48ce9 DB |
2192 | char_len = local_mbtowc (& wc, p, i + 1); |
2193 | if (char_len != -1) | |
2194 | break; | |
fbb18613 | 2195 | c = token_getch (); |
56f48ce9 DB |
2196 | } |
2197 | if (char_len == -1) | |
56f48ce9 | 2198 | { |
505e0385 DB |
2199 | warning ("Ignoring invalid multibyte character"); |
2200 | /* Replace all except the first byte. */ | |
fbb18613 | 2201 | token_put_back (c); |
505e0385 | 2202 | for (--i; i > 0; --i) |
fbb18613 | 2203 | token_put_back (p[i]); |
505e0385 DB |
2204 | char_len = 1; |
2205 | } | |
2206 | /* mbtowc sometimes needs an extra char before accepting */ | |
2207 | if (char_len <= i) | |
fbb18613 | 2208 | token_put_back (c); |
505e0385 DB |
2209 | if (! wide_flag) |
2210 | { | |
2211 | p += (i + 1); | |
fbb18613 | 2212 | c = token_getch (); |
505e0385 | 2213 | continue; |
56f48ce9 | 2214 | } |
505e0385 | 2215 | c = wc; |
56f48ce9 DB |
2216 | #endif /* MULTIBYTE_CHARS */ |
2217 | } | |
2218 | ||
2219 | /* Add this single character into the buffer either as a wchar_t | |
2220 | or as a single byte. */ | |
2221 | if (wide_flag) | |
2222 | { | |
2223 | unsigned width = TYPE_PRECISION (char_type_node); | |
2224 | unsigned bytemask = (1 << width) - 1; | |
2225 | int byte; | |
2226 | ||
45e0984c | 2227 | if (p + WCHAR_BYTES > token_buffer + maxtoken) |
56f48ce9 DB |
2228 | p = extend_token_buffer (p); |
2229 | ||
2230 | for (byte = 0; byte < WCHAR_BYTES; ++byte) | |
2231 | { | |
2232 | int value; | |
c84e2712 | 2233 | if (byte >= (int) sizeof (c)) |
56f48ce9 DB |
2234 | value = 0; |
2235 | else | |
2236 | value = (c >> (byte * width)) & bytemask; | |
2237 | if (BYTES_BIG_ENDIAN) | |
2238 | p[WCHAR_BYTES - byte - 1] = value; | |
2239 | else | |
2240 | p[byte] = value; | |
2241 | } | |
2242 | p += WCHAR_BYTES; | |
2243 | } | |
2244 | else | |
2245 | { | |
45e0984c | 2246 | if (p >= token_buffer + maxtoken) |
56f48ce9 DB |
2247 | p = extend_token_buffer (p); |
2248 | *p++ = c; | |
2249 | } | |
e8bbfc4e RK |
2250 | |
2251 | skipnewline: | |
fbb18613 | 2252 | c = token_getch (); |
56f48ce9 DB |
2253 | } |
2254 | ||
2255 | /* Terminate the string value, either with a single byte zero | |
2256 | or with a wide zero. */ | |
2257 | if (wide_flag) | |
2258 | { | |
45e0984c | 2259 | if (p + WCHAR_BYTES > token_buffer + maxtoken) |
56f48ce9 DB |
2260 | p = extend_token_buffer (p); |
2261 | bzero (p, WCHAR_BYTES); | |
2262 | p += WCHAR_BYTES; | |
2263 | } | |
2264 | else | |
2265 | { | |
45e0984c | 2266 | if (p >= token_buffer + maxtoken) |
56f48ce9 DB |
2267 | p = extend_token_buffer (p); |
2268 | *p++ = 0; | |
e8bbfc4e | 2269 | } |
e8bbfc4e | 2270 | |
fbb18613 | 2271 | if (c == EOF) |
0468bc75 RK |
2272 | error ("Unterminated string constant"); |
2273 | ||
e8bbfc4e RK |
2274 | /* We have read the entire constant. |
2275 | Construct a STRING_CST for the result. */ | |
2276 | ||
2277 | if (wide_flag) | |
2278 | { | |
56f48ce9 DB |
2279 | yylval.ttype = build_string (p - (token_buffer + 1), |
2280 | token_buffer + 1); | |
e8bbfc4e | 2281 | TREE_TYPE (yylval.ttype) = wchar_array_type_node; |
e31c7eec TW |
2282 | value = STRING; |
2283 | } | |
2284 | else if (objc_flag) | |
2285 | { | |
e31c7eec | 2286 | /* Return an Objective-C @"..." constant string object. */ |
56f48ce9 | 2287 | yylval.ttype = build_objc_string (p - (token_buffer + 1), |
e31c7eec TW |
2288 | token_buffer + 1); |
2289 | TREE_TYPE (yylval.ttype) = char_array_type_node; | |
2290 | value = OBJC_STRING; | |
e8bbfc4e RK |
2291 | } |
2292 | else | |
2293 | { | |
56f48ce9 DB |
2294 | yylval.ttype = build_string (p - (token_buffer + 1), |
2295 | token_buffer + 1); | |
e8bbfc4e | 2296 | TREE_TYPE (yylval.ttype) = char_array_type_node; |
e31c7eec | 2297 | value = STRING; |
e8bbfc4e RK |
2298 | } |
2299 | ||
e31c7eec | 2300 | break; |
e8bbfc4e RK |
2301 | } |
2302 | ||
2303 | case '+': | |
2304 | case '-': | |
2305 | case '&': | |
2306 | case '|': | |
1f746936 | 2307 | case ':': |
e8bbfc4e RK |
2308 | case '<': |
2309 | case '>': | |
2310 | case '*': | |
2311 | case '/': | |
2312 | case '%': | |
2313 | case '^': | |
2314 | case '!': | |
2315 | case '=': | |
2316 | { | |
2317 | register int c1; | |
2318 | ||
2319 | combine: | |
2320 | ||
2321 | switch (c) | |
2322 | { | |
2323 | case '+': | |
2324 | yylval.code = PLUS_EXPR; break; | |
2325 | case '-': | |
2326 | yylval.code = MINUS_EXPR; break; | |
2327 | case '&': | |
2328 | yylval.code = BIT_AND_EXPR; break; | |
2329 | case '|': | |
2330 | yylval.code = BIT_IOR_EXPR; break; | |
2331 | case '*': | |
2332 | yylval.code = MULT_EXPR; break; | |
2333 | case '/': | |
2334 | yylval.code = TRUNC_DIV_EXPR; break; | |
2335 | case '%': | |
2336 | yylval.code = TRUNC_MOD_EXPR; break; | |
2337 | case '^': | |
2338 | yylval.code = BIT_XOR_EXPR; break; | |
2339 | case LSHIFT: | |
2340 | yylval.code = LSHIFT_EXPR; break; | |
2341 | case RSHIFT: | |
2342 | yylval.code = RSHIFT_EXPR; break; | |
2343 | case '<': | |
2344 | yylval.code = LT_EXPR; break; | |
2345 | case '>': | |
2346 | yylval.code = GT_EXPR; break; | |
2347 | } | |
2348 | ||
fbb18613 | 2349 | token_buffer[1] = c1 = token_getch(); |
e8bbfc4e RK |
2350 | token_buffer[2] = 0; |
2351 | ||
2352 | if (c1 == '=') | |
2353 | { | |
2354 | switch (c) | |
2355 | { | |
2356 | case '<': | |
2357 | value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done; | |
2358 | case '>': | |
2359 | value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done; | |
2360 | case '!': | |
2361 | value = EQCOMPARE; yylval.code = NE_EXPR; goto done; | |
2362 | case '=': | |
2363 | value = EQCOMPARE; yylval.code = EQ_EXPR; goto done; | |
2364 | } | |
2365 | value = ASSIGN; goto done; | |
2366 | } | |
2367 | else if (c == c1) | |
2368 | switch (c) | |
2369 | { | |
2370 | case '+': | |
2371 | value = PLUSPLUS; goto done; | |
2372 | case '-': | |
2373 | value = MINUSMINUS; goto done; | |
2374 | case '&': | |
2375 | value = ANDAND; goto done; | |
2376 | case '|': | |
2377 | value = OROR; goto done; | |
2378 | case '<': | |
2379 | c = LSHIFT; | |
2380 | goto combine; | |
2381 | case '>': | |
2382 | c = RSHIFT; | |
2383 | goto combine; | |
2384 | } | |
1f746936 RK |
2385 | else |
2386 | switch (c) | |
2387 | { | |
2388 | case '-': | |
2389 | if (c1 == '>') | |
2390 | { value = POINTSAT; goto done; } | |
2391 | break; | |
fbb18613 JM |
2392 | |
2393 | /* digraphs */ | |
1f746936 RK |
2394 | case ':': |
2395 | if (c1 == '>') | |
2396 | { value = ']'; goto done; } | |
2397 | break; | |
2398 | case '<': | |
2399 | if (c1 == '%') | |
e9a25f70 | 2400 | { value = '{'; indent_level++; goto done; } |
1f746936 RK |
2401 | if (c1 == ':') |
2402 | { value = '['; goto done; } | |
2403 | break; | |
2404 | case '%': | |
2405 | if (c1 == '>') | |
e9a25f70 | 2406 | { value = '}'; indent_level--; goto done; } |
1f746936 RK |
2407 | break; |
2408 | } | |
fbb18613 JM |
2409 | |
2410 | token_put_back (c1); | |
e8bbfc4e RK |
2411 | token_buffer[1] = 0; |
2412 | ||
2413 | if ((c == '<') || (c == '>')) | |
2414 | value = ARITHCOMPARE; | |
2415 | else value = c; | |
fbb18613 | 2416 | break; |
e8bbfc4e RK |
2417 | } |
2418 | ||
2419 | case 0: | |
2420 | /* Don't make yyparse think this is eof. */ | |
2421 | value = 1; | |
2422 | break; | |
2423 | ||
e9a25f70 JL |
2424 | case '{': |
2425 | indent_level++; | |
2426 | value = c; | |
2427 | break; | |
2428 | ||
2429 | case '}': | |
2430 | indent_level--; | |
2431 | value = c; | |
2432 | break; | |
2433 | ||
e8bbfc4e RK |
2434 | default: |
2435 | value = c; | |
2436 | } | |
2437 | ||
2438 | done: | |
2439 | /* yylloc.last_line = lineno; */ | |
2440 | ||
2441 | return value; | |
2442 | } | |
2443 | ||
d45cf215 | 2444 | /* Sets the value of the 'yydebug' variable to VALUE. |
e8bbfc4e RK |
2445 | This is a function so we don't have to have YYDEBUG defined |
2446 | in order to build the compiler. */ | |
2447 | ||
2448 | void | |
2449 | set_yydebug (value) | |
2450 | int value; | |
2451 | { | |
2452 | #if YYDEBUG != 0 | |
2453 | yydebug = value; | |
2454 | #else | |
2455 | warning ("YYDEBUG not defined."); | |
2456 | #endif | |
2457 | } |