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