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