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