Add FR30 to list of targets for which -fpic is inappropriate.
[official-gcc.git] / gcc / c-lex.c
blobbd171abe248382265ec8514e5f2ab49c9eedab42
1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 88, 89, 92, 94-98, 1999 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"
24 #include "rtl.h"
25 #include "tree.h"
26 #include "input.h"
27 #include "output.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 #include "toplev.h"
34 #include "intl.h"
35 #include "ggc.h"
37 /* MULTIBYTE_CHARS support only works for native compilers.
38 ??? Ideally what we want is to model widechar support after
39 the current floating point support. */
40 #ifdef CROSS_COMPILE
41 #undef MULTIBYTE_CHARS
42 #endif
44 #ifdef MULTIBYTE_CHARS
45 #include "mbchar.h"
46 #include <locale.h>
47 #endif /* MULTIBYTE_CHARS */
48 #ifndef GET_ENVIRONMENT
49 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME))
50 #endif
52 #if USE_CPPLIB
53 #include "cpplib.h"
54 extern cpp_reader parse_in;
55 extern cpp_options parse_options;
56 #else
57 /* Stream for reading from the input file. */
58 FILE *finput;
59 #endif
61 extern void yyprint PROTO((FILE *, int, YYSTYPE));
63 /* The elements of `ridpointers' are identifier nodes
64 for the reserved type names and storage classes.
65 It is indexed by a RID_... value. */
66 tree ridpointers[(int) RID_MAX];
68 /* Cause the `yydebug' variable to be defined. */
69 #define YYDEBUG 1
71 #if USE_CPPLIB
72 extern unsigned char *yy_cur, *yy_lim;
73 extern enum cpp_token cpp_token;
75 extern int yy_get_token ();
77 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
78 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
80 #else /* ! USE_CPPLIB */
82 #define GETC() getch ()
83 #define UNGETC(c) put_back (c)
85 struct putback_buffer {
86 char *buffer;
87 int buffer_size;
88 int index;
91 static struct putback_buffer putback = {NULL, 0, -1};
93 static inline int
94 getch ()
96 if (putback.index != -1)
98 int ch = putback.buffer[putback.index];
99 --putback.index;
100 return ch;
102 return getc (finput);
105 static inline void
106 put_back (ch)
107 int ch;
109 if (ch != EOF)
111 if (putback.index == putback.buffer_size - 1)
113 putback.buffer_size += 16;
114 putback.buffer = xrealloc (putback.buffer, putback.buffer_size);
116 putback.buffer[++putback.index] = ch;
119 #endif /* ! USE_CPPLIB */
121 int linemode;
123 /* the declaration found for the last IDENTIFIER token read in.
124 yylex must look this up to detect typedefs, which get token type TYPENAME,
125 so it is left around in case the identifier is not a typedef but is
126 used in a context which makes it a reference to a variable. */
127 tree lastiddecl;
129 /* Nonzero enables objc features. */
131 int doing_objc_thang;
133 extern int yydebug;
135 /* File used for outputting assembler code. */
136 extern FILE *asm_out_file;
138 #ifndef WCHAR_TYPE_SIZE
139 #ifdef INT_TYPE_SIZE
140 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
141 #else
142 #define WCHAR_TYPE_SIZE BITS_PER_WORD
143 #endif
144 #endif
146 /* Number of bytes in a wide character. */
147 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
149 static int maxtoken; /* Current nominal length of token buffer. */
150 char *token_buffer; /* Pointer to token buffer.
151 Actual allocated length is maxtoken + 2.
152 This is not static because objc-parse.y uses it. */
154 static int indent_level; /* Number of { minus number of }. */
156 /* Nonzero tells yylex to ignore \ in string constants. */
157 static int ignore_escape_flag;
159 /* Nonzero if end-of-file has been seen on input. */
160 static int end_of_file;
162 #ifdef HANDLE_GENERIC_PRAGMAS
163 static int handle_generic_pragma PROTO((int));
164 #endif /* HANDLE_GENERIC_PRAGMAS */
165 static int whitespace_cr PROTO((int));
166 static int skip_white_space PROTO((int));
167 static char *extend_token_buffer PROTO((const char *));
168 static int readescape PROTO((int *));
169 static void parse_float PROTO((PTR));
171 /* Do not insert generated code into the source, instead, include it.
172 This allows us to build gcc automatically even for targets that
173 need to add or modify the reserved keyword lists. */
174 #include "c-gperf.h"
176 /* Return something to represent absolute declarators containing a *.
177 TARGET is the absolute declarator that the * contains.
178 TYPE_QUALS is a list of modifiers such as const or volatile
179 to apply to the pointer type, represented as identifiers.
181 We return an INDIRECT_REF whose "contents" are TARGET
182 and whose type is the modifier list. */
184 tree
185 make_pointer_declarator (type_quals, target)
186 tree type_quals, target;
188 return build1 (INDIRECT_REF, type_quals, target);
191 void
192 forget_protocol_qualifiers ()
194 int i, n = sizeof wordlist / sizeof (struct resword);
196 for (i = 0; i < n; i++)
197 if ((int) wordlist[i].rid >= (int) RID_IN
198 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
199 wordlist[i].name = "";
202 void
203 remember_protocol_qualifiers ()
205 int i, n = sizeof wordlist / sizeof (struct resword);
207 for (i = 0; i < n; i++)
208 if (wordlist[i].rid == RID_IN)
209 wordlist[i].name = "in";
210 else if (wordlist[i].rid == RID_OUT)
211 wordlist[i].name = "out";
212 else if (wordlist[i].rid == RID_INOUT)
213 wordlist[i].name = "inout";
214 else if (wordlist[i].rid == RID_BYCOPY)
215 wordlist[i].name = "bycopy";
216 else if (wordlist[i].rid == RID_BYREF)
217 wordlist[i].name = "byref";
218 else if (wordlist[i].rid == RID_ONEWAY)
219 wordlist[i].name = "oneway";
222 char *
223 init_parse (filename)
224 char *filename;
226 #if !USE_CPPLIB
227 /* Open input file. */
228 if (filename == 0 || !strcmp (filename, "-"))
230 finput = stdin;
231 filename = "stdin";
233 else
234 finput = fopen (filename, "r");
235 if (finput == 0)
236 pfatal_with_name (filename);
238 #ifdef IO_BUFFER_SIZE
239 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
240 #endif
241 #else /* !USE_CPPLIB */
242 parse_in.show_column = 1;
243 if (! cpp_start_read (&parse_in, filename))
244 abort ();
246 if (filename == 0 || !strcmp (filename, "-"))
247 filename = "stdin";
249 /* cpp_start_read always puts at least one line directive into the
250 token buffer. We must arrange to read it out here. */
251 yy_cur = parse_in.token_buffer;
252 yy_lim = CPP_PWRITTEN (&parse_in);
253 cpp_token = CPP_DIRECTIVE;
254 #endif
256 init_lex ();
257 init_pragma ();
259 return filename;
262 void
263 finish_parse ()
265 #if USE_CPPLIB
266 cpp_finish (&parse_in);
267 errorcount += parse_in.errors;
268 #else
269 fclose (finput);
270 #endif
273 void
274 init_lex ()
276 /* Make identifier nodes long enough for the language-specific slots. */
277 set_identifier_size (sizeof (struct lang_identifier));
279 /* Start it at 0, because check_newline is called at the very beginning
280 and will increment it to 1. */
281 lineno = 0;
283 #ifdef MULTIBYTE_CHARS
284 /* Change to the native locale for multibyte conversions. */
285 setlocale (LC_CTYPE, "");
286 GET_ENVIRONMENT (literal_codeset, "LANG");
287 #endif
289 maxtoken = 40;
290 token_buffer = (char *) xmalloc (maxtoken + 2);
292 ridpointers[(int) RID_INT] = get_identifier ("int");
293 ridpointers[(int) RID_CHAR] = get_identifier ("char");
294 ridpointers[(int) RID_VOID] = get_identifier ("void");
295 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
296 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
297 ridpointers[(int) RID_SHORT] = get_identifier ("short");
298 ridpointers[(int) RID_LONG] = get_identifier ("long");
299 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
300 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
301 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
302 ridpointers[(int) RID_CONST] = get_identifier ("const");
303 ridpointers[(int) RID_RESTRICT] = get_identifier ("restrict");
304 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
305 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
306 ridpointers[(int) RID_STATIC] = get_identifier ("static");
307 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
308 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
309 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
310 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
311 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
312 ridpointers[(int) RID_ID] = get_identifier ("id");
313 ridpointers[(int) RID_IN] = get_identifier ("in");
314 ridpointers[(int) RID_OUT] = get_identifier ("out");
315 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
316 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
317 ridpointers[(int) RID_BYREF] = get_identifier ("byref");
318 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
319 forget_protocol_qualifiers();
321 /* Some options inhibit certain reserved words.
322 Clear those words out of the hash table so they won't be recognized. */
323 #define UNSET_RESERVED_WORD(STRING) \
324 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
325 if (s) s->name = ""; } while (0)
327 if (! doing_objc_thang)
328 UNSET_RESERVED_WORD ("id");
330 if (flag_traditional)
332 UNSET_RESERVED_WORD ("const");
333 UNSET_RESERVED_WORD ("restrict");
334 UNSET_RESERVED_WORD ("volatile");
335 UNSET_RESERVED_WORD ("typeof");
336 UNSET_RESERVED_WORD ("signed");
337 UNSET_RESERVED_WORD ("inline");
338 UNSET_RESERVED_WORD ("iterator");
339 UNSET_RESERVED_WORD ("complex");
341 else if (!flag_isoc9x)
342 UNSET_RESERVED_WORD ("restrict");
344 if (flag_no_asm)
346 UNSET_RESERVED_WORD ("asm");
347 UNSET_RESERVED_WORD ("typeof");
348 UNSET_RESERVED_WORD ("inline");
349 UNSET_RESERVED_WORD ("iterator");
350 UNSET_RESERVED_WORD ("complex");
354 void
355 reinit_parse_for_function ()
359 /* Function used when yydebug is set, to print a token in more detail. */
361 void
362 yyprint (file, yychar, yylval)
363 FILE *file;
364 int yychar;
365 YYSTYPE yylval;
367 tree t;
368 switch (yychar)
370 case IDENTIFIER:
371 case TYPENAME:
372 case OBJECTNAME:
373 t = yylval.ttype;
374 if (IDENTIFIER_POINTER (t))
375 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
376 break;
378 case CONSTANT:
379 t = yylval.ttype;
380 if (TREE_CODE (t) == INTEGER_CST)
381 fprintf (file,
382 #if HOST_BITS_PER_WIDE_INT == 64
383 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
384 " 0x%x%016x",
385 #else
386 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
387 " 0x%lx%016lx",
388 #else
389 " 0x%llx%016llx",
390 #endif
391 #endif
392 #else
393 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
394 " 0x%lx%08lx",
395 #else
396 " 0x%x%08x",
397 #endif
398 #endif
399 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
400 break;
404 /* Iff C is a carriage return, warn about it - if appropriate -
405 and return nonzero. */
406 static int
407 whitespace_cr (c)
408 int c;
410 static int newline_warning = 0;
412 if (c == '\r')
414 /* ANSI C says the effects of a carriage return in a source file
415 are undefined. */
416 if (pedantic && !newline_warning)
418 warning ("carriage return in source file");
419 warning ("(we only warn about the first carriage return)");
420 newline_warning = 1;
422 return 1;
424 return 0;
427 /* If C is not whitespace, return C.
428 Otherwise skip whitespace and return first nonwhite char read. */
430 static int
431 skip_white_space (c)
432 register int c;
434 for (;;)
436 switch (c)
438 /* We don't recognize comments here, because
439 cpp output can include / and * consecutively as operators.
440 Also, there's no need, since cpp removes all comments. */
442 case '\n':
443 if (linemode)
445 UNGETC (c);
446 return EOF;
448 c = check_newline ();
449 break;
451 case ' ':
452 case '\t':
453 case '\f':
454 case '\v':
455 case '\b':
456 #if USE_CPPLIB
457 /* While processing a # directive we don't get CPP_HSPACE
458 tokens, so we also need to handle whitespace the normal way. */
459 if (cpp_token == CPP_HSPACE)
460 c = yy_get_token ();
461 else
462 #endif
463 c = GETC();
464 break;
466 case '\r':
467 whitespace_cr (c);
468 c = GETC();
469 break;
471 case '\\':
472 c = GETC();
473 if (c == '\n')
474 lineno++;
475 else
476 error ("stray '\\' in program");
477 c = GETC();
478 break;
480 default:
481 return (c);
486 /* Skips all of the white space at the current location in the input file. */
488 void
489 position_after_white_space ()
491 register int c;
493 c = GETC();
495 UNGETC (skip_white_space (c));
498 /* Make the token buffer longer, preserving the data in it.
499 P should point to just beyond the last valid character in the old buffer.
500 The value we return is a pointer to the new buffer
501 at a place corresponding to P. */
503 static void
504 extend_token_buffer_to (size)
505 int size;
508 maxtoken = maxtoken * 2 + 10;
509 while (maxtoken < size);
510 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
513 static char *
514 extend_token_buffer (p)
515 const char *p;
517 int offset = p - token_buffer;
518 extend_token_buffer_to (offset);
519 return token_buffer + offset;
522 #if defined HANDLE_PRAGMA
523 /* Local versions of these macros, that can be passed as function pointers. */
524 static int
525 pragma_getc ()
527 return GETC();
530 static void
531 pragma_ungetc (arg)
532 int arg;
534 UNGETC (arg);
536 #endif
538 static int
539 read_line_number (num)
540 int *num;
542 register int token = yylex ();
544 if (token == CONSTANT
545 && TREE_CODE (yylval.ttype) == INTEGER_CST)
547 *num = TREE_INT_CST_LOW (yylval.ttype);
548 return 1;
550 else
552 if (token != END_OF_LINE)
553 error ("invalid #-line");
554 return 0;
558 /* At the beginning of a line, increment the line number
559 and process any #-directive on this line.
560 If the line is a #-directive, read the entire line and return a newline.
561 Otherwise, return the line's first non-whitespace character.
563 Note that in the case of USE_CPPLIB, we get the whole line as one
564 CPP_DIRECTIVE token. */
567 check_newline ()
569 register int c;
570 register int token;
571 int saw_line;
572 enum { act_none, act_push, act_pop } action;
573 int old_lineno, action_number, l;
575 restart:
576 /* Read first nonwhite char on the line. */
578 #ifdef USE_CPPLIB
579 c = GETC ();
580 /* In some cases where we're leaving an include file, we can get multiple
581 CPP_HSPACE tokens in a row, so we need to loop. */
582 while (cpp_token == CPP_HSPACE)
583 c = yy_get_token ();
584 #else
586 c = GETC ();
587 while (c == ' ' || c == '\t');
588 #endif
590 lineno++;
592 if (c != '#')
594 /* Sequences of multiple newlines are very common; optimize them. */
595 if (c == '\n')
596 goto restart;
598 /* If not #, return it so caller will use it. */
599 return c;
602 /* Don't read beyond this line. */
603 saw_line = 0;
604 linemode = 1;
606 #if USE_CPPLIB
607 if (cpp_token == CPP_VSPACE)
609 /* Format is "<space> <line number> <filename> <newline>".
610 Only the line number is interesting, and even that
611 we can get more efficiently than scanning the line. */
612 yy_cur = yy_lim - 1;
613 lineno = parse_in.lineno - 1;
614 goto skipline;
616 #endif
618 token = yylex ();
620 if (token == IDENTIFIER)
622 /* If a letter follows, then if the word here is `line', skip
623 it and ignore it; otherwise, ignore the line, with an error
624 if the word isn't `pragma'. */
626 const char *name = IDENTIFIER_POINTER (yylval.ttype);
628 if (!strcmp (name, "pragma"))
630 token = yylex ();
631 if (token != IDENTIFIER
632 || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
633 goto skipline;
635 #ifdef HANDLE_PRAGMA
636 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
637 (if both are defined), in order to give the back
638 end a chance to override the interpretation of
639 SYSV style pragmas. */
640 if (HANDLE_PRAGMA (getch, put_back,
641 IDENTIFIER_POINTER (yylval.ttype)))
642 goto skipline;
643 #endif /* HANDLE_PRAGMA */
645 #ifdef HANDLE_GENERIC_PRAGMAS
646 if (handle_generic_pragma (token))
647 goto skipline;
648 #endif /* HANDLE_GENERIC_PRAGMAS */
650 /* Issue a warning message if we have been asked to do so.
651 Ignoring unknown pragmas in system header file unless
652 an explcit -Wunknown-pragmas has been given. */
653 if (warn_unknown_pragmas > 1
654 || (warn_unknown_pragmas && ! in_system_header))
655 warning ("ignoring pragma: %s", token_buffer);
657 goto skipline;
659 else if (!strcmp (name, "define"))
661 debug_define (lineno, GET_DIRECTIVE_LINE ());
662 goto skipline;
664 else if (!strcmp (name, "undef"))
666 debug_undef (lineno, GET_DIRECTIVE_LINE ());
667 goto skipline;
669 else if (!strcmp (name, "line"))
671 saw_line = 1;
672 token = yylex ();
673 goto linenum;
675 else if (!strcmp (name, "ident"))
677 /* #ident. The pedantic warning is now in cccp.c. */
679 /* Here we have just seen `#ident '.
680 A string constant should follow. */
682 token = yylex ();
683 if (token == END_OF_LINE)
684 goto skipline;
685 if (token != STRING
686 || TREE_CODE (yylval.ttype) != STRING_CST)
688 error ("invalid #ident");
689 goto skipline;
692 if (! flag_no_ident)
694 #ifdef ASM_OUTPUT_IDENT
695 ASM_OUTPUT_IDENT (asm_out_file,
696 TREE_STRING_POINTER (yylval.ttype));
697 #endif
700 /* Skip the rest of this line. */
701 goto skipline;
704 error ("undefined or invalid # directive `%s'", name);
705 goto skipline;
708 /* If the # is the only nonwhite char on the line,
709 just ignore it. Check the new newline. */
710 if (token == END_OF_LINE)
711 goto skipline;
713 linenum:
714 /* Here we have either `#line' or `# <nonletter>'.
715 In either case, it should be a line number; a digit should follow. */
717 if (token != CONSTANT
718 || TREE_CODE (yylval.ttype) != INTEGER_CST)
720 error ("invalid #-line");
721 goto skipline;
724 /* subtract one, because it is the following line that
725 gets the specified number */
727 l = TREE_INT_CST_LOW (yylval.ttype) - 1;
729 /* More follows: it must be a string constant (filename).
730 It would be neat to use cpplib to quickly process the string, but
731 (1) we don't have a handy tokenization of the string, and
732 (2) I don't know how well that would work in the presense
733 of filenames that contain wide characters. */
735 if (saw_line)
737 /* Don't treat \ as special if we are processing #line 1 "...".
738 If you want it to be treated specially, use # 1 "...". */
739 ignore_escape_flag = 1;
742 /* Read the string constant. */
743 token = yylex ();
745 ignore_escape_flag = 0;
747 if (token == END_OF_LINE)
749 /* No more: store the line number and check following line. */
750 lineno = l;
751 goto skipline;
754 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
756 error ("invalid #line");
757 goto skipline;
760 if (! ggc_p && !TREE_PERMANENT (yylval.ttype))
762 input_filename
763 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
764 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
766 else
767 input_filename = TREE_STRING_POINTER (yylval.ttype);
769 if (main_input_filename == 0)
770 main_input_filename = input_filename;
772 old_lineno = lineno;
773 action = act_none;
774 action_number = 0;
775 lineno = l;
777 /* Each change of file name
778 reinitializes whether we are now in a system header. */
779 in_system_header = 0;
781 if (!read_line_number (&action_number))
783 /* Update the name in the top element of input_file_stack. */
784 if (input_file_stack)
785 input_file_stack->name = input_filename;
788 /* `1' after file name means entering new file.
789 `2' after file name means just left a file. */
791 if (action_number == 1)
793 action = act_push;
794 read_line_number (&action_number);
796 else if (action_number == 2)
798 action = act_pop;
799 read_line_number (&action_number);
801 if (action_number == 3)
803 /* `3' after file name means this is a system header file. */
804 in_system_header = 1;
805 read_line_number (&action_number);
808 /* Do the actions implied by the preceding numbers. */
810 if (action == act_push)
812 /* Pushing to a new file. */
813 struct file_stack *p
814 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
815 input_file_stack->line = old_lineno;
816 p->next = input_file_stack;
817 p->name = input_filename;
818 p->indent_level = indent_level;
819 input_file_stack = p;
820 input_file_stack_tick++;
821 debug_start_source_file (input_filename);
823 else if (action == act_pop)
825 /* Popping out of a file. */
826 if (input_file_stack->next)
828 struct file_stack *p = input_file_stack;
829 if (indent_level != p->indent_level)
831 warning_with_file_and_line
832 (p->name, old_lineno,
833 "This file contains more `%c's than `%c's.",
834 indent_level > p->indent_level ? '{' : '}',
835 indent_level > p->indent_level ? '}' : '{');
837 input_file_stack = p->next;
838 free (p);
839 input_file_stack_tick++;
840 debug_end_source_file (input_file_stack->line);
842 else
843 error ("#-lines for entering and leaving files don't match");
846 /* Now that we've pushed or popped the input stack,
847 update the name in the top element. */
848 if (input_file_stack)
849 input_file_stack->name = input_filename;
851 /* skip the rest of this line. */
852 skipline:
853 linemode = 0;
854 end_of_file = 0;
857 c = GETC();
858 while (c != '\n' && c != EOF);
859 return c;
862 #ifdef HANDLE_GENERIC_PRAGMAS
864 /* Handle a #pragma directive.
865 TOKEN is the token we read after `#pragma'. Processes the entire input
866 line and return non-zero iff the pragma has been successfully parsed. */
868 /* This function has to be in this file, in order to get at
869 the token types. */
871 static int
872 handle_generic_pragma (token)
873 register int token;
875 for (;;)
877 switch (token)
879 case IDENTIFIER:
880 case TYPENAME:
881 case STRING:
882 case CONSTANT:
883 handle_pragma_token (token_buffer, yylval.ttype);
884 break;
886 case END_OF_LINE:
887 return handle_pragma_token (NULL_PTR, NULL_TREE);
889 default:
890 handle_pragma_token (token_buffer, NULL);
893 token = yylex ();
897 #endif /* HANDLE_GENERIC_PRAGMAS */
899 #define ENDFILE -1 /* token that represents end-of-file */
901 /* Read an escape sequence, returning its equivalent as a character,
902 or store 1 in *ignore_ptr if it is backslash-newline. */
904 static int
905 readescape (ignore_ptr)
906 int *ignore_ptr;
908 register int c = GETC();
909 register int code;
910 register unsigned count;
911 unsigned firstdig = 0;
912 int nonnull;
914 switch (c)
916 case 'x':
917 if (warn_traditional)
918 warning ("the meaning of `\\x' varies with -traditional");
920 if (flag_traditional)
921 return c;
923 code = 0;
924 count = 0;
925 nonnull = 0;
926 while (1)
928 c = GETC();
929 if (! ISXDIGIT (c))
931 UNGETC (c);
932 break;
934 code *= 16;
935 if (c >= 'a' && c <= 'f')
936 code += c - 'a' + 10;
937 if (c >= 'A' && c <= 'F')
938 code += c - 'A' + 10;
939 if (c >= '0' && c <= '9')
940 code += c - '0';
941 if (code != 0 || count != 0)
943 if (count == 0)
944 firstdig = code;
945 count++;
947 nonnull = 1;
949 if (! nonnull)
950 error ("\\x used with no following hex digits");
951 else if (count == 0)
952 /* Digits are all 0's. Ok. */
954 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
955 || (count > 1
956 && (((unsigned)1
957 << (TYPE_PRECISION (integer_type_node)
958 - (count - 1) * 4))
959 <= firstdig)))
960 pedwarn ("hex escape out of range");
961 return code;
963 case '0': case '1': case '2': case '3': case '4':
964 case '5': case '6': case '7':
965 code = 0;
966 count = 0;
967 while ((c <= '7') && (c >= '0') && (count++ < 3))
969 code = (code * 8) + (c - '0');
970 c = GETC();
972 UNGETC (c);
973 return code;
975 case '\\': case '\'': case '"':
976 return c;
978 case '\n':
979 lineno++;
980 *ignore_ptr = 1;
981 return 0;
983 case 'n':
984 return TARGET_NEWLINE;
986 case 't':
987 return TARGET_TAB;
989 case 'r':
990 return TARGET_CR;
992 case 'f':
993 return TARGET_FF;
995 case 'b':
996 return TARGET_BS;
998 case 'a':
999 if (warn_traditional)
1000 warning ("the meaning of `\\a' varies with -traditional");
1002 if (flag_traditional)
1003 return c;
1004 return TARGET_BELL;
1006 case 'v':
1007 #if 0 /* Vertical tab is present in common usage compilers. */
1008 if (flag_traditional)
1009 return c;
1010 #endif
1011 return TARGET_VT;
1013 case 'e':
1014 case 'E':
1015 if (pedantic)
1016 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1017 return TARGET_ESC;
1019 case '?':
1020 return c;
1022 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1023 case '(':
1024 case '{':
1025 case '[':
1026 /* `\%' is used to prevent SCCS from getting confused. */
1027 case '%':
1028 if (pedantic)
1029 pedwarn ("unknown escape sequence `\\%c'", c);
1030 return c;
1032 if (ISGRAPH (c))
1033 pedwarn ("unknown escape sequence `\\%c'", c);
1034 else
1035 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1036 return c;
1039 void
1040 yyerror (msgid)
1041 const char *msgid;
1043 const char *string = _(msgid);
1045 /* We can't print string and character constants well
1046 because the token_buffer contains the result of processing escapes. */
1047 if (end_of_file)
1048 error ("%s at end of input", string);
1049 else if (token_buffer[0] == 0)
1050 error ("%s at null character", string);
1051 else if (token_buffer[0] == '"')
1052 error ("%s before string constant", string);
1053 else if (token_buffer[0] == '\'')
1054 error ("%s before character constant", string);
1055 else if (!ISGRAPH(token_buffer[0]))
1056 error ("%s before character 0%o", string, (unsigned char) token_buffer[0]);
1057 else
1058 error ("%s before `%s'", string, token_buffer);
1061 #if 0
1063 struct try_type
1065 tree *node_var;
1066 char unsigned_flag;
1067 char long_flag;
1068 char long_long_flag;
1071 struct try_type type_sequence[] =
1073 { &integer_type_node, 0, 0, 0},
1074 { &unsigned_type_node, 1, 0, 0},
1075 { &long_integer_type_node, 0, 1, 0},
1076 { &long_unsigned_type_node, 1, 1, 0},
1077 { &long_long_integer_type_node, 0, 1, 1},
1078 { &long_long_unsigned_type_node, 1, 1, 1}
1080 #endif /* 0 */
1082 struct pf_args
1084 /* Input */
1085 int base;
1086 char * p;
1087 /* I/O */
1088 int c;
1089 /* Output */
1090 int imag;
1091 tree type;
1092 int conversion_errno;
1093 REAL_VALUE_TYPE value;
1096 static void
1097 parse_float (data)
1098 PTR data;
1100 struct pf_args * args = (struct pf_args *) data;
1101 int fflag = 0, lflag = 0;
1102 /* Copy token_buffer now, while it has just the number
1103 and not the suffixes; once we add `f' or `i',
1104 REAL_VALUE_ATOF may not work any more. */
1105 char *copy = (char *) alloca (args->p - token_buffer + 1);
1106 bcopy (token_buffer, copy, args->p - token_buffer + 1);
1107 args->imag = 0;
1108 args->conversion_errno = 0;
1109 args->type = double_type_node;
1111 while (1)
1113 int lose = 0;
1115 /* Read the suffixes to choose a data type. */
1116 switch (args->c)
1118 case 'f': case 'F':
1119 if (fflag)
1120 error ("more than one `f' in numeric constant");
1121 fflag = 1;
1122 break;
1124 case 'l': case 'L':
1125 if (lflag)
1126 error ("more than one `l' in numeric constant");
1127 lflag = 1;
1128 break;
1130 case 'i': case 'I':
1131 if (args->imag)
1132 error ("more than one `i' or `j' in numeric constant");
1133 else if (pedantic)
1134 pedwarn ("ANSI C forbids imaginary numeric constants");
1135 args->imag = 1;
1136 break;
1138 default:
1139 lose = 1;
1142 if (lose)
1143 break;
1145 if (args->p >= token_buffer + maxtoken - 3)
1146 args->p = extend_token_buffer (args->p);
1147 *(args->p++) = args->c;
1148 *(args->p) = 0;
1149 args->c = GETC();
1152 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1153 tells the desired precision of the binary result
1154 of decimal-to-binary conversion. */
1156 if (fflag)
1158 if (lflag)
1159 error ("both `f' and `l' in floating constant");
1161 args->type = float_type_node;
1162 errno = 0;
1163 if (args->base == 16)
1164 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
1165 else
1166 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
1167 args->conversion_errno = errno;
1168 /* A diagnostic is required here by some ANSI C testsuites.
1169 This is not pedwarn, because some people don't want
1170 an error for this. */
1171 if (REAL_VALUE_ISINF (args->value) && pedantic)
1172 warning ("floating point number exceeds range of `float'");
1174 else if (lflag)
1176 args->type = long_double_type_node;
1177 errno = 0;
1178 if (args->base == 16)
1179 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
1180 else
1181 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
1182 args->conversion_errno = errno;
1183 if (REAL_VALUE_ISINF (args->value) && pedantic)
1184 warning ("floating point number exceeds range of `long double'");
1186 else
1188 errno = 0;
1189 if (args->base == 16)
1190 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
1191 else
1192 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
1193 args->conversion_errno = errno;
1194 if (REAL_VALUE_ISINF (args->value) && pedantic)
1195 warning ("floating point number exceeds range of `double'");
1199 /* Get the next character, staying within the current token if possible.
1200 If we're lexing a token, we don't want to look beyond the end of the
1201 token cpplib has prepared for us; otherwise, we end up reading in the
1202 next token, which screws up feed_input. So just return a null
1203 character. */
1205 inline int
1206 token_getch ()
1208 #if USE_CPPLIB
1209 if (yy_cur == yy_lim)
1210 return '\0';
1211 #endif
1212 return GETC ();
1215 inline void
1216 token_put_back (ch)
1217 int ch;
1219 #if USE_CPPLIB
1220 if (ch == '\0')
1221 return;
1222 #endif
1223 UNGETC (ch);
1226 /* Read a single token from the input stream, and assign it lexical
1227 semantics. */
1230 yylex ()
1232 register int c;
1233 register char *p;
1234 register int value;
1235 int wide_flag = 0;
1236 int objc_flag = 0;
1238 c = GETC();
1240 /* Effectively do c = skip_white_space (c)
1241 but do it faster in the usual cases. */
1242 while (1)
1243 switch (c)
1245 case ' ':
1246 case '\t':
1247 case '\f':
1248 case '\v':
1249 case '\b':
1250 #if USE_CPPLIB
1251 if (cpp_token == CPP_HSPACE)
1252 c = yy_get_token ();
1253 else
1254 #endif
1255 c = GETC();
1256 break;
1258 case '\r':
1259 /* Call skip_white_space so we can warn if appropriate. */
1261 case '\n':
1262 case '/':
1263 case '\\':
1264 c = skip_white_space (c);
1265 default:
1266 goto found_nonwhite;
1268 found_nonwhite:
1270 token_buffer[0] = c;
1271 token_buffer[1] = 0;
1273 /* yylloc.first_line = lineno; */
1275 switch (c)
1277 case EOF:
1278 end_of_file = 1;
1279 token_buffer[0] = 0;
1280 if (linemode)
1281 value = END_OF_LINE;
1282 else
1283 value = ENDFILE;
1284 break;
1286 case 'L':
1287 #if USE_CPPLIB
1288 if (cpp_token == CPP_NAME)
1289 goto letter;
1290 #endif
1291 /* Capital L may start a wide-string or wide-character constant. */
1293 register int c = token_getch();
1294 if (c == '\'')
1296 wide_flag = 1;
1297 goto char_constant;
1299 if (c == '"')
1301 wide_flag = 1;
1302 goto string_constant;
1304 token_put_back (c);
1306 goto letter;
1308 case '@':
1309 if (!doing_objc_thang)
1311 value = c;
1312 break;
1314 else
1316 /* '@' may start a constant string object. */
1317 register int c = token_getch ();
1318 if (c == '"')
1320 objc_flag = 1;
1321 goto string_constant;
1323 token_put_back (c);
1324 /* Fall through to treat '@' as the start of an identifier. */
1327 case 'A': case 'B': case 'C': case 'D': case 'E':
1328 case 'F': case 'G': case 'H': case 'I': case 'J':
1329 case 'K': case 'M': case 'N': case 'O':
1330 case 'P': case 'Q': case 'R': case 'S': case 'T':
1331 case 'U': case 'V': case 'W': case 'X': case 'Y':
1332 case 'Z':
1333 case 'a': case 'b': case 'c': case 'd': case 'e':
1334 case 'f': case 'g': case 'h': case 'i': case 'j':
1335 case 'k': case 'l': case 'm': case 'n': case 'o':
1336 case 'p': case 'q': case 'r': case 's': case 't':
1337 case 'u': case 'v': case 'w': case 'x': case 'y':
1338 case 'z':
1339 case '_':
1340 case '$':
1341 letter:
1342 #if USE_CPPLIB
1343 if (cpp_token == CPP_NAME)
1345 /* Note that one character has already been read from
1346 yy_cur into token_buffer. Also, cpplib complains about
1347 $ in identifiers, so we don't have to. */
1349 int len = yy_lim - yy_cur + 1;
1350 if (len >= maxtoken)
1351 extend_token_buffer_to (len + 1);
1352 memcpy (token_buffer + 1, yy_cur, len);
1353 p = token_buffer + len;
1354 yy_cur = yy_lim;
1356 else
1357 #endif
1359 p = token_buffer;
1360 while (ISALNUM (c) || c == '_' || c == '$' || c == '@')
1362 /* Make sure this char really belongs in an identifier. */
1363 if (c == '$')
1365 if (! dollars_in_ident)
1366 error ("`$' in identifier");
1367 else if (pedantic)
1368 pedwarn ("`$' in identifier");
1371 if (p >= token_buffer + maxtoken)
1372 p = extend_token_buffer (p);
1374 *p++ = c;
1375 c = token_getch();
1378 *p = 0;
1379 token_put_back (c);
1382 value = IDENTIFIER;
1383 yylval.itype = 0;
1385 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1388 register struct resword *ptr;
1390 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
1392 if (ptr->rid)
1393 yylval.ttype = ridpointers[(int) ptr->rid];
1394 value = (int) ptr->token;
1396 /* Only return OBJECTNAME if it is a typedef. */
1397 if (doing_objc_thang && value == OBJECTNAME)
1399 lastiddecl = lookup_name(yylval.ttype);
1401 if (lastiddecl == NULL_TREE
1402 || TREE_CODE (lastiddecl) != TYPE_DECL)
1403 value = IDENTIFIER;
1406 /* Even if we decided to recognize asm, still perhaps warn. */
1407 if (pedantic
1408 && (value == ASM_KEYWORD || value == TYPEOF
1409 || ptr->rid == RID_INLINE)
1410 && token_buffer[0] != '_')
1411 pedwarn ("ANSI does not permit the keyword `%s'",
1412 token_buffer);
1416 /* If we did not find a keyword, look for an identifier
1417 (or a typename). */
1419 if (value == IDENTIFIER)
1421 if (token_buffer[0] == '@')
1422 error("invalid identifier `%s'", token_buffer);
1424 yylval.ttype = get_identifier (token_buffer);
1425 lastiddecl = lookup_name (yylval.ttype);
1427 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1428 value = TYPENAME;
1429 /* A user-invisible read-only initialized variable
1430 should be replaced by its value.
1431 We handle only strings since that's the only case used in C. */
1432 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1433 && DECL_IGNORED_P (lastiddecl)
1434 && TREE_READONLY (lastiddecl)
1435 && DECL_INITIAL (lastiddecl) != 0
1436 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1438 tree stringval = DECL_INITIAL (lastiddecl);
1440 /* Copy the string value so that we won't clobber anything
1441 if we put something in the TREE_CHAIN of this one. */
1442 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1443 TREE_STRING_POINTER (stringval));
1444 value = STRING;
1446 else if (doing_objc_thang)
1448 tree objc_interface_decl = is_class_name (yylval.ttype);
1450 if (objc_interface_decl)
1452 value = CLASSNAME;
1453 yylval.ttype = objc_interface_decl;
1458 break;
1460 case '.':
1461 #if USE_CPPLIB
1462 if (yy_cur < yy_lim)
1463 #endif
1465 /* It's hard to preserve tokenization on '.' because
1466 it could be a symbol by itself, or it could be the
1467 start of a floating point number and cpp won't tell us. */
1468 register int c1 = token_getch ();
1469 token_buffer[1] = c1;
1470 if (c1 == '.')
1472 c1 = token_getch ();
1473 if (c1 == '.')
1475 token_buffer[2] = c1;
1476 token_buffer[3] = 0;
1477 value = ELLIPSIS;
1478 goto done;
1480 error ("parse error at `..'");
1482 if (ISDIGIT (c1))
1484 token_put_back (c1);
1485 goto number;
1487 token_put_back (c1);
1489 value = '.';
1490 token_buffer[1] = 0;
1491 break;
1493 case '0': case '1':
1494 /* Optimize for most frequent case. */
1496 register int cond;
1498 #if USE_CPPLIB
1499 cond = (yy_cur == yy_lim);
1500 #else
1501 register int c1 = token_getch ();
1502 token_put_back (c1);
1503 cond = (! ISALNUM (c1) && c1 != '.');
1504 #endif
1505 if (cond)
1507 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1508 value = CONSTANT;
1509 break;
1511 /*FALLTHRU*/
1513 case '2': case '3': case '4':
1514 case '5': case '6': case '7': case '8': case '9':
1515 number:
1517 int base = 10;
1518 int count = 0;
1519 int largest_digit = 0;
1520 int numdigits = 0;
1521 int overflow = 0;
1523 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
1524 The code below which fills the parts array assumes that a host
1525 int is at least twice as wide as a host char, and that
1526 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
1527 Two HOST_WIDE_INTs is the largest int literal we can store.
1528 In order to detect overflow below, the number of parts (TOTAL_PARTS)
1529 must be exactly the number of parts needed to hold the bits
1530 of two HOST_WIDE_INTs. */
1531 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
1532 unsigned int parts[TOTAL_PARTS];
1534 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON}
1535 floatflag = NOT_FLOAT;
1537 for (count = 0; count < TOTAL_PARTS; count++)
1538 parts[count] = 0;
1540 p = token_buffer;
1541 *p++ = c;
1543 if (c == '0')
1545 *p++ = (c = token_getch());
1546 if ((c == 'x') || (c == 'X'))
1548 base = 16;
1549 *p++ = (c = token_getch());
1551 /* Leading 0 forces octal unless the 0 is the only digit. */
1552 else if (c >= '0' && c <= '9')
1554 base = 8;
1555 numdigits++;
1557 else
1558 numdigits++;
1561 /* Read all the digits-and-decimal-points. */
1563 while (c == '.'
1564 || (ISALNUM (c) && c != 'l' && c != 'L'
1565 && c != 'u' && c != 'U'
1566 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1567 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1569 if (c == '.')
1571 if (base == 16 && pedantic)
1572 pedwarn ("floating constant may not be in radix 16");
1573 if (floatflag == TOO_MANY_POINTS)
1574 /* We have already emitted an error. Don't need another. */
1576 else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON)
1578 error ("malformed floating constant");
1579 floatflag = TOO_MANY_POINTS;
1580 /* Avoid another error from atof by forcing all characters
1581 from here on to be ignored. */
1582 p[-1] = '\0';
1584 else
1585 floatflag = AFTER_POINT;
1587 if (base == 8)
1588 base = 10;
1589 *p++ = c = token_getch();
1590 /* Accept '.' as the start of a floating-point number
1591 only when it is followed by a digit. */
1592 if (p == token_buffer + 2 && !ISDIGIT (c))
1593 abort ();
1595 else
1597 /* It is not a decimal point.
1598 It should be a digit (perhaps a hex digit). */
1600 if (ISDIGIT (c))
1602 c = c - '0';
1604 else if (base <= 10)
1606 if (c == 'e' || c == 'E')
1608 base = 10;
1609 floatflag = AFTER_EXPON;
1610 break; /* start of exponent */
1612 error ("nondigits in number and not hexadecimal");
1613 c = 0;
1615 else if (base == 16 && (c == 'p' || c == 'P'))
1617 floatflag = AFTER_EXPON;
1618 break; /* start of exponent */
1620 else if (c >= 'a')
1622 c = c - 'a' + 10;
1624 else
1626 c = c - 'A' + 10;
1628 if (c >= largest_digit)
1629 largest_digit = c;
1630 numdigits++;
1632 for (count = 0; count < TOTAL_PARTS; count++)
1634 parts[count] *= base;
1635 if (count)
1637 parts[count]
1638 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1639 parts[count-1]
1640 &= (1 << HOST_BITS_PER_CHAR) - 1;
1642 else
1643 parts[0] += c;
1646 /* If the highest-order part overflows (gets larger than
1647 a host char will hold) then the whole number has
1648 overflowed. Record this and truncate the highest-order
1649 part. */
1650 if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
1652 overflow = 1;
1653 parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
1656 if (p >= token_buffer + maxtoken - 3)
1657 p = extend_token_buffer (p);
1658 *p++ = (c = token_getch());
1662 /* This can happen on input like `int i = 0x;' */
1663 if (numdigits == 0)
1664 error ("numeric constant with no digits");
1666 if (largest_digit >= base)
1667 error ("numeric constant contains digits beyond the radix");
1669 /* Remove terminating char from the token buffer and delimit the
1670 string. */
1671 *--p = 0;
1673 if (floatflag != NOT_FLOAT)
1675 tree type;
1676 int imag, conversion_errno;
1677 REAL_VALUE_TYPE value;
1678 struct pf_args args;
1680 /* Read explicit exponent if any, and put it in tokenbuf. */
1682 if ((base == 10 && ((c == 'e') || (c == 'E')))
1683 || (base == 16 && (c == 'p' || c == 'P')))
1685 if (p >= token_buffer + maxtoken - 3)
1686 p = extend_token_buffer (p);
1687 *p++ = c;
1688 c = token_getch();
1689 if ((c == '+') || (c == '-'))
1691 *p++ = c;
1692 c = token_getch();
1694 /* Exponent is decimal, even if string is a hex float. */
1695 if (! ISDIGIT (c))
1696 error ("floating constant exponent has no digits");
1697 while (ISDIGIT (c))
1699 if (p >= token_buffer + maxtoken - 3)
1700 p = extend_token_buffer (p);
1701 *p++ = c;
1702 c = token_getch ();
1705 if (base == 16 && floatflag != AFTER_EXPON)
1706 error ("hexadecimal floating constant has no exponent");
1708 *p = 0;
1710 /* Setup input for parse_float() */
1711 args.base = base;
1712 args.p = p;
1713 args.c = c;
1715 /* Convert string to a double, checking for overflow. */
1716 if (do_float_handler (parse_float, (PTR) &args))
1718 /* Receive output from parse_float() */
1719 value = args.value;
1721 else
1723 /* We got an exception from parse_float() */
1724 error ("floating constant out of range");
1725 value = dconst0;
1728 /* Receive output from parse_float() */
1729 c = args.c;
1730 imag = args.imag;
1731 type = args.type;
1732 conversion_errno = args.conversion_errno;
1734 #ifdef ERANGE
1735 /* ERANGE is also reported for underflow,
1736 so test the value to distinguish overflow from that. */
1737 if (conversion_errno == ERANGE && !flag_traditional && pedantic
1738 && (REAL_VALUES_LESS (dconst1, value)
1739 || REAL_VALUES_LESS (value, dconstm1)))
1740 warning ("floating point number exceeds range of `double'");
1741 #endif
1743 /* If the result is not a number, assume it must have been
1744 due to some error message above, so silently convert
1745 it to a zero. */
1746 if (REAL_VALUE_ISNAN (value))
1747 value = dconst0;
1749 /* Create a node with determined type and value. */
1750 if (imag)
1751 yylval.ttype = build_complex (NULL_TREE,
1752 convert (type, integer_zero_node),
1753 build_real (type, value));
1754 else
1755 yylval.ttype = build_real (type, value);
1757 else
1759 tree traditional_type, ansi_type, type;
1760 HOST_WIDE_INT high, low;
1761 int spec_unsigned = 0;
1762 int spec_long = 0;
1763 int spec_long_long = 0;
1764 int spec_imag = 0;
1765 int warn = 0, i;
1767 traditional_type = ansi_type = type = NULL_TREE;
1768 while (1)
1770 if (c == 'u' || c == 'U')
1772 if (spec_unsigned)
1773 error ("two `u's in integer constant");
1774 spec_unsigned = 1;
1776 else if (c == 'l' || c == 'L')
1778 if (spec_long)
1780 if (spec_long_long)
1781 error ("three `l's in integer constant");
1782 else if (pedantic && ! in_system_header && warn_long_long)
1783 pedwarn ("ANSI C forbids long long integer constants");
1784 spec_long_long = 1;
1786 spec_long = 1;
1788 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1790 if (spec_imag)
1791 error ("more than one `i' or `j' in numeric constant");
1792 else if (pedantic)
1793 pedwarn ("ANSI C forbids imaginary numeric constants");
1794 spec_imag = 1;
1796 else
1797 break;
1798 if (p >= token_buffer + maxtoken - 3)
1799 p = extend_token_buffer (p);
1800 *p++ = c;
1801 c = token_getch();
1804 /* If the literal overflowed, pedwarn about it now. */
1805 if (overflow)
1807 warn = 1;
1808 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2);
1811 /* This is simplified by the fact that our constant
1812 is always positive. */
1814 high = low = 0;
1816 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1818 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1819 / HOST_BITS_PER_CHAR)]
1820 << (i * HOST_BITS_PER_CHAR));
1821 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1824 yylval.ttype = build_int_2 (low, high);
1825 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1827 /* If warn_traditional, calculate both the ANSI type and the
1828 traditional type, then see if they disagree.
1829 Otherwise, calculate only the type for the dialect in use. */
1830 if (warn_traditional || flag_traditional)
1832 /* Calculate the traditional type. */
1833 /* Traditionally, any constant is signed;
1834 but if unsigned is specified explicitly, obey that.
1835 Use the smallest size with the right number of bits,
1836 except for one special case with decimal constants. */
1837 if (! spec_long && base != 10
1838 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1839 traditional_type = (spec_unsigned ? unsigned_type_node
1840 : integer_type_node);
1841 /* A decimal constant must be long
1842 if it does not fit in type int.
1843 I think this is independent of whether
1844 the constant is signed. */
1845 else if (! spec_long && base == 10
1846 && int_fits_type_p (yylval.ttype, integer_type_node))
1847 traditional_type = (spec_unsigned ? unsigned_type_node
1848 : integer_type_node);
1849 else if (! spec_long_long)
1850 traditional_type = (spec_unsigned ? long_unsigned_type_node
1851 : long_integer_type_node);
1852 else if (int_fits_type_p (yylval.ttype,
1853 spec_unsigned
1854 ? long_long_unsigned_type_node
1855 : long_long_integer_type_node))
1856 traditional_type = (spec_unsigned
1857 ? long_long_unsigned_type_node
1858 : long_long_integer_type_node);
1859 else
1860 traditional_type = (spec_unsigned
1861 ? widest_unsigned_literal_type_node
1862 : widest_integer_literal_type_node);
1864 if (warn_traditional || ! flag_traditional)
1866 /* Calculate the ANSI type. */
1867 if (! spec_long && ! spec_unsigned
1868 && int_fits_type_p (yylval.ttype, integer_type_node))
1869 ansi_type = integer_type_node;
1870 else if (! spec_long && (base != 10 || spec_unsigned)
1871 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1872 ansi_type = unsigned_type_node;
1873 else if (! spec_unsigned && !spec_long_long
1874 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1875 ansi_type = long_integer_type_node;
1876 else if (! spec_long_long
1877 && int_fits_type_p (yylval.ttype,
1878 long_unsigned_type_node))
1879 ansi_type = long_unsigned_type_node;
1880 else if (! spec_unsigned
1881 && int_fits_type_p (yylval.ttype,
1882 long_long_integer_type_node))
1883 ansi_type = long_long_integer_type_node;
1884 else if (int_fits_type_p (yylval.ttype,
1885 long_long_unsigned_type_node))
1886 ansi_type = long_long_unsigned_type_node;
1887 else if (! spec_unsigned
1888 && int_fits_type_p (yylval.ttype,
1889 widest_integer_literal_type_node))
1890 ansi_type = widest_integer_literal_type_node;
1891 else
1892 ansi_type = widest_unsigned_literal_type_node;
1895 type = flag_traditional ? traditional_type : ansi_type;
1897 if (warn_traditional && traditional_type != ansi_type)
1899 if (TYPE_PRECISION (traditional_type)
1900 != TYPE_PRECISION (ansi_type))
1901 warning ("width of integer constant changes with -traditional");
1902 else if (TREE_UNSIGNED (traditional_type)
1903 != TREE_UNSIGNED (ansi_type))
1904 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1905 else
1906 warning ("width of integer constant may change on other systems with -traditional");
1909 if (pedantic && !flag_traditional && !spec_long_long && !warn
1910 && (TYPE_PRECISION (long_integer_type_node)
1911 < TYPE_PRECISION (type)))
1913 warn = 1;
1914 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
1917 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1918 warning ("decimal constant is so large that it is unsigned");
1920 if (spec_imag)
1922 if (TYPE_PRECISION (type)
1923 <= TYPE_PRECISION (integer_type_node))
1924 yylval.ttype
1925 = build_complex (NULL_TREE, integer_zero_node,
1926 convert (integer_type_node,
1927 yylval.ttype));
1928 else
1929 error ("complex integer constant is too wide for `complex int'");
1931 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1932 /* The traditional constant 0x80000000 is signed
1933 but doesn't fit in the range of int.
1934 This will change it to -0x80000000, which does fit. */
1936 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1937 yylval.ttype = convert (type, yylval.ttype);
1938 TREE_OVERFLOW (yylval.ttype)
1939 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1941 else
1942 TREE_TYPE (yylval.ttype) = type;
1945 /* If it's still an integer (not a complex), and it doesn't
1946 fit in the type we choose for it, then pedwarn. */
1948 if (! warn
1949 && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE
1950 && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype)))
1951 pedwarn ("integer constant is larger than the maximum value for its type");
1954 token_put_back (c);
1955 *p = 0;
1957 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
1958 || (!flag_traditional && (c == '-' || c == '+')
1959 && (p[-1] == 'e' || p[-1] == 'E')))
1960 error ("missing white space after number `%s'", token_buffer);
1962 value = CONSTANT; break;
1965 case '\'':
1966 char_constant:
1968 register int result = 0;
1969 register int num_chars = 0;
1970 int chars_seen = 0;
1971 unsigned width = TYPE_PRECISION (char_type_node);
1972 int max_chars;
1973 #ifdef MULTIBYTE_CHARS
1974 int longest_char = local_mb_cur_max ();
1975 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
1976 #endif
1978 max_chars = TYPE_PRECISION (integer_type_node) / width;
1979 if (wide_flag)
1980 width = WCHAR_TYPE_SIZE;
1982 while (1)
1984 tryagain:
1985 c = token_getch();
1987 if (c == '\'' || c == EOF)
1988 break;
1990 ++chars_seen;
1991 if (c == '\\')
1993 int ignore = 0;
1994 c = readescape (&ignore);
1995 if (ignore)
1996 goto tryagain;
1997 if (width < HOST_BITS_PER_INT
1998 && (unsigned) c >= ((unsigned)1 << width))
1999 pedwarn ("escape sequence out of range for character");
2000 #ifdef MAP_CHARACTER
2001 if (ISPRINT (c))
2002 c = MAP_CHARACTER (c);
2003 #endif
2005 else if (c == '\n')
2007 if (pedantic)
2008 pedwarn ("ANSI C forbids newline in character constant");
2009 lineno++;
2011 else
2013 #ifdef MULTIBYTE_CHARS
2014 wchar_t wc;
2015 int i;
2016 int char_len = -1;
2017 for (i = 1; i <= longest_char; ++i)
2019 if (i > maxtoken - 4)
2020 extend_token_buffer (token_buffer);
2022 token_buffer[i] = c;
2023 char_len = local_mbtowc (& wc,
2024 token_buffer + 1,
2026 if (char_len != -1)
2027 break;
2028 c = token_getch ();
2030 if (char_len > 1)
2032 /* mbtowc sometimes needs an extra char before accepting */
2033 if (char_len < i)
2034 token_put_back (c);
2035 if (! wide_flag)
2037 /* Merge character into result; ignore excess chars. */
2038 for (i = 1; i <= char_len; ++i)
2040 if (i > max_chars)
2041 break;
2042 if (width < HOST_BITS_PER_INT)
2043 result = (result << width)
2044 | (token_buffer[i]
2045 & ((1 << width) - 1));
2046 else
2047 result = token_buffer[i];
2049 num_chars += char_len;
2050 goto tryagain;
2052 c = wc;
2054 else
2056 if (char_len == -1)
2058 warning ("Ignoring invalid multibyte character");
2059 /* Replace all but the first byte. */
2060 for (--i; i > 1; --i)
2061 token_put_back (token_buffer[i]);
2062 wc = token_buffer[1];
2064 #ifdef MAP_CHARACTER
2065 c = MAP_CHARACTER (wc);
2066 #else
2067 c = wc;
2068 #endif
2070 #else /* ! MULTIBYTE_CHARS */
2071 #ifdef MAP_CHARACTER
2072 c = MAP_CHARACTER (c);
2073 #endif
2074 #endif /* ! MULTIBYTE_CHARS */
2077 if (wide_flag)
2079 if (chars_seen == 1) /* only keep the first one */
2080 result = c;
2081 goto tryagain;
2084 /* Merge character into result; ignore excess chars. */
2085 num_chars += (width / TYPE_PRECISION (char_type_node));
2086 if (num_chars < max_chars + 1)
2088 if (width < HOST_BITS_PER_INT)
2089 result = (result << width) | (c & ((1 << width) - 1));
2090 else
2091 result = c;
2095 if (c != '\'')
2096 error ("malformed character constant");
2097 else if (chars_seen == 0)
2098 error ("empty character constant");
2099 else if (num_chars > max_chars)
2101 num_chars = max_chars;
2102 error ("character constant too long");
2104 else if (chars_seen != 1 && ! flag_traditional && warn_multichar)
2105 warning ("multi-character character constant");
2107 /* If char type is signed, sign-extend the constant. */
2108 if (! wide_flag)
2110 int num_bits = num_chars * width;
2111 if (num_bits == 0)
2112 /* We already got an error; avoid invalid shift. */
2113 yylval.ttype = build_int_2 (0, 0);
2114 else if (TREE_UNSIGNED (char_type_node)
2115 || ((result >> (num_bits - 1)) & 1) == 0)
2116 yylval.ttype
2117 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
2118 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
2120 else
2121 yylval.ttype
2122 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
2123 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
2124 -1);
2125 TREE_TYPE (yylval.ttype) = integer_type_node;
2127 else
2129 yylval.ttype = build_int_2 (result, 0);
2130 TREE_TYPE (yylval.ttype) = wchar_type_node;
2133 value = CONSTANT;
2134 break;
2137 case '"':
2138 string_constant:
2140 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
2141 : TYPE_PRECISION (char_type_node);
2142 #ifdef MULTIBYTE_CHARS
2143 int longest_char = local_mb_cur_max ();
2144 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
2145 #endif
2146 c = token_getch ();
2147 p = token_buffer + 1;
2149 while (c != '"' && c != EOF)
2151 /* ignore_escape_flag is set for reading the filename in #line. */
2152 if (!ignore_escape_flag && c == '\\')
2154 int ignore = 0;
2155 c = readescape (&ignore);
2156 if (ignore)
2157 goto skipnewline;
2158 if (width < HOST_BITS_PER_INT
2159 && (unsigned) c >= ((unsigned)1 << width))
2160 pedwarn ("escape sequence out of range for character");
2162 else if (c == '\n')
2164 if (pedantic)
2165 pedwarn ("ANSI C forbids newline in string constant");
2166 lineno++;
2168 else
2170 #ifdef MULTIBYTE_CHARS
2171 wchar_t wc;
2172 int i;
2173 int char_len = -1;
2174 for (i = 0; i < longest_char; ++i)
2176 if (p + i >= token_buffer + maxtoken)
2177 p = extend_token_buffer (p);
2178 p[i] = c;
2180 char_len = local_mbtowc (& wc, p, i + 1);
2181 if (char_len != -1)
2182 break;
2183 c = token_getch ();
2185 if (char_len == -1)
2187 warning ("Ignoring invalid multibyte character");
2188 /* Replace all except the first byte. */
2189 token_put_back (c);
2190 for (--i; i > 0; --i)
2191 token_put_back (p[i]);
2192 char_len = 1;
2194 /* mbtowc sometimes needs an extra char before accepting */
2195 if (char_len <= i)
2196 token_put_back (c);
2197 if (! wide_flag)
2199 p += (i + 1);
2200 c = token_getch ();
2201 continue;
2203 c = wc;
2204 #endif /* MULTIBYTE_CHARS */
2207 /* Add this single character into the buffer either as a wchar_t
2208 or as a single byte. */
2209 if (wide_flag)
2211 unsigned width = TYPE_PRECISION (char_type_node);
2212 unsigned bytemask = (1 << width) - 1;
2213 int byte;
2215 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2216 p = extend_token_buffer (p);
2218 for (byte = 0; byte < WCHAR_BYTES; ++byte)
2220 int value;
2221 if (byte >= (int) sizeof (c))
2222 value = 0;
2223 else
2224 value = (c >> (byte * width)) & bytemask;
2225 if (BYTES_BIG_ENDIAN)
2226 p[WCHAR_BYTES - byte - 1] = value;
2227 else
2228 p[byte] = value;
2230 p += WCHAR_BYTES;
2232 else
2234 if (p >= token_buffer + maxtoken)
2235 p = extend_token_buffer (p);
2236 *p++ = c;
2239 skipnewline:
2240 c = token_getch ();
2243 /* Terminate the string value, either with a single byte zero
2244 or with a wide zero. */
2245 if (wide_flag)
2247 if (p + WCHAR_BYTES > token_buffer + maxtoken)
2248 p = extend_token_buffer (p);
2249 bzero (p, WCHAR_BYTES);
2250 p += WCHAR_BYTES;
2252 else
2254 if (p >= token_buffer + maxtoken)
2255 p = extend_token_buffer (p);
2256 *p++ = 0;
2259 if (c == EOF)
2260 error ("Unterminated string constant");
2262 /* We have read the entire constant.
2263 Construct a STRING_CST for the result. */
2265 if (wide_flag)
2267 yylval.ttype = build_string (p - (token_buffer + 1),
2268 token_buffer + 1);
2269 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
2270 value = STRING;
2272 else if (objc_flag)
2274 /* Return an Objective-C @"..." constant string object. */
2275 yylval.ttype = build_objc_string (p - (token_buffer + 1),
2276 token_buffer + 1);
2277 TREE_TYPE (yylval.ttype) = char_array_type_node;
2278 value = OBJC_STRING;
2280 else
2282 yylval.ttype = build_string (p - (token_buffer + 1),
2283 token_buffer + 1);
2284 TREE_TYPE (yylval.ttype) = char_array_type_node;
2285 value = STRING;
2288 break;
2291 case '+':
2292 case '-':
2293 case '&':
2294 case '|':
2295 case ':':
2296 case '<':
2297 case '>':
2298 case '*':
2299 case '/':
2300 case '%':
2301 case '^':
2302 case '!':
2303 case '=':
2305 register int c1;
2307 combine:
2309 switch (c)
2311 case '+':
2312 yylval.code = PLUS_EXPR; break;
2313 case '-':
2314 yylval.code = MINUS_EXPR; break;
2315 case '&':
2316 yylval.code = BIT_AND_EXPR; break;
2317 case '|':
2318 yylval.code = BIT_IOR_EXPR; break;
2319 case '*':
2320 yylval.code = MULT_EXPR; break;
2321 case '/':
2322 yylval.code = TRUNC_DIV_EXPR; break;
2323 case '%':
2324 yylval.code = TRUNC_MOD_EXPR; break;
2325 case '^':
2326 yylval.code = BIT_XOR_EXPR; break;
2327 case LSHIFT:
2328 yylval.code = LSHIFT_EXPR; break;
2329 case RSHIFT:
2330 yylval.code = RSHIFT_EXPR; break;
2331 case '<':
2332 yylval.code = LT_EXPR; break;
2333 case '>':
2334 yylval.code = GT_EXPR; break;
2337 token_buffer[1] = c1 = token_getch();
2338 token_buffer[2] = 0;
2340 if (c1 == '=')
2342 switch (c)
2344 case '<':
2345 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2346 case '>':
2347 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2348 case '!':
2349 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2350 case '=':
2351 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2353 value = ASSIGN; goto done;
2355 else if (c == c1)
2356 switch (c)
2358 case '+':
2359 value = PLUSPLUS; goto done;
2360 case '-':
2361 value = MINUSMINUS; goto done;
2362 case '&':
2363 value = ANDAND; goto done;
2364 case '|':
2365 value = OROR; goto done;
2366 case '<':
2367 c = LSHIFT;
2368 goto combine;
2369 case '>':
2370 c = RSHIFT;
2371 goto combine;
2373 else
2374 switch (c)
2376 case '-':
2377 if (c1 == '>')
2378 { value = POINTSAT; goto done; }
2379 break;
2381 /* digraphs */
2382 case ':':
2383 if (c1 == '>')
2384 { value = ']'; goto done; }
2385 break;
2386 case '<':
2387 if (c1 == '%')
2388 { value = '{'; indent_level++; goto done; }
2389 if (c1 == ':')
2390 { value = '['; goto done; }
2391 break;
2392 case '%':
2393 if (c1 == '>')
2394 { value = '}'; indent_level--; goto done; }
2395 break;
2398 token_put_back (c1);
2399 token_buffer[1] = 0;
2401 if ((c == '<') || (c == '>'))
2402 value = ARITHCOMPARE;
2403 else value = c;
2404 break;
2407 case 0:
2408 /* Don't make yyparse think this is eof. */
2409 value = 1;
2410 break;
2412 case '{':
2413 indent_level++;
2414 value = c;
2415 break;
2417 case '}':
2418 indent_level--;
2419 value = c;
2420 break;
2422 default:
2423 value = c;
2426 done:
2427 /* yylloc.last_line = lineno; */
2429 return value;
2432 /* Sets the value of the 'yydebug' variable to VALUE.
2433 This is a function so we don't have to have YYDEBUG defined
2434 in order to build the compiler. */
2436 void
2437 set_yydebug (value)
2438 int value;
2440 #if YYDEBUG != 0
2441 yydebug = value;
2442 #else
2443 warning ("YYDEBUG not defined.");
2444 #endif