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 #ifdef HANDLE_SYSV_PRAGMA
402 return handle_sysv_pragma (finput
, c
);
403 #else /* !HANDLE_SYSV_PRAGMA */
405 return HANDLE_PRAGMA (finput
, c
);
406 #endif /* HANDLE_PRAGMA */
408 #endif /* !HANDLE_SYSV_PRAGMA */
414 if (getc (finput
) == 'e'
415 && getc (finput
) == 'f'
416 && getc (finput
) == 'i'
417 && getc (finput
) == 'n'
418 && getc (finput
) == 'e'
419 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'))
421 #ifdef DWARF_DEBUGGING_INFO
423 && (debug_info_level
== DINFO_LEVEL_VERBOSE
)
424 && (write_symbols
== DWARF_DEBUG
))
425 dwarfout_define (lineno
, get_directive_line (finput
));
426 #endif /* DWARF_DEBUGGING_INFO */
432 if (getc (finput
) == 'n'
433 && getc (finput
) == 'd'
434 && getc (finput
) == 'e'
435 && getc (finput
) == 'f'
436 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'))
438 #ifdef DWARF_DEBUGGING_INFO
440 && (debug_info_level
== DINFO_LEVEL_VERBOSE
)
441 && (write_symbols
== DWARF_DEBUG
))
442 dwarfout_undef (lineno
, get_directive_line (finput
));
443 #endif /* DWARF_DEBUGGING_INFO */
449 if (getc (finput
) == 'i'
450 && getc (finput
) == 'n'
451 && getc (finput
) == 'e'
452 && ((c
= getc (finput
)) == ' ' || c
== '\t'))
457 if (getc (finput
) == 'd'
458 && getc (finput
) == 'e'
459 && getc (finput
) == 'n'
460 && getc (finput
) == 't'
461 && ((c
= getc (finput
)) == ' ' || c
== '\t'))
463 /* #ident. The pedantic warning is now in cccp.c. */
465 /* Here we have just seen `#ident '.
466 A string constant should follow. */
468 while (c
== ' ' || c
== '\t')
471 /* If no argument, ignore the line. */
478 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
480 error ("invalid #ident");
486 #ifdef ASM_OUTPUT_IDENT
487 ASM_OUTPUT_IDENT (asm_out_file
, TREE_STRING_POINTER (yylval
.ttype
));
491 /* Skip the rest of this line. */
496 error ("undefined or invalid # directive");
501 /* Here we have either `#line' or `# <nonletter>'.
502 In either case, it should be a line number; a digit should follow. */
504 while (c
== ' ' || c
== '\t')
507 /* If the # is the only nonwhite char on the line,
508 just ignore it. Check the new newline. */
512 /* Something follows the #; read a token. */
517 if (token
== CONSTANT
518 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
520 int old_lineno
= lineno
;
522 /* subtract one, because it is the following line that
523 gets the specified number */
525 int l
= TREE_INT_CST_LOW (yylval
.ttype
) - 1;
527 /* Is this the last nonwhite stuff on the line? */
529 while (c
== ' ' || c
== '\t')
533 /* No more: store the line number and check following line. */
539 /* More follows: it must be a string constant (filename). */
541 /* Read the string constant. */
544 if (token
!= STRING
|| TREE_CODE (yylval
.ttype
) != STRING_CST
)
546 error ("invalid #line");
551 = (char *) permalloc (TREE_STRING_LENGTH (yylval
.ttype
) + 1);
552 strcpy (input_filename
, TREE_STRING_POINTER (yylval
.ttype
));
555 /* Each change of file name
556 reinitializes whether we are now in a system header. */
557 in_system_header
= 0;
559 if (main_input_filename
== 0)
560 main_input_filename
= input_filename
;
562 /* Is this the last nonwhite stuff on the line? */
564 while (c
== ' ' || c
== '\t')
568 /* Update the name in the top element of input_file_stack. */
569 if (input_file_stack
)
570 input_file_stack
->name
= input_filename
;
579 /* `1' after file name means entering new file.
580 `2' after file name means just left a file. */
582 if (token
== CONSTANT
583 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
585 if (TREE_INT_CST_LOW (yylval
.ttype
) == 1)
587 /* Pushing to a new file. */
589 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
590 input_file_stack
->line
= old_lineno
;
591 p
->next
= input_file_stack
;
592 p
->name
= input_filename
;
593 input_file_stack
= p
;
594 input_file_stack_tick
++;
595 #ifdef DBX_DEBUGGING_INFO
596 if (write_symbols
== DBX_DEBUG
)
597 dbxout_start_new_source_file (input_filename
);
599 #ifdef DWARF_DEBUGGING_INFO
600 if (debug_info_level
== DINFO_LEVEL_VERBOSE
601 && write_symbols
== DWARF_DEBUG
)
602 dwarfout_start_new_source_file (input_filename
);
603 #endif /* DWARF_DEBUGGING_INFO */
607 else if (TREE_INT_CST_LOW (yylval
.ttype
) == 2)
609 /* Popping out of a file. */
610 if (input_file_stack
->next
)
612 struct file_stack
*p
= input_file_stack
;
613 input_file_stack
= p
->next
;
615 input_file_stack_tick
++;
616 #ifdef DBX_DEBUGGING_INFO
617 if (write_symbols
== DBX_DEBUG
)
618 dbxout_resume_previous_source_file ();
620 #ifdef DWARF_DEBUGGING_INFO
621 if (debug_info_level
== DINFO_LEVEL_VERBOSE
622 && write_symbols
== DWARF_DEBUG
)
623 dwarfout_resume_previous_source_file (input_file_stack
->line
);
624 #endif /* DWARF_DEBUGGING_INFO */
627 error ("#-lines for entering and leaving files don't match");
633 /* Now that we've pushed or popped the input stack,
634 update the name in the top element. */
635 if (input_file_stack
)
636 input_file_stack
->name
= input_filename
;
638 /* If we have handled a `1' or a `2',
639 see if there is another number to read. */
642 /* Is this the last nonwhite stuff on the line? */
644 while (c
== ' ' || c
== '\t')
654 /* `3' after file name means this is a system header file. */
656 if (token
== CONSTANT
657 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
658 && TREE_INT_CST_LOW (yylval
.ttype
) == 3)
659 in_system_header
= 1, used_up
= 1;
663 /* Is this the last nonwhite stuff on the line? */
665 while (c
== ' ' || c
== '\t')
672 warning ("unrecognized text at end of #line");
675 error ("invalid #-line");
677 /* skip the rest of this line. */
679 while (c
!= '\n' && c
!= EOF
)
684 #ifdef HANDLE_SYSV_PRAGMA
686 /* Handle a #pragma directive. INPUT is the current input stream,
687 and C is a character to reread. Processes the entire input line
688 and returns a character for the caller to reread: either \n or EOF. */
690 /* This function has to be in this file, in order to get at
694 handle_sysv_pragma (input
, c
)
700 while (c
== ' ' || c
== '\t')
702 if (c
== '\n' || c
== EOF
)
704 handle_pragma_token (0, 0);
714 handle_pragma_token (token_buffer
, yylval
.ttype
);
717 handle_pragma_token (token_buffer
, 0);
720 c
= nextchar
, nextchar
= -1;
726 #endif /* HANDLE_SYSV_PRAGMA */
728 #define ENDFILE -1 /* token that represents end-of-file */
730 /* Read an escape sequence, returning its equivalent as a character,
731 or store 1 in *ignore_ptr if it is backslash-newline. */
734 readescape (ignore_ptr
)
737 register int c
= getc (finput
);
739 register unsigned count
;
740 unsigned firstdig
= 0;
746 if (warn_traditional
)
747 warning ("the meaning of `\\x' varies with -traditional");
749 if (flag_traditional
)
758 if (!(c
>= 'a' && c
<= 'f')
759 && !(c
>= 'A' && c
<= 'F')
760 && !(c
>= '0' && c
<= '9'))
766 if (c
>= 'a' && c
<= 'f')
767 code
+= c
- 'a' + 10;
768 if (c
>= 'A' && c
<= 'F')
769 code
+= c
- 'A' + 10;
770 if (c
>= '0' && c
<= '9')
772 if (code
!= 0 || count
!= 0)
781 error ("\\x used with no following hex digits");
783 /* Digits are all 0's. Ok. */
785 else if ((count
- 1) * 4 >= TYPE_PRECISION (integer_type_node
)
787 && ((1 << (TYPE_PRECISION (integer_type_node
) - (count
- 1) * 4))
789 pedwarn ("hex escape out of range");
792 case '0': case '1': case '2': case '3': case '4':
793 case '5': case '6': case '7':
796 while ((c
<= '7') && (c
>= '0') && (count
++ < 3))
798 code
= (code
* 8) + (c
- '0');
804 case '\\': case '\'': case '"':
813 return TARGET_NEWLINE
;
828 if (warn_traditional
)
829 warning ("the meaning of `\\a' varies with -traditional");
831 if (flag_traditional
)
836 #if 0 /* Vertical tab is present in common usage compilers. */
837 if (flag_traditional
)
845 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c
);
851 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
855 /* `\%' is used to prevent SCCS from getting confused. */
858 pedwarn ("non-ANSI escape sequence `\\%c'", c
);
861 if (c
>= 040 && c
< 0177)
862 pedwarn ("unknown escape sequence `\\%c'", c
);
864 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c
);
874 strcpy (buf
, string
);
876 /* We can't print string and character constants well
877 because the token_buffer contains the result of processing escapes. */
879 strcat (buf
, " at end of input");
880 else if (token_buffer
[0] == 0)
881 strcat (buf
, " at null character");
882 else if (token_buffer
[0] == '"')
883 strcat (buf
, " before string constant");
884 else if (token_buffer
[0] == '\'')
885 strcat (buf
, " before character constant");
886 else if (token_buffer
[0] < 040 || (unsigned char) token_buffer
[0] >= 0177)
887 sprintf (buf
+ strlen (buf
), " before character 0%o",
888 (unsigned char) token_buffer
[0]);
890 strcat (buf
, " before `%s'");
892 error (buf
, token_buffer
);
905 struct try_type type_sequence
[] =
907 { &integer_type_node
, 0, 0, 0},
908 { &unsigned_type_node
, 1, 0, 0},
909 { &long_integer_type_node
, 0, 1, 0},
910 { &long_unsigned_type_node
, 1, 1, 0},
911 { &long_long_integer_type_node
, 0, 1, 1},
912 { &long_long_unsigned_type_node
, 1, 1, 1}
926 c
= nextchar
, nextchar
= -1;
930 /* Effectively do c = skip_white_space (c)
931 but do it faster in the usual cases. */
944 /* Call skip_white_space so we can warn if appropriate. */
949 c
= skip_white_space (c
);
958 /* yylloc.first_line = lineno; */
969 if (dollars_in_ident
)
974 /* Capital L may start a wide-string or wide-character constant. */
976 register int c
= getc (finput
);
985 goto string_constant
;
992 if (!doing_objc_thang
)
999 /* '@' may start a constant string object. */
1000 register int c
= getc(finput
);
1004 goto string_constant
;
1007 /* Fall through to treat '@' as the start of an identifier. */
1010 case 'A': case 'B': case 'C': case 'D': case 'E':
1011 case 'F': case 'G': case 'H': case 'I': case 'J':
1012 case 'K': case 'M': case 'N': case 'O':
1013 case 'P': case 'Q': case 'R': case 'S': case 'T':
1014 case 'U': case 'V': case 'W': case 'X': case 'Y':
1016 case 'a': case 'b': case 'c': case 'd': case 'e':
1017 case 'f': case 'g': case 'h': case 'i': case 'j':
1018 case 'k': case 'l': case 'm': case 'n': case 'o':
1019 case 'p': case 'q': case 'r': case 's': case 't':
1020 case 'u': case 'v': case 'w': case 'x': case 'y':
1025 while (isalnum (c
) || c
== '_' || c
== '$' || c
== '@')
1027 /* Make sure this char really belongs in an identifier. */
1028 if (c
== '@' && ! doing_objc_thang
)
1030 if (c
== '$' && ! dollars_in_ident
)
1033 if (p
>= token_buffer
+ maxtoken
)
1034 p
= extend_token_buffer (p
);
1046 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1049 register struct resword
*ptr
;
1051 if (ptr
= is_reserved_word (token_buffer
, p
- token_buffer
))
1054 yylval
.ttype
= ridpointers
[(int) ptr
->rid
];
1055 value
= (int) ptr
->token
;
1057 /* Only return OBJECTNAME if it is a typedef. */
1058 if (doing_objc_thang
&& value
== OBJECTNAME
)
1060 lastiddecl
= lookup_name(yylval
.ttype
);
1062 if (lastiddecl
== NULL_TREE
1063 || TREE_CODE (lastiddecl
) != TYPE_DECL
)
1067 /* Even if we decided to recognize asm, still perhaps warn. */
1069 && (value
== ASM_KEYWORD
|| value
== TYPEOF
1070 || ptr
->rid
== RID_INLINE
)
1071 && token_buffer
[0] != '_')
1072 pedwarn ("ANSI does not permit the keyword `%s'",
1077 /* If we did not find a keyword, look for an identifier
1080 if (value
== IDENTIFIER
)
1082 if (token_buffer
[0] == '@')
1083 error("invalid identifier `%s'", token_buffer
);
1085 yylval
.ttype
= get_identifier (token_buffer
);
1086 lastiddecl
= lookup_name (yylval
.ttype
);
1088 if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == TYPE_DECL
)
1090 /* A user-invisible read-only initialized variable
1091 should be replaced by its value.
1092 We handle only strings since that's the only case used in C. */
1093 else if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == VAR_DECL
1094 && DECL_IGNORED_P (lastiddecl
)
1095 && TREE_READONLY (lastiddecl
)
1096 && DECL_INITIAL (lastiddecl
) != 0
1097 && TREE_CODE (DECL_INITIAL (lastiddecl
)) == STRING_CST
)
1099 tree stringval
= DECL_INITIAL (lastiddecl
);
1101 /* Copy the string value so that we won't clobber anything
1102 if we put something in the TREE_CHAIN of this one. */
1103 yylval
.ttype
= build_string (TREE_STRING_LENGTH (stringval
),
1104 TREE_STRING_POINTER (stringval
));
1107 else if (doing_objc_thang
)
1109 tree objc_interface_decl
= is_class_name (yylval
.ttype
);
1111 if (objc_interface_decl
)
1114 yylval
.ttype
= objc_interface_decl
;
1124 /* Check first for common special case: single-digit 0 or 1. */
1126 next_c
= getc (finput
);
1127 ungetc (next_c
, finput
); /* Always undo this lookahead. */
1128 if (!isalnum (next_c
) && next_c
!= '.')
1130 token_buffer
[0] = (char)c
, token_buffer
[1] = '\0';
1131 yylval
.ttype
= (c
== '0') ? integer_zero_node
: integer_one_node
;
1137 case '2': case '3': case '4':
1138 case '5': case '6': case '7': case '8': case '9':
1143 int largest_digit
= 0;
1145 /* for multi-precision arithmetic,
1146 we actually store only HOST_BITS_PER_CHAR bits in each part.
1147 The number of parts is chosen so as to be sufficient to hold
1148 the enough bits to fit into the two HOST_WIDE_INTs that contain
1149 the integer value (this is always at least as many bits as are
1150 in a target `long long' value, but may be wider). */
1151 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1152 int parts
[TOTAL_PARTS
];
1155 enum anon1
{ NOT_FLOAT
, AFTER_POINT
, TOO_MANY_POINTS
} floatflag
1158 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1166 *p
++ = (c
= getc (finput
));
1167 if ((c
== 'x') || (c
== 'X'))
1170 *p
++ = (c
= getc (finput
));
1172 /* Leading 0 forces octal unless the 0 is the only digit. */
1173 else if (c
>= '0' && c
<= '9')
1182 /* Read all the digits-and-decimal-points. */
1185 || (isalnum (c
) && c
!= 'l' && c
!= 'L'
1186 && c
!= 'u' && c
!= 'U'
1187 && c
!= 'i' && c
!= 'I' && c
!= 'j' && c
!= 'J'
1188 && (floatflag
== NOT_FLOAT
|| ((c
!= 'f') && (c
!= 'F')))))
1193 error ("floating constant may not be in radix 16");
1194 if (floatflag
== TOO_MANY_POINTS
)
1195 /* We have already emitted an error. Don't need another. */
1197 else if (floatflag
== AFTER_POINT
)
1199 error ("malformed floating constant");
1200 floatflag
= TOO_MANY_POINTS
;
1201 /* Avoid another error from atof by forcing all characters
1202 from here on to be ignored. */
1206 floatflag
= AFTER_POINT
;
1209 *p
++ = c
= getc (finput
);
1210 /* Accept '.' as the start of a floating-point number
1211 only when it is followed by a digit.
1212 Otherwise, unread the following non-digit
1213 and use the '.' as a structural token. */
1214 if (p
== token_buffer
+ 2 && !isdigit (c
))
1225 error ("parse error at `..'");
1228 token_buffer
[1] = 0;
1235 /* It is not a decimal point.
1236 It should be a digit (perhaps a hex digit). */
1242 else if (base
<= 10)
1244 if (c
== 'e' || c
== 'E')
1247 floatflag
= AFTER_POINT
;
1248 break; /* start of exponent */
1250 error ("nondigits in number and not hexadecimal");
1261 if (c
>= largest_digit
)
1265 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1267 parts
[count
] *= base
;
1271 += (parts
[count
-1] >> HOST_BITS_PER_CHAR
);
1273 &= (1 << HOST_BITS_PER_CHAR
) - 1;
1279 /* If the extra highest-order part ever gets anything in it,
1280 the number is certainly too big. */
1281 if (parts
[TOTAL_PARTS
- 1] != 0)
1284 if (p
>= token_buffer
+ maxtoken
- 3)
1285 p
= extend_token_buffer (p
);
1286 *p
++ = (c
= getc (finput
));
1291 error ("numeric constant with no digits");
1293 if (largest_digit
>= base
)
1294 error ("numeric constant contains digits beyond the radix");
1296 /* Remove terminating char from the token buffer and delimit the string */
1299 if (floatflag
!= NOT_FLOAT
)
1301 tree type
= double_type_node
;
1302 int exceeds_double
= 0;
1304 REAL_VALUE_TYPE value
;
1307 /* Read explicit exponent if any, and put it in tokenbuf. */
1309 if ((c
== 'e') || (c
== 'E'))
1311 if (p
>= token_buffer
+ maxtoken
- 3)
1312 p
= extend_token_buffer (p
);
1315 if ((c
== '+') || (c
== '-'))
1321 error ("floating constant exponent has no digits");
1324 if (p
>= token_buffer
+ maxtoken
- 3)
1325 p
= extend_token_buffer (p
);
1334 /* Convert string to a double, checking for overflow. */
1335 if (setjmp (handler
))
1337 error ("floating constant out of range");
1342 int fflag
= 0, lflag
= 0;
1343 /* Copy token_buffer now, while it has just the number
1344 and not the suffixes; once we add `f' or `i',
1345 REAL_VALUE_ATOF may not work any more. */
1346 char *copy
= (char *) alloca (p
- token_buffer
+ 1);
1347 bcopy (token_buffer
, copy
, p
- token_buffer
+ 1);
1349 set_float_handler (handler
);
1355 /* Read the suffixes to choose a data type. */
1360 error ("more than one `f' in numeric constant");
1366 error ("more than one `l' in numeric constant");
1372 error ("more than one `i' or `j' in numeric constant");
1374 pedwarn ("ANSI C forbids imaginary numeric constants");
1385 if (p
>= token_buffer
+ maxtoken
- 3)
1386 p
= extend_token_buffer (p
);
1392 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1393 tells the desired precision of the binary result
1394 of decimal-to-binary conversion. */
1399 error ("both `f' and `l' in floating constant");
1401 type
= float_type_node
;
1402 value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (type
));
1403 /* A diagnostic is required here by some ANSI C testsuites.
1404 This is not pedwarn, become some people don't want
1405 an error for this. */
1406 if (REAL_VALUE_ISINF (value
) && pedantic
)
1407 warning ("floating point number exceeds range of `float'");
1411 type
= long_double_type_node
;
1412 value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (type
));
1413 if (REAL_VALUE_ISINF (value
) && pedantic
)
1414 warning ("floating point number exceeds range of `long double'");
1418 value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (type
));
1419 if (REAL_VALUE_ISINF (value
) && pedantic
)
1420 warning ("floating point number exceeds range of `double'");
1423 set_float_handler (NULL_PTR
);
1426 if (errno
== ERANGE
&& !flag_traditional
&& pedantic
)
1428 /* ERANGE is also reported for underflow,
1429 so test the value to distinguish overflow from that. */
1430 if (REAL_VALUES_LESS (dconst1
, value
)
1431 || REAL_VALUES_LESS (value
, dconstm1
))
1433 warning ("floating point number exceeds range of `double'");
1439 /* If the result is not a number, assume it must have been
1440 due to some error message above, so silently convert
1442 if (REAL_VALUE_ISNAN (value
))
1445 /* Create a node with determined type and value. */
1447 yylval
.ttype
= build_complex (convert (type
, integer_zero_node
),
1448 build_real (type
, value
));
1450 yylval
.ttype
= build_real (type
, value
);
1454 tree traditional_type
, ansi_type
, type
;
1455 HOST_WIDE_INT high
, low
;
1456 int spec_unsigned
= 0;
1458 int spec_long_long
= 0;
1464 if (c
== 'u' || c
== 'U')
1467 error ("two `u's in integer constant");
1470 else if (c
== 'l' || c
== 'L')
1475 error ("three `l's in integer constant");
1477 pedwarn ("ANSI C forbids long long integer constants");
1482 else if (c
== 'i' || c
== 'j' || c
== 'I' || c
== 'J')
1485 error ("more than one `i' or `j' in numeric constant");
1487 pedwarn ("ANSI C forbids imaginary numeric constants");
1492 if (p
>= token_buffer
+ maxtoken
- 3)
1493 p
= extend_token_buffer (p
);
1498 /* If the constant is not long long and it won't fit in an
1499 unsigned long, or if the constant is long long and won't fit
1500 in an unsigned long long, then warn that the constant is out
1503 /* ??? This assumes that long long and long integer types are
1504 a multiple of 8 bits. This better than the original code
1505 though which assumed that long was exactly 32 bits and long
1506 long was exactly 64 bits. */
1509 bytes
= TYPE_PRECISION (long_long_integer_type_node
) / 8;
1511 bytes
= TYPE_PRECISION (long_integer_type_node
) / 8;
1514 for (i
= bytes
; i
< TOTAL_PARTS
; i
++)
1518 pedwarn ("integer constant out of range");
1520 /* This is simplified by the fact that our constant
1521 is always positive. */
1525 for (i
= 0; i
< HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
; i
++)
1527 high
|= ((HOST_WIDE_INT
) parts
[i
+ (HOST_BITS_PER_WIDE_INT
1528 / HOST_BITS_PER_CHAR
)]
1529 << (i
* HOST_BITS_PER_CHAR
));
1530 low
|= (HOST_WIDE_INT
) parts
[i
] << (i
* HOST_BITS_PER_CHAR
);
1533 yylval
.ttype
= build_int_2 (low
, high
);
1534 TREE_TYPE (yylval
.ttype
) = long_long_unsigned_type_node
;
1536 /* If warn_traditional, calculate both the ANSI type and the
1537 traditional type, then see if they disagree.
1538 Otherwise, calculate only the type for the dialect in use. */
1539 if (warn_traditional
|| flag_traditional
)
1541 /* Calculate the traditional type. */
1542 /* Traditionally, any constant is signed;
1543 but if unsigned is specified explicitly, obey that.
1544 Use the smallest size with the right number of bits,
1545 except for one special case with decimal constants. */
1546 if (! spec_long
&& base
!= 10
1547 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1548 traditional_type
= (spec_unsigned
? unsigned_type_node
1549 : integer_type_node
);
1550 /* A decimal constant must be long
1551 if it does not fit in type int.
1552 I think this is independent of whether
1553 the constant is signed. */
1554 else if (! spec_long
&& base
== 10
1555 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1556 traditional_type
= (spec_unsigned
? unsigned_type_node
1557 : integer_type_node
);
1558 else if (! spec_long_long
)
1559 traditional_type
= (spec_unsigned
? long_unsigned_type_node
1560 : long_integer_type_node
);
1562 traditional_type
= (spec_unsigned
1563 ? long_long_unsigned_type_node
1564 : long_long_integer_type_node
);
1566 if (warn_traditional
|| ! flag_traditional
)
1568 /* Calculate the ANSI type. */
1569 if (! spec_long
&& ! spec_unsigned
1570 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1571 ansi_type
= integer_type_node
;
1572 else if (! spec_long
&& (base
!= 10 || spec_unsigned
)
1573 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1574 ansi_type
= unsigned_type_node
;
1575 else if (! spec_unsigned
&& !spec_long_long
1576 && int_fits_type_p (yylval
.ttype
, long_integer_type_node
))
1577 ansi_type
= long_integer_type_node
;
1578 else if (! spec_long_long
)
1579 ansi_type
= long_unsigned_type_node
;
1580 else if (! spec_unsigned
1581 /* Verify value does not overflow into sign bit. */
1582 && TREE_INT_CST_HIGH (yylval
.ttype
) >= 0
1583 && int_fits_type_p (yylval
.ttype
,
1584 long_long_integer_type_node
))
1585 ansi_type
= long_long_integer_type_node
;
1587 ansi_type
= long_long_unsigned_type_node
;
1590 type
= flag_traditional
? traditional_type
: ansi_type
;
1592 if (warn_traditional
&& traditional_type
!= ansi_type
)
1594 if (TYPE_PRECISION (traditional_type
)
1595 != TYPE_PRECISION (ansi_type
))
1596 warning ("width of integer constant changes with -traditional");
1597 else if (TREE_UNSIGNED (traditional_type
)
1598 != TREE_UNSIGNED (ansi_type
))
1599 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1601 warning ("width of integer constant may change on other systems with -traditional");
1604 if (!flag_traditional
&& !int_fits_type_p (yylval
.ttype
, type
)
1606 pedwarn ("integer constant out of range");
1608 if (base
== 10 && ! spec_unsigned
&& TREE_UNSIGNED (type
))
1609 warning ("decimal constant is so large that it is unsigned");
1613 if (TYPE_PRECISION (type
)
1614 <= TYPE_PRECISION (integer_type_node
))
1616 = build_complex (integer_zero_node
,
1617 convert (integer_type_node
, yylval
.ttype
));
1619 error ("complex integer constant is too wide for `complex int'");
1621 else if (flag_traditional
&& !int_fits_type_p (yylval
.ttype
, type
))
1622 /* The traditional constant 0x80000000 is signed
1623 but doesn't fit in the range of int.
1624 This will change it to -0x80000000, which does fit. */
1626 TREE_TYPE (yylval
.ttype
) = unsigned_type (type
);
1627 yylval
.ttype
= convert (type
, yylval
.ttype
);
1628 TREE_OVERFLOW (yylval
.ttype
)
1629 = TREE_CONSTANT_OVERFLOW (yylval
.ttype
) = 0;
1632 TREE_TYPE (yylval
.ttype
) = type
;
1638 if (isalnum (c
) || c
== '.' || c
== '_'
1639 || (!flag_traditional
&& (c
== '-' || c
== '+')
1640 && (p
[-1] == 'e' || p
[-1] == 'E')))
1641 error ("missing white space after number `%s'", token_buffer
);
1643 value
= CONSTANT
; break;
1649 register int result
= 0;
1650 register int num_chars
= 0;
1651 unsigned width
= TYPE_PRECISION (char_type_node
);
1656 width
= WCHAR_TYPE_SIZE
;
1657 #ifdef MULTIBYTE_CHARS
1658 max_chars
= MB_CUR_MAX
;
1664 max_chars
= TYPE_PRECISION (integer_type_node
) / width
;
1672 if (c
== '\'' || c
== EOF
)
1678 c
= readescape (&ignore
);
1681 if (width
< HOST_BITS_PER_INT
1682 && (unsigned) c
>= (1 << width
))
1683 pedwarn ("escape sequence out of range for character");
1684 #ifdef MAP_CHARACTER
1686 c
= MAP_CHARACTER (c
);
1692 pedwarn ("ANSI C forbids newline in character constant");
1695 #ifdef MAP_CHARACTER
1697 c
= MAP_CHARACTER (c
);
1701 if (num_chars
> maxtoken
- 4)
1702 extend_token_buffer (token_buffer
);
1704 token_buffer
[num_chars
] = c
;
1706 /* Merge character into result; ignore excess chars. */
1707 if (num_chars
< max_chars
+ 1)
1709 if (width
< HOST_BITS_PER_INT
)
1710 result
= (result
<< width
) | (c
& ((1 << width
) - 1));
1716 token_buffer
[num_chars
+ 1] = '\'';
1717 token_buffer
[num_chars
+ 2] = 0;
1720 error ("malformatted character constant");
1721 else if (num_chars
== 0)
1722 error ("empty character constant");
1723 else if (num_chars
> max_chars
)
1725 num_chars
= max_chars
;
1726 error ("character constant too long");
1728 else if (num_chars
!= 1 && ! flag_traditional
)
1729 warning ("multi-character character constant");
1731 /* If char type is signed, sign-extend the constant. */
1734 int num_bits
= num_chars
* width
;
1736 /* We already got an error; avoid invalid shift. */
1737 yylval
.ttype
= build_int_2 (0, 0);
1738 else if (TREE_UNSIGNED (char_type_node
)
1739 || ((result
>> (num_bits
- 1)) & 1) == 0)
1741 = build_int_2 (result
& ((unsigned HOST_WIDE_INT
) ~0
1742 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
1746 = build_int_2 (result
| ~((unsigned HOST_WIDE_INT
) ~0
1747 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
1749 TREE_TYPE (yylval
.ttype
) = integer_type_node
;
1753 #ifdef MULTIBYTE_CHARS
1754 /* Set the initial shift state and convert the next sequence. */
1756 /* In all locales L'\0' is zero and mbtowc will return zero,
1759 || (num_chars
== 1 && token_buffer
[1] != '\0'))
1762 (void) mbtowc (NULL_PTR
, NULL_PTR
, 0);
1763 if (mbtowc (& wc
, token_buffer
+ 1, num_chars
) == num_chars
)
1766 warning ("Ignoring invalid multibyte character");
1769 yylval
.ttype
= build_int_2 (result
, 0);
1770 TREE_TYPE (yylval
.ttype
) = wchar_type_node
;
1781 p
= token_buffer
+ 1;
1783 while (c
!= '"' && c
>= 0)
1788 c
= readescape (&ignore
);
1792 && TYPE_PRECISION (char_type_node
) < HOST_BITS_PER_INT
1793 && c
>= (1 << TYPE_PRECISION (char_type_node
)))
1794 pedwarn ("escape sequence out of range for character");
1799 pedwarn ("ANSI C forbids newline in string constant");
1803 if (p
== token_buffer
+ maxtoken
)
1804 p
= extend_token_buffer (p
);
1813 error ("Unterminated string constant");
1815 /* We have read the entire constant.
1816 Construct a STRING_CST for the result. */
1820 /* If this is a L"..." wide-string, convert the multibyte string
1821 to a wide character string. */
1822 char *widep
= (char *) alloca ((p
- token_buffer
) * WCHAR_BYTES
);
1825 #ifdef MULTIBYTE_CHARS
1826 len
= mbstowcs ((wchar_t *) widep
, token_buffer
+ 1, p
- token_buffer
);
1827 if (len
< 0 || len
>= (p
- token_buffer
))
1829 warning ("Ignoring invalid multibyte string");
1832 bzero (widep
+ (len
* WCHAR_BYTES
), WCHAR_BYTES
);
1835 union { long l
; char c
[sizeof (long)]; } u
;
1839 /* Determine whether host is little or big endian. */
1841 big_endian
= u
.c
[sizeof (long) - 1];
1842 wp
= widep
+ (big_endian
? WCHAR_BYTES
- 1 : 0);
1844 bzero (widep
, (p
- token_buffer
) * WCHAR_BYTES
);
1845 for (cp
= token_buffer
+ 1; cp
< p
; cp
++)
1846 *wp
= *cp
, wp
+= WCHAR_BYTES
;
1847 len
= p
- token_buffer
- 1;
1850 yylval
.ttype
= build_string ((len
+ 1) * WCHAR_BYTES
, widep
);
1851 TREE_TYPE (yylval
.ttype
) = wchar_array_type_node
;
1856 extern tree
build_objc_string();
1857 /* Return an Objective-C @"..." constant string object. */
1858 yylval
.ttype
= build_objc_string (p
- token_buffer
,
1860 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
1861 value
= OBJC_STRING
;
1865 yylval
.ttype
= build_string (p
- token_buffer
, token_buffer
+ 1);
1866 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
1897 yylval
.code
= PLUS_EXPR
; break;
1899 yylval
.code
= MINUS_EXPR
; break;
1901 yylval
.code
= BIT_AND_EXPR
; break;
1903 yylval
.code
= BIT_IOR_EXPR
; break;
1905 yylval
.code
= MULT_EXPR
; break;
1907 yylval
.code
= TRUNC_DIV_EXPR
; break;
1909 yylval
.code
= TRUNC_MOD_EXPR
; break;
1911 yylval
.code
= BIT_XOR_EXPR
; break;
1913 yylval
.code
= LSHIFT_EXPR
; break;
1915 yylval
.code
= RSHIFT_EXPR
; break;
1917 yylval
.code
= LT_EXPR
; break;
1919 yylval
.code
= GT_EXPR
; break;
1922 token_buffer
[1] = c1
= getc (finput
);
1923 token_buffer
[2] = 0;
1930 value
= ARITHCOMPARE
; yylval
.code
= LE_EXPR
; goto done
;
1932 value
= ARITHCOMPARE
; yylval
.code
= GE_EXPR
; goto done
;
1934 value
= EQCOMPARE
; yylval
.code
= NE_EXPR
; goto done
;
1936 value
= EQCOMPARE
; yylval
.code
= EQ_EXPR
; goto done
;
1938 value
= ASSIGN
; goto done
;
1944 value
= PLUSPLUS
; goto done
;
1946 value
= MINUSMINUS
; goto done
;
1948 value
= ANDAND
; goto done
;
1950 value
= OROR
; goto done
;
1963 { value
= POINTSAT
; goto done
; }
1967 { value
= ']'; goto done
; }
1971 { value
= '{'; goto done
; }
1973 { value
= '['; goto done
; }
1977 { value
= '}'; goto done
; }
1980 ungetc (c1
, finput
);
1981 token_buffer
[1] = 0;
1983 if ((c
== '<') || (c
== '>'))
1984 value
= ARITHCOMPARE
;
1990 /* Don't make yyparse think this is eof. */
1999 /* yylloc.last_line = lineno; */
2004 /* Sets the value of the 'yydebug' variable to VALUE.
2005 This is a function so we don't have to have YYDEBUG defined
2006 in order to build the compiler. */
2015 warning ("YYDEBUG not defined.");