1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 88, 89, 92, 94, 95, 1996 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
38 #ifdef MULTIBYTE_CHARS
47 /* The elements of `ridpointers' are identifier nodes
48 for the reserved type names and storage classes.
49 It is indexed by a RID_... value. */
50 tree ridpointers[(int) RID_MAX];
52 /* Cause the `yydebug' variable to be defined. */
55 /* the declaration found for the last IDENTIFIER token read in.
56 yylex must look this up to detect typedefs, which get token type TYPENAME,
57 so it is left around in case the identifier is not a typedef but is
58 used in a context which makes it a reference to a variable. */
61 /* Nonzero enables objc features. */
65 extern tree is_class_name ();
69 /* File used for outputting assembler code. */
70 extern FILE *asm_out_file;
72 #ifndef WCHAR_TYPE_SIZE
74 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
76 #define WCHAR_TYPE_SIZE BITS_PER_WORD
80 /* Number of bytes in a wide character. */
81 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
83 static int maxtoken; /* Current nominal length of token buffer. */
84 char *token_buffer; /* Pointer to token buffer.
85 Actual allocated length is maxtoken + 2.
86 This is not static because objc-parse.y uses it. */
88 /* Nonzero if end-of-file has been seen on input. */
89 static int end_of_file;
91 /* Buffered-back input character; faster than using ungetc. */
92 static int nextchar = -1;
96 /* Do not insert generated code into the source, instead, include it.
97 This allows us to build gcc automatically even for targets that
98 need to add or modify the reserved keyword lists. */
101 /* Return something to represent absolute declarators containing a *.
102 TARGET is the absolute declarator that the * contains.
103 TYPE_QUALS is a list of modifiers such as const or volatile
104 to apply to the pointer type, represented as identifiers.
106 We return an INDIRECT_REF whose "contents" are TARGET
107 and whose type is the modifier list. */
110 make_pointer_declarator (type_quals, target)
111 tree type_quals, target;
113 return build1 (INDIRECT_REF, type_quals, target);
117 forget_protocol_qualifiers ()
119 int i, n = sizeof wordlist / sizeof (struct resword);
121 for (i = 0; i < n; i++)
122 if ((int) wordlist[i].rid >= (int) RID_IN
123 && (int) wordlist[i].rid <= (int) RID_ONEWAY)
124 wordlist[i].name = "";
128 remember_protocol_qualifiers ()
130 int i, n = sizeof wordlist / sizeof (struct resword);
132 for (i = 0; i < n; i++)
133 if (wordlist[i].rid == RID_IN)
134 wordlist[i].name = "in";
135 else if (wordlist[i].rid == RID_OUT)
136 wordlist[i].name = "out";
137 else if (wordlist[i].rid == RID_INOUT)
138 wordlist[i].name = "inout";
139 else if (wordlist[i].rid == RID_BYCOPY)
140 wordlist[i].name = "bycopy";
141 else if (wordlist[i].rid == RID_ONEWAY)
142 wordlist[i].name = "oneway";
148 /* Make identifier nodes long enough for the language-specific slots. */
149 set_identifier_size (sizeof (struct lang_identifier));
151 /* Start it at 0, because check_newline is called at the very beginning
152 and will increment it to 1. */
155 #ifdef MULTIBYTE_CHARS
156 /* Change to the native locale for multibyte conversions. */
157 setlocale (LC_CTYPE, "");
161 token_buffer = (char *) xmalloc (maxtoken + 2);
163 ridpointers[(int) RID_INT] = get_identifier ("int");
164 ridpointers[(int) RID_CHAR] = get_identifier ("char");
165 ridpointers[(int) RID_VOID] = get_identifier ("void");
166 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
167 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
168 ridpointers[(int) RID_SHORT] = get_identifier ("short");
169 ridpointers[(int) RID_LONG] = get_identifier ("long");
170 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
171 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
172 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
173 ridpointers[(int) RID_CONST] = get_identifier ("const");
174 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
175 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
176 ridpointers[(int) RID_STATIC] = get_identifier ("static");
177 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
178 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
179 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
180 ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator");
181 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
182 ridpointers[(int) RID_ID] = get_identifier ("id");
183 ridpointers[(int) RID_IN] = get_identifier ("in");
184 ridpointers[(int) RID_OUT] = get_identifier ("out");
185 ridpointers[(int) RID_INOUT] = get_identifier ("inout");
186 ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
187 ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
188 forget_protocol_qualifiers();
190 /* Some options inhibit certain reserved words.
191 Clear those words out of the hash table so they won't be recognized. */
192 #define UNSET_RESERVED_WORD(STRING) \
193 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
194 if (s) s->name = ""; } while (0)
196 if (! doing_objc_thang)
197 UNSET_RESERVED_WORD ("id");
199 if (flag_traditional)
201 UNSET_RESERVED_WORD ("const");
202 UNSET_RESERVED_WORD ("volatile");
203 UNSET_RESERVED_WORD ("typeof");
204 UNSET_RESERVED_WORD ("signed");
205 UNSET_RESERVED_WORD ("inline");
206 UNSET_RESERVED_WORD ("iterator");
207 UNSET_RESERVED_WORD ("complex");
211 UNSET_RESERVED_WORD ("asm");
212 UNSET_RESERVED_WORD ("typeof");
213 UNSET_RESERVED_WORD ("inline");
214 UNSET_RESERVED_WORD ("iterator");
215 UNSET_RESERVED_WORD ("complex");
220 reinit_parse_for_function ()
224 /* Function used when yydebug is set, to print a token in more detail. */
227 yyprint (file, yychar, yylval)
239 if (IDENTIFIER_POINTER (t))
240 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
245 if (TREE_CODE (t) == INTEGER_CST)
247 #if HOST_BITS_PER_WIDE_INT == 64
248 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
254 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
260 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
266 /* If C is not whitespace, return C.
267 Otherwise skip whitespace and return first nonwhite char read. */
273 static int newline_warning = 0;
279 /* We don't recognize comments here, because
280 cpp output can include / and * consecutively as operators.
281 Also, there's no need, since cpp removes all comments. */
284 c = check_newline ();
296 /* ANSI C says the effects of a carriage return in a source file
298 if (pedantic && !newline_warning)
300 warning ("carriage return in source file");
301 warning ("(we only warn about the first carriage return)");
312 error ("stray '\\' in program");
322 /* Skips all of the white space at the current location in the input file.
323 Must use and reset nextchar if it has the next character. */
326 position_after_white_space ()
331 c = nextchar, nextchar = -1;
335 ungetc (skip_white_space (c), finput);
338 /* Make the token buffer longer, preserving the data in it.
339 P should point to just beyond the last valid character in the old buffer.
340 The value we return is a pointer to the new buffer
341 at a place corresponding to P. */
344 extend_token_buffer (p)
347 int offset = p - token_buffer;
349 maxtoken = maxtoken * 2 + 10;
350 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
352 return token_buffer + offset;
355 /* At the beginning of a line, increment the line number
356 and process any #-directive on this line.
357 If the line is a #-directive, read the entire line and return a newline.
358 Otherwise, return the line's first non-whitespace character. */
368 /* Read first nonwhite char on the line. */
371 while (c == ' ' || c == '\t')
376 /* If not #, return it so caller will use it. */
380 /* Read first nonwhite char after the `#'. */
383 while (c == ' ' || c == '\t')
386 /* If a letter follows, then if the word here is `line', skip
387 it and ignore it; otherwise, ignore the line, with an error
388 if the word isn't `pragma', `ident', `define', or `undef'. */
390 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
394 if (getc (finput) == 'r'
395 && getc (finput) == 'a'
396 && getc (finput) == 'g'
397 && getc (finput) == 'm'
398 && getc (finput) == 'a'
399 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
401 while (c == ' ' || c == '\t')
405 #ifdef HANDLE_SYSV_PRAGMA
408 if (token != IDENTIFIER)
410 return handle_sysv_pragma (finput, token);
411 #else /* !HANDLE_SYSV_PRAGMA */
415 if (token != IDENTIFIER)
417 if (HANDLE_PRAGMA (finput, yylval.ttype))
422 #endif /* HANDLE_PRAGMA */
423 #endif /* !HANDLE_SYSV_PRAGMA */
430 if (getc (finput) == 'e'
431 && getc (finput) == 'f'
432 && getc (finput) == 'i'
433 && getc (finput) == 'n'
434 && getc (finput) == 'e'
435 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
437 #ifdef DWARF_DEBUGGING_INFO
439 && (debug_info_level == DINFO_LEVEL_VERBOSE)
440 && (write_symbols == DWARF_DEBUG))
441 dwarfout_define (lineno, get_directive_line (finput));
442 #endif /* DWARF_DEBUGGING_INFO */
448 if (getc (finput) == 'n'
449 && getc (finput) == 'd'
450 && getc (finput) == 'e'
451 && getc (finput) == 'f'
452 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
454 #ifdef DWARF_DEBUGGING_INFO
456 && (debug_info_level == DINFO_LEVEL_VERBOSE)
457 && (write_symbols == DWARF_DEBUG))
458 dwarfout_undef (lineno, get_directive_line (finput));
459 #endif /* DWARF_DEBUGGING_INFO */
465 if (getc (finput) == 'i'
466 && getc (finput) == 'n'
467 && getc (finput) == 'e'
468 && ((c = getc (finput)) == ' ' || c == '\t'))
473 if (getc (finput) == 'd'
474 && getc (finput) == 'e'
475 && getc (finput) == 'n'
476 && getc (finput) == 't'
477 && ((c = getc (finput)) == ' ' || c == '\t'))
479 /* #ident. The pedantic warning is now in cccp.c. */
481 /* Here we have just seen `#ident '.
482 A string constant should follow. */
484 while (c == ' ' || c == '\t')
487 /* If no argument, ignore the line. */
494 || TREE_CODE (yylval.ttype) != STRING_CST)
496 error ("invalid #ident");
502 #ifdef ASM_OUTPUT_IDENT
503 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
507 /* Skip the rest of this line. */
512 error ("undefined or invalid # directive");
517 /* Here we have either `#line' or `# <nonletter>'.
518 In either case, it should be a line number; a digit should follow. */
520 while (c == ' ' || c == '\t')
523 /* If the # is the only nonwhite char on the line,
524 just ignore it. Check the new newline. */
528 /* Something follows the #; read a token. */
533 if (token == CONSTANT
534 && TREE_CODE (yylval.ttype) == INTEGER_CST)
536 int old_lineno = lineno;
538 /* subtract one, because it is the following line that
539 gets the specified number */
541 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
543 /* Is this the last nonwhite stuff on the line? */
545 while (c == ' ' || c == '\t')
549 /* No more: store the line number and check following line. */
555 /* More follows: it must be a string constant (filename). */
557 /* Read the string constant. */
560 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
562 error ("invalid #line");
567 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
568 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
571 /* Each change of file name
572 reinitializes whether we are now in a system header. */
573 in_system_header = 0;
575 if (main_input_filename == 0)
576 main_input_filename = input_filename;
578 /* Is this the last nonwhite stuff on the line? */
580 while (c == ' ' || c == '\t')
584 /* Update the name in the top element of input_file_stack. */
585 if (input_file_stack)
586 input_file_stack->name = input_filename;
595 /* `1' after file name means entering new file.
596 `2' after file name means just left a file. */
598 if (token == CONSTANT
599 && TREE_CODE (yylval.ttype) == INTEGER_CST)
601 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
603 /* Pushing to a new file. */
605 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
606 input_file_stack->line = old_lineno;
607 p->next = input_file_stack;
608 p->name = input_filename;
609 input_file_stack = p;
610 input_file_stack_tick++;
611 #ifdef DBX_DEBUGGING_INFO
612 if (write_symbols == DBX_DEBUG)
613 dbxout_start_new_source_file (input_filename);
615 #ifdef DWARF_DEBUGGING_INFO
616 if (debug_info_level == DINFO_LEVEL_VERBOSE
617 && write_symbols == DWARF_DEBUG)
618 dwarfout_start_new_source_file (input_filename);
619 #endif /* DWARF_DEBUGGING_INFO */
623 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
625 /* Popping out of a file. */
626 if (input_file_stack->next)
628 struct file_stack *p = input_file_stack;
629 input_file_stack = p->next;
631 input_file_stack_tick++;
632 #ifdef DBX_DEBUGGING_INFO
633 if (write_symbols == DBX_DEBUG)
634 dbxout_resume_previous_source_file ();
636 #ifdef DWARF_DEBUGGING_INFO
637 if (debug_info_level == DINFO_LEVEL_VERBOSE
638 && write_symbols == DWARF_DEBUG)
639 dwarfout_resume_previous_source_file (input_file_stack->line);
640 #endif /* DWARF_DEBUGGING_INFO */
643 error ("#-lines for entering and leaving files don't match");
649 /* Now that we've pushed or popped the input stack,
650 update the name in the top element. */
651 if (input_file_stack)
652 input_file_stack->name = input_filename;
654 /* If we have handled a `1' or a `2',
655 see if there is another number to read. */
658 /* Is this the last nonwhite stuff on the line? */
660 while (c == ' ' || c == '\t')
670 /* `3' after file name means this is a system header file. */
672 if (token == CONSTANT
673 && TREE_CODE (yylval.ttype) == INTEGER_CST
674 && TREE_INT_CST_LOW (yylval.ttype) == 3)
675 in_system_header = 1, used_up = 1;
679 /* Is this the last nonwhite stuff on the line? */
681 while (c == ' ' || c == '\t')
688 warning ("unrecognized text at end of #line");
691 error ("invalid #-line");
693 /* skip the rest of this line. */
695 while (c != '\n' && c != EOF)
700 #ifdef HANDLE_SYSV_PRAGMA
702 /* Handle a #pragma directive. INPUT is the current input stream,
703 and TOKEN is the token we read after `#pragma'. Processes the entire input
704 line and returns a character for the caller to reread: either \n or EOF. */
706 /* This function has to be in this file, in order to get at
710 handle_sysv_pragma (input, token)
724 handle_pragma_token (token_buffer, yylval.ttype);
727 handle_pragma_token (token_buffer, 0);
731 c = nextchar, nextchar = -1;
735 while (c == ' ' || c == '\t')
737 if (c == '\n' || c == EOF)
739 handle_pragma_token (0, 0);
747 #endif /* HANDLE_SYSV_PRAGMA */
749 #define ENDFILE -1 /* token that represents end-of-file */
751 /* Read an escape sequence, returning its equivalent as a character,
752 or store 1 in *ignore_ptr if it is backslash-newline. */
755 readescape (ignore_ptr)
758 register int c = getc (finput);
760 register unsigned count;
761 unsigned firstdig = 0;
767 if (warn_traditional)
768 warning ("the meaning of `\\x' varies with -traditional");
770 if (flag_traditional)
779 if (!(c >= 'a' && c <= 'f')
780 && !(c >= 'A' && c <= 'F')
781 && !(c >= '0' && c <= '9'))
787 if (c >= 'a' && c <= 'f')
788 code += c - 'a' + 10;
789 if (c >= 'A' && c <= 'F')
790 code += c - 'A' + 10;
791 if (c >= '0' && c <= '9')
793 if (code != 0 || count != 0)
802 error ("\\x used with no following hex digits");
804 /* Digits are all 0's. Ok. */
806 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
808 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
810 pedwarn ("hex escape out of range");
813 case '0': case '1': case '2': case '3': case '4':
814 case '5': case '6': case '7':
817 while ((c <= '7') && (c >= '0') && (count++ < 3))
819 code = (code * 8) + (c - '0');
825 case '\\': case '\'': case '"':
834 return TARGET_NEWLINE;
849 if (warn_traditional)
850 warning ("the meaning of `\\a' varies with -traditional");
852 if (flag_traditional)
857 #if 0 /* Vertical tab is present in common usage compilers. */
858 if (flag_traditional)
866 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
872 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
876 /* `\%' is used to prevent SCCS from getting confused. */
879 pedwarn ("non-ANSI escape sequence `\\%c'", c);
882 if (c >= 040 && c < 0177)
883 pedwarn ("unknown escape sequence `\\%c'", c);
885 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
895 strcpy (buf, string);
897 /* We can't print string and character constants well
898 because the token_buffer contains the result of processing escapes. */
900 strcat (buf, " at end of input");
901 else if (token_buffer[0] == 0)
902 strcat (buf, " at null character");
903 else if (token_buffer[0] == '"')
904 strcat (buf, " before string constant");
905 else if (token_buffer[0] == '\'')
906 strcat (buf, " before character constant");
907 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
908 sprintf (buf + strlen (buf), " before character 0%o",
909 (unsigned char) token_buffer[0]);
911 strcat (buf, " before `%s'");
913 error (buf, token_buffer);
926 struct try_type type_sequence[] =
928 { &integer_type_node, 0, 0, 0},
929 { &unsigned_type_node, 1, 0, 0},
930 { &long_integer_type_node, 0, 1, 0},
931 { &long_unsigned_type_node, 1, 1, 0},
932 { &long_long_integer_type_node, 0, 1, 1},
933 { &long_long_unsigned_type_node, 1, 1, 1}
947 c = nextchar, nextchar = -1;
951 /* Effectively do c = skip_white_space (c)
952 but do it faster in the usual cases. */
965 /* Call skip_white_space so we can warn if appropriate. */
970 c = skip_white_space (c);
979 /* yylloc.first_line = lineno; */
990 if (dollars_in_ident)
995 /* Capital L may start a wide-string or wide-character constant. */
997 register int c = getc (finput);
1006 goto string_constant;
1013 if (!doing_objc_thang)
1020 /* '@' may start a constant string object. */
1021 register int c = getc(finput);
1025 goto string_constant;
1028 /* Fall through to treat '@' as the start of an identifier. */
1031 case 'A': case 'B': case 'C': case 'D': case 'E':
1032 case 'F': case 'G': case 'H': case 'I': case 'J':
1033 case 'K': case 'M': case 'N': case 'O':
1034 case 'P': case 'Q': case 'R': case 'S': case 'T':
1035 case 'U': case 'V': case 'W': case 'X': case 'Y':
1037 case 'a': case 'b': case 'c': case 'd': case 'e':
1038 case 'f': case 'g': case 'h': case 'i': case 'j':
1039 case 'k': case 'l': case 'm': case 'n': case 'o':
1040 case 'p': case 'q': case 'r': case 's': case 't':
1041 case 'u': case 'v': case 'w': case 'x': case 'y':
1046 while (isalnum (c) || c == '_' || c == '$' || c == '@')
1048 /* Make sure this char really belongs in an identifier. */
1049 if (c == '@' && ! doing_objc_thang)
1051 if (c == '$' && ! dollars_in_ident)
1054 if (p >= token_buffer + maxtoken)
1055 p = extend_token_buffer (p);
1067 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1070 register struct resword *ptr;
1072 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
1075 yylval.ttype = ridpointers[(int) ptr->rid];
1076 value = (int) ptr->token;
1078 /* Only return OBJECTNAME if it is a typedef. */
1079 if (doing_objc_thang && value == OBJECTNAME)
1081 lastiddecl = lookup_name(yylval.ttype);
1083 if (lastiddecl == NULL_TREE
1084 || TREE_CODE (lastiddecl) != TYPE_DECL)
1088 /* Even if we decided to recognize asm, still perhaps warn. */
1090 && (value == ASM_KEYWORD || value == TYPEOF
1091 || ptr->rid == RID_INLINE)
1092 && token_buffer[0] != '_')
1093 pedwarn ("ANSI does not permit the keyword `%s'",
1098 /* If we did not find a keyword, look for an identifier
1101 if (value == IDENTIFIER)
1103 if (token_buffer[0] == '@')
1104 error("invalid identifier `%s'", token_buffer);
1106 yylval.ttype = get_identifier (token_buffer);
1107 lastiddecl = lookup_name (yylval.ttype);
1109 if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1111 /* A user-invisible read-only initialized variable
1112 should be replaced by its value.
1113 We handle only strings since that's the only case used in C. */
1114 else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL
1115 && DECL_IGNORED_P (lastiddecl)
1116 && TREE_READONLY (lastiddecl)
1117 && DECL_INITIAL (lastiddecl) != 0
1118 && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST)
1120 tree stringval = DECL_INITIAL (lastiddecl);
1122 /* Copy the string value so that we won't clobber anything
1123 if we put something in the TREE_CHAIN of this one. */
1124 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
1125 TREE_STRING_POINTER (stringval));
1128 else if (doing_objc_thang)
1130 tree objc_interface_decl = is_class_name (yylval.ttype);
1132 if (objc_interface_decl)
1135 yylval.ttype = objc_interface_decl;
1145 /* Check first for common special case: single-digit 0 or 1. */
1147 next_c = getc (finput);
1148 ungetc (next_c, finput); /* Always undo this lookahead. */
1149 if (!isalnum (next_c) && next_c != '.')
1151 token_buffer[0] = (char)c, token_buffer[1] = '\0';
1152 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
1158 case '2': case '3': case '4':
1159 case '5': case '6': case '7': case '8': case '9':
1164 int largest_digit = 0;
1166 /* for multi-precision arithmetic,
1167 we actually store only HOST_BITS_PER_CHAR bits in each part.
1168 The number of parts is chosen so as to be sufficient to hold
1169 the enough bits to fit into the two HOST_WIDE_INTs that contain
1170 the integer value (this is always at least as many bits as are
1171 in a target `long long' value, but may be wider). */
1172 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1173 int parts[TOTAL_PARTS];
1176 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
1179 for (count = 0; count < TOTAL_PARTS; count++)
1187 *p++ = (c = getc (finput));
1188 if ((c == 'x') || (c == 'X'))
1191 *p++ = (c = getc (finput));
1193 /* Leading 0 forces octal unless the 0 is the only digit. */
1194 else if (c >= '0' && c <= '9')
1203 /* Read all the digits-and-decimal-points. */
1206 || (isalnum (c) && c != 'l' && c != 'L'
1207 && c != 'u' && c != 'U'
1208 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
1209 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1214 error ("floating constant may not be in radix 16");
1215 if (floatflag == TOO_MANY_POINTS)
1216 /* We have already emitted an error. Don't need another. */
1218 else if (floatflag == AFTER_POINT)
1220 error ("malformed floating constant");
1221 floatflag = TOO_MANY_POINTS;
1222 /* Avoid another error from atof by forcing all characters
1223 from here on to be ignored. */
1227 floatflag = AFTER_POINT;
1230 *p++ = c = getc (finput);
1231 /* Accept '.' as the start of a floating-point number
1232 only when it is followed by a digit.
1233 Otherwise, unread the following non-digit
1234 and use the '.' as a structural token. */
1235 if (p == token_buffer + 2 && !isdigit (c))
1246 error ("parse error at `..'");
1249 token_buffer[1] = 0;
1256 /* It is not a decimal point.
1257 It should be a digit (perhaps a hex digit). */
1263 else if (base <= 10)
1265 if (c == 'e' || c == 'E')
1268 floatflag = AFTER_POINT;
1269 break; /* start of exponent */
1271 error ("nondigits in number and not hexadecimal");
1282 if (c >= largest_digit)
1286 for (count = 0; count < TOTAL_PARTS; count++)
1288 parts[count] *= base;
1292 += (parts[count-1] >> HOST_BITS_PER_CHAR);
1294 &= (1 << HOST_BITS_PER_CHAR) - 1;
1300 /* If the extra highest-order part ever gets anything in it,
1301 the number is certainly too big. */
1302 if (parts[TOTAL_PARTS - 1] != 0)
1305 if (p >= token_buffer + maxtoken - 3)
1306 p = extend_token_buffer (p);
1307 *p++ = (c = getc (finput));
1312 error ("numeric constant with no digits");
1314 if (largest_digit >= base)
1315 error ("numeric constant contains digits beyond the radix");
1317 /* Remove terminating char from the token buffer and delimit the string */
1320 if (floatflag != NOT_FLOAT)
1322 tree type = double_type_node;
1323 int exceeds_double = 0;
1325 REAL_VALUE_TYPE value;
1328 /* Read explicit exponent if any, and put it in tokenbuf. */
1330 if ((c == 'e') || (c == 'E'))
1332 if (p >= token_buffer + maxtoken - 3)
1333 p = extend_token_buffer (p);
1336 if ((c == '+') || (c == '-'))
1342 error ("floating constant exponent has no digits");
1345 if (p >= token_buffer + maxtoken - 3)
1346 p = extend_token_buffer (p);
1355 /* Convert string to a double, checking for overflow. */
1356 if (setjmp (handler))
1358 error ("floating constant out of range");
1363 int fflag = 0, lflag = 0;
1364 /* Copy token_buffer now, while it has just the number
1365 and not the suffixes; once we add `f' or `i',
1366 REAL_VALUE_ATOF may not work any more. */
1367 char *copy = (char *) alloca (p - token_buffer + 1);
1368 bcopy (token_buffer, copy, p - token_buffer + 1);
1370 set_float_handler (handler);
1376 /* Read the suffixes to choose a data type. */
1381 error ("more than one `f' in numeric constant");
1387 error ("more than one `l' in numeric constant");
1393 error ("more than one `i' or `j' in numeric constant");
1395 pedwarn ("ANSI C forbids imaginary numeric constants");
1406 if (p >= token_buffer + maxtoken - 3)
1407 p = extend_token_buffer (p);
1413 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1414 tells the desired precision of the binary result
1415 of decimal-to-binary conversion. */
1420 error ("both `f' and `l' in floating constant");
1422 type = float_type_node;
1423 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1424 /* A diagnostic is required here by some ANSI C testsuites.
1425 This is not pedwarn, become some people don't want
1426 an error for this. */
1427 if (REAL_VALUE_ISINF (value) && pedantic)
1428 warning ("floating point number exceeds range of `float'");
1432 type = long_double_type_node;
1433 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1434 if (REAL_VALUE_ISINF (value) && pedantic)
1435 warning ("floating point number exceeds range of `long double'");
1439 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
1440 if (REAL_VALUE_ISINF (value) && pedantic)
1441 warning ("floating point number exceeds range of `double'");
1444 set_float_handler (NULL_PTR);
1447 if (errno == ERANGE && !flag_traditional && pedantic)
1449 /* ERANGE is also reported for underflow,
1450 so test the value to distinguish overflow from that. */
1451 if (REAL_VALUES_LESS (dconst1, value)
1452 || REAL_VALUES_LESS (value, dconstm1))
1454 warning ("floating point number exceeds range of `double'");
1460 /* If the result is not a number, assume it must have been
1461 due to some error message above, so silently convert
1463 if (REAL_VALUE_ISNAN (value))
1466 /* Create a node with determined type and value. */
1468 yylval.ttype = build_complex (NULL_TREE,
1469 convert (type, integer_zero_node),
1470 build_real (type, value));
1472 yylval.ttype = build_real (type, value);
1476 tree traditional_type, ansi_type, type;
1477 HOST_WIDE_INT high, low;
1478 int spec_unsigned = 0;
1480 int spec_long_long = 0;
1486 if (c == 'u' || c == 'U')
1489 error ("two `u's in integer constant");
1492 else if (c == 'l' || c == 'L')
1497 error ("three `l's in integer constant");
1499 pedwarn ("ANSI C forbids long long integer constants");
1504 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
1507 error ("more than one `i' or `j' in numeric constant");
1509 pedwarn ("ANSI C forbids imaginary numeric constants");
1514 if (p >= token_buffer + maxtoken - 3)
1515 p = extend_token_buffer (p);
1520 /* If the constant is not long long and it won't fit in an
1521 unsigned long, or if the constant is long long and won't fit
1522 in an unsigned long long, then warn that the constant is out
1525 /* ??? This assumes that long long and long integer types are
1526 a multiple of 8 bits. This better than the original code
1527 though which assumed that long was exactly 32 bits and long
1528 long was exactly 64 bits. */
1531 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
1533 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
1536 for (i = bytes; i < TOTAL_PARTS; i++)
1540 pedwarn ("integer constant out of range");
1542 /* This is simplified by the fact that our constant
1543 is always positive. */
1547 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
1549 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
1550 / HOST_BITS_PER_CHAR)]
1551 << (i * HOST_BITS_PER_CHAR));
1552 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
1555 yylval.ttype = build_int_2 (low, high);
1556 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
1558 /* If warn_traditional, calculate both the ANSI type and the
1559 traditional type, then see if they disagree.
1560 Otherwise, calculate only the type for the dialect in use. */
1561 if (warn_traditional || flag_traditional)
1563 /* Calculate the traditional type. */
1564 /* Traditionally, any constant is signed;
1565 but if unsigned is specified explicitly, obey that.
1566 Use the smallest size with the right number of bits,
1567 except for one special case with decimal constants. */
1568 if (! spec_long && base != 10
1569 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1570 traditional_type = (spec_unsigned ? unsigned_type_node
1571 : integer_type_node);
1572 /* A decimal constant must be long
1573 if it does not fit in type int.
1574 I think this is independent of whether
1575 the constant is signed. */
1576 else if (! spec_long && base == 10
1577 && int_fits_type_p (yylval.ttype, integer_type_node))
1578 traditional_type = (spec_unsigned ? unsigned_type_node
1579 : integer_type_node);
1580 else if (! spec_long_long)
1581 traditional_type = (spec_unsigned ? long_unsigned_type_node
1582 : long_integer_type_node);
1584 traditional_type = (spec_unsigned
1585 ? long_long_unsigned_type_node
1586 : long_long_integer_type_node);
1588 if (warn_traditional || ! flag_traditional)
1590 /* Calculate the ANSI type. */
1591 if (! spec_long && ! spec_unsigned
1592 && int_fits_type_p (yylval.ttype, integer_type_node))
1593 ansi_type = integer_type_node;
1594 else if (! spec_long && (base != 10 || spec_unsigned)
1595 && int_fits_type_p (yylval.ttype, unsigned_type_node))
1596 ansi_type = unsigned_type_node;
1597 else if (! spec_unsigned && !spec_long_long
1598 && int_fits_type_p (yylval.ttype, long_integer_type_node))
1599 ansi_type = long_integer_type_node;
1600 else if (! spec_long_long)
1601 ansi_type = long_unsigned_type_node;
1602 else if (! spec_unsigned
1603 /* Verify value does not overflow into sign bit. */
1604 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
1605 && int_fits_type_p (yylval.ttype,
1606 long_long_integer_type_node))
1607 ansi_type = long_long_integer_type_node;
1609 ansi_type = long_long_unsigned_type_node;
1612 type = flag_traditional ? traditional_type : ansi_type;
1614 if (warn_traditional && traditional_type != ansi_type)
1616 if (TYPE_PRECISION (traditional_type)
1617 != TYPE_PRECISION (ansi_type))
1618 warning ("width of integer constant changes with -traditional");
1619 else if (TREE_UNSIGNED (traditional_type)
1620 != TREE_UNSIGNED (ansi_type))
1621 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1623 warning ("width of integer constant may change on other systems with -traditional");
1626 if (!flag_traditional && !int_fits_type_p (yylval.ttype, type)
1628 pedwarn ("integer constant out of range");
1630 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
1631 warning ("decimal constant is so large that it is unsigned");
1635 if (TYPE_PRECISION (type)
1636 <= TYPE_PRECISION (integer_type_node))
1638 = build_complex (NULL_TREE, integer_zero_node,
1639 convert (integer_type_node,
1642 error ("complex integer constant is too wide for `complex int'");
1644 else if (flag_traditional && !int_fits_type_p (yylval.ttype, type))
1645 /* The traditional constant 0x80000000 is signed
1646 but doesn't fit in the range of int.
1647 This will change it to -0x80000000, which does fit. */
1649 TREE_TYPE (yylval.ttype) = unsigned_type (type);
1650 yylval.ttype = convert (type, yylval.ttype);
1651 TREE_OVERFLOW (yylval.ttype)
1652 = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0;
1655 TREE_TYPE (yylval.ttype) = type;
1661 if (isalnum (c) || c == '.' || c == '_'
1662 || (!flag_traditional && (c == '-' || c == '+')
1663 && (p[-1] == 'e' || p[-1] == 'E')))
1664 error ("missing white space after number `%s'", token_buffer);
1666 value = CONSTANT; break;
1672 register int result = 0;
1673 register int num_chars = 0;
1674 unsigned width = TYPE_PRECISION (char_type_node);
1679 width = WCHAR_TYPE_SIZE;
1680 #ifdef MULTIBYTE_CHARS
1681 max_chars = MB_CUR_MAX;
1687 max_chars = TYPE_PRECISION (integer_type_node) / width;
1695 if (c == '\'' || c == EOF)
1701 c = readescape (&ignore);
1704 if (width < HOST_BITS_PER_INT
1705 && (unsigned) c >= (1 << width))
1706 pedwarn ("escape sequence out of range for character");
1707 #ifdef MAP_CHARACTER
1709 c = MAP_CHARACTER (c);
1715 pedwarn ("ANSI C forbids newline in character constant");
1718 #ifdef MAP_CHARACTER
1720 c = MAP_CHARACTER (c);
1724 if (num_chars > maxtoken - 4)
1725 extend_token_buffer (token_buffer);
1727 token_buffer[num_chars] = c;
1729 /* Merge character into result; ignore excess chars. */
1730 if (num_chars < max_chars + 1)
1732 if (width < HOST_BITS_PER_INT)
1733 result = (result << width) | (c & ((1 << width) - 1));
1739 token_buffer[num_chars + 1] = '\'';
1740 token_buffer[num_chars + 2] = 0;
1743 error ("malformatted character constant");
1744 else if (num_chars == 0)
1745 error ("empty character constant");
1746 else if (num_chars > max_chars)
1748 num_chars = max_chars;
1749 error ("character constant too long");
1751 else if (num_chars != 1 && ! flag_traditional)
1752 warning ("multi-character character constant");
1754 /* If char type is signed, sign-extend the constant. */
1757 int num_bits = num_chars * width;
1759 /* We already got an error; avoid invalid shift. */
1760 yylval.ttype = build_int_2 (0, 0);
1761 else if (TREE_UNSIGNED (char_type_node)
1762 || ((result >> (num_bits - 1)) & 1) == 0)
1764 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
1765 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1769 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
1770 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
1772 TREE_TYPE (yylval.ttype) = integer_type_node;
1776 #ifdef MULTIBYTE_CHARS
1777 /* Set the initial shift state and convert the next sequence. */
1779 /* In all locales L'\0' is zero and mbtowc will return zero,
1782 || (num_chars == 1 && token_buffer[1] != '\0'))
1785 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1786 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
1789 warning ("Ignoring invalid multibyte character");
1792 yylval.ttype = build_int_2 (result, 0);
1793 TREE_TYPE (yylval.ttype) = wchar_type_node;
1804 p = token_buffer + 1;
1806 while (c != '"' && c >= 0)
1811 c = readescape (&ignore);
1815 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
1816 && c >= (1 << TYPE_PRECISION (char_type_node)))
1817 pedwarn ("escape sequence out of range for character");
1822 pedwarn ("ANSI C forbids newline in string constant");
1826 if (p == token_buffer + maxtoken)
1827 p = extend_token_buffer (p);
1836 error ("Unterminated string constant");
1838 /* We have read the entire constant.
1839 Construct a STRING_CST for the result. */
1843 /* If this is a L"..." wide-string, convert the multibyte string
1844 to a wide character string. */
1845 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
1848 #ifdef MULTIBYTE_CHARS
1849 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
1850 if (len < 0 || len >= (p - token_buffer))
1852 warning ("Ignoring invalid multibyte string");
1855 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
1858 union { long l; char c[sizeof (long)]; } u;
1862 /* Determine whether host is little or big endian. */
1864 big_endian = u.c[sizeof (long) - 1];
1865 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
1867 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
1868 for (cp = token_buffer + 1; cp < p; cp++)
1869 *wp = *cp, wp += WCHAR_BYTES;
1870 len = p - token_buffer - 1;
1873 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
1874 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
1879 extern tree build_objc_string();
1880 /* Return an Objective-C @"..." constant string object. */
1881 yylval.ttype = build_objc_string (p - token_buffer,
1883 TREE_TYPE (yylval.ttype) = char_array_type_node;
1884 value = OBJC_STRING;
1888 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
1889 TREE_TYPE (yylval.ttype) = char_array_type_node;
1920 yylval.code = PLUS_EXPR; break;
1922 yylval.code = MINUS_EXPR; break;
1924 yylval.code = BIT_AND_EXPR; break;
1926 yylval.code = BIT_IOR_EXPR; break;
1928 yylval.code = MULT_EXPR; break;
1930 yylval.code = TRUNC_DIV_EXPR; break;
1932 yylval.code = TRUNC_MOD_EXPR; break;
1934 yylval.code = BIT_XOR_EXPR; break;
1936 yylval.code = LSHIFT_EXPR; break;
1938 yylval.code = RSHIFT_EXPR; break;
1940 yylval.code = LT_EXPR; break;
1942 yylval.code = GT_EXPR; break;
1945 token_buffer[1] = c1 = getc (finput);
1946 token_buffer[2] = 0;
1953 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
1955 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
1957 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
1959 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
1961 value = ASSIGN; goto done;
1967 value = PLUSPLUS; goto done;
1969 value = MINUSMINUS; goto done;
1971 value = ANDAND; goto done;
1973 value = OROR; goto done;
1986 { value = POINTSAT; goto done; }
1990 { value = ']'; goto done; }
1994 { value = '{'; goto done; }
1996 { value = '['; goto done; }
2000 { value = '}'; goto done; }
2003 ungetc (c1, finput);
2004 token_buffer[1] = 0;
2006 if ((c == '<') || (c == '>'))
2007 value = ARITHCOMPARE;
2013 /* Don't make yyparse think this is eof. */
2022 /* yylloc.last_line = lineno; */
2027 /* Sets the value of the 'yydebug' variable to VALUE.
2028 This is a function so we don't have to have YYDEBUG defined
2029 in order to build the compiler. */
2038 warning ("YYDEBUG not defined.");