]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* Separate lexical analyzer for GNU C++. |
ad236eab | 2 | Copyright (C) 1987, 89, 92-98, 1999 Free Software Foundation, Inc. |
8d08fdba MS |
3 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
e9fa0c7c RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
21 | |
22 | ||
23 | /* This file is the lexical analyzer for GNU C++. */ | |
24 | ||
8926095f | 25 | /* Cause the `yydebug' variable to be defined. */ |
8d08fdba | 26 | #define YYDEBUG 1 |
8d08fdba | 27 | |
da20811c | 28 | #include "config.h" |
8d052bc7 | 29 | #include "system.h" |
8d08fdba MS |
30 | #include "input.h" |
31 | #include "tree.h" | |
32 | #include "lex.h" | |
8d08fdba | 33 | #include "cp-tree.h" |
46b02c6d | 34 | #include "parse.h" |
8d08fdba MS |
35 | #include "flags.h" |
36 | #include "obstack.h" | |
3d6f7931 | 37 | #include "c-pragma.h" |
54f92bfb | 38 | #include "toplev.h" |
7dee3f36 | 39 | #include "output.h" |
8d08fdba MS |
40 | |
41 | #ifdef MULTIBYTE_CHARS | |
0d3ba739 | 42 | #include "mbchar.h" |
8d08fdba MS |
43 | #include <locale.h> |
44 | #endif | |
45 | ||
8d08fdba MS |
46 | #define obstack_chunk_alloc xmalloc |
47 | #define obstack_chunk_free free | |
48 | ||
ab535dac MK |
49 | #ifndef DIR_SEPARATOR |
50 | #define DIR_SEPARATOR '/' | |
51 | #endif | |
52 | ||
5566b478 | 53 | extern struct obstack permanent_obstack; |
8d08fdba MS |
54 | extern struct obstack *current_obstack, *saveable_obstack; |
55 | ||
49c249e1 | 56 | extern void yyprint PROTO((FILE *, int, YYSTYPE)); |
49c249e1 | 57 | |
d8e178a0 | 58 | static tree get_time_identifier PROTO((const char *)); |
49c249e1 | 59 | static int check_newline PROTO((void)); |
1ceb5ff3 | 60 | static int whitespace_cr PROTO((int)); |
49c249e1 | 61 | static int skip_white_space PROTO((int)); |
49c249e1 JM |
62 | static void finish_defarg PROTO((void)); |
63 | static int my_get_run_time PROTO((void)); | |
d8e178a0 | 64 | static int interface_strcmp PROTO((const char *)); |
49c249e1 | 65 | static int readescape PROTO((int *)); |
d8e178a0 | 66 | static char *extend_token_buffer PROTO((const char *)); |
49c249e1 | 67 | static void consume_string PROTO((struct obstack *, int)); |
49c249e1 | 68 | static void feed_defarg PROTO((tree, tree)); |
49c249e1 JM |
69 | static void store_pending_inline PROTO((tree, struct pending_inline *)); |
70 | static void reinit_parse_for_expr PROTO((struct obstack *)); | |
69ac77ce | 71 | static int *init_cpp_parse PROTO((void)); |
1d02ac83 JM |
72 | static void cp_pragma_interface PROTO((char *)); |
73 | static void cp_pragma_implementation PROTO ((char *)); | |
d8e178a0 | 74 | static int handle_cp_pragma PROTO((const char *)); |
a09a009c NC |
75 | #ifdef HANDLE_GENERIC_PRAGMAS |
76 | static int handle_generic_pragma PROTO((int)); | |
69ac77ce JL |
77 | #endif |
78 | #ifdef GATHER_STATISTICS | |
79 | #ifdef REDUCE_LENGTH | |
80 | static int reduce_cmp PROTO((int *, int *)); | |
81 | static int token_cmp PROTO((int *, int *)); | |
82 | #endif | |
83 | #endif | |
f181d4ae | 84 | static void begin_definition_of_inclass_inline PROTO((struct pending_inline*)); |
9b2bf201 | 85 | static void parse_float PROTO((PTR)); |
d8e178a0 KG |
86 | static int is_global PROTO((tree)); |
87 | static void init_filename_times PROTO((void)); | |
9c0758dd KG |
88 | static void extend_token_buffer_to PROTO((int)); |
89 | #ifdef HANDLE_PRAGMA | |
90 | static int pragma_getc PROTO((void)); | |
91 | static void pragma_ungetc PROTO((int)); | |
92 | #endif | |
93 | static int read_line_number PROTO((int *)); | |
8d08fdba MS |
94 | |
95 | /* Given a file name X, return the nondirectory portion. | |
96 | Keep in mind that X can be computed more than once. */ | |
b2bb2710 BK |
97 | char * |
98 | file_name_nondirectory (x) | |
d8e178a0 | 99 | const char *x; |
b2bb2710 | 100 | { |
e95d117b MK |
101 | char *tmp = (char *) rindex (x, '/'); |
102 | if (DIR_SEPARATOR != '/' && ! tmp) | |
103 | tmp = (char *) rindex (x, DIR_SEPARATOR); | |
b2bb2710 BK |
104 | if (tmp) |
105 | return (char *) (tmp + 1); | |
106 | else | |
d8e178a0 | 107 | return (char *) x; |
b2bb2710 | 108 | } |
8d08fdba | 109 | |
8d08fdba MS |
110 | /* This obstack is needed to hold text. It is not safe to use |
111 | TOKEN_BUFFER because `check_newline' calls `yylex'. */ | |
112 | struct obstack inline_text_obstack; | |
42976354 | 113 | char *inline_text_firstobj; |
f376e137 | 114 | |
d4dfe7d6 DB |
115 | #if USE_CPPLIB |
116 | #include "cpplib.h" | |
276ca6ea DB |
117 | extern cpp_reader parse_in; |
118 | extern cpp_options parse_options; | |
119 | extern unsigned char *yy_cur, *yy_lim; | |
66a6250f | 120 | extern enum cpp_token cpp_token; |
d4dfe7d6 | 121 | #else |
2b2a3531 DB |
122 | FILE *finput; |
123 | #endif | |
8d08fdba MS |
124 | int end_of_file; |
125 | ||
66a6250f JM |
126 | int linemode; |
127 | ||
8d08fdba MS |
128 | /* Pending language change. |
129 | Positive is push count, negative is pop count. */ | |
130 | int pending_lang_change = 0; | |
131 | ||
132 | /* Wrap the current header file in extern "C". */ | |
133 | static int c_header_level = 0; | |
134 | ||
135 | extern int first_token; | |
136 | extern struct obstack token_obstack; | |
137 | ||
138 | /* ??? Don't really know where this goes yet. */ | |
8d08fdba | 139 | #include "input.c" |
8d08fdba MS |
140 | |
141 | /* Holds translations from TREE_CODEs to operator name strings, | |
142 | i.e., opname_tab[PLUS_EXPR] == "+". */ | |
9c0758dd KG |
143 | const char **opname_tab; |
144 | const char **assignop_tab; | |
8d08fdba MS |
145 | \f |
146 | extern int yychar; /* the lookahead symbol */ | |
147 | extern YYSTYPE yylval; /* the semantic value of the */ | |
148 | /* lookahead symbol */ | |
149 | ||
150 | #if 0 | |
151 | YYLTYPE yylloc; /* location data for the lookahead */ | |
152 | /* symbol */ | |
153 | #endif | |
154 | ||
155 | ||
156 | /* the declaration found for the last IDENTIFIER token read in. | |
157 | yylex must look this up to detect typedefs, which get token type TYPENAME, | |
158 | so it is left around in case the identifier is not a typedef but is | |
159 | used in a context which makes it a reference to a variable. */ | |
160 | tree lastiddecl; | |
161 | ||
162 | /* The elements of `ridpointers' are identifier nodes | |
163 | for the reserved type names and storage classes. | |
164 | It is indexed by a RID_... value. */ | |
165 | tree ridpointers[(int) RID_MAX]; | |
166 | ||
167 | /* We may keep statistics about how long which files took to compile. */ | |
168 | static int header_time, body_time; | |
8d08fdba MS |
169 | static tree filename_times; |
170 | static tree this_filename_time; | |
171 | ||
8d08fdba MS |
172 | /* Array for holding counts of the numbers of tokens seen. */ |
173 | extern int *token_count; | |
8d08fdba MS |
174 | \f |
175 | /* Return something to represent absolute declarators containing a *. | |
176 | TARGET is the absolute declarator that the * contains. | |
c11b6f21 | 177 | CV_QUALIFIERS is a list of modifiers such as const or volatile |
8d08fdba MS |
178 | to apply to the pointer type, represented as identifiers. |
179 | ||
180 | We return an INDIRECT_REF whose "contents" are TARGET | |
181 | and whose type is the modifier list. */ | |
182 | ||
183 | tree | |
c11b6f21 MS |
184 | make_pointer_declarator (cv_qualifiers, target) |
185 | tree cv_qualifiers, target; | |
8d08fdba MS |
186 | { |
187 | if (target && TREE_CODE (target) == IDENTIFIER_NODE | |
188 | && ANON_AGGRNAME_P (target)) | |
8251199e | 189 | error ("type name expected before `*'"); |
8d08fdba | 190 | target = build_parse_node (INDIRECT_REF, target); |
c11b6f21 | 191 | TREE_TYPE (target) = cv_qualifiers; |
8d08fdba MS |
192 | return target; |
193 | } | |
194 | ||
195 | /* Return something to represent absolute declarators containing a &. | |
196 | TARGET is the absolute declarator that the & contains. | |
c11b6f21 | 197 | CV_QUALIFIERS is a list of modifiers such as const or volatile |
8d08fdba MS |
198 | to apply to the reference type, represented as identifiers. |
199 | ||
200 | We return an ADDR_EXPR whose "contents" are TARGET | |
201 | and whose type is the modifier list. */ | |
202 | ||
203 | tree | |
c11b6f21 MS |
204 | make_reference_declarator (cv_qualifiers, target) |
205 | tree cv_qualifiers, target; | |
8d08fdba MS |
206 | { |
207 | if (target) | |
208 | { | |
209 | if (TREE_CODE (target) == ADDR_EXPR) | |
210 | { | |
8251199e | 211 | error ("cannot declare references to references"); |
8d08fdba MS |
212 | return target; |
213 | } | |
214 | if (TREE_CODE (target) == INDIRECT_REF) | |
215 | { | |
8251199e | 216 | error ("cannot declare pointers to references"); |
8d08fdba MS |
217 | return target; |
218 | } | |
219 | if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target)) | |
8251199e | 220 | error ("type name expected before `&'"); |
8d08fdba MS |
221 | } |
222 | target = build_parse_node (ADDR_EXPR, target); | |
c11b6f21 | 223 | TREE_TYPE (target) = cv_qualifiers; |
8d08fdba MS |
224 | return target; |
225 | } | |
c11b6f21 MS |
226 | |
227 | tree | |
228 | make_call_declarator (target, parms, cv_qualifiers, exception_specification) | |
229 | tree target, parms, cv_qualifiers, exception_specification; | |
230 | { | |
231 | target = build_parse_node (CALL_EXPR, target, parms, cv_qualifiers); | |
232 | TREE_TYPE (target) = exception_specification; | |
233 | return target; | |
234 | } | |
235 | ||
236 | void | |
237 | set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification) | |
238 | tree call_declarator, cv_qualifiers, exception_specification; | |
239 | { | |
240 | TREE_OPERAND (call_declarator, 2) = cv_qualifiers; | |
241 | TREE_TYPE (call_declarator) = exception_specification; | |
242 | } | |
8d08fdba MS |
243 | \f |
244 | /* Build names and nodes for overloaded operators. */ | |
245 | ||
246 | tree ansi_opname[LAST_CPLUS_TREE_CODE]; | |
247 | tree ansi_assopname[LAST_CPLUS_TREE_CODE]; | |
248 | ||
9c0758dd | 249 | const char * |
8d08fdba MS |
250 | operator_name_string (name) |
251 | tree name; | |
252 | { | |
253 | char *opname = IDENTIFIER_POINTER (name) + 2; | |
254 | tree *opname_table; | |
255 | int i, assign; | |
256 | ||
257 | /* Works for builtin and user defined types. */ | |
258 | if (IDENTIFIER_GLOBAL_VALUE (name) | |
259 | && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TYPE_DECL) | |
260 | return IDENTIFIER_POINTER (name); | |
261 | ||
262 | if (opname[0] == 'a' && opname[2] != '\0' && opname[2] != '_') | |
263 | { | |
264 | opname += 1; | |
265 | assign = 1; | |
266 | opname_table = ansi_assopname; | |
267 | } | |
268 | else | |
269 | { | |
270 | assign = 0; | |
271 | opname_table = ansi_opname; | |
272 | } | |
273 | ||
274 | for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++) | |
275 | { | |
276 | if (opname[0] == IDENTIFIER_POINTER (opname_table[i])[2+assign] | |
277 | && opname[1] == IDENTIFIER_POINTER (opname_table[i])[3+assign]) | |
278 | break; | |
279 | } | |
280 | ||
281 | if (i == LAST_CPLUS_TREE_CODE) | |
282 | return "<invalid operator>"; | |
283 | ||
284 | if (assign) | |
285 | return assignop_tab[i]; | |
286 | else | |
287 | return opname_tab[i]; | |
288 | } | |
289 | \f | |
290 | int interface_only; /* whether or not current file is only for | |
291 | interface definitions. */ | |
292 | int interface_unknown; /* whether or not we know this class | |
293 | to behave according to #pragma interface. */ | |
294 | ||
295 | /* lexical analyzer */ | |
296 | ||
8d08fdba MS |
297 | #ifndef WCHAR_TYPE_SIZE |
298 | #ifdef INT_TYPE_SIZE | |
299 | #define WCHAR_TYPE_SIZE INT_TYPE_SIZE | |
300 | #else | |
301 | #define WCHAR_TYPE_SIZE BITS_PER_WORD | |
302 | #endif | |
303 | #endif | |
304 | ||
305 | /* Number of bytes in a wide character. */ | |
306 | #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT) | |
307 | ||
308 | static int maxtoken; /* Current nominal length of token buffer. */ | |
309 | char *token_buffer; /* Pointer to token buffer. | |
310 | Actual allocated length is maxtoken + 2. */ | |
311 | ||
1ceb5ff3 | 312 | static int indent_level; /* Number of { minus number of }. */ |
66a6250f | 313 | |
8d08fdba MS |
314 | #include "hash.h" |
315 | \f | |
8d08fdba MS |
316 | |
317 | /* Nonzero tells yylex to ignore \ in string constants. */ | |
1ceb5ff3 | 318 | static int ignore_escape_flag; |
8d08fdba | 319 | |
8d08fdba MS |
320 | static tree |
321 | get_time_identifier (name) | |
d8e178a0 | 322 | const char *name; |
8d08fdba MS |
323 | { |
324 | tree time_identifier; | |
325 | int len = strlen (name); | |
326 | char *buf = (char *) alloca (len + 6); | |
327 | strcpy (buf, "file "); | |
328 | bcopy (name, buf+5, len); | |
329 | buf[len+5] = '\0'; | |
330 | time_identifier = get_identifier (buf); | |
f181d4ae | 331 | if (TIME_IDENTIFIER_TIME (time_identifier) == NULL_TREE) |
8d08fdba | 332 | { |
9188c363 | 333 | push_permanent_obstack (); |
f181d4ae MM |
334 | TIME_IDENTIFIER_TIME (time_identifier) = build_int_2 (0, 0); |
335 | TIME_IDENTIFIER_FILEINFO (time_identifier) | |
336 | = build_int_2 (0, 1); | |
2c73f9f5 | 337 | SET_IDENTIFIER_GLOBAL_VALUE (time_identifier, filename_times); |
8d08fdba MS |
338 | filename_times = time_identifier; |
339 | pop_obstacks (); | |
340 | } | |
341 | return time_identifier; | |
342 | } | |
343 | ||
344 | #ifdef __GNUC__ | |
345 | __inline | |
346 | #endif | |
347 | static int | |
348 | my_get_run_time () | |
349 | { | |
350 | int old_quiet_flag = quiet_flag; | |
351 | int this_time; | |
352 | quiet_flag = 0; | |
353 | this_time = get_run_time (); | |
354 | quiet_flag = old_quiet_flag; | |
355 | return this_time; | |
356 | } | |
357 | \f | |
358 | /* Table indexed by tree code giving a string containing a character | |
359 | classifying the tree code. Possibilities are | |
e92cc029 | 360 | t, d, s, c, r, <, 1 and 2. See cp/cp-tree.def for details. */ |
8d08fdba MS |
361 | |
362 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, | |
363 | ||
0a6969ad JC |
364 | char cplus_tree_code_type[] = { |
365 | 'x', | |
e92cc029 | 366 | #include "cp-tree.def" |
8d08fdba MS |
367 | }; |
368 | #undef DEFTREECODE | |
369 | ||
370 | /* Table indexed by tree code giving number of expression | |
371 | operands beyond the fixed part of the node structure. | |
372 | Not used for types or decls. */ | |
373 | ||
374 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, | |
375 | ||
376 | int cplus_tree_code_length[] = { | |
377 | 0, | |
e92cc029 | 378 | #include "cp-tree.def" |
8d08fdba MS |
379 | }; |
380 | #undef DEFTREECODE | |
381 | ||
382 | /* Names of tree components. | |
383 | Used for printing out the tree and error messages. */ | |
384 | #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, | |
385 | ||
d8e178a0 | 386 | const char *cplus_tree_code_name[] = { |
8d08fdba | 387 | "@@dummy", |
e92cc029 | 388 | #include "cp-tree.def" |
8d08fdba MS |
389 | }; |
390 | #undef DEFTREECODE | |
391 | \f | |
392 | /* toplev.c needs to call these. */ | |
393 | ||
9116eca2 RH |
394 | void |
395 | lang_init_options () | |
396 | { | |
dfb0fb1d DB |
397 | #if USE_CPPLIB |
398 | cpp_reader_init (&parse_in); | |
399 | parse_in.opts = &parse_options; | |
400 | cpp_options_init (&parse_options); | |
66a6250f | 401 | parse_options.cplusplus = 1; |
dfb0fb1d DB |
402 | #endif |
403 | ||
9116eca2 RH |
404 | /* Default exceptions on. */ |
405 | flag_exceptions = 1; | |
406 | } | |
407 | ||
8d08fdba MS |
408 | void |
409 | lang_init () | |
410 | { | |
411 | /* the beginning of the file is a new line; check for # */ | |
412 | /* With luck, we discover the real source file's name from that | |
413 | and put it in input_filename. */ | |
414 | put_back (check_newline ()); | |
8d08fdba | 415 | if (flag_gnu_xref) GNU_xref_begin (input_filename); |
faae18ab | 416 | init_repo (input_filename); |
8d08fdba MS |
417 | } |
418 | ||
419 | void | |
420 | lang_finish () | |
421 | { | |
8d08fdba MS |
422 | if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount); |
423 | } | |
424 | ||
8df4696d | 425 | const char * |
8d08fdba MS |
426 | lang_identify () |
427 | { | |
428 | return "cplusplus"; | |
429 | } | |
430 | ||
d8e178a0 | 431 | static void |
8d08fdba MS |
432 | init_filename_times () |
433 | { | |
434 | this_filename_time = get_time_identifier ("<top level>"); | |
435 | if (flag_detailed_statistics) | |
436 | { | |
437 | header_time = 0; | |
438 | body_time = my_get_run_time (); | |
f181d4ae MM |
439 | TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time)) |
440 | = body_time; | |
8d08fdba MS |
441 | } |
442 | } | |
443 | ||
444 | /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989. | |
445 | Stuck this hack in to get the files open correctly; this is called | |
2b2a3531 | 446 | in place of init_parse if we are an unexec'd binary. */ |
e92cc029 | 447 | |
bd6dd845 | 448 | #if 0 |
8d08fdba MS |
449 | void |
450 | reinit_lang_specific () | |
451 | { | |
452 | init_filename_times (); | |
453 | reinit_search_statistics (); | |
454 | } | |
bd6dd845 | 455 | #endif |
8d08fdba | 456 | |
2b2a3531 DB |
457 | static int * |
458 | init_cpp_parse () | |
459 | { | |
460 | #ifdef GATHER_STATISTICS | |
461 | #ifdef REDUCE_LENGTH | |
462 | reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1)); | |
463 | bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1)); | |
464 | reduce_count += 1; | |
465 | token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1)); | |
466 | bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1)); | |
467 | token_count += 1; | |
468 | #endif | |
469 | #endif | |
470 | return token_count; | |
471 | } | |
472 | ||
a755ad1c | 473 | char * |
2b2a3531 DB |
474 | init_parse (filename) |
475 | char *filename; | |
8d08fdba | 476 | { |
e1cd6e56 MS |
477 | extern int flag_no_gnu_keywords; |
478 | extern int flag_operator_names; | |
8d08fdba MS |
479 | |
480 | int i; | |
481 | ||
0d3ba739 DB |
482 | #ifdef MULTIBYTE_CHARS |
483 | /* Change to the native locale for multibyte conversions. */ | |
484 | setlocale (LC_CTYPE, ""); | |
3e81ad16 | 485 | literal_codeset = getenv ("LANG"); |
0d3ba739 DB |
486 | #endif |
487 | ||
1ceb5ff3 | 488 | #if !USE_CPPLIB |
2b2a3531 DB |
489 | /* Open input file. */ |
490 | if (filename == 0 || !strcmp (filename, "-")) | |
491 | { | |
492 | finput = stdin; | |
493 | filename = "stdin"; | |
494 | } | |
495 | else | |
496 | finput = fopen (filename, "r"); | |
497 | if (finput == 0) | |
498 | pfatal_with_name (filename); | |
499 | ||
500 | #ifdef IO_BUFFER_SIZE | |
501 | setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE); | |
502 | #endif | |
1ceb5ff3 JM |
503 | #else /* !USE_CPPLIB */ |
504 | parse_in.show_column = 1; | |
505 | if (! cpp_start_read (&parse_in, filename)) | |
506 | abort (); | |
507 | ||
508 | if (filename == 0 || !strcmp (filename, "-")) | |
509 | filename = "stdin"; | |
510 | ||
511 | /* cpp_start_read always puts at least one line directive into the | |
512 | token buffer. We must arrange to read it out here. */ | |
513 | yy_cur = parse_in.token_buffer; | |
514 | yy_lim = CPP_PWRITTEN (&parse_in); | |
515 | cpp_token = CPP_DIRECTIVE; | |
516 | ||
2b2a3531 DB |
517 | #endif /* !USE_CPPLIB */ |
518 | ||
8d08fdba MS |
519 | /* Initialize the lookahead machinery. */ |
520 | init_spew (); | |
521 | ||
522 | /* Make identifier nodes long enough for the language-specific slots. */ | |
523 | set_identifier_size (sizeof (struct lang_identifier)); | |
524 | decl_printable_name = lang_printable_name; | |
525 | ||
0a818f84 | 526 | init_cplus_unsave (); |
8d08fdba MS |
527 | init_cplus_expand (); |
528 | ||
0a6969ad JC |
529 | bcopy (cplus_tree_code_type, |
530 | tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE, | |
531 | (int)LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE); | |
8d08fdba MS |
532 | bcopy ((char *)cplus_tree_code_length, |
533 | (char *)(tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE), | |
534 | (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int)); | |
535 | bcopy ((char *)cplus_tree_code_name, | |
536 | (char *)(tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE), | |
537 | (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *)); | |
538 | ||
9c0758dd | 539 | opname_tab = (const char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *)); |
8d08fdba | 540 | bzero ((char *)opname_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *)); |
9c0758dd | 541 | assignop_tab = (const char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *)); |
8d08fdba MS |
542 | bzero ((char *)assignop_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *)); |
543 | ||
544 | ansi_opname[0] = get_identifier ("<invalid operator>"); | |
545 | for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++) | |
546 | { | |
547 | ansi_opname[i] = ansi_opname[0]; | |
548 | ansi_assopname[i] = ansi_opname[0]; | |
549 | } | |
550 | ||
551 | ansi_opname[(int) MULT_EXPR] = get_identifier ("__ml"); | |
552 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MULT_EXPR]) = 1; | |
553 | ansi_opname[(int) INDIRECT_REF] = ansi_opname[(int) MULT_EXPR]; | |
554 | ansi_assopname[(int) MULT_EXPR] = get_identifier ("__aml"); | |
555 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) MULT_EXPR]) = 1; | |
556 | ansi_assopname[(int) INDIRECT_REF] = ansi_assopname[(int) MULT_EXPR]; | |
557 | ansi_opname[(int) TRUNC_MOD_EXPR] = get_identifier ("__md"); | |
558 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUNC_MOD_EXPR]) = 1; | |
559 | ansi_assopname[(int) TRUNC_MOD_EXPR] = get_identifier ("__amd"); | |
560 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) TRUNC_MOD_EXPR]) = 1; | |
561 | ansi_opname[(int) CEIL_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR]; | |
562 | ansi_opname[(int) FLOOR_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR]; | |
563 | ansi_opname[(int) ROUND_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR]; | |
564 | ansi_opname[(int) MINUS_EXPR] = get_identifier ("__mi"); | |
565 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MINUS_EXPR]) = 1; | |
566 | ansi_opname[(int) NEGATE_EXPR] = ansi_opname[(int) MINUS_EXPR]; | |
567 | ansi_assopname[(int) MINUS_EXPR] = get_identifier ("__ami"); | |
568 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) MINUS_EXPR]) = 1; | |
569 | ansi_assopname[(int) NEGATE_EXPR] = ansi_assopname[(int) MINUS_EXPR]; | |
570 | ansi_opname[(int) RSHIFT_EXPR] = get_identifier ("__rs"); | |
571 | IDENTIFIER_OPNAME_P (ansi_opname[(int) RSHIFT_EXPR]) = 1; | |
572 | ansi_assopname[(int) RSHIFT_EXPR] = get_identifier ("__ars"); | |
573 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) RSHIFT_EXPR]) = 1; | |
574 | ansi_opname[(int) NE_EXPR] = get_identifier ("__ne"); | |
575 | IDENTIFIER_OPNAME_P (ansi_opname[(int) NE_EXPR]) = 1; | |
576 | ansi_opname[(int) GT_EXPR] = get_identifier ("__gt"); | |
577 | IDENTIFIER_OPNAME_P (ansi_opname[(int) GT_EXPR]) = 1; | |
578 | ansi_opname[(int) GE_EXPR] = get_identifier ("__ge"); | |
579 | IDENTIFIER_OPNAME_P (ansi_opname[(int) GE_EXPR]) = 1; | |
580 | ansi_opname[(int) BIT_IOR_EXPR] = get_identifier ("__or"); | |
581 | IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_IOR_EXPR]) = 1; | |
582 | ansi_assopname[(int) BIT_IOR_EXPR] = get_identifier ("__aor"); | |
583 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_IOR_EXPR]) = 1; | |
584 | ansi_opname[(int) TRUTH_ANDIF_EXPR] = get_identifier ("__aa"); | |
585 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ANDIF_EXPR]) = 1; | |
586 | ansi_opname[(int) TRUTH_NOT_EXPR] = get_identifier ("__nt"); | |
587 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_NOT_EXPR]) = 1; | |
588 | ansi_opname[(int) PREINCREMENT_EXPR] = get_identifier ("__pp"); | |
589 | IDENTIFIER_OPNAME_P (ansi_opname[(int) PREINCREMENT_EXPR]) = 1; | |
590 | ansi_opname[(int) POSTINCREMENT_EXPR] = ansi_opname[(int) PREINCREMENT_EXPR]; | |
591 | ansi_opname[(int) MODIFY_EXPR] = get_identifier ("__as"); | |
592 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MODIFY_EXPR]) = 1; | |
593 | ansi_assopname[(int) NOP_EXPR] = ansi_opname[(int) MODIFY_EXPR]; | |
594 | ansi_opname[(int) COMPOUND_EXPR] = get_identifier ("__cm"); | |
595 | IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPOUND_EXPR]) = 1; | |
596 | ansi_opname[(int) EXACT_DIV_EXPR] = get_identifier ("__dv"); | |
597 | IDENTIFIER_OPNAME_P (ansi_opname[(int) EXACT_DIV_EXPR]) = 1; | |
598 | ansi_assopname[(int) EXACT_DIV_EXPR] = get_identifier ("__adv"); | |
599 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) EXACT_DIV_EXPR]) = 1; | |
600 | ansi_opname[(int) TRUNC_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; | |
601 | ansi_opname[(int) CEIL_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; | |
602 | ansi_opname[(int) FLOOR_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; | |
603 | ansi_opname[(int) ROUND_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; | |
604 | ansi_opname[(int) PLUS_EXPR] = get_identifier ("__pl"); | |
605 | ansi_assopname[(int) TRUNC_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; | |
606 | ansi_assopname[(int) CEIL_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; | |
607 | ansi_assopname[(int) FLOOR_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; | |
608 | ansi_assopname[(int) ROUND_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; | |
609 | IDENTIFIER_OPNAME_P (ansi_opname[(int) PLUS_EXPR]) = 1; | |
610 | ansi_assopname[(int) PLUS_EXPR] = get_identifier ("__apl"); | |
611 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) PLUS_EXPR]) = 1; | |
612 | ansi_opname[(int) CONVERT_EXPR] = ansi_opname[(int) PLUS_EXPR]; | |
613 | ansi_assopname[(int) CONVERT_EXPR] = ansi_assopname[(int) PLUS_EXPR]; | |
614 | ansi_opname[(int) LSHIFT_EXPR] = get_identifier ("__ls"); | |
615 | IDENTIFIER_OPNAME_P (ansi_opname[(int) LSHIFT_EXPR]) = 1; | |
616 | ansi_assopname[(int) LSHIFT_EXPR] = get_identifier ("__als"); | |
617 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) LSHIFT_EXPR]) = 1; | |
618 | ansi_opname[(int) EQ_EXPR] = get_identifier ("__eq"); | |
619 | IDENTIFIER_OPNAME_P (ansi_opname[(int) EQ_EXPR]) = 1; | |
620 | ansi_opname[(int) LT_EXPR] = get_identifier ("__lt"); | |
621 | IDENTIFIER_OPNAME_P (ansi_opname[(int) LT_EXPR]) = 1; | |
622 | ansi_opname[(int) LE_EXPR] = get_identifier ("__le"); | |
623 | IDENTIFIER_OPNAME_P (ansi_opname[(int) LE_EXPR]) = 1; | |
624 | ansi_opname[(int) BIT_AND_EXPR] = get_identifier ("__ad"); | |
625 | IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_AND_EXPR]) = 1; | |
626 | ansi_assopname[(int) BIT_AND_EXPR] = get_identifier ("__aad"); | |
627 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_AND_EXPR]) = 1; | |
628 | ansi_opname[(int) ADDR_EXPR] = ansi_opname[(int) BIT_AND_EXPR]; | |
629 | ansi_assopname[(int) ADDR_EXPR] = ansi_assopname[(int) BIT_AND_EXPR]; | |
630 | ansi_opname[(int) BIT_XOR_EXPR] = get_identifier ("__er"); | |
631 | IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_XOR_EXPR]) = 1; | |
632 | ansi_assopname[(int) BIT_XOR_EXPR] = get_identifier ("__aer"); | |
633 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_XOR_EXPR]) = 1; | |
634 | ansi_opname[(int) TRUTH_ORIF_EXPR] = get_identifier ("__oo"); | |
635 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ORIF_EXPR]) = 1; | |
636 | ansi_opname[(int) BIT_NOT_EXPR] = get_identifier ("__co"); | |
637 | IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_NOT_EXPR]) = 1; | |
638 | ansi_opname[(int) PREDECREMENT_EXPR] = get_identifier ("__mm"); | |
639 | IDENTIFIER_OPNAME_P (ansi_opname[(int) PREDECREMENT_EXPR]) = 1; | |
640 | ansi_opname[(int) POSTDECREMENT_EXPR] = ansi_opname[(int) PREDECREMENT_EXPR]; | |
641 | ansi_opname[(int) COMPONENT_REF] = get_identifier ("__rf"); | |
642 | IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPONENT_REF]) = 1; | |
643 | ansi_opname[(int) MEMBER_REF] = get_identifier ("__rm"); | |
644 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MEMBER_REF]) = 1; | |
645 | ansi_opname[(int) CALL_EXPR] = get_identifier ("__cl"); | |
646 | IDENTIFIER_OPNAME_P (ansi_opname[(int) CALL_EXPR]) = 1; | |
647 | ansi_opname[(int) ARRAY_REF] = get_identifier ("__vc"); | |
648 | IDENTIFIER_OPNAME_P (ansi_opname[(int) ARRAY_REF]) = 1; | |
649 | ansi_opname[(int) NEW_EXPR] = get_identifier ("__nw"); | |
650 | IDENTIFIER_OPNAME_P (ansi_opname[(int) NEW_EXPR]) = 1; | |
651 | ansi_opname[(int) DELETE_EXPR] = get_identifier ("__dl"); | |
652 | IDENTIFIER_OPNAME_P (ansi_opname[(int) DELETE_EXPR]) = 1; | |
a28e3c7f MS |
653 | ansi_opname[(int) VEC_NEW_EXPR] = get_identifier ("__vn"); |
654 | IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_NEW_EXPR]) = 1; | |
655 | ansi_opname[(int) VEC_DELETE_EXPR] = get_identifier ("__vd"); | |
656 | IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_DELETE_EXPR]) = 1; | |
4c571114 | 657 | ansi_opname[(int) TYPE_EXPR] = get_identifier (OPERATOR_TYPENAME_FORMAT); |
8d08fdba MS |
658 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TYPE_EXPR]) = 1; |
659 | ||
660 | /* This is not true: these operators are not defined in ANSI, | |
661 | but we need them anyway. */ | |
662 | ansi_opname[(int) MIN_EXPR] = get_identifier ("__mn"); | |
663 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MIN_EXPR]) = 1; | |
664 | ansi_opname[(int) MAX_EXPR] = get_identifier ("__mx"); | |
665 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MAX_EXPR]) = 1; | |
666 | ansi_opname[(int) COND_EXPR] = get_identifier ("__cn"); | |
667 | IDENTIFIER_OPNAME_P (ansi_opname[(int) COND_EXPR]) = 1; | |
ff29fd00 MM |
668 | ansi_opname[(int) SIZEOF_EXPR] = get_identifier ("__sz"); |
669 | IDENTIFIER_OPNAME_P (ansi_opname[(int) SIZEOF_EXPR]) = 1; | |
8d08fdba MS |
670 | |
671 | init_method (); | |
672 | init_error (); | |
673 | gcc_obstack_init (&inline_text_obstack); | |
42976354 | 674 | inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0); |
8d08fdba MS |
675 | |
676 | /* Start it at 0, because check_newline is called at the very beginning | |
677 | and will increment it to 1. */ | |
678 | lineno = 0; | |
679 | input_filename = "<internal>"; | |
680 | current_function_decl = NULL; | |
681 | ||
682 | maxtoken = 40; | |
683 | token_buffer = (char *) xmalloc (maxtoken + 2); | |
684 | ||
685 | ridpointers[(int) RID_INT] = get_identifier ("int"); | |
2986ae00 | 686 | ridpointers[(int) RID_BOOL] = get_identifier ("bool"); |
8d08fdba | 687 | ridpointers[(int) RID_CHAR] = get_identifier ("char"); |
8d08fdba | 688 | ridpointers[(int) RID_VOID] = get_identifier ("void"); |
8d08fdba | 689 | ridpointers[(int) RID_FLOAT] = get_identifier ("float"); |
8d08fdba | 690 | ridpointers[(int) RID_DOUBLE] = get_identifier ("double"); |
8d08fdba | 691 | ridpointers[(int) RID_SHORT] = get_identifier ("short"); |
8d08fdba | 692 | ridpointers[(int) RID_LONG] = get_identifier ("long"); |
8d08fdba | 693 | ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned"); |
8d08fdba | 694 | ridpointers[(int) RID_SIGNED] = get_identifier ("signed"); |
8d08fdba | 695 | ridpointers[(int) RID_INLINE] = get_identifier ("inline"); |
8d08fdba | 696 | ridpointers[(int) RID_CONST] = get_identifier ("const"); |
91063b51 | 697 | ridpointers[(int) RID_RESTRICT] = get_identifier ("__restrict"); |
1ceb5ff3 | 698 | ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile"); |
8d08fdba | 699 | ridpointers[(int) RID_AUTO] = get_identifier ("auto"); |
8d08fdba | 700 | ridpointers[(int) RID_STATIC] = get_identifier ("static"); |
8d08fdba | 701 | ridpointers[(int) RID_EXTERN] = get_identifier ("extern"); |
8d08fdba | 702 | ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef"); |
8d08fdba | 703 | ridpointers[(int) RID_REGISTER] = get_identifier ("register"); |
8eeda2ec | 704 | ridpointers[(int) RID_COMPLEX] = get_identifier ("__complex"); |
8d08fdba | 705 | |
e92cc029 | 706 | /* C++ extensions. These are probably not correctly named. */ |
8d08fdba | 707 | ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t"); |
8d08fdba MS |
708 | class_type_node = build_int_2 (class_type, 0); |
709 | TREE_TYPE (class_type_node) = class_type_node; | |
710 | ridpointers[(int) RID_CLASS] = class_type_node; | |
711 | ||
712 | record_type_node = build_int_2 (record_type, 0); | |
713 | TREE_TYPE (record_type_node) = record_type_node; | |
714 | ridpointers[(int) RID_RECORD] = record_type_node; | |
715 | ||
716 | union_type_node = build_int_2 (union_type, 0); | |
717 | TREE_TYPE (union_type_node) = union_type_node; | |
718 | ridpointers[(int) RID_UNION] = union_type_node; | |
719 | ||
720 | enum_type_node = build_int_2 (enum_type, 0); | |
721 | TREE_TYPE (enum_type_node) = enum_type_node; | |
722 | ridpointers[(int) RID_ENUM] = enum_type_node; | |
723 | ||
724 | ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual"); | |
db5ae43f | 725 | ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit"); |
9a469008 | 726 | ridpointers[(int) RID_EXPORT] = get_identifier ("export"); |
8d08fdba | 727 | ridpointers[(int) RID_FRIEND] = get_identifier ("friend"); |
8d08fdba MS |
728 | |
729 | ridpointers[(int) RID_PUBLIC] = get_identifier ("public"); | |
8d08fdba | 730 | ridpointers[(int) RID_PRIVATE] = get_identifier ("private"); |
8d08fdba | 731 | ridpointers[(int) RID_PROTECTED] = get_identifier ("protected"); |
a4443a08 | 732 | ridpointers[(int) RID_TEMPLATE] = get_identifier ("template"); |
e92cc029 | 733 | /* This is for ANSI C++. */ |
8d08fdba | 734 | ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable"); |
8d08fdba | 735 | |
898600d5 MM |
736 | /* Create the built-in __null node. Note that we can't yet call for |
737 | type_for_size here because integer_type_node and so forth are not | |
738 | set up. Therefore, we don't set the type of these nodes until | |
739 | init_decl_processing. */ | |
03d0f4af | 740 | null_node = build_int_2 (0, 0); |
d11ad92e | 741 | ridpointers[RID_NULL] = null_node; |
c73964b2 | 742 | |
8d08fdba MS |
743 | opname_tab[(int) COMPONENT_REF] = "->"; |
744 | opname_tab[(int) MEMBER_REF] = "->*"; | |
6467930b | 745 | opname_tab[(int) INDIRECT_REF] = "*"; |
8d08fdba MS |
746 | opname_tab[(int) ARRAY_REF] = "[]"; |
747 | opname_tab[(int) MODIFY_EXPR] = "="; | |
748 | opname_tab[(int) NEW_EXPR] = "new"; | |
749 | opname_tab[(int) DELETE_EXPR] = "delete"; | |
a28e3c7f MS |
750 | opname_tab[(int) VEC_NEW_EXPR] = "new []"; |
751 | opname_tab[(int) VEC_DELETE_EXPR] = "delete []"; | |
6467930b | 752 | opname_tab[(int) COND_EXPR] = "?:"; |
8d08fdba MS |
753 | opname_tab[(int) CALL_EXPR] = "()"; |
754 | opname_tab[(int) PLUS_EXPR] = "+"; | |
755 | opname_tab[(int) MINUS_EXPR] = "-"; | |
756 | opname_tab[(int) MULT_EXPR] = "*"; | |
757 | opname_tab[(int) TRUNC_DIV_EXPR] = "/"; | |
758 | opname_tab[(int) CEIL_DIV_EXPR] = "(ceiling /)"; | |
759 | opname_tab[(int) FLOOR_DIV_EXPR] = "(floor /)"; | |
760 | opname_tab[(int) ROUND_DIV_EXPR] = "(round /)"; | |
761 | opname_tab[(int) TRUNC_MOD_EXPR] = "%"; | |
762 | opname_tab[(int) CEIL_MOD_EXPR] = "(ceiling %)"; | |
763 | opname_tab[(int) FLOOR_MOD_EXPR] = "(floor %)"; | |
764 | opname_tab[(int) ROUND_MOD_EXPR] = "(round %)"; | |
2adeacc9 | 765 | opname_tab[(int) EXACT_DIV_EXPR] = "/"; |
8d08fdba MS |
766 | opname_tab[(int) NEGATE_EXPR] = "-"; |
767 | opname_tab[(int) MIN_EXPR] = "<?"; | |
768 | opname_tab[(int) MAX_EXPR] = ">?"; | |
769 | opname_tab[(int) ABS_EXPR] = "abs"; | |
770 | opname_tab[(int) FFS_EXPR] = "ffs"; | |
771 | opname_tab[(int) LSHIFT_EXPR] = "<<"; | |
772 | opname_tab[(int) RSHIFT_EXPR] = ">>"; | |
773 | opname_tab[(int) BIT_IOR_EXPR] = "|"; | |
774 | opname_tab[(int) BIT_XOR_EXPR] = "^"; | |
775 | opname_tab[(int) BIT_AND_EXPR] = "&"; | |
776 | opname_tab[(int) BIT_ANDTC_EXPR] = "&~"; | |
777 | opname_tab[(int) BIT_NOT_EXPR] = "~"; | |
778 | opname_tab[(int) TRUTH_ANDIF_EXPR] = "&&"; | |
779 | opname_tab[(int) TRUTH_ORIF_EXPR] = "||"; | |
780 | opname_tab[(int) TRUTH_AND_EXPR] = "strict &&"; | |
781 | opname_tab[(int) TRUTH_OR_EXPR] = "strict ||"; | |
782 | opname_tab[(int) TRUTH_NOT_EXPR] = "!"; | |
783 | opname_tab[(int) LT_EXPR] = "<"; | |
784 | opname_tab[(int) LE_EXPR] = "<="; | |
785 | opname_tab[(int) GT_EXPR] = ">"; | |
786 | opname_tab[(int) GE_EXPR] = ">="; | |
787 | opname_tab[(int) EQ_EXPR] = "=="; | |
788 | opname_tab[(int) NE_EXPR] = "!="; | |
789 | opname_tab[(int) IN_EXPR] = "in"; | |
6467930b MS |
790 | opname_tab[(int) RANGE_EXPR] = "..."; |
791 | opname_tab[(int) CONVERT_EXPR] = "+"; | |
792 | opname_tab[(int) ADDR_EXPR] = "&"; | |
8d08fdba MS |
793 | opname_tab[(int) PREDECREMENT_EXPR] = "--"; |
794 | opname_tab[(int) PREINCREMENT_EXPR] = "++"; | |
795 | opname_tab[(int) POSTDECREMENT_EXPR] = "--"; | |
796 | opname_tab[(int) POSTINCREMENT_EXPR] = "++"; | |
797 | opname_tab[(int) COMPOUND_EXPR] = ","; | |
798 | ||
799 | assignop_tab[(int) NOP_EXPR] = "="; | |
800 | assignop_tab[(int) PLUS_EXPR] = "+="; | |
801 | assignop_tab[(int) CONVERT_EXPR] = "+="; | |
802 | assignop_tab[(int) MINUS_EXPR] = "-="; | |
803 | assignop_tab[(int) NEGATE_EXPR] = "-="; | |
804 | assignop_tab[(int) MULT_EXPR] = "*="; | |
805 | assignop_tab[(int) INDIRECT_REF] = "*="; | |
806 | assignop_tab[(int) TRUNC_DIV_EXPR] = "/="; | |
807 | assignop_tab[(int) EXACT_DIV_EXPR] = "(exact /=)"; | |
808 | assignop_tab[(int) CEIL_DIV_EXPR] = "(ceiling /=)"; | |
809 | assignop_tab[(int) FLOOR_DIV_EXPR] = "(floor /=)"; | |
810 | assignop_tab[(int) ROUND_DIV_EXPR] = "(round /=)"; | |
811 | assignop_tab[(int) TRUNC_MOD_EXPR] = "%="; | |
812 | assignop_tab[(int) CEIL_MOD_EXPR] = "(ceiling %=)"; | |
813 | assignop_tab[(int) FLOOR_MOD_EXPR] = "(floor %=)"; | |
814 | assignop_tab[(int) ROUND_MOD_EXPR] = "(round %=)"; | |
815 | assignop_tab[(int) MIN_EXPR] = "<?="; | |
816 | assignop_tab[(int) MAX_EXPR] = ">?="; | |
817 | assignop_tab[(int) LSHIFT_EXPR] = "<<="; | |
818 | assignop_tab[(int) RSHIFT_EXPR] = ">>="; | |
819 | assignop_tab[(int) BIT_IOR_EXPR] = "|="; | |
820 | assignop_tab[(int) BIT_XOR_EXPR] = "^="; | |
821 | assignop_tab[(int) BIT_AND_EXPR] = "&="; | |
822 | assignop_tab[(int) ADDR_EXPR] = "&="; | |
823 | ||
824 | init_filename_times (); | |
825 | ||
826 | /* Some options inhibit certain reserved words. | |
827 | Clear those words out of the hash table so they won't be recognized. */ | |
828 | #define UNSET_RESERVED_WORD(STRING) \ | |
829 | do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \ | |
830 | if (s) s->name = ""; } while (0) | |
831 | ||
8d2733ca MS |
832 | #if 0 |
833 | /* let's parse things, and if they use it, then give them an error. */ | |
6467930b | 834 | if (!flag_exceptions) |
8d08fdba | 835 | { |
8d2733ca MS |
836 | UNSET_RESERVED_WORD ("throw"); |
837 | UNSET_RESERVED_WORD ("try"); | |
8d08fdba MS |
838 | UNSET_RESERVED_WORD ("catch"); |
839 | } | |
8d2733ca | 840 | #endif |
8d08fdba | 841 | |
9e9ff709 | 842 | if (!flag_rtti || flag_no_gnu_keywords) |
8d08fdba MS |
843 | { |
844 | UNSET_RESERVED_WORD ("classof"); | |
845 | UNSET_RESERVED_WORD ("headof"); | |
846 | } | |
5427d758 | 847 | |
e1cd6e56 | 848 | if (flag_no_asm || flag_no_gnu_keywords) |
8d08fdba | 849 | UNSET_RESERVED_WORD ("typeof"); |
e1cd6e56 | 850 | if (! flag_operator_names) |
db5ae43f MS |
851 | { |
852 | /* These are new ANSI keywords that may break code. */ | |
853 | UNSET_RESERVED_WORD ("and"); | |
79ff2c6c | 854 | UNSET_RESERVED_WORD ("and_eq"); |
db5ae43f MS |
855 | UNSET_RESERVED_WORD ("bitand"); |
856 | UNSET_RESERVED_WORD ("bitor"); | |
857 | UNSET_RESERVED_WORD ("compl"); | |
858 | UNSET_RESERVED_WORD ("not"); | |
79ff2c6c | 859 | UNSET_RESERVED_WORD ("not_eq"); |
db5ae43f | 860 | UNSET_RESERVED_WORD ("or"); |
79ff2c6c | 861 | UNSET_RESERVED_WORD ("or_eq"); |
db5ae43f | 862 | UNSET_RESERVED_WORD ("xor"); |
79ff2c6c | 863 | UNSET_RESERVED_WORD ("xor_eq"); |
db5ae43f | 864 | } |
8d08fdba | 865 | |
2b2a3531 | 866 | token_count = init_cpp_parse (); |
8d08fdba | 867 | interface_unknown = 1; |
a755ad1c DB |
868 | |
869 | return filename; | |
8d08fdba MS |
870 | } |
871 | ||
2b2a3531 DB |
872 | void |
873 | finish_parse () | |
874 | { | |
875 | #if USE_CPPLIB | |
876 | cpp_finish (&parse_in); | |
1b87232a | 877 | errorcount += parse_in.errors; |
2b2a3531 DB |
878 | #else |
879 | fclose (finput); | |
880 | #endif | |
881 | } | |
882 | ||
8d08fdba MS |
883 | void |
884 | reinit_parse_for_function () | |
885 | { | |
886 | current_base_init_list = NULL_TREE; | |
887 | current_member_init_list = NULL_TREE; | |
888 | } | |
889 | \f | |
890 | #ifdef __GNUC__ | |
891 | __inline | |
892 | #endif | |
893 | void | |
894 | yyprint (file, yychar, yylval) | |
895 | FILE *file; | |
896 | int yychar; | |
897 | YYSTYPE yylval; | |
898 | { | |
899 | tree t; | |
900 | switch (yychar) | |
901 | { | |
902 | case IDENTIFIER: | |
903 | case TYPENAME: | |
904 | case TYPESPEC: | |
905 | case PTYPENAME: | |
074917ba | 906 | case PFUNCNAME: |
8d08fdba MS |
907 | case IDENTIFIER_DEFN: |
908 | case TYPENAME_DEFN: | |
909 | case PTYPENAME_DEFN: | |
8d08fdba MS |
910 | case SCSPEC: |
911 | case PRE_PARSED_CLASS_DECL: | |
912 | t = yylval.ttype; | |
11686454 | 913 | if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL) |
fc378698 | 914 | { |
430bb96b | 915 | fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t))); |
fc378698 MS |
916 | break; |
917 | } | |
8d08fdba MS |
918 | my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224); |
919 | if (IDENTIFIER_POINTER (t)) | |
920 | fprintf (file, " `%s'", IDENTIFIER_POINTER (t)); | |
921 | break; | |
1ceb5ff3 | 922 | |
8d08fdba MS |
923 | case AGGR: |
924 | if (yylval.ttype == class_type_node) | |
925 | fprintf (file, " `class'"); | |
926 | else if (yylval.ttype == record_type_node) | |
927 | fprintf (file, " `struct'"); | |
928 | else if (yylval.ttype == union_type_node) | |
929 | fprintf (file, " `union'"); | |
930 | else if (yylval.ttype == enum_type_node) | |
931 | fprintf (file, " `enum'"); | |
8d08fdba MS |
932 | else |
933 | my_friendly_abort (80); | |
934 | break; | |
1ceb5ff3 JM |
935 | |
936 | case CONSTANT: | |
937 | t = yylval.ttype; | |
938 | if (TREE_CODE (t) == INTEGER_CST) | |
939 | fprintf (file, | |
940 | #if HOST_BITS_PER_WIDE_INT == 64 | |
941 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT | |
942 | " 0x%x%016x", | |
943 | #else | |
944 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG | |
945 | " 0x%lx%016lx", | |
946 | #else | |
947 | " 0x%llx%016llx", | |
948 | #endif | |
949 | #endif | |
950 | #else | |
951 | #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT | |
952 | " 0x%lx%08lx", | |
953 | #else | |
954 | " 0x%x%08x", | |
955 | #endif | |
956 | #endif | |
957 | TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t)); | |
958 | break; | |
8d08fdba MS |
959 | } |
960 | } | |
961 | ||
5566b478 | 962 | #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH) |
8d08fdba | 963 | static int *reduce_count; |
5566b478 MS |
964 | #endif |
965 | ||
8d08fdba MS |
966 | int *token_count; |
967 | ||
72b7eeff | 968 | #if 0 |
8d08fdba MS |
969 | #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0])) |
970 | #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0])) | |
72b7eeff | 971 | #endif |
8d08fdba | 972 | |
8d08fdba | 973 | #ifdef GATHER_STATISTICS |
72b7eeff | 974 | #ifdef REDUCE_LENGTH |
8d08fdba MS |
975 | void |
976 | yyhook (yyn) | |
977 | int yyn; | |
978 | { | |
979 | reduce_count[yyn] += 1; | |
980 | } | |
8d08fdba MS |
981 | |
982 | static int | |
983 | reduce_cmp (p, q) | |
984 | int *p, *q; | |
985 | { | |
986 | return reduce_count[*q] - reduce_count[*p]; | |
987 | } | |
988 | ||
989 | static int | |
990 | token_cmp (p, q) | |
991 | int *p, *q; | |
992 | { | |
993 | return token_count[*q] - token_count[*p]; | |
994 | } | |
8926095f | 995 | #endif |
72b7eeff | 996 | #endif |
8d08fdba MS |
997 | |
998 | void | |
999 | print_parse_statistics () | |
1000 | { | |
1001 | #ifdef GATHER_STATISTICS | |
72b7eeff | 1002 | #ifdef REDUCE_LENGTH |
8d08fdba MS |
1003 | #if YYDEBUG != 0 |
1004 | int i; | |
1005 | int maxlen = REDUCE_LENGTH; | |
1006 | unsigned *sorted; | |
1007 | ||
1008 | if (reduce_count[-1] == 0) | |
1009 | return; | |
1010 | ||
1011 | if (TOKEN_LENGTH > REDUCE_LENGTH) | |
1012 | maxlen = TOKEN_LENGTH; | |
1013 | sorted = (unsigned *) alloca (sizeof (int) * maxlen); | |
1014 | ||
1015 | for (i = 0; i < TOKEN_LENGTH; i++) | |
1016 | sorted[i] = i; | |
1017 | qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp); | |
1018 | for (i = 0; i < TOKEN_LENGTH; i++) | |
1019 | { | |
e92cc029 MS |
1020 | int idx = sorted[i]; |
1021 | if (token_count[idx] == 0) | |
8d08fdba | 1022 | break; |
e92cc029 | 1023 | if (token_count[idx] < token_count[-1]) |
8d08fdba MS |
1024 | break; |
1025 | fprintf (stderr, "token %d, `%s', count = %d\n", | |
e92cc029 | 1026 | idx, yytname[YYTRANSLATE (idx)], token_count[idx]); |
8d08fdba MS |
1027 | } |
1028 | fprintf (stderr, "\n"); | |
1029 | for (i = 0; i < REDUCE_LENGTH; i++) | |
1030 | sorted[i] = i; | |
1031 | qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp); | |
1032 | for (i = 0; i < REDUCE_LENGTH; i++) | |
1033 | { | |
e92cc029 MS |
1034 | int idx = sorted[i]; |
1035 | if (reduce_count[idx] == 0) | |
8d08fdba | 1036 | break; |
e92cc029 | 1037 | if (reduce_count[idx] < reduce_count[-1]) |
8d08fdba MS |
1038 | break; |
1039 | fprintf (stderr, "rule %d, line %d, count = %d\n", | |
e92cc029 | 1040 | idx, yyrline[idx], reduce_count[idx]); |
8d08fdba MS |
1041 | } |
1042 | fprintf (stderr, "\n"); | |
1043 | #endif | |
1044 | #endif | |
72b7eeff | 1045 | #endif |
8d08fdba MS |
1046 | } |
1047 | ||
1048 | /* Sets the value of the 'yydebug' variable to VALUE. | |
1049 | This is a function so we don't have to have YYDEBUG defined | |
1050 | in order to build the compiler. */ | |
e92cc029 | 1051 | |
8d08fdba MS |
1052 | void |
1053 | set_yydebug (value) | |
1054 | int value; | |
1055 | { | |
1056 | #if YYDEBUG != 0 | |
1057 | extern int yydebug; | |
1058 | yydebug = value; | |
1059 | #else | |
8251199e | 1060 | warning ("YYDEBUG not defined."); |
8d08fdba MS |
1061 | #endif |
1062 | } | |
1063 | ||
8d08fdba MS |
1064 | \f |
1065 | /* Functions and data structures for #pragma interface. | |
1066 | ||
1067 | `#pragma implementation' means that the main file being compiled | |
1068 | is considered to implement (provide) the classes that appear in | |
1069 | its main body. I.e., if this is file "foo.cc", and class `bar' | |
1070 | is defined in "foo.cc", then we say that "foo.cc implements bar". | |
1071 | ||
1072 | All main input files "implement" themselves automagically. | |
1073 | ||
1074 | `#pragma interface' means that unless this file (of the form "foo.h" | |
1075 | is not presently being included by file "foo.cc", the | |
1076 | CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none | |
1077 | of the vtables nor any of the inline functions defined in foo.h | |
1078 | will ever be output. | |
1079 | ||
1080 | There are cases when we want to link files such as "defs.h" and | |
1081 | "main.cc". In this case, we give "defs.h" a `#pragma interface', | |
1082 | and "main.cc" has `#pragma implementation "defs.h"'. */ | |
1083 | ||
1084 | struct impl_files | |
1085 | { | |
1086 | char *filename; | |
1087 | struct impl_files *next; | |
1088 | }; | |
1089 | ||
1090 | static struct impl_files *impl_file_chain; | |
1091 | ||
1092 | /* Helper function to load global variables with interface | |
1093 | information. */ | |
e92cc029 | 1094 | |
8d08fdba MS |
1095 | void |
1096 | extract_interface_info () | |
1097 | { | |
1098 | tree fileinfo = 0; | |
1099 | ||
1100 | if (flag_alt_external_templates) | |
1101 | { | |
1102 | struct tinst_level *til = tinst_for_decl (); | |
1103 | ||
1104 | if (til) | |
1105 | fileinfo = get_time_identifier (til->file); | |
1106 | } | |
1107 | if (!fileinfo) | |
1108 | fileinfo = get_time_identifier (input_filename); | |
f181d4ae | 1109 | fileinfo = TIME_IDENTIFIER_FILEINFO (fileinfo); |
8d08fdba | 1110 | interface_only = TREE_INT_CST_LOW (fileinfo); |
5566b478 | 1111 | interface_unknown = TREE_INT_CST_HIGH (fileinfo); |
8d08fdba MS |
1112 | } |
1113 | ||
51c184be | 1114 | /* Return nonzero if S is not considered part of an |
8d08fdba | 1115 | INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */ |
e92cc029 | 1116 | |
8d08fdba MS |
1117 | static int |
1118 | interface_strcmp (s) | |
d8e178a0 | 1119 | const char *s; |
8d08fdba MS |
1120 | { |
1121 | /* Set the interface/implementation bits for this scope. */ | |
1122 | struct impl_files *ifiles; | |
d8e178a0 | 1123 | const char *s1; |
8d08fdba | 1124 | |
8d08fdba MS |
1125 | for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next) |
1126 | { | |
d8e178a0 | 1127 | const char *t1 = ifiles->filename; |
8d08fdba MS |
1128 | s1 = s; |
1129 | ||
1130 | if (*s1 != *t1 || *s1 == 0) | |
1131 | continue; | |
1132 | ||
1133 | while (*s1 == *t1 && *s1 != 0) | |
1134 | s1++, t1++; | |
1135 | ||
1136 | /* A match. */ | |
1137 | if (*s1 == *t1) | |
1138 | return 0; | |
1139 | ||
1140 | /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */ | |
1141 | if (index (s1, '.') || index (t1, '.')) | |
1142 | continue; | |
1143 | ||
1144 | if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.') | |
1145 | continue; | |
1146 | ||
1147 | /* A match. */ | |
1148 | return 0; | |
1149 | } | |
1150 | ||
1151 | /* No matches. */ | |
1152 | return 1; | |
1153 | } | |
1154 | ||
1d02ac83 JM |
1155 | static void |
1156 | cp_pragma_interface (main_filename) | |
1157 | char *main_filename; | |
1158 | { | |
1159 | tree fileinfo | |
1160 | = TIME_IDENTIFIER_FILEINFO (get_time_identifier (input_filename)); | |
1161 | ||
1162 | if (impl_file_chain == 0) | |
1163 | { | |
1164 | /* If this is zero at this point, then we are | |
1165 | auto-implementing. */ | |
1166 | if (main_input_filename == 0) | |
1167 | main_input_filename = input_filename; | |
1168 | ||
1169 | #ifdef AUTO_IMPLEMENT | |
1170 | filename = file_name_nondirectory (main_input_filename); | |
1171 | fi = get_time_identifier (filename); | |
1172 | fi = TIME_IDENTIFIER_FILEINFO (fi); | |
1173 | TREE_INT_CST_LOW (fi) = 0; | |
1174 | TREE_INT_CST_HIGH (fi) = 1; | |
1175 | /* Get default. */ | |
1176 | impl_file_chain = (struct impl_files *)permalloc (sizeof (struct impl_files)); | |
1177 | impl_file_chain->filename = filename; | |
1178 | impl_file_chain->next = 0; | |
1179 | #endif | |
1180 | } | |
1181 | ||
1182 | interface_only = interface_strcmp (main_filename); | |
1183 | #ifdef MULTIPLE_SYMBOL_SPACES | |
1184 | if (! interface_only) | |
1185 | interface_unknown = 0; | |
1186 | #else /* MULTIPLE_SYMBOL_SPACES */ | |
1187 | interface_unknown = 0; | |
1188 | #endif /* MULTIPLE_SYMBOL_SPACES */ | |
1189 | TREE_INT_CST_LOW (fileinfo) = interface_only; | |
1190 | TREE_INT_CST_HIGH (fileinfo) = interface_unknown; | |
1191 | } | |
1192 | ||
1193 | static void | |
1194 | cp_pragma_implementation (main_filename) | |
1195 | char *main_filename; | |
1196 | { | |
1197 | tree fileinfo | |
1198 | = TIME_IDENTIFIER_FILEINFO (get_time_identifier (input_filename)); | |
1199 | ||
1200 | if (impl_file_chain) | |
1201 | { | |
1202 | struct impl_files *ifiles = impl_file_chain; | |
1203 | while (ifiles) | |
1204 | { | |
1205 | if (! strcmp (ifiles->filename, main_filename)) | |
1206 | break; | |
1207 | ifiles = ifiles->next; | |
1208 | } | |
1209 | if (ifiles == 0) | |
1210 | { | |
1211 | ifiles = (struct impl_files*) permalloc (sizeof (struct impl_files)); | |
1212 | ifiles->filename = main_filename; | |
1213 | ifiles->next = impl_file_chain; | |
1214 | impl_file_chain = ifiles; | |
1215 | } | |
1216 | } | |
1217 | else if ((main_input_filename != 0 | |
1218 | && ! strcmp (main_input_filename, input_filename)) | |
1219 | || ! strcmp (main_filename, input_filename)) | |
1220 | { | |
1221 | impl_file_chain = (struct impl_files*) permalloc (sizeof (struct impl_files)); | |
1222 | impl_file_chain->filename = main_filename; | |
1223 | impl_file_chain->next = 0; | |
1224 | } | |
1225 | else | |
1226 | error ("`#pragma implementation' can only appear at top-level"); | |
1227 | interface_only = 0; | |
1228 | #if 1 | |
1229 | /* We make this non-zero so that we infer decl linkage | |
1230 | in the impl file only for variables first declared | |
1231 | in the interface file. */ | |
1232 | interface_unknown = 1; | |
1233 | #else | |
1234 | /* We make this zero so that templates in the impl | |
1235 | file will be emitted properly. */ | |
1236 | interface_unknown = 0; | |
1237 | #endif | |
1238 | TREE_INT_CST_LOW (fileinfo) = interface_only; | |
1239 | TREE_INT_CST_HIGH (fileinfo) = interface_unknown; | |
1240 | } | |
8d08fdba | 1241 | \f |
f181d4ae MM |
1242 | /* Set up the state required to correctly handle the definition of the |
1243 | inline function whose preparsed state has been saved in PI. */ | |
1244 | ||
1245 | static void | |
1246 | begin_definition_of_inclass_inline (pi) | |
1247 | struct pending_inline* pi; | |
1248 | { | |
1249 | tree context; | |
1250 | ||
1251 | if (!pi->fndecl) | |
1252 | return; | |
1253 | ||
1254 | /* If this is an inline function in a local class, we must make sure | |
1255 | that we save all pertinent information about the function | |
1256 | surrounding the local class. */ | |
1257 | context = hack_decl_function_context (pi->fndecl); | |
1258 | if (context) | |
1259 | push_cp_function_context (context); | |
1260 | ||
1946537b | 1261 | feed_input (pi->buf, pi->len, pi->filename, pi->lineno); |
f181d4ae MM |
1262 | yychar = PRE_PARSED_FUNCTION_DECL; |
1263 | yylval.ttype = build_tree_list ((tree) pi, pi->fndecl); | |
1264 | /* Pass back a handle to the rest of the inline functions, so that they | |
1265 | can be processed later. */ | |
1266 | DECL_PENDING_INLINE_INFO (pi->fndecl) = 0; | |
1267 | interface_unknown = pi->interface == 1; | |
1268 | interface_only = pi->interface == 0; | |
1269 | } | |
1270 | ||
8d08fdba MS |
1271 | /* Called from the top level: if there are any pending inlines to |
1272 | do, set up to process them now. This function sets up the first function | |
51c184be | 1273 | to be parsed; after it has been, the rule for fndef in parse.y will |
8d08fdba | 1274 | call process_next_inline to start working on the next one. */ |
e92cc029 | 1275 | |
8d08fdba MS |
1276 | void |
1277 | do_pending_inlines () | |
1278 | { | |
8d08fdba MS |
1279 | struct pending_inline *t; |
1280 | ||
1281 | /* Oops, we're still dealing with the last batch. */ | |
1282 | if (yychar == PRE_PARSED_FUNCTION_DECL) | |
1283 | return; | |
f376e137 | 1284 | |
8d08fdba MS |
1285 | /* Reverse the pending inline functions, since |
1286 | they were cons'd instead of appended. */ | |
f376e137 | 1287 | { |
9e9ff709 | 1288 | struct pending_inline *prev = 0, *tail; |
f376e137 MS |
1289 | t = pending_inlines; |
1290 | pending_inlines = 0; | |
1291 | ||
1292 | for (; t; t = tail) | |
1293 | { | |
1294 | tail = t->next; | |
eac293a1 MS |
1295 | t->next = prev; |
1296 | t->deja_vu = 1; | |
1297 | prev = t; | |
1298 | } | |
f376e137 MS |
1299 | t = prev; |
1300 | } | |
1301 | ||
1302 | if (t == 0) | |
1303 | return; | |
1304 | ||
8d08fdba | 1305 | /* Now start processing the first inline function. */ |
f181d4ae | 1306 | begin_definition_of_inclass_inline (t); |
8d08fdba MS |
1307 | } |
1308 | ||
8d08fdba MS |
1309 | /* Called from the fndecl rule in the parser when the function just parsed |
1310 | was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from | |
1311 | do_pending_inlines). */ | |
e92cc029 | 1312 | |
8d08fdba MS |
1313 | void |
1314 | process_next_inline (t) | |
1315 | tree t; | |
1316 | { | |
5566b478 | 1317 | tree context; |
8d08fdba | 1318 | struct pending_inline *i = (struct pending_inline *) TREE_PURPOSE (t); |
98c1c668 | 1319 | context = hack_decl_function_context (i->fndecl); |
5566b478 MS |
1320 | if (context) |
1321 | pop_cp_function_context (context); | |
8d08fdba MS |
1322 | i = i->next; |
1323 | if (yychar == YYEMPTY) | |
1324 | yychar = yylex (); | |
1325 | if (yychar != END_OF_SAVED_INPUT) | |
1326 | { | |
8251199e | 1327 | error ("parse error at end of saved function text"); |
e92cc029 | 1328 | |
8d08fdba | 1329 | /* restore_pending_input will abort unless yychar is either |
e92cc029 | 1330 | END_OF_SAVED_INPUT or YYEMPTY; since we already know we're |
66a6250f | 1331 | hosed, feed back YYEMPTY. */ |
8d08fdba MS |
1332 | } |
1333 | yychar = YYEMPTY; | |
42976354 | 1334 | end_input (); |
8d08fdba | 1335 | if (i) |
f181d4ae | 1336 | begin_definition_of_inclass_inline (i); |
8d08fdba MS |
1337 | else |
1338 | extract_interface_info (); | |
1339 | } | |
1340 | ||
1341 | /* Since inline methods can refer to text which has not yet been seen, | |
1342 | we store the text of the method in a structure which is placed in the | |
1343 | DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL. | |
1344 | After parsing the body of the class definition, the FUNCTION_DECL's are | |
1345 | scanned to see which ones have this field set. Those are then digested | |
1346 | one at a time. | |
1347 | ||
1348 | This function's FUNCTION_DECL will have a bit set in its common so | |
1349 | that we know to watch out for it. */ | |
1350 | ||
1351 | static void | |
1352 | consume_string (this_obstack, matching_char) | |
1353 | register struct obstack *this_obstack; | |
1354 | int matching_char; | |
1355 | { | |
1356 | register int c; | |
66a6250f JM |
1357 | int starting_lineno; |
1358 | ||
1359 | #if USE_CPPLIB | |
1360 | if (cpp_token == CPP_STRING) | |
1361 | { | |
1362 | /* The C preprocessor will warn about newlines in strings. */ | |
1363 | obstack_grow (this_obstack, yy_cur, (yy_lim - yy_cur)); | |
1364 | yy_cur = yy_lim; | |
1365 | lineno = parse_in.lineno; | |
1366 | return; | |
1367 | } | |
1368 | #endif | |
1369 | ||
1370 | starting_lineno = lineno; | |
8d08fdba MS |
1371 | do |
1372 | { | |
1373 | c = getch (); | |
1374 | if (c == EOF) | |
1375 | { | |
1376 | int save_lineno = lineno; | |
1377 | lineno = starting_lineno; | |
1378 | if (matching_char == '"') | |
8251199e | 1379 | error ("end of file encountered inside string constant"); |
8d08fdba | 1380 | else |
8251199e | 1381 | error ("end of file encountered inside character constant"); |
8d08fdba MS |
1382 | lineno = save_lineno; |
1383 | return; | |
1384 | } | |
1385 | if (c == '\\') | |
1386 | { | |
1387 | obstack_1grow (this_obstack, c); | |
1388 | c = getch (); | |
1389 | obstack_1grow (this_obstack, c); | |
1390 | ||
1391 | /* Make sure we continue the loop */ | |
1392 | c = 0; | |
1393 | continue; | |
1394 | } | |
1395 | if (c == '\n') | |
1396 | { | |
1397 | if (pedantic) | |
8251199e | 1398 | pedwarn ("ANSI C++ forbids newline in string constant"); |
8d08fdba MS |
1399 | lineno++; |
1400 | } | |
1401 | obstack_1grow (this_obstack, c); | |
1402 | } | |
1403 | while (c != matching_char); | |
1404 | } | |
1405 | ||
8d08fdba | 1406 | struct pending_input { |
66a6250f JM |
1407 | int yychar, eof; |
1408 | YYSTYPE yylval; | |
8d08fdba MS |
1409 | struct obstack token_obstack; |
1410 | int first_token; | |
1411 | }; | |
1412 | ||
1413 | struct pending_input * | |
1414 | save_pending_input () | |
1415 | { | |
1416 | struct pending_input *p; | |
1417 | p = (struct pending_input *) xmalloc (sizeof (struct pending_input)); | |
8d08fdba | 1418 | p->yychar = yychar; |
8d08fdba | 1419 | p->yylval = yylval; |
8d08fdba | 1420 | p->eof = end_of_file; |
66a6250f | 1421 | yychar = YYEMPTY; |
8d08fdba MS |
1422 | p->first_token = first_token; |
1423 | p->token_obstack = token_obstack; | |
1424 | ||
1425 | first_token = 0; | |
1426 | gcc_obstack_init (&token_obstack); | |
1427 | end_of_file = 0; | |
1428 | return p; | |
1429 | } | |
1430 | ||
1431 | void | |
1432 | restore_pending_input (p) | |
1433 | struct pending_input *p; | |
1434 | { | |
8d08fdba MS |
1435 | my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230); |
1436 | yychar = p->yychar; | |
8d08fdba | 1437 | yylval = p->yylval; |
8d08fdba MS |
1438 | first_token = p->first_token; |
1439 | obstack_free (&token_obstack, (char *) 0); | |
1440 | token_obstack = p->token_obstack; | |
1441 | end_of_file = p->eof; | |
1442 | free (p); | |
1443 | } | |
1444 | ||
8d08fdba MS |
1445 | /* Unget character CH from the input stream. |
1446 | If RESCAN is non-zero, then we want to `see' this | |
1447 | character as the next input token. */ | |
e92cc029 | 1448 | |
8d08fdba MS |
1449 | void |
1450 | yyungetc (ch, rescan) | |
1451 | int ch; | |
1452 | int rescan; | |
1453 | { | |
1454 | /* Unget a character from the input stream. */ | |
1455 | if (yychar == YYEMPTY || rescan == 0) | |
1456 | { | |
1ceb5ff3 JM |
1457 | /* If we're putting back a brace, undo the change in indent_level |
1458 | from the first time we saw it. */ | |
1459 | if (ch == '{') | |
1460 | indent_level--; | |
1461 | else if (ch == '}') | |
1462 | indent_level++; | |
1463 | ||
66a6250f | 1464 | put_back (ch); |
8d08fdba MS |
1465 | } |
1466 | else | |
1467 | { | |
8d08fdba MS |
1468 | yychar = ch; |
1469 | } | |
1470 | } | |
1471 | ||
42976354 BK |
1472 | void |
1473 | clear_inline_text_obstack () | |
1474 | { | |
1475 | obstack_free (&inline_text_obstack, inline_text_firstobj); | |
1476 | } | |
1477 | ||
8d08fdba MS |
1478 | /* This function stores away the text for an inline function that should |
1479 | be processed later. It decides how much later, and may need to move | |
1480 | the info between obstacks; therefore, the caller should not refer to | |
5566b478 | 1481 | the T parameter after calling this function. */ |
8d08fdba MS |
1482 | |
1483 | static void | |
1484 | store_pending_inline (decl, t) | |
1485 | tree decl; | |
1486 | struct pending_inline *t; | |
1487 | { | |
8d08fdba | 1488 | t->fndecl = decl; |
5566b478 | 1489 | DECL_PENDING_INLINE_INFO (decl) = t; |
8d08fdba MS |
1490 | |
1491 | /* Because we use obstacks, we must process these in precise order. */ | |
5566b478 MS |
1492 | t->next = pending_inlines; |
1493 | pending_inlines = t; | |
8d08fdba MS |
1494 | } |
1495 | ||
8d08fdba MS |
1496 | void |
1497 | reinit_parse_for_method (yychar, decl) | |
1498 | int yychar; | |
1499 | tree decl; | |
1500 | { | |
1501 | int len; | |
1502 | int starting_lineno = lineno; | |
1503 | char *starting_filename = input_filename; | |
1504 | ||
5566b478 | 1505 | reinit_parse_for_block (yychar, &inline_text_obstack); |
8d08fdba MS |
1506 | |
1507 | len = obstack_object_size (&inline_text_obstack); | |
1508 | current_base_init_list = NULL_TREE; | |
1509 | current_member_init_list = NULL_TREE; | |
1510 | if (decl == void_type_node | |
1511 | || (current_class_type && TYPE_REDEFINED (current_class_type))) | |
1512 | { | |
1513 | /* Happens when we get two declarations of the same | |
1514 | function in the same scope. */ | |
1515 | char *buf = obstack_finish (&inline_text_obstack); | |
1516 | obstack_free (&inline_text_obstack, buf); | |
1517 | return; | |
1518 | } | |
1519 | else | |
1520 | { | |
1521 | struct pending_inline *t; | |
1522 | char *buf = obstack_finish (&inline_text_obstack); | |
1523 | ||
1524 | t = (struct pending_inline *) obstack_alloc (&inline_text_obstack, | |
1525 | sizeof (struct pending_inline)); | |
1526 | t->lineno = starting_lineno; | |
1527 | t->filename = starting_filename; | |
1528 | t->token = YYEMPTY; | |
1529 | t->token_value = 0; | |
1530 | t->buf = buf; | |
1531 | t->len = len; | |
8d08fdba | 1532 | t->deja_vu = 0; |
5566b478 | 1533 | #if 0 |
8d08fdba | 1534 | if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl)) |
8ccc31eb | 1535 | warn_if_unknown_interface (decl); |
5566b478 | 1536 | #endif |
8d08fdba MS |
1537 | t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2)); |
1538 | store_pending_inline (decl, t); | |
1539 | } | |
1540 | } | |
1541 | ||
5566b478 MS |
1542 | /* Consume a block -- actually, a method beginning |
1543 | with `:' or `{' -- and save it away on the specified obstack. */ | |
8d08fdba | 1544 | |
49c249e1 | 1545 | void |
5566b478 | 1546 | reinit_parse_for_block (pyychar, obstackp) |
f30432d7 | 1547 | int pyychar; |
8d08fdba | 1548 | struct obstack *obstackp; |
8d08fdba | 1549 | { |
66a6250f | 1550 | register int c; |
8d08fdba MS |
1551 | int blev = 1; |
1552 | int starting_lineno = lineno; | |
1553 | char *starting_filename = input_filename; | |
1554 | int len; | |
1555 | int look_for_semicolon = 0; | |
1556 | int look_for_lbrac = 0; | |
1557 | ||
f30432d7 | 1558 | if (pyychar == '{') |
1ceb5ff3 JM |
1559 | { |
1560 | obstack_1grow (obstackp, '{'); | |
1561 | /* We incremented indent_level in yylex; undo that. */ | |
1562 | indent_level--; | |
1563 | } | |
f30432d7 | 1564 | else if (pyychar == '=') |
8d08fdba | 1565 | look_for_semicolon = 1; |
f30432d7 | 1566 | else if (pyychar == ':') |
8d08fdba | 1567 | { |
f30432d7 | 1568 | obstack_1grow (obstackp, pyychar); |
8ebeee52 JM |
1569 | /* Add a space so we don't get confused by ': ::A(20)'. */ |
1570 | obstack_1grow (obstackp, ' '); | |
f30432d7 MS |
1571 | look_for_lbrac = 1; |
1572 | blev = 0; | |
8d08fdba | 1573 | } |
3dcaad8b | 1574 | else if (pyychar == RETURN_KEYWORD) |
f30432d7 MS |
1575 | { |
1576 | obstack_grow (obstackp, "return", 6); | |
1577 | look_for_lbrac = 1; | |
1578 | blev = 0; | |
1579 | } | |
5566b478 | 1580 | else if (pyychar == TRY) |
8d08fdba | 1581 | { |
f30432d7 | 1582 | obstack_grow (obstackp, "try", 3); |
8d08fdba MS |
1583 | look_for_lbrac = 1; |
1584 | blev = 0; | |
1585 | } | |
f30432d7 MS |
1586 | else |
1587 | { | |
5566b478 | 1588 | yyerror ("parse error in method specification"); |
f30432d7 MS |
1589 | obstack_1grow (obstackp, '{'); |
1590 | } | |
8d08fdba | 1591 | |
66a6250f JM |
1592 | c = getch (); |
1593 | ||
8d08fdba MS |
1594 | while (c != EOF) |
1595 | { | |
1596 | int this_lineno = lineno; | |
1597 | ||
1598 | c = skip_white_space (c); | |
1599 | ||
1600 | /* Don't lose our cool if there are lots of comments. */ | |
1601 | if (lineno == this_lineno + 1) | |
1602 | obstack_1grow (obstackp, '\n'); | |
1603 | else if (lineno == this_lineno) | |
1604 | ; | |
1605 | else if (lineno - this_lineno < 10) | |
1606 | { | |
1607 | int i; | |
1608 | for (i = lineno - this_lineno; i > 0; i--) | |
1609 | obstack_1grow (obstackp, '\n'); | |
1610 | } | |
1611 | else | |
1612 | { | |
1613 | char buf[16]; | |
1614 | sprintf (buf, "\n# %d \"", lineno); | |
1615 | len = strlen (buf); | |
1616 | obstack_grow (obstackp, buf, len); | |
1617 | ||
1618 | len = strlen (input_filename); | |
1619 | obstack_grow (obstackp, input_filename, len); | |
1620 | obstack_1grow (obstackp, '\"'); | |
1621 | obstack_1grow (obstackp, '\n'); | |
1622 | } | |
1623 | ||
1624 | while (c > ' ') /* ASCII dependent... */ | |
1625 | { | |
1626 | obstack_1grow (obstackp, c); | |
1627 | if (c == '{') | |
1628 | { | |
1629 | look_for_lbrac = 0; | |
1630 | blev++; | |
1631 | } | |
1632 | else if (c == '}') | |
1633 | { | |
1634 | blev--; | |
1635 | if (blev == 0 && !look_for_semicolon) | |
f30432d7 MS |
1636 | { |
1637 | if (pyychar == TRY) | |
1638 | { | |
1639 | if (peekyylex () == CATCH) | |
1640 | { | |
1641 | yylex (); | |
1642 | obstack_grow (obstackp, " catch ", 7); | |
1643 | look_for_lbrac = 1; | |
1644 | } | |
1645 | else | |
1646 | { | |
1647 | yychar = '{'; | |
1648 | goto done; | |
1649 | } | |
1650 | } | |
1651 | else | |
1652 | { | |
1653 | goto done; | |
1654 | } | |
1655 | } | |
8d08fdba MS |
1656 | } |
1657 | else if (c == '\\') | |
1658 | { | |
1659 | /* Don't act on the next character...e.g, doing an escaped | |
1660 | double-quote. */ | |
1661 | c = getch (); | |
1662 | if (c == EOF) | |
1663 | { | |
1664 | error_with_file_and_line (starting_filename, | |
1665 | starting_lineno, | |
1666 | "end of file read inside definition"); | |
1667 | goto done; | |
1668 | } | |
1669 | obstack_1grow (obstackp, c); | |
1670 | } | |
1671 | else if (c == '\"') | |
1672 | consume_string (obstackp, c); | |
1673 | else if (c == '\'') | |
1674 | consume_string (obstackp, c); | |
1675 | else if (c == ';') | |
1676 | { | |
1677 | if (look_for_lbrac) | |
1678 | { | |
8251199e | 1679 | error ("function body for constructor missing"); |
8d08fdba MS |
1680 | obstack_1grow (obstackp, '{'); |
1681 | obstack_1grow (obstackp, '}'); | |
1682 | len += 2; | |
1683 | goto done; | |
1684 | } | |
1685 | else if (look_for_semicolon && blev == 0) | |
1686 | goto done; | |
1687 | } | |
1688 | c = getch (); | |
1689 | } | |
1690 | ||
1691 | if (c == EOF) | |
1692 | { | |
1693 | error_with_file_and_line (starting_filename, | |
1694 | starting_lineno, | |
1695 | "end of file read inside definition"); | |
1696 | goto done; | |
1697 | } | |
1698 | else if (c != '\n') | |
1699 | { | |
1700 | obstack_1grow (obstackp, c); | |
1701 | c = getch (); | |
1702 | } | |
1703 | } | |
1704 | done: | |
1705 | obstack_1grow (obstackp, '\0'); | |
1706 | } | |
1707 | ||
42976354 BK |
1708 | /* Consume a no-commas expression -- actually, a default argument -- and |
1709 | save it away on the specified obstack. */ | |
1710 | ||
1711 | static void | |
1712 | reinit_parse_for_expr (obstackp) | |
1713 | struct obstack *obstackp; | |
1714 | { | |
66a6250f | 1715 | register int c; |
42976354 BK |
1716 | int starting_lineno = lineno; |
1717 | char *starting_filename = input_filename; | |
1718 | int len; | |
42976354 BK |
1719 | int plev = 0; |
1720 | ||
66a6250f JM |
1721 | c = getch (); |
1722 | ||
42976354 BK |
1723 | while (c != EOF) |
1724 | { | |
1725 | int this_lineno = lineno; | |
1726 | ||
1727 | c = skip_white_space (c); | |
1728 | ||
1729 | /* Don't lose our cool if there are lots of comments. */ | |
1730 | if (lineno == this_lineno + 1) | |
1731 | obstack_1grow (obstackp, '\n'); | |
1732 | else if (lineno == this_lineno) | |
1733 | ; | |
1734 | else if (lineno - this_lineno < 10) | |
1735 | { | |
1736 | int i; | |
1737 | for (i = lineno - this_lineno; i > 0; --i) | |
1738 | obstack_1grow (obstackp, '\n'); | |
1739 | } | |
1740 | else | |
1741 | { | |
1742 | char buf[16]; | |
1743 | sprintf (buf, "\n# %d \"", lineno); | |
1744 | len = strlen (buf); | |
1745 | obstack_grow (obstackp, buf, len); | |
1746 | ||
1747 | len = strlen (input_filename); | |
1748 | obstack_grow (obstackp, input_filename, len); | |
1749 | obstack_1grow (obstackp, '\"'); | |
1750 | obstack_1grow (obstackp, '\n'); | |
1751 | } | |
1752 | ||
1753 | while (c > ' ') /* ASCII dependent... */ | |
1754 | { | |
1755 | if (plev <= 0 && (c == ')' || c == ',')) | |
1756 | { | |
1757 | put_back (c); | |
1758 | goto done; | |
1759 | } | |
1760 | obstack_1grow (obstackp, c); | |
1761 | if (c == '(' || c == '[') | |
1762 | ++plev; | |
1763 | else if (c == ']' || c == ')') | |
1764 | --plev; | |
1765 | else if (c == '\\') | |
1766 | { | |
1767 | /* Don't act on the next character...e.g, doing an escaped | |
1768 | double-quote. */ | |
1769 | c = getch (); | |
1770 | if (c == EOF) | |
1771 | { | |
1772 | error_with_file_and_line (starting_filename, | |
1773 | starting_lineno, | |
1774 | "end of file read inside definition"); | |
1775 | goto done; | |
1776 | } | |
1777 | obstack_1grow (obstackp, c); | |
1778 | } | |
1779 | else if (c == '\"') | |
1780 | consume_string (obstackp, c); | |
1781 | else if (c == '\'') | |
1782 | consume_string (obstackp, c); | |
1783 | c = getch (); | |
1784 | } | |
1785 | ||
1786 | if (c == EOF) | |
1787 | { | |
1788 | error_with_file_and_line (starting_filename, | |
1789 | starting_lineno, | |
1790 | "end of file read inside definition"); | |
1791 | goto done; | |
1792 | } | |
1793 | else if (c != '\n') | |
1794 | { | |
1795 | obstack_1grow (obstackp, c); | |
1796 | c = getch (); | |
1797 | } | |
1798 | } | |
1799 | done: | |
1800 | obstack_1grow (obstackp, '\0'); | |
1801 | } | |
1802 | ||
1803 | int do_snarf_defarg; | |
1804 | ||
1805 | /* Decide whether the default argument we are about to see should be | |
1806 | gobbled up as text for later parsing. */ | |
1807 | ||
1808 | void | |
1809 | maybe_snarf_defarg () | |
1810 | { | |
1811 | if (current_class_type && TYPE_BEING_DEFINED (current_class_type)) | |
1812 | do_snarf_defarg = 1; | |
1813 | } | |
1814 | ||
1815 | /* When we see a default argument in a method declaration, we snarf it as | |
1816 | text using snarf_defarg. When we get up to namespace scope, we then go | |
1817 | through and parse all of them using do_pending_defargs. Since yacc | |
1818 | parsers are not reentrant, we retain defargs state in these two | |
1819 | variables so that subsequent calls to do_pending_defargs can resume | |
1820 | where the previous call left off. */ | |
1821 | ||
1822 | tree defarg_fns; | |
1823 | tree defarg_parm; | |
1824 | ||
1825 | tree | |
1826 | snarf_defarg () | |
1827 | { | |
1828 | int len; | |
1829 | char *buf; | |
1830 | tree arg; | |
42976354 BK |
1831 | |
1832 | reinit_parse_for_expr (&inline_text_obstack); | |
1833 | len = obstack_object_size (&inline_text_obstack); | |
1834 | buf = obstack_finish (&inline_text_obstack); | |
1835 | ||
1836 | push_obstacks (&inline_text_obstack, &inline_text_obstack); | |
1837 | arg = make_node (DEFAULT_ARG); | |
1838 | DEFARG_LENGTH (arg) = len - 1; | |
1839 | DEFARG_POINTER (arg) = buf; | |
1840 | pop_obstacks (); | |
1841 | ||
1842 | return arg; | |
1843 | } | |
1844 | ||
1845 | /* Called from grokfndecl to note a function decl with unparsed default | |
1846 | arguments for later processing. Also called from grokdeclarator | |
1847 | for function types with unparsed defargs; the call from grokfndecl | |
1848 | will always come second, so we can overwrite the entry from the type. */ | |
1849 | ||
1850 | void | |
1851 | add_defarg_fn (decl) | |
1852 | tree decl; | |
1853 | { | |
1854 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1855 | TREE_VALUE (defarg_fns) = decl; | |
1856 | else | |
1857 | { | |
1858 | push_obstacks (&inline_text_obstack, &inline_text_obstack); | |
1859 | defarg_fns = tree_cons (current_class_type, decl, defarg_fns); | |
1860 | pop_obstacks (); | |
1861 | } | |
1862 | } | |
1863 | ||
1864 | /* Helper for do_pending_defargs. Starts the parsing of a default arg. */ | |
1865 | ||
1866 | static void | |
1867 | feed_defarg (f, p) | |
1868 | tree f, p; | |
1869 | { | |
1870 | tree d = TREE_PURPOSE (p); | |
1946537b JM |
1871 | char *file; |
1872 | int line; | |
42976354 BK |
1873 | if (TREE_CODE (f) == FUNCTION_DECL) |
1874 | { | |
1946537b JM |
1875 | line = DECL_SOURCE_LINE (f); |
1876 | file = DECL_SOURCE_FILE (f); | |
42976354 | 1877 | } |
1946537b JM |
1878 | else |
1879 | { | |
1880 | line = lineno; | |
1881 | file = input_filename; | |
1882 | } | |
1883 | ||
1884 | feed_input (DEFARG_POINTER (d), DEFARG_LENGTH (d), file, line); | |
42976354 BK |
1885 | yychar = DEFARG_MARKER; |
1886 | yylval.ttype = p; | |
1887 | } | |
1888 | ||
1889 | /* Helper for do_pending_defargs. Ends the parsing of a default arg. */ | |
1890 | ||
1891 | static void | |
1892 | finish_defarg () | |
1893 | { | |
1894 | if (yychar == YYEMPTY) | |
1895 | yychar = yylex (); | |
1896 | if (yychar != END_OF_SAVED_INPUT) | |
1897 | { | |
8251199e | 1898 | error ("parse error at end of saved function text"); |
42976354 BK |
1899 | |
1900 | /* restore_pending_input will abort unless yychar is either | |
1901 | END_OF_SAVED_INPUT or YYEMPTY; since we already know we're | |
66a6250f | 1902 | hosed, feed back YYEMPTY. */ |
42976354 BK |
1903 | } |
1904 | yychar = YYEMPTY; | |
1905 | end_input (); | |
1906 | } | |
1907 | ||
1908 | /* Main function for deferred parsing of default arguments. Called from | |
1909 | the parser. */ | |
1910 | ||
1911 | void | |
1912 | do_pending_defargs () | |
1913 | { | |
1914 | if (defarg_parm) | |
1915 | finish_defarg (); | |
1916 | ||
1917 | for (; defarg_fns; defarg_fns = TREE_CHAIN (defarg_fns)) | |
1918 | { | |
1919 | tree defarg_fn = TREE_VALUE (defarg_fns); | |
1920 | if (defarg_parm == NULL_TREE) | |
1921 | { | |
42976354 BK |
1922 | push_nested_class (TREE_PURPOSE (defarg_fns), 1); |
1923 | pushlevel (0); | |
22531e51 JM |
1924 | if (TREE_CODE (defarg_fn) == FUNCTION_DECL) |
1925 | maybe_begin_member_template_processing (defarg_fn); | |
42976354 BK |
1926 | |
1927 | if (TREE_CODE (defarg_fn) == FUNCTION_DECL) | |
1928 | { | |
1929 | #if 0 | |
b2bb2710 | 1930 | tree p; |
42976354 BK |
1931 | for (p = DECL_ARGUMENTS (defarg_fn); p; p = TREE_CHAIN (p)) |
1932 | pushdecl (copy_node (p)); | |
1933 | #endif | |
1934 | defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn)); | |
1935 | } | |
1936 | else | |
1937 | defarg_parm = TYPE_ARG_TYPES (defarg_fn); | |
1938 | } | |
1939 | else | |
1940 | defarg_parm = TREE_CHAIN (defarg_parm); | |
1941 | ||
1942 | for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm)) | |
da20811c JM |
1943 | if (TREE_PURPOSE (defarg_parm) |
1944 | && TREE_CODE (TREE_PURPOSE (defarg_parm)) == DEFAULT_ARG) | |
42976354 | 1945 | { |
42976354 BK |
1946 | feed_defarg (defarg_fn, defarg_parm); |
1947 | ||
1948 | /* Return to the parser, which will process this defarg | |
1949 | and call us again. */ | |
1950 | return; | |
1951 | } | |
1952 | ||
22531e51 | 1953 | if (TREE_CODE (defarg_fn) == FUNCTION_DECL) |
b7698cf0 | 1954 | { |
b370501f | 1955 | maybe_end_member_template_processing (); |
b7698cf0 JM |
1956 | check_default_args (defarg_fn); |
1957 | } | |
1958 | ||
42976354 | 1959 | poplevel (0, 0, 0); |
b74a0560 | 1960 | pop_nested_class (); |
42976354 BK |
1961 | } |
1962 | } | |
1963 | ||
8d08fdba MS |
1964 | /* Build a default function named NAME for type TYPE. |
1965 | KIND says what to build. | |
1966 | ||
1967 | When KIND == 0, build default destructor. | |
1968 | When KIND == 1, build virtual destructor. | |
1969 | When KIND == 2, build default constructor. | |
1970 | When KIND == 3, build default X(const X&) constructor. | |
1971 | When KIND == 4, build default X(X&) constructor. | |
1972 | When KIND == 5, build default operator = (const X&). | |
1973 | When KIND == 6, build default operator = (X&). */ | |
1974 | ||
1975 | tree | |
8ccc31eb MS |
1976 | cons_up_default_function (type, full_name, kind) |
1977 | tree type, full_name; | |
8d08fdba MS |
1978 | int kind; |
1979 | { | |
8d08fdba | 1980 | tree declspecs = NULL_TREE; |
a703fb38 | 1981 | tree fn, args = NULL_TREE; |
8d08fdba MS |
1982 | tree argtype; |
1983 | int retref = 0; | |
8ccc31eb | 1984 | tree name = constructor_name (full_name); |
8d08fdba | 1985 | |
8d08fdba MS |
1986 | switch (kind) |
1987 | { | |
1988 | /* Destructors. */ | |
1989 | case 1: | |
1990 | declspecs = build_decl_list (NULL_TREE, ridpointers [(int) RID_VIRTUAL]); | |
1991 | /* Fall through... */ | |
1992 | case 0: | |
1993 | name = build_parse_node (BIT_NOT_EXPR, name); | |
db5ae43f MS |
1994 | args = void_list_node; |
1995 | break; | |
1996 | ||
8d08fdba MS |
1997 | case 2: |
1998 | /* Default constructor. */ | |
1999 | args = void_list_node; | |
8d08fdba MS |
2000 | break; |
2001 | ||
2002 | case 3: | |
91063b51 | 2003 | type = build_qualified_type (type, TYPE_QUAL_CONST); |
8d08fdba MS |
2004 | /* Fall through... */ |
2005 | case 4: | |
2006 | /* According to ARM $12.8, the default copy ctor will be declared, but | |
f376e137 | 2007 | not defined, unless it's needed. */ |
8d08fdba MS |
2008 | argtype = build_reference_type (type); |
2009 | args = tree_cons (NULL_TREE, | |
2010 | build_tree_list (hash_tree_chain (argtype, NULL_TREE), | |
2011 | get_identifier ("_ctor_arg")), | |
2012 | void_list_node); | |
8d08fdba MS |
2013 | break; |
2014 | ||
2015 | case 5: | |
8d08fdba MS |
2016 | case 6: |
2017 | retref = 1; | |
6b5fbb55 | 2018 | declspecs = build_decl_list (NULL_TREE, type); |
8d08fdba | 2019 | |
824b9a4c | 2020 | if (kind == 5) |
91063b51 | 2021 | type = build_qualified_type (type, TYPE_QUAL_CONST); |
824b9a4c | 2022 | |
8d08fdba MS |
2023 | name = ansi_opname [(int) MODIFY_EXPR]; |
2024 | ||
2025 | argtype = build_reference_type (type); | |
2026 | args = tree_cons (NULL_TREE, | |
2027 | build_tree_list (hash_tree_chain (argtype, NULL_TREE), | |
2028 | get_identifier ("_ctor_arg")), | |
2029 | void_list_node); | |
8d08fdba MS |
2030 | break; |
2031 | ||
2032 | default: | |
2033 | my_friendly_abort (59); | |
2034 | } | |
2035 | ||
f376e137 MS |
2036 | declspecs = decl_tree_cons (NULL_TREE, ridpointers [(int) RID_INLINE], |
2037 | declspecs); | |
8d08fdba MS |
2038 | |
2039 | TREE_PARMLIST (args) = 1; | |
2040 | ||
2041 | { | |
c11b6f21 | 2042 | tree declarator = make_call_declarator (name, args, NULL_TREE, NULL_TREE); |
8d08fdba MS |
2043 | if (retref) |
2044 | declarator = build_parse_node (ADDR_EXPR, declarator); | |
92eca640 | 2045 | |
c11b6f21 | 2046 | fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE); |
8d08fdba MS |
2047 | } |
2048 | ||
2049 | if (fn == void_type_node) | |
2050 | return fn; | |
2051 | ||
d11ad92e MS |
2052 | if (kind > 2) |
2053 | SET_DECL_ARTIFICIAL (TREE_CHAIN (DECL_ARGUMENTS (fn))); | |
2054 | ||
5566b478 | 2055 | #if 0 |
db5ae43f | 2056 | if (processing_template_defn) |
79ff2c6c MS |
2057 | { |
2058 | SET_DECL_IMPLICIT_INSTANTIATION (fn); | |
2059 | repo_template_used (fn); | |
2060 | } | |
5566b478 | 2061 | #endif |
3536cd7e | 2062 | |
fc378698 | 2063 | #if 0 |
db5ae43f MS |
2064 | if (CLASSTYPE_INTERFACE_KNOWN (type)) |
2065 | { | |
2066 | DECL_INTERFACE_KNOWN (fn) = 1; | |
a5894242 MS |
2067 | DECL_NOT_REALLY_EXTERN (fn) = (!CLASSTYPE_INTERFACE_ONLY (type) |
2068 | && flag_implement_inlines); | |
db5ae43f | 2069 | } |
e8abc66f | 2070 | else |
fc378698 | 2071 | #endif |
e8abc66f | 2072 | DECL_NOT_REALLY_EXTERN (fn) = 1; |
db5ae43f | 2073 | |
5566b478 | 2074 | mark_inline_for_output (fn); |
8d08fdba | 2075 | |
8d08fdba MS |
2076 | #ifdef DEBUG_DEFAULT_FUNCTIONS |
2077 | { char *fn_type = NULL; | |
2078 | tree t = name; | |
2079 | switch (kind) | |
2080 | { | |
2081 | case 0: fn_type = "default destructor"; break; | |
2082 | case 1: fn_type = "virtual destructor"; break; | |
2083 | case 2: fn_type = "default constructor"; break; | |
2084 | case 3: fn_type = "default X(const X&)"; break; | |
2085 | case 4: fn_type = "default X(X&)"; break; | |
2086 | } | |
2087 | if (fn_type) | |
2088 | { | |
2089 | if (TREE_CODE (name) == BIT_NOT_EXPR) | |
2090 | t = TREE_OPERAND (name, 0); | |
2091 | fprintf (stderr, "[[[[ %s for %s:\n%s]]]]\n", fn_type, | |
2092 | IDENTIFIER_POINTER (t), func_buf); | |
2093 | } | |
2094 | } | |
8926095f | 2095 | #endif /* DEBUG_DEFAULT_FUNCTIONS */ |
8d08fdba | 2096 | |
8d08fdba | 2097 | /* Show that this function was generated by the compiler. */ |
700f8a87 | 2098 | SET_DECL_ARTIFICIAL (fn); |
8d08fdba MS |
2099 | |
2100 | return fn; | |
2101 | } | |
2102 | ||
8d08fdba MS |
2103 | /* Heuristic to tell whether the user is missing a semicolon |
2104 | after a struct or enum declaration. Emit an error message | |
2105 | if we know the user has blown it. */ | |
e92cc029 | 2106 | |
8d08fdba MS |
2107 | void |
2108 | check_for_missing_semicolon (type) | |
2109 | tree type; | |
2110 | { | |
2111 | if (yychar < 0) | |
2112 | yychar = yylex (); | |
2113 | ||
00595019 MS |
2114 | if ((yychar > 255 |
2115 | && yychar != SCSPEC | |
2116 | && yychar != IDENTIFIER | |
a80e4195 | 2117 | && yychar != TYPENAME |
b88c08b6 | 2118 | && yychar != CV_QUALIFIER |
a80e4195 | 2119 | && yychar != SELFNAME) |
00595019 | 2120 | || end_of_file) |
8d08fdba MS |
2121 | { |
2122 | if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) | |
8251199e | 2123 | error ("semicolon missing after %s declaration", |
8d08fdba MS |
2124 | TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct"); |
2125 | else | |
8251199e | 2126 | cp_error ("semicolon missing after declaration of `%T'", type); |
8d08fdba MS |
2127 | shadow_tag (build_tree_list (0, type)); |
2128 | } | |
2129 | /* Could probably also hack cases where class { ... } f (); appears. */ | |
2130 | clear_anon_tags (); | |
2131 | } | |
2132 | ||
2133 | void | |
2134 | note_got_semicolon (type) | |
2135 | tree type; | |
2136 | { | |
2137 | if (TREE_CODE_CLASS (TREE_CODE (type)) != 't') | |
2138 | my_friendly_abort (60); | |
7ddedda4 | 2139 | if (CLASS_TYPE_P (type)) |
8d08fdba MS |
2140 | CLASSTYPE_GOT_SEMICOLON (type) = 1; |
2141 | } | |
2142 | ||
2143 | void | |
2144 | note_list_got_semicolon (declspecs) | |
2145 | tree declspecs; | |
2146 | { | |
2147 | tree link; | |
2148 | ||
2149 | for (link = declspecs; link; link = TREE_CHAIN (link)) | |
2150 | { | |
2151 | tree type = TREE_VALUE (link); | |
2152 | if (TREE_CODE_CLASS (TREE_CODE (type)) == 't') | |
2153 | note_got_semicolon (type); | |
2154 | } | |
2155 | clear_anon_tags (); | |
2156 | } | |
2157 | \f | |
1ceb5ff3 JM |
2158 | /* Iff C is a carriage return, warn about it - if appropriate - |
2159 | and return nonzero. */ | |
2160 | static int | |
2161 | whitespace_cr (c) | |
2162 | int c; | |
2163 | { | |
2164 | static int newline_warning = 0; | |
2165 | ||
2166 | if (c == '\r') | |
2167 | { | |
2168 | /* ANSI C says the effects of a carriage return in a source file | |
2169 | are undefined. */ | |
2170 | if (pedantic && !newline_warning) | |
2171 | { | |
2172 | warning ("carriage return in source file"); | |
2173 | warning ("(we only warn about the first carriage return)"); | |
2174 | newline_warning = 1; | |
2175 | } | |
2176 | return 1; | |
2177 | } | |
2178 | return 0; | |
2179 | } | |
2180 | ||
8d08fdba MS |
2181 | /* If C is not whitespace, return C. |
2182 | Otherwise skip whitespace and return first nonwhite char read. */ | |
2183 | ||
2184 | static int | |
2185 | skip_white_space (c) | |
2186 | register int c; | |
2187 | { | |
2188 | for (;;) | |
2189 | { | |
2190 | switch (c) | |
2191 | { | |
1ceb5ff3 JM |
2192 | /* We don't recognize comments here, because |
2193 | cpp output can include / and * consecutively as operators. | |
2194 | Also, there's no need, since cpp removes all comments. */ | |
2195 | ||
8d08fdba | 2196 | case '\n': |
66a6250f JM |
2197 | if (linemode) |
2198 | { | |
2199 | put_back (c); | |
2200 | return EOF; | |
2201 | } | |
8d08fdba MS |
2202 | c = check_newline (); |
2203 | break; | |
2204 | ||
2205 | case ' ': | |
2206 | case '\t': | |
2207 | case '\f': | |
8d08fdba MS |
2208 | case '\v': |
2209 | case '\b': | |
66a6250f JM |
2210 | #if USE_CPPLIB |
2211 | /* While processing a # directive we don't get CPP_HSPACE | |
2212 | tokens, so we also need to handle whitespace the normal way. */ | |
2213 | if (cpp_token == CPP_HSPACE) | |
2214 | c = yy_get_token (); | |
2215 | else | |
2216 | #endif | |
8d08fdba | 2217 | c = getch (); |
8d08fdba MS |
2218 | break; |
2219 | ||
1ceb5ff3 JM |
2220 | case '\r': |
2221 | whitespace_cr (c); | |
2222 | c = getch (); | |
2223 | break; | |
2224 | ||
8d08fdba MS |
2225 | case '\\': |
2226 | c = getch (); | |
2227 | if (c == '\n') | |
2228 | lineno++; | |
2229 | else | |
8251199e | 2230 | error ("stray '\\' in program"); |
8d08fdba MS |
2231 | c = getch (); |
2232 | break; | |
2233 | ||
2234 | default: | |
2235 | return (c); | |
2236 | } | |
2237 | } | |
2238 | } | |
2239 | ||
8d08fdba MS |
2240 | /* Make the token buffer longer, preserving the data in it. |
2241 | P should point to just beyond the last valid character in the old buffer. | |
2242 | The value we return is a pointer to the new buffer | |
2243 | at a place corresponding to P. */ | |
2244 | ||
66a6250f JM |
2245 | static void |
2246 | extend_token_buffer_to (size) | |
2247 | int size; | |
2248 | { | |
2249 | do | |
2250 | maxtoken = maxtoken * 2 + 10; | |
2251 | while (maxtoken < size); | |
2252 | token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2); | |
2253 | } | |
2254 | ||
8d08fdba MS |
2255 | static char * |
2256 | extend_token_buffer (p) | |
d8e178a0 | 2257 | const char *p; |
8d08fdba MS |
2258 | { |
2259 | int offset = p - token_buffer; | |
66a6250f | 2260 | extend_token_buffer_to (offset); |
8d08fdba MS |
2261 | return token_buffer + offset; |
2262 | } | |
2263 | \f | |
1ceb5ff3 JM |
2264 | #if defined HANDLE_PRAGMA |
2265 | /* Local versions of these macros, that can be passed as function pointers. */ | |
2266 | static int | |
2267 | pragma_getc () | |
2268 | { | |
2269 | return getch (); | |
2270 | } | |
2271 | ||
2272 | static void | |
2273 | pragma_ungetc (arg) | |
2274 | int arg; | |
2275 | { | |
2276 | put_back (arg); | |
2277 | } | |
2278 | #endif | |
2279 | ||
8d08fdba | 2280 | static int |
66a6250f JM |
2281 | read_line_number (num) |
2282 | int *num; | |
8d08fdba | 2283 | { |
66a6250f | 2284 | register int token = real_yylex (); |
8d08fdba | 2285 | |
66a6250f JM |
2286 | if (token == CONSTANT |
2287 | && TREE_CODE (yylval.ttype) == INTEGER_CST) | |
ae4d12ca | 2288 | { |
66a6250f JM |
2289 | *num = TREE_INT_CST_LOW (yylval.ttype); |
2290 | return 1; | |
ae4d12ca NC |
2291 | } |
2292 | else | |
66a6250f JM |
2293 | { |
2294 | if (token != END_OF_LINE) | |
2295 | error ("invalid #-line"); | |
2296 | return 0; | |
2297 | } | |
ae4d12ca | 2298 | } |
ae4d12ca | 2299 | |
8d08fdba MS |
2300 | /* At the beginning of a line, increment the line number |
2301 | and process any #-directive on this line. | |
2302 | If the line is a #-directive, read the entire line and return a newline. | |
66a6250f | 2303 | Otherwise, return the line's first non-whitespace character. |
8d08fdba | 2304 | |
66a6250f JM |
2305 | Note that in the case of USE_CPPLIB, we get the whole line as one |
2306 | CPP_DIRECTIVE token. */ | |
d18c083e | 2307 | |
bd6dd845 | 2308 | static int |
8d08fdba MS |
2309 | check_newline () |
2310 | { | |
2311 | register int c; | |
2312 | register int token; | |
66a6250f JM |
2313 | int saw_line; |
2314 | enum { act_none, act_push, act_pop } action; | |
2315 | int old_lineno, action_number, l; | |
66a6250f | 2316 | int entering_c_header; |
8d08fdba | 2317 | |
66a6250f | 2318 | restart: |
a28e3c7f MS |
2319 | /* Read first nonwhite char on the line. Do this before incrementing the |
2320 | line number, in case we're at the end of saved text. */ | |
8d08fdba | 2321 | |
66a6250f JM |
2322 | #ifdef USE_CPPLIB |
2323 | c = getch (); | |
2324 | /* In some cases where we're leaving an include file, we can get multiple | |
2325 | CPP_HSPACE tokens in a row, so we need to loop. */ | |
2326 | while (cpp_token == CPP_HSPACE) | |
2327 | c = yy_get_token (); | |
2328 | #else | |
8d08fdba MS |
2329 | do |
2330 | c = getch (); | |
2331 | while (c == ' ' || c == '\t'); | |
66a6250f | 2332 | #endif |
8d08fdba | 2333 | |
a28e3c7f MS |
2334 | lineno++; |
2335 | ||
8d08fdba MS |
2336 | if (c != '#') |
2337 | { | |
66a6250f JM |
2338 | /* Sequences of multiple newlines are very common; optimize them. */ |
2339 | if (c == '\n') | |
2340 | goto restart; | |
2341 | ||
8d08fdba MS |
2342 | /* If not #, return it so caller will use it. */ |
2343 | return c; | |
2344 | } | |
2345 | ||
d18c083e | 2346 | /* Don't read beyond this line. */ |
66a6250f | 2347 | saw_line = 0; |
d18c083e MS |
2348 | linemode = 1; |
2349 | ||
66a6250f JM |
2350 | #if USE_CPPLIB |
2351 | if (cpp_token == CPP_VSPACE) | |
2352 | { | |
2353 | /* Format is "<space> <line number> <filename> <newline>". | |
2354 | Only the line number is interesting, and even that | |
2355 | we can get more efficiently than scanning the line. */ | |
2356 | yy_cur = yy_lim - 1; | |
2357 | lineno = parse_in.lineno - 1; | |
2358 | goto skipline; | |
2359 | } | |
2360 | #endif | |
8d08fdba | 2361 | |
66a6250f | 2362 | token = real_yylex (); |
8d08fdba | 2363 | |
66a6250f | 2364 | if (token == IDENTIFIER) |
8d08fdba | 2365 | { |
66a6250f JM |
2366 | /* If a letter follows, then if the word here is `line', skip |
2367 | it and ignore it; otherwise, ignore the line, with an error | |
2368 | if the word isn't `pragma'. */ | |
2369 | ||
2370 | const char *name = IDENTIFIER_POINTER (yylval.ttype); | |
2371 | ||
2372 | if (!strcmp (name, "pragma")) | |
8d08fdba | 2373 | { |
66a6250f | 2374 | token = real_yylex (); |
1ceb5ff3 JM |
2375 | if (token != IDENTIFIER |
2376 | || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE) | |
2377 | goto skipline; | |
2378 | ||
2379 | /* If this is 1, we handled it; if it's -1, it was one we | |
2380 | wanted but had something wrong with it. Only if it's | |
2381 | 0 was it not handled. */ | |
2382 | if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype))) | |
66a6250f | 2383 | goto skipline; |
51c184be | 2384 | |
ae4d12ca | 2385 | #ifdef HANDLE_PRAGMA |
66a6250f JM |
2386 | /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS |
2387 | (if both are defined), in order to give the back | |
2388 | end a chance to override the interpretation of | |
2389 | SYSV style pragmas. */ | |
1ceb5ff3 | 2390 | if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc, |
66a6250f JM |
2391 | IDENTIFIER_POINTER (yylval.ttype))) |
2392 | goto skipline; | |
ae4d12ca NC |
2393 | #endif /* HANDLE_PRAGMA */ |
2394 | ||
a09a009c | 2395 | #ifdef HANDLE_GENERIC_PRAGMAS |
66a6250f JM |
2396 | if (handle_generic_pragma (token)) |
2397 | goto skipline; | |
a09a009c | 2398 | #endif /* HANDLE_GENERIC_PRAGMAS */ |
ae4d12ca | 2399 | |
66a6250f JM |
2400 | /* Issue a warning message if we have been asked to do so. |
2401 | Ignoring unknown pragmas in system header file unless | |
2402 | an explcit -Wunknown-pragmas has been given. */ | |
2403 | if (warn_unknown_pragmas > 1 | |
2404 | || (warn_unknown_pragmas && ! in_system_header)) | |
2405 | warning ("ignoring pragma: %s", token_buffer); | |
2406 | ||
a82e1b55 | 2407 | goto skipline; |
8d08fdba | 2408 | } |
66a6250f | 2409 | else if (!strcmp (name, "define")) |
8d08fdba | 2410 | { |
66a6250f JM |
2411 | debug_define (lineno, GET_DIRECTIVE_LINE ()); |
2412 | goto skipline; | |
8d08fdba | 2413 | } |
66a6250f | 2414 | else if (!strcmp (name, "undef")) |
8d08fdba | 2415 | { |
66a6250f JM |
2416 | debug_undef (lineno, GET_DIRECTIVE_LINE ()); |
2417 | goto skipline; | |
8d08fdba | 2418 | } |
66a6250f | 2419 | else if (!strcmp (name, "line")) |
8d08fdba | 2420 | { |
66a6250f JM |
2421 | saw_line = 1; |
2422 | token = real_yylex (); | |
2423 | goto linenum; | |
8d08fdba | 2424 | } |
66a6250f | 2425 | else if (!strcmp (name, "ident")) |
8d08fdba | 2426 | { |
66a6250f | 2427 | /* #ident. The pedantic warning is now in cccp.c. */ |
8d08fdba | 2428 | |
66a6250f JM |
2429 | /* Here we have just seen `#ident '. |
2430 | A string constant should follow. */ | |
8d08fdba | 2431 | |
66a6250f JM |
2432 | token = real_yylex (); |
2433 | if (token == END_OF_LINE) | |
2434 | goto skipline; | |
2435 | if (token != STRING | |
2436 | || TREE_CODE (yylval.ttype) != STRING_CST) | |
2437 | { | |
2438 | error ("invalid #ident"); | |
8d08fdba MS |
2439 | goto skipline; |
2440 | } | |
66a6250f JM |
2441 | |
2442 | if (! flag_no_ident) | |
8d08fdba | 2443 | { |
66a6250f JM |
2444 | #ifdef ASM_OUTPUT_IDENT |
2445 | ASM_OUTPUT_IDENT (asm_out_file, | |
2446 | TREE_STRING_POINTER (yylval.ttype)); | |
2447 | #endif | |
8d08fdba | 2448 | } |
66a6250f JM |
2449 | |
2450 | /* Skip the rest of this line. */ | |
2451 | goto skipline; | |
8d08fdba | 2452 | } |
66a6250f JM |
2453 | |
2454 | error ("undefined or invalid # directive `%s'", name); | |
8d08fdba MS |
2455 | goto skipline; |
2456 | } | |
2457 | ||
8d08fdba MS |
2458 | /* If the # is the only nonwhite char on the line, |
2459 | just ignore it. Check the new newline. */ | |
66a6250f | 2460 | if (token == END_OF_LINE) |
d18c083e | 2461 | goto skipline; |
8d08fdba | 2462 | |
66a6250f JM |
2463 | linenum: |
2464 | /* Here we have either `#line' or `# <nonletter>'. | |
2465 | In either case, it should be a line number; a digit should follow. */ | |
8d08fdba | 2466 | |
66a6250f JM |
2467 | if (token != CONSTANT |
2468 | || TREE_CODE (yylval.ttype) != INTEGER_CST) | |
8d08fdba | 2469 | { |
66a6250f JM |
2470 | error ("invalid #-line"); |
2471 | goto skipline; | |
2472 | } | |
8d08fdba | 2473 | |
66a6250f JM |
2474 | /* subtract one, because it is the following line that |
2475 | gets the specified number */ | |
8d08fdba | 2476 | |
66a6250f | 2477 | l = TREE_INT_CST_LOW (yylval.ttype) - 1; |
8d08fdba | 2478 | |
66a6250f JM |
2479 | /* More follows: it must be a string constant (filename). |
2480 | It would be neat to use cpplib to quickly process the string, but | |
2481 | (1) we don't have a handy tokenization of the string, and | |
2482 | (2) I don't know how well that would work in the presense | |
2483 | of filenames that contain wide characters. */ | |
8d08fdba | 2484 | |
66a6250f JM |
2485 | if (saw_line) |
2486 | { | |
2487 | /* Don't treat \ as special if we are processing #line 1 "...". | |
2488 | If you want it to be treated specially, use # 1 "...". */ | |
2489 | ignore_escape_flag = 1; | |
2490 | } | |
069f7cf2 | 2491 | |
66a6250f JM |
2492 | /* Read the string constant. */ |
2493 | token = real_yylex (); | |
069f7cf2 | 2494 | |
66a6250f | 2495 | ignore_escape_flag = 0; |
8d08fdba | 2496 | |
66a6250f JM |
2497 | if (token == END_OF_LINE) |
2498 | { | |
2499 | /* No more: store the line number and check following line. */ | |
2500 | lineno = l; | |
2501 | goto skipline; | |
2502 | } | |
8d08fdba | 2503 | |
66a6250f JM |
2504 | if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) |
2505 | { | |
2506 | error ("invalid #line"); | |
2507 | goto skipline; | |
2508 | } | |
8d08fdba | 2509 | |
66a6250f JM |
2510 | /* Changing files again. This means currently collected time |
2511 | is charged against header time, and body time starts back at 0. */ | |
2512 | if (flag_detailed_statistics) | |
2513 | { | |
2514 | int this_time = my_get_run_time (); | |
2515 | tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype)); | |
2516 | header_time += this_time - body_time; | |
2517 | TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time)) | |
2518 | += this_time - body_time; | |
2519 | this_filename_time = time_identifier; | |
2520 | body_time = this_time; | |
2521 | } | |
2522 | ||
2523 | if (!TREE_PERMANENT (yylval.ttype)) | |
2524 | { | |
8d08fdba MS |
2525 | input_filename |
2526 | = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1); | |
2527 | strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype)); | |
66a6250f JM |
2528 | } |
2529 | else | |
2530 | input_filename = TREE_STRING_POINTER (yylval.ttype); | |
8d08fdba | 2531 | |
66a6250f JM |
2532 | GNU_xref_file (input_filename); |
2533 | ||
2534 | if (main_input_filename == 0) | |
2535 | { | |
2536 | struct impl_files *ifiles = impl_file_chain; | |
8d08fdba | 2537 | |
66a6250f | 2538 | if (ifiles) |
28cbf42c | 2539 | { |
66a6250f JM |
2540 | while (ifiles->next) |
2541 | ifiles = ifiles->next; | |
2542 | ifiles->filename = file_name_nondirectory (input_filename); | |
28cbf42c | 2543 | } |
8d08fdba | 2544 | |
66a6250f JM |
2545 | main_input_filename = input_filename; |
2546 | } | |
8d08fdba | 2547 | |
66a6250f | 2548 | extract_interface_info (); |
8d08fdba | 2549 | |
66a6250f | 2550 | old_lineno = lineno; |
66a6250f JM |
2551 | action = act_none; |
2552 | action_number = 0; | |
2553 | lineno = l; | |
8d08fdba | 2554 | |
1ceb5ff3 JM |
2555 | /* Each change of file name |
2556 | reinitializes whether we are now in a system header. */ | |
2557 | in_system_header = 0; | |
2558 | entering_c_header = 0; | |
2559 | ||
66a6250f JM |
2560 | if (!read_line_number (&action_number)) |
2561 | { | |
2562 | /* Update the name in the top element of input_file_stack. */ | |
2563 | if (input_file_stack) | |
2564 | input_file_stack->name = input_filename; | |
2565 | } | |
8d08fdba | 2566 | |
66a6250f JM |
2567 | /* `1' after file name means entering new file. |
2568 | `2' after file name means just left a file. */ | |
8d08fdba | 2569 | |
66a6250f JM |
2570 | if (action_number == 1) |
2571 | { | |
2572 | action = act_push; | |
2573 | read_line_number (&action_number); | |
2574 | } | |
2575 | else if (action_number == 2) | |
2576 | { | |
2577 | action = act_pop; | |
2578 | read_line_number (&action_number); | |
2579 | } | |
2580 | if (action_number == 3) | |
2581 | { | |
2582 | /* `3' after file name means this is a system header file. */ | |
1ceb5ff3 | 2583 | in_system_header = 1; |
66a6250f JM |
2584 | read_line_number (&action_number); |
2585 | } | |
2586 | if (action_number == 4) | |
2587 | { | |
2588 | /* `4' after file name means this is a C header file. */ | |
2589 | entering_c_header = 1; | |
2590 | read_line_number (&action_number); | |
2591 | } | |
8d08fdba | 2592 | |
66a6250f | 2593 | /* Do the actions implied by the preceding numbers. */ |
8d08fdba | 2594 | |
66a6250f JM |
2595 | if (action == act_push) |
2596 | { | |
2597 | /* Pushing to a new file. */ | |
1ceb5ff3 JM |
2598 | struct file_stack *p |
2599 | = (struct file_stack *) xmalloc (sizeof (struct file_stack)); | |
66a6250f JM |
2600 | input_file_stack->line = old_lineno; |
2601 | p->next = input_file_stack; | |
2602 | p->name = input_filename; | |
2603 | p->indent_level = indent_level; | |
2604 | input_file_stack = p; | |
2605 | input_file_stack_tick++; | |
2606 | debug_start_source_file (input_filename); | |
66a6250f JM |
2607 | if (c_header_level) |
2608 | ++c_header_level; | |
2609 | else if (entering_c_header) | |
2610 | { | |
2611 | c_header_level = 1; | |
2612 | ++pending_lang_change; | |
2613 | } | |
2614 | } | |
2615 | else if (action == act_pop) | |
2616 | { | |
2617 | /* Popping out of a file. */ | |
2618 | if (input_file_stack->next) | |
2619 | { | |
1ceb5ff3 | 2620 | struct file_stack *p = input_file_stack; |
8d08fdba | 2621 | |
66a6250f | 2622 | if (c_header_level && --c_header_level == 0) |
8d08fdba | 2623 | { |
66a6250f JM |
2624 | if (entering_c_header) |
2625 | warning ("badly nested C headers from preprocessor"); | |
2626 | --pending_lang_change; | |
8d08fdba MS |
2627 | } |
2628 | ||
66a6250f | 2629 | if (indent_level != p->indent_level) |
8d08fdba | 2630 | { |
66a6250f JM |
2631 | warning_with_file_and_line |
2632 | (p->name, old_lineno, | |
2633 | "This file contains more `%c's than `%c's.", | |
2634 | indent_level > p->indent_level ? '{' : '}', | |
2635 | indent_level > p->indent_level ? '}' : '{'); | |
8d08fdba | 2636 | } |
66a6250f JM |
2637 | input_file_stack = p->next; |
2638 | free (p); | |
2639 | input_file_stack_tick++; | |
2640 | debug_end_source_file (input_file_stack->line); | |
8d08fdba | 2641 | } |
66a6250f JM |
2642 | else |
2643 | error ("#-lines for entering and leaving files don't match"); | |
8d08fdba | 2644 | } |
1ceb5ff3 JM |
2645 | |
2646 | /* Now that we've pushed or popped the input stack, | |
2647 | update the name in the top element. */ | |
2648 | if (input_file_stack) | |
2649 | input_file_stack->name = input_filename; | |
8d08fdba MS |
2650 | |
2651 | /* skip the rest of this line. */ | |
2652 | skipline: | |
d18c083e MS |
2653 | linemode = 0; |
2654 | end_of_file = 0; | |
66a6250f | 2655 | |
1ceb5ff3 JM |
2656 | do |
2657 | c = getch (); | |
2658 | while (c != '\n' && c != EOF); | |
8d08fdba MS |
2659 | return c; |
2660 | } | |
1ceb5ff3 JM |
2661 | \f |
2662 | #ifdef HANDLE_GENERIC_PRAGMAS | |
2663 | ||
2664 | /* Handle a #pragma directive. | |
2665 | TOKEN is the token we read after `#pragma'. Processes the entire input | |
2666 | line and return non-zero iff the pragma has been successfully parsed. */ | |
2667 | ||
2668 | /* This function has to be in this file, in order to get at | |
2669 | the token types. */ | |
2670 | ||
2671 | static int | |
2672 | handle_generic_pragma (token) | |
2673 | register int token; | |
2674 | { | |
2675 | for (;;) | |
2676 | { | |
2677 | switch (token) | |
2678 | { | |
2679 | case IDENTIFIER: | |
2680 | case TYPENAME: | |
2681 | case STRING: | |
2682 | case CONSTANT: | |
2683 | handle_pragma_token (token_buffer, yylval.ttype); | |
2684 | break; | |
2685 | ||
2686 | case LEFT_RIGHT: | |
2687 | handle_pragma_token ("(", NULL_TREE); | |
2688 | handle_pragma_token (")", NULL_TREE); | |
2689 | break; | |
2690 | ||
2691 | case END_OF_LINE: | |
2692 | return handle_pragma_token (NULL_PTR, NULL_TREE); | |
2693 | ||
2694 | default: | |
2695 | handle_pragma_token (token_buffer, NULL_TREE); | |
2696 | } | |
2697 | ||
2698 | token = real_yylex (); | |
2699 | } | |
2700 | } | |
2701 | #endif /* HANDLE_GENERIC_PRAGMAS */ | |
2702 | ||
2703 | static int | |
2704 | handle_cp_pragma (pname) | |
2705 | const char *pname; | |
2706 | { | |
2707 | register int token; | |
2708 | ||
2709 | if (! strcmp (pname, "vtable")) | |
2710 | { | |
2711 | extern tree pending_vtables; | |
2712 | ||
2713 | /* More follows: it must be a string constant (class name). */ | |
2714 | token = real_yylex (); | |
2715 | if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) | |
2716 | { | |
2717 | error ("invalid #pragma vtable"); | |
2718 | return -1; | |
2719 | } | |
2720 | ||
2721 | pending_vtables | |
2722 | = perm_tree_cons (NULL_TREE, | |
2723 | get_identifier (TREE_STRING_POINTER (yylval.ttype)), | |
2724 | pending_vtables); | |
2725 | token = real_yylex (); | |
2726 | if (token != END_OF_LINE) | |
2727 | warning ("trailing characters ignored"); | |
2728 | return 1; | |
2729 | } | |
2730 | else if (! strcmp (pname, "unit")) | |
2731 | { | |
2732 | /* More follows: it must be a string constant (unit name). */ | |
2733 | token = real_yylex (); | |
2734 | if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) | |
2735 | { | |
2736 | error ("invalid #pragma unit"); | |
2737 | return -1; | |
2738 | } | |
2739 | token = real_yylex (); | |
2740 | if (token != END_OF_LINE) | |
2741 | warning ("trailing characters ignored"); | |
2742 | return 1; | |
2743 | } | |
2744 | else if (! strcmp (pname, "interface")) | |
2745 | { | |
2746 | char *main_filename = input_filename; | |
2747 | ||
2748 | main_filename = file_name_nondirectory (main_filename); | |
2749 | ||
2750 | token = real_yylex (); | |
2751 | ||
2752 | if (token != END_OF_LINE) | |
2753 | { | |
2754 | if (token != STRING | |
2755 | || TREE_CODE (yylval.ttype) != STRING_CST) | |
2756 | { | |
2757 | error ("invalid `#pragma interface'"); | |
2758 | return -1; | |
2759 | } | |
2760 | main_filename = TREE_STRING_POINTER (yylval.ttype); | |
2761 | token = real_yylex (); | |
2762 | } | |
2763 | ||
2764 | if (token != END_OF_LINE) | |
2765 | warning ("garbage after `#pragma interface' ignored"); | |
2766 | ||
2767 | cp_pragma_interface (main_filename); | |
2768 | ||
2769 | return 1; | |
2770 | } | |
2771 | else if (! strcmp (pname, "implementation")) | |
2772 | { | |
2773 | char *main_filename = main_input_filename ? main_input_filename : input_filename; | |
2774 | ||
2775 | main_filename = file_name_nondirectory (main_filename); | |
2776 | ||
2777 | token = real_yylex (); | |
2778 | ||
2779 | if (token != END_OF_LINE) | |
2780 | { | |
2781 | if (token != STRING | |
2782 | || TREE_CODE (yylval.ttype) != STRING_CST) | |
2783 | { | |
2784 | error ("invalid `#pragma implementation'"); | |
2785 | return -1; | |
2786 | } | |
2787 | main_filename = TREE_STRING_POINTER (yylval.ttype); | |
2788 | token = real_yylex (); | |
2789 | } | |
2790 | ||
2791 | if (token != END_OF_LINE) | |
2792 | warning ("garbage after `#pragma implementation' ignored"); | |
2793 | ||
2794 | cp_pragma_implementation (main_filename); | |
8d08fdba | 2795 | |
1ceb5ff3 JM |
2796 | return 1; |
2797 | } | |
2798 | ||
2799 | return 0; | |
2800 | } | |
2801 | \f | |
8d08fdba MS |
2802 | void |
2803 | do_pending_lang_change () | |
2804 | { | |
2805 | for (; pending_lang_change > 0; --pending_lang_change) | |
2806 | push_lang_context (lang_name_c); | |
2807 | for (; pending_lang_change < 0; ++pending_lang_change) | |
2808 | pop_lang_context (); | |
2809 | } | |
2810 | \f | |
8d08fdba MS |
2811 | #define ENDFILE -1 /* token that represents end-of-file */ |
2812 | ||
2813 | /* Read an escape sequence, returning its equivalent as a character, | |
2814 | or store 1 in *ignore_ptr if it is backslash-newline. */ | |
2815 | ||
2816 | static int | |
2817 | readescape (ignore_ptr) | |
2818 | int *ignore_ptr; | |
2819 | { | |
2820 | register int c = getch (); | |
2821 | register int code; | |
2822 | register unsigned count; | |
a703fb38 | 2823 | unsigned firstdig = 0; |
8d08fdba MS |
2824 | int nonnull; |
2825 | ||
2826 | switch (c) | |
2827 | { | |
2828 | case 'x': | |
8d08fdba MS |
2829 | code = 0; |
2830 | count = 0; | |
2831 | nonnull = 0; | |
2832 | while (1) | |
2833 | { | |
2834 | c = getch (); | |
faa25e97 | 2835 | if (! ISXDIGIT (c)) |
8d08fdba MS |
2836 | { |
2837 | put_back (c); | |
2838 | break; | |
2839 | } | |
2840 | code *= 16; | |
2841 | if (c >= 'a' && c <= 'f') | |
2842 | code += c - 'a' + 10; | |
2843 | if (c >= 'A' && c <= 'F') | |
2844 | code += c - 'A' + 10; | |
2845 | if (c >= '0' && c <= '9') | |
2846 | code += c - '0'; | |
2847 | if (code != 0 || count != 0) | |
2848 | { | |
2849 | if (count == 0) | |
2850 | firstdig = code; | |
2851 | count++; | |
2852 | } | |
2853 | nonnull = 1; | |
2854 | } | |
2855 | if (! nonnull) | |
8251199e | 2856 | error ("\\x used with no following hex digits"); |
8d08fdba MS |
2857 | else if (count == 0) |
2858 | /* Digits are all 0's. Ok. */ | |
2859 | ; | |
2860 | else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node) | |
2861 | || (count > 1 | |
1ceb5ff3 JM |
2862 | && (((unsigned)1 |
2863 | << (TYPE_PRECISION (integer_type_node) | |
2864 | - (count - 1) * 4)) | |
8d08fdba | 2865 | <= firstdig))) |
8251199e | 2866 | pedwarn ("hex escape out of range"); |
8d08fdba MS |
2867 | return code; |
2868 | ||
2869 | case '0': case '1': case '2': case '3': case '4': | |
2870 | case '5': case '6': case '7': | |
2871 | code = 0; | |
2872 | count = 0; | |
2873 | while ((c <= '7') && (c >= '0') && (count++ < 3)) | |
2874 | { | |
2875 | code = (code * 8) + (c - '0'); | |
2876 | c = getch (); | |
2877 | } | |
2878 | put_back (c); | |
2879 | return code; | |
2880 | ||
2881 | case '\\': case '\'': case '"': | |
2882 | return c; | |
2883 | ||
2884 | case '\n': | |
2885 | lineno++; | |
2886 | *ignore_ptr = 1; | |
2887 | return 0; | |
2888 | ||
2889 | case 'n': | |
2890 | return TARGET_NEWLINE; | |
2891 | ||
2892 | case 't': | |
2893 | return TARGET_TAB; | |
2894 | ||
2895 | case 'r': | |
2896 | return TARGET_CR; | |
2897 | ||
2898 | case 'f': | |
2899 | return TARGET_FF; | |
2900 | ||
2901 | case 'b': | |
2902 | return TARGET_BS; | |
2903 | ||
2904 | case 'a': | |
8d08fdba MS |
2905 | return TARGET_BELL; |
2906 | ||
2907 | case 'v': | |
2908 | return TARGET_VT; | |
2909 | ||
2910 | case 'e': | |
2911 | case 'E': | |
2912 | if (pedantic) | |
8251199e | 2913 | pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c); |
8d08fdba MS |
2914 | return 033; |
2915 | ||
2916 | case '?': | |
2917 | return c; | |
2918 | ||
2919 | /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */ | |
2920 | case '(': | |
2921 | case '{': | |
2922 | case '[': | |
2923 | /* `\%' is used to prevent SCCS from getting confused. */ | |
2924 | case '%': | |
2925 | if (pedantic) | |
8251199e | 2926 | pedwarn ("unknown escape sequence `\\%c'", c); |
8d08fdba MS |
2927 | return c; |
2928 | } | |
83f660b7 | 2929 | if (ISGRAPH (c)) |
8251199e | 2930 | pedwarn ("unknown escape sequence `\\%c'", c); |
8d08fdba | 2931 | else |
8251199e | 2932 | pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c); |
8d08fdba MS |
2933 | return c; |
2934 | } | |
1ceb5ff3 JM |
2935 | \f |
2936 | void | |
2937 | yyerror (string) | |
2938 | const char *string; | |
2939 | { | |
2940 | extern int end_of_file; | |
2941 | char buf[200]; | |
2942 | ||
2943 | strcpy (buf, string); | |
2944 | ||
2945 | /* We can't print string and character constants well | |
2946 | because the token_buffer contains the result of processing escapes. */ | |
2947 | if (end_of_file) | |
2948 | strcat (buf, input_redirected () | |
2949 | ? " at end of saved text" | |
2950 | : " at end of input"); | |
2951 | else if (token_buffer[0] == 0) | |
2952 | strcat (buf, " at null character"); | |
2953 | else if (token_buffer[0] == '"') | |
2954 | strcat (buf, " before string constant"); | |
2955 | else if (token_buffer[0] == '\'') | |
2956 | strcat (buf, " before character constant"); | |
2957 | else if (!ISGRAPH ((unsigned char)token_buffer[0])) | |
2958 | sprintf (buf + strlen (buf), " before character 0%o", | |
2959 | (unsigned char) token_buffer[0]); | |
2960 | else | |
2961 | strcat (buf, " before `%s'"); | |
8d08fdba | 2962 | |
1ceb5ff3 JM |
2963 | error (buf, token_buffer); |
2964 | } | |
2965 | \f | |
a28e3c7f MS |
2966 | /* Value is 1 (or 2) if we should try to make the next identifier look like |
2967 | a typename (when it may be a local variable or a class variable). | |
2968 | Value is 0 if we treat this name in a default fashion. */ | |
00dc6358 | 2969 | int looking_for_typename; |
8d08fdba | 2970 | |
8d08fdba | 2971 | #ifdef __GNUC__ |
8d08fdba MS |
2972 | __inline |
2973 | #endif | |
2974 | int | |
2975 | identifier_type (decl) | |
2976 | tree decl; | |
2977 | { | |
830fcda8 | 2978 | tree t; |
5566b478 MS |
2979 | if (TREE_CODE (decl) == TEMPLATE_DECL) |
2980 | { | |
2981 | if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL) | |
2982 | return PTYPENAME; | |
386b8a85 JM |
2983 | else if (looking_for_template) |
2984 | return PFUNCNAME; | |
2985 | } | |
2986 | if (looking_for_template && really_overloaded_fn (decl)) | |
2987 | { | |
161c12b0 JM |
2988 | /* See through a baselink. */ |
2989 | if (TREE_CODE (decl) == TREE_LIST) | |
2990 | decl = TREE_VALUE (decl); | |
2991 | ||
2c73f9f5 ML |
2992 | for (t = decl; t != NULL_TREE; t = OVL_CHAIN (t)) |
2993 | if (DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (t))) | |
386b8a85 | 2994 | return PFUNCNAME; |
5566b478 | 2995 | } |
a9aedbc2 MS |
2996 | if (TREE_CODE (decl) == NAMESPACE_DECL) |
2997 | return NSNAME; | |
8d08fdba MS |
2998 | if (TREE_CODE (decl) != TYPE_DECL) |
2999 | return IDENTIFIER; | |
830fcda8 JM |
3000 | if (DECL_ARTIFICIAL (decl) && TREE_TYPE (decl) == current_class_type) |
3001 | return SELFNAME; | |
3002 | ||
3003 | /* A constructor declarator for a template type will get here as an | |
3004 | implicit typename, a TYPENAME_TYPE with a type. */ | |
3005 | t = got_scope; | |
3006 | if (t && TREE_CODE (t) == TYPENAME_TYPE) | |
3007 | t = TREE_TYPE (t); | |
3008 | decl = TREE_TYPE (decl); | |
3009 | if (TREE_CODE (decl) == TYPENAME_TYPE) | |
3010 | decl = TREE_TYPE (decl); | |
3011 | if (t && t == decl) | |
a80e4195 | 3012 | return SELFNAME; |
830fcda8 | 3013 | |
8d08fdba MS |
3014 | return TYPENAME; |
3015 | } | |
3016 | ||
3017 | void | |
3018 | see_typename () | |
3019 | { | |
2c73f9f5 ML |
3020 | /* Only types expected, not even namespaces. */ |
3021 | looking_for_typename = 2; | |
f30432d7 | 3022 | if (yychar < 0) |
fc378698 | 3023 | if ((yychar = yylex ()) < 0) yychar = 0; |
8d08fdba MS |
3024 | looking_for_typename = 0; |
3025 | if (yychar == IDENTIFIER) | |
3026 | { | |
a28e3c7f | 3027 | lastiddecl = lookup_name (yylval.ttype, -2); |
8d08fdba MS |
3028 | if (lastiddecl == 0) |
3029 | { | |
3030 | if (flag_labels_ok) | |
3031 | lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype); | |
3032 | } | |
3033 | else | |
3034 | yychar = identifier_type (lastiddecl); | |
3035 | } | |
3036 | } | |
3037 | ||
a759e627 ML |
3038 | /* Return true if d is in a global scope. */ |
3039 | ||
3040 | static int | |
3041 | is_global (d) | |
3042 | tree d; | |
3043 | { | |
3044 | while (1) | |
3045 | switch (TREE_CODE (d)) | |
3046 | { | |
01240200 MM |
3047 | case ERROR_MARK: |
3048 | return 1; | |
3049 | ||
a759e627 ML |
3050 | case OVERLOAD: d = OVL_FUNCTION (d); continue; |
3051 | case TREE_LIST: d = TREE_VALUE (d); continue; | |
3052 | default: | |
3053 | my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (d)) == 'd', 980629); | |
8bcc97de MM |
3054 | |
3055 | /* A template parameter is not really global, even though it | |
3056 | has no enclosing scope. */ | |
3057 | if (DECL_TEMPLATE_PARM_P (d)) | |
3058 | return 0; | |
3059 | ||
a759e627 ML |
3060 | d = CP_DECL_CONTEXT (d); |
3061 | return TREE_CODE (d) == NAMESPACE_DECL; | |
3062 | } | |
3063 | } | |
3064 | ||
8d08fdba | 3065 | tree |
a759e627 | 3066 | do_identifier (token, parsing, args) |
8d08fdba | 3067 | register tree token; |
5566b478 | 3068 | int parsing; |
a759e627 | 3069 | tree args; |
8d08fdba | 3070 | { |
5566b478 | 3071 | register tree id; |
e13a4123 JM |
3072 | int lexing = (parsing == 1); |
3073 | int in_call = (parsing == 2); | |
8d08fdba | 3074 | |
e13a4123 | 3075 | if (! lexing || IDENTIFIER_OPNAME_P (token)) |
72b7eeff | 3076 | id = lookup_name (token, 0); |
5566b478 MS |
3077 | else |
3078 | id = lastiddecl; | |
72b7eeff | 3079 | |
a759e627 | 3080 | /* Do Koenig lookup if appropriate (inside templates we build lookup |
2c169bab JM |
3081 | expressions instead). |
3082 | ||
3083 | [basic.lookup.koenig]: If the ordinary unqualified lookup of the name | |
3084 | finds the declaration of a class member function, the associated | |
3085 | namespaces and classes are not considered. */ | |
3086 | ||
a759e627 | 3087 | if (args && !current_template_parms && (!id || is_global (id))) |
f181d4ae | 3088 | id = lookup_arg_dependent (token, id, args); |
a759e627 | 3089 | |
8d2733ca MS |
3090 | /* Remember that this name has been used in the class definition, as per |
3091 | [class.scope0] */ | |
8f032717 | 3092 | if (id && parsing |
bd6dd845 MS |
3093 | /* Avoid breaking if we get called for a default argument that |
3094 | refers to an overloaded method. Eventually this will not be | |
3095 | necessary, since default arguments shouldn't be parsed until | |
3096 | after the class is complete. (jason 3/12/97) */ | |
2c73f9f5 | 3097 | && TREE_CODE (id) != OVERLOAD) |
8f032717 | 3098 | maybe_note_name_used_in_class (token, id); |
72b7eeff | 3099 | |
5b163de4 JM |
3100 | if (id == error_mark_node) |
3101 | { | |
3102 | /* lookup_name quietly returns error_mark_node if we're parsing, | |
3103 | as we don't want to complain about an identifier that ends up | |
3104 | being used as a declarator. So we call it again to get the error | |
3105 | message. */ | |
3106 | id = lookup_name (token, 0); | |
3107 | return error_mark_node; | |
3108 | } | |
3109 | ||
3110 | if (!id) | |
3111 | { | |
5566b478 | 3112 | if (current_template_parms) |
672476cb | 3113 | return build_min_nt (LOOKUP_EXPR, token); |
5566b478 | 3114 | else if (IDENTIFIER_OPNAME_P (token)) |
72b7eeff MS |
3115 | { |
3116 | if (token != ansi_opname[ERROR_MARK]) | |
8251199e | 3117 | cp_error ("`%D' not defined", token); |
72b7eeff MS |
3118 | id = error_mark_node; |
3119 | } | |
830fcda8 | 3120 | else if (in_call && ! flag_strict_prototype) |
8d08fdba MS |
3121 | { |
3122 | id = implicitly_declare (token); | |
3123 | } | |
3124 | else if (current_function_decl == 0) | |
3125 | { | |
8251199e | 3126 | cp_error ("`%D' was not declared in this scope", token); |
8d08fdba MS |
3127 | id = error_mark_node; |
3128 | } | |
3129 | else | |
3130 | { | |
30394414 | 3131 | if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node |
8d08fdba MS |
3132 | || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl) |
3133 | { | |
3134 | static int undeclared_variable_notice; | |
3135 | ||
8251199e | 3136 | cp_error ("`%D' undeclared (first use this function)", token); |
8d08fdba MS |
3137 | |
3138 | if (! undeclared_variable_notice) | |
3139 | { | |
8251199e JM |
3140 | error ("(Each undeclared identifier is reported only once"); |
3141 | error ("for each function it appears in.)"); | |
8d08fdba MS |
3142 | undeclared_variable_notice = 1; |
3143 | } | |
3144 | } | |
3145 | id = error_mark_node; | |
3146 | /* Prevent repeated error messages. */ | |
2c73f9f5 | 3147 | SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node); |
8d08fdba MS |
3148 | SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl); |
3149 | } | |
3150 | } | |
f3be9e3c PB |
3151 | |
3152 | if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id)) | |
3153 | { | |
3154 | tree shadowed = DECL_SHADOWED_FOR_VAR (id); | |
2ee887f2 MS |
3155 | while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL |
3156 | && DECL_DEAD_FOR_LOCAL (shadowed)) | |
3157 | shadowed = DECL_SHADOWED_FOR_VAR (shadowed); | |
3158 | if (!shadowed) | |
30394414 | 3159 | shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id)); |
f3be9e3c PB |
3160 | if (shadowed) |
3161 | { | |
3162 | if (!DECL_ERROR_REPORTED (id)) | |
3163 | { | |
8251199e | 3164 | warning ("name lookup of `%s' changed", |
f3be9e3c | 3165 | IDENTIFIER_POINTER (token)); |
8251199e | 3166 | cp_warning_at (" matches this `%D' under current ANSI rules", |
f3be9e3c | 3167 | shadowed); |
8251199e | 3168 | cp_warning_at (" matches this `%D' under old rules", id); |
f3be9e3c PB |
3169 | DECL_ERROR_REPORTED (id) = 1; |
3170 | } | |
3171 | id = shadowed; | |
3172 | } | |
3173 | else if (!DECL_ERROR_REPORTED (id)) | |
3174 | { | |
3175 | static char msg[] | |
3176 | = "name lookup of `%s' changed for new ANSI `for' scoping"; | |
3177 | DECL_ERROR_REPORTED (id) = 1; | |
3178 | if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id))) | |
3179 | { | |
3180 | error (msg, IDENTIFIER_POINTER (token)); | |
8251199e | 3181 | cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id); |
f3be9e3c PB |
3182 | id = error_mark_node; |
3183 | } | |
3184 | else | |
3185 | { | |
3186 | pedwarn (msg, IDENTIFIER_POINTER (token)); | |
8251199e | 3187 | cp_pedwarn_at (" using obsolete binding at `%D'", id); |
f3be9e3c PB |
3188 | } |
3189 | } | |
3190 | } | |
8d08fdba MS |
3191 | /* TREE_USED is set in `hack_identifier'. */ |
3192 | if (TREE_CODE (id) == CONST_DECL) | |
3193 | { | |
d6479fe7 | 3194 | /* Check access. */ |
8d08fdba | 3195 | if (IDENTIFIER_CLASS_VALUE (token) == id) |
8084bf81 | 3196 | enforce_access (DECL_REAL_CONTEXT(id), id); |
50714e79 | 3197 | if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id)) |
5566b478 | 3198 | id = DECL_INITIAL (id); |
8d08fdba MS |
3199 | } |
3200 | else | |
5566b478 MS |
3201 | id = hack_identifier (id, token); |
3202 | ||
ed44da02 MM |
3203 | /* We must look up dependent names when the template is |
3204 | instantiated, not while parsing it. For now, we don't | |
3205 | distinguish between dependent and independent names. So, for | |
3206 | example, we look up all overloaded functions at | |
3207 | instantiation-time, even though in some cases we should just use | |
3208 | the DECL we have here. We also use LOOKUP_EXPRs to find things | |
c0a483c7 | 3209 | like local variables, rather than creating TEMPLATE_DECLs for the |
ed44da02 | 3210 | local variables and then finding matching instantiations. */ |
672476cb MM |
3211 | if (current_template_parms |
3212 | && (is_overloaded_fn (id) | |
ed44da02 MM |
3213 | /* If it's not going to be around at instantiation time, we |
3214 | look it up then. This is a hack, and should go when we | |
3215 | really get dependent/independent name lookup right. */ | |
672476cb | 3216 | || !TREE_PERMANENT (id) |
ed44da02 MM |
3217 | /* Some local VAR_DECLs (such as those for local variables |
3218 | in member functions of local classes) are built on the | |
3219 | permanent obstack. */ | |
3220 | || (TREE_CODE (id) == VAR_DECL | |
3221 | && CP_DECL_CONTEXT (id) | |
3222 | && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL) | |
672476cb | 3223 | || TREE_CODE (id) == PARM_DECL |
c6882a35 | 3224 | || TREE_CODE (id) == RESULT_DECL |
672476cb MM |
3225 | || TREE_CODE (id) == USING_DECL)) |
3226 | id = build_min_nt (LOOKUP_EXPR, token); | |
5566b478 MS |
3227 | |
3228 | return id; | |
3229 | } | |
3230 | ||
3231 | tree | |
3232 | do_scoped_id (token, parsing) | |
3233 | tree token; | |
3234 | int parsing; | |
3235 | { | |
30394414 JM |
3236 | tree id; |
3237 | /* during parsing, this is ::name. Otherwise, it is black magic. */ | |
3238 | if (parsing) | |
2c73f9f5 ML |
3239 | { |
3240 | struct tree_binding _b; | |
3241 | id = binding_init (&_b); | |
52c11ef6 | 3242 | if (!qualified_lookup_using_namespace (token, global_namespace, id, 0)) |
2c73f9f5 ML |
3243 | id = NULL_TREE; |
3244 | else | |
3245 | id = BINDING_VALUE (id); | |
3246 | } | |
30394414 JM |
3247 | else |
3248 | id = IDENTIFIER_GLOBAL_VALUE (token); | |
5566b478 MS |
3249 | if (parsing && yychar == YYEMPTY) |
3250 | yychar = yylex (); | |
3251 | if (! id) | |
3252 | { | |
5156628f | 3253 | if (processing_template_decl) |
5566b478 | 3254 | { |
672476cb | 3255 | id = build_min_nt (LOOKUP_EXPR, token); |
5566b478 MS |
3256 | LOOKUP_EXPR_GLOBAL (id) = 1; |
3257 | return id; | |
3258 | } | |
830fcda8 JM |
3259 | if (parsing && (yychar == '(' || yychar == LEFT_RIGHT) |
3260 | && ! flag_strict_prototype) | |
5566b478 MS |
3261 | id = implicitly_declare (token); |
3262 | else | |
3263 | { | |
30394414 | 3264 | if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node) |
8251199e | 3265 | cp_error ("`::%D' undeclared (first use here)", token); |
5566b478 MS |
3266 | id = error_mark_node; |
3267 | /* Prevent repeated error messages. */ | |
2c73f9f5 | 3268 | SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node); |
5566b478 MS |
3269 | } |
3270 | } | |
3271 | else | |
3272 | { | |
3273 | if (TREE_CODE (id) == ADDR_EXPR) | |
3274 | mark_used (TREE_OPERAND (id, 0)); | |
2c73f9f5 | 3275 | else if (TREE_CODE (id) != OVERLOAD) |
5566b478 MS |
3276 | mark_used (id); |
3277 | } | |
5156628f | 3278 | if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl) |
5566b478 MS |
3279 | { |
3280 | /* XXX CHS - should we set TREE_USED of the constant? */ | |
3281 | id = DECL_INITIAL (id); | |
3282 | /* This is to prevent an enum whose value is 0 | |
3283 | from being considered a null pointer constant. */ | |
3284 | id = build1 (NOP_EXPR, TREE_TYPE (id), id); | |
3285 | TREE_CONSTANT (id) = 1; | |
3286 | } | |
3287 | ||
5156628f | 3288 | if (processing_template_decl) |
5566b478 MS |
3289 | { |
3290 | if (is_overloaded_fn (id)) | |
3291 | { | |
672476cb | 3292 | id = build_min_nt (LOOKUP_EXPR, token); |
5566b478 | 3293 | LOOKUP_EXPR_GLOBAL (id) = 1; |
672476cb | 3294 | return id; |
5566b478 MS |
3295 | } |
3296 | /* else just use the decl */ | |
3297 | } | |
42976354 | 3298 | return convert_from_reference (id); |
8d08fdba MS |
3299 | } |
3300 | ||
3301 | tree | |
3302 | identifier_typedecl_value (node) | |
3303 | tree node; | |
3304 | { | |
3305 | tree t, type; | |
3306 | type = IDENTIFIER_TYPE_VALUE (node); | |
3307 | if (type == NULL_TREE) | |
3308 | return NULL_TREE; | |
f181d4ae MM |
3309 | |
3310 | if (IDENTIFIER_BINDING (node)) | |
3311 | { | |
3312 | t = IDENTIFIER_VALUE (node); | |
3313 | if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) | |
3314 | return t; | |
3315 | } | |
3316 | if (IDENTIFIER_NAMESPACE_VALUE (node)) | |
3317 | { | |
3318 | t = IDENTIFIER_NAMESPACE_VALUE (node); | |
3319 | if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) | |
3320 | return t; | |
3321 | } | |
3322 | ||
8d08fdba | 3323 | /* Will this one ever happen? */ |
d2e5ee5c MS |
3324 | if (TYPE_MAIN_DECL (type)) |
3325 | return TYPE_MAIN_DECL (type); | |
8d08fdba MS |
3326 | |
3327 | /* We used to do an internal error of 62 here, but instead we will | |
3328 | handle the return of a null appropriately in the callers. */ | |
3329 | return NULL_TREE; | |
3330 | } | |
3331 | ||
1ceb5ff3 | 3332 | struct pf_args |
9b2bf201 KG |
3333 | { |
3334 | /* Input */ | |
1ceb5ff3 JM |
3335 | int base; |
3336 | char * p; | |
9b2bf201 | 3337 | /* I/O */ |
9b2bf201 | 3338 | int c; |
1ceb5ff3 | 3339 | /* Output */ |
9b2bf201 KG |
3340 | int imag; |
3341 | tree type; | |
1ceb5ff3 | 3342 | int conversion_errno; |
9b2bf201 KG |
3343 | REAL_VALUE_TYPE value; |
3344 | }; | |
3345 | ||
3346 | static void | |
3347 | parse_float (data) | |
3348 | PTR data; | |
3349 | { | |
3350 | struct pf_args * args = (struct pf_args *) data; | |
3351 | int fflag = 0, lflag = 0; | |
3352 | /* Copy token_buffer now, while it has just the number | |
3353 | and not the suffixes; once we add `f' or `i', | |
3354 | REAL_VALUE_ATOF may not work any more. */ | |
3355 | char *copy = (char *) alloca (args->p - token_buffer + 1); | |
3356 | bcopy (token_buffer, copy, args->p - token_buffer + 1); | |
1ceb5ff3 JM |
3357 | args->imag = 0; |
3358 | args->conversion_errno = 0; | |
3359 | args->type = double_type_node; | |
3360 | ||
9b2bf201 KG |
3361 | while (1) |
3362 | { | |
3363 | int lose = 0; | |
1ceb5ff3 | 3364 | |
9b2bf201 KG |
3365 | /* Read the suffixes to choose a data type. */ |
3366 | switch (args->c) | |
3367 | { | |
3368 | case 'f': case 'F': | |
3369 | if (fflag) | |
3370 | error ("more than one `f' in numeric constant"); | |
3371 | fflag = 1; | |
3372 | break; | |
1ceb5ff3 | 3373 | |
9b2bf201 KG |
3374 | case 'l': case 'L': |
3375 | if (lflag) | |
3376 | error ("more than one `l' in numeric constant"); | |
3377 | lflag = 1; | |
3378 | break; | |
1ceb5ff3 | 3379 | |
9b2bf201 KG |
3380 | case 'i': case 'I': |
3381 | if (args->imag) | |
3382 | error ("more than one `i' or `j' in numeric constant"); | |
3383 | else if (pedantic) | |
3384 | pedwarn ("ANSI C++ forbids imaginary numeric constants"); | |
3385 | args->imag = 1; | |
3386 | break; | |
1ceb5ff3 | 3387 | |
9b2bf201 KG |
3388 | default: |
3389 | lose = 1; | |
3390 | } | |
1ceb5ff3 | 3391 | |
9b2bf201 KG |
3392 | if (lose) |
3393 | break; | |
1ceb5ff3 | 3394 | |
9b2bf201 KG |
3395 | if (args->p >= token_buffer + maxtoken - 3) |
3396 | args->p = extend_token_buffer (args->p); | |
3397 | *(args->p++) = args->c; | |
3398 | *(args->p) = 0; | |
3399 | args->c = getch (); | |
3400 | } | |
1ceb5ff3 | 3401 | |
9b2bf201 KG |
3402 | /* The second argument, machine_mode, of REAL_VALUE_ATOF |
3403 | tells the desired precision of the binary result | |
3404 | of decimal-to-binary conversion. */ | |
1ceb5ff3 | 3405 | |
9b2bf201 KG |
3406 | if (fflag) |
3407 | { | |
3408 | if (lflag) | |
3409 | error ("both `f' and `l' in floating constant"); | |
1ceb5ff3 | 3410 | |
9b2bf201 | 3411 | args->type = float_type_node; |
1ceb5ff3 JM |
3412 | errno = 0; |
3413 | if (args->base == 16) | |
3414 | args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type)); | |
3415 | else | |
3416 | args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type)); | |
3417 | args->conversion_errno = errno; | |
9b2bf201 | 3418 | /* A diagnostic is required here by some ANSI C testsuites. |
1ceb5ff3 | 3419 | This is not pedwarn, because some people don't want |
9b2bf201 KG |
3420 | an error for this. */ |
3421 | if (REAL_VALUE_ISINF (args->value) && pedantic) | |
3422 | warning ("floating point number exceeds range of `float'"); | |
3423 | } | |
3424 | else if (lflag) | |
3425 | { | |
3426 | args->type = long_double_type_node; | |
1ceb5ff3 JM |
3427 | errno = 0; |
3428 | if (args->base == 16) | |
3429 | args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type)); | |
3430 | else | |
3431 | args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type)); | |
3432 | args->conversion_errno = errno; | |
9b2bf201 KG |
3433 | if (REAL_VALUE_ISINF (args->value) && pedantic) |
3434 | warning ("floating point number exceeds range of `long double'"); | |
3435 | } | |
3436 | else | |
3437 | { | |
1ceb5ff3 JM |
3438 | errno = 0; |
3439 | if (args->base == 16) | |
3440 | args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type)); | |
3441 | else | |
3442 | args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type)); | |
3443 | args->conversion_errno = errno; | |
9b2bf201 KG |
3444 | if (REAL_VALUE_ISINF (args->value) && pedantic) |
3445 | warning ("floating point number exceeds range of `double'"); | |
3446 | } | |
3447 | } | |
3448 | ||
66a6250f JM |
3449 | /* Get the next character, staying within the current token if possible. |
3450 | If we're lexing a token, we don't want to look beyond the end of the | |
3451 | token cpplib has prepared for us; otherwise, we end up reading in the | |
3452 | next token, which screws up feed_input. So just return a null | |
3453 | character. */ | |
3454 | ||
3455 | inline int | |
3456 | token_getch () | |
3457 | { | |
3458 | #if USE_CPPLIB | |
3459 | if (yy_cur == yy_lim) | |
3460 | return '\0'; | |
3461 | #endif | |
3462 | return getch (); | |
3463 | } | |
3464 | ||
3465 | inline void | |
3466 | token_put_back (ch) | |
3467 | int ch; | |
3468 | { | |
3469 | #if USE_CPPLIB | |
3470 | if (ch == '\0') | |
3471 | return; | |
3472 | #endif | |
3473 | put_back (ch); | |
3474 | } | |
3475 | ||
3476 | /* Read a single token from the input stream, and assign it lexical | |
3477 | semantics. | |
3478 | ||
3479 | Note: We used to do token pasting here, to produce compound tokens like | |
3480 | LEFT_RIGHT and EXTERN_LANG_STRING. That's now handled in spew.c, along | |
3481 | with symbol table interaction and other context-sensitivity. */ | |
3482 | ||
8d08fdba MS |
3483 | int |
3484 | real_yylex () | |
3485 | { | |
3486 | register int c; | |
1ceb5ff3 | 3487 | register char *p; |
8d08fdba MS |
3488 | register int value; |
3489 | int wide_flag = 0; | |
8d08fdba | 3490 | |
66a6250f | 3491 | c = getch (); |
8d08fdba MS |
3492 | |
3493 | /* Effectively do c = skip_white_space (c) | |
3494 | but do it faster in the usual cases. */ | |
3495 | while (1) | |
3496 | switch (c) | |
3497 | { | |
3498 | case ' ': | |
3499 | case '\t': | |
3500 | case '\f': | |
3501 | case '\v': | |
3502 | case '\b': | |
66a6250f JM |
3503 | #if USE_CPPLIB |
3504 | if (cpp_token == CPP_HSPACE) | |
3505 | c = yy_get_token (); | |
3506 | else | |
3507 | #endif | |
3508 | c = getch (); | |
8d08fdba MS |
3509 | break; |
3510 | ||
3511 | case '\r': | |
3512 | /* Call skip_white_space so we can warn if appropriate. */ | |
3513 | ||
3514 | case '\n': | |
3515 | case '/': | |
3516 | case '\\': | |
3517 | c = skip_white_space (c); | |
3518 | default: | |
3519 | goto found_nonwhite; | |
3520 | } | |
3521 | found_nonwhite: | |
3522 | ||
3523 | token_buffer[0] = c; | |
3524 | token_buffer[1] = 0; | |
3525 | ||
3526 | /* yylloc.first_line = lineno; */ | |
3527 | ||
3528 | switch (c) | |
3529 | { | |
3530 | case EOF: | |
8d08fdba | 3531 | end_of_file = 1; |
1ceb5ff3 | 3532 | token_buffer[0] = 0; |
1946537b | 3533 | if (linemode) |
d18c083e | 3534 | value = END_OF_LINE; |
1946537b JM |
3535 | else if (input_redirected ()) |
3536 | value = END_OF_SAVED_INPUT; | |
8d08fdba MS |
3537 | else |
3538 | value = ENDFILE; | |
3539 | break; | |
3540 | ||
8d08fdba | 3541 | case 'L': |
66a6250f JM |
3542 | #if USE_CPPLIB |
3543 | if (cpp_token == CPP_NAME) | |
3544 | goto letter; | |
3545 | #endif | |
8d08fdba MS |
3546 | /* Capital L may start a wide-string or wide-character constant. */ |
3547 | { | |
66a6250f | 3548 | register int c = token_getch (); |
8d08fdba MS |
3549 | if (c == '\'') |
3550 | { | |
3551 | wide_flag = 1; | |
3552 | goto char_constant; | |
3553 | } | |
3554 | if (c == '"') | |
3555 | { | |
3556 | wide_flag = 1; | |
3557 | goto string_constant; | |
3558 | } | |
66a6250f | 3559 | token_put_back (c); |
8d08fdba | 3560 | } |
1ceb5ff3 | 3561 | |
8d08fdba MS |
3562 | case 'A': case 'B': case 'C': case 'D': case 'E': |
3563 | case 'F': case 'G': case 'H': case 'I': case 'J': | |
3564 | case 'K': case 'M': case 'N': case 'O': | |
3565 | case 'P': case 'Q': case 'R': case 'S': case 'T': | |
3566 | case 'U': case 'V': case 'W': case 'X': case 'Y': | |
3567 | case 'Z': | |
3568 | case 'a': case 'b': case 'c': case 'd': case 'e': | |
3569 | case 'f': case 'g': case 'h': case 'i': case 'j': | |
3570 | case 'k': case 'l': case 'm': case 'n': case 'o': | |
3571 | case 'p': case 'q': case 'r': case 's': case 't': | |
3572 | case 'u': case 'v': case 'w': case 'x': case 'y': | |
3573 | case 'z': | |
3574 | case '_': | |
1ceb5ff3 | 3575 | case '$': |
66a6250f | 3576 | #if USE_CPPLIB |
9c0758dd | 3577 | letter: |
1ceb5ff3 JM |
3578 | if (cpp_token == CPP_NAME) |
3579 | { | |
3580 | /* Note that one character has already been read from | |
3581 | yy_cur into token_buffer. Also, cpplib complains about | |
3582 | $ in identifiers, so we don't have to. */ | |
3583 | ||
3584 | int len = yy_lim - yy_cur + 1; | |
3585 | if (len >= maxtoken) | |
3586 | extend_token_buffer_to (len + 1); | |
3587 | memcpy (token_buffer + 1, yy_cur, len); | |
3588 | p = token_buffer + len; | |
3589 | yy_cur = yy_lim; | |
3590 | } | |
3591 | else | |
66a6250f | 3592 | #endif |
1ceb5ff3 JM |
3593 | { |
3594 | p = token_buffer; | |
3595 | while (ISALNUM (c) || (c == '_') || c == '$') | |
3596 | { | |
3597 | /* Make sure this char really belongs in an identifier. */ | |
3598 | if (c == '$') | |
3599 | { | |
3600 | if (! dollars_in_ident) | |
3601 | error ("`$' in identifier"); | |
3602 | else if (pedantic) | |
3603 | pedwarn ("`$' in identifier"); | |
3604 | } | |
4f6140be | 3605 | |
1ceb5ff3 JM |
3606 | if (p >= token_buffer + maxtoken) |
3607 | p = extend_token_buffer (p); | |
8d08fdba | 3608 | |
1ceb5ff3 JM |
3609 | *p++ = c; |
3610 | c = token_getch (); | |
3611 | } | |
8d08fdba | 3612 | |
1ceb5ff3 JM |
3613 | *p = 0; |
3614 | token_put_back (c); | |
3615 | } | |
8d08fdba | 3616 | |
1ceb5ff3 JM |
3617 | value = IDENTIFIER; |
3618 | yylval.itype = 0; | |
8d08fdba | 3619 | |
1ceb5ff3 | 3620 | /* Try to recognize a keyword. Uses minimum-perfect hash function */ |
8d08fdba | 3621 | |
1ceb5ff3 JM |
3622 | { |
3623 | register struct resword *ptr; | |
8d08fdba | 3624 | |
1ceb5ff3 JM |
3625 | if ((ptr = is_reserved_word (token_buffer, p - token_buffer))) |
3626 | { | |
3627 | if (ptr->rid) | |
3628 | { | |
3629 | if (ptr->token == VISSPEC) | |
3630 | { | |
3631 | switch (ptr->rid) | |
3632 | { | |
3633 | case RID_PUBLIC: | |
3634 | yylval.ttype = access_public_node; | |
3635 | break; | |
3636 | case RID_PRIVATE: | |
3637 | yylval.ttype = access_private_node; | |
3638 | break; | |
3639 | case RID_PROTECTED: | |
3640 | yylval.ttype = access_protected_node; | |
3641 | break; | |
3642 | default: | |
3643 | my_friendly_abort (63); | |
3644 | } | |
3645 | } | |
3646 | else | |
3647 | yylval.ttype = ridpointers[(int) ptr->rid]; | |
3648 | } | |
3649 | else switch (ptr->token) | |
3650 | { | |
3651 | case EQCOMPARE: | |
3652 | yylval.code = NE_EXPR; | |
3653 | token_buffer[0] = '!'; | |
3654 | token_buffer[1] = '='; | |
3655 | token_buffer[2] = 0; | |
3656 | break; | |
66a6250f | 3657 | |
1ceb5ff3 JM |
3658 | case ASSIGN: |
3659 | if (strcmp ("and_eq", token_buffer) == 0) | |
3660 | { | |
3661 | yylval.code = BIT_AND_EXPR; | |
3662 | token_buffer[0] = '&'; | |
3663 | } | |
3664 | else if (strcmp ("or_eq", token_buffer) == 0) | |
3665 | { | |
3666 | yylval.code = BIT_IOR_EXPR; | |
3667 | token_buffer[0] = '|'; | |
3668 | } | |
3669 | else if (strcmp ("xor_eq", token_buffer) == 0) | |
3670 | { | |
3671 | yylval.code = BIT_XOR_EXPR; | |
3672 | token_buffer[0] = '^'; | |
3673 | } | |
3674 | token_buffer[1] = '='; | |
3675 | token_buffer[2] = 0; | |
3676 | break; | |
66a6250f | 3677 | |
1ceb5ff3 JM |
3678 | case '&': |
3679 | yylval.code = BIT_AND_EXPR; | |
3680 | token_buffer[0] = '&'; | |
3681 | token_buffer[1] = 0; | |
3682 | break; | |
66a6250f | 3683 | |
1ceb5ff3 JM |
3684 | case '|': |
3685 | yylval.code = BIT_IOR_EXPR; | |
3686 | token_buffer[0] = '|'; | |
3687 | token_buffer[1] = 0; | |
3688 | break; | |
66a6250f | 3689 | |
1ceb5ff3 JM |
3690 | case '^': |
3691 | yylval.code = BIT_XOR_EXPR; | |
3692 | token_buffer[0] = '^'; | |
3693 | token_buffer[1] = 0; | |
3694 | break; | |
3695 | } | |
db5ae43f | 3696 | |
1ceb5ff3 JM |
3697 | value = (int) ptr->token; |
3698 | } | |
3699 | } | |
8d08fdba | 3700 | |
1ceb5ff3 JM |
3701 | /* If we did not find a keyword, look for an identifier |
3702 | (or a typename). */ | |
8d08fdba | 3703 | |
1ceb5ff3 JM |
3704 | if (value == IDENTIFIER || value == TYPESPEC) |
3705 | GNU_xref_ref (current_function_decl, token_buffer); | |
8d08fdba | 3706 | |
1ceb5ff3 JM |
3707 | if (value == IDENTIFIER) |
3708 | { | |
3709 | register tree tmp = get_identifier (token_buffer); | |
8d08fdba MS |
3710 | |
3711 | #if !defined(VMS) && defined(JOINER) | |
1ceb5ff3 JM |
3712 | /* Make sure that user does not collide with our internal |
3713 | naming scheme. */ | |
3714 | if (JOINER == '$' | |
3715 | && (THIS_NAME_P (tmp) | |
3716 | || VPTR_NAME_P (tmp) | |
3717 | || DESTRUCTOR_NAME_P (tmp) | |
3718 | || VTABLE_NAME_P (tmp) | |
3719 | || TEMP_NAME_P (tmp) | |
3720 | || ANON_AGGRNAME_P (tmp) | |
3721 | || ANON_PARMNAME_P (tmp))) | |
3722 | warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy", | |
3723 | token_buffer); | |
8d08fdba MS |
3724 | #endif |
3725 | ||
1ceb5ff3 JM |
3726 | yylval.ttype = tmp; |
3727 | } | |
3728 | if (value == NEW && ! global_bindings_p ()) | |
3729 | { | |
3730 | value = NEW; | |
3731 | goto done; | |
3732 | } | |
8d08fdba MS |
3733 | break; |
3734 | ||
3735 | case '.': | |
66a6250f JM |
3736 | #if USE_CPPLIB |
3737 | if (yy_cur < yy_lim) | |
3738 | #endif | |
3739 | { | |
3740 | /* It's hard to preserve tokenization on '.' because | |
3741 | it could be a symbol by itself, or it could be the | |
3742 | start of a floating point number and cpp won't tell us. */ | |
3743 | register int c1 = token_getch (); | |
3744 | token_buffer[1] = c1; | |
3745 | if (c1 == '*') | |
3746 | { | |
3747 | value = DOT_STAR; | |
3748 | token_buffer[2] = 0; | |
3749 | goto done; | |
3750 | } | |
3751 | if (c1 == '.') | |
3752 | { | |
3753 | c1 = token_getch (); | |
3754 | if (c1 == '.') | |
3755 | { | |
3756 | token_buffer[2] = c1; | |
3757 | token_buffer[3] = 0; | |
3758 | value = ELLIPSIS; | |
3759 | goto done; | |
3760 | } | |
3761 | error ("parse error at `..'"); | |
3762 | } | |
3763 | if (ISDIGIT (c1)) | |
3764 | { | |
3765 | token_put_back (c1); | |
1ceb5ff3 | 3766 | goto number; |
66a6250f JM |
3767 | } |
3768 | token_put_back (c1); | |
3769 | } | |
3770 | value = '.'; | |
3771 | token_buffer[1] = 0; | |
1ceb5ff3 | 3772 | break; |
66a6250f | 3773 | |
8d08fdba | 3774 | case '0': case '1': |
66a6250f | 3775 | /* Optimize for most frequent case. */ |
8d08fdba | 3776 | { |
66a6250f JM |
3777 | register int cond; |
3778 | ||
3779 | #if USE_CPPLIB | |
3780 | cond = (yy_cur == yy_lim); | |
3781 | #else | |
3782 | register int c1 = token_getch (); | |
3783 | token_put_back (c1); | |
3784 | cond = (! ISALNUM (c1) && c1 != '.'); | |
3785 | #endif | |
3786 | if (cond) | |
8d08fdba | 3787 | { |
1ceb5ff3 | 3788 | yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node; |
8d08fdba | 3789 | value = CONSTANT; |
1ceb5ff3 | 3790 | break; |
8d08fdba | 3791 | } |
1ceb5ff3 | 3792 | /*FALLTHRU*/ |
8d08fdba | 3793 | } |
1ceb5ff3 | 3794 | case '2': case '3': case '4': |
8d08fdba | 3795 | case '5': case '6': case '7': case '8': case '9': |
1ceb5ff3 | 3796 | number: |
8d08fdba | 3797 | { |
8d08fdba MS |
3798 | int base = 10; |
3799 | int count = 0; | |
3800 | int largest_digit = 0; | |
3801 | int numdigits = 0; | |
8d08fdba MS |
3802 | int overflow = 0; |
3803 | ||
cc144655 GRK |
3804 | /* We actually store only HOST_BITS_PER_CHAR bits in each part. |
3805 | The code below which fills the parts array assumes that a host | |
3806 | int is at least twice as wide as a host char, and that | |
3807 | HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR. | |
3808 | Two HOST_WIDE_INTs is the largest int literal we can store. | |
3809 | In order to detect overflow below, the number of parts (TOTAL_PARTS) | |
3810 | must be exactly the number of parts needed to hold the bits | |
3811 | of two HOST_WIDE_INTs. */ | |
3812 | #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2) | |
3813 | unsigned int parts[TOTAL_PARTS]; | |
3814 | ||
1ceb5ff3 JM |
3815 | enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON } |
3816 | floatflag = NOT_FLOAT; | |
8d08fdba | 3817 | |
8d08fdba MS |
3818 | for (count = 0; count < TOTAL_PARTS; count++) |
3819 | parts[count] = 0; | |
3820 | ||
37c46b43 MS |
3821 | p = token_buffer; |
3822 | *p++ = c; | |
3823 | ||
8d08fdba MS |
3824 | if (c == '0') |
3825 | { | |
66a6250f | 3826 | *p++ = (c = token_getch ()); |
8d08fdba MS |
3827 | if ((c == 'x') || (c == 'X')) |
3828 | { | |
3829 | base = 16; | |
66a6250f | 3830 | *p++ = (c = token_getch ()); |
8d08fdba MS |
3831 | } |
3832 | /* Leading 0 forces octal unless the 0 is the only digit. */ | |
3833 | else if (c >= '0' && c <= '9') | |
3834 | { | |
3835 | base = 8; | |
3836 | numdigits++; | |
3837 | } | |
3838 | else | |
3839 | numdigits++; | |
3840 | } | |
3841 | ||
3842 | /* Read all the digits-and-decimal-points. */ | |
3843 | ||
3844 | while (c == '.' | |
1ceb5ff3 JM |
3845 | || (ISALNUM (c) && c != 'l' && c != 'L' |
3846 | && c != 'u' && c != 'U' | |
37c46b43 | 3847 | && c != 'i' && c != 'I' && c != 'j' && c != 'J' |
8d08fdba MS |
3848 | && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F'))))) |
3849 | { | |
3850 | if (c == '.') | |
3851 | { | |
1ceb5ff3 JM |
3852 | if (base == 16 && pedantic) |
3853 | pedwarn ("floating constant may not be in radix 16"); | |
37c46b43 MS |
3854 | if (floatflag == TOO_MANY_POINTS) |
3855 | /* We have already emitted an error. Don't need another. */ | |
3856 | ; | |
1ceb5ff3 | 3857 | else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON) |
8d08fdba | 3858 | { |
8251199e | 3859 | error ("malformed floating constant"); |
8d08fdba | 3860 | floatflag = TOO_MANY_POINTS; |
37c46b43 MS |
3861 | /* Avoid another error from atof by forcing all characters |
3862 | from here on to be ignored. */ | |
3863 | p[-1] = '\0'; | |
8d08fdba MS |
3864 | } |
3865 | else | |
3866 | floatflag = AFTER_POINT; | |
3867 | ||
1ceb5ff3 JM |
3868 | if (base == 8) |
3869 | base = 10; | |
66a6250f | 3870 | *p++ = c = token_getch (); |
8d08fdba | 3871 | /* Accept '.' as the start of a floating-point number |
66a6250f | 3872 | only when it is followed by a digit. */ |
faa25e97 | 3873 | if (p == token_buffer + 2 && !ISDIGIT (c)) |
66a6250f | 3874 | my_friendly_abort (990710); |
8d08fdba MS |
3875 | } |
3876 | else | |
3877 | { | |
3878 | /* It is not a decimal point. | |
3879 | It should be a digit (perhaps a hex digit). */ | |
3880 | ||
faa25e97 | 3881 | if (ISDIGIT (c)) |
8d08fdba MS |
3882 | { |
3883 | c = c - '0'; | |
3884 | } | |
3885 | else if (base <= 10) | |
3886 | { | |
3887 | if (c == 'e' || c == 'E') | |
3888 | { | |
3889 | base = 10; | |
1ceb5ff3 | 3890 | floatflag = AFTER_EXPON; |
8d08fdba MS |
3891 | break; /* start of exponent */ |
3892 | } | |
8251199e | 3893 | error ("nondigits in number and not hexadecimal"); |
8d08fdba MS |
3894 | c = 0; |
3895 | } | |
1ceb5ff3 JM |
3896 | else if (base == 16 && (c == 'p' || c == 'P')) |
3897 | { | |
3898 | floatflag = AFTER_EXPON; | |
3899 | break; /* start of exponent */ | |
3900 | } | |
8d08fdba MS |
3901 | else if (c >= 'a') |
3902 | { | |
3903 | c = c - 'a' + 10; | |
3904 | } | |
3905 | else | |
3906 | { | |
3907 | c = c - 'A' + 10; | |
3908 | } | |
3909 | if (c >= largest_digit) | |
3910 | largest_digit = c; | |
3911 | numdigits++; | |
3912 | ||
3913 | for (count = 0; count < TOTAL_PARTS; count++) | |
3914 | { | |
3915 | parts[count] *= base; | |
3916 | if (count) | |
3917 | { | |
3918 | parts[count] | |
3919 | += (parts[count-1] >> HOST_BITS_PER_CHAR); | |
3920 | parts[count-1] | |
3921 | &= (1 << HOST_BITS_PER_CHAR) - 1; | |
3922 | } | |
3923 | else | |
3924 | parts[0] += c; | |
3925 | } | |
3926 | ||
cc144655 GRK |
3927 | /* If the highest-order part overflows (gets larger than |
3928 | a host char will hold) then the whole number has | |
3929 | overflowed. Record this and truncate the highest-order | |
3930 | part. */ | |
3931 | if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR) | |
3932 | { | |
3933 | overflow = 1; | |
3934 | parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1; | |
3935 | } | |
8d08fdba MS |
3936 | |
3937 | if (p >= token_buffer + maxtoken - 3) | |
3938 | p = extend_token_buffer (p); | |
66a6250f | 3939 | *p++ = (c = token_getch ()); |
8d08fdba MS |
3940 | } |
3941 | } | |
3942 | ||
6ad07332 | 3943 | /* This can happen on input like `int i = 0x;' */ |
8d08fdba | 3944 | if (numdigits == 0) |
6ad07332 | 3945 | error ("numeric constant with no digits"); |
8d08fdba MS |
3946 | |
3947 | if (largest_digit >= base) | |
8251199e | 3948 | error ("numeric constant contains digits beyond the radix"); |
8d08fdba | 3949 | |
66a6250f JM |
3950 | /* Remove terminating char from the token buffer and delimit the |
3951 | string. */ | |
8d08fdba MS |
3952 | *--p = 0; |
3953 | ||
3954 | if (floatflag != NOT_FLOAT) | |
3955 | { | |
1ceb5ff3 JM |
3956 | tree type; |
3957 | int imag, conversion_errno; | |
8d08fdba | 3958 | REAL_VALUE_TYPE value; |
9b2bf201 | 3959 | struct pf_args args; |
8d08fdba MS |
3960 | |
3961 | /* Read explicit exponent if any, and put it in tokenbuf. */ | |
3962 | ||
1ceb5ff3 JM |
3963 | if ((base == 10 && ((c == 'e') || (c == 'E'))) |
3964 | || (base == 16 && (c == 'p' || c == 'P'))) | |
8d08fdba MS |
3965 | { |
3966 | if (p >= token_buffer + maxtoken - 3) | |
3967 | p = extend_token_buffer (p); | |
3968 | *p++ = c; | |
66a6250f | 3969 | c = token_getch (); |
8d08fdba MS |
3970 | if ((c == '+') || (c == '-')) |
3971 | { | |
3972 | *p++ = c; | |
66a6250f | 3973 | c = token_getch (); |
8d08fdba | 3974 | } |
1ceb5ff3 | 3975 | /* Exponent is decimal, even if string is a hex float. */ |
faa25e97 | 3976 | if (! ISDIGIT (c)) |
8251199e | 3977 | error ("floating constant exponent has no digits"); |
1ceb5ff3 | 3978 | while (ISDIGIT (c)) |
8d08fdba MS |
3979 | { |
3980 | if (p >= token_buffer + maxtoken - 3) | |
3981 | p = extend_token_buffer (p); | |
3982 | *p++ = c; | |
66a6250f | 3983 | c = token_getch (); |
8d08fdba MS |
3984 | } |
3985 | } | |
1ceb5ff3 JM |
3986 | if (base == 16 && floatflag != AFTER_EXPON) |
3987 | error ("hexadecimal floating constant has no exponent"); | |
8d08fdba MS |
3988 | |
3989 | *p = 0; | |
8d08fdba | 3990 | |
9b2bf201 | 3991 | /* Setup input for parse_float() */ |
1ceb5ff3 | 3992 | args.base = base; |
9b2bf201 KG |
3993 | args.p = p; |
3994 | args.c = c; | |
1ceb5ff3 | 3995 | |
8d08fdba | 3996 | /* Convert string to a double, checking for overflow. */ |
9b2bf201 | 3997 | if (do_float_handler (parse_float, (PTR) &args)) |
8d08fdba | 3998 | { |
9b2bf201 KG |
3999 | /* Receive output from parse_float() */ |
4000 | value = args.value; | |
8d08fdba MS |
4001 | } |
4002 | else | |
4003 | { | |
9b2bf201 KG |
4004 | /* We got an exception from parse_float() */ |
4005 | error ("floating constant out of range"); | |
4006 | value = dconst0; | |
8d08fdba | 4007 | } |
9b2bf201 KG |
4008 | |
4009 | /* Receive output from parse_float() */ | |
9b2bf201 KG |
4010 | c = args.c; |
4011 | imag = args.imag; | |
4012 | type = args.type; | |
1ceb5ff3 | 4013 | conversion_errno = args.conversion_errno; |
9b2bf201 | 4014 | |
8d08fdba | 4015 | #ifdef ERANGE |
1ceb5ff3 JM |
4016 | /* ERANGE is also reported for underflow, |
4017 | so test the value to distinguish overflow from that. */ | |
4018 | if (conversion_errno == ERANGE && pedantic | |
4019 | && (REAL_VALUES_LESS (dconst1, value) | |
4020 | || REAL_VALUES_LESS (value, dconstm1))) | |
4021 | warning ("floating point number exceeds range of `double'"); | |
37c46b43 | 4022 | #endif |
8d08fdba | 4023 | |
37c46b43 MS |
4024 | /* If the result is not a number, assume it must have been |
4025 | due to some error message above, so silently convert | |
4026 | it to a zero. */ | |
4027 | if (REAL_VALUE_ISNAN (value)) | |
4028 | value = dconst0; | |
8d08fdba MS |
4029 | |
4030 | /* Create a node with determined type and value. */ | |
37c46b43 MS |
4031 | if (imag) |
4032 | yylval.ttype = build_complex (NULL_TREE, | |
1ceb5ff3 | 4033 | convert (type, integer_zero_node), |
37c46b43 MS |
4034 | build_real (type, value)); |
4035 | else | |
4036 | yylval.ttype = build_real (type, value); | |
8d08fdba MS |
4037 | } |
4038 | else | |
4039 | { | |
4040 | tree type; | |
4041 | HOST_WIDE_INT high, low; | |
4042 | int spec_unsigned = 0; | |
4043 | int spec_long = 0; | |
4044 | int spec_long_long = 0; | |
37c46b43 | 4045 | int spec_imag = 0; |
9dfce8fd JM |
4046 | int warn = 0; |
4047 | int i; | |
8d08fdba MS |
4048 | |
4049 | while (1) | |
4050 | { | |
4051 | if (c == 'u' || c == 'U') | |
4052 | { | |
4053 | if (spec_unsigned) | |
8251199e | 4054 | error ("two `u's in integer constant"); |
8d08fdba MS |
4055 | spec_unsigned = 1; |
4056 | } | |
4057 | else if (c == 'l' || c == 'L') | |
4058 | { | |
4059 | if (spec_long) | |
4060 | { | |
4061 | if (spec_long_long) | |
8251199e | 4062 | error ("three `l's in integer constant"); |
31928556 | 4063 | else if (pedantic && ! in_system_header && warn_long_long) |
8251199e | 4064 | pedwarn ("ANSI C++ forbids long long integer constants"); |
8d08fdba MS |
4065 | spec_long_long = 1; |
4066 | } | |
4067 | spec_long = 1; | |
4068 | } | |
37c46b43 | 4069 | else if (c == 'i' || c == 'j' || c == 'I' || c == 'J') |
8d08fdba | 4070 | { |
37c46b43 | 4071 | if (spec_imag) |
8251199e | 4072 | error ("more than one `i' or `j' in numeric constant"); |
37c46b43 | 4073 | else if (pedantic) |
8251199e | 4074 | pedwarn ("ANSI C++ forbids imaginary numeric constants"); |
37c46b43 | 4075 | spec_imag = 1; |
8d08fdba | 4076 | } |
37c46b43 MS |
4077 | else |
4078 | break; | |
8d08fdba MS |
4079 | if (p >= token_buffer + maxtoken - 3) |
4080 | p = extend_token_buffer (p); | |
4081 | *p++ = c; | |
66a6250f | 4082 | c = token_getch (); |
8d08fdba MS |
4083 | } |
4084 | ||
cc144655 GRK |
4085 | /* If the literal overflowed, pedwarn about it now. */ |
4086 | if (overflow) | |
4087 | { | |
4088 | warn = 1; | |
4089 | pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2); | |
4090 | } | |
8d08fdba MS |
4091 | |
4092 | /* This is simplified by the fact that our constant | |
4093 | is always positive. */ | |
1ceb5ff3 | 4094 | |
8d08fdba MS |
4095 | high = low = 0; |
4096 | ||
4097 | for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++) | |
4098 | { | |
4099 | high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT | |
4100 | / HOST_BITS_PER_CHAR)] | |
4101 | << (i * HOST_BITS_PER_CHAR)); | |
4102 | low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR); | |
4103 | } | |
1ceb5ff3 | 4104 | |
8d08fdba MS |
4105 | yylval.ttype = build_int_2 (low, high); |
4106 | TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node; | |
4107 | ||
a3f44a13 | 4108 | /* Calculate the ANSI type. */ |
1ceb5ff3 | 4109 | if (! spec_long && ! spec_unsigned |
8d08fdba | 4110 | && int_fits_type_p (yylval.ttype, integer_type_node)) |
a3f44a13 | 4111 | type = integer_type_node; |
1ceb5ff3 | 4112 | else if (! spec_long && (base != 10 || spec_unsigned) |
8d08fdba | 4113 | && int_fits_type_p (yylval.ttype, unsigned_type_node)) |
a3f44a13 | 4114 | type = unsigned_type_node; |
1ceb5ff3 | 4115 | else if (! spec_unsigned && !spec_long_long |
8d08fdba MS |
4116 | && int_fits_type_p (yylval.ttype, long_integer_type_node)) |
4117 | type = long_integer_type_node; | |
1ceb5ff3 JM |
4118 | else if (! spec_long_long |
4119 | && int_fits_type_p (yylval.ttype, | |
4120 | long_unsigned_type_node)) | |
d22c8596 | 4121 | type = long_unsigned_type_node; |
8d08fdba | 4122 | else if (! spec_unsigned |
8d08fdba MS |
4123 | && int_fits_type_p (yylval.ttype, |
4124 | long_long_integer_type_node)) | |
4125 | type = long_long_integer_type_node; | |
835f9b4d GRK |
4126 | else if (int_fits_type_p (yylval.ttype, |
4127 | long_long_unsigned_type_node)) | |
d22c8596 | 4128 | type = long_long_unsigned_type_node; |
835f9b4d GRK |
4129 | else if (! spec_unsigned |
4130 | && int_fits_type_p (yylval.ttype, | |
4131 | widest_integer_literal_type_node)) | |
4132 | type = widest_integer_literal_type_node; | |
4133 | else | |
4134 | type = widest_unsigned_literal_type_node; | |
8d08fdba | 4135 | |
1ceb5ff3 JM |
4136 | if (pedantic && !spec_long_long && !warn |
4137 | && (TYPE_PRECISION (long_integer_type_node) | |
4138 | < TYPE_PRECISION (type))) | |
4139 | { | |
4140 | warn = 1; | |
4141 | pedwarn ("integer constant larger than the maximum value of an unsigned long int"); | |
4142 | } | |
8d08fdba | 4143 | |
a3f44a13 | 4144 | if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type)) |
1ceb5ff3 | 4145 | warning ("decimal constant is so large that it is unsigned"); |
8d08fdba | 4146 | |
a3f44a13 BK |
4147 | if (spec_imag) |
4148 | { | |
4149 | if (TYPE_PRECISION (type) | |
4150 | <= TYPE_PRECISION (integer_type_node)) | |
4151 | yylval.ttype | |
4152 | = build_complex (NULL_TREE, integer_zero_node, | |
1ceb5ff3 JM |
4153 | convert (integer_type_node, |
4154 | yylval.ttype)); | |
a3f44a13 | 4155 | else |
8251199e | 4156 | error ("complex integer constant is too wide for `__complex int'"); |
a3f44a13 BK |
4157 | } |
4158 | else | |
4159 | TREE_TYPE (yylval.ttype) = type; | |
1ceb5ff3 JM |
4160 | |
4161 | ||
4162 | /* If it's still an integer (not a complex), and it doesn't | |
4163 | fit in the type we choose for it, then pedwarn. */ | |
4164 | ||
4165 | if (! warn | |
4166 | && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE | |
4167 | && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype))) | |
4168 | pedwarn ("integer constant is larger than the maximum value for its type"); | |
8d08fdba MS |
4169 | } |
4170 | ||
66a6250f | 4171 | token_put_back (c); |
37c46b43 MS |
4172 | *p = 0; |
4173 | ||
1ceb5ff3 JM |
4174 | if (ISALNUM (c) || c == '.' || c == '_' || c == '$' |
4175 | || ((c == '-' || c == '+') | |
4176 | && (p[-1] == 'e' || p[-1] == 'E'))) | |
4177 | error ("missing white space after number `%s'", token_buffer); | |
4178 | ||
8d08fdba MS |
4179 | value = CONSTANT; break; |
4180 | } | |
4181 | ||
4182 | case '\'': | |
4183 | char_constant: | |
4184 | { | |
4185 | register int result = 0; | |
4186 | register int num_chars = 0; | |
0d3ba739 | 4187 | int chars_seen = 0; |
8d08fdba MS |
4188 | unsigned width = TYPE_PRECISION (char_type_node); |
4189 | int max_chars; | |
8d08fdba | 4190 | #ifdef MULTIBYTE_CHARS |
0d3ba739 | 4191 | int longest_char = local_mb_cur_max (); |
66a6250f | 4192 | local_mbtowc (NULL_PTR, NULL_PTR, 0); |
8d08fdba | 4193 | #endif |
0d3ba739 DB |
4194 | |
4195 | max_chars = TYPE_PRECISION (integer_type_node) / width; | |
4196 | if (wide_flag) | |
4197 | width = WCHAR_TYPE_SIZE; | |
8d08fdba MS |
4198 | |
4199 | while (1) | |
4200 | { | |
4201 | tryagain: | |
66a6250f | 4202 | c = token_getch (); |
8d08fdba MS |
4203 | |
4204 | if (c == '\'' || c == EOF) | |
4205 | break; | |
4206 | ||
0d3ba739 | 4207 | ++chars_seen; |
8d08fdba MS |
4208 | if (c == '\\') |
4209 | { | |
4210 | int ignore = 0; | |
4211 | c = readescape (&ignore); | |
4212 | if (ignore) | |
4213 | goto tryagain; | |
4214 | if (width < HOST_BITS_PER_INT | |
b370501f | 4215 | && (unsigned) c >= ((unsigned)1 << width)) |
8251199e | 4216 | pedwarn ("escape sequence out of range for character"); |
8d08fdba | 4217 | #ifdef MAP_CHARACTER |
faa25e97 | 4218 | if (ISPRINT (c)) |
8d08fdba MS |
4219 | c = MAP_CHARACTER (c); |
4220 | #endif | |
4221 | } | |
4222 | else if (c == '\n') | |
4223 | { | |
4224 | if (pedantic) | |
8251199e | 4225 | pedwarn ("ANSI C forbids newline in character constant"); |
8d08fdba MS |
4226 | lineno++; |
4227 | } | |
8d08fdba | 4228 | else |
0d3ba739 DB |
4229 | { |
4230 | #ifdef MULTIBYTE_CHARS | |
4231 | wchar_t wc; | |
4232 | int i; | |
4233 | int char_len = -1; | |
4234 | for (i = 1; i <= longest_char; ++i) | |
4235 | { | |
4236 | if (i > maxtoken - 4) | |
4237 | extend_token_buffer (token_buffer); | |
4238 | ||
4239 | token_buffer[i] = c; | |
4240 | char_len = local_mbtowc (& wc, | |
4241 | token_buffer + 1, | |
4242 | i); | |
4243 | if (char_len != -1) | |
4244 | break; | |
66a6250f | 4245 | c = token_getch (); |
0d3ba739 DB |
4246 | } |
4247 | if (char_len > 1) | |
4248 | { | |
4249 | /* mbtowc sometimes needs an extra char before accepting */ | |
4250 | if (char_len < i) | |
66a6250f | 4251 | token_put_back (c); |
0d3ba739 DB |
4252 | if (! wide_flag) |
4253 | { | |
4254 | /* Merge character into result; ignore excess chars. */ | |
4255 | for (i = 1; i <= char_len; ++i) | |
4256 | { | |
4257 | if (i > max_chars) | |
4258 | break; | |
4259 | if (width < HOST_BITS_PER_INT) | |
4260 | result = (result << width) | |
4261 | | (token_buffer[i] | |
4262 | & ((1 << width) - 1)); | |
4263 | else | |
4264 | result = token_buffer[i]; | |
4265 | } | |
4266 | num_chars += char_len; | |
4267 | goto tryagain; | |
4268 | } | |
4269 | c = wc; | |
4270 | } | |
4271 | else | |
4272 | { | |
4273 | if (char_len == -1) | |
cd28936c DB |
4274 | { |
4275 | warning ("Ignoring invalid multibyte character"); | |
4276 | /* Replace all but the first byte. */ | |
4277 | for (--i; i > 1; --i) | |
66a6250f | 4278 | token_put_back (token_buffer[i]); |
cd28936c DB |
4279 | wc = token_buffer[1]; |
4280 | } | |
0d3ba739 | 4281 | #ifdef MAP_CHARACTER |
cd28936c DB |
4282 | c = MAP_CHARACTER (wc); |
4283 | #else | |
4284 | c = wc; | |
8d08fdba | 4285 | #endif |
0d3ba739 DB |
4286 | } |
4287 | #else /* ! MULTIBYTE_CHARS */ | |
4288 | #ifdef MAP_CHARACTER | |
4289 | c = MAP_CHARACTER (c); | |
4290 | #endif | |
4291 | #endif /* ! MULTIBYTE_CHARS */ | |
4292 | } | |
8d08fdba | 4293 | |
0d3ba739 DB |
4294 | if (wide_flag) |
4295 | { | |
4296 | if (chars_seen == 1) /* only keep the first one */ | |
4297 | result = c; | |
4298 | goto tryagain; | |
4299 | } | |
8d08fdba MS |
4300 | |
4301 | /* Merge character into result; ignore excess chars. */ | |
1ceb5ff3 | 4302 | num_chars += (width / TYPE_PRECISION (char_type_node)); |
8d08fdba MS |
4303 | if (num_chars < max_chars + 1) |
4304 | { | |
4305 | if (width < HOST_BITS_PER_INT) | |
4306 | result = (result << width) | (c & ((1 << width) - 1)); | |
4307 | else | |
4308 | result = c; | |
4309 | } | |
4310 | } | |
4311 | ||
8d08fdba | 4312 | if (c != '\'') |
8251199e | 4313 | error ("malformatted character constant"); |
0d3ba739 | 4314 | else if (chars_seen == 0) |
8251199e | 4315 | error ("empty character constant"); |
8d08fdba MS |
4316 | else if (num_chars > max_chars) |
4317 | { | |
4318 | num_chars = max_chars; | |
8251199e | 4319 | error ("character constant too long"); |
8d08fdba | 4320 | } |
0d3ba739 | 4321 | else if (chars_seen != 1 && warn_multichar) |
8251199e | 4322 | warning ("multi-character character constant"); |
8d08fdba MS |
4323 | |
4324 | /* If char type is signed, sign-extend the constant. */ | |
4325 | if (! wide_flag) | |
4326 | { | |
4327 | int num_bits = num_chars * width; | |
4328 | if (num_bits == 0) | |
4329 | /* We already got an error; avoid invalid shift. */ | |
4330 | yylval.ttype = build_int_2 (0, 0); | |
4331 | else if (TREE_UNSIGNED (char_type_node) | |
4332 | || ((result >> (num_bits - 1)) & 1) == 0) | |
4333 | yylval.ttype | |
0d3ba739 | 4334 | = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0 |
c6a29b1f | 4335 | >> (HOST_BITS_PER_WIDE_INT - num_bits)), |
8d08fdba MS |
4336 | 0); |
4337 | else | |
4338 | yylval.ttype | |
0d3ba739 | 4339 | = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0 |
c6a29b1f | 4340 | >> (HOST_BITS_PER_WIDE_INT - num_bits)), |
8d08fdba | 4341 | -1); |
1ceb5ff3 | 4342 | /* In C, a character constant has type 'int'; in C++, 'char'. */ |
0d3ba739 | 4343 | if (chars_seen <= 1) |
8d08fdba MS |
4344 | TREE_TYPE (yylval.ttype) = char_type_node; |
4345 | else | |
4346 | TREE_TYPE (yylval.ttype) = integer_type_node; | |
4347 | } | |
4348 | else | |
4349 | { | |
8d08fdba MS |
4350 | yylval.ttype = build_int_2 (result, 0); |
4351 | TREE_TYPE (yylval.ttype) = wchar_type_node; | |
4352 | } | |
4353 | ||
4354 | value = CONSTANT; | |
4355 | break; | |
4356 | } | |
4357 | ||
4358 | case '"': | |
4359 | string_constant: | |
4360 | { | |
0d3ba739 DB |
4361 | unsigned width = wide_flag ? WCHAR_TYPE_SIZE |
4362 | : TYPE_PRECISION (char_type_node); | |
4363 | #ifdef MULTIBYTE_CHARS | |
4364 | int longest_char = local_mb_cur_max (); | |
66a6250f | 4365 | local_mbtowc (NULL_PTR, NULL_PTR, 0); |
0d3ba739 | 4366 | #endif |
8d08fdba | 4367 | |
66a6250f | 4368 | c = token_getch (); |
8d08fdba MS |
4369 | p = token_buffer + 1; |
4370 | ||
66a6250f | 4371 | while (c != '"' && c != EOF) |
8d08fdba MS |
4372 | { |
4373 | /* ignore_escape_flag is set for reading the filename in #line. */ | |
4374 | if (!ignore_escape_flag && c == '\\') | |
4375 | { | |
4376 | int ignore = 0; | |
4377 | c = readescape (&ignore); | |
4378 | if (ignore) | |
4379 | goto skipnewline; | |
0d3ba739 | 4380 | if (width < HOST_BITS_PER_INT |
b370501f | 4381 | && (unsigned) c >= ((unsigned)1 << width)) |
1ceb5ff3 | 4382 | pedwarn ("escape sequence out of range for character"); |
8d08fdba MS |
4383 | } |
4384 | else if (c == '\n') | |
4385 | { | |
4386 | if (pedantic) | |
8251199e | 4387 | pedwarn ("ANSI C++ forbids newline in string constant"); |
8d08fdba MS |
4388 | lineno++; |
4389 | } | |
0d3ba739 DB |
4390 | else |
4391 | { | |
4392 | #ifdef MULTIBYTE_CHARS | |
4393 | wchar_t wc; | |
4394 | int i; | |
4395 | int char_len = -1; | |
4396 | for (i = 0; i < longest_char; ++i) | |
4397 | { | |
ea6c1142 | 4398 | if (p + i >= token_buffer + maxtoken) |
0d3ba739 DB |
4399 | p = extend_token_buffer (p); |
4400 | p[i] = c; | |
4401 | ||
4402 | char_len = local_mbtowc (& wc, p, i + 1); | |
4403 | if (char_len != -1) | |
4404 | break; | |
66a6250f | 4405 | c = token_getch (); |
0d3ba739 DB |
4406 | } |
4407 | if (char_len == -1) | |
0d3ba739 | 4408 | { |
cd28936c DB |
4409 | warning ("Ignoring invalid multibyte character"); |
4410 | /* Replace all except the first byte. */ | |
66a6250f | 4411 | token_put_back (c); |
cd28936c | 4412 | for (--i; i > 0; --i) |
66a6250f | 4413 | token_put_back (p[i]); |
cd28936c DB |
4414 | char_len = 1; |
4415 | } | |
4416 | /* mbtowc sometimes needs an extra char before accepting */ | |
4417 | if (char_len <= i) | |
66a6250f | 4418 | token_put_back (c); |
cd28936c DB |
4419 | if (! wide_flag) |
4420 | { | |
4421 | p += (i + 1); | |
66a6250f | 4422 | c = token_getch (); |
cd28936c | 4423 | continue; |
0d3ba739 | 4424 | } |
cd28936c | 4425 | c = wc; |
0d3ba739 DB |
4426 | #endif /* MULTIBYTE_CHARS */ |
4427 | } | |
8d08fdba | 4428 | |
0d3ba739 DB |
4429 | /* Add this single character into the buffer either as a wchar_t |
4430 | or as a single byte. */ | |
4431 | if (wide_flag) | |
4432 | { | |
4433 | unsigned width = TYPE_PRECISION (char_type_node); | |
4434 | unsigned bytemask = (1 << width) - 1; | |
4435 | int byte; | |
4436 | ||
ea6c1142 | 4437 | if (p + WCHAR_BYTES > token_buffer + maxtoken) |
0d3ba739 DB |
4438 | p = extend_token_buffer (p); |
4439 | ||
4440 | for (byte = 0; byte < WCHAR_BYTES; ++byte) | |
4441 | { | |
4442 | int value; | |
1ceb5ff3 | 4443 | if (byte >= (int) sizeof (c)) |
0d3ba739 DB |
4444 | value = 0; |
4445 | else | |
4446 | value = (c >> (byte * width)) & bytemask; | |
4447 | if (BYTES_BIG_ENDIAN) | |
4448 | p[WCHAR_BYTES - byte - 1] = value; | |
4449 | else | |
4450 | p[byte] = value; | |
4451 | } | |
4452 | p += WCHAR_BYTES; | |
4453 | } | |
4454 | else | |
4455 | { | |
ea6c1142 | 4456 | if (p >= token_buffer + maxtoken) |
0d3ba739 DB |
4457 | p = extend_token_buffer (p); |
4458 | *p++ = c; | |
4459 | } | |
8d08fdba MS |
4460 | |
4461 | skipnewline: | |
66a6250f | 4462 | c = token_getch (); |
8d08fdba | 4463 | } |
8d08fdba | 4464 | |
0d3ba739 DB |
4465 | /* Terminate the string value, either with a single byte zero |
4466 | or with a wide zero. */ | |
8d08fdba MS |
4467 | if (wide_flag) |
4468 | { | |
ea6c1142 | 4469 | if (p + WCHAR_BYTES > token_buffer + maxtoken) |
0d3ba739 DB |
4470 | p = extend_token_buffer (p); |
4471 | bzero (p, WCHAR_BYTES); | |
4472 | p += WCHAR_BYTES; | |
8d08fdba MS |
4473 | } |
4474 | else | |
4475 | { | |
ea6c1142 | 4476 | if (p >= token_buffer + maxtoken) |
0d3ba739 DB |
4477 | p = extend_token_buffer (p); |
4478 | *p++ = 0; | |
8d08fdba MS |
4479 | } |
4480 | ||
1ceb5ff3 JM |
4481 | if (c == EOF) |
4482 | error ("Unterminated string constant"); | |
4483 | ||
0d3ba739 DB |
4484 | /* We have read the entire constant. |
4485 | Construct a STRING_CST for the result. */ | |
4486 | ||
4487 | if (processing_template_decl) | |
4488 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
4489 | yylval.ttype = build_string (p - (token_buffer + 1), token_buffer + 1); | |
4490 | if (processing_template_decl) | |
4491 | pop_obstacks (); | |
4492 | ||
4493 | if (wide_flag) | |
4494 | TREE_TYPE (yylval.ttype) = wchar_array_type_node; | |
4495 | else | |
4496 | TREE_TYPE (yylval.ttype) = char_array_type_node; | |
8d08fdba MS |
4497 | |
4498 | value = STRING; break; | |
4499 | } | |
4500 | ||
4501 | case '+': | |
4502 | case '-': | |
4503 | case '&': | |
4504 | case '|': | |
1ceb5ff3 | 4505 | case ':': |
8d08fdba MS |
4506 | case '<': |
4507 | case '>': | |
4508 | case '*': | |
4509 | case '/': | |
4510 | case '%': | |
4511 | case '^': | |
4512 | case '!': | |
4513 | case '=': | |
4514 | { | |
4515 | register int c1; | |
4516 | ||
4517 | combine: | |
4518 | ||
4519 | switch (c) | |
4520 | { | |
4521 | case '+': | |
4522 | yylval.code = PLUS_EXPR; break; | |
4523 | case '-': | |
4524 | yylval.code = MINUS_EXPR; break; | |
4525 | case '&': | |
4526 | yylval.code = BIT_AND_EXPR; break; | |
4527 | case '|': | |
4528 | yylval.code = BIT_IOR_EXPR; break; | |
4529 | case '*': | |
4530 | yylval.code = MULT_EXPR; break; | |
4531 | case '/': | |
4532 | yylval.code = TRUNC_DIV_EXPR; break; | |
4533 | case '%': | |
4534 | yylval.code = TRUNC_MOD_EXPR; break; | |
4535 | case '^': | |
4536 | yylval.code = BIT_XOR_EXPR; break; | |
4537 | case LSHIFT: | |
4538 | yylval.code = LSHIFT_EXPR; break; | |
4539 | case RSHIFT: | |
4540 | yylval.code = RSHIFT_EXPR; break; | |
4541 | case '<': | |
4542 | yylval.code = LT_EXPR; break; | |
4543 | case '>': | |
4544 | yylval.code = GT_EXPR; break; | |
4545 | } | |
4546 | ||
66a6250f | 4547 | token_buffer[1] = c1 = token_getch (); |
8d08fdba MS |
4548 | token_buffer[2] = 0; |
4549 | ||
4550 | if (c1 == '=') | |
4551 | { | |
4552 | switch (c) | |
4553 | { | |
4554 | case '<': | |
4555 | value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done; | |
4556 | case '>': | |
4557 | value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done; | |
4558 | case '!': | |
4559 | value = EQCOMPARE; yylval.code = NE_EXPR; goto done; | |
4560 | case '=': | |
4561 | value = EQCOMPARE; yylval.code = EQ_EXPR; goto done; | |
4562 | } | |
4563 | value = ASSIGN; goto done; | |
4564 | } | |
4565 | else if (c == c1) | |
4566 | switch (c) | |
4567 | { | |
4568 | case '+': | |
4569 | value = PLUSPLUS; goto done; | |
4570 | case '-': | |
4571 | value = MINUSMINUS; goto done; | |
4572 | case '&': | |
4573 | value = ANDAND; goto done; | |
4574 | case '|': | |
4575 | value = OROR; goto done; | |
4576 | case '<': | |
4577 | c = LSHIFT; | |
4578 | goto combine; | |
4579 | case '>': | |
4580 | c = RSHIFT; | |
4581 | goto combine; | |
1ceb5ff3 JM |
4582 | case ':': |
4583 | value = SCOPE; | |
4584 | yylval.itype = 1; | |
4585 | goto done; | |
8d08fdba | 4586 | } |
8d08fdba MS |
4587 | else if (c1 == '?' && (c == '<' || c == '>')) |
4588 | { | |
4589 | token_buffer[3] = 0; | |
4590 | ||
66a6250f | 4591 | c1 = token_getch (); |
8d08fdba MS |
4592 | yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR); |
4593 | if (c1 == '=') | |
4594 | { | |
4595 | /* <?= or >?= expression. */ | |
4596 | token_buffer[2] = c1; | |
4597 | value = ASSIGN; | |
4598 | } | |
4599 | else | |
4600 | { | |
4601 | value = MIN_MAX; | |
66a6250f | 4602 | token_put_back (c1); |
8d08fdba | 4603 | } |
e1cd6e56 | 4604 | if (pedantic) |
8251199e | 4605 | pedwarn ("use of `operator %s' is not standard C++", |
2986ae00 | 4606 | token_buffer); |
8d08fdba MS |
4607 | goto done; |
4608 | } | |
1ceb5ff3 JM |
4609 | else |
4610 | switch (c) | |
4611 | { | |
4612 | case '-': | |
4613 | if (c1 == '>') | |
4614 | { | |
4615 | c1 = token_getch (); | |
4616 | if (c1 == '*') | |
4617 | value = POINTSAT_STAR; | |
4618 | else | |
4619 | { | |
4620 | token_put_back (c1); | |
4621 | value = POINTSAT; | |
4622 | } | |
4623 | goto done; | |
4624 | } | |
4625 | break; | |
4626 | ||
4627 | /* digraphs */ | |
4628 | case ':': | |
4629 | if (c1 == '>') | |
4630 | { value = ']'; goto done; } | |
4631 | break; | |
4632 | case '<': | |
4633 | if (c1 == '%') | |
4634 | { value = '{'; indent_level++; goto done; } | |
4635 | if (c1 == ':') | |
4636 | { value = '['; goto done; } | |
4637 | break; | |
4638 | case '%': | |
4639 | if (c1 == '>') | |
4640 | { value = '}'; indent_level--; goto done; } | |
4641 | break; | |
4642 | } | |
8d08fdba | 4643 | |
66a6250f | 4644 | token_put_back (c1); |
8d08fdba MS |
4645 | token_buffer[1] = 0; |
4646 | ||
1ceb5ff3 JM |
4647 | /* Here the C frontend changes < and > to ARITHCOMPARE. We don't |
4648 | do that because of templates. */ | |
4649 | ||
8d08fdba | 4650 | value = c; |
1ceb5ff3 | 4651 | break; |
8d08fdba MS |
4652 | } |
4653 | ||
8d08fdba MS |
4654 | case 0: |
4655 | /* Don't make yyparse think this is eof. */ | |
4656 | value = 1; | |
4657 | break; | |
4658 | ||
1ceb5ff3 JM |
4659 | case '{': |
4660 | indent_level++; | |
4661 | value = c; | |
4662 | break; | |
4663 | ||
4664 | case '}': | |
4665 | indent_level--; | |
4666 | value = c; | |
4667 | break; | |
4668 | ||
8d08fdba MS |
4669 | default: |
4670 | value = c; | |
4671 | } | |
4672 | ||
4673 | done: | |
4674 | /* yylloc.last_line = lineno; */ | |
4675 | #ifdef GATHER_STATISTICS | |
72b7eeff | 4676 | #ifdef REDUCE_LENGTH |
8d08fdba | 4677 | token_count[value] += 1; |
72b7eeff | 4678 | #endif |
8d08fdba MS |
4679 | #endif |
4680 | ||
4681 | return value; | |
4682 | } | |
4683 | ||
be99da77 MS |
4684 | int |
4685 | is_rid (t) | |
4686 | tree t; | |
4687 | { | |
4688 | return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t)); | |
4689 | } | |
4690 | ||
5566b478 | 4691 | #ifdef GATHER_STATISTICS |
5156628f MS |
4692 | /* The original for tree_node_kind is in the toplevel tree.c; changes there |
4693 | need to be brought into here, unless this were actually put into a header | |
4694 | instead. */ | |
4695 | /* Statistics-gathering stuff. */ | |
4696 | typedef enum | |
4697 | { | |
4698 | d_kind, | |
4699 | t_kind, | |
4700 | b_kind, | |
4701 | s_kind, | |
4702 | r_kind, | |
4703 | e_kind, | |
4704 | c_kind, | |
4705 | id_kind, | |
4706 | op_id_kind, | |
4707 | perm_list_kind, | |
4708 | temp_list_kind, | |
4709 | vec_kind, | |
4710 | x_kind, | |
4711 | lang_decl, | |
4712 | lang_type, | |
4713 | all_kinds | |
4714 | } tree_node_kind; | |
4715 | ||
8d08fdba MS |
4716 | extern int tree_node_counts[]; |
4717 | extern int tree_node_sizes[]; | |
5566b478 | 4718 | #endif |
8d08fdba MS |
4719 | |
4720 | /* Place to save freed lang_decls which were allocated on the | |
9188c363 MM |
4721 | permanent_obstack. */ |
4722 | struct lang_decl *free_lang_decl_chain; | |
8d08fdba MS |
4723 | |
4724 | tree | |
4725 | build_lang_decl (code, name, type) | |
4726 | enum tree_code code; | |
4727 | tree name; | |
4728 | tree type; | |
4729 | { | |
4730 | register tree t = build_decl (code, name, type); | |
fcfcdfc8 JM |
4731 | retrofit_lang_decl (t); |
4732 | return t; | |
4733 | } | |
4734 | ||
4735 | /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl | |
4736 | and pushdecl (for functions generated by the backend). */ | |
4737 | ||
4738 | void | |
4739 | retrofit_lang_decl (t) | |
4740 | tree t; | |
4741 | { | |
8d08fdba | 4742 | struct obstack *obstack = current_obstack; |
9188c363 | 4743 | struct lang_decl *ld; |
8d08fdba MS |
4744 | |
4745 | if (! TREE_PERMANENT (t)) | |
4746 | obstack = saveable_obstack; | |
4747 | else | |
4748 | /* Could be that saveable is permanent and current is not. */ | |
4749 | obstack = &permanent_obstack; | |
4750 | ||
4751 | if (free_lang_decl_chain && obstack == &permanent_obstack) | |
4752 | { | |
9188c363 MM |
4753 | ld = free_lang_decl_chain; |
4754 | free_lang_decl_chain = free_lang_decl_chain->u.next; | |
8d08fdba MS |
4755 | } |
4756 | else | |
9188c363 MM |
4757 | ld = ((struct lang_decl *) |
4758 | obstack_alloc (obstack, sizeof (struct lang_decl))); | |
8d08fdba | 4759 | |
9188c363 | 4760 | bzero (ld, sizeof (struct lang_decl)); |
8d08fdba | 4761 | |
9188c363 MM |
4762 | DECL_LANG_SPECIFIC (t) = ld; |
4763 | LANG_DECL_PERMANENT (ld) = obstack == &permanent_obstack; | |
4764 | my_friendly_assert (LANG_DECL_PERMANENT (ld) == TREE_PERMANENT (t), 234); | |
8d08fdba MS |
4765 | DECL_MAIN_VARIANT (t) = t; |
4766 | if (current_lang_name == lang_name_cplusplus) | |
d22c8596 | 4767 | DECL_LANGUAGE (t) = lang_cplusplus; |
8d08fdba MS |
4768 | else if (current_lang_name == lang_name_c) |
4769 | DECL_LANGUAGE (t) = lang_c; | |
a1774733 BK |
4770 | else if (current_lang_name == lang_name_java) |
4771 | DECL_LANGUAGE (t) = lang_java; | |
8d08fdba MS |
4772 | else my_friendly_abort (64); |
4773 | ||
8d08fdba MS |
4774 | #ifdef GATHER_STATISTICS |
4775 | tree_node_counts[(int)lang_decl] += 1; | |
fc378698 | 4776 | tree_node_sizes[(int)lang_decl] += sizeof (struct lang_decl); |
8d08fdba | 4777 | #endif |
8d08fdba MS |
4778 | } |
4779 | ||
9188c363 MM |
4780 | /* Like build_decl, except that a new lang_decl_flags structure is |
4781 | placed in DECL_LANG_SPECIFIC. */ | |
4782 | ||
8d08fdba MS |
4783 | tree |
4784 | build_lang_field_decl (code, name, type) | |
4785 | enum tree_code code; | |
4786 | tree name; | |
4787 | tree type; | |
4788 | { | |
4789 | extern struct obstack *current_obstack, *saveable_obstack; | |
4790 | register tree t = build_decl (code, name, type); | |
4791 | struct obstack *obstack = current_obstack; | |
8d08fdba MS |
4792 | |
4793 | if (! TREE_PERMANENT (t)) | |
4794 | obstack = saveable_obstack; | |
4795 | else | |
4796 | my_friendly_assert (obstack == &permanent_obstack, 235); | |
4797 | ||
9188c363 MM |
4798 | DECL_LANG_SPECIFIC (t) |
4799 | = ((struct lang_decl *) | |
4800 | obstack_alloc (obstack, sizeof (struct lang_decl_flags))); | |
4801 | bzero (DECL_LANG_SPECIFIC (t), sizeof (struct lang_decl_flags)); | |
8d08fdba MS |
4802 | return t; |
4803 | } | |
4804 | ||
4805 | void | |
4806 | copy_lang_decl (node) | |
4807 | tree node; | |
4808 | { | |
4809 | int size; | |
4810 | int *pi; | |
4811 | ||
5566b478 MS |
4812 | if (! DECL_LANG_SPECIFIC (node)) |
4813 | return; | |
4814 | ||
8d08fdba MS |
4815 | if (TREE_CODE (node) == FIELD_DECL) |
4816 | size = sizeof (struct lang_decl_flags); | |
4817 | else | |
4818 | size = sizeof (struct lang_decl); | |
4819 | pi = (int *)obstack_alloc (&permanent_obstack, size); | |
4820 | bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)pi, size); | |
4821 | DECL_LANG_SPECIFIC (node) = (struct lang_decl *)pi; | |
4822 | } | |
4823 | ||
4824 | tree | |
4825 | make_lang_type (code) | |
4826 | enum tree_code code; | |
4827 | { | |
4828 | extern struct obstack *current_obstack, *saveable_obstack; | |
4829 | register tree t = make_node (code); | |
8d08fdba MS |
4830 | |
4831 | /* Set up some flags that give proper default behavior. */ | |
7ddedda4 MM |
4832 | if (IS_AGGR_TYPE_CODE (code)) |
4833 | { | |
4834 | struct obstack *obstack = current_obstack; | |
32201ce4 AS |
4835 | struct lang_type *pi; |
4836 | ||
7ddedda4 | 4837 | SET_IS_AGGR_TYPE (t, 1); |
8d08fdba | 4838 | |
7ddedda4 MM |
4839 | if (! TREE_PERMANENT (t)) |
4840 | obstack = saveable_obstack; | |
4841 | else | |
4842 | my_friendly_assert (obstack == &permanent_obstack, 236); | |
8d08fdba | 4843 | |
32201ce4 AS |
4844 | pi = (struct lang_type *) obstack_alloc (obstack, sizeof (struct lang_type)); |
4845 | bzero ((char *) pi, (int) sizeof (struct lang_type)); | |
8d08fdba | 4846 | |
32201ce4 | 4847 | TYPE_LANG_SPECIFIC (t) = pi; |
7ddedda4 MM |
4848 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown); |
4849 | CLASSTYPE_INTERFACE_ONLY (t) = interface_only; | |
8d08fdba | 4850 | |
7ddedda4 MM |
4851 | /* Make sure this is laid out, for ease of use later. In the |
4852 | presence of parse errors, the normal was of assuring this | |
4853 | might not ever get executed, so we lay it out *immediately*. */ | |
4854 | build_pointer_type (t); | |
8d08fdba MS |
4855 | |
4856 | #ifdef GATHER_STATISTICS | |
7ddedda4 MM |
4857 | tree_node_counts[(int)lang_type] += 1; |
4858 | tree_node_sizes[(int)lang_type] += sizeof (struct lang_type); | |
8d08fdba | 4859 | #endif |
7ddedda4 MM |
4860 | } |
4861 | else | |
4862 | /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But, | |
4863 | TYPE_ALIAS_SET is initialized to -1 by default, so we must | |
4864 | clear it here. */ | |
4865 | TYPE_ALIAS_SET (t) = 0; | |
8d08fdba | 4866 | |
f6a7cfd2 MM |
4867 | /* We need to allocate a TYPE_BINFO even for TEMPALTE_TYPE_PARMs |
4868 | since they can be virtual base types, and we then need a | |
4869 | canonical binfo for them. Ideally, this would be done lazily for | |
4870 | all types. */ | |
4871 | if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM) | |
4872 | TYPE_BINFO (t) = make_binfo (integer_zero_node, t, NULL_TREE, NULL_TREE); | |
4873 | ||
8d08fdba MS |
4874 | return t; |
4875 | } | |
4876 | ||
8d08fdba MS |
4877 | void |
4878 | dump_time_statistics () | |
4879 | { | |
4880 | register tree prev = 0, decl, next; | |
4881 | int this_time = my_get_run_time (); | |
f181d4ae | 4882 | TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time)) |
8d08fdba MS |
4883 | += this_time - body_time; |
4884 | ||
4885 | fprintf (stderr, "\n******\n"); | |
4886 | print_time ("header files (total)", header_time); | |
4887 | print_time ("main file (total)", this_time - body_time); | |
4888 | fprintf (stderr, "ratio = %g : 1\n", | |
4889 | (double)header_time / (double)(this_time - body_time)); | |
4890 | fprintf (stderr, "\n******\n"); | |
4891 | ||
4892 | for (decl = filename_times; decl; decl = next) | |
4893 | { | |
4894 | next = IDENTIFIER_GLOBAL_VALUE (decl); | |
2c73f9f5 | 4895 | SET_IDENTIFIER_GLOBAL_VALUE (decl, prev); |
8d08fdba MS |
4896 | prev = decl; |
4897 | } | |
4898 | ||
4899 | for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl)) | |
4900 | print_time (IDENTIFIER_POINTER (decl), | |
f181d4ae | 4901 | TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (decl))); |
8d08fdba MS |
4902 | } |
4903 | ||
4904 | void | |
d8e178a0 | 4905 | compiler_error VPROTO ((const char *msg, ...)) |
8d08fdba | 4906 | { |
d8e178a0 KG |
4907 | #ifndef ANSI_PROTOTYPES |
4908 | const char *msg; | |
4909 | #endif | |
8d08fdba | 4910 | char buf[1024]; |
d8e178a0 KG |
4911 | va_list ap; |
4912 | ||
4913 | VA_START (ap, msg); | |
4914 | ||
4915 | #ifndef ANSI_PROTOTYPES | |
4916 | msg = va_arg (ap, const char *); | |
4917 | #endif | |
4918 | ||
4919 | vsprintf (buf, msg, ap); | |
8d08fdba MS |
4920 | error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf); |
4921 | } | |
8d08fdba | 4922 | \f |
91063b51 MM |
4923 | /* Return the type-qualifier corresponding to the identifier given by |
4924 | RID. */ | |
4925 | ||
4926 | int | |
4927 | cp_type_qual_from_rid (rid) | |
4928 | tree rid; | |
4929 | { | |
4930 | if (rid == ridpointers[(int) RID_CONST]) | |
4931 | return TYPE_QUAL_CONST; | |
4932 | else if (rid == ridpointers[(int) RID_VOLATILE]) | |
4933 | return TYPE_QUAL_VOLATILE; | |
4934 | else if (rid == ridpointers[(int) RID_RESTRICT]) | |
4935 | return TYPE_QUAL_RESTRICT; | |
4936 | ||
4937 | my_friendly_abort (0); | |
4938 | return TYPE_UNQUALIFIED; | |
4939 | } |