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