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