]> gcc.gnu.org Git - gcc.git/blob - gcc/c-lex.c
c-lex.c (is_class_name): Delete declaration.
[gcc.git] / gcc / c-lex.c
1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 88, 89, 92, 94-97, 1998 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "config.h"
22 #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 int yydebug;
97
98 /* File used for outputting assembler code. */
99 extern FILE *asm_out_file;
100
101 #ifndef WCHAR_TYPE_SIZE
102 #ifdef INT_TYPE_SIZE
103 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
104 #else
105 #define WCHAR_TYPE_SIZE BITS_PER_WORD
106 #endif
107 #endif
108
109 /* Number of bytes in a wide character. */
110 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
111
112 static int maxtoken; /* Current nominal length of token buffer. */
113 char *token_buffer; /* Pointer to token buffer.
114 Actual allocated length is maxtoken + 2.
115 This is not static because objc-parse.y uses it. */
116
117 static int indent_level = 0; /* Number of { minus number of }. */
118
119 /* Nonzero if end-of-file has been seen on input. */
120 static int end_of_file;
121
122 #if !USE_CPPLIB
123 /* Buffered-back input character; faster than using ungetc. */
124 static int nextchar = -1;
125 #endif
126
127 #ifdef HANDLE_SYSV_PRAGMA
128 static int handle_sysv_pragma PROTO((int));
129 #endif /* HANDLE_SYSV_PRAGMA */
130 static int whitespace_cr PROTO((int));
131 static int skip_white_space PROTO((int));
132 static char *extend_token_buffer PROTO((char *));
133 static int readescape PROTO((int *));
134 int check_newline ();
135 \f
136 /* Do not insert generated code into the source, instead, include it.
137 This allows us to build gcc automatically even for targets that
138 need to add or modify the reserved keyword lists. */
139 #include "c-gperf.h"
140 \f
141 /* Return something to represent absolute declarators containing a *.
142 TARGET is the absolute declarator that the * contains.
143 TYPE_QUALS is a list of modifiers such as const or volatile
144 to apply to the pointer type, represented as identifiers.
145
146 We return an INDIRECT_REF whose "contents" are TARGET
147 and whose type is the modifier list. */
148
149 tree
150 make_pointer_declarator (type_quals, target)
151 tree type_quals, target;
152 {
153 return build1 (INDIRECT_REF, type_quals, target);
154 }
155 \f
156 void
157 forget_protocol_qualifiers ()
158 {
159 int i, n = sizeof wordlist / sizeof (struct resword);
160
161 for (i = 0; i < n; i++)
162 if ((int) wordlist[i].rid >= (int) RID_IN
163 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
164 wordlist[i].name = "";
165 }
166
167 void
168 remember_protocol_qualifiers ()
169 {
170 int i, n = sizeof wordlist / sizeof (struct resword);
171
172 for (i = 0; i < n; i++)
173 if (wordlist[i].rid == RID_IN)
174 wordlist[i].name = "in";
175 else if (wordlist[i].rid == RID_OUT)
176 wordlist[i].name = "out";
177 else if (wordlist[i].rid == RID_INOUT)
178 wordlist[i].name = "inout";
179 else if (wordlist[i].rid == RID_BYCOPY)
180 wordlist[i].name = "bycopy";
181 else if (wordlist[i].rid == RID_ONEWAY)
182 wordlist[i].name = "oneway";
183 }
184 \f
185 #if USE_CPPLIB
186 void
187 init_parse (filename)
188 char *filename;
189 {
190 init_lex ();
191 yy_cur = "\n";
192 yy_lim = yy_cur+1;
193
194 cpp_reader_init (&parse_in);
195 parse_in.data = &parse_options;
196 cpp_options_init (&parse_options);
197 cpp_handle_options (&parse_in, 0, NULL); /* FIXME */
198 parse_in.show_column = 1;
199 if (! cpp_start_read (&parse_in, filename))
200 abort ();
201 }
202
203 void
204 finish_parse ()
205 {
206 cpp_finish (&parse_in);
207 }
208 #endif
209
210 void
211 init_lex ()
212 {
213 /* Make identifier nodes long enough for the language-specific slots. */
214 set_identifier_size (sizeof (struct lang_identifier));
215
216 /* Start it at 0, because check_newline is called at the very beginning
217 and will increment it to 1. */
218 lineno = 0;
219
220 #ifdef MULTIBYTE_CHARS
221 /* Change to the native locale for multibyte conversions. */
222 setlocale (LC_CTYPE, "");
223 #endif
224
225 maxtoken = 40;
226 token_buffer = (char *) xmalloc (maxtoken + 2);
227
228 ridpointers[(int) RID_INT] = get_identifier ("int");
229 ridpointers[(int) RID_CHAR] = get_identifier ("char");
230 ridpointers[(int) RID_VOID] = get_identifier ("void");
231 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
232 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
233 ridpointers[(int) RID_SHORT] = get_identifier ("short");
234 ridpointers[(int) RID_LONG] = get_identifier ("long");
235 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
236 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
237 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
238 ridpointers[(int) RID_CONST] = get_identifier ("const");
239 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
240 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
241 ridpointers[(int) RID_STATIC] = get_identifier ("static");
242 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
243 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
244 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
245 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
246 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
247 ridpointers[(int) RID_ID] = get_identifier ("id");
248 ridpointers[(int) RID_IN] = get_identifier ("in");
249 ridpointers[(int) RID_OUT] = get_identifier ("out");
250 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
251 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
252 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
253 forget_protocol_qualifiers();
254
255 /* Some options inhibit certain reserved words.
256 Clear those words out of the hash table so they won't be recognized. */
257 #define UNSET_RESERVED_WORD(STRING) \
258 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
259 if (s) s->name = ""; } while (0)
260
261 if (! doing_objc_thang)
262 UNSET_RESERVED_WORD ("id");
263
264 if (flag_traditional)
265 {
266 UNSET_RESERVED_WORD ("const");
267 UNSET_RESERVED_WORD ("volatile");
268 UNSET_RESERVED_WORD ("typeof");
269 UNSET_RESERVED_WORD ("signed");
270 UNSET_RESERVED_WORD ("inline");
271 UNSET_RESERVED_WORD ("iterator");
272 UNSET_RESERVED_WORD ("complex");
273 }
274 if (flag_no_asm)
275 {
276 UNSET_RESERVED_WORD ("asm");
277 UNSET_RESERVED_WORD ("typeof");
278 UNSET_RESERVED_WORD ("inline");
279 UNSET_RESERVED_WORD ("iterator");
280 UNSET_RESERVED_WORD ("complex");
281 }
282 }
283
284 void
285 reinit_parse_for_function ()
286 {
287 }
288 \f
289 /* Function used when yydebug is set, to print a token in more detail. */
290
291 void
292 yyprint (file, yychar, yylval)
293 FILE *file;
294 int yychar;
295 YYSTYPE yylval;
296 {
297 tree t;
298 switch (yychar)
299 {
300 case IDENTIFIER:
301 case TYPENAME:
302 case OBJECTNAME:
303 t = yylval.ttype;
304 if (IDENTIFIER_POINTER (t))
305 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
306 break;
307
308 case CONSTANT:
309 t = yylval.ttype;
310 if (TREE_CODE (t) == INTEGER_CST)
311 fprintf (file,
312 #if HOST_BITS_PER_WIDE_INT == 64
313 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
314 " 0x%x%016x",
315 #else
316 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
317 " 0x%lx%016lx",
318 #else
319 " 0x%llx%016llx",
320 #endif
321 #endif
322 #else
323 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
324 " 0x%lx%08lx",
325 #else
326 " 0x%x%08x",
327 #endif
328 #endif
329 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
330 break;
331 }
332 }
333 \f
334 /* Iff C is a carriage return, warn about it - if appropriate -
335 and return nonzero. */
336 static int
337 whitespace_cr (c)
338 int c;
339 {
340 static int newline_warning = 0;
341
342 if (c == '\r')
343 {
344 /* ANSI C says the effects of a carriage return in a source file
345 are undefined. */
346 if (pedantic && !newline_warning)
347 {
348 warning ("carriage return in source file");
349 warning ("(we only warn about the first carriage return)");
350 newline_warning = 1;
351 }
352 return 1;
353 }
354 return 0;
355 }
356
357 /* If C is not whitespace, return C.
358 Otherwise skip whitespace and return first nonwhite char read. */
359
360 static int
361 skip_white_space (c)
362 register int c;
363 {
364 for (;;)
365 {
366 switch (c)
367 {
368 /* We don't recognize comments here, because
369 cpp output can include / and * consecutively as operators.
370 Also, there's no need, since cpp removes all comments. */
371
372 case '\n':
373 c = check_newline ();
374 break;
375
376 case ' ':
377 case '\t':
378 case '\f':
379 case '\v':
380 case '\b':
381 c = GETC();
382 break;
383
384 case '\r':
385 whitespace_cr (c);
386 c = GETC();
387 break;
388
389 case '\\':
390 c = GETC();
391 if (c == '\n')
392 lineno++;
393 else
394 error ("stray '\\' in program");
395 c = GETC();
396 break;
397
398 default:
399 return (c);
400 }
401 }
402 }
403
404 /* Skips all of the white space at the current location in the input file.
405 Must use and reset nextchar if it has the next character. */
406
407 void
408 position_after_white_space ()
409 {
410 register int c;
411
412 #if !USE_CPPLIB
413 if (nextchar != -1)
414 c = nextchar, nextchar = -1;
415 else
416 #endif
417 c = GETC();
418
419 UNGETC (skip_white_space (c));
420 }
421
422 /* Like skip_white_space, but don't advance beyond the end of line.
423 Moreover, we don't get passed a character to start with. */
424 static int
425 skip_white_space_on_line ()
426 {
427 register int c;
428
429 while (1)
430 {
431 c = GETC();
432 switch (c)
433 {
434 case '\n':
435 default:
436 break;
437
438 case ' ':
439 case '\t':
440 case '\f':
441 case '\v':
442 case '\b':
443 continue;
444
445 case '\r':
446 whitespace_cr (c);
447 continue;
448 }
449 break;
450 }
451 return c;
452 }
453
454 /* Make the token buffer longer, preserving the data in it.
455 P should point to just beyond the last valid character in the old buffer.
456 The value we return is a pointer to the new buffer
457 at a place corresponding to P. */
458
459 static char *
460 extend_token_buffer (p)
461 char *p;
462 {
463 int offset = p - token_buffer;
464
465 maxtoken = maxtoken * 2 + 10;
466 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
467
468 return token_buffer + offset;
469 }
470 \f
471 #if !USE_CPPLIB
472 #define GET_DIRECTIVE_LINE() get_directive_line (finput)
473 #else /* USE_CPPLIB */
474 /* Read the rest of a #-directive from input stream FINPUT.
475 In normal use, the directive name and the white space after it
476 have already been read, so they won't be included in the result.
477 We allow for the fact that the directive line may contain
478 a newline embedded within a character or string literal which forms
479 a part of the directive.
480
481 The value is a string in a reusable buffer. It remains valid
482 only until the next time this function is called. */
483
484 static char *
485 GET_DIRECTIVE_LINE ()
486 {
487 static char *directive_buffer = NULL;
488 static unsigned buffer_length = 0;
489 register char *p;
490 register char *buffer_limit;
491 register int looking_for = 0;
492 register int char_escaped = 0;
493
494 if (buffer_length == 0)
495 {
496 directive_buffer = (char *)xmalloc (128);
497 buffer_length = 128;
498 }
499
500 buffer_limit = &directive_buffer[buffer_length];
501
502 for (p = directive_buffer; ; )
503 {
504 int c;
505
506 /* Make buffer bigger if it is full. */
507 if (p >= buffer_limit)
508 {
509 register unsigned bytes_used = (p - directive_buffer);
510
511 buffer_length *= 2;
512 directive_buffer
513 = (char *)xrealloc (directive_buffer, buffer_length);
514 p = &directive_buffer[bytes_used];
515 buffer_limit = &directive_buffer[buffer_length];
516 }
517
518 c = GETC ();
519
520 /* Discard initial whitespace. */
521 if ((c == ' ' || c == '\t') && p == directive_buffer)
522 continue;
523
524 /* Detect the end of the directive. */
525 if (c == '\n' && looking_for == 0)
526 {
527 UNGETC (c);
528 c = '\0';
529 }
530
531 *p++ = c;
532
533 if (c == 0)
534 return directive_buffer;
535
536 /* Handle string and character constant syntax. */
537 if (looking_for)
538 {
539 if (looking_for == c && !char_escaped)
540 looking_for = 0; /* Found terminator... stop looking. */
541 }
542 else
543 if (c == '\'' || c == '"')
544 looking_for = c; /* Don't stop buffering until we see another
545 another one of these (or an EOF). */
546
547 /* Handle backslash. */
548 char_escaped = (c == '\\' && ! char_escaped);
549 }
550 }
551 #endif /* USE_CPPLIB */
552 \f
553 /* At the beginning of a line, increment the line number
554 and process any #-directive on this line.
555 If the line is a #-directive, read the entire line and return a newline.
556 Otherwise, return the line's first non-whitespace character. */
557
558 int
559 check_newline ()
560 {
561 register int c;
562 register int token;
563
564 lineno++;
565
566 /* Read first nonwhite char on the line. */
567
568 c = GETC();
569 while (c == ' ' || c == '\t')
570 c = GETC();
571
572 if (c != '#')
573 {
574 /* If not #, return it so caller will use it. */
575 return c;
576 }
577
578 /* Read first nonwhite char after the `#'. */
579
580 c = GETC();
581 while (c == ' ' || c == '\t')
582 c = GETC();
583
584 /* If a letter follows, then if the word here is `line', skip
585 it and ignore it; otherwise, ignore the line, with an error
586 if the word isn't `pragma', `ident', `define', or `undef'. */
587
588 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
589 {
590 if (c == 'p')
591 {
592 if (GETC() == 'r'
593 && GETC() == 'a'
594 && GETC() == 'g'
595 && GETC() == 'm'
596 && GETC() == 'a'
597 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'
598 || whitespace_cr (c) ))
599 {
600 while (c == ' ' || c == '\t' || whitespace_cr (c))
601 c = GETC ();
602 if (c == '\n')
603 return c;
604 #ifdef HANDLE_SYSV_PRAGMA
605 UNGETC (c);
606 token = yylex ();
607 if (token != IDENTIFIER)
608 goto skipline;
609 return handle_sysv_pragma (token);
610 #else /* !HANDLE_SYSV_PRAGMA */
611 #ifdef HANDLE_PRAGMA
612 #if !USE_CPPLIB
613 UNGETC (c);
614 token = yylex ();
615 if (token != IDENTIFIER)
616 goto skipline;
617 if (HANDLE_PRAGMA (finput, yylval.ttype))
618 {
619 c = GETC ();
620 return c;
621 }
622 #else
623 ??? do not know what to do ???;
624 #endif /* !USE_CPPLIB */
625 #endif /* HANDLE_PRAGMA */
626 #endif /* !HANDLE_SYSV_PRAGMA */
627 goto skipline;
628 }
629 }
630
631 else if (c == 'd')
632 {
633 if (GETC() == 'e'
634 && GETC() == 'f'
635 && GETC() == 'i'
636 && GETC() == 'n'
637 && GETC() == 'e'
638 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
639 {
640 if (c != '\n')
641 debug_define (lineno, GET_DIRECTIVE_LINE ());
642 goto skipline;
643 }
644 }
645 else if (c == 'u')
646 {
647 if (GETC() == 'n'
648 && GETC() == 'd'
649 && GETC() == 'e'
650 && GETC() == 'f'
651 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
652 {
653 if (c != '\n')
654 debug_undef (lineno, GET_DIRECTIVE_LINE ());
655 goto skipline;
656 }
657 }
658 else if (c == 'l')
659 {
660 if (GETC() == 'i'
661 && GETC() == 'n'
662 && GETC() == 'e'
663 && ((c = GETC()) == ' ' || c == '\t'))
664 goto linenum;
665 }
666 else if (c == 'i')
667 {
668 if (GETC() == 'd'
669 && GETC() == 'e'
670 && GETC() == 'n'
671 && GETC() == 't'
672 && ((c = GETC()) == ' ' || c == '\t'))
673 {
674 /* #ident. The pedantic warning is now in cccp.c. */
675
676 /* Here we have just seen `#ident '.
677 A string constant should follow. */
678
679 c = skip_white_space_on_line ();
680
681 /* If no argument, ignore the line. */
682 if (c == '\n')
683 return c;
684
685 UNGETC (c);
686 token = yylex ();
687 if (token != STRING
688 || TREE_CODE (yylval.ttype) != STRING_CST)
689 {
690 error ("invalid #ident");
691 goto skipline;
692 }
693
694 if (!flag_no_ident)
695 {
696 #ifdef ASM_OUTPUT_IDENT
697 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
698 #endif
699 }
700
701 /* Skip the rest of this line. */
702 goto skipline;
703 }
704 }
705
706 error ("undefined or invalid # directive");
707 goto skipline;
708 }
709
710 linenum:
711 /* Here we have either `#line' or `# <nonletter>'.
712 In either case, it should be a line number; a digit should follow. */
713
714 /* Can't use skip_white_space here, but must handle all whitespace
715 that is not '\n', lest we get a recursion for '\r' '\n' when
716 calling yylex. */
717 UNGETC (c);
718 c = skip_white_space_on_line ();
719
720 /* If the # is the only nonwhite char on the line,
721 just ignore it. Check the new newline. */
722 if (c == '\n')
723 return c;
724
725 /* Something follows the #; read a token. */
726
727 UNGETC (c);
728 token = yylex ();
729
730 if (token == CONSTANT
731 && TREE_CODE (yylval.ttype) == INTEGER_CST)
732 {
733 int old_lineno = lineno;
734 int used_up = 0;
735 /* subtract one, because it is the following line that
736 gets the specified number */
737
738 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
739
740 /* Is this the last nonwhite stuff on the line? */
741 c = skip_white_space_on_line ();
742 if (c == '\n')
743 {
744 /* No more: store the line number and check following line. */
745 lineno = l;
746 return c;
747 }
748 UNGETC (c);
749
750 /* More follows: it must be a string constant (filename). */
751
752 /* Read the string constant. */
753 token = yylex ();
754
755 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
756 {
757 error ("invalid #line");
758 goto skipline;
759 }
760
761 input_filename
762 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
763 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
764 lineno = l;
765
766 /* Each change of file name
767 reinitializes whether we are now in a system header. */
768 in_system_header = 0;
769
770 if (main_input_filename == 0)
771 main_input_filename = input_filename;
772
773 /* Is this the last nonwhite stuff on the line? */
774 c = skip_white_space_on_line ();
775 if (c == '\n')
776 {
777 /* Update the name in the top element of input_file_stack. */
778 if (input_file_stack)
779 input_file_stack->name = input_filename;
780
781 return c;
782 }
783 UNGETC (c);
784
785 token = yylex ();
786 used_up = 0;
787
788 /* `1' after file name means entering new file.
789 `2' after file name means just left a file. */
790
791 if (token == CONSTANT
792 && TREE_CODE (yylval.ttype) == INTEGER_CST)
793 {
794 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
795 {
796 /* Pushing to a new file. */
797 struct file_stack *p
798 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
799 input_file_stack->line = old_lineno;
800 p->next = input_file_stack;
801 p->name = input_filename;
802 p->indent_level = indent_level;
803 input_file_stack = p;
804 input_file_stack_tick++;
805 debug_start_source_file (input_filename);
806 used_up = 1;
807 }
808 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
809 {
810 /* Popping out of a file. */
811 if (input_file_stack->next)
812 {
813 struct file_stack *p = input_file_stack;
814 if (indent_level != p->indent_level)
815 {
816 warning_with_file_and_line
817 (p->name, old_lineno,
818 "This file contains more `%c's than `%c's.",
819 indent_level > p->indent_level ? '{' : '}',
820 indent_level > p->indent_level ? '}' : '{');
821 }
822 input_file_stack = p->next;
823 free (p);
824 input_file_stack_tick++;
825 debug_end_source_file (input_file_stack->line);
826 }
827 else
828 error ("#-lines for entering and leaving files don't match");
829
830 used_up = 1;
831 }
832 }
833
834 /* Now that we've pushed or popped the input stack,
835 update the name in the top element. */
836 if (input_file_stack)
837 input_file_stack->name = input_filename;
838
839 /* If we have handled a `1' or a `2',
840 see if there is another number to read. */
841 if (used_up)
842 {
843 /* Is this the last nonwhite stuff on the line? */
844 c = skip_white_space_on_line ();
845 if (c == '\n')
846 return c;
847 UNGETC (c);
848
849 token = yylex ();
850 used_up = 0;
851 }
852
853 /* `3' after file name means this is a system header file. */
854
855 if (token == CONSTANT
856 && TREE_CODE (yylval.ttype) == INTEGER_CST
857 && TREE_INT_CST_LOW (yylval.ttype) == 3)
858 in_system_header = 1, used_up = 1;
859
860 if (used_up)
861 {
862 /* Is this the last nonwhite stuff on the line? */
863 c = skip_white_space_on_line ();
864 if (c == '\n')
865 return c;
866 UNGETC (c);
867 }
868
869 warning ("unrecognized text at end of #line");
870 }
871 else
872 error ("invalid #-line");
873
874 /* skip the rest of this line. */
875 skipline:
876 #if !USE_CPPLIB
877 if (c != '\n' && c != EOF && nextchar >= 0)
878 c = nextchar, nextchar = -1;
879 #endif
880 while (c != '\n' && c != EOF)
881 c = GETC();
882 return c;
883 }
884 \f
885 #ifdef HANDLE_SYSV_PRAGMA
886
887 /* Handle a #pragma directive.
888 TOKEN is the token we read after `#pragma'. Processes the entire input
889 line and returns a character for the caller to reread: either \n or EOF. */
890
891 /* This function has to be in this file, in order to get at
892 the token types. */
893
894 static int
895 handle_sysv_pragma (token)
896 register int token;
897 {
898 register int c;
899
900 for (;;)
901 {
902 switch (token)
903 {
904 case IDENTIFIER:
905 case TYPENAME:
906 case STRING:
907 case CONSTANT:
908 handle_pragma_token (token_buffer, yylval.ttype);
909 break;
910 default:
911 handle_pragma_token (token_buffer, 0);
912 }
913 #if !USE_CPPLIB
914 if (nextchar >= 0)
915 c = nextchar, nextchar = -1;
916 else
917 #endif
918 c = GETC ();
919
920 while (c == ' ' || c == '\t')
921 c = GETC ();
922 if (c == '\n' || c == EOF)
923 {
924 handle_pragma_token (0, 0);
925 return c;
926 }
927 UNGETC (c);
928 token = yylex ();
929 }
930 }
931
932 #endif /* HANDLE_SYSV_PRAGMA */
933 \f
934 #define ENDFILE -1 /* token that represents end-of-file */
935
936 /* Read an escape sequence, returning its equivalent as a character,
937 or store 1 in *ignore_ptr if it is backslash-newline. */
938
939 static int
940 readescape (ignore_ptr)
941 int *ignore_ptr;
942 {
943 register int c = GETC();
944 register int code;
945 register unsigned count;
946 unsigned firstdig = 0;
947 int nonnull;
948
949 switch (c)
950 {
951 case 'x':
952 if (warn_traditional)
953 warning ("the meaning of `\\x' varies with -traditional");
954
955 if (flag_traditional)
956 return c;
957
958 code = 0;
959 count = 0;
960 nonnull = 0;
961 while (1)
962 {
963 c = GETC();
964 if (!(c >= 'a' && c <= 'f')
965 && !(c >= 'A' && c <= 'F')
966 && !(c >= '0' && c <= '9'))
967 {
968 UNGETC (c);
969 break;
970 }
971 code *= 16;
972 if (c >= 'a' && c <= 'f')
973 code += c - 'a' + 10;
974 if (c >= 'A' && c <= 'F')
975 code += c - 'A' + 10;
976 if (c >= '0' && c <= '9')
977 code += c - '0';
978 if (code != 0 || count != 0)
979 {
980 if (count == 0)
981 firstdig = code;
982 count++;
983 }
984 nonnull = 1;
985 }
986 if (! nonnull)
987 error ("\\x used with no following hex digits");
988 else if (count == 0)
989 /* Digits are all 0's. Ok. */
990 ;
991 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
992 || (count > 1
993 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
994 <= firstdig)))
995 pedwarn ("hex escape out of range");
996 return code;
997
998 case '0': case '1': case '2': case '3': case '4':
999 case '5': case '6': case '7':
1000 code = 0;
1001 count = 0;
1002 while ((c <= '7') && (c >= '0') && (count++ < 3))
1003 {
1004 code = (code * 8) + (c - '0');
1005 c = GETC();
1006 }
1007 UNGETC (c);
1008 return code;
1009
1010 case '\\': case '\'': case '"':
1011 return c;
1012
1013 case '\n':
1014 lineno++;
1015 *ignore_ptr = 1;
1016 return 0;
1017
1018 case 'n':
1019 return TARGET_NEWLINE;
1020
1021 case 't':
1022 return TARGET_TAB;
1023
1024 case 'r':
1025 return TARGET_CR;
1026
1027 case 'f':
1028 return TARGET_FF;
1029
1030 case 'b':
1031 return TARGET_BS;
1032
1033 case 'a':
1034 if (warn_traditional)
1035 warning ("the meaning of `\\a' varies with -traditional");
1036
1037 if (flag_traditional)
1038 return c;
1039 return TARGET_BELL;
1040
1041 case 'v':
1042 #if 0 /* Vertical tab is present in common usage compilers. */
1043 if (flag_traditional)
1044 return c;
1045 #endif
1046 return TARGET_VT;
1047
1048 case 'e':
1049 case 'E':
1050 if (pedantic)
1051 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1052 return 033;
1053
1054 case '?':
1055 return c;
1056
1057 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1058 case '(':
1059 case '{':
1060 case '[':
1061 /* `\%' is used to prevent SCCS from getting confused. */
1062 case '%':
1063 if (pedantic)
1064 pedwarn ("non-ANSI escape sequence `\\%c'", c);
1065 return c;
1066 }
1067 if (c >= 040 && c < 0177)
1068 pedwarn ("unknown escape sequence `\\%c'", c);
1069 else
1070 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1071 return c;
1072 }
1073 \f
1074 void
1075 yyerror (string)
1076 char *string;
1077 {
1078 char buf[200];
1079
1080 strcpy (buf, string);
1081
1082 /* We can't print string and character constants well
1083 because the token_buffer contains the result of processing escapes. */
1084 if (end_of_file)
1085 strcat (buf, " at end of input");
1086 else if (token_buffer[0] == 0)
1087 strcat (buf, " at null character");
1088 else if (token_buffer[0] == '"')
1089 strcat (buf, " before string constant");
1090 else if (token_buffer[0] == '\'')
1091 strcat (buf, " before character constant");
1092 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
1093 sprintf (buf + strlen (buf), " before character 0%o",
1094 (unsigned char) token_buffer[0]);
1095 else
1096 strcat (buf, " before `%s'");
1097
1098 error (buf, token_buffer);
1099 }
1100
1101 #if 0
1102
1103 struct try_type
1104 {
1105 tree *node_var;
1106 char unsigned_flag;
1107 char long_flag;
1108 char long_long_flag;
1109 };
1110
1111 struct try_type type_sequence[] =
1112 {
1113 { &integer_type_node, 0, 0, 0},
1114 { &unsigned_type_node, 1, 0, 0},
1115 { &long_integer_type_node, 0, 1, 0},
1116 { &long_unsigned_type_node, 1, 1, 0},
1117 { &long_long_integer_type_node, 0, 1, 1},
1118 { &long_long_unsigned_type_node, 1, 1, 1}
1119 };
1120 #endif /* 0 */
1121 \f
1122 int
1123 yylex ()
1124 {
1125 register int c;
1126 register char *p;
1127 register int value;
1128 int wide_flag = 0;
1129 int objc_flag = 0;
1130
1131 #if !USE_CPPLIB
1132 if (nextchar >= 0)
1133 c = nextchar, nextchar = -1;
1134 else
1135 #endif
1136 c = GETC();
1137
1138 /* Effectively do c = skip_white_space (c)
1139 but do it faster in the usual cases. */
1140 while (1)
1141 switch (c)
1142 {
1143 case ' ':
1144 case '\t':
1145 case '\f':
1146 case '\v':
1147 case '\b':
1148 c = GETC();
1149 break;
1150
1151 case '\r':
1152 /* Call skip_white_space so we can warn if appropriate. */
1153
1154 case '\n':
1155 case '/':
1156 case '\\':
1157 c = skip_white_space (c);
1158 default:
1159 goto found_nonwhite;
1160 }
1161 found_nonwhite:
1162
1163 token_buffer[0] = c;
1164 token_buffer[1] = 0;
1165
1166 /* yylloc.first_line = lineno; */
1167
1168 switch (c)
1169 {
1170 case EOF:
1171 end_of_file = 1;
1172 token_buffer[0] = 0;
1173 value = ENDFILE;
1174 break;
1175
1176 case 'L':
1177 /* Capital L may start a wide-string or wide-character constant. */
1178 {
1179 register int c = GETC();
1180 if (c == '\'')
1181 {
1182 wide_flag = 1;
1183 goto char_constant;
1184 }
1185 if (c == '"')
1186 {
1187 wide_flag = 1;
1188 goto string_constant;
1189 }
1190 UNGETC (c);
1191 }
1192 goto letter;
1193
1194 case '@':
1195 if (!doing_objc_thang)
1196 {
1197 value = c;
1198 break;
1199 }
1200 else
1201 {
1202 /* '@' may start a constant string object. */
1203 register int c = GETC ();
1204 if (c == '"')
1205 {
1206 objc_flag = 1;
1207 goto string_constant;
1208 }
1209 UNGETC (c);
1210 /* Fall through to treat '@' as the start of an identifier. */
1211 }
1212
1213 case 'A': case 'B': case 'C': case 'D': case 'E':
1214 case 'F': case 'G': case 'H': case 'I': case 'J':
1215 case 'K': case 'M': case 'N': case 'O':
1216 case 'P': case 'Q': case 'R': case 'S': case 'T':
1217 case 'U': case 'V': case 'W': case 'X': case 'Y':
1218 case 'Z':
1219 case 'a': case 'b': case 'c': case 'd': case 'e':
1220 case 'f': case 'g': case 'h': case 'i': case 'j':
1221 case 'k': case 'l': case 'm': case 'n': case 'o':
1222 case 'p': case 'q': case 'r': case 's': case 't':
1223 case 'u': case 'v': case 'w': case 'x': case 'y':
1224 case 'z':
1225 case '_':
1226 case '$':
1227 letter:
1228 p = token_buffer;
1229 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1230 {
1231 /* Make sure this char really belongs in an identifier. */
1232 if (c == '@' && ! doing_objc_thang)
1233 break;
1234 if (c == '$')
1235 {
1236 if (! dollars_in_ident)
1237 error ("`$' in identifier");
1238 else if (pedantic)
1239 pedwarn ("`$' in identifier");
1240 }
1241
1242 if (p >= token_buffer + maxtoken)
1243 p = extend_token_buffer (p);
1244
1245 *p++ = c;
1246 c = GETC();
1247 }
1248
1249 *p = 0;
1250 #if USE_CPPLIB
1251 UNGETC (c);
1252 #else
1253 nextchar = c;
1254 #endif
1255
1256 value = IDENTIFIER;
1257 yylval.itype = 0;
1258
1259 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1260
1261 {
1262 register struct resword *ptr;
1263
1264 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
1265 {
1266 if (ptr->rid)
1267 yylval.ttype = ridpointers[(int) ptr->rid];
1268 value = (int) ptr->token;
1269
1270 /* Only return OBJECTNAME if it is a typedef. */
1271 if (doing_objc_thang && value == OBJECTNAME)
1272 {
1273 lastiddecl = lookup_name(yylval.ttype);
1274
1275 if (lastiddecl == NULL_TREE
1276 || TREE_CODE (lastiddecl) != TYPE_DECL)
1277 value = IDENTIFIER;
1278 }
1279
1280 /* Even if we decided to recognize asm, still perhaps warn. */
1281 if (pedantic
1282 && (value == ASM_KEYWORD || value == TYPEOF
1283 || ptr->rid == RID_INLINE)
1284 && token_buffer[0] != '_')
1285 pedwarn ("ANSI does not permit the keyword `%s'",
1286 token_buffer);
1287 }
1288 }
1289
1290 /* If we did not find a keyword, look for an identifier
1291 (or a typename). */
1292
1293 if (value == IDENTIFIER)
1294 {
1295 if (token_buffer[0] == '@')
1296 error("invalid identifier `%s'", token_buffer);
1297
1298 yylval.ttype = get_identifier (token_buffer);
1299 lastiddecl = lookup_name (yylval.ttype);
1300
1301 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1302 value = TYPENAME;
1303 /* A user-invisible read-only initialized variable
1304 should be replaced by its value.
1305 We handle only strings since that's the only case used in C. */
1306 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1307 && DECL_IGNORED_P (lastiddecl)
1308 && TREE_READONLY (lastiddecl)
1309 && DECL_INITIAL (lastiddecl) != 0
1310 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1311 {
1312 tree stringval = DECL_INITIAL (lastiddecl);
1313
1314 /* Copy the string value so that we won't clobber anything
1315 if we put something in the TREE_CHAIN of this one. */
1316 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1317 TREE_STRING_POINTER (stringval));
1318 value = STRING;
1319 }
1320 else if (doing_objc_thang)
1321 {
1322 tree objc_interface_decl = is_class_name (yylval.ttype);
1323
1324 if (objc_interface_decl)
1325 {
1326 value = CLASSNAME;
1327 yylval.ttype = objc_interface_decl;
1328 }
1329 }
1330 }
1331
1332 break;
1333
1334 case '0': case '1':
1335 {
1336 int next_c;
1337 /* Check first for common special case: single-digit 0 or 1. */
1338
1339 next_c = GETC ();
1340 UNGETC (next_c); /* Always undo this lookahead. */
1341 if (!isalnum (next_c) && next_c != '.')
1342 {
1343 token_buffer[0] = (char)c, token_buffer[1] = '\0';
1344 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1345 value = CONSTANT;
1346 break;
1347 }
1348 /*FALLTHRU*/
1349 }
1350 case '2': case '3': case '4':
1351 case '5': case '6': case '7': case '8': case '9':
1352 case '.':
1353 {
1354 int base = 10;
1355 int count = 0;
1356 int largest_digit = 0;
1357 int numdigits = 0;
1358 /* for multi-precision arithmetic,
1359 we actually store only HOST_BITS_PER_CHAR bits in each part.
1360 The number of parts is chosen so as to be sufficient to hold
1361 the enough bits to fit into the two HOST_WIDE_INTs that contain
1362 the integer value (this is always at least as many bits as are
1363 in a target `long long' value, but may be wider). */
1364 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1365 int parts[TOTAL_PARTS];
1366 int overflow = 0;
1367
1368 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1369 = NOT_FLOAT;
1370
1371 for (count = 0; count < TOTAL_PARTS; count++)
1372 parts[count] = 0;
1373
1374 p = token_buffer;
1375 *p++ = c;
1376
1377 if (c == '0')
1378 {
1379 *p++ = (c = GETC());
1380 if ((c == 'x') || (c == 'X'))
1381 {
1382 base = 16;
1383 *p++ = (c = GETC());
1384 }
1385 /* Leading 0 forces octal unless the 0 is the only digit. */
1386 else if (c >= '0' && c <= '9')
1387 {
1388 base = 8;
1389 numdigits++;
1390 }
1391 else
1392 numdigits++;
1393 }
1394
1395 /* Read all the digits-and-decimal-points. */
1396
1397 while (c == '.'
1398 || (isalnum (c) && c != 'l' && c != 'L'
1399 && c != 'u' && c != 'U'
1400 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1401 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1402 {
1403 if (c == '.')
1404 {
1405 if (base == 16)
1406 error ("floating constant may not be in radix 16");
1407 if (floatflag == TOO_MANY_POINTS)
1408 /* We have already emitted an error. Don't need another. */
1409 ;
1410 else if (floatflag == AFTER_POINT)
1411 {
1412 error ("malformed floating constant");
1413 floatflag = TOO_MANY_POINTS;
1414 /* Avoid another error from atof by forcing all characters
1415 from here on to be ignored. */
1416 p[-1] = '\0';
1417 }
1418 else
1419 floatflag = AFTER_POINT;
1420
1421 base = 10;
1422 *p++ = c = GETC();
1423 /* Accept '.' as the start of a floating-point number
1424 only when it is followed by a digit.
1425 Otherwise, unread the following non-digit
1426 and use the '.' as a structural token. */
1427 if (p == token_buffer + 2 && !isdigit (c))
1428 {
1429 if (c == '.')
1430 {
1431 c = GETC();
1432 if (c == '.')
1433 {
1434 *p++ = c;
1435 *p = 0;
1436 return ELLIPSIS;
1437 }
1438 error ("parse error at `..'");
1439 }
1440 UNGETC (c);
1441 token_buffer[1] = 0;
1442 value = '.';
1443 goto done;
1444 }
1445 }
1446 else
1447 {
1448 /* It is not a decimal point.
1449 It should be a digit (perhaps a hex digit). */
1450
1451 if (isdigit (c))
1452 {
1453 c = c - '0';
1454 }
1455 else if (base <= 10)
1456 {
1457 if (c == 'e' || c == 'E')
1458 {
1459 base = 10;
1460 floatflag = AFTER_POINT;
1461 break; /* start of exponent */
1462 }
1463 error ("nondigits in number and not hexadecimal");
1464 c = 0;
1465 }
1466 else if (c >= 'a')
1467 {
1468 c = c - 'a' + 10;
1469 }
1470 else
1471 {
1472 c = c - 'A' + 10;
1473 }
1474 if (c >= largest_digit)
1475 largest_digit = c;
1476 numdigits++;
1477
1478 for (count = 0; count < TOTAL_PARTS; count++)
1479 {
1480 parts[count] *= base;
1481 if (count)
1482 {
1483 parts[count]
1484 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1485 parts[count-1]
1486 &= (1 << HOST_BITS_PER_CHAR) - 1;
1487 }
1488 else
1489 parts[0] += c;
1490 }
1491
1492 /* If the extra highest-order part ever gets anything in it,
1493 the number is certainly too big. */
1494 if (parts[TOTAL_PARTS - 1] != 0)
1495 overflow = 1;
1496
1497 if (p >= token_buffer + maxtoken - 3)
1498 p = extend_token_buffer (p);
1499 *p++ = (c = GETC());
1500 }
1501 }
1502
1503 if (numdigits == 0)
1504 error ("numeric constant with no digits");
1505
1506 if (largest_digit >= base)
1507 error ("numeric constant contains digits beyond the radix");
1508
1509 /* Remove terminating char from the token buffer and delimit the string */
1510 *--p = 0;
1511
1512 if (floatflag != NOT_FLOAT)
1513 {
1514 tree type = double_type_node;
1515 int imag = 0;
1516 int conversion_errno = 0;
1517 REAL_VALUE_TYPE value;
1518 jmp_buf handler;
1519
1520 /* Read explicit exponent if any, and put it in tokenbuf. */
1521
1522 if ((c == 'e') || (c == 'E'))
1523 {
1524 if (p >= token_buffer + maxtoken - 3)
1525 p = extend_token_buffer (p);
1526 *p++ = c;
1527 c = GETC();
1528 if ((c == '+') || (c == '-'))
1529 {
1530 *p++ = c;
1531 c = GETC();
1532 }
1533 if (! isdigit (c))
1534 error ("floating constant exponent has no digits");
1535 while (isdigit (c))
1536 {
1537 if (p >= token_buffer + maxtoken - 3)
1538 p = extend_token_buffer (p);
1539 *p++ = c;
1540 c = GETC();
1541 }
1542 }
1543
1544 *p = 0;
1545
1546 /* Convert string to a double, checking for overflow. */
1547 if (setjmp (handler))
1548 {
1549 error ("floating constant out of range");
1550 value = dconst0;
1551 }
1552 else
1553 {
1554 int fflag = 0, lflag = 0;
1555 /* Copy token_buffer now, while it has just the number
1556 and not the suffixes; once we add `f' or `i',
1557 REAL_VALUE_ATOF may not work any more. */
1558 char *copy = (char *) alloca (p - token_buffer + 1);
1559 bcopy (token_buffer, copy, p - token_buffer + 1);
1560
1561 set_float_handler (handler);
1562
1563 while (1)
1564 {
1565 int lose = 0;
1566
1567 /* Read the suffixes to choose a data type. */
1568 switch (c)
1569 {
1570 case 'f': case 'F':
1571 if (fflag)
1572 error ("more than one `f' in numeric constant");
1573 fflag = 1;
1574 break;
1575
1576 case 'l': case 'L':
1577 if (lflag)
1578 error ("more than one `l' in numeric constant");
1579 lflag = 1;
1580 break;
1581
1582 case 'i': case 'I':
1583 if (imag)
1584 error ("more than one `i' or `j' in numeric constant");
1585 else if (pedantic)
1586 pedwarn ("ANSI C forbids imaginary numeric constants");
1587 imag = 1;
1588 break;
1589
1590 default:
1591 lose = 1;
1592 }
1593
1594 if (lose)
1595 break;
1596
1597 if (p >= token_buffer + maxtoken - 3)
1598 p = extend_token_buffer (p);
1599 *p++ = c;
1600 *p = 0;
1601 c = GETC();
1602 }
1603
1604 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1605 tells the desired precision of the binary result
1606 of decimal-to-binary conversion. */
1607
1608 if (fflag)
1609 {
1610 if (lflag)
1611 error ("both `f' and `l' in floating constant");
1612
1613 type = float_type_node;
1614 errno = 0;
1615 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1616 conversion_errno = errno;
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 errno = 0;
1627 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1628 conversion_errno = errno;
1629 if (REAL_VALUE_ISINF (value) && pedantic)
1630 warning ("floating point number exceeds range of `long double'");
1631 }
1632 else
1633 {
1634 errno = 0;
1635 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1636 conversion_errno = errno;
1637 if (REAL_VALUE_ISINF (value) && pedantic)
1638 warning ("floating point number exceeds range of `double'");
1639 }
1640
1641 set_float_handler (NULL_PTR);
1642 }
1643 #ifdef ERANGE
1644 /* ERANGE is also reported for underflow,
1645 so test the value to distinguish overflow from that. */
1646 if (conversion_errno == ERANGE && !flag_traditional && pedantic
1647 && (REAL_VALUES_LESS (dconst1, value)
1648 || REAL_VALUES_LESS (value, dconstm1)))
1649 warning ("floating point number exceeds range of `double'");
1650 #endif
1651
1652 /* If the result is not a number, assume it must have been
1653 due to some error message above, so silently convert
1654 it to a zero. */
1655 if (REAL_VALUE_ISNAN (value))
1656 value = dconst0;
1657
1658 /* Create a node with determined type and value. */
1659 if (imag)
1660 yylval.ttype = build_complex (NULL_TREE,
1661 convert (type, integer_zero_node),
1662 build_real (type, value));
1663 else
1664 yylval.ttype = build_real (type, value);
1665 }
1666 else
1667 {
1668 tree traditional_type, ansi_type, type;
1669 HOST_WIDE_INT high, low;
1670 int spec_unsigned = 0;
1671 int spec_long = 0;
1672 int spec_long_long = 0;
1673 int spec_imag = 0;
1674 int bytes, warn, i;
1675
1676 traditional_type = ansi_type = type = NULL_TREE;
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.139661 seconds and 6 git commands to generate.