1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1994 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
36 #ifdef MULTIBYTE_CHARS
45 /* The elements of `ridpointers' are identifier nodes
46 for the reserved type names and storage classes.
47 It is indexed by a RID_... value. */
48 tree ridpointers
[(int) RID_MAX
];
50 /* Cause the `yydebug' variable to be defined. */
53 /* the declaration found for the last IDENTIFIER token read in.
54 yylex must look this up to detect typedefs, which get token type TYPENAME,
55 so it is left around in case the identifier is not a typedef but is
56 used in a context which makes it a reference to a variable. */
59 /* Nonzero enables objc features. */
63 extern tree
is_class_name ();
67 /* File used for outputting assembler code. */
68 extern FILE *asm_out_file
;
70 #ifndef WCHAR_TYPE_SIZE
72 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
74 #define WCHAR_TYPE_SIZE BITS_PER_WORD
78 /* Number of bytes in a wide character. */
79 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
81 static int maxtoken
; /* Current nominal length of token buffer. */
82 char *token_buffer
; /* Pointer to token buffer.
83 Actual allocated length is maxtoken + 2.
84 This is not static because objc-parse.y uses it. */
86 /* Nonzero if end-of-file has been seen on input. */
87 static int end_of_file
;
89 /* Buffered-back input character; faster than using ungetc. */
90 static int nextchar
= -1;
94 /* Do not insert generated code into the source, instead, include it.
95 This allows us to build gcc automatically even for targets that
96 need to add or modify the reserved keyword lists. */
99 /* Return something to represent absolute declarators containing a *.
100 TARGET is the absolute declarator that the * contains.
101 TYPE_QUALS is a list of modifiers such as const or volatile
102 to apply to the pointer type, represented as identifiers.
104 We return an INDIRECT_REF whose "contents" are TARGET
105 and whose type is the modifier list. */
108 make_pointer_declarator (type_quals
, target
)
109 tree type_quals
, target
;
111 return build1 (INDIRECT_REF
, type_quals
, target
);
115 forget_protocol_qualifiers ()
117 int i
, n
= sizeof wordlist
/ sizeof (struct resword
);
119 for (i
= 0; i
< n
; i
++)
120 if ((int) wordlist
[i
].rid
>= (int) RID_IN
121 && (int) wordlist
[i
].rid
<= (int) RID_ONEWAY
)
122 wordlist
[i
].name
= "";
126 remember_protocol_qualifiers ()
128 int i
, n
= sizeof wordlist
/ sizeof (struct resword
);
130 for (i
= 0; i
< n
; i
++)
131 if (wordlist
[i
].rid
== RID_IN
)
132 wordlist
[i
].name
= "in";
133 else if (wordlist
[i
].rid
== RID_OUT
)
134 wordlist
[i
].name
= "out";
135 else if (wordlist
[i
].rid
== RID_INOUT
)
136 wordlist
[i
].name
= "inout";
137 else if (wordlist
[i
].rid
== RID_BYCOPY
)
138 wordlist
[i
].name
= "bycopy";
139 else if (wordlist
[i
].rid
== RID_ONEWAY
)
140 wordlist
[i
].name
= "oneway";
146 /* Make identifier nodes long enough for the language-specific slots. */
147 set_identifier_size (sizeof (struct lang_identifier
));
149 /* Start it at 0, because check_newline is called at the very beginning
150 and will increment it to 1. */
153 #ifdef MULTIBYTE_CHARS
154 /* Change to the native locale for multibyte conversions. */
155 setlocale (LC_CTYPE
, "");
159 token_buffer
= (char *) xmalloc (maxtoken
+ 2);
161 ridpointers
[(int) RID_INT
] = get_identifier ("int");
162 ridpointers
[(int) RID_CHAR
] = get_identifier ("char");
163 ridpointers
[(int) RID_VOID
] = get_identifier ("void");
164 ridpointers
[(int) RID_FLOAT
] = get_identifier ("float");
165 ridpointers
[(int) RID_DOUBLE
] = get_identifier ("double");
166 ridpointers
[(int) RID_SHORT
] = get_identifier ("short");
167 ridpointers
[(int) RID_LONG
] = get_identifier ("long");
168 ridpointers
[(int) RID_UNSIGNED
] = get_identifier ("unsigned");
169 ridpointers
[(int) RID_SIGNED
] = get_identifier ("signed");
170 ridpointers
[(int) RID_INLINE
] = get_identifier ("inline");
171 ridpointers
[(int) RID_CONST
] = get_identifier ("const");
172 ridpointers
[(int) RID_VOLATILE
] = get_identifier ("volatile");
173 ridpointers
[(int) RID_AUTO
] = get_identifier ("auto");
174 ridpointers
[(int) RID_STATIC
] = get_identifier ("static");
175 ridpointers
[(int) RID_EXTERN
] = get_identifier ("extern");
176 ridpointers
[(int) RID_TYPEDEF
] = get_identifier ("typedef");
177 ridpointers
[(int) RID_REGISTER
] = get_identifier ("register");
178 ridpointers
[(int) RID_ITERATOR
] = get_identifier ("iterator");
179 ridpointers
[(int) RID_COMPLEX
] = get_identifier ("complex");
180 ridpointers
[(int) RID_ID
] = get_identifier ("id");
181 ridpointers
[(int) RID_IN
] = get_identifier ("in");
182 ridpointers
[(int) RID_OUT
] = get_identifier ("out");
183 ridpointers
[(int) RID_INOUT
] = get_identifier ("inout");
184 ridpointers
[(int) RID_BYCOPY
] = get_identifier ("bycopy");
185 ridpointers
[(int) RID_ONEWAY
] = get_identifier ("oneway");
186 forget_protocol_qualifiers();
188 /* Some options inhibit certain reserved words.
189 Clear those words out of the hash table so they won't be recognized. */
190 #define UNSET_RESERVED_WORD(STRING) \
191 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
192 if (s) s->name = ""; } while (0)
194 if (! doing_objc_thang
)
195 UNSET_RESERVED_WORD ("id");
197 if (flag_traditional
)
199 UNSET_RESERVED_WORD ("const");
200 UNSET_RESERVED_WORD ("volatile");
201 UNSET_RESERVED_WORD ("typeof");
202 UNSET_RESERVED_WORD ("signed");
203 UNSET_RESERVED_WORD ("inline");
204 UNSET_RESERVED_WORD ("iterator");
205 UNSET_RESERVED_WORD ("complex");
209 UNSET_RESERVED_WORD ("asm");
210 UNSET_RESERVED_WORD ("typeof");
211 UNSET_RESERVED_WORD ("inline");
212 UNSET_RESERVED_WORD ("iterator");
213 UNSET_RESERVED_WORD ("complex");
218 reinit_parse_for_function ()
222 /* Function used when yydebug is set, to print a token in more detail. */
225 yyprint (file
, yychar
, yylval
)
237 if (IDENTIFIER_POINTER (t
))
238 fprintf (file
, " `%s'", IDENTIFIER_POINTER (t
));
243 if (TREE_CODE (t
) == INTEGER_CST
)
245 #if HOST_BITS_PER_WIDE_INT == 64
246 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
252 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
258 TREE_INT_CST_HIGH (t
), TREE_INT_CST_LOW (t
));
264 /* If C is not whitespace, return C.
265 Otherwise skip whitespace and return first nonwhite char read. */
271 static int newline_warning
= 0;
277 /* We don't recognize comments here, because
278 cpp output can include / and * consecutively as operators.
279 Also, there's no need, since cpp removes all comments. */
282 c
= check_newline ();
294 /* ANSI C says the effects of a carriage return in a source file
296 if (pedantic
&& !newline_warning
)
298 warning ("carriage return in source file");
299 warning ("(we only warn about the first carriage return)");
310 error ("stray '\\' in program");
320 /* Skips all of the white space at the current location in the input file.
321 Must use and reset nextchar if it has the next character. */
324 position_after_white_space ()
329 c
= nextchar
, nextchar
= -1;
333 ungetc (skip_white_space (c
), finput
);
336 /* Make the token buffer longer, preserving the data in it.
337 P should point to just beyond the last valid character in the old buffer.
338 The value we return is a pointer to the new buffer
339 at a place corresponding to P. */
342 extend_token_buffer (p
)
345 int offset
= p
- token_buffer
;
347 maxtoken
= maxtoken
* 2 + 10;
348 token_buffer
= (char *) xrealloc (token_buffer
, maxtoken
+ 2);
350 return token_buffer
+ offset
;
353 /* At the beginning of a line, increment the line number
354 and process any #-directive on this line.
355 If the line is a #-directive, read the entire line and return a newline.
356 Otherwise, return the line's first non-whitespace character. */
366 /* Read first nonwhite char on the line. */
369 while (c
== ' ' || c
== '\t')
374 /* If not #, return it so caller will use it. */
378 /* Read first nonwhite char after the `#'. */
381 while (c
== ' ' || c
== '\t')
384 /* If a letter follows, then if the word here is `line', skip
385 it and ignore it; otherwise, ignore the line, with an error
386 if the word isn't `pragma', `ident', `define', or `undef'. */
388 if ((c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z'))
392 if (getc (finput
) == 'r'
393 && getc (finput
) == 'a'
394 && getc (finput
) == 'g'
395 && getc (finput
) == 'm'
396 && getc (finput
) == 'a'
397 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'))
399 #ifdef HANDLE_SYSV_PRAGMA
400 return handle_sysv_pragma (finput
, c
);
401 #else /* !HANDLE_SYSV_PRAGMA */
403 HANDLE_PRAGMA (finput
);
404 #endif /* HANDLE_PRAGMA */
406 #endif /* !HANDLE_SYSV_PRAGMA */
412 if (getc (finput
) == 'e'
413 && getc (finput
) == 'f'
414 && getc (finput
) == 'i'
415 && getc (finput
) == 'n'
416 && getc (finput
) == 'e'
417 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'))
419 #ifdef DWARF_DEBUGGING_INFO
420 if ((debug_info_level
== DINFO_LEVEL_VERBOSE
)
421 && (write_symbols
== DWARF_DEBUG
))
422 dwarfout_define (lineno
, get_directive_line (finput
));
423 #endif /* DWARF_DEBUGGING_INFO */
429 if (getc (finput
) == 'n'
430 && getc (finput
) == 'd'
431 && getc (finput
) == 'e'
432 && getc (finput
) == 'f'
433 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'))
435 #ifdef DWARF_DEBUGGING_INFO
436 if ((debug_info_level
== DINFO_LEVEL_VERBOSE
)
437 && (write_symbols
== DWARF_DEBUG
))
438 dwarfout_undef (lineno
, get_directive_line (finput
));
439 #endif /* DWARF_DEBUGGING_INFO */
445 if (getc (finput
) == 'i'
446 && getc (finput
) == 'n'
447 && getc (finput
) == 'e'
448 && ((c
= getc (finput
)) == ' ' || c
== '\t'))
453 if (getc (finput
) == 'd'
454 && getc (finput
) == 'e'
455 && getc (finput
) == 'n'
456 && getc (finput
) == 't'
457 && ((c
= getc (finput
)) == ' ' || c
== '\t'))
459 /* #ident. The pedantic warning is now in cccp.c. */
461 /* Here we have just seen `#ident '.
462 A string constant should follow. */
464 while (c
== ' ' || c
== '\t')
467 /* If no argument, ignore the line. */
474 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
476 error ("invalid #ident");
482 #ifdef ASM_OUTPUT_IDENT
483 ASM_OUTPUT_IDENT (asm_out_file
, TREE_STRING_POINTER (yylval
.ttype
));
487 /* Skip the rest of this line. */
492 error ("undefined or invalid # directive");
497 /* Here we have either `#line' or `# <nonletter>'.
498 In either case, it should be a line number; a digit should follow. */
500 while (c
== ' ' || c
== '\t')
503 /* If the # is the only nonwhite char on the line,
504 just ignore it. Check the new newline. */
508 /* Something follows the #; read a token. */
513 if (token
== CONSTANT
514 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
516 int old_lineno
= lineno
;
518 /* subtract one, because it is the following line that
519 gets the specified number */
521 int l
= TREE_INT_CST_LOW (yylval
.ttype
) - 1;
523 /* Is this the last nonwhite stuff on the line? */
525 while (c
== ' ' || c
== '\t')
529 /* No more: store the line number and check following line. */
535 /* More follows: it must be a string constant (filename). */
537 /* Read the string constant. */
540 if (token
!= STRING
|| TREE_CODE (yylval
.ttype
) != STRING_CST
)
542 error ("invalid #line");
547 = (char *) permalloc (TREE_STRING_LENGTH (yylval
.ttype
) + 1);
548 strcpy (input_filename
, TREE_STRING_POINTER (yylval
.ttype
));
551 /* Each change of file name
552 reinitializes whether we are now in a system header. */
553 in_system_header
= 0;
555 if (main_input_filename
== 0)
556 main_input_filename
= input_filename
;
558 /* Is this the last nonwhite stuff on the line? */
560 while (c
== ' ' || c
== '\t')
564 /* Update the name in the top element of input_file_stack. */
565 if (input_file_stack
)
566 input_file_stack
->name
= input_filename
;
575 /* `1' after file name means entering new file.
576 `2' after file name means just left a file. */
578 if (token
== CONSTANT
579 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
581 if (TREE_INT_CST_LOW (yylval
.ttype
) == 1)
583 /* Pushing to a new file. */
585 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
586 input_file_stack
->line
= old_lineno
;
587 p
->next
= input_file_stack
;
588 p
->name
= input_filename
;
589 input_file_stack
= p
;
590 input_file_stack_tick
++;
591 #ifdef DWARF_DEBUGGING_INFO
592 if (debug_info_level
== DINFO_LEVEL_VERBOSE
593 && write_symbols
== DWARF_DEBUG
)
594 dwarfout_start_new_source_file (input_filename
);
595 #endif /* DWARF_DEBUGGING_INFO */
599 else if (TREE_INT_CST_LOW (yylval
.ttype
) == 2)
601 /* Popping out of a file. */
602 if (input_file_stack
->next
)
604 struct file_stack
*p
= input_file_stack
;
605 input_file_stack
= p
->next
;
607 input_file_stack_tick
++;
608 #ifdef DWARF_DEBUGGING_INFO
609 if (debug_info_level
== DINFO_LEVEL_VERBOSE
610 && write_symbols
== DWARF_DEBUG
)
611 dwarfout_resume_previous_source_file (input_file_stack
->line
);
612 #endif /* DWARF_DEBUGGING_INFO */
615 error ("#-lines for entering and leaving files don't match");
621 /* Now that we've pushed or popped the input stack,
622 update the name in the top element. */
623 if (input_file_stack
)
624 input_file_stack
->name
= input_filename
;
626 /* If we have handled a `1' or a `2',
627 see if there is another number to read. */
630 /* Is this the last nonwhite stuff on the line? */
632 while (c
== ' ' || c
== '\t')
642 /* `3' after file name means this is a system header file. */
644 if (token
== CONSTANT
645 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
646 && TREE_INT_CST_LOW (yylval
.ttype
) == 3)
647 in_system_header
= 1;
650 error ("invalid #-line");
652 /* skip the rest of this line. */
656 while ((c
= getc (finput
)) != EOF
&& c
!= '\n');
660 #ifdef HANDLE_SYSV_PRAGMA
662 /* Handle a #pragma directive. INPUT is the current input stream,
663 and C is a character to reread. Processes the entire input line
664 and returns a character for the caller to reread: either \n or EOF. */
666 /* This function has to be in this file, in order to get at
670 handle_sysv_pragma (input
, c
)
676 while (c
== ' ' || c
== '\t')
678 if (c
== '\n' || c
== EOF
)
680 handle_pragma_token (0, 0);
690 handle_pragma_token (token_buffer
, yylval
.ttype
);
693 handle_pragma_token (token_buffer
, 0);
696 c
= nextchar
, nextchar
= -1;
702 #endif /* HANDLE_SYSV_PRAGMA */
704 #define ENDFILE -1 /* token that represents end-of-file */
706 /* Read an escape sequence, returning its equivalent as a character,
707 or store 1 in *ignore_ptr if it is backslash-newline. */
710 readescape (ignore_ptr
)
713 register int c
= getc (finput
);
715 register unsigned count
;
716 unsigned firstdig
= 0;
722 if (warn_traditional
)
723 warning ("the meaning of `\\x' varies with -traditional");
725 if (flag_traditional
)
734 if (!(c
>= 'a' && c
<= 'f')
735 && !(c
>= 'A' && c
<= 'F')
736 && !(c
>= '0' && c
<= '9'))
742 if (c
>= 'a' && c
<= 'f')
743 code
+= c
- 'a' + 10;
744 if (c
>= 'A' && c
<= 'F')
745 code
+= c
- 'A' + 10;
746 if (c
>= '0' && c
<= '9')
748 if (code
!= 0 || count
!= 0)
757 error ("\\x used with no following hex digits");
759 /* Digits are all 0's. Ok. */
761 else if ((count
- 1) * 4 >= TYPE_PRECISION (integer_type_node
)
763 && ((1 << (TYPE_PRECISION (integer_type_node
) - (count
- 1) * 4))
765 pedwarn ("hex escape out of range");
768 case '0': case '1': case '2': case '3': case '4':
769 case '5': case '6': case '7':
772 while ((c
<= '7') && (c
>= '0') && (count
++ < 3))
774 code
= (code
* 8) + (c
- '0');
780 case '\\': case '\'': case '"':
789 return TARGET_NEWLINE
;
804 if (warn_traditional
)
805 warning ("the meaning of `\\a' varies with -traditional");
807 if (flag_traditional
)
812 #if 0 /* Vertical tab is present in common usage compilers. */
813 if (flag_traditional
)
821 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c
);
827 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
831 /* `\%' is used to prevent SCCS from getting confused. */
834 pedwarn ("non-ANSI escape sequence `\\%c'", c
);
837 if (c
>= 040 && c
< 0177)
838 pedwarn ("unknown escape sequence `\\%c'", c
);
840 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c
);
850 strcpy (buf
, string
);
852 /* We can't print string and character constants well
853 because the token_buffer contains the result of processing escapes. */
855 strcat (buf
, " at end of input");
856 else if (token_buffer
[0] == 0)
857 strcat (buf
, " at null character");
858 else if (token_buffer
[0] == '"')
859 strcat (buf
, " before string constant");
860 else if (token_buffer
[0] == '\'')
861 strcat (buf
, " before character constant");
862 else if (token_buffer
[0] < 040 || (unsigned char) token_buffer
[0] >= 0177)
863 sprintf (buf
+ strlen (buf
), " before character 0%o",
864 (unsigned char) token_buffer
[0]);
866 strcat (buf
, " before `%s'");
868 error (buf
, token_buffer
);
881 struct try_type type_sequence
[] =
883 { &integer_type_node
, 0, 0, 0},
884 { &unsigned_type_node
, 1, 0, 0},
885 { &long_integer_type_node
, 0, 1, 0},
886 { &long_unsigned_type_node
, 1, 1, 0},
887 { &long_long_integer_type_node
, 0, 1, 1},
888 { &long_long_unsigned_type_node
, 1, 1, 1}
902 c
= nextchar
, nextchar
= -1;
906 /* Effectively do c = skip_white_space (c)
907 but do it faster in the usual cases. */
920 /* Call skip_white_space so we can warn if appropriate. */
925 c
= skip_white_space (c
);
934 /* yylloc.first_line = lineno; */
945 if (dollars_in_ident
)
950 /* Capital L may start a wide-string or wide-character constant. */
952 register int c
= getc (finput
);
961 goto string_constant
;
968 if (!doing_objc_thang
)
975 /* '@' may start a constant string object. */
976 register int c
= getc(finput
);
980 goto string_constant
;
983 /* Fall through to treat '@' as the start of an indentifier. */
986 case 'A': case 'B': case 'C': case 'D': case 'E':
987 case 'F': case 'G': case 'H': case 'I': case 'J':
988 case 'K': case 'M': case 'N': case 'O':
989 case 'P': case 'Q': case 'R': case 'S': case 'T':
990 case 'U': case 'V': case 'W': case 'X': case 'Y':
992 case 'a': case 'b': case 'c': case 'd': case 'e':
993 case 'f': case 'g': case 'h': case 'i': case 'j':
994 case 'k': case 'l': case 'm': case 'n': case 'o':
995 case 'p': case 'q': case 'r': case 's': case 't':
996 case 'u': case 'v': case 'w': case 'x': case 'y':
1001 while (isalnum (c
) || c
== '_' || c
== '$' || c
== '@')
1003 /* Make sure this char really belongs in an identifier. */
1004 if (c
== '@' && ! doing_objc_thang
)
1006 if (c
== '$' && ! dollars_in_ident
)
1009 if (p
>= token_buffer
+ maxtoken
)
1010 p
= extend_token_buffer (p
);
1022 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1025 register struct resword
*ptr
;
1027 if (ptr
= is_reserved_word (token_buffer
, p
- token_buffer
))
1030 yylval
.ttype
= ridpointers
[(int) ptr
->rid
];
1031 value
= (int) ptr
->token
;
1033 /* Only return OBJECTNAME if it is a typedef. */
1034 if (doing_objc_thang
&& value
== OBJECTNAME
)
1036 lastiddecl
= lookup_name(yylval
.ttype
);
1038 if (lastiddecl
== NULL_TREE
1039 || TREE_CODE (lastiddecl
) != TYPE_DECL
)
1043 /* Even if we decided to recognize asm, still perhaps warn. */
1045 && (value
== ASM_KEYWORD
|| value
== TYPEOF
1046 || ptr
->rid
== RID_INLINE
)
1047 && token_buffer
[0] != '_')
1048 pedwarn ("ANSI does not permit the keyword `%s'",
1053 /* If we did not find a keyword, look for an identifier
1056 if (value
== IDENTIFIER
)
1058 if (token_buffer
[0] == '@')
1059 error("invalid identifier `%s'", token_buffer
);
1061 yylval
.ttype
= get_identifier (token_buffer
);
1062 lastiddecl
= lookup_name (yylval
.ttype
);
1064 if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == TYPE_DECL
)
1066 /* A user-invisible read-only initialized variable
1067 should be replaced by its value.
1068 We handle only strings since that's the only case used in C. */
1069 else if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == VAR_DECL
1070 && DECL_IGNORED_P (lastiddecl
)
1071 && TREE_READONLY (lastiddecl
)
1072 && DECL_INITIAL (lastiddecl
) != 0
1073 && TREE_CODE (DECL_INITIAL (lastiddecl
)) == STRING_CST
)
1075 tree stringval
= DECL_INITIAL (lastiddecl
);
1077 /* Copy the string value so that we won't clobber anything
1078 if we put something in the TREE_CHAIN of this one. */
1079 yylval
.ttype
= build_string (TREE_STRING_LENGTH (stringval
),
1080 TREE_STRING_POINTER (stringval
));
1083 else if (doing_objc_thang
)
1085 tree objc_interface_decl
= is_class_name (yylval
.ttype
);
1087 if (objc_interface_decl
)
1090 yylval
.ttype
= objc_interface_decl
;
1097 case '0': case '1': case '2': case '3': case '4':
1098 case '5': case '6': case '7': case '8': case '9':
1103 int largest_digit
= 0;
1105 /* for multi-precision arithmetic,
1106 we actually store only HOST_BITS_PER_CHAR bits in each part.
1107 The number of parts is chosen so as to be sufficient to hold
1108 the enough bits to fit into the two HOST_WIDE_INTs that contain
1109 the integer value (this is always at least as many bits as are
1110 in a target `long long' value, but may be wider). */
1111 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
1112 int parts
[TOTAL_PARTS
];
1115 enum anon1
{ NOT_FLOAT
, AFTER_POINT
, TOO_MANY_POINTS
} floatflag
1118 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1126 *p
++ = (c
= getc (finput
));
1127 if ((c
== 'x') || (c
== 'X'))
1130 *p
++ = (c
= getc (finput
));
1132 /* Leading 0 forces octal unless the 0 is the only digit. */
1133 else if (c
>= '0' && c
<= '9')
1142 /* Read all the digits-and-decimal-points. */
1145 || (isalnum (c
) && c
!= 'l' && c
!= 'L'
1146 && c
!= 'u' && c
!= 'U'
1147 && c
!= 'i' && c
!= 'I' && c
!= 'j' && c
!= 'J'
1148 && (floatflag
== NOT_FLOAT
|| ((c
!= 'f') && (c
!= 'F')))))
1153 error ("floating constant may not be in radix 16");
1154 if (floatflag
== TOO_MANY_POINTS
)
1155 /* We have already emitted an error. Don't need another. */
1157 else if (floatflag
== AFTER_POINT
)
1159 error ("malformed floating constant");
1160 floatflag
= TOO_MANY_POINTS
;
1161 /* Avoid another error from atof by forcing all characters
1162 from here on to be ignored. */
1166 floatflag
= AFTER_POINT
;
1169 *p
++ = c
= getc (finput
);
1170 /* Accept '.' as the start of a floating-point number
1171 only when it is followed by a digit.
1172 Otherwise, unread the following non-digit
1173 and use the '.' as a structural token. */
1174 if (p
== token_buffer
+ 2 && !isdigit (c
))
1185 error ("parse error at `..'");
1188 token_buffer
[1] = 0;
1195 /* It is not a decimal point.
1196 It should be a digit (perhaps a hex digit). */
1202 else if (base
<= 10)
1204 if (c
== 'e' || c
== 'E')
1207 floatflag
= AFTER_POINT
;
1208 break; /* start of exponent */
1210 error ("nondigits in number and not hexadecimal");
1221 if (c
>= largest_digit
)
1225 for (count
= 0; count
< TOTAL_PARTS
; count
++)
1227 parts
[count
] *= base
;
1231 += (parts
[count
-1] >> HOST_BITS_PER_CHAR
);
1233 &= (1 << HOST_BITS_PER_CHAR
) - 1;
1239 /* If the extra highest-order part ever gets anything in it,
1240 the number is certainly too big. */
1241 if (parts
[TOTAL_PARTS
- 1] != 0)
1244 if (p
>= token_buffer
+ maxtoken
- 3)
1245 p
= extend_token_buffer (p
);
1246 *p
++ = (c
= getc (finput
));
1251 error ("numeric constant with no digits");
1253 if (largest_digit
>= base
)
1254 error ("numeric constant contains digits beyond the radix");
1256 /* Remove terminating char from the token buffer and delimit the string */
1259 if (floatflag
!= NOT_FLOAT
)
1261 tree type
= double_type_node
;
1262 int garbage_chars
= 0, exceeds_double
= 0;
1264 REAL_VALUE_TYPE value
;
1267 /* Read explicit exponent if any, and put it in tokenbuf. */
1269 if ((c
== 'e') || (c
== 'E'))
1271 if (p
>= token_buffer
+ maxtoken
- 3)
1272 p
= extend_token_buffer (p
);
1275 if ((c
== '+') || (c
== '-'))
1281 error ("floating constant exponent has no digits");
1284 if (p
>= token_buffer
+ maxtoken
- 3)
1285 p
= extend_token_buffer (p
);
1294 /* Convert string to a double, checking for overflow. */
1295 if (setjmp (handler
))
1297 error ("floating constant out of range");
1302 int fflag
= 0, lflag
= 0;
1303 /* Copy token_buffer now, while it has just the number
1304 and not the suffixes; once we add `f' or `i',
1305 REAL_VALUE_ATOF may not work any more. */
1306 char *copy
= (char *) alloca (p
- token_buffer
+ 1);
1307 bcopy (token_buffer
, copy
, p
- token_buffer
+ 1);
1309 set_float_handler (handler
);
1315 /* Read the suffixes to choose a data type. */
1320 error ("more than one `f' in numeric constant");
1326 error ("more than one `l' in numeric constant");
1332 error ("more than one `i' or `j' in numeric constant");
1334 pedwarn ("ANSI C forbids imaginary numeric constants");
1345 if (p
>= token_buffer
+ maxtoken
- 3)
1346 p
= extend_token_buffer (p
);
1352 /* The second argument, machine_mode, of REAL_VALUE_ATOF
1353 tells the desired precision of the binary result
1354 of decimal-to-binary conversion. */
1359 error ("both `f' and `l' in floating constant");
1361 type
= float_type_node
;
1362 value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (type
));
1363 /* A diagnostic is required here by some ANSI C testsuites.
1364 This is not pedwarn, become some people don't want
1365 an error for this. */
1366 if (REAL_VALUE_ISINF (value
) && pedantic
)
1367 warning ("floating point number exceeds range of `float'");
1371 type
= long_double_type_node
;
1372 value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (type
));
1373 if (REAL_VALUE_ISINF (value
) && pedantic
)
1374 warning ("floating point number exceeds range of `long double'");
1378 value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (type
));
1379 if (REAL_VALUE_ISINF (value
) && pedantic
)
1380 warning ("floating point number exceeds range of `double'");
1383 set_float_handler (NULL_PTR
);
1386 if (errno
== ERANGE
&& !flag_traditional
&& pedantic
)
1388 /* ERANGE is also reported for underflow,
1389 so test the value to distinguish overflow from that. */
1390 if (REAL_VALUES_LESS (dconst1
, value
)
1391 || REAL_VALUES_LESS (value
, dconstm1
))
1393 warning ("floating point number exceeds range of `double'");
1399 while (isalnum (c
) || c
== '.' || c
== '_'
1400 || (!flag_traditional
&& (c
== '+' || c
== '-')
1401 && (p
[-1] == 'e' || p
[-1] == 'E')))
1403 if (p
>= token_buffer
+ maxtoken
- 3)
1404 p
= extend_token_buffer (p
);
1409 if (garbage_chars
> 0)
1410 error ("garbage at end of number");
1412 /* If the result is not a number, assume it must have been
1413 due to some error message above, so silently convert
1415 if (REAL_VALUE_ISNAN (value
))
1418 /* Create a node with determined type and value. */
1420 yylval
.ttype
= build_complex (convert (type
, integer_zero_node
),
1421 build_real (type
, value
));
1423 yylval
.ttype
= build_real (type
, value
);
1430 tree traditional_type
, ansi_type
, type
;
1431 HOST_WIDE_INT high
, low
;
1432 int spec_unsigned
= 0;
1434 int spec_long_long
= 0;
1440 if (c
== 'u' || c
== 'U')
1443 error ("two `u's in integer constant");
1446 else if (c
== 'l' || c
== 'L')
1451 error ("three `l's in integer constant");
1453 pedwarn ("ANSI C forbids long long integer constants");
1458 else if (c
== 'i' || c
== 'j' || c
== 'I' || c
== 'J')
1461 error ("more than one `i' or `j' in numeric constant");
1463 pedwarn ("ANSI C forbids imaginary numeric constants");
1468 if (isalnum (c
) || c
== '.' || c
== '_'
1469 || (!flag_traditional
&& (c
== '+' || c
== '-')
1470 && (p
[-1] == 'e' || p
[-1] == 'E')))
1472 error ("garbage at end of number");
1473 while (isalnum (c
) || c
== '.' || c
== '_'
1474 || (!flag_traditional
&& (c
== '+' || c
== '-')
1475 && (p
[-1] == 'e' || p
[-1] == 'E')))
1477 if (p
>= token_buffer
+ maxtoken
- 3)
1478 p
= extend_token_buffer (p
);
1485 if (p
>= token_buffer
+ maxtoken
- 3)
1486 p
= extend_token_buffer (p
);
1493 /* If the constant is not long long and it won't fit in an
1494 unsigned long, or if the constant is long long and won't fit
1495 in an unsigned long long, then warn that the constant is out
1498 /* ??? This assumes that long long and long integer types are
1499 a multiple of 8 bits. This better than the original code
1500 though which assumed that long was exactly 32 bits and long
1501 long was exactly 64 bits. */
1504 bytes
= TYPE_PRECISION (long_long_integer_type_node
) / 8;
1506 bytes
= TYPE_PRECISION (long_integer_type_node
) / 8;
1509 for (i
= bytes
; i
< TOTAL_PARTS
; i
++)
1513 pedwarn ("integer constant out of range");
1515 /* This is simplified by the fact that our constant
1516 is always positive. */
1520 for (i
= 0; i
< HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
; i
++)
1522 high
|= ((HOST_WIDE_INT
) parts
[i
+ (HOST_BITS_PER_WIDE_INT
1523 / HOST_BITS_PER_CHAR
)]
1524 << (i
* HOST_BITS_PER_CHAR
));
1525 low
|= (HOST_WIDE_INT
) parts
[i
] << (i
* HOST_BITS_PER_CHAR
);
1528 yylval
.ttype
= build_int_2 (low
, high
);
1529 TREE_TYPE (yylval
.ttype
) = long_long_unsigned_type_node
;
1531 /* If warn_traditional, calculate both the ANSI type and the
1532 traditional type, then see if they disagree.
1533 Otherwise, calculate only the type for the dialect in use. */
1534 if (warn_traditional
|| flag_traditional
)
1536 /* Calculate the traditional type. */
1537 /* Traditionally, any constant is signed;
1538 but if unsigned is specified explicitly, obey that.
1539 Use the smallest size with the right number of bits,
1540 except for one special case with decimal constants. */
1541 if (! spec_long
&& base
!= 10
1542 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1543 traditional_type
= (spec_unsigned
? unsigned_type_node
1544 : integer_type_node
);
1545 /* A decimal constant must be long
1546 if it does not fit in type int.
1547 I think this is independent of whether
1548 the constant is signed. */
1549 else if (! spec_long
&& base
== 10
1550 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1551 traditional_type
= (spec_unsigned
? unsigned_type_node
1552 : integer_type_node
);
1553 else if (! spec_long_long
)
1554 traditional_type
= (spec_unsigned
? long_unsigned_type_node
1555 : long_integer_type_node
);
1557 traditional_type
= (spec_unsigned
1558 ? long_long_unsigned_type_node
1559 : long_long_integer_type_node
);
1561 if (warn_traditional
|| ! flag_traditional
)
1563 /* Calculate the ANSI type. */
1564 if (! spec_long
&& ! spec_unsigned
1565 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1566 ansi_type
= integer_type_node
;
1567 else if (! spec_long
&& (base
!= 10 || spec_unsigned
)
1568 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1569 ansi_type
= unsigned_type_node
;
1570 else if (! spec_unsigned
&& !spec_long_long
1571 && int_fits_type_p (yylval
.ttype
, long_integer_type_node
))
1572 ansi_type
= long_integer_type_node
;
1573 else if (! spec_long_long
)
1574 ansi_type
= long_unsigned_type_node
;
1575 else if (! spec_unsigned
1576 /* Verify value does not overflow into sign bit. */
1577 && TREE_INT_CST_HIGH (yylval
.ttype
) >= 0
1578 && int_fits_type_p (yylval
.ttype
,
1579 long_long_integer_type_node
))
1580 ansi_type
= long_long_integer_type_node
;
1582 ansi_type
= long_long_unsigned_type_node
;
1585 type
= flag_traditional
? traditional_type
: ansi_type
;
1587 if (warn_traditional
&& traditional_type
!= ansi_type
)
1589 if (TYPE_PRECISION (traditional_type
)
1590 != TYPE_PRECISION (ansi_type
))
1591 warning ("width of integer constant changes with -traditional");
1592 else if (TREE_UNSIGNED (traditional_type
)
1593 != TREE_UNSIGNED (ansi_type
))
1594 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1596 warning ("width of integer constant may change on other systems with -traditional");
1599 if (!flag_traditional
&& !int_fits_type_p (yylval
.ttype
, type
)
1601 pedwarn ("integer constant out of range");
1603 if (base
== 10 && ! spec_unsigned
&& TREE_UNSIGNED (type
))
1604 warning ("decimal constant is so large that it is unsigned");
1608 if (TYPE_PRECISION (type
)
1609 <= TYPE_PRECISION (integer_type_node
))
1611 = build_complex (integer_zero_node
,
1612 convert (integer_type_node
, yylval
.ttype
));
1614 error ("complex integer constant is too wide for `complex int'");
1616 else if (flag_traditional
&& !int_fits_type_p (yylval
.ttype
, type
))
1617 /* The traditional constant 0x80000000 is signed
1618 but doesn't fit in the range of int.
1619 This will change it to -0x80000000, which does fit. */
1621 TREE_TYPE (yylval
.ttype
) = unsigned_type (type
);
1622 yylval
.ttype
= convert (type
, yylval
.ttype
);
1623 TREE_OVERFLOW (yylval
.ttype
)
1624 = TREE_CONSTANT_OVERFLOW (yylval
.ttype
) = 0;
1627 TREE_TYPE (yylval
.ttype
) = type
;
1632 value
= CONSTANT
; break;
1638 register int result
= 0;
1639 register int num_chars
= 0;
1640 unsigned width
= TYPE_PRECISION (char_type_node
);
1645 width
= WCHAR_TYPE_SIZE
;
1646 #ifdef MULTIBYTE_CHARS
1647 max_chars
= MB_CUR_MAX
;
1653 max_chars
= TYPE_PRECISION (integer_type_node
) / width
;
1661 if (c
== '\'' || c
== EOF
)
1667 c
= readescape (&ignore
);
1670 if (width
< HOST_BITS_PER_INT
1671 && (unsigned) c
>= (1 << width
))
1672 pedwarn ("escape sequence out of range for character");
1673 #ifdef MAP_CHARACTER
1675 c
= MAP_CHARACTER (c
);
1681 pedwarn ("ANSI C forbids newline in character constant");
1684 #ifdef MAP_CHARACTER
1686 c
= MAP_CHARACTER (c
);
1690 if (num_chars
> maxtoken
- 4)
1691 extend_token_buffer (token_buffer
);
1693 token_buffer
[num_chars
] = c
;
1695 /* Merge character into result; ignore excess chars. */
1696 if (num_chars
< max_chars
+ 1)
1698 if (width
< HOST_BITS_PER_INT
)
1699 result
= (result
<< width
) | (c
& ((1 << width
) - 1));
1705 token_buffer
[num_chars
+ 1] = '\'';
1706 token_buffer
[num_chars
+ 2] = 0;
1709 error ("malformatted character constant");
1710 else if (num_chars
== 0)
1711 error ("empty character constant");
1712 else if (num_chars
> max_chars
)
1714 num_chars
= max_chars
;
1715 error ("character constant too long");
1717 else if (num_chars
!= 1 && ! flag_traditional
)
1718 warning ("multi-character character constant");
1720 /* If char type is signed, sign-extend the constant. */
1723 int num_bits
= num_chars
* width
;
1725 /* We already got an error; avoid invalid shift. */
1726 yylval
.ttype
= build_int_2 (0, 0);
1727 else if (TREE_UNSIGNED (char_type_node
)
1728 || ((result
>> (num_bits
- 1)) & 1) == 0)
1730 = build_int_2 (result
& ((unsigned HOST_WIDE_INT
) ~0
1731 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
1735 = build_int_2 (result
| ~((unsigned HOST_WIDE_INT
) ~0
1736 >> (HOST_BITS_PER_WIDE_INT
- num_bits
)),
1738 TREE_TYPE (yylval
.ttype
) = integer_type_node
;
1742 #ifdef MULTIBYTE_CHARS
1743 /* Set the initial shift state and convert the next sequence. */
1745 /* In all locales L'\0' is zero and mbtowc will return zero,
1748 || (num_chars
== 1 && token_buffer
[1] != '\0'))
1751 (void) mbtowc (NULL_PTR
, NULL_PTR
, 0);
1752 if (mbtowc (& wc
, token_buffer
+ 1, num_chars
) == num_chars
)
1755 warning ("Ignoring invalid multibyte character");
1758 yylval
.ttype
= build_int_2 (result
, 0);
1759 TREE_TYPE (yylval
.ttype
) = wchar_type_node
;
1770 p
= token_buffer
+ 1;
1772 while (c
!= '"' && c
>= 0)
1777 c
= readescape (&ignore
);
1781 && TYPE_PRECISION (char_type_node
) < HOST_BITS_PER_INT
1782 && c
>= (1 << TYPE_PRECISION (char_type_node
)))
1783 pedwarn ("escape sequence out of range for character");
1788 pedwarn ("ANSI C forbids newline in string constant");
1792 if (p
== token_buffer
+ maxtoken
)
1793 p
= extend_token_buffer (p
);
1801 /* We have read the entire constant.
1802 Construct a STRING_CST for the result. */
1806 /* If this is a L"..." wide-string, convert the multibyte string
1807 to a wide character string. */
1808 char *widep
= (char *) alloca ((p
- token_buffer
) * WCHAR_BYTES
);
1811 #ifdef MULTIBYTE_CHARS
1812 len
= mbstowcs ((wchar_t *) widep
, token_buffer
+ 1, p
- token_buffer
);
1813 if (len
< 0 || len
>= (p
- token_buffer
))
1815 warning ("Ignoring invalid multibyte string");
1818 bzero (widep
+ (len
* WCHAR_BYTES
), WCHAR_BYTES
);
1821 union { long l
; char c
[sizeof (long)]; } u
;
1825 /* Determine whether host is little or big endian. */
1827 big_endian
= u
.c
[sizeof (long) - 1];
1828 wp
= widep
+ (big_endian
? WCHAR_BYTES
- 1 : 0);
1830 bzero (widep
, (p
- token_buffer
) * WCHAR_BYTES
);
1831 for (cp
= token_buffer
+ 1; cp
< p
; cp
++)
1832 *wp
= *cp
, wp
+= WCHAR_BYTES
;
1833 len
= p
- token_buffer
- 1;
1836 yylval
.ttype
= build_string ((len
+ 1) * WCHAR_BYTES
, widep
);
1837 TREE_TYPE (yylval
.ttype
) = wchar_array_type_node
;
1842 extern tree
build_objc_string();
1843 /* Return an Objective-C @"..." constant string object. */
1844 yylval
.ttype
= build_objc_string (p
- token_buffer
,
1846 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
1847 value
= OBJC_STRING
;
1851 yylval
.ttype
= build_string (p
- token_buffer
, token_buffer
+ 1);
1852 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
1882 yylval
.code
= PLUS_EXPR
; break;
1884 yylval
.code
= MINUS_EXPR
; break;
1886 yylval
.code
= BIT_AND_EXPR
; break;
1888 yylval
.code
= BIT_IOR_EXPR
; break;
1890 yylval
.code
= MULT_EXPR
; break;
1892 yylval
.code
= TRUNC_DIV_EXPR
; break;
1894 yylval
.code
= TRUNC_MOD_EXPR
; break;
1896 yylval
.code
= BIT_XOR_EXPR
; break;
1898 yylval
.code
= LSHIFT_EXPR
; break;
1900 yylval
.code
= RSHIFT_EXPR
; break;
1902 yylval
.code
= LT_EXPR
; break;
1904 yylval
.code
= GT_EXPR
; break;
1907 token_buffer
[1] = c1
= getc (finput
);
1908 token_buffer
[2] = 0;
1915 value
= ARITHCOMPARE
; yylval
.code
= LE_EXPR
; goto done
;
1917 value
= ARITHCOMPARE
; yylval
.code
= GE_EXPR
; goto done
;
1919 value
= EQCOMPARE
; yylval
.code
= NE_EXPR
; goto done
;
1921 value
= EQCOMPARE
; yylval
.code
= EQ_EXPR
; goto done
;
1923 value
= ASSIGN
; goto done
;
1929 value
= PLUSPLUS
; goto done
;
1931 value
= MINUSMINUS
; goto done
;
1933 value
= ANDAND
; goto done
;
1935 value
= OROR
; goto done
;
1943 else if ((c
== '-') && (c1
== '>'))
1944 { value
= POINTSAT
; goto done
; }
1945 ungetc (c1
, finput
);
1946 token_buffer
[1] = 0;
1948 if ((c
== '<') || (c
== '>'))
1949 value
= ARITHCOMPARE
;
1955 /* Don't make yyparse think this is eof. */
1964 /* yylloc.last_line = lineno; */
1969 /* Sets the value of the 'yydebug' variable to VALUE.
1970 This is a function so we don't have to have YYDEBUG defined
1971 in order to build the compiler. */
1980 warning ("YYDEBUG not defined.");