Call fatal_insn_not_found instead of abort
[official-gcc.git] / gcc / c-lex.c
blobc33ade528225c362fe293e8b225299bc0930004d
1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 88, 89, 92, 94-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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.
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.
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. */
21 #include "config.h"
22 #include "system.h"
23 #include <setjmp.h>
25 #include "rtl.h"
26 #include "tree.h"
27 #include "input.h"
28 #include "output.h"
29 #include "c-lex.h"
30 #include "c-tree.h"
31 #include "flags.h"
32 #include "c-parse.h"
33 #include "c-pragma.h"
34 #include "toplev.h"
36 /* MULTIBYTE_CHARS support only works for native compilers.
37 ??? Ideally what we want is to model widechar support after
38 the current floating point support. */
39 #ifdef CROSS_COMPILE
40 #undef MULTIBYTE_CHARS
41 #endif
43 #ifdef MULTIBYTE_CHARS
44 #include <locale.h>
45 #endif
47 #if USE_CPPLIB
48 #include "cpplib.h"
49 extern cpp_reader parse_in;
50 extern cpp_options parse_options;
51 #else
52 /* Stream for reading from the input file. */
53 FILE *finput;
54 #endif
56 extern void yyprint PROTO((FILE *, int, YYSTYPE));
58 /* The elements of `ridpointers' are identifier nodes
59 for the reserved type names and storage classes.
60 It is indexed by a RID_... value. */
61 tree ridpointers[(int) RID_MAX];
63 /* Cause the `yydebug' variable to be defined. */
64 #define YYDEBUG 1
66 #if USE_CPPLIB
67 extern unsigned char *yy_cur, *yy_lim;
69 extern int yy_get_token ();
71 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
72 #define UNGETC(c) ((c), yy_cur--)
73 #else
74 #define GETC() getc (finput)
75 #define UNGETC(c) ungetc (c, finput)
76 #endif
78 /* the declaration found for the last IDENTIFIER token read in.
79 yylex must look this up to detect typedefs, which get token type TYPENAME,
80 so it is left around in case the identifier is not a typedef but is
81 used in a context which makes it a reference to a variable. */
82 tree lastiddecl;
84 /* Nonzero enables objc features. */
86 int doing_objc_thang;
88 extern int yydebug;
90 /* File used for outputting assembler code. */
91 extern FILE *asm_out_file;
93 #ifndef WCHAR_TYPE_SIZE
94 #ifdef INT_TYPE_SIZE
95 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
96 #else
97 #define WCHAR_TYPE_SIZE BITS_PER_WORD
98 #endif
99 #endif
101 /* Number of bytes in a wide character. */
102 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
104 static int maxtoken; /* Current nominal length of token buffer. */
105 char *token_buffer; /* Pointer to token buffer.
106 Actual allocated length is maxtoken + 2.
107 This is not static because objc-parse.y uses it. */
109 static int indent_level = 0; /* Number of { minus number of }. */
111 /* Nonzero if end-of-file has been seen on input. */
112 static int end_of_file;
114 #if !USE_CPPLIB
115 /* Buffered-back input character; faster than using ungetc. */
116 static int nextchar = -1;
117 #endif
119 #ifdef HANDLE_SYSV_PRAGMA
120 static int handle_sysv_pragma PROTO((int));
121 #endif /* HANDLE_SYSV_PRAGMA */
122 static int whitespace_cr PROTO((int));
123 static int skip_white_space PROTO((int));
124 static int skip_white_space_on_line PROTO((void));
125 static char *extend_token_buffer PROTO((char *));
126 static int readescape PROTO((int *));
128 /* Do not insert generated code into the source, instead, include it.
129 This allows us to build gcc automatically even for targets that
130 need to add or modify the reserved keyword lists. */
131 #include "c-gperf.h"
133 /* Return something to represent absolute declarators containing a *.
134 TARGET is the absolute declarator that the * contains.
135 TYPE_QUALS is a list of modifiers such as const or volatile
136 to apply to the pointer type, represented as identifiers.
138 We return an INDIRECT_REF whose "contents" are TARGET
139 and whose type is the modifier list. */
141 tree
142 make_pointer_declarator (type_quals, target)
143 tree type_quals, target;
145 return build1 (INDIRECT_REF, type_quals, target);
148 void
149 forget_protocol_qualifiers ()
151 int i, n = sizeof wordlist / sizeof (struct resword);
153 for (i = 0; i < n; i++)
154 if ((int) wordlist[i].rid >= (int) RID_IN
155 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
156 wordlist[i].name = "";
159 void
160 remember_protocol_qualifiers ()
162 int i, n = sizeof wordlist / sizeof (struct resword);
164 for (i = 0; i < n; i++)
165 if (wordlist[i].rid == RID_IN)
166 wordlist[i].name = "in";
167 else if (wordlist[i].rid == RID_OUT)
168 wordlist[i].name = "out";
169 else if (wordlist[i].rid == RID_INOUT)
170 wordlist[i].name = "inout";
171 else if (wordlist[i].rid == RID_BYCOPY)
172 wordlist[i].name = "bycopy";
173 else if (wordlist[i].rid == RID_ONEWAY)
174 wordlist[i].name = "oneway";
177 char *
178 init_parse (filename)
179 char *filename;
181 #if !USE_CPPLIB
182 /* Open input file. */
183 if (filename == 0 || !strcmp (filename, "-"))
185 finput = stdin;
186 filename = "stdin";
188 else
189 finput = fopen (filename, "r");
190 if (finput == 0)
191 pfatal_with_name (filename);
193 #ifdef IO_BUFFER_SIZE
194 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
195 #endif
196 #endif /* !USE_CPPLIB */
198 init_lex ();
200 #if USE_CPPLIB
201 yy_cur = "\n";
202 yy_lim = yy_cur+1;
204 parse_in.show_column = 1;
205 if (! cpp_start_read (&parse_in, filename))
206 abort ();
207 #endif
209 return filename;
212 void
213 finish_parse ()
215 #if USE_CPPLIB
216 cpp_finish (&parse_in);
217 #else
218 fclose (finput);
219 #endif
222 void
223 init_lex ()
225 /* Make identifier nodes long enough for the language-specific slots. */
226 set_identifier_size (sizeof (struct lang_identifier));
228 /* Start it at 0, because check_newline is called at the very beginning
229 and will increment it to 1. */
230 lineno = 0;
232 #ifdef MULTIBYTE_CHARS
233 /* Change to the native locale for multibyte conversions. */
234 setlocale (LC_CTYPE, "");
235 #endif
237 maxtoken = 40;
238 token_buffer = (char *) xmalloc (maxtoken + 2);
240 ridpointers[(int) RID_INT] = get_identifier ("int");
241 ridpointers[(int) RID_CHAR] = get_identifier ("char");
242 ridpointers[(int) RID_VOID] = get_identifier ("void");
243 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
244 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
245 ridpointers[(int) RID_SHORT] = get_identifier ("short");
246 ridpointers[(int) RID_LONG] = get_identifier ("long");
247 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
248 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
249 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
250 ridpointers[(int) RID_CONST] = get_identifier ("const");
251 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
252 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
253 ridpointers[(int) RID_STATIC] = get_identifier ("static");
254 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
255 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
256 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
257 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
258 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
259 ridpointers[(int) RID_ID] = get_identifier ("id");
260 ridpointers[(int) RID_IN] = get_identifier ("in");
261 ridpointers[(int) RID_OUT] = get_identifier ("out");
262 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
263 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
264 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
265 forget_protocol_qualifiers();
267 /* Some options inhibit certain reserved words.
268 Clear those words out of the hash table so they won't be recognized. */
269 #define UNSET_RESERVED_WORD(STRING) \
270 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
271 if (s) s->name = ""; } while (0)
273 if (! doing_objc_thang)
274 UNSET_RESERVED_WORD ("id");
276 if (flag_traditional)
278 UNSET_RESERVED_WORD ("const");
279 UNSET_RESERVED_WORD ("volatile");
280 UNSET_RESERVED_WORD ("typeof");
281 UNSET_RESERVED_WORD ("signed");
282 UNSET_RESERVED_WORD ("inline");
283 UNSET_RESERVED_WORD ("iterator");
284 UNSET_RESERVED_WORD ("complex");
286 if (flag_no_asm)
288 UNSET_RESERVED_WORD ("asm");
289 UNSET_RESERVED_WORD ("typeof");
290 UNSET_RESERVED_WORD ("inline");
291 UNSET_RESERVED_WORD ("iterator");
292 UNSET_RESERVED_WORD ("complex");
296 void
297 reinit_parse_for_function ()
301 /* Function used when yydebug is set, to print a token in more detail. */
303 void
304 yyprint (file, yychar, yylval)
305 FILE *file;
306 int yychar;
307 YYSTYPE yylval;
309 tree t;
310 switch (yychar)
312 case IDENTIFIER:
313 case TYPENAME:
314 case OBJECTNAME:
315 t = yylval.ttype;
316 if (IDENTIFIER_POINTER (t))
317 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
318 break;
320 case CONSTANT:
321 t = yylval.ttype;
322 if (TREE_CODE (t) == INTEGER_CST)
323 fprintf (file,
324 #if HOST_BITS_PER_WIDE_INT == 64
325 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
326 " 0x%x%016x",
327 #else
328 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
329 " 0x%lx%016lx",
330 #else
331 " 0x%llx%016llx",
332 #endif
333 #endif
334 #else
335 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
336 " 0x%lx%08lx",
337 #else
338 " 0x%x%08x",
339 #endif
340 #endif
341 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
342 break;
346 /* Iff C is a carriage return, warn about it - if appropriate -
347 and return nonzero. */
348 static int
349 whitespace_cr (c)
350 int c;
352 static int newline_warning = 0;
354 if (c == '\r')
356 /* ANSI C says the effects of a carriage return in a source file
357 are undefined. */
358 if (pedantic && !newline_warning)
360 warning ("carriage return in source file");
361 warning ("(we only warn about the first carriage return)");
362 newline_warning = 1;
364 return 1;
366 return 0;
369 /* If C is not whitespace, return C.
370 Otherwise skip whitespace and return first nonwhite char read. */
372 static int
373 skip_white_space (c)
374 register int c;
376 for (;;)
378 switch (c)
380 /* We don't recognize comments here, because
381 cpp output can include / and * consecutively as operators.
382 Also, there's no need, since cpp removes all comments. */
384 case '\n':
385 c = check_newline ();
386 break;
388 case ' ':
389 case '\t':
390 case '\f':
391 case '\v':
392 case '\b':
393 c = GETC();
394 break;
396 case '\r':
397 whitespace_cr (c);
398 c = GETC();
399 break;
401 case '\\':
402 c = GETC();
403 if (c == '\n')
404 lineno++;
405 else
406 error ("stray '\\' in program");
407 c = GETC();
408 break;
410 default:
411 return (c);
416 /* Skips all of the white space at the current location in the input file.
417 Must use and reset nextchar if it has the next character. */
419 void
420 position_after_white_space ()
422 register int c;
424 #if !USE_CPPLIB
425 if (nextchar != -1)
426 c = nextchar, nextchar = -1;
427 else
428 #endif
429 c = GETC();
431 UNGETC (skip_white_space (c));
434 /* Like skip_white_space, but don't advance beyond the end of line.
435 Moreover, we don't get passed a character to start with. */
436 static int
437 skip_white_space_on_line ()
439 register int c;
441 while (1)
443 c = GETC();
444 switch (c)
446 case '\n':
447 default:
448 break;
450 case ' ':
451 case '\t':
452 case '\f':
453 case '\v':
454 case '\b':
455 continue;
457 case '\r':
458 whitespace_cr (c);
459 continue;
461 break;
463 return c;
466 /* Make the token buffer longer, preserving the data in it.
467 P should point to just beyond the last valid character in the old buffer.
468 The value we return is a pointer to the new buffer
469 at a place corresponding to P. */
471 static char *
472 extend_token_buffer (p)
473 char *p;
475 int offset = p - token_buffer;
477 maxtoken = maxtoken * 2 + 10;
478 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
480 return token_buffer + offset;
483 /* At the beginning of a line, increment the line number
484 and process any #-directive on this line.
485 If the line is a #-directive, read the entire line and return a newline.
486 Otherwise, return the line's first non-whitespace character. */
489 check_newline ()
491 register int c;
492 register int token;
494 lineno++;
496 /* Read first nonwhite char on the line. */
498 c = GETC();
499 while (c == ' ' || c == '\t')
500 c = GETC();
502 if (c != '#')
504 /* If not #, return it so caller will use it. */
505 return c;
508 /* Read first nonwhite char after the `#'. */
510 c = GETC();
511 while (c == ' ' || c == '\t')
512 c = GETC();
514 /* If a letter follows, then if the word here is `line', skip
515 it and ignore it; otherwise, ignore the line, with an error
516 if the word isn't `pragma', `ident', `define', or `undef'. */
518 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
520 if (c == 'p')
522 if (GETC() == 'r'
523 && GETC() == 'a'
524 && GETC() == 'g'
525 && GETC() == 'm'
526 && GETC() == 'a'
527 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'
528 || whitespace_cr (c) ))
530 while (c == ' ' || c == '\t' || whitespace_cr (c))
531 c = GETC ();
532 if (c == '\n')
533 return c;
534 #ifdef HANDLE_SYSV_PRAGMA
535 UNGETC (c);
536 token = yylex ();
537 if (token != IDENTIFIER)
538 goto skipline;
539 return handle_sysv_pragma (token);
540 #else /* !HANDLE_SYSV_PRAGMA */
541 #ifdef HANDLE_PRAGMA
542 #if !USE_CPPLIB
543 UNGETC (c);
544 token = yylex ();
545 if (token != IDENTIFIER)
546 goto skipline;
547 if (nextchar >= 0)
548 c = nextchar, nextchar = -1;
549 else
550 c = GETC ();
551 ungetc (c, finput);
552 if (HANDLE_PRAGMA (finput, yylval.ttype))
554 c = GETC ();
555 return c;
557 #else
558 ??? do not know what to do ???;
559 #endif /* !USE_CPPLIB */
560 #endif /* HANDLE_PRAGMA */
561 #endif /* !HANDLE_SYSV_PRAGMA */
562 goto skipline;
566 else if (c == 'd')
568 if (GETC() == 'e'
569 && GETC() == 'f'
570 && GETC() == 'i'
571 && GETC() == 'n'
572 && GETC() == 'e'
573 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
575 if (c != '\n')
576 debug_define (lineno, GET_DIRECTIVE_LINE ());
577 goto skipline;
580 else if (c == 'u')
582 if (GETC() == 'n'
583 && GETC() == 'd'
584 && GETC() == 'e'
585 && GETC() == 'f'
586 && ((c = GETC()) == ' ' || c == '\t' || c == '\n'))
588 if (c != '\n')
589 debug_undef (lineno, GET_DIRECTIVE_LINE ());
590 goto skipline;
593 else if (c == 'l')
595 if (GETC() == 'i'
596 && GETC() == 'n'
597 && GETC() == 'e'
598 && ((c = GETC()) == ' ' || c == '\t'))
599 goto linenum;
601 else if (c == 'i')
603 if (GETC() == 'd'
604 && GETC() == 'e'
605 && GETC() == 'n'
606 && GETC() == 't'
607 && ((c = GETC()) == ' ' || c == '\t'))
609 /* #ident. The pedantic warning is now in cccp.c. */
611 /* Here we have just seen `#ident '.
612 A string constant should follow. */
614 c = skip_white_space_on_line ();
616 /* If no argument, ignore the line. */
617 if (c == '\n')
618 return c;
620 UNGETC (c);
621 token = yylex ();
622 if (token != STRING
623 || TREE_CODE (yylval.ttype) != STRING_CST)
625 error ("invalid #ident");
626 goto skipline;
629 if (!flag_no_ident)
631 #ifdef ASM_OUTPUT_IDENT
632 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
633 #endif
636 /* Skip the rest of this line. */
637 goto skipline;
641 error ("undefined or invalid # directive");
642 goto skipline;
645 linenum:
646 /* Here we have either `#line' or `# <nonletter>'.
647 In either case, it should be a line number; a digit should follow. */
649 /* Can't use skip_white_space here, but must handle all whitespace
650 that is not '\n', lest we get a recursion for '\r' '\n' when
651 calling yylex. */
652 UNGETC (c);
653 c = skip_white_space_on_line ();
655 /* If the # is the only nonwhite char on the line,
656 just ignore it. Check the new newline. */
657 if (c == '\n')
658 return c;
660 /* Something follows the #; read a token. */
662 UNGETC (c);
663 token = yylex ();
665 if (token == CONSTANT
666 && TREE_CODE (yylval.ttype) == INTEGER_CST)
668 int old_lineno = lineno;
669 int used_up = 0;
670 /* subtract one, because it is the following line that
671 gets the specified number */
673 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
675 /* Is this the last nonwhite stuff on the line? */
676 c = skip_white_space_on_line ();
677 if (c == '\n')
679 /* No more: store the line number and check following line. */
680 lineno = l;
681 return c;
683 UNGETC (c);
685 /* More follows: it must be a string constant (filename). */
687 /* Read the string constant. */
688 token = yylex ();
690 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
692 error ("invalid #line");
693 goto skipline;
696 input_filename
697 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
698 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
699 lineno = l;
701 /* Each change of file name
702 reinitializes whether we are now in a system header. */
703 in_system_header = 0;
705 if (main_input_filename == 0)
706 main_input_filename = input_filename;
708 /* Is this the last nonwhite stuff on the line? */
709 c = skip_white_space_on_line ();
710 if (c == '\n')
712 /* Update the name in the top element of input_file_stack. */
713 if (input_file_stack)
714 input_file_stack->name = input_filename;
716 return c;
718 UNGETC (c);
720 token = yylex ();
721 used_up = 0;
723 /* `1' after file name means entering new file.
724 `2' after file name means just left a file. */
726 if (token == CONSTANT
727 && TREE_CODE (yylval.ttype) == INTEGER_CST)
729 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
731 /* Pushing to a new file. */
732 struct file_stack *p
733 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
734 input_file_stack->line = old_lineno;
735 p->next = input_file_stack;
736 p->name = input_filename;
737 p->indent_level = indent_level;
738 input_file_stack = p;
739 input_file_stack_tick++;
740 debug_start_source_file (input_filename);
741 used_up = 1;
743 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
745 /* Popping out of a file. */
746 if (input_file_stack->next)
748 struct file_stack *p = input_file_stack;
749 if (indent_level != p->indent_level)
751 warning_with_file_and_line
752 (p->name, old_lineno,
753 "This file contains more `%c's than `%c's.",
754 indent_level > p->indent_level ? '{' : '}',
755 indent_level > p->indent_level ? '}' : '{');
757 input_file_stack = p->next;
758 free (p);
759 input_file_stack_tick++;
760 debug_end_source_file (input_file_stack->line);
762 else
763 error ("#-lines for entering and leaving files don't match");
765 used_up = 1;
769 /* Now that we've pushed or popped the input stack,
770 update the name in the top element. */
771 if (input_file_stack)
772 input_file_stack->name = input_filename;
774 /* If we have handled a `1' or a `2',
775 see if there is another number to read. */
776 if (used_up)
778 /* Is this the last nonwhite stuff on the line? */
779 c = skip_white_space_on_line ();
780 if (c == '\n')
781 return c;
782 UNGETC (c);
784 token = yylex ();
785 used_up = 0;
788 /* `3' after file name means this is a system header file. */
790 if (token == CONSTANT
791 && TREE_CODE (yylval.ttype) == INTEGER_CST
792 && TREE_INT_CST_LOW (yylval.ttype) == 3)
793 in_system_header = 1, used_up = 1;
795 if (used_up)
797 /* Is this the last nonwhite stuff on the line? */
798 c = skip_white_space_on_line ();
799 if (c == '\n')
800 return c;
801 UNGETC (c);
804 warning ("unrecognized text at end of #line");
806 else
807 error ("invalid #-line");
809 /* skip the rest of this line. */
810 skipline:
811 #if !USE_CPPLIB
812 if (c != '\n' && c != EOF && nextchar >= 0)
813 c = nextchar, nextchar = -1;
814 #endif
815 while (c != '\n' && c != EOF)
816 c = GETC();
817 return c;
820 #ifdef HANDLE_SYSV_PRAGMA
822 /* Handle a #pragma directive.
823 TOKEN is the token we read after `#pragma'. Processes the entire input
824 line and returns a character for the caller to reread: either \n or EOF. */
826 /* This function has to be in this file, in order to get at
827 the token types. */
829 static int
830 handle_sysv_pragma (token)
831 register int token;
833 register int c;
835 for (;;)
837 switch (token)
839 case IDENTIFIER:
840 case TYPENAME:
841 case STRING:
842 case CONSTANT:
843 handle_pragma_token (token_buffer, yylval.ttype);
844 break;
845 default:
846 handle_pragma_token (token_buffer, 0);
848 #if !USE_CPPLIB
849 if (nextchar >= 0)
850 c = nextchar, nextchar = -1;
851 else
852 #endif
853 c = GETC ();
855 while (c == ' ' || c == '\t')
856 c = GETC ();
857 if (c == '\n' || c == EOF)
859 handle_pragma_token (0, 0);
860 return c;
862 UNGETC (c);
863 token = yylex ();
867 #endif /* HANDLE_SYSV_PRAGMA */
869 #define ENDFILE -1 /* token that represents end-of-file */
871 /* Read an escape sequence, returning its equivalent as a character,
872 or store 1 in *ignore_ptr if it is backslash-newline. */
874 static int
875 readescape (ignore_ptr)
876 int *ignore_ptr;
878 register int c = GETC();
879 register int code;
880 register unsigned count;
881 unsigned firstdig = 0;
882 int nonnull;
884 switch (c)
886 case 'x':
887 if (warn_traditional)
888 warning ("the meaning of `\\x' varies with -traditional");
890 if (flag_traditional)
891 return c;
893 code = 0;
894 count = 0;
895 nonnull = 0;
896 while (1)
898 c = GETC();
899 if (!(c >= 'a' && c <= 'f')
900 && !(c >= 'A' && c <= 'F')
901 && !(c >= '0' && c <= '9'))
903 UNGETC (c);
904 break;
906 code *= 16;
907 if (c >= 'a' && c <= 'f')
908 code += c - 'a' + 10;
909 if (c >= 'A' && c <= 'F')
910 code += c - 'A' + 10;
911 if (c >= '0' && c <= '9')
912 code += c - '0';
913 if (code != 0 || count != 0)
915 if (count == 0)
916 firstdig = code;
917 count++;
919 nonnull = 1;
921 if (! nonnull)
922 error ("\\x used with no following hex digits");
923 else if (count == 0)
924 /* Digits are all 0's. Ok. */
926 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
927 || (count > 1
928 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
929 <= firstdig)))
930 pedwarn ("hex escape out of range");
931 return code;
933 case '0': case '1': case '2': case '3': case '4':
934 case '5': case '6': case '7':
935 code = 0;
936 count = 0;
937 while ((c <= '7') && (c >= '0') && (count++ < 3))
939 code = (code * 8) + (c - '0');
940 c = GETC();
942 UNGETC (c);
943 return code;
945 case '\\': case '\'': case '"':
946 return c;
948 case '\n':
949 lineno++;
950 *ignore_ptr = 1;
951 return 0;
953 case 'n':
954 return TARGET_NEWLINE;
956 case 't':
957 return TARGET_TAB;
959 case 'r':
960 return TARGET_CR;
962 case 'f':
963 return TARGET_FF;
965 case 'b':
966 return TARGET_BS;
968 case 'a':
969 if (warn_traditional)
970 warning ("the meaning of `\\a' varies with -traditional");
972 if (flag_traditional)
973 return c;
974 return TARGET_BELL;
976 case 'v':
977 #if 0 /* Vertical tab is present in common usage compilers. */
978 if (flag_traditional)
979 return c;
980 #endif
981 return TARGET_VT;
983 case 'e':
984 case 'E':
985 if (pedantic)
986 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
987 return 033;
989 case '?':
990 return c;
992 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
993 case '(':
994 case '{':
995 case '[':
996 /* `\%' is used to prevent SCCS from getting confused. */
997 case '%':
998 if (pedantic)
999 pedwarn ("non-ANSI escape sequence `\\%c'", c);
1000 return c;
1002 if (c >= 040 && c < 0177)
1003 pedwarn ("unknown escape sequence `\\%c'", c);
1004 else
1005 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1006 return c;
1009 void
1010 yyerror (string)
1011 char *string;
1013 char buf[200];
1015 strcpy (buf, string);
1017 /* We can't print string and character constants well
1018 because the token_buffer contains the result of processing escapes. */
1019 if (end_of_file)
1020 strcat (buf, " at end of input");
1021 else if (token_buffer[0] == 0)
1022 strcat (buf, " at null character");
1023 else if (token_buffer[0] == '"')
1024 strcat (buf, " before string constant");
1025 else if (token_buffer[0] == '\'')
1026 strcat (buf, " before character constant");
1027 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
1028 sprintf (buf + strlen (buf), " before character 0%o",
1029 (unsigned char) token_buffer[0]);
1030 else
1031 strcat (buf, " before `%s'");
1033 error (buf, token_buffer);
1036 #if 0
1038 struct try_type
1040 tree *node_var;
1041 char unsigned_flag;
1042 char long_flag;
1043 char long_long_flag;
1046 struct try_type type_sequence[] =
1048 { &integer_type_node, 0, 0, 0},
1049 { &unsigned_type_node, 1, 0, 0},
1050 { &long_integer_type_node, 0, 1, 0},
1051 { &long_unsigned_type_node, 1, 1, 0},
1052 { &long_long_integer_type_node, 0, 1, 1},
1053 { &long_long_unsigned_type_node, 1, 1, 1}
1055 #endif /* 0 */
1058 yylex ()
1060 register int c;
1061 register char *p;
1062 register int value;
1063 int wide_flag = 0;
1064 int objc_flag = 0;
1066 #if !USE_CPPLIB
1067 if (nextchar >= 0)
1068 c = nextchar, nextchar = -1;
1069 else
1070 #endif
1071 c = GETC();
1073 /* Effectively do c = skip_white_space (c)
1074 but do it faster in the usual cases. */
1075 while (1)
1076 switch (c)
1078 case ' ':
1079 case '\t':
1080 case '\f':
1081 case '\v':
1082 case '\b':
1083 c = GETC();
1084 break;
1086 case '\r':
1087 /* Call skip_white_space so we can warn if appropriate. */
1089 case '\n':
1090 case '/':
1091 case '\\':
1092 c = skip_white_space (c);
1093 default:
1094 goto found_nonwhite;
1096 found_nonwhite:
1098 token_buffer[0] = c;
1099 token_buffer[1] = 0;
1101 /* yylloc.first_line = lineno; */
1103 switch (c)
1105 case EOF:
1106 end_of_file = 1;
1107 token_buffer[0] = 0;
1108 value = ENDFILE;
1109 break;
1111 case 'L':
1112 /* Capital L may start a wide-string or wide-character constant. */
1114 register int c = GETC();
1115 if (c == '\'')
1117 wide_flag = 1;
1118 goto char_constant;
1120 if (c == '"')
1122 wide_flag = 1;
1123 goto string_constant;
1125 UNGETC (c);
1127 goto letter;
1129 case '@':
1130 if (!doing_objc_thang)
1132 value = c;
1133 break;
1135 else
1137 /* '@' may start a constant string object. */
1138 register int c = GETC ();
1139 if (c == '"')
1141 objc_flag = 1;
1142 goto string_constant;
1144 UNGETC (c);
1145 /* Fall through to treat '@' as the start of an identifier. */
1148 case 'A': case 'B': case 'C': case 'D': case 'E':
1149 case 'F': case 'G': case 'H': case 'I': case 'J':
1150 case 'K': case 'M': case 'N': case 'O':
1151 case 'P': case 'Q': case 'R': case 'S': case 'T':
1152 case 'U': case 'V': case 'W': case 'X': case 'Y':
1153 case 'Z':
1154 case 'a': case 'b': case 'c': case 'd': case 'e':
1155 case 'f': case 'g': case 'h': case 'i': case 'j':
1156 case 'k': case 'l': case 'm': case 'n': case 'o':
1157 case 'p': case 'q': case 'r': case 's': case 't':
1158 case 'u': case 'v': case 'w': case 'x': case 'y':
1159 case 'z':
1160 case '_':
1161 case '$':
1162 letter:
1163 p = token_buffer;
1164 while (ISALNUM (c) || c == '_' || c == '$' || c == '@')
1166 /* Make sure this char really belongs in an identifier. */
1167 if (c == '@' && ! doing_objc_thang)
1168 break;
1169 if (c == '$')
1171 if (! dollars_in_ident)
1172 error ("`$' in identifier");
1173 else if (pedantic)
1174 pedwarn ("`$' in identifier");
1177 if (p >= token_buffer + maxtoken)
1178 p = extend_token_buffer (p);
1180 *p++ = c;
1181 c = GETC();
1184 *p = 0;
1185 #if USE_CPPLIB
1186 UNGETC (c);
1187 #else
1188 nextchar = c;
1189 #endif
1191 value = IDENTIFIER;
1192 yylval.itype = 0;
1194 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1197 register struct resword *ptr;
1199 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
1201 if (ptr->rid)
1202 yylval.ttype = ridpointers[(int) ptr->rid];
1203 value = (int) ptr->token;
1205 /* Only return OBJECTNAME if it is a typedef. */
1206 if (doing_objc_thang && value == OBJECTNAME)
1208 lastiddecl = lookup_name(yylval.ttype);
1210 if (lastiddecl == NULL_TREE
1211 || TREE_CODE (lastiddecl) != TYPE_DECL)
1212 value = IDENTIFIER;
1215 /* Even if we decided to recognize asm, still perhaps warn. */
1216 if (pedantic
1217 && (value == ASM_KEYWORD || value == TYPEOF
1218 || ptr->rid == RID_INLINE)
1219 && token_buffer[0] != '_')
1220 pedwarn ("ANSI does not permit the keyword `%s'",
1221 token_buffer);
1225 /* If we did not find a keyword, look for an identifier
1226 (or a typename). */
1228 if (value == IDENTIFIER)
1230 if (token_buffer[0] == '@')
1231 error("invalid identifier `%s'", token_buffer);
1233 yylval.ttype = get_identifier (token_buffer);
1234 lastiddecl = lookup_name (yylval.ttype);
1236 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1237 value = TYPENAME;
1238 /* A user-invisible read-only initialized variable
1239 should be replaced by its value.
1240 We handle only strings since that's the only case used in C. */
1241 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1242 && DECL_IGNORED_P (lastiddecl)
1243 && TREE_READONLY (lastiddecl)
1244 && DECL_INITIAL (lastiddecl) != 0
1245 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1247 tree stringval = DECL_INITIAL (lastiddecl);
1249 /* Copy the string value so that we won't clobber anything
1250 if we put something in the TREE_CHAIN of this one. */
1251 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1252 TREE_STRING_POINTER (stringval));
1253 value = STRING;
1255 else if (doing_objc_thang)
1257 tree objc_interface_decl = is_class_name (yylval.ttype);
1259 if (objc_interface_decl)
1261 value = CLASSNAME;
1262 yylval.ttype = objc_interface_decl;
1267 break;
1269 case '0': case '1':
1271 int next_c;
1272 /* Check first for common special case: single-digit 0 or 1. */
1274 next_c = GETC ();
1275 UNGETC (next_c); /* Always undo this lookahead. */
1276 if (!ISALNUM (next_c) && next_c != '.')
1278 token_buffer[0] = (char)c, token_buffer[1] = '\0';
1279 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1280 value = CONSTANT;
1281 break;
1283 /*FALLTHRU*/
1285 case '2': case '3': case '4':
1286 case '5': case '6': case '7': case '8': case '9':
1287 case '.':
1289 int base = 10;
1290 int count = 0;
1291 int largest_digit = 0;
1292 int numdigits = 0;
1293 /* for multi-precision arithmetic,
1294 we actually store only HOST_BITS_PER_CHAR bits in each part.
1295 The number of parts is chosen so as to be sufficient to hold
1296 the enough bits to fit into the two HOST_WIDE_INTs that contain
1297 the integer value (this is always at least as many bits as are
1298 in a target `long long' value, but may be wider). */
1299 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1300 int parts[TOTAL_PARTS];
1301 int overflow = 0;
1303 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1304 = NOT_FLOAT;
1306 for (count = 0; count < TOTAL_PARTS; count++)
1307 parts[count] = 0;
1309 p = token_buffer;
1310 *p++ = c;
1312 if (c == '0')
1314 *p++ = (c = GETC());
1315 if ((c == 'x') || (c == 'X'))
1317 base = 16;
1318 *p++ = (c = GETC());
1320 /* Leading 0 forces octal unless the 0 is the only digit. */
1321 else if (c >= '0' && c <= '9')
1323 base = 8;
1324 numdigits++;
1326 else
1327 numdigits++;
1330 /* Read all the digits-and-decimal-points. */
1332 while (c == '.'
1333 || (ISALNUM (c) && c != 'l' && c != 'L'
1334 && c != 'u' && c != 'U'
1335 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1336 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1338 if (c == '.')
1340 if (base == 16)
1341 error ("floating constant may not be in radix 16");
1342 if (floatflag == TOO_MANY_POINTS)
1343 /* We have already emitted an error. Don't need another. */
1345 else if (floatflag == AFTER_POINT)
1347 error ("malformed floating constant");
1348 floatflag = TOO_MANY_POINTS;
1349 /* Avoid another error from atof by forcing all characters
1350 from here on to be ignored. */
1351 p[-1] = '\0';
1353 else
1354 floatflag = AFTER_POINT;
1356 base = 10;
1357 *p++ = c = GETC();
1358 /* Accept '.' as the start of a floating-point number
1359 only when it is followed by a digit.
1360 Otherwise, unread the following non-digit
1361 and use the '.' as a structural token. */
1362 if (p == token_buffer + 2 && !ISDIGIT (c))
1364 if (c == '.')
1366 c = GETC();
1367 if (c == '.')
1369 *p++ = c;
1370 *p = 0;
1371 return ELLIPSIS;
1373 error ("parse error at `..'");
1375 UNGETC (c);
1376 token_buffer[1] = 0;
1377 value = '.';
1378 goto done;
1381 else
1383 /* It is not a decimal point.
1384 It should be a digit (perhaps a hex digit). */
1386 if (ISDIGIT (c))
1388 c = c - '0';
1390 else if (base <= 10)
1392 if (c == 'e' || c == 'E')
1394 base = 10;
1395 floatflag = AFTER_POINT;
1396 break; /* start of exponent */
1398 error ("nondigits in number and not hexadecimal");
1399 c = 0;
1401 else if (c >= 'a')
1403 c = c - 'a' + 10;
1405 else
1407 c = c - 'A' + 10;
1409 if (c >= largest_digit)
1410 largest_digit = c;
1411 numdigits++;
1413 for (count = 0; count < TOTAL_PARTS; count++)
1415 parts[count] *= base;
1416 if (count)
1418 parts[count]
1419 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1420 parts[count-1]
1421 &= (1 << HOST_BITS_PER_CHAR) - 1;
1423 else
1424 parts[0] += c;
1427 /* If the extra highest-order part ever gets anything in it,
1428 the number is certainly too big. */
1429 if (parts[TOTAL_PARTS - 1] != 0)
1430 overflow = 1;
1432 if (p >= token_buffer + maxtoken - 3)
1433 p = extend_token_buffer (p);
1434 *p++ = (c = GETC());
1438 if (numdigits == 0)
1439 error ("numeric constant with no digits");
1441 if (largest_digit >= base)
1442 error ("numeric constant contains digits beyond the radix");
1444 /* Remove terminating char from the token buffer and delimit the string */
1445 *--p = 0;
1447 if (floatflag != NOT_FLOAT)
1449 tree type = double_type_node;
1450 int imag = 0;
1451 int conversion_errno = 0;
1452 REAL_VALUE_TYPE value;
1453 jmp_buf handler;
1455 /* Read explicit exponent if any, and put it in tokenbuf. */
1457 if ((c == 'e') || (c == 'E'))
1459 if (p >= token_buffer + maxtoken - 3)
1460 p = extend_token_buffer (p);
1461 *p++ = c;
1462 c = GETC();
1463 if ((c == '+') || (c == '-'))
1465 *p++ = c;
1466 c = GETC();
1468 if (! ISDIGIT (c))
1469 error ("floating constant exponent has no digits");
1470 while (ISDIGIT (c))
1472 if (p >= token_buffer + maxtoken - 3)
1473 p = extend_token_buffer (p);
1474 *p++ = c;
1475 c = GETC();
1479 *p = 0;
1481 /* Convert string to a double, checking for overflow. */
1482 if (setjmp (handler))
1484 error ("floating constant out of range");
1485 value = dconst0;
1487 else
1489 int fflag = 0, lflag = 0;
1490 /* Copy token_buffer now, while it has just the number
1491 and not the suffixes; once we add `f' or `i',
1492 REAL_VALUE_ATOF may not work any more. */
1493 char *copy = (char *) alloca (p - token_buffer + 1);
1494 bcopy (token_buffer, copy, p - token_buffer + 1);
1496 set_float_handler (handler);
1498 while (1)
1500 int lose = 0;
1502 /* Read the suffixes to choose a data type. */
1503 switch (c)
1505 case 'f': case 'F':
1506 if (fflag)
1507 error ("more than one `f' in numeric constant");
1508 fflag = 1;
1509 break;
1511 case 'l': case 'L':
1512 if (lflag)
1513 error ("more than one `l' in numeric constant");
1514 lflag = 1;
1515 break;
1517 case 'i': case 'I':
1518 if (imag)
1519 error ("more than one `i' or `j' in numeric constant");
1520 else if (pedantic)
1521 pedwarn ("ANSI C forbids imaginary numeric constants");
1522 imag = 1;
1523 break;
1525 default:
1526 lose = 1;
1529 if (lose)
1530 break;
1532 if (p >= token_buffer + maxtoken - 3)
1533 p = extend_token_buffer (p);
1534 *p++ = c;
1535 *p = 0;
1536 c = GETC();
1539 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1540 tells the desired precision of the binary result
1541 of decimal-to-binary conversion. */
1543 if (fflag)
1545 if (lflag)
1546 error ("both `f' and `l' in floating constant");
1548 type = float_type_node;
1549 errno = 0;
1550 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1551 conversion_errno = errno;
1552 /* A diagnostic is required here by some ANSI C testsuites.
1553 This is not pedwarn, become some people don't want
1554 an error for this. */
1555 if (REAL_VALUE_ISINF (value) && pedantic)
1556 warning ("floating point number exceeds range of `float'");
1558 else if (lflag)
1560 type = long_double_type_node;
1561 errno = 0;
1562 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1563 conversion_errno = errno;
1564 if (REAL_VALUE_ISINF (value) && pedantic)
1565 warning ("floating point number exceeds range of `long double'");
1567 else
1569 errno = 0;
1570 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1571 conversion_errno = errno;
1572 if (REAL_VALUE_ISINF (value) && pedantic)
1573 warning ("floating point number exceeds range of `double'");
1576 set_float_handler (NULL_PTR);
1578 #ifdef ERANGE
1579 /* ERANGE is also reported for underflow,
1580 so test the value to distinguish overflow from that. */
1581 if (conversion_errno == ERANGE && !flag_traditional && pedantic
1582 && (REAL_VALUES_LESS (dconst1, value)
1583 || REAL_VALUES_LESS (value, dconstm1)))
1584 warning ("floating point number exceeds range of `double'");
1585 #endif
1587 /* If the result is not a number, assume it must have been
1588 due to some error message above, so silently convert
1589 it to a zero. */
1590 if (REAL_VALUE_ISNAN (value))
1591 value = dconst0;
1593 /* Create a node with determined type and value. */
1594 if (imag)
1595 yylval.ttype = build_complex (NULL_TREE,
1596 convert (type, integer_zero_node),
1597 build_real (type, value));
1598 else
1599 yylval.ttype = build_real (type, value);
1601 else
1603 tree traditional_type, ansi_type, type;
1604 HOST_WIDE_INT high, low;
1605 int spec_unsigned = 0;
1606 int spec_long = 0;
1607 int spec_long_long = 0;
1608 int spec_imag = 0;
1609 int bytes, warn, i;
1611 traditional_type = ansi_type = type = NULL_TREE;
1612 while (1)
1614 if (c == 'u' || c == 'U')
1616 if (spec_unsigned)
1617 error ("two `u's in integer constant");
1618 spec_unsigned = 1;
1620 else if (c == 'l' || c == 'L')
1622 if (spec_long)
1624 if (spec_long_long)
1625 error ("three `l's in integer constant");
1626 else if (pedantic)
1627 pedwarn ("ANSI C forbids long long integer constants");
1628 spec_long_long = 1;
1630 spec_long = 1;
1632 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1634 if (spec_imag)
1635 error ("more than one `i' or `j' in numeric constant");
1636 else if (pedantic)
1637 pedwarn ("ANSI C forbids imaginary numeric constants");
1638 spec_imag = 1;
1640 else
1641 break;
1642 if (p >= token_buffer + maxtoken - 3)
1643 p = extend_token_buffer (p);
1644 *p++ = c;
1645 c = GETC();
1648 /* If the constant won't fit in an unsigned long long,
1649 then warn that the constant is out of range. */
1651 /* ??? This assumes that long long and long integer types are
1652 a multiple of 8 bits. This better than the original code
1653 though which assumed that long was exactly 32 bits and long
1654 long was exactly 64 bits. */
1656 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1658 warn = overflow;
1659 for (i = bytes; i < TOTAL_PARTS; i++)
1660 if (parts[i])
1661 warn = 1;
1662 if (warn)
1663 pedwarn ("integer constant out of range");
1665 /* This is simplified by the fact that our constant
1666 is always positive. */
1668 high = low = 0;
1670 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1672 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1673 / HOST_BITS_PER_CHAR)]
1674 << (i * HOST_BITS_PER_CHAR));
1675 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1678 yylval.ttype = build_int_2 (low, high);
1679 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1681 /* If warn_traditional, calculate both the ANSI type and the
1682 traditional type, then see if they disagree.
1683 Otherwise, calculate only the type for the dialect in use. */
1684 if (warn_traditional || flag_traditional)
1686 /* Calculate the traditional type. */
1687 /* Traditionally, any constant is signed;
1688 but if unsigned is specified explicitly, obey that.
1689 Use the smallest size with the right number of bits,
1690 except for one special case with decimal constants. */
1691 if (! spec_long && base != 10
1692 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1693 traditional_type = (spec_unsigned ? unsigned_type_node
1694 : integer_type_node);
1695 /* A decimal constant must be long
1696 if it does not fit in type int.
1697 I think this is independent of whether
1698 the constant is signed. */
1699 else if (! spec_long && base == 10
1700 && int_fits_type_p (yylval.ttype, integer_type_node))
1701 traditional_type = (spec_unsigned ? unsigned_type_node
1702 : integer_type_node);
1703 else if (! spec_long_long)
1704 traditional_type = (spec_unsigned ? long_unsigned_type_node
1705 : long_integer_type_node);
1706 else
1707 traditional_type = (spec_unsigned
1708 ? long_long_unsigned_type_node
1709 : long_long_integer_type_node);
1711 if (warn_traditional || ! flag_traditional)
1713 /* Calculate the ANSI type. */
1714 if (! spec_long && ! spec_unsigned
1715 && int_fits_type_p (yylval.ttype, integer_type_node))
1716 ansi_type = integer_type_node;
1717 else if (! spec_long && (base != 10 || spec_unsigned)
1718 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1719 ansi_type = unsigned_type_node;
1720 else if (! spec_unsigned && !spec_long_long
1721 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1722 ansi_type = long_integer_type_node;
1723 else if (! spec_long_long
1724 && int_fits_type_p (yylval.ttype,
1725 long_unsigned_type_node))
1726 ansi_type = long_unsigned_type_node;
1727 else if (! spec_unsigned
1728 && int_fits_type_p (yylval.ttype,
1729 long_long_integer_type_node))
1730 ansi_type = long_long_integer_type_node;
1731 else
1732 ansi_type = long_long_unsigned_type_node;
1735 type = flag_traditional ? traditional_type : ansi_type;
1737 if (warn_traditional && traditional_type != ansi_type)
1739 if (TYPE_PRECISION (traditional_type)
1740 != TYPE_PRECISION (ansi_type))
1741 warning ("width of integer constant changes with -traditional");
1742 else if (TREE_UNSIGNED (traditional_type)
1743 != TREE_UNSIGNED (ansi_type))
1744 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1745 else
1746 warning ("width of integer constant may change on other systems with -traditional");
1749 if (pedantic && !flag_traditional && !spec_long_long && !warn
1750 && (TYPE_PRECISION (long_integer_type_node)
1751 < TYPE_PRECISION (type)))
1752 pedwarn ("integer constant out of range");
1754 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1755 warning ("decimal constant is so large that it is unsigned");
1757 if (spec_imag)
1759 if (TYPE_PRECISION (type)
1760 <= TYPE_PRECISION (integer_type_node))
1761 yylval.ttype
1762 = build_complex (NULL_TREE, integer_zero_node,
1763 convert (integer_type_node,
1764 yylval.ttype));
1765 else
1766 error ("complex integer constant is too wide for `complex int'");
1768 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1769 /* The traditional constant 0x80000000 is signed
1770 but doesn't fit in the range of int.
1771 This will change it to -0x80000000, which does fit. */
1773 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1774 yylval.ttype = convert (type, yylval.ttype);
1775 TREE_OVERFLOW (yylval.ttype)
1776 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1778 else
1779 TREE_TYPE (yylval.ttype) = type;
1782 UNGETC (c);
1783 *p = 0;
1785 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
1786 || (!flag_traditional && (c == '-' || c == '+')
1787 && (p[-1] == 'e' || p[-1] == 'E')))
1788 error ("missing white space after number `%s'", token_buffer);
1790 value = CONSTANT; break;
1793 case '\'':
1794 char_constant:
1796 register int result = 0;
1797 register int num_chars = 0;
1798 unsigned width = TYPE_PRECISION (char_type_node);
1799 int max_chars;
1801 if (wide_flag)
1803 width = WCHAR_TYPE_SIZE;
1804 #ifdef MULTIBYTE_CHARS
1805 max_chars = MB_CUR_MAX;
1806 #else
1807 max_chars = 1;
1808 #endif
1810 else
1811 max_chars = TYPE_PRECISION (integer_type_node) / width;
1813 while (1)
1815 tryagain:
1817 c = GETC();
1819 if (c == '\'' || c == EOF)
1820 break;
1822 if (c == '\\')
1824 int ignore = 0;
1825 c = readescape (&ignore);
1826 if (ignore)
1827 goto tryagain;
1828 if (width < HOST_BITS_PER_INT
1829 && (unsigned) c >= (1 << width))
1830 pedwarn ("escape sequence out of range for character");
1831 #ifdef MAP_CHARACTER
1832 if (ISPRINT (c))
1833 c = MAP_CHARACTER (c);
1834 #endif
1836 else if (c == '\n')
1838 if (pedantic)
1839 pedwarn ("ANSI C forbids newline in character constant");
1840 lineno++;
1842 #ifdef MAP_CHARACTER
1843 else
1844 c = MAP_CHARACTER (c);
1845 #endif
1847 num_chars++;
1848 if (num_chars > maxtoken - 4)
1849 extend_token_buffer (token_buffer);
1851 token_buffer[num_chars] = c;
1853 /* Merge character into result; ignore excess chars. */
1854 if (num_chars < max_chars + 1)
1856 if (width < HOST_BITS_PER_INT)
1857 result = (result << width) | (c & ((1 << width) - 1));
1858 else
1859 result = c;
1863 token_buffer[num_chars + 1] = '\'';
1864 token_buffer[num_chars + 2] = 0;
1866 if (c != '\'')
1867 error ("malformatted character constant");
1868 else if (num_chars == 0)
1869 error ("empty character constant");
1870 else if (num_chars > max_chars)
1872 num_chars = max_chars;
1873 error ("character constant too long");
1875 else if (num_chars != 1 && ! flag_traditional)
1876 warning ("multi-character character constant");
1878 /* If char type is signed, sign-extend the constant. */
1879 if (! wide_flag)
1881 int num_bits = num_chars * width;
1882 if (num_bits == 0)
1883 /* We already got an error; avoid invalid shift. */
1884 yylval.ttype = build_int_2 (0, 0);
1885 else if (TREE_UNSIGNED (char_type_node)
1886 || ((result >> (num_bits - 1)) & 1) == 0)
1887 yylval.ttype
1888 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
1889 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1891 else
1892 yylval.ttype
1893 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
1894 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1895 -1);
1896 TREE_TYPE (yylval.ttype) = integer_type_node;
1898 else
1900 #ifdef MULTIBYTE_CHARS
1901 /* Set the initial shift state and convert the next sequence. */
1902 result = 0;
1903 /* In all locales L'\0' is zero and mbtowc will return zero,
1904 so don't use it. */
1905 if (num_chars > 1
1906 || (num_chars == 1 && token_buffer[1] != '\0'))
1908 wchar_t wc;
1909 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1910 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1911 result = wc;
1912 else
1913 warning ("Ignoring invalid multibyte character");
1915 #endif
1916 yylval.ttype = build_int_2 (result, 0);
1917 TREE_TYPE (yylval.ttype) = wchar_type_node;
1920 value = CONSTANT;
1921 break;
1924 case '"':
1925 string_constant:
1927 c = GETC();
1928 p = token_buffer + 1;
1930 while (c != '"' && c >= 0)
1932 if (c == '\\')
1934 int ignore = 0;
1935 c = readescape (&ignore);
1936 if (ignore)
1937 goto skipnewline;
1938 if (!wide_flag
1939 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1940 && c >= (1 << TYPE_PRECISION (char_type_node)))
1941 pedwarn ("escape sequence out of range for character");
1943 else if (c == '\n')
1945 if (pedantic)
1946 pedwarn ("ANSI C forbids newline in string constant");
1947 lineno++;
1950 if (p == token_buffer + maxtoken)
1951 p = extend_token_buffer (p);
1952 *p++ = c;
1954 skipnewline:
1955 c = GETC();
1957 *p = 0;
1959 if (c < 0)
1960 error ("Unterminated string constant");
1962 /* We have read the entire constant.
1963 Construct a STRING_CST for the result. */
1965 if (wide_flag)
1967 /* If this is a L"..." wide-string, convert the multibyte string
1968 to a wide character string. */
1969 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1970 int len;
1972 #ifdef MULTIBYTE_CHARS
1973 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1974 if (len < 0 || len >= (p - token_buffer))
1976 warning ("Ignoring invalid multibyte string");
1977 len = 0;
1979 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1980 #else
1982 char *wp, *cp;
1984 wp = widep + (BYTES_BIG_ENDIAN ? WCHAR_BYTES - 1 : 0);
1985 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1986 for (cp = token_buffer + 1; cp < p; cp++)
1987 *wp = *cp, wp += WCHAR_BYTES;
1988 len = p - token_buffer - 1;
1990 #endif
1991 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1992 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1993 value = STRING;
1995 else if (objc_flag)
1997 /* Return an Objective-C @"..." constant string object. */
1998 yylval.ttype = build_objc_string (p - token_buffer,
1999 token_buffer + 1);
2000 TREE_TYPE (yylval.ttype) = char_array_type_node;
2001 value = OBJC_STRING;
2003 else
2005 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
2006 TREE_TYPE (yylval.ttype) = char_array_type_node;
2007 value = STRING;
2010 *p++ = '"';
2011 *p = 0;
2013 break;
2016 case '+':
2017 case '-':
2018 case '&':
2019 case '|':
2020 case ':':
2021 case '<':
2022 case '>':
2023 case '*':
2024 case '/':
2025 case '%':
2026 case '^':
2027 case '!':
2028 case '=':
2030 register int c1;
2032 combine:
2034 switch (c)
2036 case '+':
2037 yylval.code = PLUS_EXPR; break;
2038 case '-':
2039 yylval.code = MINUS_EXPR; break;
2040 case '&':
2041 yylval.code = BIT_AND_EXPR; break;
2042 case '|':
2043 yylval.code = BIT_IOR_EXPR; break;
2044 case '*':
2045 yylval.code = MULT_EXPR; break;
2046 case '/':
2047 yylval.code = TRUNC_DIV_EXPR; break;
2048 case '%':
2049 yylval.code = TRUNC_MOD_EXPR; break;
2050 case '^':
2051 yylval.code = BIT_XOR_EXPR; break;
2052 case LSHIFT:
2053 yylval.code = LSHIFT_EXPR; break;
2054 case RSHIFT:
2055 yylval.code = RSHIFT_EXPR; break;
2056 case '<':
2057 yylval.code = LT_EXPR; break;
2058 case '>':
2059 yylval.code = GT_EXPR; break;
2062 token_buffer[1] = c1 = GETC();
2063 token_buffer[2] = 0;
2065 if (c1 == '=')
2067 switch (c)
2069 case '<':
2070 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2071 case '>':
2072 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2073 case '!':
2074 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2075 case '=':
2076 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2078 value = ASSIGN; goto done;
2080 else if (c == c1)
2081 switch (c)
2083 case '+':
2084 value = PLUSPLUS; goto done;
2085 case '-':
2086 value = MINUSMINUS; goto done;
2087 case '&':
2088 value = ANDAND; goto done;
2089 case '|':
2090 value = OROR; goto done;
2091 case '<':
2092 c = LSHIFT;
2093 goto combine;
2094 case '>':
2095 c = RSHIFT;
2096 goto combine;
2098 else
2099 switch (c)
2101 case '-':
2102 if (c1 == '>')
2103 { value = POINTSAT; goto done; }
2104 break;
2105 case ':':
2106 if (c1 == '>')
2107 { value = ']'; goto done; }
2108 break;
2109 case '<':
2110 if (c1 == '%')
2111 { value = '{'; indent_level++; goto done; }
2112 if (c1 == ':')
2113 { value = '['; goto done; }
2114 break;
2115 case '%':
2116 if (c1 == '>')
2117 { value = '}'; indent_level--; goto done; }
2118 break;
2120 UNGETC (c1);
2121 token_buffer[1] = 0;
2123 if ((c == '<') || (c == '>'))
2124 value = ARITHCOMPARE;
2125 else value = c;
2126 goto done;
2129 case 0:
2130 /* Don't make yyparse think this is eof. */
2131 value = 1;
2132 break;
2134 case '{':
2135 indent_level++;
2136 value = c;
2137 break;
2139 case '}':
2140 indent_level--;
2141 value = c;
2142 break;
2144 default:
2145 value = c;
2148 done:
2149 /* yylloc.last_line = lineno; */
2151 return value;
2154 /* Sets the value of the 'yydebug' variable to VALUE.
2155 This is a function so we don't have to have YYDEBUG defined
2156 in order to build the compiler. */
2158 void
2159 set_yydebug (value)
2160 int value;
2162 #if YYDEBUG != 0
2163 yydebug = value;
2164 #else
2165 warning ("YYDEBUG not defined.");
2166 #endif