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