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