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