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