1 /* Lexical analyzer for C and Objective C.
2 Copyright (C) 1987, 1988, 1989, 1992 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. */
34 #ifdef MULTIBYTE_CHARS
43 /* The elements of `ridpointers' are identifier nodes
44 for the reserved type names and storage classes.
45 It is indexed by a RID_... value. */
46 tree ridpointers
[(int) RID_MAX
];
48 /* Cause the `yydebug' variable to be defined. */
51 /* the declaration found for the last IDENTIFIER token read in.
52 yylex must look this up to detect typedefs, which get token type TYPENAME,
53 so it is left around in case the identifier is not a typedef but is
54 used in a context which makes it a reference to a variable. */
57 /* Nonzero enables objc features. */
61 extern tree
lookup_interface ();
65 /* File used for outputting assembler code. */
66 extern FILE *asm_out_file
;
68 #ifndef WCHAR_TYPE_SIZE
70 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
72 #define WCHAR_TYPE_SIZE BITS_PER_WORD
76 /* Number of bytes in a wide character. */
77 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
79 static int maxtoken
; /* Current nominal length of token buffer. */
80 char *token_buffer
; /* Pointer to token buffer.
81 Actual allocated length is maxtoken + 2.
82 This is not static because objc-parse.y uses it. */
84 /* Nonzero if end-of-file has been seen on input. */
85 static int end_of_file
;
87 /* Buffered-back input character; faster than using ungetc. */
88 static int nextchar
= -1;
92 /* Nonzero tells yylex to ignore \ in string constants. */
93 static int ignore_escape_flag
= 0;
95 /* C code produced by gperf version 2.5 (GNU C++ version) */
96 /* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */
97 struct resword
{ char *name
; short token
; enum rid rid
; };
99 #define TOTAL_KEYWORDS 53
100 #define MIN_WORD_LENGTH 2
101 #define MAX_WORD_LENGTH 13
102 #define MIN_HASH_VALUE 7
103 #define MAX_HASH_VALUE 102
104 /* maximum key range = 96, duplicates = 0 */
112 register int unsigned len
;
114 static unsigned char asso_values
[] =
116 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
117 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
118 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
119 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
120 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
121 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
122 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
123 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
124 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
125 103, 103, 103, 103, 103, 1, 103, 2, 1, 24,
126 1, 5, 19, 39, 16, 13, 103, 1, 25, 1,
127 34, 34, 24, 103, 13, 12, 1, 45, 24, 7,
128 103, 103, 2, 103, 103, 103, 103, 103,
130 register int hval
= len
;
136 hval
+= asso_values
[str
[2]];
139 hval
+= asso_values
[str
[0]];
141 return hval
+ asso_values
[str
[len
- 1]];
148 is_reserved_word (str
, len
)
150 register unsigned int len
;
152 static struct resword wordlist
[] =
154 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
155 {"asm", ASM_KEYWORD
, NORID
},
157 {"__asm", ASM_KEYWORD
, NORID
},
159 {"__asm__", ASM_KEYWORD
, NORID
},
160 {"break", BREAK
, NORID
},
161 {"__typeof__", TYPEOF
, NORID
},
163 {"__alignof__", ALIGNOF
, NORID
},
165 {"__attribute__", ATTRIBUTE
, NORID
},
166 {"int", TYPESPEC
, RID_INT
},
167 {"__attribute", ATTRIBUTE
, NORID
},
168 {"__extension__", EXTENSION
, NORID
},
170 {"__signed", TYPESPEC
, RID_SIGNED
},
172 {"__signed__", TYPESPEC
, RID_SIGNED
},
173 {"__inline__", SCSPEC
, RID_INLINE
},
174 {"else", ELSE
, NORID
},
175 {"__inline", SCSPEC
, RID_INLINE
},
176 {"default", DEFAULT
, NORID
},
177 {"__typeof", TYPEOF
, NORID
},
178 {"while", WHILE
, NORID
},
179 {"__alignof", ALIGNOF
, NORID
},
180 {"struct", STRUCT
, NORID
},
181 {"__const", TYPE_QUAL
, RID_CONST
},
183 {"__const__", TYPE_QUAL
, RID_CONST
},
184 {"__label__", LABEL
, NORID
},
186 {"__volatile__", TYPE_QUAL
, RID_VOLATILE
},
187 {"sizeof", SIZEOF
, NORID
},
188 {"__volatile", TYPE_QUAL
, RID_VOLATILE
},
189 {"auto", SCSPEC
, RID_AUTO
},
190 {"void", TYPESPEC
, RID_VOID
},
191 {"char", TYPESPEC
, RID_CHAR
},
192 {"static", SCSPEC
, RID_STATIC
},
193 {"case", CASE
, NORID
},
194 {"extern", SCSPEC
, RID_EXTERN
},
195 {"switch", SWITCH
, NORID
},
197 {"inline", SCSPEC
, RID_INLINE
},
198 {"typeof", TYPEOF
, NORID
},
199 {"typedef", SCSPEC
, RID_TYPEDEF
},
200 {"short", TYPESPEC
, RID_SHORT
},
202 {"return", RETURN
, NORID
},
203 {"enum", ENUM
, NORID
},
205 {"double", TYPESPEC
, RID_DOUBLE
},
206 {"signed", TYPESPEC
, RID_SIGNED
},
207 {"float", TYPESPEC
, RID_FLOAT
},
209 {"volatile", TYPE_QUAL
, RID_VOLATILE
},
211 {"const", TYPE_QUAL
, RID_CONST
},
213 {"unsigned", TYPESPEC
, RID_UNSIGNED
},
214 {"",}, {"",}, {"",}, {"",},
215 {"continue", CONTINUE
, NORID
},
217 {"register", SCSPEC
, RID_REGISTER
},
218 {"",}, {"",}, {"",}, {"",},
219 {"goto", GOTO
, NORID
},
220 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
221 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
223 {"union", UNION
, NORID
},
224 {"",}, {"",}, {"",}, {"",},
225 {"long", TYPESPEC
, RID_LONG
},
228 if (len
<= MAX_WORD_LENGTH
&& len
>= MIN_WORD_LENGTH
)
230 register int key
= hash (str
, len
);
232 if (key
<= MAX_HASH_VALUE
&& key
>= 0)
234 register char *s
= wordlist
[key
].name
;
236 if (*s
== *str
&& !strcmp (str
+ 1, s
+ 1))
237 return &wordlist
[key
];
243 /* Return something to represent absolute declarators containing a *.
244 TARGET is the absolute declarator that the * contains.
245 TYPE_QUALS is a list of modifiers such as const or volatile
246 to apply to the pointer type, represented as identifiers.
248 We return an INDIRECT_REF whose "contents" are TARGET
249 and whose type is the modifier list. */
252 make_pointer_declarator (type_quals
, target
)
253 tree type_quals
, target
;
255 return build1 (INDIRECT_REF
, type_quals
, target
);
261 /* Make identifier nodes long enough for the language-specific slots. */
262 set_identifier_size (sizeof (struct lang_identifier
));
264 /* Start it at 0, because check_newline is called at the very beginning
265 and will increment it to 1. */
268 #ifdef MULTIBYTE_CHARS
269 /* Change to the native locale for multibyte conversions. */
270 setlocale (LC_CTYPE
, "");
274 token_buffer
= (char *) xmalloc (maxtoken
+ 2);
276 ridpointers
[(int) RID_INT
] = get_identifier ("int");
277 ridpointers
[(int) RID_CHAR
] = get_identifier ("char");
278 ridpointers
[(int) RID_VOID
] = get_identifier ("void");
279 ridpointers
[(int) RID_FLOAT
] = get_identifier ("float");
280 ridpointers
[(int) RID_DOUBLE
] = get_identifier ("double");
281 ridpointers
[(int) RID_SHORT
] = get_identifier ("short");
282 ridpointers
[(int) RID_LONG
] = get_identifier ("long");
283 ridpointers
[(int) RID_UNSIGNED
] = get_identifier ("unsigned");
284 ridpointers
[(int) RID_SIGNED
] = get_identifier ("signed");
285 ridpointers
[(int) RID_INLINE
] = get_identifier ("inline");
286 ridpointers
[(int) RID_CONST
] = get_identifier ("const");
287 ridpointers
[(int) RID_VOLATILE
] = get_identifier ("volatile");
288 ridpointers
[(int) RID_AUTO
] = get_identifier ("auto");
289 ridpointers
[(int) RID_STATIC
] = get_identifier ("static");
290 ridpointers
[(int) RID_EXTERN
] = get_identifier ("extern");
291 ridpointers
[(int) RID_TYPEDEF
] = get_identifier ("typedef");
292 ridpointers
[(int) RID_REGISTER
] = get_identifier ("register");
294 /* Some options inhibit certain reserved words.
295 Clear those words out of the hash table so they won't be recognized. */
296 #define UNSET_RESERVED_WORD(STRING) \
297 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
298 if (s) s->name = ""; } while (0)
300 if (flag_traditional
)
302 UNSET_RESERVED_WORD ("const");
303 UNSET_RESERVED_WORD ("volatile");
304 UNSET_RESERVED_WORD ("typeof");
305 UNSET_RESERVED_WORD ("signed");
306 UNSET_RESERVED_WORD ("inline");
310 UNSET_RESERVED_WORD ("asm");
311 UNSET_RESERVED_WORD ("typeof");
312 UNSET_RESERVED_WORD ("inline");
317 reinit_parse_for_function ()
321 /* Function used when yydebug is set, to print a token in more detail. */
324 yyprint (file
, yychar
, yylval
)
335 if (IDENTIFIER_POINTER (t
))
336 fprintf (file
, " `%s'", IDENTIFIER_POINTER (t
));
341 if (TREE_CODE (t
) == INTEGER_CST
)
342 fprintf (file
, " 0x%8x%8x", TREE_INT_CST_HIGH (t
),
343 TREE_INT_CST_LOW (t
));
349 /* If C is not whitespace, return C.
350 Otherwise skip whitespace and return first nonwhite char read. */
356 static int newline_warning
= 0;
362 /* We don't recognize comments here, because
363 cpp output can include / and * consecutively as operators.
364 Also, there's no need, since cpp removes all comments. */
367 c
= check_newline ();
379 /* ANSI C says the effects of a carriage return in a source file
381 if (pedantic
&& !newline_warning
)
383 warning ("carriage return in source file");
384 warning ("(we only warn about the first carriage return)");
395 error ("stray '\\' in program");
405 /* Skips all of the white space at the current location in the input file.
406 Must use and reset nextchar if it has the next character. */
409 position_after_white_space ()
414 c
= nextchar
, nextchar
= -1;
418 ungetc (skip_white_space (c
), finput
);
421 /* Make the token buffer longer, preserving the data in it.
422 P should point to just beyond the last valid character in the old buffer.
423 The value we return is a pointer to the new buffer
424 at a place corresponding to P. */
427 extend_token_buffer (p
)
430 int offset
= p
- token_buffer
;
432 maxtoken
= maxtoken
* 2 + 10;
433 token_buffer
= (char *) xrealloc (token_buffer
, maxtoken
+ 2);
435 return token_buffer
+ offset
;
438 /* At the beginning of a line, increment the line number
439 and process any #-directive on this line.
440 If the line is a #-directive, read the entire line and return a newline.
441 Otherwise, return the line's first non-whitespace character. */
451 /* Read first nonwhite char on the line. */
454 while (c
== ' ' || c
== '\t')
459 /* If not #, return it so caller will use it. */
463 /* Read first nonwhite char after the `#'. */
466 while (c
== ' ' || c
== '\t')
469 /* If a letter follows, then if the word here is `line', skip
470 it and ignore it; otherwise, ignore the line, with an error
471 if the word isn't `pragma', `ident', `define', or `undef'. */
473 if ((c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z'))
477 if (getc (finput
) == 'r'
478 && getc (finput
) == 'a'
479 && getc (finput
) == 'g'
480 && getc (finput
) == 'm'
481 && getc (finput
) == 'a'
482 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'))
485 HANDLE_PRAGMA (finput
);
486 #endif /* HANDLE_PRAGMA */
493 if (getc (finput
) == 'e'
494 && getc (finput
) == 'f'
495 && getc (finput
) == 'i'
496 && getc (finput
) == 'n'
497 && getc (finput
) == 'e'
498 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'))
500 #ifdef DWARF_DEBUGGING_INFO
501 if ((debug_info_level
== DINFO_LEVEL_VERBOSE
)
502 && (write_symbols
== DWARF_DEBUG
))
503 dwarfout_define (lineno
, get_directive_line (finput
));
504 #endif /* DWARF_DEBUGGING_INFO */
510 if (getc (finput
) == 'n'
511 && getc (finput
) == 'd'
512 && getc (finput
) == 'e'
513 && getc (finput
) == 'f'
514 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'))
516 #ifdef DWARF_DEBUGGING_INFO
517 if ((debug_info_level
== DINFO_LEVEL_VERBOSE
)
518 && (write_symbols
== DWARF_DEBUG
))
519 dwarfout_undef (lineno
, get_directive_line (finput
));
520 #endif /* DWARF_DEBUGGING_INFO */
526 if (getc (finput
) == 'i'
527 && getc (finput
) == 'n'
528 && getc (finput
) == 'e'
529 && ((c
= getc (finput
)) == ' ' || c
== '\t'))
534 if (getc (finput
) == 'd'
535 && getc (finput
) == 'e'
536 && getc (finput
) == 'n'
537 && getc (finput
) == 't'
538 && ((c
= getc (finput
)) == ' ' || c
== '\t'))
540 /* #ident. The pedantic warning is now in cccp.c. */
542 /* Here we have just seen `#ident '.
543 A string constant should follow. */
545 while (c
== ' ' || c
== '\t')
548 /* If no argument, ignore the line. */
555 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
557 error ("invalid #ident");
563 #ifdef ASM_OUTPUT_IDENT
564 ASM_OUTPUT_IDENT (asm_out_file
, TREE_STRING_POINTER (yylval
.ttype
));
568 /* Skip the rest of this line. */
573 error ("undefined or invalid # directive");
578 /* Here we have either `#line' or `# <nonletter>'.
579 In either case, it should be a line number; a digit should follow. */
581 while (c
== ' ' || c
== '\t')
584 /* If the # is the only nonwhite char on the line,
585 just ignore it. Check the new newline. */
589 /* Something follows the #; read a token. */
594 if (token
== CONSTANT
595 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
597 int old_lineno
= lineno
;
599 /* subtract one, because it is the following line that
600 gets the specified number */
602 int l
= TREE_INT_CST_LOW (yylval
.ttype
) - 1;
604 /* Is this the last nonwhite stuff on the line? */
606 while (c
== ' ' || c
== '\t')
610 /* No more: store the line number and check following line. */
616 /* More follows: it must be a string constant (filename). */
618 /* Read the string constant, but don't treat \ as special. */
619 ignore_escape_flag
= 1;
621 ignore_escape_flag
= 0;
623 if (token
!= STRING
|| TREE_CODE (yylval
.ttype
) != STRING_CST
)
625 error ("invalid #line");
630 = (char *) permalloc (TREE_STRING_LENGTH (yylval
.ttype
) + 1);
631 strcpy (input_filename
, TREE_STRING_POINTER (yylval
.ttype
));
634 /* Each change of file name
635 reinitializes whether we are now in a system header. */
636 in_system_header
= 0;
638 if (main_input_filename
== 0)
639 main_input_filename
= input_filename
;
641 /* Is this the last nonwhite stuff on the line? */
643 while (c
== ' ' || c
== '\t')
652 /* `1' after file name means entering new file.
653 `2' after file name means just left a file. */
655 if (token
== CONSTANT
656 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
658 if (TREE_INT_CST_LOW (yylval
.ttype
) == 1)
660 /* Pushing to a new file. */
662 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
663 input_file_stack
->line
= old_lineno
;
664 p
->next
= input_file_stack
;
665 p
->name
= input_filename
;
666 input_file_stack
= p
;
667 input_file_stack_tick
++;
668 #ifdef DWARF_DEBUGGING_INFO
669 if (debug_info_level
== DINFO_LEVEL_VERBOSE
670 && write_symbols
== DWARF_DEBUG
)
671 dwarfout_start_new_source_file (input_filename
);
672 #endif /* DWARF_DEBUGGING_INFO */
676 else if (TREE_INT_CST_LOW (yylval
.ttype
) == 2)
678 /* Popping out of a file. */
679 if (input_file_stack
->next
)
681 struct file_stack
*p
= input_file_stack
;
682 input_file_stack
= p
->next
;
684 input_file_stack_tick
++;
685 #ifdef DWARF_DEBUGGING_INFO
686 if (debug_info_level
== DINFO_LEVEL_VERBOSE
687 && write_symbols
== DWARF_DEBUG
)
688 dwarfout_resume_previous_source_file (input_file_stack
->line
);
689 #endif /* DWARF_DEBUGGING_INFO */
692 error ("#-lines for entering and leaving files don't match");
698 /* If we have handled a `1' or a `2',
699 see if there is another number to read. */
702 /* Is this the last nonwhite stuff on the line? */
704 while (c
== ' ' || c
== '\t')
714 /* `3' after file name means this is a system header file. */
716 if (token
== CONSTANT
717 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
718 && TREE_INT_CST_LOW (yylval
.ttype
) == 3)
719 in_system_header
= 1;
722 error ("invalid #-line");
724 /* skip the rest of this line. */
728 while ((c
= getc (finput
)) != EOF
&& c
!= '\n');
732 #define isalnum(char) ((char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'))
733 #define isdigit(char) (char >= '0' && char <= '9')
734 #define ENDFILE -1 /* token that represents end-of-file */
736 /* Read an escape sequence, returning its equivalent as a character,
737 or -1 if it is backslash-newline. */
742 register int c
= getc (finput
);
744 register unsigned count
;
750 if (warn_traditional
)
751 warning ("the meaning of `\\x' varies with -traditional");
753 if (flag_traditional
)
761 if (!(c
>= 'a' && c
<= 'f')
762 && !(c
>= 'A' && c
<= 'F')
763 && !(c
>= '0' && c
<= '9'))
769 if (c
>= 'a' && c
<= 'f')
770 code
+= c
- 'a' + 10;
771 if (c
>= 'A' && c
<= 'F')
772 code
+= c
- 'A' + 10;
773 if (c
>= '0' && c
<= '9')
780 error ("\\x used with no following hex digits");
781 else if ((count
- 1) * 4 >= TYPE_PRECISION (integer_type_node
)
783 && ((1 << (TYPE_PRECISION (integer_type_node
) - (count
- 1) * 4))
785 pedwarn ("hex escape out of range");
788 case '0': case '1': case '2': case '3': case '4':
789 case '5': case '6': case '7':
792 while ((c
<= '7') && (c
>= '0') && (count
++ < 3))
794 code
= (code
* 8) + (c
- '0');
800 case '\\': case '\'': case '"':
808 return TARGET_NEWLINE
;
823 if (warn_traditional
)
824 warning ("the meaning of `\\a' varies with -traditional");
826 if (flag_traditional
)
831 #if 0 /* Vertical tab is present in common usage compilers. */
832 if (flag_traditional
)
838 pedwarn ("non-ANSI-standard escape sequence, `\\E'");
844 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
849 pedwarn ("non-ANSI escape sequence `\\%c'", c
);
852 if (c
>= 040 && c
<= 0177)
853 pedwarn ("unknown escape sequence `\\%c'", c
);
855 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c
);
865 strcpy (buf
, string
);
867 /* We can't print string and character constants well
868 because the token_buffer contains the result of processing escapes. */
870 strcat (buf
, " at end of input");
871 else if (token_buffer
[0] == 0)
872 strcat (buf
, " at null character");
873 else if (token_buffer
[0] == '"')
874 strcat (buf
, " before string constant");
875 else if (token_buffer
[0] == '\'')
876 strcat (buf
, " before character constant");
877 else if (token_buffer
[0] < 040 || (unsigned char) token_buffer
[0] >= 0177)
878 sprintf (buf
+ strlen (buf
), " before character 0%o",
879 (unsigned char) token_buffer
[0]);
881 strcat (buf
, " before `%s'");
883 error (buf
, token_buffer
);
896 struct try_type type_sequence
[] =
898 { &integer_type_node
, 0, 0, 0},
899 { &unsigned_type_node
, 1, 0, 0},
900 { &long_integer_type_node
, 0, 1, 0},
901 { &long_unsigned_type_node
, 1, 1, 0},
902 { &long_long_integer_type_node
, 0, 1, 1},
903 { &long_long_unsigned_type_node
, 1, 1, 1}
916 c
= nextchar
, nextchar
= -1;
920 /* Effectively do c = skip_white_space (c)
921 but do it faster in the usual cases. */
926 if (!flag_traditional
) /* ANSI says no */
939 c
= skip_white_space (c
);
948 /* yylloc.first_line = lineno; */
959 if (dollars_in_ident
)
964 /* Capital L may start a wide-string or wide-character constant. */
966 register int c
= getc (finput
);
975 goto string_constant
;
982 if (!doing_objc_thang
)
990 while (isalnum (c
) || c
== '_')
992 if (p
>= token_buffer
+ maxtoken
)
993 p
= extend_token_buffer (p
);
1001 value
= recognize_objc_keyword (token_buffer
+ 1);
1004 error ("invalid Objective C keyword `%s'", token_buffer
);
1005 /* Cause a syntax error--1 is not a valid token type. */
1009 case 'A': case 'B': case 'C': case 'D': case 'E':
1010 case 'F': case 'G': case 'H': case 'I': case 'J':
1011 case 'K': case 'M': case 'N': case 'O':
1012 case 'P': case 'Q': case 'R': case 'S': case 'T':
1013 case 'U': case 'V': case 'W': case 'X': case 'Y':
1015 case 'a': case 'b': case 'c': case 'd': case 'e':
1016 case 'f': case 'g': case 'h': case 'i': case 'j':
1017 case 'k': case 'l': case 'm': case 'n': case 'o':
1018 case 'p': case 'q': case 'r': case 's': case 't':
1019 case 'u': case 'v': case 'w': case 'x': case 'y':
1024 while (isalnum (c
) || c
== '_' || c
== '$' || c
== '@')
1026 if (p
>= token_buffer
+ maxtoken
)
1027 p
= extend_token_buffer (p
);
1028 if (c
== '$' && ! dollars_in_ident
)
1041 /* Try to recognize a keyword. Uses minimum-perfect hash function */
1044 register struct resword
*ptr
;
1046 if (ptr
= is_reserved_word (token_buffer
, p
- token_buffer
))
1049 yylval
.ttype
= ridpointers
[(int) ptr
->rid
];
1050 value
= (int) ptr
->token
;
1052 /* Even if we decided to recognize asm, still perhaps warn. */
1054 && (value
== ASM_KEYWORD
|| value
== TYPEOF
1055 || ptr
->rid
== RID_INLINE
)
1056 && token_buffer
[0] != '_')
1057 pedwarn ("ANSI does not permit the keyword `%s'",
1062 /* If we did not find a keyword, look for an identifier
1065 if (value
== IDENTIFIER
)
1067 yylval
.ttype
= get_identifier (token_buffer
);
1068 lastiddecl
= lookup_name (yylval
.ttype
);
1070 if (lastiddecl
!= 0 && TREE_CODE (lastiddecl
) == TYPE_DECL
)
1072 else if (doing_objc_thang
)
1074 tree objc_interface_decl
= lookup_interface (yylval
.ttype
);
1076 if (objc_interface_decl
)
1079 yylval
.ttype
= objc_interface_decl
;
1086 case '0': case '1': case '2': case '3': case '4':
1087 case '5': case '6': case '7': case '8': case '9':
1092 int largest_digit
= 0;
1094 /* for multi-precision arithmetic,
1095 we store only 8 live bits in each short,
1096 giving us 64 bits of reliable precision */
1100 enum anon1
{ NOT_FLOAT
, AFTER_POINT
, TOO_MANY_POINTS
} floatflag
1103 for (count
= 0; count
< 8; count
++)
1111 *p
++ = (c
= getc (finput
));
1112 if ((c
== 'x') || (c
== 'X'))
1115 *p
++ = (c
= getc (finput
));
1117 /* Leading 0 forces octal unless the 0 is the only digit. */
1118 else if (c
>= '0' && c
<= '9')
1127 /* Read all the digits-and-decimal-points. */
1130 || (isalnum (c
) && (c
!= 'l') && (c
!= 'L')
1131 && (c
!= 'u') && (c
!= 'U')
1132 && (floatflag
== NOT_FLOAT
|| ((c
!= 'f') && (c
!= 'F')))))
1137 error ("floating constant may not be in radix 16");
1138 if (floatflag
== AFTER_POINT
)
1140 error ("malformed floating constant");
1141 floatflag
= TOO_MANY_POINTS
;
1144 floatflag
= AFTER_POINT
;
1147 *p
++ = c
= getc (finput
);
1148 /* Accept '.' as the start of a floating-point number
1149 only when it is followed by a digit.
1150 Otherwise, unread the following non-digit
1151 and use the '.' as a structural token. */
1152 if (p
== token_buffer
+ 2 && !isdigit (c
))
1163 error ("parse error at `..'");
1166 token_buffer
[1] = 0;
1173 /* It is not a decimal point.
1174 It should be a digit (perhaps a hex digit). */
1180 else if (base
<= 10)
1182 if ((c
&~040) == 'E')
1185 floatflag
= AFTER_POINT
;
1186 break; /* start of exponent */
1188 error ("nondigits in number and not hexadecimal");
1199 if (c
>= largest_digit
)
1203 for (count
= 0; count
< 8; count
++)
1205 shorts
[count
] *= base
;
1208 shorts
[count
] += (shorts
[count
-1] >> 8);
1209 shorts
[count
-1] &= (1<<8)-1;
1211 else shorts
[0] += c
;
1214 if (shorts
[7] >= 1<<8
1215 || shorts
[7] < - (1 << 8))
1218 if (p
>= token_buffer
+ maxtoken
- 3)
1219 p
= extend_token_buffer (p
);
1220 *p
++ = (c
= getc (finput
));
1225 error ("numeric constant with no digits");
1227 if (largest_digit
>= base
)
1228 error ("numeric constant contains digits beyond the radix");
1230 /* Remove terminating char from the token buffer and delimit the string */
1233 if (floatflag
!= NOT_FLOAT
)
1235 tree type
= double_type_node
;
1238 REAL_VALUE_TYPE value
;
1241 /* Read explicit exponent if any, and put it in tokenbuf. */
1243 if ((c
== 'e') || (c
== 'E'))
1245 if (p
>= token_buffer
+ maxtoken
- 3)
1246 p
= extend_token_buffer (p
);
1249 if ((c
== '+') || (c
== '-'))
1255 error ("floating constant exponent has no digits");
1258 if (p
>= token_buffer
+ maxtoken
- 3)
1259 p
= extend_token_buffer (p
);
1268 /* Convert string to a double, checking for overflow. */
1269 if (setjmp (handler
))
1271 error ("floating constant out of range");
1276 set_float_handler (handler
);
1277 value
= REAL_VALUE_ATOF (token_buffer
);
1278 set_float_handler (0);
1281 if (errno
== ERANGE
&& !flag_traditional
)
1283 char *p1
= token_buffer
;
1284 /* Check for "0.0" and variants;
1285 Sunos 4 spuriously returns ERANGE for them. */
1286 while (*p1
== '0') p1
++;
1290 while (*p1
== '0') p1
++;
1292 if (*p1
== 'e' || *p1
== 'E')
1294 /* with significand==0, ignore the exponent */
1296 while (*p1
!= 0) p1
++;
1298 /* ERANGE is also reported for underflow,
1299 so test the value to distinguish overflow from that. */
1300 if (*p1
!= 0 && (value
> 1.0 || value
< -1.0))
1301 warning ("floating point number exceeds range of `double'");
1305 /* Read the suffixes to choose a data type. */
1308 if (c
== 'f' || c
== 'F')
1311 error ("two `f's in floating constant");
1313 type
= float_type_node
;
1314 value
= REAL_VALUE_TRUNCATE (TYPE_MODE (type
), value
);
1316 else if (c
== 'l' || c
== 'L')
1319 error ("two `l's in floating constant");
1321 type
= long_double_type_node
;
1327 error ("garbage at end of number");
1330 if (p
>= token_buffer
+ maxtoken
- 3)
1331 p
= extend_token_buffer (p
);
1338 if (p
>= token_buffer
+ maxtoken
- 3)
1339 p
= extend_token_buffer (p
);
1344 /* Create a node with determined type and value. */
1345 yylval
.ttype
= build_real (type
, value
);
1352 tree traditional_type
, ansi_type
, type
;
1353 int spec_unsigned
= 0;
1355 int spec_long_long
= 0;
1360 if (c
== 'u' || c
== 'U')
1363 error ("two `u's in integer constant");
1366 else if (c
== 'l' || c
== 'L')
1371 error ("three `l's in integer constant");
1373 pedwarn ("ANSI C forbids long long integer constants");
1382 error ("garbage at end of number");
1385 if (p
>= token_buffer
+ maxtoken
- 3)
1386 p
= extend_token_buffer (p
);
1393 if (p
>= token_buffer
+ maxtoken
- 3)
1394 p
= extend_token_buffer (p
);
1401 /* If the constant is not long long and it won't fit in an
1402 unsigned long, or if the constant is long long and won't fit
1403 in an unsigned long long, then warn that the constant is out
1406 /* ??? This assumes that long long and long integer types are
1407 a multiple of 8 bits. This better than the original code
1408 though which assumed that long was exactly 32 bits and long
1409 long was exactly 64 bits. */
1412 bytes
= TYPE_PRECISION (long_long_integer_type_node
) / 8;
1414 bytes
= TYPE_PRECISION (long_integer_type_node
) / 8;
1419 for (i
= bytes
; i
< 8; i
++)
1422 /* If LL was not used, then clear any excess precision.
1423 This is equivalent to the original code, but it is
1424 not clear why this is being done. Perhaps to prevent
1425 ANSI programs from creating long long constants
1427 if (! spec_long_long
)
1432 warning ("integer constant out of range");
1435 warning ("integer constant larger than compiler can handle");
1437 /* If it overflowed our internal buffer, then make it unsigned.
1438 We can't distinguish based on the tree node because
1439 any integer constant fits any long long type. */
1443 /* This is simplified by the fact that our constant
1444 is always positive. */
1445 /* The casts in the following statement should not be
1446 needed, but they get around bugs in some C compilers. */
1449 ((((long)shorts
[3]<<24) + ((long)shorts
[2]<<16)
1450 + ((long)shorts
[1]<<8) + (long)shorts
[0]),
1451 (((long)shorts
[7]<<24) + ((long)shorts
[6]<<16)
1452 + ((long)shorts
[5]<<8) + (long)shorts
[4])));
1455 /* Find the first allowable type that the value fits in. */
1457 for (i
= 0; i
< sizeof (type_sequence
) / sizeof (type_sequence
[0]);
1459 if (!(spec_long
&& !type_sequence
[i
].long_flag
)
1460 && !(spec_long_long
&& !type_sequence
[i
].long_long_flag
)
1461 && !(spec_unsigned
&& !type_sequence
[i
].unsigned_flag
)
1462 /* A decimal constant can't be unsigned int
1463 unless explicitly specified. */
1464 && !(base
== 10 && !spec_unsigned
1465 && *type_sequence
[i
].node_var
== unsigned_type_node
))
1466 if (int_fits_type_p (yylval
.ttype
, *type_sequence
[i
].node_var
))
1468 type
= *type_sequence
[i
].node_var
;
1471 if (flag_traditional
&& type
== long_unsigned_type_node
1473 type
= long_integer_type_node
;
1477 type
= long_long_integer_type_node
;
1478 warning ("integer constant out of range");
1481 /* Warn about some cases where the type of a given constant
1482 changes from traditional C to ANSI C. */
1483 if (warn_traditional
)
1485 tree other_type
= 0;
1487 /* This computation is the same as the previous one
1488 except that flag_traditional is used backwards. */
1489 for (i
= 0; i
< sizeof (type_sequence
) / sizeof (type_sequence
[0]);
1491 if (!(spec_long
&& !type_sequence
[i
].long_flag
)
1492 && !(spec_long_long
&& !type_sequence
[i
].long_long_flag
)
1493 && !(spec_unsigned
&& !type_sequence
[i
].unsigned_flag
)
1494 /* A decimal constant can't be unsigned int
1495 unless explicitly specified. */
1496 && !(base
== 10 && !spec_unsigned
1497 && *type_sequence
[i
].node_var
== unsigned_type_node
))
1498 if (int_fits_type_p (yylval
.ttype
, *type_sequence
[i
].node_var
))
1500 other_type
= *type_sequence
[i
].node_var
;
1503 if (!flag_traditional
&& type
== long_unsigned_type_node
1505 type
= long_integer_type_node
;
1507 if (other_type
!= 0 && other_type
!= type
)
1509 if (flag_traditional
)
1510 warning ("type of integer constant would be different without -traditional");
1512 warning ("type of integer constant would be different with -traditional");
1517 /* If warn_traditional, calculate both the ANSI type and the
1518 traditional type, then see if they disagree.
1519 Otherwise, calculate only the type for the dialect in use. */
1520 if (warn_traditional
|| flag_traditional
)
1522 /* Calculate the traditional type. */
1523 /* Traditionally, any constant is signed;
1524 but if unsigned is specified explicitly, obey that.
1525 Use the smallest size with the right number of bits,
1526 except for one special case with decimal constants. */
1527 if (! spec_long
&& base
!= 10
1528 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1529 traditional_type
= (spec_unsigned
? unsigned_type_node
1530 : integer_type_node
);
1531 /* A decimal constant must be long
1532 if it does not fit in type int.
1533 I think this is independent of whether
1534 the constant is signed. */
1535 else if (! spec_long
&& base
== 10
1536 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1537 traditional_type
= (spec_unsigned
? unsigned_type_node
1538 : integer_type_node
);
1539 else if (! spec_long_long
1540 && int_fits_type_p (yylval
.ttype
,
1541 long_unsigned_type_node
))
1542 traditional_type
= (spec_unsigned
? long_unsigned_type_node
1543 : long_integer_type_node
);
1545 traditional_type
= (spec_unsigned
1546 ? long_long_unsigned_type_node
1547 : long_long_integer_type_node
);
1549 if (warn_traditional
|| ! flag_traditional
)
1551 /* Calculate the ANSI type. */
1552 if (! spec_long
&& ! spec_unsigned
1553 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
1554 ansi_type
= integer_type_node
;
1555 else if (! spec_long
&& (base
!= 10 || spec_unsigned
)
1556 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
1557 ansi_type
= unsigned_type_node
;
1558 else if (! spec_unsigned
&& !spec_long_long
1559 && int_fits_type_p (yylval
.ttype
, long_integer_type_node
))
1560 ansi_type
= long_integer_type_node
;
1561 else if (! spec_long_long
1562 && int_fits_type_p (yylval
.ttype
,
1563 long_unsigned_type_node
))
1564 ansi_type
= long_unsigned_type_node
;
1565 else if (! spec_unsigned
1566 && int_fits_type_p (yylval
.ttype
,
1567 long_long_integer_type_node
))
1568 ansi_type
= long_long_integer_type_node
;
1570 ansi_type
= long_long_unsigned_type_node
;
1573 type
= flag_traditional
? traditional_type
: ansi_type
;
1575 if (warn_traditional
&& traditional_type
!= ansi_type
)
1577 if (TYPE_PRECISION (traditional_type
)
1578 != TYPE_PRECISION (ansi_type
))
1579 warning ("width of integer constant changes with -traditional");
1580 else if (TREE_UNSIGNED (traditional_type
)
1581 != TREE_UNSIGNED (ansi_type
))
1582 warning ("integer constant is unsigned in ANSI C, signed with -traditional");
1584 warning ("width of integer constant may change on other systems with -traditional");
1588 TREE_TYPE (yylval
.ttype
) = type
;
1592 value
= CONSTANT
; break;
1598 register int result
= 0;
1599 register num_chars
= 0;
1600 unsigned width
= TYPE_PRECISION (char_type_node
);
1605 width
= WCHAR_TYPE_SIZE
;
1606 #ifdef MULTIBYTE_CHARS
1607 max_chars
= MB_CUR_MAX
;
1613 max_chars
= TYPE_PRECISION (integer_type_node
) / width
;
1621 if (c
== '\'' || c
== EOF
)
1629 if (width
< HOST_BITS_PER_INT
1630 && (unsigned) c
>= (1 << width
))
1631 pedwarn ("escape sequence out of range for character");
1636 pedwarn ("ANSI C forbids newline in character constant");
1641 if (num_chars
> maxtoken
- 4)
1642 extend_token_buffer (token_buffer
);
1644 token_buffer
[num_chars
] = c
;
1646 /* Merge character into result; ignore excess chars. */
1647 if (num_chars
< max_chars
+ 1)
1649 if (width
< HOST_BITS_PER_INT
)
1650 result
= (result
<< width
) | (c
& ((1 << width
) - 1));
1656 token_buffer
[num_chars
+ 1] = '\'';
1657 token_buffer
[num_chars
+ 2] = 0;
1660 error ("malformatted character constant");
1661 else if (num_chars
== 0)
1662 error ("empty character constant");
1663 else if (num_chars
> max_chars
)
1665 num_chars
= max_chars
;
1666 error ("character constant too long");
1668 else if (num_chars
!= 1 && ! flag_traditional
)
1669 warning ("multi-character character constant");
1671 /* If char type is signed, sign-extend the constant. */
1674 int num_bits
= num_chars
* width
;
1675 if (TREE_UNSIGNED (char_type_node
)
1676 || ((result
>> (num_bits
- 1)) & 1) == 0)
1678 = build_int_2 (result
& ((unsigned) ~0
1679 >> (HOST_BITS_PER_INT
- num_bits
)),
1683 = build_int_2 (result
| ~((unsigned) ~0
1684 >> (HOST_BITS_PER_INT
- num_bits
)),
1689 #ifdef MULTIBYTE_CHARS
1690 /* Set the initial shift state and convert the next sequence. */
1692 /* In all locales L'\0' is zero and mbtowc will return zero,
1695 || (num_chars
== 1 && token_buffer
[1] != '\0'))
1698 (void) mbtowc (NULL
, NULL
, 0);
1699 if (mbtowc (& wc
, token_buffer
+ 1, num_chars
) == num_chars
)
1702 warning ("Ignoring invalid multibyte character");
1705 yylval
.ttype
= build_int_2 (result
, 0);
1708 TREE_TYPE (yylval
.ttype
) = integer_type_node
;
1717 p
= token_buffer
+ 1;
1719 while (c
!= '"' && c
>= 0)
1721 /* ignore_escape_flag is set for reading the filename in #line. */
1722 if (!ignore_escape_flag
&& c
== '\\')
1728 && TYPE_PRECISION (char_type_node
) < HOST_BITS_PER_INT
1729 && c
>= (1 << TYPE_PRECISION (char_type_node
)))
1730 pedwarn ("escape sequence out of range for character");
1735 pedwarn ("ANSI C forbids newline in string constant");
1739 if (p
== token_buffer
+ maxtoken
)
1740 p
= extend_token_buffer (p
);
1748 /* We have read the entire constant.
1749 Construct a STRING_CST for the result. */
1753 /* If this is a L"..." wide-string, convert the multibyte string
1754 to a wide character string. */
1755 char *widep
= (char *) alloca ((p
- token_buffer
) * WCHAR_BYTES
);
1758 #ifdef MULTIBYTE_CHARS
1759 len
= mbstowcs ((wchar_t *) widep
, token_buffer
+ 1, p
- token_buffer
);
1760 if ((unsigned) len
>= (p
- token_buffer
))
1762 warning ("Ignoring invalid multibyte string");
1765 bzero (widep
+ (len
* WCHAR_BYTES
), WCHAR_BYTES
);
1768 union { long l
; char c
[sizeof (long)]; } u
;
1772 /* Determine whether host is little or big endian. */
1774 big_endian
= u
.c
[sizeof (long) - 1];
1775 wp
= widep
+ (big_endian
? WCHAR_BYTES
- 1 : 0);
1777 bzero (widep
, (p
- token_buffer
) * WCHAR_BYTES
);
1778 for (cp
= token_buffer
+ 1; cp
< p
; cp
++)
1779 *wp
= *cp
, wp
+= WCHAR_BYTES
;
1780 len
= p
- token_buffer
- 1;
1783 yylval
.ttype
= build_string ((len
+ 1) * WCHAR_BYTES
, widep
);
1784 TREE_TYPE (yylval
.ttype
) = wchar_array_type_node
;
1788 yylval
.ttype
= build_string (p
- token_buffer
, token_buffer
+ 1);
1789 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
1795 value
= STRING
; break;
1818 yylval
.code
= PLUS_EXPR
; break;
1820 yylval
.code
= MINUS_EXPR
; break;
1822 yylval
.code
= BIT_AND_EXPR
; break;
1824 yylval
.code
= BIT_IOR_EXPR
; break;
1826 yylval
.code
= MULT_EXPR
; break;
1828 yylval
.code
= TRUNC_DIV_EXPR
; break;
1830 yylval
.code
= TRUNC_MOD_EXPR
; break;
1832 yylval
.code
= BIT_XOR_EXPR
; break;
1834 yylval
.code
= LSHIFT_EXPR
; break;
1836 yylval
.code
= RSHIFT_EXPR
; break;
1838 yylval
.code
= LT_EXPR
; break;
1840 yylval
.code
= GT_EXPR
; break;
1843 token_buffer
[1] = c1
= getc (finput
);
1844 token_buffer
[2] = 0;
1851 value
= ARITHCOMPARE
; yylval
.code
= LE_EXPR
; goto done
;
1853 value
= ARITHCOMPARE
; yylval
.code
= GE_EXPR
; goto done
;
1855 value
= EQCOMPARE
; yylval
.code
= NE_EXPR
; goto done
;
1857 value
= EQCOMPARE
; yylval
.code
= EQ_EXPR
; goto done
;
1859 value
= ASSIGN
; goto done
;
1865 value
= PLUSPLUS
; goto done
;
1867 value
= MINUSMINUS
; goto done
;
1869 value
= ANDAND
; goto done
;
1871 value
= OROR
; goto done
;
1879 else if ((c
== '-') && (c1
== '>'))
1880 { value
= POINTSAT
; goto done
; }
1881 ungetc (c1
, finput
);
1882 token_buffer
[1] = 0;
1884 if ((c
== '<') || (c
== '>'))
1885 value
= ARITHCOMPARE
;
1891 /* Don't make yyparse think this is eof. */
1900 /* yylloc.last_line = lineno; */
1905 /* Sets the value of the 'yydebug' variable to VALUE.
1906 This is a function so we don't have to have YYDEBUG defined
1907 in order to build the compiler. */
1916 warning ("YYDEBUG not defined.");