Commit | Line | Data |
---|---|---|
9bf86ebb PR |
1 | /* Process declarations and variables for C compiler. |
2 | Copyright (C) 1988, 1992, 1993 Free Software Foundation, Inc. | |
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 | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | ||
22 | /* Process declarations and symbol lookup for C front end. | |
23 | Also constructs types; the standard scalar types at initialization, | |
24 | and structure, union, array and enum types when they are declared. */ | |
25 | ||
26 | /* ??? not all decl nodes are given the most useful possible | |
27 | line numbers. For example, the CONST_DECLs for enum values. */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include "config.h" | |
31 | #include "tree.h" | |
32 | #include "rtl.h" | |
33 | #include "flags.h" | |
34 | #include "cp-tree.h" | |
35 | #include "cp-decl.h" | |
36 | #include "cp-lex.h" | |
37 | #include <sys/types.h> | |
38 | #include <signal.h> | |
39 | #include "obstack.h" | |
40 | ||
41 | #define obstack_chunk_alloc xmalloc | |
42 | #define obstack_chunk_free free | |
43 | ||
44 | extern struct obstack permanent_obstack; | |
45 | ||
46 | /* Stack of places to restore the search obstack back to. */ | |
47 | ||
48 | /* Obstack used for remembering local class declarations (like | |
49 | enums and static (const) members. */ | |
50 | #include "stack.h" | |
51 | static struct obstack decl_obstack; | |
52 | static struct stack_level *decl_stack; | |
53 | ||
54 | #undef NULL | |
55 | #define NULL (char *)0 | |
56 | ||
57 | #ifndef CHAR_TYPE_SIZE | |
58 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
59 | #endif | |
60 | ||
61 | #ifndef SHORT_TYPE_SIZE | |
62 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) | |
63 | #endif | |
64 | ||
65 | #ifndef INT_TYPE_SIZE | |
66 | #define INT_TYPE_SIZE BITS_PER_WORD | |
67 | #endif | |
68 | ||
69 | #ifndef LONG_TYPE_SIZE | |
70 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
71 | #endif | |
72 | ||
73 | #ifndef LONG_LONG_TYPE_SIZE | |
74 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
75 | #endif | |
76 | ||
77 | #ifndef WCHAR_UNSIGNED | |
78 | #define WCHAR_UNSIGNED 0 | |
79 | #endif | |
80 | ||
81 | #ifndef FLOAT_TYPE_SIZE | |
82 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
83 | #endif | |
84 | ||
85 | #ifndef DOUBLE_TYPE_SIZE | |
86 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
87 | #endif | |
88 | ||
89 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
90 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
91 | #endif | |
92 | ||
93 | /* We let tm.h override the types used here, to handle trivial differences | |
94 | such as the choice of unsigned int or long unsigned int for size_t. | |
95 | When machines start needing nontrivial differences in the size type, | |
96 | it would be best to do something here to figure out automatically | |
97 | from other information what type to use. */ | |
98 | ||
99 | #ifndef SIZE_TYPE | |
100 | #define SIZE_TYPE "long unsigned int" | |
101 | #endif | |
102 | ||
103 | #ifndef PTRDIFF_TYPE | |
104 | #define PTRDIFF_TYPE "long int" | |
105 | #endif | |
106 | ||
107 | #ifndef WCHAR_TYPE | |
108 | #define WCHAR_TYPE "int" | |
109 | #endif | |
110 | ||
111 | #define builtin_function(NAME, TYPE, CODE, LIBNAME) \ | |
112 | define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME) | |
113 | #define auto_function(NAME, TYPE, CODE) \ | |
114 | do { \ | |
115 | tree __name = NAME; \ | |
116 | tree __type = TYPE; \ | |
117 | define_function (IDENTIFIER_POINTER (__name), __type, CODE, \ | |
118 | (void (*)())push_overloaded_decl_1, \ | |
119 | IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\ | |
120 | } while (0) | |
121 | ||
122 | static tree grokparms PROTO((tree, int)); | |
123 | static tree lookup_nested_type PROTO((tree, tree)); | |
124 | static char *redeclaration_error_message PROTO((tree, tree)); | |
125 | static int parmlist_is_random PROTO((tree)); | |
126 | static void grok_op_properties PROTO((tree, int)); | |
127 | static void expand_static_init PROTO((tree, tree)); | |
128 | static void deactivate_exception_cleanups PROTO((void)); | |
129 | ||
130 | tree define_function PROTO((char *, tree, enum built_in_function, void (*)(), char *)); | |
131 | ||
132 | /* a node which has tree code ERROR_MARK, and whose type is itself. | |
133 | All erroneous expressions are replaced with this node. All functions | |
134 | that accept nodes as arguments should avoid generating error messages | |
135 | if this node is one of the arguments, since it is undesirable to get | |
136 | multiple error messages from one error in the input. */ | |
137 | ||
138 | tree error_mark_node; | |
139 | ||
140 | /* Erroneous argument lists can use this *IFF* they do not modify it. */ | |
141 | tree error_mark_list; | |
142 | ||
143 | /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ | |
144 | ||
145 | tree short_integer_type_node; | |
146 | tree integer_type_node; | |
147 | tree long_integer_type_node; | |
148 | tree long_long_integer_type_node; | |
149 | ||
150 | tree short_unsigned_type_node; | |
151 | tree unsigned_type_node; | |
152 | tree long_unsigned_type_node; | |
153 | tree long_long_unsigned_type_node; | |
154 | ||
155 | tree ptrdiff_type_node; | |
156 | ||
157 | tree unsigned_char_type_node; | |
158 | tree signed_char_type_node; | |
159 | tree char_type_node; | |
160 | tree wchar_type_node; | |
161 | tree signed_wchar_type_node; | |
162 | tree unsigned_wchar_type_node; | |
163 | ||
164 | tree float_type_node; | |
165 | tree double_type_node; | |
166 | tree long_double_type_node; | |
167 | ||
168 | tree intQI_type_node; | |
169 | tree intHI_type_node; | |
170 | tree intSI_type_node; | |
171 | tree intDI_type_node; | |
172 | ||
173 | tree unsigned_intQI_type_node; | |
174 | tree unsigned_intHI_type_node; | |
175 | tree unsigned_intSI_type_node; | |
176 | tree unsigned_intDI_type_node; | |
177 | ||
178 | /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */ | |
179 | ||
180 | tree void_type_node, void_list_node; | |
181 | tree void_zero_node; | |
182 | ||
183 | /* Nodes for types `void *' and `const void *'. */ | |
184 | ||
185 | tree ptr_type_node, const_ptr_type_node; | |
186 | ||
187 | /* Nodes for types `char *' and `const char *'. */ | |
188 | ||
189 | tree string_type_node, const_string_type_node; | |
190 | ||
191 | /* Type `char[256]' or something like it. | |
192 | Used when an array of char is needed and the size is irrelevant. */ | |
193 | ||
194 | tree char_array_type_node; | |
195 | ||
196 | /* Type `int[256]' or something like it. | |
197 | Used when an array of int needed and the size is irrelevant. */ | |
198 | ||
199 | tree int_array_type_node; | |
200 | ||
201 | /* Type `wchar_t[256]' or something like it. | |
202 | Used when a wide string literal is created. */ | |
203 | ||
204 | tree wchar_array_type_node; | |
205 | ||
206 | /* type `int ()' -- used for implicit declaration of functions. */ | |
207 | ||
208 | tree default_function_type; | |
209 | ||
210 | /* function types `double (double)' and `double (double, double)', etc. */ | |
211 | ||
212 | tree double_ftype_double, double_ftype_double_double; | |
213 | tree int_ftype_int, long_ftype_long; | |
214 | ||
215 | /* Function type `void (void *, void *, int)' and similar ones. */ | |
216 | ||
217 | tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int; | |
218 | ||
219 | /* Function type `char *(char *, char *)' and similar ones */ | |
220 | tree string_ftype_ptr_ptr, int_ftype_string_string; | |
221 | ||
222 | /* Function type `size_t (const char *)' */ | |
223 | tree sizet_ftype_string; | |
224 | ||
225 | /* Function type `int (const void *, const void *, size_t)' */ | |
226 | tree int_ftype_cptr_cptr_sizet; | |
227 | ||
228 | /* C++ extensions */ | |
229 | tree vtable_entry_type; | |
230 | tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node; | |
231 | tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; | |
232 | tree class_star_type_node; | |
233 | tree class_type_node, record_type_node, union_type_node, enum_type_node; | |
234 | tree exception_type_node, unknown_type_node; | |
235 | tree maybe_gc_cleanup; | |
236 | ||
237 | /* Used for virtual function tables. */ | |
238 | tree vtbl_mask; | |
239 | ||
240 | /* Array type `(void *)[]' */ | |
241 | tree vtbl_type_node; | |
242 | ||
243 | /* Static decls which do not have static initializers have no | |
244 | initializers as far as GNU C is concerned. EMPTY_INIT_NODE | |
245 | is a static initializer which makes varasm code place the decl | |
246 | in data rather than in bss space. Such gymnastics are necessary | |
247 | to avoid the problem that the linker will not include a library | |
248 | file if all the library appears to contribute are bss variables. */ | |
249 | ||
250 | tree empty_init_node; | |
251 | ||
252 | /* In a destructor, the point at which all derived class destroying | |
253 | has been done, just before any base class destroying will be done. */ | |
254 | ||
255 | tree dtor_label; | |
256 | ||
257 | /* In a constructor, the point at which we are ready to return | |
258 | the pointer to the initialized object. */ | |
259 | ||
260 | tree ctor_label; | |
261 | ||
262 | /* A FUNCTION_DECL which can call `unhandled_exception'. | |
263 | Not necessarily the one that the user will declare, | |
264 | but sufficient to be called by routines that want to abort the program. */ | |
265 | ||
266 | tree unhandled_exception_fndecl; | |
267 | ||
268 | /* A FUNCTION_DECL which can call `abort'. Not necessarily the | |
269 | one that the user will declare, but sufficient to be called | |
270 | by routines that want to abort the program. */ | |
271 | ||
272 | tree abort_fndecl; | |
273 | ||
274 | extern rtx cleanup_label, return_label; | |
275 | ||
276 | /* If original DECL_RESULT of current function was a register, | |
277 | but due to being an addressable named return value, would up | |
278 | on the stack, this variable holds the named return value's | |
279 | original location. */ | |
280 | rtx original_result_rtx; | |
281 | ||
282 | /* Sequence of insns which represents base initialization. */ | |
283 | rtx base_init_insns; | |
284 | ||
285 | /* C++: Keep these around to reduce calls to `get_identifier'. | |
286 | Identifiers for `this' in member functions and the auto-delete | |
287 | parameter for destructors. */ | |
288 | tree this_identifier, in_charge_identifier; | |
289 | ||
290 | /* A list (chain of TREE_LIST nodes) of named label uses. | |
291 | The TREE_PURPOSE field is the list of variables defined | |
292 | the the label's scope defined at the point of use. | |
293 | The TREE_VALUE field is the LABEL_DECL used. | |
294 | The TREE_TYPE field holds `current_binding_level' at the | |
295 | point of the label's use. | |
296 | ||
297 | Used only for jumps to as-yet undefined labels, since | |
298 | jumps to defined labels can have their validity checked | |
299 | by stmt.c. */ | |
300 | ||
301 | static tree named_label_uses; | |
302 | ||
303 | /* A list of objects which have constructors or destructors | |
304 | which reside in the global scope. The decl is stored in | |
305 | the TREE_VALUE slot and the initializer is stored | |
306 | in the TREE_PURPOSE slot. */ | |
307 | tree static_aggregates; | |
308 | ||
309 | /* A list of functions which were declared inline, but later had their | |
310 | address taken. Used only for non-virtual member functions, since we can | |
311 | find other functions easily enough. */ | |
312 | tree pending_addressable_inlines; | |
313 | ||
314 | /* A list of overloaded functions which we should forget ever | |
315 | existed, such as functions declared in a function's scope, | |
316 | once we leave that function's scope. */ | |
317 | static tree overloads_to_forget; | |
318 | ||
319 | /* -- end of C++ */ | |
320 | ||
321 | /* Two expressions that are constants with value zero. | |
322 | The first is of type `int', the second of type `void *'. */ | |
323 | ||
324 | tree integer_zero_node; | |
325 | tree null_pointer_node; | |
326 | ||
327 | /* A node for the integer constants 1, 2, and 3. */ | |
328 | ||
329 | tree integer_one_node, integer_two_node, integer_three_node; | |
330 | ||
331 | /* Nonzero if we have seen an invalid cross reference | |
332 | to a struct, union, or enum, but not yet printed the message. */ | |
333 | ||
334 | tree pending_invalid_xref; | |
335 | /* File and line to appear in the eventual error message. */ | |
336 | char *pending_invalid_xref_file; | |
337 | int pending_invalid_xref_line; | |
338 | ||
339 | /* While defining an enum type, this is 1 plus the last enumerator | |
340 | constant value. */ | |
341 | ||
342 | static tree enum_next_value; | |
343 | ||
344 | /* Parsing a function declarator leaves a list of parameter names | |
345 | or a chain or parameter decls here. */ | |
346 | ||
347 | tree last_function_parms; | |
348 | ||
349 | /* Parsing a function declarator leaves here a chain of structure | |
350 | and enum types declared in the parmlist. */ | |
351 | ||
352 | static tree last_function_parm_tags; | |
353 | ||
354 | /* After parsing the declarator that starts a function definition, | |
355 | `start_function' puts here the list of parameter names or chain of decls. | |
356 | `store_parm_decls' finds it here. */ | |
357 | ||
358 | static tree current_function_parms; | |
359 | ||
360 | /* Similar, for last_function_parm_tags. */ | |
361 | static tree current_function_parm_tags; | |
362 | ||
363 | /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function | |
364 | that have names. Here so we can clear out their names' definitions | |
365 | at the end of the function. */ | |
366 | ||
367 | static tree named_labels; | |
368 | ||
369 | /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ | |
370 | ||
371 | static tree shadowed_labels; | |
372 | ||
373 | #if 0 /* Not needed by C++ */ | |
374 | /* Nonzero when store_parm_decls is called indicates a varargs function. | |
375 | Value not meaningful after store_parm_decls. */ | |
376 | ||
377 | static int c_function_varargs; | |
378 | #endif | |
379 | ||
380 | /* The FUNCTION_DECL for the function currently being compiled, | |
381 | or 0 if between functions. */ | |
382 | tree current_function_decl; | |
383 | ||
384 | /* Set to 0 at beginning of a function definition, set to 1 if | |
385 | a return statement that specifies a return value is seen. */ | |
386 | ||
387 | int current_function_returns_value; | |
388 | ||
389 | /* Set to 0 at beginning of a function definition, set to 1 if | |
390 | a return statement with no argument is seen. */ | |
391 | ||
392 | int current_function_returns_null; | |
393 | ||
394 | /* Set to 0 at beginning of a function definition, and whenever | |
395 | a label (case or named) is defined. Set to value of expression | |
396 | returned from function when that value can be transformed into | |
397 | a named return value. */ | |
398 | ||
399 | tree current_function_return_value; | |
400 | ||
401 | /* Nonzero means warn about multiple (redundant) decls for the same single | |
402 | variable or function. */ | |
403 | ||
404 | extern int warn_redundant_decls; | |
405 | ||
406 | /* Set to nonzero by `grokdeclarator' for a function | |
407 | whose return type is defaulted, if warnings for this are desired. */ | |
408 | ||
409 | static int warn_about_return_type; | |
410 | ||
411 | /* Nonzero when starting a function declared `extern inline'. */ | |
412 | ||
413 | static int current_extern_inline; | |
414 | ||
415 | /* Nonzero means give `double' the same size as `float'. */ | |
416 | ||
417 | extern int flag_short_double; | |
418 | ||
419 | /* Nonzero means don't recognize any builtin functions. */ | |
420 | ||
421 | extern int flag_no_builtin; | |
422 | ||
423 | /* Nonzero means do emit exported implementations of functions even if | |
424 | they can be inlined. */ | |
425 | ||
426 | extern int flag_implement_inlines; | |
427 | ||
428 | /* Nonzero means handle things in ANSI, instead of GNU fashion. This | |
429 | flag should be tested for language behavior that's different between | |
430 | ANSI and GNU, but not so horrible as to merit a PEDANTIC label. */ | |
431 | ||
432 | extern int flag_ansi; | |
433 | ||
434 | /* Pointers to the base and current top of the language name stack. */ | |
435 | ||
436 | extern tree *current_lang_base, *current_lang_stack; | |
437 | \f | |
438 | /* C and C++ flags are in cp-decl2.c. */ | |
439 | ||
440 | /* Set to 0 at beginning of a constructor, set to 1 | |
441 | if that function does an allocation before referencing its | |
442 | instance variable. */ | |
443 | int current_function_assigns_this; | |
444 | int current_function_just_assigned_this; | |
445 | ||
446 | /* Set to 0 at beginning of a function. Set non-zero when | |
447 | store_parm_decls is called. Don't call store_parm_decls | |
448 | if this flag is non-zero! */ | |
449 | int current_function_parms_stored; | |
450 | ||
451 | /* Current end of entries in the gc obstack for stack pointer variables. */ | |
452 | ||
453 | int current_function_obstack_index; | |
454 | ||
455 | /* Flag saying whether we have used the obstack in this function or not. */ | |
456 | ||
457 | int current_function_obstack_usage; | |
458 | ||
459 | /* Flag used when debugging cp-spew.c */ | |
460 | ||
461 | extern int spew_debug; | |
462 | \f | |
463 | /* Allocate a level of searching. */ | |
464 | struct stack_level * | |
465 | push_decl_level (stack, obstack) | |
466 | struct stack_level *stack; | |
467 | struct obstack *obstack; | |
468 | { | |
469 | struct stack_level tem; | |
470 | tem.prev = stack; | |
471 | ||
472 | return push_stack_level (obstack, (char *)&tem, sizeof (tem)); | |
473 | } | |
474 | ||
475 | /* Discard a level of decl allocation. */ | |
476 | ||
477 | static struct stack_level * | |
478 | pop_decl_level (stack) | |
479 | struct stack_level *stack; | |
480 | { | |
481 | tree *bp, *tp; | |
482 | struct obstack *obstack = stack->obstack; | |
483 | bp = stack->first; | |
484 | tp = (tree *)obstack_next_free (obstack); | |
485 | while (tp != bp) | |
486 | { | |
487 | --tp; | |
488 | if (*tp != NULL_TREE) | |
489 | IDENTIFIER_CLASS_VALUE (DECL_NAME (*tp)) = NULL_TREE; | |
490 | } | |
491 | return pop_stack_level (stack); | |
492 | } | |
493 | \f | |
494 | /* For each binding contour we allocate a binding_level structure | |
495 | * which records the names defined in that contour. | |
496 | * Contours include: | |
497 | * 0) the global one | |
498 | * 1) one for each function definition, | |
499 | * where internal declarations of the parameters appear. | |
500 | * 2) one for each compound statement, | |
501 | * to record its declarations. | |
502 | * | |
503 | * The current meaning of a name can be found by searching the levels from | |
504 | * the current one out to the global one. | |
505 | * | |
506 | * Off to the side, may be the class_binding_level. This exists | |
507 | * only to catch class-local declarations. It is otherwise | |
508 | * nonexistent. | |
509 | * | |
510 | * Also there may be binding levels that catch cleanups that | |
511 | * must be run when exceptions occur. | |
512 | */ | |
513 | ||
514 | /* Note that the information in the `names' component of the global contour | |
515 | is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ | |
516 | ||
517 | struct binding_level | |
518 | { | |
519 | /* A chain of _DECL nodes for all variables, constants, functions, | |
520 | * and typedef types. These are in the reverse of the order supplied. | |
521 | */ | |
522 | tree names; | |
523 | ||
524 | /* A list of structure, union and enum definitions, | |
525 | * for looking up tag names. | |
526 | * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, | |
527 | * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, | |
528 | * or ENUMERAL_TYPE node. | |
529 | * | |
530 | * C++: the TREE_VALUE nodes can be simple types for component_bindings. | |
531 | * | |
532 | */ | |
533 | tree tags; | |
534 | ||
535 | /* For each level, a list of shadowed outer-level local definitions | |
536 | to be restored when this level is popped. | |
537 | Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and | |
538 | whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ | |
539 | tree shadowed; | |
540 | ||
541 | /* Same, for IDENTIFIER_CLASS_VALUE. */ | |
542 | tree class_shadowed; | |
543 | ||
544 | /* Same, for IDENTIFIER_TYPE_VALUE. */ | |
545 | tree type_shadowed; | |
546 | ||
547 | /* For each level (except not the global one), | |
548 | a chain of BLOCK nodes for all the levels | |
549 | that were entered and exited one level down. */ | |
550 | tree blocks; | |
551 | ||
552 | /* The BLOCK node for this level, if one has been preallocated. | |
553 | If 0, the BLOCK is allocated (if needed) when the level is popped. */ | |
554 | tree this_block; | |
555 | ||
556 | /* The binding level which this one is contained in (inherits from). */ | |
557 | struct binding_level *level_chain; | |
558 | ||
559 | /* Number of decls in `names' that have incomplete | |
560 | structure or union types. */ | |
561 | unsigned short n_incomplete; | |
562 | ||
563 | /* 1 for the level that holds the parameters of a function. | |
564 | 2 for the level that holds a class declaration. | |
565 | 3 for levels that hold parameter declarations. */ | |
566 | unsigned parm_flag : 4; | |
567 | ||
568 | /* 1 means make a BLOCK for this level regardless of all else. | |
569 | 2 for temporary binding contours created by the compiler. */ | |
570 | unsigned keep : 3; | |
571 | ||
572 | /* Nonzero if this level "doesn't exist" for tags. */ | |
573 | unsigned tag_transparent : 1; | |
574 | ||
575 | /* Nonzero if this level can safely have additional | |
576 | cleanup-needing variables added to it. */ | |
577 | unsigned more_cleanups_ok : 1; | |
578 | unsigned have_cleanups : 1; | |
579 | ||
580 | /* Nonzero if this level can safely have additional | |
581 | exception-raising statements added to it. */ | |
582 | unsigned more_exceptions_ok : 1; | |
583 | unsigned have_exceptions : 1; | |
584 | ||
585 | /* Nonzero if we should accept any name as an identifier in | |
586 | this scope. This happens in some template definitions. */ | |
587 | unsigned accept_any : 1; | |
588 | ||
589 | /* Nonzero if this level is for completing a template class definition | |
590 | inside a binding level that temporarily binds the parameters. This | |
591 | means that definitions here should not be popped off when unwinding | |
592 | this binding level. (Not actually implemented this way, | |
593 | unfortunately.) */ | |
594 | unsigned pseudo_global : 1; | |
595 | ||
596 | /* Two bits left for this word. */ | |
597 | ||
598 | #if PARANOID | |
599 | unsigned char depth; | |
600 | #endif | |
601 | }; | |
602 | ||
603 | #define NULL_BINDING_LEVEL (struct binding_level *) NULL | |
604 | ||
605 | /* The binding level currently in effect. */ | |
606 | ||
607 | static struct binding_level *current_binding_level; | |
608 | ||
609 | /* The binding level of the current class, if any. */ | |
610 | ||
611 | static struct binding_level *class_binding_level; | |
612 | ||
613 | /* A chain of binding_level structures awaiting reuse. */ | |
614 | ||
615 | static struct binding_level *free_binding_level; | |
616 | ||
617 | /* The outermost binding level, for names of file scope. | |
618 | This is created when the compiler is started and exists | |
619 | through the entire run. */ | |
620 | ||
621 | static struct binding_level *global_binding_level; | |
622 | ||
623 | /* Binding level structures are initialized by copying this one. */ | |
624 | ||
625 | static struct binding_level clear_binding_level; | |
626 | ||
627 | /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ | |
628 | ||
629 | static int keep_next_level_flag; | |
630 | ||
631 | #if PARANOID | |
632 | /* Perform sanity checking on binding levels. Normally not needed. */ | |
633 | void | |
634 | binding_levels_sane () | |
635 | { | |
636 | struct binding_level *b = current_binding_level; | |
637 | static int n; | |
638 | if (++n < 3) | |
639 | return; | |
640 | my_friendly_assert (global_binding_level != 0, 126); | |
641 | my_friendly_assert (current_binding_level != 0, 127); | |
642 | for (b = current_binding_level; b != global_binding_level; b = b->level_chain) | |
643 | { | |
644 | my_friendly_assert (b->level_chain != 0, 128); | |
645 | my_friendly_assert (b->depth == 1 + b->level_chain->depth, 129); | |
646 | } | |
647 | if (class_binding_level) | |
648 | for (b = class_binding_level; | |
649 | b != global_binding_level && b != current_binding_level; | |
650 | b = b->level_chain) | |
651 | { | |
652 | my_friendly_assert (b->level_chain != 0, 130); | |
653 | my_friendly_assert (b->depth == 1 + b->level_chain->depth, 131); | |
654 | } | |
655 | my_friendly_assert (global_binding_level->depth == 0, 132); | |
656 | my_friendly_assert (global_binding_level->level_chain == 0, 133); | |
657 | return; | |
658 | } | |
659 | ||
660 | #else | |
661 | #define binding_levels_sane() ((void)(1)) | |
662 | #endif | |
663 | ||
664 | #ifdef DEBUG_CP_BINDING_LEVELS | |
665 | int debug_bindings_indentation; | |
666 | #endif | |
667 | ||
668 | static void | |
669 | #if !PARANOID && defined (__GNUC__) | |
670 | __inline | |
671 | #endif | |
672 | push_binding_level (newlevel, tag_transparent, keep) | |
673 | struct binding_level *newlevel; | |
674 | int tag_transparent, keep; | |
675 | { | |
676 | binding_levels_sane(); | |
677 | /* Add this level to the front of the chain (stack) of levels that | |
678 | are active. */ | |
679 | #ifdef DEBUG_CP_BINDING_LEVELS | |
680 | indent_to (stderr, debug_bindings_indentation); | |
681 | fprintf (stderr, "pushing binding level "); | |
682 | fprintf (stderr, HOST_PTR_PRINTF, newlevel); | |
683 | fprintf (stderr, "\n"); | |
684 | #endif | |
685 | *newlevel = clear_binding_level; | |
686 | if (class_binding_level) | |
687 | { | |
688 | newlevel->level_chain = class_binding_level; | |
689 | class_binding_level = (struct binding_level *)0; | |
690 | } | |
691 | else | |
692 | { | |
693 | newlevel->level_chain = current_binding_level; | |
694 | } | |
695 | current_binding_level = newlevel; | |
696 | newlevel->tag_transparent = tag_transparent; | |
697 | newlevel->more_cleanups_ok = 1; | |
698 | newlevel->more_exceptions_ok = 1; | |
699 | newlevel->keep = keep; | |
700 | #if PARANOID | |
701 | newlevel->depth = (newlevel->level_chain | |
702 | ? newlevel->level_chain->depth + 1 | |
703 | : 0); | |
704 | #endif | |
705 | binding_levels_sane(); | |
706 | } | |
707 | ||
708 | static void | |
709 | #if !PARANOID && defined (__GNUC__) | |
710 | __inline | |
711 | #endif | |
712 | pop_binding_level () | |
713 | { | |
714 | binding_levels_sane(); | |
715 | #ifdef DEBUG_CP_BINDING_LEVELS | |
716 | indent_to (stderr, debug_bindings_indentation); | |
717 | fprintf (stderr, "popping binding level "); | |
718 | fprintf (stderr, HOST_PTR_PRINTF, current_binding_level); | |
719 | fprintf (stderr, "\n"); | |
720 | #endif | |
721 | if (global_binding_level) | |
722 | { | |
723 | /* cannot pop a level, if there are none left to pop. */ | |
724 | if (current_binding_level == global_binding_level) | |
725 | my_friendly_abort (123); | |
726 | } | |
727 | /* Pop the current level, and free the structure for reuse. */ | |
728 | { | |
729 | register struct binding_level *level = current_binding_level; | |
730 | current_binding_level = current_binding_level->level_chain; | |
731 | level->level_chain = free_binding_level; | |
732 | #ifdef DEBUG_CP_BINDING_LEVELS | |
733 | memset (level, 0x69, sizeof (*level)); | |
734 | #else | |
735 | free_binding_level = level; | |
736 | #if PARANOID | |
737 | level->depth = ~0; /* ~0 assumes that the depth is unsigned. */ | |
738 | #endif | |
739 | #endif | |
740 | if (current_binding_level->parm_flag == 2) | |
741 | { | |
742 | class_binding_level = current_binding_level; | |
743 | do | |
744 | { | |
745 | current_binding_level = current_binding_level->level_chain; | |
746 | } | |
747 | while (current_binding_level->parm_flag == 2); | |
748 | } | |
749 | } | |
750 | binding_levels_sane(); | |
751 | } | |
752 | \f | |
753 | /* Nonzero if we are currently in the global binding level. */ | |
754 | ||
755 | int | |
756 | global_bindings_p () | |
757 | { | |
758 | return current_binding_level == global_binding_level; | |
759 | } | |
760 | ||
761 | void | |
762 | keep_next_level () | |
763 | { | |
764 | keep_next_level_flag = 1; | |
765 | } | |
766 | ||
767 | /* Nonzero if the current level needs to have a BLOCK made. */ | |
768 | ||
769 | int | |
770 | kept_level_p () | |
771 | { | |
772 | return (current_binding_level->blocks != NULL_TREE | |
773 | || current_binding_level->keep | |
774 | || current_binding_level->names != NULL_TREE | |
775 | || (current_binding_level->tags != NULL_TREE | |
776 | && !current_binding_level->tag_transparent)); | |
777 | } | |
778 | ||
779 | /* Identify this binding level as a level of parameters. */ | |
780 | ||
781 | void | |
782 | declare_parm_level () | |
783 | { | |
784 | current_binding_level->parm_flag = 1; | |
785 | } | |
786 | ||
787 | /* Identify this binding level as a level of a default exception handler. */ | |
788 | ||
789 | void | |
790 | declare_implicit_exception () | |
791 | { | |
792 | current_binding_level->parm_flag = 3; | |
793 | } | |
794 | ||
795 | /* Nonzero if current binding contour contains expressions | |
796 | that might raise exceptions. */ | |
797 | ||
798 | int | |
799 | have_exceptions_p () | |
800 | { | |
801 | return current_binding_level->have_exceptions; | |
802 | } | |
803 | ||
804 | void | |
805 | declare_uninstantiated_type_level () | |
806 | { | |
807 | current_binding_level->accept_any = 1; | |
808 | } | |
809 | ||
810 | int | |
811 | uninstantiated_type_level_p () | |
812 | { | |
813 | return current_binding_level->accept_any; | |
814 | } | |
815 | ||
816 | void | |
817 | declare_pseudo_global_level () | |
818 | { | |
819 | current_binding_level->pseudo_global = 1; | |
820 | } | |
821 | ||
822 | int | |
823 | pseudo_global_level_p () | |
824 | { | |
825 | return current_binding_level->pseudo_global; | |
826 | } | |
827 | ||
828 | /* Enter a new binding level. | |
829 | If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, | |
830 | not for that of tags. */ | |
831 | ||
832 | void | |
833 | pushlevel (tag_transparent) | |
834 | int tag_transparent; | |
835 | { | |
836 | register struct binding_level *newlevel = NULL_BINDING_LEVEL; | |
837 | ||
838 | #ifdef DEBUG_CP_BINDING_LEVELS | |
839 | indent_to (stderr, debug_bindings_indentation); | |
840 | fprintf (stderr, "pushlevel"); | |
841 | debug_bindings_indentation += 4; | |
842 | #endif | |
843 | ||
844 | /* If this is the top level of a function, | |
845 | just make sure that NAMED_LABELS is 0. | |
846 | They should have been set to 0 at the end of the previous function. */ | |
847 | ||
848 | if (current_binding_level == global_binding_level) | |
849 | my_friendly_assert (named_labels == NULL_TREE, 134); | |
850 | ||
851 | /* Reuse or create a struct for this binding level. */ | |
852 | ||
853 | if (free_binding_level) | |
854 | { | |
855 | newlevel = free_binding_level; | |
856 | free_binding_level = free_binding_level->level_chain; | |
857 | } | |
858 | else | |
859 | { | |
860 | /* Create a new `struct binding_level'. */ | |
861 | newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level)); | |
862 | } | |
863 | push_binding_level (newlevel, tag_transparent, keep_next_level_flag); | |
864 | GNU_xref_start_scope ((int) newlevel); | |
865 | keep_next_level_flag = 0; | |
866 | ||
867 | #ifdef DEBUG_CP_BINDING_LEVELS | |
868 | debug_bindings_indentation -= 4; | |
869 | #endif | |
870 | } | |
871 | ||
872 | void | |
873 | pushlevel_temporary (tag_transparent) | |
874 | int tag_transparent; | |
875 | { | |
876 | pushlevel (tag_transparent); | |
877 | current_binding_level->keep = 2; | |
878 | clear_last_expr (); | |
879 | ||
880 | /* Note we don't call push_momentary() here. Otherwise, it would cause | |
881 | cleanups to be allocated on the momentary obstack, and they will be | |
882 | overwritten by the next statement. */ | |
883 | ||
884 | expand_start_bindings (0); | |
885 | } | |
886 | ||
887 | /* Exit a binding level. | |
888 | Pop the level off, and restore the state of the identifier-decl mappings | |
889 | that were in effect when this level was entered. | |
890 | ||
891 | If KEEP == 1, this level had explicit declarations, so | |
892 | and create a "block" (a BLOCK node) for the level | |
893 | to record its declarations and subblocks for symbol table output. | |
894 | ||
895 | If KEEP == 2, this level's subblocks go to the front, | |
896 | not the back of the current binding level. This happens, | |
897 | for instance, when code for constructors and destructors | |
898 | need to generate code at the end of a function which must | |
899 | be moved up to the front of the function. | |
900 | ||
901 | If FUNCTIONBODY is nonzero, this level is the body of a function, | |
902 | so create a block as if KEEP were set and also clear out all | |
903 | label names. | |
904 | ||
905 | If REVERSE is nonzero, reverse the order of decls before putting | |
906 | them into the BLOCK. */ | |
907 | ||
908 | tree | |
909 | poplevel (keep, reverse, functionbody) | |
910 | int keep; | |
911 | int reverse; | |
912 | int functionbody; | |
913 | { | |
914 | register tree link; | |
915 | /* The chain of decls was accumulated in reverse order. | |
916 | Put it into forward order, just for cleanliness. */ | |
917 | tree decls; | |
918 | int tmp = functionbody; | |
919 | int implicit_try_block = current_binding_level->parm_flag == 3; | |
920 | int real_functionbody = current_binding_level->keep == 2 | |
921 | ? ((functionbody = 0), tmp) : functionbody; | |
922 | tree tags = functionbody >= 0 ? current_binding_level->tags : 0; | |
923 | tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; | |
924 | tree block = NULL_TREE; | |
925 | tree decl; | |
926 | int block_previously_created; | |
927 | ||
928 | #ifdef DEBUG_CP_BINDING_LEVELS | |
929 | indent_to (stderr, debug_bindings_indentation); | |
930 | fprintf (stderr, "poplevel"); | |
931 | debug_bindings_indentation += 4; | |
932 | #endif | |
933 | ||
934 | binding_levels_sane(); | |
935 | GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, | |
936 | (HOST_WIDE_INT) current_binding_level->level_chain, | |
937 | current_binding_level->parm_flag, | |
938 | current_binding_level->keep, | |
939 | current_binding_level->tag_transparent); | |
940 | ||
941 | if (current_binding_level->keep == 1) | |
942 | keep = 1; | |
943 | ||
944 | /* This warning is turned off because it causes warnings for | |
945 | declarations like `extern struct foo *x'. */ | |
946 | #if 0 | |
947 | /* Warn about incomplete structure types in this level. */ | |
948 | for (link = tags; link; link = TREE_CHAIN (link)) | |
949 | if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE) | |
950 | { | |
951 | tree type = TREE_VALUE (link); | |
952 | char *errmsg; | |
953 | switch (TREE_CODE (type)) | |
954 | { | |
955 | case RECORD_TYPE: | |
956 | errmsg = "`struct %s' incomplete in scope ending here"; | |
957 | break; | |
958 | case UNION_TYPE: | |
959 | errmsg = "`union %s' incomplete in scope ending here"; | |
960 | break; | |
961 | case ENUMERAL_TYPE: | |
962 | errmsg = "`enum %s' incomplete in scope ending here"; | |
963 | break; | |
964 | } | |
965 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
966 | error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type))); | |
967 | else | |
968 | /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ | |
969 | error (errmsg, TYPE_NAME_STRING (type)); | |
970 | } | |
971 | #endif /* 0 */ | |
972 | ||
973 | /* Get the decls in the order they were written. | |
974 | Usually current_binding_level->names is in reverse order. | |
975 | But parameter decls were previously put in forward order. */ | |
976 | ||
977 | if (reverse) | |
978 | current_binding_level->names | |
979 | = decls = nreverse (current_binding_level->names); | |
980 | else | |
981 | decls = current_binding_level->names; | |
982 | ||
983 | /* Output any nested inline functions within this block | |
984 | if they weren't already output. */ | |
985 | ||
986 | for (decl = decls; decl; decl = TREE_CHAIN (decl)) | |
987 | if (TREE_CODE (decl) == FUNCTION_DECL | |
988 | && ! TREE_ASM_WRITTEN (decl) | |
989 | && DECL_INITIAL (decl) != NULL_TREE | |
990 | && TREE_ADDRESSABLE (decl)) | |
991 | { | |
992 | /* If this decl was copied from a file-scope decl | |
993 | on account of a block-scope extern decl, | |
994 | propagate TREE_ADDRESSABLE to the file-scope decl. */ | |
995 | if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) | |
996 | TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; | |
997 | else | |
998 | output_inline_function (decl); | |
999 | } | |
1000 | ||
1001 | /* If there were any declarations or structure tags in that level, | |
1002 | or if this level is a function body, | |
1003 | create a BLOCK to record them for the life of this function. */ | |
1004 | ||
1005 | block = NULL_TREE; | |
1006 | block_previously_created = (current_binding_level->this_block != NULL_TREE); | |
1007 | if (block_previously_created) | |
1008 | block = current_binding_level->this_block; | |
1009 | else if (keep == 1 || functionbody) | |
1010 | block = make_node (BLOCK); | |
1011 | if (block != NULL_TREE) | |
1012 | { | |
1013 | BLOCK_VARS (block) = decls; | |
1014 | BLOCK_TYPE_TAGS (block) = tags; | |
1015 | BLOCK_SUBBLOCKS (block) = subblocks; | |
1016 | remember_end_note (block); | |
1017 | } | |
1018 | ||
1019 | /* In each subblock, record that this is its superior. */ | |
1020 | ||
1021 | if (keep >= 0) | |
1022 | for (link = subblocks; link; link = TREE_CHAIN (link)) | |
1023 | BLOCK_SUPERCONTEXT (link) = block; | |
1024 | ||
1025 | /* Clear out the meanings of the local variables of this level. */ | |
1026 | ||
1027 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1028 | { | |
1029 | if (DECL_NAME (link) != NULL_TREE) | |
1030 | { | |
1031 | /* If the ident. was used or addressed via a local extern decl, | |
1032 | don't forget that fact. */ | |
1033 | if (DECL_EXTERNAL (link)) | |
1034 | { | |
1035 | if (TREE_USED (link)) | |
1036 | TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; | |
1037 | if (TREE_ADDRESSABLE (link)) | |
1038 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1039 | } | |
1040 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
1041 | } | |
1042 | } | |
1043 | ||
1044 | /* Restore all name-meanings of the outer levels | |
1045 | that were shadowed by this level. */ | |
1046 | ||
1047 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1048 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1049 | for (link = current_binding_level->class_shadowed; | |
1050 | link; link = TREE_CHAIN (link)) | |
1051 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1052 | for (link = current_binding_level->type_shadowed; | |
1053 | link; link = TREE_CHAIN (link)) | |
1054 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1055 | ||
1056 | /* If the level being exited is the top level of a function, | |
1057 | check over all the labels. */ | |
1058 | ||
1059 | if (functionbody) | |
1060 | { | |
1061 | /* If this is the top level block of a function, | |
1062 | the vars are the function's parameters. | |
1063 | Don't leave them in the BLOCK because they are | |
1064 | found in the FUNCTION_DECL instead. */ | |
1065 | ||
1066 | BLOCK_VARS (block) = 0; | |
1067 | ||
1068 | /* Clear out the definitions of all label names, | |
1069 | since their scopes end here. */ | |
1070 | ||
1071 | for (link = named_labels; link; link = TREE_CHAIN (link)) | |
1072 | { | |
1073 | register tree label = TREE_VALUE (link); | |
1074 | ||
1075 | if (DECL_INITIAL (label) == NULL_TREE) | |
1076 | { | |
1077 | error_with_decl (label, "label `%s' used but not defined"); | |
1078 | /* Avoid crashing later. */ | |
1079 | define_label (input_filename, 1, DECL_NAME (label)); | |
1080 | } | |
1081 | else if (warn_unused && !TREE_USED (label)) | |
1082 | warning_with_decl (label, | |
1083 | "label `%s' defined but not used"); | |
1084 | SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), 0); | |
1085 | ||
1086 | /* Put the labels into the "variables" of the | |
1087 | top-level block, so debugger can see them. */ | |
1088 | TREE_CHAIN (label) = BLOCK_VARS (block); | |
1089 | BLOCK_VARS (block) = label; | |
1090 | } | |
1091 | ||
1092 | named_labels = NULL_TREE; | |
1093 | } | |
1094 | ||
1095 | /* Any uses of undefined labels now operate under constraints | |
1096 | of next binding contour. */ | |
1097 | { | |
1098 | struct binding_level *level_chain; | |
1099 | level_chain = current_binding_level->level_chain; | |
1100 | if (level_chain) | |
1101 | { | |
1102 | tree labels; | |
1103 | for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels)) | |
1104 | if (TREE_TYPE (labels) == (tree)current_binding_level) | |
1105 | { | |
1106 | TREE_TYPE (labels) = (tree)level_chain; | |
1107 | TREE_PURPOSE (labels) = level_chain->names; | |
1108 | } | |
1109 | } | |
1110 | } | |
1111 | ||
1112 | tmp = current_binding_level->keep; | |
1113 | ||
1114 | pop_binding_level (); | |
1115 | if (functionbody) | |
1116 | DECL_INITIAL (current_function_decl) = block; | |
1117 | else if (block) | |
1118 | { | |
1119 | if (!block_previously_created) | |
1120 | current_binding_level->blocks | |
1121 | = chainon (current_binding_level->blocks, block); | |
1122 | } | |
1123 | ||
1124 | /* If we did not make a block for the level just exited, | |
1125 | any blocks made for inner levels | |
1126 | (since they cannot be recorded as subblocks in that level) | |
1127 | must be carried forward so they will later become subblocks | |
1128 | of something else. */ | |
1129 | else if (subblocks) | |
1130 | if (keep == 2) | |
1131 | current_binding_level->blocks = chainon (subblocks, current_binding_level->blocks); | |
1132 | else | |
1133 | current_binding_level->blocks | |
1134 | = chainon (current_binding_level->blocks, subblocks); | |
1135 | ||
1136 | /* Take care of compiler's internal binding structures. */ | |
1137 | if (tmp == 2 && !implicit_try_block) | |
1138 | { | |
1139 | #if 0 | |
1140 | /* We did not call push_momentary for this | |
1141 | binding contour, so there is nothing to pop. */ | |
1142 | pop_momentary (); | |
1143 | #endif | |
1144 | expand_end_bindings (getdecls (), keep, 1); | |
1145 | block = poplevel (keep, reverse, real_functionbody); | |
1146 | } | |
1147 | if (block) | |
1148 | TREE_USED (block) = 1; | |
1149 | binding_levels_sane(); | |
1150 | #ifdef DEBUG_CP_BINDING_LEVELS | |
1151 | debug_bindings_indentation -= 4; | |
1152 | #endif | |
1153 | return block; | |
1154 | } | |
1155 | ||
1156 | /* Delete the node BLOCK from the current binding level. | |
1157 | This is used for the block inside a stmt expr ({...}) | |
1158 | so that the block can be reinserted where appropriate. */ | |
1159 | ||
1160 | void | |
1161 | delete_block (block) | |
1162 | tree block; | |
1163 | { | |
1164 | tree t; | |
1165 | if (current_binding_level->blocks == block) | |
1166 | current_binding_level->blocks = TREE_CHAIN (block); | |
1167 | for (t = current_binding_level->blocks; t;) | |
1168 | { | |
1169 | if (TREE_CHAIN (t) == block) | |
1170 | TREE_CHAIN (t) = TREE_CHAIN (block); | |
1171 | else | |
1172 | t = TREE_CHAIN (t); | |
1173 | } | |
1174 | TREE_CHAIN (block) = NULL_TREE; | |
1175 | /* Clear TREE_USED which is always set by poplevel. | |
1176 | The flag is set again if insert_block is called. */ | |
1177 | TREE_USED (block) = 0; | |
1178 | } | |
1179 | ||
1180 | /* Insert BLOCK at the end of the list of subblocks of the | |
1181 | current binding level. This is used when a BIND_EXPR is expanded, | |
1182 | to handle the BLOCK node inside the BIND_EXPR. */ | |
1183 | ||
1184 | void | |
1185 | insert_block (block) | |
1186 | tree block; | |
1187 | { | |
1188 | TREE_USED (block) = 1; | |
1189 | current_binding_level->blocks | |
1190 | = chainon (current_binding_level->blocks, block); | |
1191 | } | |
1192 | ||
1193 | /* Add BLOCK to the current list of blocks for this binding contour. */ | |
1194 | void | |
1195 | add_block_current_level (block) | |
1196 | tree block; | |
1197 | { | |
1198 | current_binding_level->blocks | |
1199 | = chainon (current_binding_level->blocks, block); | |
1200 | } | |
1201 | ||
1202 | /* Set the BLOCK node for the innermost scope | |
1203 | (the one we are currently in). */ | |
1204 | ||
1205 | void | |
1206 | set_block (block) | |
1207 | register tree block; | |
1208 | { | |
1209 | current_binding_level->this_block = block; | |
1210 | } | |
1211 | ||
1212 | /* Do a pushlevel for class declarations. */ | |
1213 | void | |
1214 | pushlevel_class () | |
1215 | { | |
1216 | binding_levels_sane(); | |
1217 | #ifdef DEBUG_CP_BINDING_LEVELS | |
1218 | indent_to (stderr, debug_bindings_indentation); | |
1219 | fprintf (stderr, "pushlevel_class"); | |
1220 | debug_bindings_indentation += 4; | |
1221 | #endif | |
1222 | pushlevel (0); | |
1223 | decl_stack = push_decl_level (decl_stack, &decl_obstack); | |
1224 | class_binding_level = current_binding_level; | |
1225 | class_binding_level->parm_flag = 2; | |
1226 | do | |
1227 | { | |
1228 | current_binding_level = current_binding_level->level_chain; | |
1229 | } | |
1230 | while (current_binding_level->parm_flag == 2); | |
1231 | binding_levels_sane(); | |
1232 | #ifdef DEBUG_CP_BINDING_LEVELS | |
1233 | debug_bindings_indentation -= 4; | |
1234 | #endif | |
1235 | } | |
1236 | ||
1237 | /* ...and a poplevel for class declarations. */ | |
1238 | tree | |
1239 | poplevel_class () | |
1240 | { | |
1241 | register struct binding_level *level = class_binding_level; | |
1242 | tree block = NULL_TREE; | |
1243 | tree shadowed; | |
1244 | ||
1245 | #ifdef DEBUG_CP_BINDING_LEVELS | |
1246 | indent_to (stderr, debug_bindings_indentation); | |
1247 | fprintf (stderr, "poplevel_class"); | |
1248 | debug_bindings_indentation += 4; | |
1249 | #endif | |
1250 | binding_levels_sane(); | |
1251 | if (level == (struct binding_level *)0) | |
1252 | { | |
1253 | while (current_binding_level && class_binding_level == (struct binding_level *)0) | |
1254 | block = poplevel (0, 0, 0); | |
1255 | if (current_binding_level == (struct binding_level *)0) | |
1256 | fatal ("syntax error too serious"); | |
1257 | level = class_binding_level; | |
1258 | } | |
1259 | decl_stack = pop_decl_level (decl_stack); | |
1260 | for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
1261 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1262 | for (shadowed = level->class_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
1263 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1264 | for (shadowed = level->type_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
1265 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1266 | ||
1267 | GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, | |
1268 | (HOST_WIDE_INT) class_binding_level->level_chain, | |
1269 | class_binding_level->parm_flag, | |
1270 | class_binding_level->keep, | |
1271 | class_binding_level->tag_transparent); | |
1272 | ||
1273 | class_binding_level = level->level_chain; | |
1274 | if (class_binding_level->parm_flag != 2) | |
1275 | class_binding_level = (struct binding_level *)0; | |
1276 | ||
1277 | #ifdef DEBUG_CP_BINDING_LEVELS | |
1278 | indent_to (stderr, debug_bindings_indentation); | |
1279 | fprintf (stderr, "popping class binding level "); | |
1280 | fprintf (stderr, HOST_PTR_PRINTF, level); | |
1281 | fprintf (stderr, "\n"); | |
1282 | memset (level, 0x69, sizeof (*level)); | |
1283 | debug_bindings_indentation -= 4; | |
1284 | #else | |
1285 | level->level_chain = free_binding_level; | |
1286 | free_binding_level = level; | |
1287 | #endif | |
1288 | binding_levels_sane(); | |
1289 | ||
1290 | return block; | |
1291 | } | |
1292 | \f | |
1293 | /* For debugging. */ | |
1294 | int no_print_functions = 0; | |
1295 | int no_print_builtins = 0; | |
1296 | ||
1297 | void | |
1298 | print_binding_level (lvl) | |
1299 | struct binding_level *lvl; | |
1300 | { | |
1301 | tree t; | |
1302 | int i = 0, len; | |
1303 | fprintf (stderr, " blocks="); | |
1304 | fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks); | |
1305 | fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d", | |
1306 | lvl->n_incomplete, lvl->parm_flag, lvl->keep); | |
1307 | if (lvl->tag_transparent) | |
1308 | fprintf (stderr, " tag-transparent"); | |
1309 | if (lvl->more_cleanups_ok) | |
1310 | fprintf (stderr, " more-cleanups-ok"); | |
1311 | if (lvl->have_cleanups) | |
1312 | fprintf (stderr, " have-cleanups"); | |
1313 | if (lvl->more_exceptions_ok) | |
1314 | fprintf (stderr, " more-exceptions-ok"); | |
1315 | if (lvl->have_exceptions) | |
1316 | fprintf (stderr, " have-exceptions"); | |
1317 | fprintf (stderr, "\n"); | |
1318 | if (lvl->names) | |
1319 | { | |
1320 | fprintf (stderr, " names:\t"); | |
1321 | /* We can probably fit 3 names to a line? */ | |
1322 | for (t = lvl->names; t; t = TREE_CHAIN (t)) | |
1323 | { | |
1324 | if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) | |
1325 | continue; | |
1326 | if (no_print_builtins | |
1327 | && (TREE_CODE(t) == TYPE_DECL) | |
1328 | && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>"))) | |
1329 | continue; | |
1330 | ||
1331 | /* Function decls tend to have longer names. */ | |
1332 | if (TREE_CODE (t) == FUNCTION_DECL) | |
1333 | len = 3; | |
1334 | else | |
1335 | len = 2; | |
1336 | i += len; | |
1337 | if (i > 6) | |
1338 | { | |
1339 | fprintf (stderr, "\n\t"); | |
1340 | i = len; | |
1341 | } | |
1342 | print_node_brief (stderr, "", t, 0); | |
1343 | if (TREE_CODE (t) == ERROR_MARK) | |
1344 | break; | |
1345 | } | |
1346 | if (i) | |
1347 | fprintf (stderr, "\n"); | |
1348 | } | |
1349 | if (lvl->tags) | |
1350 | { | |
1351 | fprintf (stderr, " tags:\t"); | |
1352 | i = 0; | |
1353 | for (t = lvl->tags; t; t = TREE_CHAIN (t)) | |
1354 | { | |
1355 | if (TREE_PURPOSE (t) == NULL_TREE) | |
1356 | len = 3; | |
1357 | else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) | |
1358 | len = 2; | |
1359 | else | |
1360 | len = 4; | |
1361 | i += len; | |
1362 | if (i > 5) | |
1363 | { | |
1364 | fprintf (stderr, "\n\t"); | |
1365 | i = len; | |
1366 | } | |
1367 | if (TREE_PURPOSE (t) == NULL_TREE) | |
1368 | { | |
1369 | print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0); | |
1370 | fprintf (stderr, ">"); | |
1371 | } | |
1372 | else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) | |
1373 | print_node_brief (stderr, "", TREE_VALUE (t), 0); | |
1374 | else | |
1375 | { | |
1376 | print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0); | |
1377 | print_node_brief (stderr, "", TREE_VALUE (t), 0); | |
1378 | fprintf (stderr, ">"); | |
1379 | } | |
1380 | } | |
1381 | if (i) | |
1382 | fprintf (stderr, "\n"); | |
1383 | } | |
1384 | if (lvl->shadowed) | |
1385 | { | |
1386 | fprintf (stderr, " shadowed:"); | |
1387 | for (t = lvl->shadowed; t; t = TREE_CHAIN (t)) | |
1388 | { | |
1389 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
1390 | } | |
1391 | fprintf (stderr, "\n"); | |
1392 | } | |
1393 | if (lvl->class_shadowed) | |
1394 | { | |
1395 | fprintf (stderr, " class-shadowed:"); | |
1396 | for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t)) | |
1397 | { | |
1398 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
1399 | } | |
1400 | fprintf (stderr, "\n"); | |
1401 | } | |
1402 | if (lvl->type_shadowed) | |
1403 | { | |
1404 | fprintf (stderr, " type-shadowed:"); | |
1405 | for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t)) | |
1406 | { | |
1407 | #if 0 | |
1408 | fprintf (stderr, "\n\t"); | |
1409 | print_node_brief (stderr, "<", TREE_PURPOSE (t), 0); | |
1410 | if (TREE_VALUE (t)) | |
1411 | print_node_brief (stderr, " ", TREE_VALUE (t), 0); | |
1412 | else | |
1413 | fprintf (stderr, " (none)"); | |
1414 | fprintf (stderr, ">"); | |
1415 | #else | |
1416 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
1417 | #endif | |
1418 | } | |
1419 | fprintf (stderr, "\n"); | |
1420 | } | |
1421 | } | |
1422 | ||
1423 | void | |
1424 | print_other_binding_stack (stack) | |
1425 | struct binding_level *stack; | |
1426 | { | |
1427 | struct binding_level *level; | |
1428 | for (level = stack; level != global_binding_level; level = level->level_chain) | |
1429 | { | |
1430 | fprintf (stderr, "binding level "); | |
1431 | fprintf (stderr, HOST_PTR_PRINTF, level); | |
1432 | fprintf (stderr, "\n"); | |
1433 | print_binding_level (level); | |
1434 | } | |
1435 | } | |
1436 | ||
1437 | void | |
1438 | print_binding_stack () | |
1439 | { | |
1440 | struct binding_level *b; | |
1441 | fprintf (stderr, "current_binding_level="); | |
1442 | fprintf (stderr, HOST_PTR_PRINTF, current_binding_level); | |
1443 | fprintf (stderr, "\nclass_binding_level="); | |
1444 | fprintf (stderr, HOST_PTR_PRINTF, class_binding_level); | |
1445 | fprintf (stderr, "\nglobal_binding_level="); | |
1446 | fprintf (stderr, HOST_PTR_PRINTF, global_binding_level); | |
1447 | fprintf (stderr, "\n"); | |
1448 | if (class_binding_level) | |
1449 | { | |
1450 | for (b = class_binding_level; b; b = b->level_chain) | |
1451 | if (b == current_binding_level) | |
1452 | break; | |
1453 | if (b) | |
1454 | b = class_binding_level; | |
1455 | else | |
1456 | b = current_binding_level; | |
1457 | } | |
1458 | else | |
1459 | b = current_binding_level; | |
1460 | print_other_binding_stack (b); | |
1461 | fprintf (stderr, "global:\n"); | |
1462 | print_binding_level (global_binding_level); | |
1463 | } | |
1464 | \f | |
1465 | /* Subroutines for reverting temporarily to top-level for instantiation | |
1466 | of templates and such. We actually need to clear out the class- and | |
1467 | local-value slots of all identifiers, so that only the global values | |
1468 | are at all visible. Simply setting current_binding_level to the global | |
1469 | scope isn't enough, because more binding levels may be pushed. */ | |
1470 | struct saved_scope { | |
1471 | struct binding_level *old_binding_level; | |
1472 | tree old_bindings; | |
1473 | struct saved_scope *prev; | |
1474 | tree class_name, class_type, class_decl, function_decl; | |
1475 | struct binding_level *class_bindings; | |
1476 | }; | |
1477 | static struct saved_scope *current_saved_scope; | |
1478 | extern tree prev_class_type; | |
1479 | ||
1480 | void | |
1481 | push_to_top_level () | |
1482 | { | |
1483 | struct saved_scope *s = | |
1484 | (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); | |
1485 | struct binding_level *b = current_binding_level; | |
1486 | tree old_bindings = NULL_TREE; | |
1487 | ||
1488 | #ifdef DEBUG_CP_BINDING_LEVELS | |
1489 | fprintf (stderr, "PUSH_TO_TOP_LEVEL\n"); | |
1490 | #endif | |
1491 | ||
1492 | /* Have to include global_binding_level, because class-level decls | |
1493 | aren't listed anywhere useful. */ | |
1494 | for (; b; b = b->level_chain) | |
1495 | { | |
1496 | tree t; | |
1497 | for (t = b->names; t; t = TREE_CHAIN (t)) | |
1498 | if (b != global_binding_level) | |
1499 | { | |
1500 | tree binding, t1, t2 = t; | |
1501 | tree id = DECL_ASSEMBLER_NAME (t2); | |
1502 | ||
1503 | if (!id | |
1504 | || (!IDENTIFIER_LOCAL_VALUE (id) | |
1505 | && !IDENTIFIER_CLASS_VALUE (id))) | |
1506 | continue; | |
1507 | ||
1508 | for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) | |
1509 | if (TREE_VEC_ELT (t1, 0) == id) | |
1510 | goto skip_it; | |
1511 | ||
1512 | binding = make_tree_vec (4); | |
1513 | if (id) | |
1514 | { | |
1515 | my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); | |
1516 | TREE_VEC_ELT (binding, 0) = id; | |
1517 | TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id); | |
1518 | TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id); | |
1519 | TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); | |
1520 | IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE; | |
1521 | IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; | |
1522 | adjust_type_value (id); | |
1523 | } | |
1524 | TREE_CHAIN (binding) = old_bindings; | |
1525 | old_bindings = binding; | |
1526 | skip_it: | |
1527 | ; | |
1528 | } | |
1529 | /* Unwind type-value slots back to top level. */ | |
1530 | if (b != global_binding_level) | |
1531 | for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) | |
1532 | SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); | |
1533 | } | |
1534 | ||
1535 | s->old_binding_level = current_binding_level; | |
1536 | current_binding_level = global_binding_level; | |
1537 | ||
1538 | s->class_name = current_class_name; | |
1539 | s->class_type = current_class_type; | |
1540 | s->class_decl = current_class_decl; | |
1541 | s->function_decl = current_function_decl; | |
1542 | s->class_bindings = class_binding_level; | |
1543 | current_class_name = current_class_type = current_class_decl = NULL_TREE; | |
1544 | current_function_decl = NULL_TREE; | |
1545 | class_binding_level = (struct binding_level *)0; | |
1546 | ||
1547 | s->prev = current_saved_scope; | |
1548 | s->old_bindings = old_bindings; | |
1549 | current_saved_scope = s; | |
1550 | binding_levels_sane(); | |
1551 | } | |
1552 | ||
1553 | void | |
1554 | pop_from_top_level () | |
1555 | { | |
1556 | struct saved_scope *s = current_saved_scope; | |
1557 | tree t; | |
1558 | ||
1559 | #ifdef DEBUG_CP_BINDING_LEVELS | |
1560 | fprintf (stderr, "POP_FROM_TOP_LEVEL\n"); | |
1561 | #endif | |
1562 | ||
1563 | binding_levels_sane(); | |
1564 | current_binding_level = s->old_binding_level; | |
1565 | current_saved_scope = s->prev; | |
1566 | for (t = s->old_bindings; t; t = TREE_CHAIN (t)) | |
1567 | { | |
1568 | tree id = TREE_VEC_ELT (t, 0); | |
1569 | if (id) | |
1570 | { | |
1571 | IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1); | |
1572 | IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2); | |
1573 | IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); | |
1574 | } | |
1575 | } | |
1576 | current_class_name = s->class_name; | |
1577 | current_class_type = s->class_type; | |
1578 | current_class_decl = s->class_decl; | |
1579 | if (current_class_type) | |
1580 | C_C_D = CLASSTYPE_INST_VAR (current_class_type); | |
1581 | else | |
1582 | C_C_D = NULL_TREE; | |
1583 | current_function_decl = s->function_decl; | |
1584 | class_binding_level = s->class_bindings; | |
1585 | free (s); | |
1586 | binding_levels_sane(); | |
1587 | } | |
1588 | \f | |
1589 | /* Push a definition of struct, union or enum tag "name". | |
1590 | "type" should be the type node. | |
1591 | We assume that the tag "name" is not already defined. | |
1592 | ||
1593 | Note that the definition may really be just a forward reference. | |
1594 | In that case, the TYPE_SIZE will be a NULL_TREE. | |
1595 | ||
1596 | C++ gratuitously puts all these tags in the name space. */ | |
1597 | ||
1598 | /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID, | |
1599 | record the shadowed value for this binding contour. TYPE is | |
1600 | the type that ID maps to. */ | |
1601 | void | |
1602 | set_identifier_type_value (id, type) | |
1603 | tree id; | |
1604 | tree type; | |
1605 | { | |
1606 | if (current_binding_level != global_binding_level) | |
1607 | { | |
1608 | tree old_type_value = IDENTIFIER_TYPE_VALUE (id); | |
1609 | current_binding_level->type_shadowed | |
1610 | = tree_cons (id, old_type_value, current_binding_level->type_shadowed); | |
1611 | } | |
1612 | else if (class_binding_level) | |
1613 | { | |
1614 | tree old_type_value = IDENTIFIER_TYPE_VALUE (id); | |
1615 | class_binding_level->type_shadowed | |
1616 | = tree_cons (id, old_type_value, class_binding_level->type_shadowed); | |
1617 | } | |
1618 | SET_IDENTIFIER_TYPE_VALUE (id, type); | |
1619 | } | |
1620 | ||
1621 | /* | |
1622 | * local values can need to be shadowed too, but it only happens | |
1623 | * explicitly from pushdecl, in support of nested enums. | |
1624 | */ | |
1625 | void | |
1626 | set_identifier_local_value (id, type) | |
1627 | tree id; | |
1628 | tree type; | |
1629 | { | |
1630 | if (current_binding_level != global_binding_level) | |
1631 | { | |
1632 | tree old_local_value = IDENTIFIER_LOCAL_VALUE (id); | |
1633 | current_binding_level->shadowed | |
1634 | = tree_cons (id, old_local_value, current_binding_level->shadowed); | |
1635 | } | |
1636 | else if (class_binding_level) | |
1637 | { | |
1638 | tree old_local_value = IDENTIFIER_LOCAL_VALUE (id); | |
1639 | class_binding_level->shadowed | |
1640 | = tree_cons (id, old_local_value, class_binding_level->shadowed); | |
1641 | } | |
1642 | IDENTIFIER_LOCAL_VALUE (id) = type; | |
1643 | } | |
1644 | ||
1645 | /* Subroutine "set_nested_typename" builds the nested-typename of | |
1646 | the type decl in question. (Argument CLASSNAME can actually be | |
1647 | a function as well, if that's the smallest containing scope.) */ | |
1648 | ||
1649 | static void | |
1650 | set_nested_typename (decl, classname, name, type) | |
1651 | tree decl, classname, name, type; | |
1652 | { | |
1653 | my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136); | |
1654 | if (classname != NULL_TREE) | |
1655 | { | |
1656 | char *buf; | |
1657 | my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137); | |
1658 | my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138); | |
1659 | buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname) | |
1660 | + IDENTIFIER_LENGTH (name)); | |
1661 | sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname), | |
1662 | IDENTIFIER_POINTER (name)); | |
1663 | DECL_NESTED_TYPENAME (decl) = get_identifier (buf); | |
1664 | SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type); | |
1665 | } | |
1666 | else | |
1667 | DECL_NESTED_TYPENAME (decl) = name; | |
1668 | } | |
1669 | ||
1670 | #if 0 /* not yet, should get fixed properly later */ | |
1671 | /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME. | |
1672 | Other routines shouldn't use build_decl directly; they'll produce | |
1673 | incorrect results with `-g' unless they duplicate this code. | |
1674 | ||
1675 | This is currently needed mainly for dbxout.c, but we can make | |
1676 | use of it in cp-method.c later as well. */ | |
1677 | tree | |
1678 | make_type_decl (name, type) | |
1679 | tree name, type; | |
1680 | { | |
1681 | tree decl, id; | |
1682 | decl = build_decl (TYPE_DECL, name, type); | |
1683 | if (TYPE_NAME (type) == name) | |
1684 | /* Class/union/enum definition, or a redundant typedef for same. */ | |
1685 | { | |
1686 | id = get_identifier (build_overload_name (type, 1, 1)); | |
1687 | DECL_ASSEMBLER_NAME (decl) = id; | |
1688 | } | |
1689 | else if (TYPE_NAME (type) != NULL_TREE) | |
1690 | /* Explicit typedef, or implicit typedef for template expansion. */ | |
1691 | DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type)); | |
1692 | else | |
1693 | { | |
1694 | /* Typedef for unnamed struct; some other situations. | |
1695 | TYPE_NAME is null; what's right here? */ | |
1696 | } | |
1697 | return decl; | |
1698 | } | |
1699 | ||
1700 | #endif | |
1701 | void | |
1702 | pushtag (name, type) | |
1703 | tree name, type; | |
1704 | { | |
1705 | register struct binding_level *b; | |
1706 | ||
1707 | if (class_binding_level) | |
1708 | b = class_binding_level; | |
1709 | else | |
1710 | { | |
1711 | b = current_binding_level; | |
1712 | while (b->tag_transparent) b = b->level_chain; | |
1713 | } | |
1714 | ||
1715 | if (b == global_binding_level) | |
1716 | b->tags = perm_tree_cons (name, type, b->tags); | |
1717 | else | |
1718 | b->tags = saveable_tree_cons (name, type, b->tags); | |
1719 | ||
1720 | if (name) | |
1721 | { | |
1722 | /* Record the identifier as the type's name if it has none. */ | |
1723 | ||
1724 | if (TYPE_NAME (type) == NULL_TREE) | |
1725 | TYPE_NAME (type) = name; | |
1726 | ||
1727 | /* Do C++ gratuitous typedefing. */ | |
1728 | if (IDENTIFIER_TYPE_VALUE (name) != type | |
1729 | && (TREE_CODE (type) != RECORD_TYPE | |
1730 | || class_binding_level == (struct binding_level *)0 | |
1731 | || !CLASSTYPE_DECLARED_EXCEPTION (type))) | |
1732 | { | |
1733 | register tree d; | |
1734 | if (current_class_type == NULL_TREE | |
1735 | || TYPE_SIZE (current_class_type) != NULL_TREE) | |
1736 | { | |
1737 | if (current_lang_name == lang_name_cplusplus) | |
1738 | d = lookup_nested_type (type, current_class_type ? TYPE_NAME (current_class_type) : NULL_TREE); | |
1739 | else | |
1740 | d = NULL_TREE; | |
1741 | ||
1742 | if (d == NULL_TREE) | |
1743 | { | |
1744 | #if 0 /* not yet, should get fixed properly later */ | |
1745 | d = make_type_decl (name, type); | |
1746 | DECL_ASSEMBLER_NAME (d) = get_identifier (build_overload_name (type, 1, 1)); | |
1747 | #else | |
1748 | d = build_decl (TYPE_DECL, name, type); | |
1749 | DECL_ASSEMBLER_NAME (d) = get_identifier (build_overload_name (type, 1, 1)); | |
1750 | #endif | |
1751 | /* mark the binding layer marker as internal. (mrs) */ | |
1752 | DECL_SOURCE_LINE (d) = 0; | |
1753 | set_identifier_type_value (name, type); | |
1754 | } | |
1755 | else | |
1756 | d = TYPE_NAME (d); | |
1757 | ||
1758 | /* If it is anonymous, then we are called from pushdecl, | |
1759 | and we don't want to infinitely recurse. Also, if the | |
1760 | name is already in scope, we don't want to push it | |
1761 | again--pushdecl is only for pushing new decls. */ | |
1762 | if (! ANON_AGGRNAME_P (name) | |
1763 | && TYPE_NAME (type) | |
1764 | && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL | |
1765 | || lookup_name (name, 1) != TYPE_NAME (type))) | |
1766 | { | |
1767 | if (class_binding_level) | |
1768 | d = pushdecl_class_level (d); | |
1769 | else | |
1770 | d = pushdecl (d); | |
1771 | } | |
1772 | } | |
1773 | else | |
1774 | { | |
1775 | /* Make nested declarations go into class-level scope. */ | |
1776 | d = build_lang_field_decl (TYPE_DECL, name, type); | |
1777 | set_identifier_type_value (name, type); | |
1778 | d = pushdecl_class_level (d); | |
1779 | } | |
1780 | if (ANON_AGGRNAME_P (name)) | |
1781 | DECL_IGNORED_P (d) = 1; | |
1782 | TYPE_NAME (type) = d; | |
1783 | ||
1784 | if ((current_class_type == NULL_TREE | |
1785 | && current_function_decl == NULL_TREE) | |
1786 | || current_lang_name != lang_name_cplusplus) | |
1787 | /* Non-nested class. */ | |
1788 | DECL_NESTED_TYPENAME (d) = name; | |
1789 | else if (current_function_decl != NULL_TREE) | |
1790 | { | |
1791 | /* Function-nested class. */ | |
1792 | set_nested_typename (d, DECL_ASSEMBLER_NAME (current_function_decl), | |
1793 | name, type); | |
1794 | /* This builds the links for classes nested in fn scope. */ | |
1795 | DECL_CONTEXT (d) = current_function_decl; | |
1796 | } | |
1797 | else if (TYPE_SIZE (current_class_type) == NULL_TREE) | |
1798 | { | |
1799 | /* Class-nested class. */ | |
1800 | set_nested_typename (d, DECL_NESTED_TYPENAME (TYPE_NAME (current_class_type)), | |
1801 | name, type); | |
1802 | /* This builds the links for classes nested in type scope. */ | |
1803 | DECL_CONTEXT (d) = current_class_type; | |
1804 | DECL_CLASS_CONTEXT (d) = current_class_type; | |
1805 | } | |
1806 | } | |
1807 | if (b->parm_flag == 2) | |
1808 | { | |
1809 | TREE_NONLOCAL_FLAG (type) = 1; | |
1810 | IDENTIFIER_CLASS_VALUE (name) = TYPE_NAME (type); | |
1811 | if (TYPE_SIZE (current_class_type) == NULL_TREE) | |
1812 | CLASSTYPE_TAGS (current_class_type) = b->tags; | |
1813 | } | |
1814 | } | |
1815 | ||
1816 | if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) | |
1817 | /* Use the canonical TYPE_DECL for this node. */ | |
1818 | TYPE_STUB_DECL (type) = TYPE_NAME (type); | |
1819 | else | |
1820 | { | |
1821 | /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE | |
1822 | will be the tagged type we just added to the current | |
1823 | binding level. This fake NULL-named TYPE_DECL node helps | |
1824 | dwarfout.c to know when it needs to output a | |
1825 | representation of a tagged type, and it also gives us a | |
1826 | convenient place to record the "scope start" address for | |
1827 | the tagged type. */ | |
1828 | ||
1829 | #if 0 /* not yet, should get fixed properly later */ | |
1830 | TYPE_STUB_DECL (type) = pushdecl (make_type_decl (NULL, type)); | |
1831 | #else | |
1832 | TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type)); | |
1833 | #endif | |
1834 | } | |
1835 | } | |
1836 | ||
1837 | /* Counter used to create anonymous type names. */ | |
1838 | static int anon_cnt = 0; | |
1839 | ||
1840 | /* Return an IDENTIFIER which can be used as a name for | |
1841 | anonymous structs and unions. */ | |
1842 | tree | |
1843 | make_anon_name () | |
1844 | { | |
1845 | char buf[32]; | |
1846 | ||
1847 | sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++); | |
1848 | return get_identifier (buf); | |
1849 | } | |
1850 | ||
1851 | /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames. | |
1852 | This keeps dbxout from getting confused. */ | |
1853 | void | |
1854 | clear_anon_tags () | |
1855 | { | |
1856 | register struct binding_level *b; | |
1857 | register tree tags; | |
1858 | static int last_cnt = 0; | |
1859 | ||
1860 | /* Fast out if no new anon names were declared. */ | |
1861 | if (last_cnt == anon_cnt) | |
1862 | return; | |
1863 | ||
1864 | b = current_binding_level; | |
1865 | while (b->tag_transparent) | |
1866 | b = b->level_chain; | |
1867 | tags = b->tags; | |
1868 | while (tags) | |
1869 | { | |
1870 | /* A NULL purpose means we have already processed all tags | |
1871 | from here to the end of the list. */ | |
1872 | if (TREE_PURPOSE (tags) == NULL_TREE) | |
1873 | break; | |
1874 | if (ANON_AGGRNAME_P (TREE_PURPOSE (tags))) | |
1875 | TREE_PURPOSE (tags) = NULL_TREE; | |
1876 | tags = TREE_CHAIN (tags); | |
1877 | } | |
1878 | last_cnt = anon_cnt; | |
1879 | } | |
1880 | \f | |
1881 | /* Subroutine of duplicate_decls: return truthvalue of whether | |
1882 | or not types of these decls match. */ | |
1883 | static int | |
1884 | decls_match (newdecl, olddecl) | |
1885 | tree newdecl, olddecl; | |
1886 | { | |
1887 | int types_match; | |
1888 | ||
1889 | if (TREE_CODE (newdecl) == FUNCTION_DECL && TREE_CODE (olddecl) == FUNCTION_DECL) | |
1890 | { | |
1891 | tree f1 = TREE_TYPE (newdecl); | |
1892 | tree f2 = TREE_TYPE (olddecl); | |
1893 | tree p1 = TYPE_ARG_TYPES (f1); | |
1894 | tree p2 = TYPE_ARG_TYPES (f2); | |
1895 | ||
1896 | /* When we parse a static member function definition, | |
1897 | we put together a FUNCTION_DECL which thinks its type | |
1898 | is METHOD_TYPE. Change that to FUNCTION_TYPE, and | |
1899 | proceed. */ | |
1900 | if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl)) | |
1901 | revert_static_member_fn (&f1, &newdecl, &p1); | |
1902 | else if (TREE_CODE (f2) == METHOD_TYPE | |
1903 | && DECL_STATIC_FUNCTION_P (newdecl)) | |
1904 | revert_static_member_fn (&f2, &olddecl, &p2); | |
1905 | ||
1906 | /* Here we must take care of the case where new default | |
1907 | parameters are specified. Also, warn if an old | |
1908 | declaration becomes ambiguous because default | |
1909 | parameters may cause the two to be ambiguous. */ | |
1910 | if (TREE_CODE (f1) != TREE_CODE (f2)) | |
1911 | { | |
1912 | if (TREE_CODE (f1) == OFFSET_TYPE) | |
1913 | compiler_error_with_decl (newdecl, "`%s' redeclared as member function"); | |
1914 | else | |
1915 | compiler_error_with_decl (newdecl, "`%s' redeclared as non-member function"); | |
1916 | return 0; | |
1917 | } | |
1918 | ||
1919 | if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (f1)), | |
1920 | TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 1)) | |
1921 | types_match = compparms (p1, p2, 1); | |
1922 | else types_match = 0; | |
1923 | } | |
1924 | else | |
1925 | { | |
1926 | if (TREE_TYPE (newdecl) == error_mark_node) | |
1927 | types_match = TREE_TYPE (olddecl) == error_mark_node; | |
1928 | else if (TREE_TYPE (olddecl) == NULL_TREE) | |
1929 | types_match = TREE_TYPE (newdecl) == NULL_TREE; | |
1930 | else | |
1931 | types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1); | |
1932 | } | |
1933 | ||
1934 | return types_match; | |
1935 | } | |
1936 | ||
1937 | /* Handle when a new declaration NEWDECL has the same name as an old | |
1938 | one OLDDECL in the same binding contour. Prints an error message | |
1939 | if appropriate. | |
1940 | ||
1941 | If safely possible, alter OLDDECL to look like NEWDECL, and return 1. | |
1942 | Otherwise, return 0. */ | |
1943 | ||
1944 | static int | |
1945 | duplicate_decls (newdecl, olddecl) | |
1946 | register tree newdecl, olddecl; | |
1947 | { | |
1948 | extern struct obstack permanent_obstack; | |
1949 | unsigned olddecl_uid = DECL_UID (olddecl); | |
1950 | int olddecl_friend = 0, types_match; | |
1951 | int new_defines_function; | |
1952 | register unsigned saved_old_decl_uid; | |
1953 | register int saved_old_decl_friend_p; | |
1954 | ||
1955 | if (TREE_CODE (olddecl) == TREE_LIST | |
1956 | && TREE_CODE (newdecl) == FUNCTION_DECL) | |
1957 | { | |
1958 | /* If a new decl finds a list of old decls, then | |
1959 | we assume that the new decl has C linkage, and | |
1960 | that the old decls have C++ linkage. In this case, | |
1961 | we must look through the list to see whether | |
1962 | there is an ambiguity or not. */ | |
1963 | tree olddecls = olddecl; | |
1964 | ||
1965 | /* If the overload list is empty, just install the decl. */ | |
1966 | if (TREE_VALUE (olddecls) == NULL_TREE) | |
1967 | { | |
1968 | TREE_VALUE (olddecls) = newdecl; | |
1969 | return 1; | |
1970 | } | |
1971 | ||
1972 | while (olddecls) | |
1973 | { | |
1974 | if (decls_match (newdecl, TREE_VALUE (olddecls))) | |
1975 | { | |
1976 | if (TREE_CODE (newdecl) == VAR_DECL) | |
1977 | ; | |
1978 | else if (DECL_LANGUAGE (newdecl) | |
1979 | != DECL_LANGUAGE (TREE_VALUE (olddecls))) | |
1980 | { | |
1981 | error_with_decl (newdecl, "declaration of `%s' with different language linkage"); | |
1982 | error_with_decl (TREE_VALUE (olddecls), "previous declaration here"); | |
1983 | } | |
1984 | types_match = 1; | |
1985 | break; | |
1986 | } | |
1987 | olddecls = TREE_CHAIN (olddecls); | |
1988 | } | |
1989 | if (olddecls) | |
1990 | olddecl = TREE_VALUE (olddecl); | |
1991 | else | |
1992 | return 1; | |
1993 | } | |
1994 | else | |
1995 | { | |
1996 | if (TREE_CODE (olddecl) != TREE_LIST) | |
1997 | olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl); | |
1998 | types_match = decls_match (newdecl, olddecl); | |
1999 | } | |
2000 | ||
2001 | if ((TREE_TYPE (newdecl) && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK) | |
2002 | || (TREE_TYPE (olddecl) && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK)) | |
2003 | types_match = 0; | |
2004 | ||
2005 | /* If this decl has linkage, and the old one does too, maybe no error. */ | |
2006 | if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) | |
2007 | { | |
2008 | error_with_decl (newdecl, "`%s' redeclared as different kind of symbol"); | |
2009 | if (TREE_CODE (olddecl) == TREE_LIST) | |
2010 | olddecl = TREE_VALUE (olddecl); | |
2011 | error_with_decl (olddecl, "previous declaration of `%s'"); | |
2012 | ||
2013 | /* New decl is completely inconsistent with the old one => | |
2014 | tell caller to replace the old one. */ | |
2015 | ||
2016 | return 0; | |
2017 | } | |
2018 | ||
2019 | if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
2020 | { | |
2021 | /* Now that functions must hold information normally held | |
2022 | by field decls, there is extra work to do so that | |
2023 | declaration information does not get destroyed during | |
2024 | definition. */ | |
2025 | if (DECL_VINDEX (olddecl)) | |
2026 | DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl); | |
2027 | if (DECL_CONTEXT (olddecl)) | |
2028 | DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); | |
2029 | if (DECL_CLASS_CONTEXT (olddecl)) | |
2030 | DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); | |
2031 | if (DECL_CHAIN (newdecl) == NULL_TREE) | |
2032 | DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); | |
2033 | if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) | |
2034 | DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); | |
2035 | } | |
2036 | ||
2037 | if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL | |
2038 | && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl) | |
2039 | /* If -traditional, avoid error for redeclaring fcn | |
2040 | after implicit decl. */ | |
2041 | ; | |
2042 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
2043 | && DECL_BUILT_IN (olddecl)) | |
2044 | { | |
2045 | if (!types_match) | |
2046 | { | |
2047 | error_with_decl (newdecl, "declaration of `%s'"); | |
2048 | error_with_decl (olddecl, "conflicts with built-in declaration `%s'"); | |
2049 | } | |
2050 | } | |
2051 | else if (!types_match) | |
2052 | { | |
2053 | tree oldtype = TREE_TYPE (olddecl); | |
2054 | tree newtype = TREE_TYPE (newdecl); | |
2055 | int give_error = 0; | |
2056 | ||
2057 | /* Already complained about this, so don't do so again. */ | |
2058 | if (current_class_type == NULL_TREE | |
2059 | || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) | |
2060 | { | |
2061 | give_error = 1; | |
2062 | error_with_decl (newdecl, "conflicting types for `%s'"); | |
2063 | } | |
2064 | ||
2065 | /* Check for function type mismatch | |
2066 | involving an empty arglist vs a nonempty one. */ | |
2067 | if (TREE_CODE (olddecl) == FUNCTION_DECL | |
2068 | && comptypes (TREE_TYPE (oldtype), | |
2069 | TREE_TYPE (newtype), 1) | |
2070 | && ((TYPE_ARG_TYPES (oldtype) == NULL_TREE | |
2071 | && DECL_INITIAL (olddecl) == NULL_TREE) | |
2072 | || (TYPE_ARG_TYPES (newtype) == NULL_TREE | |
2073 | && DECL_INITIAL (newdecl) == NULL_TREE))) | |
2074 | { | |
2075 | /* Classify the problem further. */ | |
2076 | register tree t = TYPE_ARG_TYPES (oldtype); | |
2077 | if (t == NULL_TREE) | |
2078 | t = TYPE_ARG_TYPES (newtype); | |
2079 | for (; t; t = TREE_CHAIN (t)) | |
2080 | { | |
2081 | register tree type = TREE_VALUE (t); | |
2082 | ||
2083 | if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node) | |
2084 | { | |
2085 | error ("A parameter list with an ellipsis can't match"); | |
2086 | error ("an empty parameter name list declaration."); | |
2087 | break; | |
2088 | } | |
2089 | ||
2090 | if (TYPE_MAIN_VARIANT (type) == float_type_node | |
2091 | || C_PROMOTING_INTEGER_TYPE_P (type)) | |
2092 | { | |
2093 | error ("An argument type that has a default promotion"); | |
2094 | error ("can't match an empty parameter name list declaration."); | |
2095 | break; | |
2096 | } | |
2097 | } | |
2098 | } | |
2099 | if (give_error) | |
2100 | error_with_decl (olddecl, "previous declaration of `%s'"); | |
2101 | ||
2102 | /* There is one thing GNU C++ cannot tolerate: a constructor | |
2103 | which takes the type of object being constructed. | |
2104 | Farm that case out here. */ | |
2105 | if (TREE_CODE (newdecl) == FUNCTION_DECL | |
2106 | && DECL_CONSTRUCTOR_P (newdecl)) | |
2107 | { | |
2108 | tree tmp = TREE_CHAIN (TYPE_ARG_TYPES (newtype)); | |
2109 | ||
2110 | if (tmp != NULL_TREE | |
2111 | && (TYPE_MAIN_VARIANT (TREE_VALUE (tmp)) | |
2112 | == TYPE_METHOD_BASETYPE (newtype))) | |
2113 | { | |
2114 | tree parm = TREE_CHAIN (DECL_ARGUMENTS (newdecl)); | |
2115 | tree argtypes | |
2116 | = hash_tree_chain (build_reference_type (TREE_VALUE (tmp)), | |
2117 | TREE_CHAIN (tmp)); | |
2118 | ||
2119 | DECL_ARG_TYPE (parm) | |
2120 | = TREE_TYPE (parm) | |
2121 | = TYPE_REFERENCE_TO (TREE_VALUE (tmp)); | |
2122 | ||
2123 | TREE_TYPE (newdecl) = newtype | |
2124 | = build_cplus_method_type (TYPE_METHOD_BASETYPE (newtype), | |
2125 | TREE_TYPE (newtype), argtypes); | |
2126 | error ("constructor cannot take as argument the type being constructed"); | |
2127 | SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl), current_class_type); | |
2128 | } | |
2129 | } | |
2130 | } | |
2131 | else | |
2132 | { | |
2133 | char *errmsg = redeclaration_error_message (newdecl, olddecl); | |
2134 | if (errmsg) | |
2135 | { | |
2136 | error_with_decl (newdecl, errmsg); | |
2137 | if (DECL_NAME (olddecl) != NULL_TREE) | |
2138 | error_with_decl (olddecl, | |
2139 | (DECL_INITIAL (olddecl) | |
2140 | && current_binding_level == global_binding_level) | |
2141 | ? "`%s' previously defined here" | |
2142 | : "`%s' previously declared here"); | |
2143 | } | |
2144 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
2145 | && DECL_INITIAL (olddecl) != NULL_TREE | |
2146 | && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE | |
2147 | && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE) | |
2148 | { | |
2149 | /* Prototype decl follows defn w/o prototype. */ | |
2150 | warning_with_decl (newdecl, "prototype for `%s'"); | |
2151 | warning_with_decl (olddecl, | |
2152 | "follows non-prototype definition here"); | |
2153 | } | |
2154 | ||
2155 | /* These bits are logically part of the type. */ | |
2156 | if (pedantic | |
2157 | && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) | |
2158 | || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))) | |
2159 | error_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl"); | |
2160 | } | |
2161 | ||
2162 | /* Deal with C++: must preserve virtual function table size. */ | |
2163 | if (TREE_CODE (olddecl) == TYPE_DECL) | |
2164 | { | |
2165 | if (TYPE_LANG_SPECIFIC (TREE_TYPE (newdecl)) | |
2166 | && TYPE_LANG_SPECIFIC (TREE_TYPE (olddecl))) | |
2167 | { | |
2168 | CLASSTYPE_VSIZE (TREE_TYPE (newdecl)) | |
2169 | = CLASSTYPE_VSIZE (TREE_TYPE (olddecl)); | |
2170 | CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (newdecl)) | |
2171 | = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (olddecl)); | |
2172 | } | |
2173 | /* why assert here? Just because debugging information is | |
2174 | messed up? (mrs) */ | |
2175 | /* it happens on something like: | |
2176 | typedef struct Thing { | |
2177 | Thing(); | |
2178 | int x; | |
2179 | } Thing; | |
2180 | */ | |
2181 | #if 0 | |
2182 | my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl), 139); | |
2183 | #endif | |
2184 | } | |
2185 | ||
2186 | /* Special handling ensues if new decl is a function definition. */ | |
2187 | new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL | |
2188 | && DECL_INITIAL (newdecl) != NULL_TREE); | |
2189 | ||
2190 | /* Optionally warn about more than one declaration for the same name, | |
2191 | but don't warn about a function declaration followed by a definition. */ | |
2192 | if (warn_redundant_decls | |
2193 | && DECL_SOURCE_LINE (olddecl) != 0 | |
2194 | && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)) | |
2195 | { | |
2196 | warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope"); | |
2197 | warning_with_decl (olddecl, "previous declaration of `%s'"); | |
2198 | } | |
2199 | ||
2200 | /* Copy all the DECL_... slots specified in the new decl | |
2201 | except for any that we copy here from the old type. */ | |
2202 | ||
2203 | if (types_match) | |
2204 | { | |
2205 | /* Automatically handles default parameters. */ | |
2206 | tree oldtype = TREE_TYPE (olddecl); | |
2207 | /* Merge the data types specified in the two decls. */ | |
2208 | tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); | |
2209 | ||
2210 | if (TREE_CODE (newdecl) == VAR_DECL) | |
2211 | DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl); | |
2212 | /* Do this after calling `common_type' so that default | |
2213 | parameters don't confuse us. */ | |
2214 | else if (TREE_CODE (newdecl) == FUNCTION_DECL | |
2215 | && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)) | |
2216 | != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)))) | |
2217 | { | |
2218 | tree ctype = NULL_TREE; | |
2219 | ctype = DECL_CLASS_CONTEXT (newdecl); | |
2220 | TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype, | |
2221 | TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); | |
2222 | TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype, | |
2223 | TYPE_RAISES_EXCEPTIONS (oldtype)); | |
2224 | ||
2225 | if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE(olddecl), 0)) | |
2226 | { | |
2227 | error_with_decl (newdecl, "declaration of `%s' raises different exceptions..."); | |
2228 | error_with_decl (olddecl, "...from previous declaration here"); | |
2229 | } | |
2230 | } | |
2231 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; | |
2232 | ||
2233 | /* Lay the type out, unless already done. */ | |
2234 | if (oldtype != TREE_TYPE (newdecl)) | |
2235 | { | |
2236 | if (TREE_TYPE (newdecl) != error_mark_node) | |
2237 | layout_type (TREE_TYPE (newdecl)); | |
2238 | if (TREE_CODE (newdecl) != FUNCTION_DECL | |
2239 | && TREE_CODE (newdecl) != TYPE_DECL | |
2240 | && TREE_CODE (newdecl) != CONST_DECL) | |
2241 | layout_decl (newdecl, 0); | |
2242 | } | |
2243 | else | |
2244 | { | |
2245 | /* Since the type is OLDDECL's, make OLDDECL's size go with. */ | |
2246 | DECL_SIZE (newdecl) = DECL_SIZE (olddecl); | |
2247 | } | |
2248 | ||
2249 | /* Merge the type qualifiers. */ | |
2250 | if (TREE_READONLY (newdecl)) | |
2251 | TREE_READONLY (olddecl) = 1; | |
2252 | if (TREE_THIS_VOLATILE (newdecl)) | |
2253 | TREE_THIS_VOLATILE (olddecl) = 1; | |
2254 | ||
2255 | /* Merge the initialization information. */ | |
2256 | if (DECL_INITIAL (newdecl) == NULL_TREE) | |
2257 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
2258 | /* Keep the old rtl since we can safely use it, unless it's the | |
2259 | call to abort() used for abstract virtuals. */ | |
2260 | if ((DECL_LANG_SPECIFIC (olddecl) | |
2261 | && !DECL_ABSTRACT_VIRTUAL_P (olddecl)) | |
2262 | || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl)) | |
2263 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
2264 | } | |
2265 | /* If cannot merge, then use the new type and qualifiers, | |
2266 | and don't preserve the old rtl. */ | |
2267 | else | |
2268 | { | |
2269 | /* Clean out any memory we had of the old declaration. */ | |
2270 | tree oldstatic = value_member (olddecl, static_aggregates); | |
2271 | if (oldstatic) | |
2272 | TREE_VALUE (oldstatic) = error_mark_node; | |
2273 | ||
2274 | TREE_TYPE (olddecl) = TREE_TYPE (newdecl); | |
2275 | TREE_READONLY (olddecl) = TREE_READONLY (newdecl); | |
2276 | TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); | |
2277 | TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); | |
2278 | } | |
2279 | ||
2280 | /* Merge the storage class information. */ | |
2281 | if (DECL_EXTERNAL (newdecl)) | |
2282 | { | |
2283 | TREE_STATIC (newdecl) = TREE_STATIC (olddecl); | |
2284 | DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl); | |
2285 | ||
2286 | /* For functions, static overrides non-static. */ | |
2287 | if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
2288 | { | |
2289 | TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); | |
2290 | /* This is since we don't automatically | |
2291 | copy the attributes of NEWDECL into OLDDECL. */ | |
2292 | TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); | |
2293 | /* If this clears `static', clear it in the identifier too. */ | |
2294 | if (! TREE_PUBLIC (olddecl)) | |
2295 | TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0; | |
2296 | } | |
2297 | else | |
2298 | TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); | |
2299 | } | |
2300 | else | |
2301 | { | |
2302 | TREE_STATIC (olddecl) = TREE_STATIC (newdecl); | |
2303 | /* A `const' which was not declared `extern' and is | |
2304 | in static storage is invisible. */ | |
2305 | if (TREE_CODE (newdecl) == VAR_DECL | |
2306 | && TREE_READONLY (newdecl) && TREE_STATIC (newdecl) | |
2307 | && ! DECL_THIS_EXTERN (newdecl)) | |
2308 | TREE_PUBLIC (newdecl) = 0; | |
2309 | TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); | |
2310 | } | |
2311 | ||
2312 | /* If either decl says `inline', this fn is inline, | |
2313 | unless its definition was passed already. */ | |
2314 | if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE) | |
2315 | DECL_INLINE (olddecl) = 1; | |
2316 | DECL_INLINE (newdecl) = DECL_INLINE (olddecl); | |
2317 | ||
2318 | if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
2319 | { | |
2320 | if (new_defines_function) | |
2321 | /* If defining a function declared with other language | |
2322 | linkage, use the previously declared language linkage. */ | |
2323 | DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); | |
2324 | else | |
2325 | { | |
2326 | /* If redeclaring a builtin function, and not a definition, | |
2327 | it stays built in. */ | |
2328 | if (DECL_BUILT_IN (olddecl)) | |
2329 | { | |
2330 | DECL_BUILT_IN (newdecl) = 1; | |
2331 | DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl)); | |
2332 | /* If we're keeping the built-in definition, keep the rtl, | |
2333 | regardless of declaration matches. */ | |
2334 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
2335 | } | |
2336 | else | |
2337 | DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); | |
2338 | ||
2339 | DECL_RESULT (newdecl) = DECL_RESULT (olddecl); | |
2340 | if (DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)) | |
2341 | /* Previously saved insns go together with | |
2342 | the function's previous definition. */ | |
2343 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
2344 | /* Don't clear out the arguments if we're redefining a function. */ | |
2345 | if (DECL_ARGUMENTS (olddecl)) | |
2346 | DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); | |
2347 | } | |
2348 | } | |
2349 | ||
2350 | /* Now preserve various other info from the definition. */ | |
2351 | TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); | |
2352 | TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); | |
2353 | ||
2354 | /* Don't really know how much of the language-specific | |
2355 | values we should copy from old to new. */ | |
2356 | #if 1 | |
2357 | if (DECL_LANG_SPECIFIC (olddecl)) | |
2358 | DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); | |
2359 | #endif | |
2360 | ||
2361 | /* We are about to copy the contexts of newdecl into olddecl, so save a | |
2362 | few tidbits of information from olddecl that we may need to restore | |
2363 | after the copying takes place. */ | |
2364 | ||
2365 | saved_old_decl_uid = DECL_UID (olddecl); | |
2366 | saved_old_decl_friend_p | |
2367 | = DECL_LANG_SPECIFIC (olddecl) ? DECL_FRIEND_P (olddecl) : 0; | |
2368 | ||
2369 | if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
2370 | { | |
2371 | int function_size; | |
2372 | struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl); | |
2373 | struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl); | |
2374 | ||
2375 | function_size = sizeof (struct tree_decl); | |
2376 | ||
2377 | bcopy ((char *) newdecl + sizeof (struct tree_common), | |
2378 | (char *) olddecl + sizeof (struct tree_common), | |
2379 | function_size - sizeof (struct tree_common)); | |
2380 | ||
2381 | if ((char *)newdecl + ((function_size + sizeof (struct lang_decl) | |
2382 | + obstack_alignment_mask (&permanent_obstack)) | |
2383 | & ~ obstack_alignment_mask (&permanent_obstack)) | |
2384 | == obstack_next_free (&permanent_obstack)) | |
2385 | { | |
2386 | DECL_MAIN_VARIANT (newdecl) = olddecl; | |
2387 | DECL_LANG_SPECIFIC (olddecl) = ol; | |
2388 | bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl)); | |
2389 | ||
2390 | obstack_free (&permanent_obstack, newdecl); | |
2391 | } | |
2392 | else if (LANG_DECL_PERMANENT (ol)) | |
2393 | { | |
2394 | if (DECL_MAIN_VARIANT (olddecl) == olddecl) | |
2395 | { | |
2396 | /* Save these lang_decls that would otherwise be lost. */ | |
2397 | extern tree free_lang_decl_chain; | |
2398 | tree free_lang_decl = (tree) ol; | |
2399 | TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; | |
2400 | free_lang_decl_chain = free_lang_decl; | |
2401 | } | |
2402 | else | |
2403 | { | |
2404 | /* Storage leak. */ | |
2405 | } | |
2406 | } | |
2407 | } | |
2408 | else | |
2409 | { | |
2410 | bcopy ((char *) newdecl + sizeof (struct tree_common), | |
2411 | (char *) olddecl + sizeof (struct tree_common), | |
2412 | sizeof (struct tree_decl) - sizeof (struct tree_common) | |
2413 | + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); | |
2414 | } | |
2415 | ||
2416 | DECL_UID (olddecl) = olddecl_uid; | |
2417 | if (olddecl_friend) | |
2418 | DECL_FRIEND_P (olddecl) = 1; | |
2419 | ||
2420 | /* Restore some pieces of information which were originally in olddecl. */ | |
2421 | ||
2422 | DECL_UID (olddecl) = saved_old_decl_uid; | |
2423 | if (DECL_LANG_SPECIFIC (olddecl)) | |
2424 | DECL_FRIEND_P (olddecl) |= saved_old_decl_friend_p; | |
2425 | ||
2426 | return 1; | |
2427 | } | |
2428 | ||
2429 | void | |
2430 | adjust_type_value (id) | |
2431 | tree id; | |
2432 | { | |
2433 | tree t; | |
2434 | ||
2435 | if (current_binding_level != global_binding_level) | |
2436 | { | |
2437 | if (current_binding_level != class_binding_level) | |
2438 | { | |
2439 | t = IDENTIFIER_LOCAL_VALUE (id); | |
2440 | if (t && TREE_CODE (t) == TYPE_DECL) | |
2441 | { | |
2442 | set_it: | |
2443 | SET_IDENTIFIER_TYPE_VALUE (id, TREE_TYPE (t)); | |
2444 | return; | |
2445 | } | |
2446 | } | |
2447 | else | |
2448 | my_friendly_abort (7); | |
2449 | ||
2450 | if (current_class_type) | |
2451 | { | |
2452 | t = IDENTIFIER_CLASS_VALUE (id); | |
2453 | if (t && TREE_CODE (t) == TYPE_DECL) | |
2454 | goto set_it; | |
2455 | } | |
2456 | } | |
2457 | ||
2458 | t = IDENTIFIER_GLOBAL_VALUE (id); | |
2459 | if (t && TREE_CODE (t) == TYPE_DECL) | |
2460 | goto set_it; | |
2461 | if (t && TREE_CODE (t) == TEMPLATE_DECL) | |
2462 | SET_IDENTIFIER_TYPE_VALUE (id, NULL_TREE); | |
2463 | } | |
2464 | ||
2465 | /* Record a decl-node X as belonging to the current lexical scope. | |
2466 | Check for errors (such as an incompatible declaration for the same | |
2467 | name already seen in the same scope). | |
2468 | ||
2469 | Returns either X or an old decl for the same name. | |
2470 | If an old decl is returned, it may have been smashed | |
2471 | to agree with what X says. */ | |
2472 | ||
2473 | tree | |
2474 | pushdecl (x) | |
2475 | tree x; | |
2476 | { | |
2477 | register tree t; | |
2478 | #if 0 /* not yet, should get fixed properly later */ | |
2479 | register tree name; | |
2480 | #else | |
2481 | register tree name = DECL_ASSEMBLER_NAME (x); | |
2482 | #endif | |
2483 | register struct binding_level *b = current_binding_level; | |
2484 | ||
2485 | #if 0 | |
2486 | static int nglobals; int len; | |
2487 | ||
2488 | len = list_length (global_binding_level->names); | |
2489 | if (len < nglobals) | |
2490 | my_friendly_abort (8); | |
2491 | else if (len > nglobals) | |
2492 | nglobals = len; | |
2493 | #endif | |
2494 | ||
2495 | /* Don't change DECL_CONTEXT of virtual methods. */ | |
2496 | if (x != current_function_decl | |
2497 | && (TREE_CODE (x) != FUNCTION_DECL | |
2498 | || !DECL_VIRTUAL_P (x))) | |
2499 | DECL_CONTEXT (x) = current_function_decl; | |
2500 | /* A local declaration for a function doesn't constitute nesting. */ | |
2501 | if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0) | |
2502 | DECL_CONTEXT (x) = 0; | |
2503 | ||
2504 | #if 0 /* not yet, should get fixed properly later */ | |
2505 | /* For functions and class static data, we currently look up the encoded | |
2506 | form of the name. For types, we want the real name. The former will | |
2507 | probably be changed soon, according to MDT. */ | |
2508 | if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) | |
2509 | name = DECL_ASSEMBLER_NAME (x); | |
2510 | else | |
2511 | name = DECL_NAME (x); | |
2512 | #else | |
2513 | /* Type are looked up using the DECL_NAME, as that is what the rest of the | |
2514 | compiler wants to use. */ | |
2515 | if (TREE_CODE (x) == TYPE_DECL) | |
2516 | name = DECL_NAME (x); | |
2517 | #endif | |
2518 | ||
2519 | if (name) | |
2520 | { | |
2521 | char *file; | |
2522 | int line; | |
2523 | ||
2524 | t = lookup_name_current_level (name); | |
2525 | if (t == error_mark_node) | |
2526 | { | |
2527 | /* error_mark_node is 0 for a while during initialization! */ | |
2528 | t = NULL_TREE; | |
2529 | error_with_decl (x, "`%s' used prior to declaration"); | |
2530 | } | |
2531 | ||
2532 | if (t != NULL_TREE) | |
2533 | { | |
2534 | if (TREE_CODE (t) == PARM_DECL) | |
2535 | { | |
2536 | if (DECL_CONTEXT (t) == NULL_TREE) | |
2537 | fatal ("parse errors have confused me too much"); | |
2538 | } | |
2539 | file = DECL_SOURCE_FILE (t); | |
2540 | line = DECL_SOURCE_LINE (t); | |
2541 | } | |
2542 | ||
2543 | if (t != NULL_TREE && TREE_CODE (t) != TREE_CODE (x)) | |
2544 | { | |
2545 | if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (x) == TYPE_DECL) | |
2546 | { | |
2547 | /* We do nothing special here, because C++ does such nasty | |
2548 | things with TYPE_DECLs. Instead, just let the TYPE_DECL | |
2549 | get shadowed, and know that if we need to find a TYPE_DECL | |
2550 | for a given name, we can look in the IDENTIFIER_TYPE_VALUE | |
2551 | slot of the identifier. */ | |
2552 | ; | |
2553 | } | |
2554 | else if (duplicate_decls (x, t)) | |
2555 | return t; | |
2556 | } | |
2557 | else if (t != NULL_TREE && duplicate_decls (x, t)) | |
2558 | { | |
2559 | /* If this decl is `static' and an `extern' was seen previously, | |
2560 | that is erroneous. But don't complain if -traditional, | |
2561 | since traditional compilers don't complain. | |
2562 | ||
2563 | Note that this does not apply to the C++ case of declaring | |
2564 | a variable `extern const' and then later `const'. */ | |
2565 | if (!flag_traditional && TREE_PUBLIC (name) | |
2566 | && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x) && ! DECL_INLINE (x)) | |
2567 | { | |
2568 | /* Due to interference in memory reclamation (X may be | |
2569 | obstack-deallocated at this point), we must guard against | |
2570 | one really special case. */ | |
2571 | if (current_function_decl == x) | |
2572 | current_function_decl = t; | |
2573 | if (IDENTIFIER_IMPLICIT_DECL (name)) | |
2574 | warning ("`%s' was declared implicitly `extern' and later `static'", | |
2575 | lang_printable_name (t)); | |
2576 | else | |
2577 | warning ("`%s' was declared `extern' and later `static'", | |
2578 | lang_printable_name (t)); | |
2579 | warning_with_file_and_line (file, line, | |
2580 | "previous declaration of `%s'", | |
2581 | lang_printable_name (t)); | |
2582 | } | |
2583 | return t; | |
2584 | } | |
2585 | ||
2586 | /* If declaring a type as a typedef, and the type has no known | |
2587 | typedef name, install this TYPE_DECL as its typedef name. | |
2588 | ||
2589 | C++: If it had an anonymous aggregate or enum name, | |
2590 | give it a `better' one. */ | |
2591 | if (TREE_CODE (x) == TYPE_DECL) | |
2592 | { | |
2593 | tree name = TYPE_NAME (TREE_TYPE (x)); | |
2594 | ||
2595 | if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL) | |
2596 | { | |
2597 | /* If these are different names, and we're at the global | |
2598 | binding level, make two equivalent definitions. */ | |
2599 | name = x; | |
2600 | if (global_bindings_p ()) | |
2601 | TYPE_NAME (TREE_TYPE (x)) = x; | |
2602 | } | |
2603 | else | |
2604 | { | |
2605 | tree tname = DECL_NAME (name); | |
2606 | if (global_bindings_p () && ANON_AGGRNAME_P (tname)) | |
2607 | { | |
2608 | /* do gratuitous C++ typedefing, and make sure that | |
2609 | we access this type either through TREE_TYPE field | |
2610 | or via the tags list. */ | |
2611 | TYPE_NAME (TREE_TYPE (x)) = x; | |
2612 | pushtag (tname, TREE_TYPE (x)); | |
2613 | } | |
2614 | } | |
2615 | my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140); | |
2616 | if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name)) | |
2617 | set_nested_typename (x, current_class_name, DECL_NAME (name), | |
2618 | TREE_TYPE (x)); | |
2619 | if (TYPE_NAME (TREE_TYPE (x)) && TYPE_IDENTIFIER (TREE_TYPE (x))) | |
2620 | set_identifier_type_value (DECL_NAME (x), TREE_TYPE (x)); | |
2621 | /* was using TYPE_IDENTIFIER (TREE_TYPE (x)) */ | |
2622 | } | |
2623 | ||
2624 | /* Multiple external decls of the same identifier ought to match. */ | |
2625 | ||
2626 | if (DECL_EXTERNAL (x) && IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE | |
2627 | && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name)) | |
2628 | || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))) | |
2629 | /* We get warnings about inline functions where they are defined. | |
2630 | Avoid duplicate warnings where they are used. */ | |
2631 | && !DECL_INLINE (x)) | |
2632 | { | |
2633 | if (! comptypes (TREE_TYPE (x), | |
2634 | TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)), 1)) | |
2635 | { | |
2636 | warning_with_decl (x, | |
2637 | "type mismatch with previous external decl"); | |
2638 | warning_with_decl (IDENTIFIER_GLOBAL_VALUE (name), | |
2639 | "previous external decl of `%s'"); | |
2640 | } | |
2641 | } | |
2642 | ||
2643 | /* In PCC-compatibility mode, extern decls of vars with no current decl | |
2644 | take effect at top level no matter where they are. */ | |
2645 | if (flag_traditional && DECL_EXTERNAL (x) | |
2646 | && lookup_name (name, 0) == NULL_TREE) | |
2647 | b = global_binding_level; | |
2648 | ||
2649 | /* This name is new in its binding level. | |
2650 | Install the new declaration and return it. */ | |
2651 | if (b == global_binding_level) | |
2652 | { | |
2653 | /* Install a global value. */ | |
2654 | ||
2655 | /* Rule for VAR_DECLs, but not for other kinds of _DECLs: | |
2656 | A `const' which was not declared `extern' is invisible. */ | |
2657 | if (TREE_CODE (x) == VAR_DECL | |
2658 | && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x)) | |
2659 | TREE_PUBLIC (x) = 0; | |
2660 | ||
2661 | /* If the first global decl has external linkage, | |
2662 | warn if we later see static one. */ | |
2663 | if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x)) | |
2664 | TREE_PUBLIC (name) = 1; | |
2665 | ||
2666 | /* Don't install a TYPE_DECL if we already have another | |
2667 | sort of _DECL with that name. */ | |
2668 | if (TREE_CODE (x) != TYPE_DECL | |
2669 | || t == NULL_TREE | |
2670 | || TREE_CODE (t) == TYPE_DECL) | |
2671 | #if 0 | |
2672 | /* This has not be thoroughly tested yet. */ | |
2673 | /* It allows better dwarf debugging. */ | |
2674 | IDENTIFIER_GLOBAL_VALUE (name) | |
2675 | = TREE_CODE_CLASS (TREE_CODE (x)) == 'd' | |
2676 | ? x : build_decl (TYPE_DECL, NULL, TREE_TYPE (x)); | |
2677 | #else | |
2678 | IDENTIFIER_GLOBAL_VALUE (name) = x; | |
2679 | #endif | |
2680 | ||
2681 | /* Don't forget if the function was used via an implicit decl. */ | |
2682 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
2683 | && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) | |
2684 | TREE_USED (x) = 1; | |
2685 | ||
2686 | /* Don't forget if its address was taken in that way. */ | |
2687 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
2688 | && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) | |
2689 | TREE_ADDRESSABLE (x) = 1; | |
2690 | ||
2691 | /* Warn about mismatches against previous implicit decl. */ | |
2692 | if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE | |
2693 | /* If this real decl matches the implicit, don't complain. */ | |
2694 | && ! (TREE_CODE (x) == FUNCTION_DECL | |
2695 | && TREE_TYPE (TREE_TYPE (x)) == integer_type_node)) | |
2696 | warning ("`%s' was previously implicitly declared to return `int'", | |
2697 | lang_printable_name (x)); | |
2698 | ||
2699 | /* If this decl is `static' and an `extern' was seen previously, | |
2700 | that is erroneous. Don't do this for TYPE_DECLs. */ | |
2701 | if (TREE_PUBLIC (name) | |
2702 | && TREE_CODE (x) != TYPE_DECL | |
2703 | && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x)) | |
2704 | { | |
2705 | if (IDENTIFIER_IMPLICIT_DECL (name)) | |
2706 | warning ("`%s' was declared implicitly `extern' and later `static'", | |
2707 | lang_printable_name (x)); | |
2708 | else | |
2709 | warning ("`%s' was declared `extern' and later `static'", | |
2710 | lang_printable_name (x)); | |
2711 | } | |
2712 | } | |
2713 | else | |
2714 | { | |
2715 | /* Here to install a non-global value. */ | |
2716 | tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); | |
2717 | tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); | |
2718 | set_identifier_local_value (name, x); | |
2719 | ||
2720 | /* If this is an extern function declaration, see if we | |
2721 | have a global definition or declaration for the function. */ | |
2722 | if (oldlocal == NULL_TREE | |
2723 | && DECL_EXTERNAL (x) && !DECL_INLINE (x) | |
2724 | && oldglobal != NULL_TREE | |
2725 | && TREE_CODE (x) == FUNCTION_DECL | |
2726 | && TREE_CODE (oldglobal) == FUNCTION_DECL) | |
2727 | { | |
2728 | /* We have one. Their types must agree. */ | |
2729 | if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1)) | |
2730 | warning_with_decl (x, "extern declaration of `%s' doesn't match global one"); | |
2731 | else | |
2732 | { | |
2733 | /* Inner extern decl is inline if global one is. | |
2734 | Copy enough to really inline it. */ | |
2735 | if (DECL_INLINE (oldglobal)) | |
2736 | { | |
2737 | DECL_INLINE (x) = DECL_INLINE (oldglobal); | |
2738 | DECL_INITIAL (x) = (current_function_decl == oldglobal | |
2739 | ? NULL_TREE : DECL_INITIAL (oldglobal)); | |
2740 | DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal); | |
2741 | DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal); | |
2742 | DECL_RESULT (x) = DECL_RESULT (oldglobal); | |
2743 | TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal); | |
2744 | DECL_ABSTRACT_ORIGIN (x) = oldglobal; | |
2745 | } | |
2746 | /* Inner extern decl is built-in if global one is. */ | |
2747 | if (DECL_BUILT_IN (oldglobal)) | |
2748 | { | |
2749 | DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal); | |
2750 | DECL_SET_FUNCTION_CODE (x, DECL_FUNCTION_CODE (oldglobal)); | |
2751 | } | |
2752 | /* Keep the arg types from a file-scope fcn defn. */ | |
2753 | if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != NULL_TREE | |
2754 | && DECL_INITIAL (oldglobal) | |
2755 | && TYPE_ARG_TYPES (TREE_TYPE (x)) == NULL_TREE) | |
2756 | TREE_TYPE (x) = TREE_TYPE (oldglobal); | |
2757 | } | |
2758 | } | |
2759 | /* If we have a local external declaration, | |
2760 | and no file-scope declaration has yet been seen, | |
2761 | then if we later have a file-scope decl it must not be static. */ | |
2762 | if (oldlocal == NULL_TREE | |
2763 | && oldglobal == NULL_TREE | |
2764 | && DECL_EXTERNAL (x) | |
2765 | && TREE_PUBLIC (x)) | |
2766 | { | |
2767 | TREE_PUBLIC (name) = 1; | |
2768 | } | |
2769 | ||
2770 | if (DECL_FROM_INLINE (x)) | |
2771 | /* Inline decls shadow nothing. */; | |
2772 | ||
2773 | /* Warn if shadowing an argument at the top level of the body. */ | |
2774 | else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) | |
2775 | && TREE_CODE (oldlocal) == PARM_DECL | |
2776 | && TREE_CODE (x) != PARM_DECL) | |
2777 | { | |
2778 | /* Go to where the parms should be and see if we | |
2779 | find them there. */ | |
2780 | struct binding_level *b = current_binding_level->level_chain; | |
2781 | ||
2782 | if (cleanup_label) | |
2783 | b = b->level_chain; | |
2784 | ||
2785 | /* ARM $8.3 */ | |
2786 | if (b->parm_flag == 1) | |
2787 | pedwarn ("declaration of `%s' shadows a parameter", | |
2788 | IDENTIFIER_POINTER (name)); | |
2789 | } | |
2790 | /* Maybe warn if shadowing something else. */ | |
2791 | else if (warn_shadow && !DECL_EXTERNAL (x) | |
2792 | /* No shadow warnings for internally generated vars. */ | |
2793 | && DECL_SOURCE_LINE (x) != 0 | |
2794 | /* No shadow warnings for vars made for inlining. */ | |
2795 | && ! DECL_FROM_INLINE (x)) | |
2796 | { | |
2797 | char *warnstring = NULL; | |
2798 | ||
2799 | if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) | |
2800 | warnstring = "declaration of `%s' shadows a parameter"; | |
2801 | else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE) | |
2802 | warnstring = "declaration of `%s' shadows a member of `this'"; | |
2803 | else if (oldlocal != NULL_TREE) | |
2804 | warnstring = "declaration of `%s' shadows previous local"; | |
2805 | else if (oldglobal != NULL_TREE) | |
2806 | warnstring = "declaration of `%s' shadows global declaration"; | |
2807 | ||
2808 | if (warnstring) | |
2809 | warning (warnstring, IDENTIFIER_POINTER (name)); | |
2810 | } | |
2811 | ||
2812 | /* If storing a local value, there may already be one (inherited). | |
2813 | If so, record it for restoration when this binding level ends. */ | |
2814 | if (oldlocal != NULL_TREE) | |
2815 | b->shadowed = tree_cons (name, oldlocal, b->shadowed); | |
2816 | } | |
2817 | ||
2818 | /* Keep count of variables in this level with incomplete type. */ | |
2819 | if (TREE_CODE (x) != TEMPLATE_DECL | |
2820 | && TREE_CODE (x) != CPLUS_CATCH_DECL | |
2821 | && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE | |
2822 | && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) | |
2823 | { | |
2824 | if (++b->n_incomplete == 0) | |
2825 | error ("too many incomplete variables at this point"); | |
2826 | } | |
2827 | } | |
2828 | ||
2829 | if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE) | |
2830 | { | |
2831 | adjust_type_value (name); | |
2832 | if (current_class_name) | |
2833 | { | |
2834 | if (!DECL_NESTED_TYPENAME (x)) | |
2835 | set_nested_typename (x, current_class_name, DECL_NAME (x), | |
2836 | TREE_TYPE (x)); | |
2837 | adjust_type_value (DECL_NESTED_TYPENAME (x)); | |
2838 | } | |
2839 | } | |
2840 | ||
2841 | /* Put decls on list in reverse order. | |
2842 | We will reverse them later if necessary. */ | |
2843 | TREE_CHAIN (x) = b->names; | |
2844 | b->names = x; | |
2845 | if (! (b != global_binding_level || TREE_PERMANENT (x))) | |
2846 | my_friendly_abort (124); | |
2847 | ||
2848 | return x; | |
2849 | } | |
2850 | ||
2851 | /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, | |
2852 | if appropriate. */ | |
2853 | tree | |
2854 | pushdecl_top_level (x) | |
2855 | tree x; | |
2856 | { | |
2857 | register tree t; | |
2858 | register struct binding_level *b = current_binding_level; | |
2859 | ||
2860 | current_binding_level = global_binding_level; | |
2861 | t = pushdecl (x); | |
2862 | current_binding_level = b; | |
2863 | if (class_binding_level) | |
2864 | b = class_binding_level; | |
2865 | /* Now, the type_shadowed stack may screw us. Munge it so it does | |
2866 | what we want. */ | |
2867 | if (TREE_CODE (x) == TYPE_DECL) | |
2868 | { | |
2869 | tree name = DECL_NAME (x); | |
2870 | tree newval; | |
2871 | tree *ptr = (tree *)0; | |
2872 | for (; b != global_binding_level; b = b->level_chain) | |
2873 | { | |
2874 | tree shadowed = b->type_shadowed; | |
2875 | for (; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
2876 | if (TREE_PURPOSE (shadowed) == name) | |
2877 | { | |
2878 | ptr = &TREE_VALUE (shadowed); | |
2879 | /* Can't break out of the loop here because sometimes | |
2880 | a binding level will have duplicate bindings for | |
2881 | PT names. It's gross, but I haven't time to fix it. */ | |
2882 | } | |
2883 | } | |
2884 | newval = TREE_TYPE (x); | |
2885 | if (ptr == (tree *)0) | |
2886 | { | |
2887 | /* @@ This shouldn't be needed. My test case "zstring.cc" trips | |
2888 | up here if this is changed to an assertion. --KR */ | |
2889 | SET_IDENTIFIER_TYPE_VALUE (name, newval); | |
2890 | } | |
2891 | else | |
2892 | { | |
2893 | #if 0 | |
2894 | /* Disabled this 11/10/92, since there are many cases which | |
2895 | behave just fine when *ptr doesn't satisfy either of these. | |
2896 | For example, nested classes declared as friends of their enclosing | |
2897 | class will not meet this criteria. (bpk) */ | |
2898 | my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141); | |
2899 | #endif | |
2900 | *ptr = newval; | |
2901 | } | |
2902 | } | |
2903 | return t; | |
2904 | } | |
2905 | ||
2906 | /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL, | |
2907 | if appropriate. */ | |
2908 | void | |
2909 | push_overloaded_decl_top_level (x, forget) | |
2910 | tree x; | |
2911 | int forget; | |
2912 | { | |
2913 | struct binding_level *b = current_binding_level; | |
2914 | ||
2915 | current_binding_level = global_binding_level; | |
2916 | push_overloaded_decl (x, forget); | |
2917 | current_binding_level = b; | |
2918 | } | |
2919 | ||
2920 | /* Make the declaration of X appear in CLASS scope. */ | |
2921 | tree | |
2922 | pushdecl_class_level (x) | |
2923 | tree x; | |
2924 | { | |
2925 | /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class | |
2926 | scope looks for the pre-mangled name. */ | |
2927 | register tree name = DECL_NAME (x); | |
2928 | ||
2929 | if (name) | |
2930 | { | |
2931 | tree oldclass = IDENTIFIER_CLASS_VALUE (name); | |
2932 | if (oldclass) | |
2933 | class_binding_level->class_shadowed | |
2934 | = tree_cons (name, oldclass, class_binding_level->class_shadowed); | |
2935 | IDENTIFIER_CLASS_VALUE (name) = x; | |
2936 | obstack_ptr_grow (&decl_obstack, x); | |
2937 | if (TREE_CODE (x) == TYPE_DECL && !DECL_NESTED_TYPENAME (x)) | |
2938 | set_nested_typename (x, current_class_name, name, TREE_TYPE (x)); | |
2939 | } | |
2940 | return x; | |
2941 | } | |
2942 | ||
2943 | /* Tell caller how to interpret a TREE_LIST which contains | |
2944 | chains of FUNCTION_DECLS. */ | |
2945 | int | |
2946 | overloaded_globals_p (list) | |
2947 | tree list; | |
2948 | { | |
2949 | my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142); | |
2950 | ||
2951 | /* Don't commit caller to seeing them as globals. */ | |
2952 | if (TREE_NONLOCAL_FLAG (list)) | |
2953 | return -1; | |
2954 | /* Do commit caller to seeing them as globals. */ | |
2955 | if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE) | |
2956 | return 1; | |
2957 | /* Do commit caller to not seeing them as globals. */ | |
2958 | return 0; | |
2959 | } | |
2960 | ||
2961 | /* DECL is a FUNCTION_DECL which may have other definitions already in place. | |
2962 | We get around this by making IDENTIFIER_GLOBAL_VALUE (DECL_NAME (DECL)) | |
2963 | point to a list of all the things that want to be referenced by that name. | |
2964 | It is then up to the users of that name to decide what to do with that | |
2965 | list. | |
2966 | ||
2967 | DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT | |
2968 | slot. It is dealt with the same way. | |
2969 | ||
2970 | The value returned may be a previous declaration if we guessed wrong | |
2971 | about what language DECL should belong to (C or C++). Otherwise, | |
2972 | it's always DECL (and never something that's not a _DECL). */ | |
2973 | tree | |
2974 | push_overloaded_decl (decl, forgettable) | |
2975 | tree decl; | |
2976 | int forgettable; | |
2977 | { | |
2978 | tree orig_name = DECL_NAME (decl); | |
2979 | tree glob = IDENTIFIER_GLOBAL_VALUE (orig_name); | |
2980 | ||
2981 | DECL_OVERLOADED (decl) = 1; | |
2982 | if (glob) | |
2983 | { | |
2984 | if (TREE_CODE (glob) != TREE_LIST) | |
2985 | { | |
2986 | if (DECL_LANGUAGE (decl) == lang_c) | |
2987 | { | |
2988 | if (TREE_CODE (glob) == FUNCTION_DECL) | |
2989 | { | |
2990 | if (DECL_LANGUAGE (glob) == lang_c) | |
2991 | { | |
2992 | error_with_decl (decl, "C-language function `%s' overloaded here"); | |
2993 | error_with_decl (glob, "Previous C-language version of this function was `%s'"); | |
2994 | } | |
2995 | } | |
2996 | else | |
2997 | my_friendly_abort (9); | |
2998 | } | |
2999 | if (forgettable | |
3000 | && ! flag_traditional | |
3001 | && TREE_PERMANENT (glob) == 1 | |
3002 | && !global_bindings_p ()) | |
3003 | overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget); | |
3004 | /* We cache the value of builtin functions as ADDR_EXPRs | |
3005 | in the name space. Convert it to some kind of _DECL after | |
3006 | remembering what to forget. */ | |
3007 | if (TREE_CODE (glob) == ADDR_EXPR) | |
3008 | glob = TREE_OPERAND (glob, 0); | |
3009 | ||
3010 | if (TREE_CODE (glob) == FUNCTION_DECL | |
3011 | && DECL_LANGUAGE (glob) != DECL_LANGUAGE (decl) | |
3012 | && comptypes (TREE_TYPE (glob), TREE_TYPE (decl), 1)) | |
3013 | { | |
3014 | if (current_lang_stack == current_lang_base) | |
3015 | { | |
3016 | DECL_LANGUAGE (decl) = DECL_LANGUAGE (glob); | |
3017 | return glob; | |
3018 | } | |
3019 | else | |
3020 | { | |
3021 | error_with_decl (decl, "conflicting language contexts for declaration of `%s';"); | |
3022 | error_with_decl (glob, "conflicts with previous declaration here"); | |
3023 | } | |
3024 | } | |
3025 | if (pedantic && TREE_CODE (glob) == VAR_DECL) | |
3026 | { | |
3027 | my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (glob)) == 'd', 143); | |
3028 | error_with_decl (glob, "non-function declaration `%s'"); | |
3029 | error_with_decl (decl, "conflicts with function declaration `%s'"); | |
3030 | } | |
3031 | glob = tree_cons (orig_name, glob, NULL_TREE); | |
3032 | glob = tree_cons (TREE_PURPOSE (glob), decl, glob); | |
3033 | IDENTIFIER_GLOBAL_VALUE (orig_name) = glob; | |
3034 | TREE_TYPE (glob) = unknown_type_node; | |
3035 | return decl; | |
3036 | } | |
3037 | ||
3038 | if (TREE_VALUE (glob) == NULL_TREE) | |
3039 | { | |
3040 | TREE_VALUE (glob) = decl; | |
3041 | return decl; | |
3042 | } | |
3043 | if (TREE_CODE (decl) != TEMPLATE_DECL) | |
3044 | { | |
3045 | tree name = DECL_ASSEMBLER_NAME (decl); | |
3046 | tree tmp; | |
3047 | ||
3048 | for (tmp = glob; tmp; tmp = TREE_CHAIN (tmp)) | |
3049 | { | |
3050 | if (TREE_CODE (TREE_VALUE (tmp)) == FUNCTION_DECL | |
3051 | && DECL_LANGUAGE (TREE_VALUE (tmp)) != DECL_LANGUAGE (decl) | |
3052 | && comptypes (TREE_TYPE (TREE_VALUE (tmp)), TREE_TYPE (decl), | |
3053 | 1)) | |
3054 | { | |
3055 | error_with_decl (decl, | |
3056 | "conflicting language contexts for declaration of `%s';"); | |
3057 | error_with_decl (TREE_VALUE (tmp), | |
3058 | "conflicts with previous declaration here"); | |
3059 | } | |
3060 | if (TREE_CODE (TREE_VALUE (tmp)) != TEMPLATE_DECL | |
3061 | && DECL_ASSEMBLER_NAME (TREE_VALUE (tmp)) == name) | |
3062 | return decl; | |
3063 | } | |
3064 | } | |
3065 | } | |
3066 | if (DECL_LANGUAGE (decl) == lang_c) | |
3067 | { | |
3068 | tree decls = glob; | |
3069 | while (decls && DECL_LANGUAGE (TREE_VALUE (decls)) == lang_cplusplus) | |
3070 | decls = TREE_CHAIN (decls); | |
3071 | if (decls) | |
3072 | { | |
3073 | error_with_decl (decl, "C-language function `%s' overloaded here"); | |
3074 | error_with_decl (TREE_VALUE (decls), "Previous C-language version of this function was `%s'"); | |
3075 | } | |
3076 | } | |
3077 | ||
3078 | if (forgettable | |
3079 | && ! flag_traditional | |
3080 | && (glob == NULL_TREE || TREE_PERMANENT (glob) == 1) | |
3081 | && !global_bindings_p () | |
3082 | && !pseudo_global_level_p ()) | |
3083 | overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget); | |
3084 | glob = tree_cons (orig_name, decl, glob); | |
3085 | IDENTIFIER_GLOBAL_VALUE (orig_name) = glob; | |
3086 | TREE_TYPE (glob) = unknown_type_node; | |
3087 | return decl; | |
3088 | } | |
3089 | \f | |
3090 | /* Generate an implicit declaration for identifier FUNCTIONID | |
3091 | as a function of type int (). Print a warning if appropriate. */ | |
3092 | ||
3093 | tree | |
3094 | implicitly_declare (functionid) | |
3095 | tree functionid; | |
3096 | { | |
3097 | register tree decl; | |
3098 | int temp = allocation_temporary_p (); | |
3099 | ||
3100 | push_obstacks_nochange (); | |
3101 | ||
3102 | /* Save the decl permanently so we can warn if definition follows. | |
3103 | In ANSI C, warn_implicit is usually false, so the saves little space. | |
3104 | But in C++, it's usually true, hence the extra code. */ | |
3105 | if (temp && (flag_traditional || !warn_implicit | |
3106 | || current_binding_level == global_binding_level)) | |
3107 | end_temporary_allocation (); | |
3108 | ||
3109 | /* We used to reuse an old implicit decl here, | |
3110 | but this loses with inline functions because it can clobber | |
3111 | the saved decl chains. */ | |
3112 | decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type); | |
3113 | ||
3114 | DECL_EXTERNAL (decl) = 1; | |
3115 | TREE_PUBLIC (decl) = 1; | |
3116 | ||
3117 | /* ANSI standard says implicit declarations are in the innermost block. | |
3118 | So we record the decl in the standard fashion. | |
3119 | If flag_traditional is set, pushdecl does it top-level. */ | |
3120 | pushdecl (decl); | |
3121 | rest_of_decl_compilation (decl, NULL_PTR, 0, 0); | |
3122 | ||
3123 | if (warn_implicit | |
3124 | /* Only one warning per identifier. */ | |
3125 | && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE) | |
3126 | { | |
3127 | pedwarn ("implicit declaration of function `%s'", | |
3128 | IDENTIFIER_POINTER (functionid)); | |
3129 | } | |
3130 | ||
3131 | SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl); | |
3132 | ||
3133 | pop_obstacks (); | |
3134 | ||
3135 | return decl; | |
3136 | } | |
3137 | ||
3138 | /* Return zero if the declaration NEWDECL is valid | |
3139 | when the declaration OLDDECL (assumed to be for the same name) | |
3140 | has already been seen. | |
3141 | Otherwise return an error message format string with a %s | |
3142 | where the identifier should go. */ | |
3143 | ||
3144 | static char * | |
3145 | redeclaration_error_message (newdecl, olddecl) | |
3146 | tree newdecl, olddecl; | |
3147 | { | |
3148 | if (TREE_CODE (newdecl) == TYPE_DECL) | |
3149 | { | |
3150 | /* Because C++ can put things into name space for free, | |
3151 | constructs like "typedef struct foo { ... } foo" | |
3152 | would look like an erroneous redeclaration. */ | |
3153 | if (TREE_TYPE (olddecl) == TREE_TYPE (newdecl)) | |
3154 | return 0; | |
3155 | else | |
3156 | return "redefinition of `%s'"; | |
3157 | } | |
3158 | else if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
3159 | { | |
3160 | /* If this is a pure function, its olddecl will actually be | |
3161 | the original initialization to `0' (which we force to call | |
3162 | abort()). Don't complain about redefinition in this case. */ | |
3163 | if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) | |
3164 | return 0; | |
3165 | ||
3166 | /* Declarations of functions can insist on internal linkage | |
3167 | but they can't be inconsistent with internal linkage, | |
3168 | so there can be no error on that account. | |
3169 | However defining the same name twice is no good. */ | |
3170 | if (DECL_INITIAL (olddecl) != NULL_TREE | |
3171 | && DECL_INITIAL (newdecl) != NULL_TREE | |
3172 | /* However, defining once as extern inline and a second | |
3173 | time in another way is ok. */ | |
3174 | && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl) | |
3175 | && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl)))) | |
3176 | { | |
3177 | if (DECL_NAME (olddecl) == NULL_TREE) | |
3178 | return "`%s' not declared in class"; | |
3179 | else | |
3180 | return "redefinition of `%s'"; | |
3181 | } | |
3182 | return 0; | |
3183 | } | |
3184 | else if (current_binding_level == global_binding_level) | |
3185 | { | |
3186 | /* Objects declared at top level: */ | |
3187 | /* If at least one is a reference, it's ok. */ | |
3188 | if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) | |
3189 | return 0; | |
3190 | /* Reject two definitions. */ | |
3191 | if (DECL_INITIAL (olddecl) != NULL_TREE | |
3192 | && DECL_INITIAL (newdecl) != NULL_TREE) | |
3193 | return "redefinition of `%s'"; | |
3194 | /* Now we have two tentative defs, or one tentative and one real def. */ | |
3195 | /* Insist that the linkage match. */ | |
3196 | if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl)) | |
3197 | return "conflicting declarations of `%s'"; | |
3198 | return 0; | |
3199 | } | |
3200 | else | |
3201 | { | |
3202 | /* Objects declared with block scope: */ | |
3203 | /* Reject two definitions, and reject a definition | |
3204 | together with an external reference. */ | |
3205 | if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))) | |
3206 | return "redeclaration of `%s'"; | |
3207 | return 0; | |
3208 | } | |
3209 | } | |
3210 | \f | |
3211 | /* Get the LABEL_DECL corresponding to identifier ID as a label. | |
3212 | Create one if none exists so far for the current function. | |
3213 | This function is called for both label definitions and label references. */ | |
3214 | ||
3215 | tree | |
3216 | lookup_label (id) | |
3217 | tree id; | |
3218 | { | |
3219 | register tree decl = IDENTIFIER_LABEL_VALUE (id); | |
3220 | ||
3221 | if ((decl == NULL_TREE | |
3222 | || DECL_SOURCE_LINE (decl) == 0) | |
3223 | && (named_label_uses == 0 | |
3224 | || TREE_PURPOSE (named_label_uses) != current_binding_level->names | |
3225 | || TREE_VALUE (named_label_uses) != decl)) | |
3226 | { | |
3227 | named_label_uses | |
3228 | = tree_cons (current_binding_level->names, decl, named_label_uses); | |
3229 | TREE_TYPE (named_label_uses) = (tree)current_binding_level; | |
3230 | } | |
3231 | ||
3232 | /* Use a label already defined or ref'd with this name. */ | |
3233 | if (decl != NULL_TREE) | |
3234 | { | |
3235 | /* But not if it is inherited and wasn't declared to be inheritable. */ | |
3236 | if (DECL_CONTEXT (decl) != current_function_decl | |
3237 | && ! C_DECLARED_LABEL_FLAG (decl)) | |
3238 | return shadow_label (id); | |
3239 | return decl; | |
3240 | } | |
3241 | ||
3242 | decl = build_decl (LABEL_DECL, id, void_type_node); | |
3243 | ||
3244 | /* A label not explicitly declared must be local to where it's ref'd. */ | |
3245 | DECL_CONTEXT (decl) = current_function_decl; | |
3246 | ||
3247 | DECL_MODE (decl) = VOIDmode; | |
3248 | ||
3249 | /* Say where one reference is to the label, | |
3250 | for the sake of the error if it is not defined. */ | |
3251 | DECL_SOURCE_LINE (decl) = lineno; | |
3252 | DECL_SOURCE_FILE (decl) = input_filename; | |
3253 | ||
3254 | SET_IDENTIFIER_LABEL_VALUE (id, decl); | |
3255 | ||
3256 | named_labels = tree_cons (NULL_TREE, decl, named_labels); | |
3257 | TREE_VALUE (named_label_uses) = decl; | |
3258 | ||
3259 | return decl; | |
3260 | } | |
3261 | ||
3262 | /* Make a label named NAME in the current function, | |
3263 | shadowing silently any that may be inherited from containing functions | |
3264 | or containing scopes. | |
3265 | ||
3266 | Note that valid use, if the label being shadowed | |
3267 | comes from another scope in the same function, | |
3268 | requires calling declare_nonlocal_label right away. */ | |
3269 | ||
3270 | tree | |
3271 | shadow_label (name) | |
3272 | tree name; | |
3273 | { | |
3274 | register tree decl = IDENTIFIER_LABEL_VALUE (name); | |
3275 | ||
3276 | if (decl != NULL_TREE) | |
3277 | { | |
3278 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
3279 | SET_IDENTIFIER_LABEL_VALUE (name, 0); | |
3280 | SET_IDENTIFIER_LABEL_VALUE (decl, 0); | |
3281 | } | |
3282 | ||
3283 | return lookup_label (name); | |
3284 | } | |
3285 | ||
3286 | /* Define a label, specifying the location in the source file. | |
3287 | Return the LABEL_DECL node for the label, if the definition is valid. | |
3288 | Otherwise return 0. */ | |
3289 | ||
3290 | tree | |
3291 | define_label (filename, line, name) | |
3292 | char *filename; | |
3293 | int line; | |
3294 | tree name; | |
3295 | { | |
3296 | tree decl = lookup_label (name); | |
3297 | ||
3298 | /* After labels, make any new cleanups go into their | |
3299 | own new (temporary) binding contour. */ | |
3300 | current_binding_level->more_cleanups_ok = 0; | |
3301 | ||
3302 | /* If label with this name is known from an outer context, shadow it. */ | |
3303 | if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl) | |
3304 | { | |
3305 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
3306 | SET_IDENTIFIER_LABEL_VALUE (name, 0); | |
3307 | decl = lookup_label (name); | |
3308 | } | |
3309 | ||
3310 | if (DECL_INITIAL (decl) != NULL_TREE) | |
3311 | { | |
3312 | error_with_decl (decl, "duplicate label `%s'"); | |
3313 | return 0; | |
3314 | } | |
3315 | else | |
3316 | { | |
3317 | tree uses, prev; | |
3318 | ||
3319 | /* Mark label as having been defined. */ | |
3320 | DECL_INITIAL (decl) = error_mark_node; | |
3321 | /* Say where in the source. */ | |
3322 | DECL_SOURCE_FILE (decl) = filename; | |
3323 | DECL_SOURCE_LINE (decl) = line; | |
3324 | ||
3325 | for (prev = NULL_TREE, uses = named_label_uses; | |
3326 | uses; | |
3327 | prev = uses, uses = TREE_CHAIN (uses)) | |
3328 | if (TREE_VALUE (uses) == decl) | |
3329 | { | |
3330 | struct binding_level *b = current_binding_level; | |
3331 | while (b) | |
3332 | { | |
3333 | tree new_decls = b->names; | |
3334 | tree old_decls = ((tree)b == TREE_TYPE (uses) | |
3335 | ? TREE_PURPOSE (uses) : NULL_TREE); | |
3336 | while (new_decls != old_decls) | |
3337 | { | |
3338 | if (TREE_CODE (new_decls) == VAR_DECL | |
3339 | /* Don't complain about crossing initialization | |
3340 | of internal entities. They can't be accessed, | |
3341 | and they should be cleaned up | |
3342 | by the time we get to the label. */ | |
3343 | && DECL_SOURCE_LINE (new_decls) != 0 | |
3344 | && ((DECL_INITIAL (new_decls) != NULL_TREE | |
3345 | && DECL_INITIAL (new_decls) != error_mark_node) | |
3346 | || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) | |
3347 | { | |
3348 | if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE) | |
3349 | error_with_decl (decl, "invalid jump to label `%s'"); | |
3350 | SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl); | |
3351 | error_with_decl (new_decls, "crosses initialization of `%s'"); | |
3352 | } | |
3353 | new_decls = TREE_CHAIN (new_decls); | |
3354 | } | |
3355 | if ((tree)b == TREE_TYPE (uses)) | |
3356 | break; | |
3357 | b = b->level_chain; | |
3358 | } | |
3359 | ||
3360 | if (prev) | |
3361 | TREE_CHAIN (prev) = TREE_CHAIN (uses); | |
3362 | else | |
3363 | named_label_uses = TREE_CHAIN (uses); | |
3364 | } | |
3365 | current_function_return_value = NULL_TREE; | |
3366 | return decl; | |
3367 | } | |
3368 | } | |
3369 | ||
3370 | /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ | |
3371 | /* XXX Note decl is never actually used. (bpk) */ | |
3372 | void | |
3373 | define_case_label (decl) | |
3374 | tree decl; | |
3375 | { | |
3376 | tree cleanup = last_cleanup_this_contour (); | |
3377 | if (cleanup) | |
3378 | { | |
3379 | static int explained = 0; | |
3380 | error_with_decl (TREE_PURPOSE (cleanup), "destructor needed for `%s'"); | |
3381 | error ("where case label appears here"); | |
3382 | if (!explained) | |
3383 | { | |
3384 | error ("(enclose actions of previous case statements requiring"); | |
3385 | error ("destructors in their own binding contours.)"); | |
3386 | explained = 1; | |
3387 | } | |
3388 | } | |
3389 | ||
3390 | /* After labels, make any new cleanups go into their | |
3391 | own new (temporary) binding contour. */ | |
3392 | ||
3393 | current_binding_level->more_cleanups_ok = 0; | |
3394 | current_function_return_value = NULL_TREE; | |
3395 | } | |
3396 | \f | |
3397 | /* Return the list of declarations of the current level. | |
3398 | Note that this list is in reverse order unless/until | |
3399 | you nreverse it; and when you do nreverse it, you must | |
3400 | store the result back using `storedecls' or you will lose. */ | |
3401 | ||
3402 | tree | |
3403 | getdecls () | |
3404 | { | |
3405 | return current_binding_level->names; | |
3406 | } | |
3407 | ||
3408 | /* Return the list of type-tags (for structs, etc) of the current level. */ | |
3409 | ||
3410 | tree | |
3411 | gettags () | |
3412 | { | |
3413 | return current_binding_level->tags; | |
3414 | } | |
3415 | ||
3416 | /* Store the list of declarations of the current level. | |
3417 | This is done for the parameter declarations of a function being defined, | |
3418 | after they are modified in the light of any missing parameters. */ | |
3419 | ||
3420 | static void | |
3421 | storedecls (decls) | |
3422 | tree decls; | |
3423 | { | |
3424 | current_binding_level->names = decls; | |
3425 | } | |
3426 | ||
3427 | /* Similarly, store the list of tags of the current level. */ | |
3428 | ||
3429 | static void | |
3430 | storetags (tags) | |
3431 | tree tags; | |
3432 | { | |
3433 | current_binding_level->tags = tags; | |
3434 | } | |
3435 | \f | |
3436 | /* Given NAME, an IDENTIFIER_NODE, | |
3437 | return the structure (or union or enum) definition for that name. | |
3438 | Searches binding levels from BINDING_LEVEL up to the global level. | |
3439 | If THISLEVEL_ONLY is nonzero, searches only the specified context | |
3440 | (but skips any tag-transparent contexts to find one that is | |
3441 | meaningful for tags). | |
3442 | FORM says which kind of type the caller wants; | |
3443 | it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. | |
3444 | If the wrong kind of type is found, and it's not a template, an error is | |
3445 | reported. */ | |
3446 | ||
3447 | static tree | |
3448 | lookup_tag (form, name, binding_level, thislevel_only) | |
3449 | enum tree_code form; | |
3450 | struct binding_level *binding_level; | |
3451 | tree name; | |
3452 | int thislevel_only; | |
3453 | { | |
3454 | register struct binding_level *level; | |
3455 | ||
3456 | for (level = binding_level; level; level = level->level_chain) | |
3457 | { | |
3458 | register tree tail; | |
3459 | if (ANON_AGGRNAME_P (name)) | |
3460 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
3461 | { | |
3462 | /* There's no need for error checking here, because | |
3463 | anon names are unique throughout the compilation. */ | |
3464 | if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name) | |
3465 | return TREE_VALUE (tail); | |
3466 | } | |
3467 | else | |
3468 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
3469 | { | |
3470 | if (TREE_PURPOSE (tail) == name) | |
3471 | { | |
3472 | enum tree_code code = TREE_CODE (TREE_VALUE (tail)); | |
3473 | /* Should tighten this up; it'll probably permit | |
3474 | UNION_TYPE and a struct template, for example. */ | |
3475 | if (code != form | |
3476 | && !(form != ENUMERAL_TYPE | |
3477 | && (code == TEMPLATE_DECL | |
3478 | || code == UNINSTANTIATED_P_TYPE))) | |
3479 | ||
3480 | { | |
3481 | /* Definition isn't the kind we were looking for. */ | |
3482 | error ("`%s' defined as wrong kind of tag", | |
3483 | IDENTIFIER_POINTER (name)); | |
3484 | } | |
3485 | return TREE_VALUE (tail); | |
3486 | } | |
3487 | } | |
3488 | if (thislevel_only && ! level->tag_transparent) | |
3489 | return NULL_TREE; | |
3490 | if (current_class_type && level->level_chain == global_binding_level) | |
3491 | { | |
3492 | /* Try looking in this class's tags before heading into | |
3493 | global binding level. */ | |
3494 | tree context = current_class_type; | |
3495 | while (context) | |
3496 | { | |
3497 | switch (TREE_CODE_CLASS (TREE_CODE (context))) | |
3498 | { | |
3499 | case 't': | |
3500 | { | |
3501 | tree these_tags = CLASSTYPE_TAGS (context); | |
3502 | if (ANON_AGGRNAME_P (name)) | |
3503 | while (these_tags) | |
3504 | { | |
3505 | if (TYPE_IDENTIFIER (TREE_VALUE (these_tags)) | |
3506 | == name) | |
3507 | return TREE_VALUE (tail); | |
3508 | these_tags = TREE_CHAIN (these_tags); | |
3509 | } | |
3510 | else | |
3511 | while (these_tags) | |
3512 | { | |
3513 | if (TREE_PURPOSE (these_tags) == name) | |
3514 | { | |
3515 | if (TREE_CODE (TREE_VALUE (these_tags)) != form) | |
3516 | { | |
3517 | error ("`%s' defined as wrong kind of tag in class scope", | |
3518 | IDENTIFIER_POINTER (name)); | |
3519 | } | |
3520 | return TREE_VALUE (tail); | |
3521 | } | |
3522 | these_tags = TREE_CHAIN (these_tags); | |
3523 | } | |
3524 | /* If this type is not yet complete, then don't | |
3525 | look at its context. */ | |
3526 | if (TYPE_SIZE (context) == NULL_TREE) | |
3527 | goto no_context; | |
3528 | /* Go to next enclosing type, if any. */ | |
3529 | context = DECL_CONTEXT (TYPE_NAME (context)); | |
3530 | break; | |
3531 | case 'd': | |
3532 | context = DECL_CONTEXT (context); | |
3533 | break; | |
3534 | default: | |
3535 | my_friendly_abort (10); | |
3536 | } | |
3537 | continue; | |
3538 | } | |
3539 | no_context: | |
3540 | break; | |
3541 | } | |
3542 | } | |
3543 | } | |
3544 | return NULL_TREE; | |
3545 | } | |
3546 | ||
3547 | void | |
3548 | set_current_level_tags_transparency (tags_transparent) | |
3549 | int tags_transparent; | |
3550 | { | |
3551 | current_binding_level->tag_transparent = tags_transparent; | |
3552 | } | |
3553 | ||
3554 | /* Given a type, find the tag that was defined for it and return the tag name. | |
3555 | Otherwise return 0. However, the value can never be 0 | |
3556 | in the cases in which this is used. | |
3557 | ||
3558 | C++: If NAME is non-zero, this is the new name to install. This is | |
3559 | done when replacing anonymous tags with real tag names. */ | |
3560 | ||
3561 | static tree | |
3562 | lookup_tag_reverse (type, name) | |
3563 | tree type; | |
3564 | tree name; | |
3565 | { | |
3566 | register struct binding_level *level; | |
3567 | ||
3568 | for (level = current_binding_level; level; level = level->level_chain) | |
3569 | { | |
3570 | register tree tail; | |
3571 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
3572 | { | |
3573 | if (TREE_VALUE (tail) == type) | |
3574 | { | |
3575 | if (name) | |
3576 | TREE_PURPOSE (tail) = name; | |
3577 | return TREE_PURPOSE (tail); | |
3578 | } | |
3579 | } | |
3580 | } | |
3581 | return NULL_TREE; | |
3582 | } | |
3583 | ||
3584 | /* Given type TYPE which was not declared in C++ language context, | |
3585 | attempt to find a name by which it is referred. */ | |
3586 | tree | |
3587 | typedecl_for_tag (tag) | |
3588 | tree tag; | |
3589 | { | |
3590 | struct binding_level *b = current_binding_level; | |
3591 | ||
3592 | if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL) | |
3593 | return TYPE_NAME (tag); | |
3594 | ||
3595 | while (b) | |
3596 | { | |
3597 | tree decls = b->names; | |
3598 | while (decls) | |
3599 | { | |
3600 | if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag) | |
3601 | break; | |
3602 | decls = TREE_CHAIN (decls); | |
3603 | } | |
3604 | if (decls) | |
3605 | return decls; | |
3606 | b = b->level_chain; | |
3607 | } | |
3608 | return NULL_TREE; | |
3609 | } | |
3610 | \f | |
3611 | /* Called when we must retroactively globalize a type we previously | |
3612 | thought needed to be nested. This happens, for example, when | |
3613 | a `friend class' declaration is seen for an undefined type. */ | |
3614 | ||
3615 | static void | |
3616 | globalize_nested_type (type) | |
3617 | tree type; | |
3618 | { | |
3619 | tree t, prev = NULL_TREE, d = TYPE_NAME (type); | |
3620 | struct binding_level *b; | |
3621 | ||
3622 | my_friendly_assert (TREE_CODE (d) == TYPE_DECL, 144); | |
3623 | /* If the type value has already been globalized, then we're set. */ | |
3624 | if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (d)) == d) | |
3625 | return; | |
3626 | if (IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (d))) | |
3627 | { | |
3628 | /* If this type already made it into the global tags, | |
3629 | silently return. */ | |
3630 | if (value_member (type, global_binding_level->tags)) | |
3631 | return; | |
3632 | } | |
3633 | ||
3634 | set_identifier_type_value (DECL_NESTED_TYPENAME (d), NULL_TREE); | |
3635 | DECL_NESTED_TYPENAME (d) = DECL_NAME (d); | |
3636 | DECL_CONTEXT (d) = NULL_TREE; | |
3637 | if (class_binding_level) | |
3638 | b = class_binding_level; | |
3639 | else | |
3640 | b = current_binding_level; | |
3641 | while (b != global_binding_level) | |
3642 | { | |
3643 | prev = NULL_TREE; | |
3644 | if (b->parm_flag == 2) | |
3645 | for (t = b->tags; t != NULL_TREE; prev = t, t = TREE_CHAIN (t)) | |
3646 | if (TREE_VALUE (t) == type) | |
3647 | goto found; | |
3648 | b = b->level_chain; | |
3649 | } | |
3650 | /* We failed to find this tag anywhere up the binding chains. | |
3651 | B is now the global binding level... check there. */ | |
3652 | prev = NULL_TREE; | |
3653 | if (b->parm_flag == 2) | |
3654 | for (t = b->tags; t != NULL_TREE; prev = t, t = TREE_CHAIN (t)) | |
3655 | if (TREE_VALUE (t) == type) | |
3656 | goto foundglobal; | |
3657 | /* It wasn't in global scope either, so this is an anonymous forward ref | |
3658 | of some kind; let it happen. */ | |
3659 | return; | |
3660 | ||
3661 | foundglobal: | |
3662 | print_node_brief (stderr, "Tried to globalize already-global type ", | |
3663 | type, 0); | |
3664 | my_friendly_abort (11); | |
3665 | ||
3666 | found: | |
3667 | /* Pull the tag out of the nested binding contour. */ | |
3668 | if (prev) | |
3669 | TREE_CHAIN (prev) = TREE_CHAIN (t); | |
3670 | else | |
3671 | b->tags = TREE_CHAIN (t); | |
3672 | ||
3673 | set_identifier_type_value (TREE_PURPOSE (t), TREE_VALUE (t)); | |
3674 | global_binding_level->tags | |
3675 | = perm_tree_cons (TREE_PURPOSE (t), TREE_VALUE (t), | |
3676 | global_binding_level->tags); | |
3677 | ||
3678 | /* Pull the tag out of the class's tags (if there). | |
3679 | It won't show up if it appears e.g. in a parameter declaration | |
3680 | or definition of a member function of this type. */ | |
3681 | if (current_class_type != NULL_TREE) | |
3682 | { | |
3683 | for (t = CLASSTYPE_TAGS (current_class_type), prev = NULL_TREE; | |
3684 | t != NULL_TREE; | |
3685 | prev = t, t = TREE_CHAIN (t)) | |
3686 | if (TREE_VALUE (t) == type) | |
3687 | break; | |
3688 | ||
3689 | if (t != NULL_TREE) | |
3690 | { | |
3691 | if (prev) | |
3692 | TREE_CHAIN (prev) = TREE_CHAIN (t); | |
3693 | else | |
3694 | CLASSTYPE_TAGS (current_class_type) = TREE_CHAIN (t); | |
3695 | } | |
3696 | } | |
3697 | ||
3698 | pushdecl_top_level (d); | |
3699 | } | |
3700 | ||
3701 | static void | |
3702 | maybe_globalize_type (type) | |
3703 | tree type; | |
3704 | { | |
3705 | if ((((TREE_CODE (type) == RECORD_TYPE | |
3706 | || TREE_CODE (type) == UNION_TYPE) | |
3707 | && ! TYPE_BEING_DEFINED (type)) | |
3708 | || TREE_CODE (type) == ENUMERAL_TYPE) | |
3709 | && TYPE_SIZE (type) == NULL_TREE | |
3710 | /* This part is gross. We keep calling here with types that | |
3711 | are instantiations of templates, when that type should is | |
3712 | global, or doesn't have the type decl established yet, | |
3713 | so globalizing will fail (because it won't find the type in any | |
3714 | non-global scope). So we short-circuit that path. */ | |
3715 | && !(TYPE_NAME (type) != NULL_TREE | |
3716 | && TYPE_IDENTIFIER (type) != NULL_TREE | |
3717 | && ! IDENTIFIER_HAS_TYPE_VALUE (TYPE_IDENTIFIER (type))) | |
3718 | ) | |
3719 | globalize_nested_type (type); | |
3720 | } | |
3721 | ||
3722 | /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). | |
3723 | Return the type value, or NULL_TREE if not found. */ | |
3724 | static tree | |
3725 | lookup_nested_type (type, context) | |
3726 | tree type; | |
3727 | tree context; | |
3728 | { | |
3729 | if (context == NULL_TREE) | |
3730 | return NULL_TREE; | |
3731 | while (context) | |
3732 | { | |
3733 | switch (TREE_CODE (context)) | |
3734 | { | |
3735 | case TYPE_DECL: | |
3736 | { | |
3737 | tree ctype = TREE_TYPE (context); | |
3738 | tree match = value_member (type, CLASSTYPE_TAGS (ctype)); | |
3739 | if (match) | |
3740 | return TREE_VALUE (match); | |
3741 | context = DECL_CONTEXT (context); | |
3742 | ||
3743 | /* When we have a nested class whose member functions have | |
3744 | local types (e.g., a set of enums), we'll arrive here | |
3745 | with the DECL_CONTEXT as the actual RECORD_TYPE node for | |
3746 | the enclosing class. Instead, we want to make sure we | |
3747 | come back in here with the TYPE_DECL, not the RECORD_TYPE. */ | |
3748 | if (context && TREE_CODE (context) == RECORD_TYPE) | |
3749 | context = TREE_CHAIN (context); | |
3750 | } | |
3751 | break; | |
3752 | case FUNCTION_DECL: | |
3753 | return TYPE_IDENTIFIER (type) ? lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE; | |
3754 | break; | |
3755 | default: | |
3756 | my_friendly_abort (12); | |
3757 | } | |
3758 | } | |
3759 | return NULL_TREE; | |
3760 | } | |
3761 | ||
3762 | /* Look up NAME in the current binding level and its superiors in the | |
3763 | namespace of variables, functions and typedefs. Return a ..._DECL | |
3764 | node of some kind representing its definition if there is only one | |
3765 | such declaration, or return a TREE_LIST with all the overloaded | |
3766 | definitions if there are many, or return 0 if it is undefined. | |
3767 | ||
3768 | If PREFER_TYPE is > 0, we prefer TYPE_DECLs. | |
3769 | If PREFER_TYPE is = 0, we prefer non-TYPE_DECLs. | |
3770 | If PREFER_TYPE is < 0, we arbitrate according to lexical context. */ | |
3771 | ||
3772 | tree | |
3773 | lookup_name (name, prefer_type) | |
3774 | tree name; | |
3775 | int prefer_type; | |
3776 | { | |
3777 | register tree val; | |
3778 | ||
3779 | if (current_binding_level != global_binding_level | |
3780 | && IDENTIFIER_LOCAL_VALUE (name)) | |
3781 | val = IDENTIFIER_LOCAL_VALUE (name); | |
3782 | /* In C++ class fields are between local and global scope, | |
3783 | just before the global scope. */ | |
3784 | else if (current_class_type) | |
3785 | { | |
3786 | val = IDENTIFIER_CLASS_VALUE (name); | |
3787 | if (val == NULL_TREE | |
3788 | && TYPE_SIZE (current_class_type) == NULL_TREE | |
3789 | && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type)) | |
3790 | { | |
3791 | /* Try to find values from base classes | |
3792 | if we are presently defining a type. | |
3793 | We are presently only interested in TYPE_DECLs. */ | |
3794 | val = lookup_field (current_class_type, name, 0, prefer_type < 0); | |
3795 | if (val == error_mark_node) | |
3796 | return val; | |
3797 | if (val && TREE_CODE (val) != TYPE_DECL) | |
3798 | val = NULL_TREE; | |
3799 | } | |
3800 | ||
3801 | /* yylex() calls this with -2, since we should never start digging for | |
3802 | the nested name at the point where we haven't even, for example, | |
3803 | created the COMPONENT_REF or anything like that. */ | |
3804 | if (val == NULL_TREE) | |
3805 | val = lookup_nested_field (name, prefer_type != -2); | |
3806 | ||
3807 | if (val == NULL_TREE) | |
3808 | val = IDENTIFIER_GLOBAL_VALUE (name); | |
3809 | } | |
3810 | else | |
3811 | val = IDENTIFIER_GLOBAL_VALUE (name); | |
3812 | ||
3813 | if (val) | |
3814 | { | |
3815 | extern int looking_for_typename; | |
3816 | ||
3817 | /* Arbitrate between finding a TYPE_DECL and finding | |
3818 | other kinds of _DECLs. */ | |
3819 | if (TREE_CODE (val) == TYPE_DECL || looking_for_typename < 0) | |
3820 | return val; | |
3821 | ||
3822 | if (IDENTIFIER_HAS_TYPE_VALUE (name)) | |
3823 | { | |
3824 | register tree val_as_type = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name)); | |
3825 | ||
3826 | if (val == val_as_type || prefer_type > 0 | |
3827 | || looking_for_typename > 0) | |
3828 | return val_as_type; | |
3829 | if (prefer_type == 0) | |
3830 | return val; | |
3831 | return arbitrate_lookup (name, val, val_as_type); | |
3832 | } | |
3833 | if (TREE_TYPE (val) == error_mark_node) | |
3834 | return error_mark_node; | |
3835 | } | |
3836 | ||
3837 | return val; | |
3838 | } | |
3839 | ||
3840 | /* Similar to `lookup_name' but look only at current binding level. */ | |
3841 | ||
3842 | tree | |
3843 | lookup_name_current_level (name) | |
3844 | tree name; | |
3845 | { | |
3846 | register tree t; | |
3847 | ||
3848 | if (current_binding_level == global_binding_level) | |
3849 | return IDENTIFIER_GLOBAL_VALUE (name); | |
3850 | ||
3851 | if (IDENTIFIER_LOCAL_VALUE (name) == NULL_TREE) | |
3852 | return 0; | |
3853 | ||
3854 | for (t = current_binding_level->names; t; t = TREE_CHAIN (t)) | |
3855 | if (DECL_NAME (t) == name) | |
3856 | break; | |
3857 | ||
3858 | return t; | |
3859 | } | |
3860 | \f | |
3861 | /* Arrange for the user to get a source line number, even when the | |
3862 | compiler is going down in flames, so that she at least has a | |
3863 | chance of working around problems in the compiler. We used to | |
3864 | call error(), but that let the segmentation fault continue | |
3865 | through; now, it's much more passive by asking them to send the | |
3866 | maintainers mail about the problem. */ | |
3867 | ||
3868 | static void | |
3869 | sigsegv (sig) | |
3870 | int sig; | |
3871 | { | |
3872 | signal (SIGSEGV, SIG_DFL); | |
3873 | #ifdef SIGIOT | |
3874 | signal (SIGIOT, SIG_DFL); | |
3875 | #endif | |
3876 | #ifdef SIGILL | |
3877 | signal (SIGILL, SIG_DFL); | |
3878 | #endif | |
3879 | #ifdef SIGABRT | |
3880 | signal (SIGABRT, SIG_DFL); | |
3881 | #endif | |
3882 | my_friendly_abort (0); | |
3883 | } | |
3884 | ||
3885 | /* Array for holding types considered "built-in". These types | |
3886 | are output in the module in which `main' is defined. */ | |
3887 | static tree *builtin_type_tdescs_arr; | |
3888 | static int builtin_type_tdescs_len, builtin_type_tdescs_max; | |
3889 | ||
3890 | /* Push the declarations of builtin types into the namespace. | |
3891 | RID_INDEX, if < RID_MAX is the index of the builtin type | |
3892 | in the array RID_POINTERS. NAME is the name used when looking | |
3893 | up the builtin type. TYPE is the _TYPE node for the builtin type. */ | |
3894 | ||
3895 | static void | |
3896 | record_builtin_type (rid_index, name, type) | |
3897 | enum rid rid_index; | |
3898 | char *name; | |
3899 | tree type; | |
3900 | { | |
3901 | tree rname = NULL_TREE, tname = NULL_TREE; | |
3902 | tree tdecl; | |
3903 | ||
3904 | if ((int) rid_index < (int) RID_MAX) | |
3905 | rname = ridpointers[(int) rid_index]; | |
3906 | if (name) | |
3907 | tname = get_identifier (name); | |
3908 | ||
3909 | if (tname) | |
3910 | { | |
3911 | #if 0 /* not yet, should get fixed properly later */ | |
3912 | tdecl = pushdecl (make_type_decl (tname, type)); | |
3913 | #else | |
3914 | tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); | |
3915 | #endif | |
3916 | set_identifier_type_value (tname, NULL_TREE); | |
3917 | if ((int) rid_index < (int) RID_MAX) | |
3918 | IDENTIFIER_GLOBAL_VALUE (tname) = tdecl; | |
3919 | } | |
3920 | if (rname != NULL_TREE) | |
3921 | { | |
3922 | if (tname != NULL_TREE) | |
3923 | { | |
3924 | set_identifier_type_value (rname, NULL_TREE); | |
3925 | IDENTIFIER_GLOBAL_VALUE (rname) = tdecl; | |
3926 | } | |
3927 | else | |
3928 | { | |
3929 | #if 0 /* not yet, should get fixed properly later */ | |
3930 | tdecl = pushdecl (make_type_decl (rname, type)); | |
3931 | #else | |
3932 | tdecl = pushdecl (build_decl (TYPE_DECL, rname, type)); | |
3933 | #endif | |
3934 | set_identifier_type_value (rname, NULL_TREE); | |
3935 | } | |
3936 | } | |
3937 | ||
3938 | if (flag_dossier) | |
3939 | { | |
3940 | if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max) | |
3941 | { | |
3942 | builtin_type_tdescs_max *= 2; | |
3943 | builtin_type_tdescs_arr | |
3944 | = (tree *)xrealloc (builtin_type_tdescs_arr, | |
3945 | builtin_type_tdescs_max * sizeof (tree)); | |
3946 | } | |
3947 | builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type; | |
3948 | if (TREE_CODE (type) != POINTER_TYPE) | |
3949 | { | |
3950 | builtin_type_tdescs_arr[builtin_type_tdescs_len++] | |
3951 | = build_pointer_type (type); | |
3952 | builtin_type_tdescs_arr[builtin_type_tdescs_len++] | |
3953 | = build_type_variant (TYPE_POINTER_TO (type), 1, 0); | |
3954 | } | |
3955 | if (TREE_CODE (type) != VOID_TYPE) | |
3956 | { | |
3957 | builtin_type_tdescs_arr[builtin_type_tdescs_len++] | |
3958 | = build_reference_type (type); | |
3959 | builtin_type_tdescs_arr[builtin_type_tdescs_len++] | |
3960 | = build_type_variant (TYPE_REFERENCE_TO (type), 1, 0); | |
3961 | } | |
3962 | } | |
3963 | } | |
3964 | ||
3965 | static void | |
3966 | output_builtin_tdesc_entries () | |
3967 | { | |
3968 | extern struct obstack permanent_obstack; | |
3969 | ||
3970 | /* If there's more than one main in this file, don't crash. */ | |
3971 | if (builtin_type_tdescs_arr == 0) | |
3972 | return; | |
3973 | ||
3974 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
3975 | while (builtin_type_tdescs_len > 0) | |
3976 | { | |
3977 | tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len]; | |
3978 | tree tdesc = build_t_desc (type, 0); | |
3979 | TREE_ASM_WRITTEN (tdesc) = 0; | |
3980 | build_t_desc (type, 2); | |
3981 | } | |
3982 | free (builtin_type_tdescs_arr); | |
3983 | builtin_type_tdescs_arr = 0; | |
3984 | pop_obstacks (); | |
3985 | } | |
3986 | ||
3987 | /* Push overloaded decl, in global scope, with one argument so it | |
3988 | can be used as a callback from define_function. */ | |
3989 | static void | |
3990 | push_overloaded_decl_1 (x) | |
3991 | tree x; | |
3992 | { | |
3993 | push_overloaded_decl (x, 0); | |
3994 | } | |
3995 | ||
3996 | /* Create the predefined scalar types of C, | |
3997 | and some nodes representing standard constants (0, 1, (void *)0). | |
3998 | Initialize the global binding level. | |
3999 | Make definitions for built-in primitive functions. */ | |
4000 | ||
4001 | void | |
4002 | init_decl_processing () | |
4003 | { | |
4004 | tree decl; | |
4005 | register tree endlink, int_endlink, double_endlink, ptr_endlink; | |
4006 | tree fields[20]; | |
4007 | /* Either char* or void*. */ | |
4008 | tree traditional_ptr_type_node; | |
4009 | /* Data type of memcpy. */ | |
4010 | tree memcpy_ftype; | |
4011 | int wchar_type_size; | |
4012 | ||
4013 | /* Have to make these distinct before we try using them. */ | |
4014 | lang_name_cplusplus = get_identifier ("C++"); | |
4015 | lang_name_c = get_identifier ("C"); | |
4016 | ||
4017 | /* Initially, C. */ | |
4018 | current_lang_name = lang_name_c; | |
4019 | ||
4020 | current_function_decl = NULL_TREE; | |
4021 | named_labels = NULL_TREE; | |
4022 | named_label_uses = NULL_TREE; | |
4023 | current_binding_level = NULL_BINDING_LEVEL; | |
4024 | free_binding_level = NULL_BINDING_LEVEL; | |
4025 | ||
4026 | /* Because most segmentation signals can be traced back into user | |
4027 | code, catch them and at least give the user a chance of working | |
4028 | around compiler bugs. */ | |
4029 | signal (SIGSEGV, sigsegv); | |
4030 | ||
4031 | /* We will also catch aborts in the back-end through sigsegv and give the | |
4032 | user a chance to see where the error might be, and to defeat aborts in | |
4033 | the back-end when there have been errors previously in their code. */ | |
4034 | #ifdef SIGIOT | |
4035 | signal (SIGIOT, sigsegv); | |
4036 | #endif | |
4037 | #ifdef SIGILL | |
4038 | signal (SIGILL, sigsegv); | |
4039 | #endif | |
4040 | #ifdef SIGABRT | |
4041 | signal (SIGABRT, sigsegv); | |
4042 | #endif | |
4043 | ||
4044 | gcc_obstack_init (&decl_obstack); | |
4045 | if (flag_dossier) | |
4046 | { | |
4047 | builtin_type_tdescs_max = 100; | |
4048 | builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree)); | |
4049 | } | |
4050 | ||
4051 | /* Must lay these out before anything else gets laid out. */ | |
4052 | error_mark_node = make_node (ERROR_MARK); | |
4053 | TREE_PERMANENT (error_mark_node) = 1; | |
4054 | TREE_TYPE (error_mark_node) = error_mark_node; | |
4055 | error_mark_list = build_tree_list (error_mark_node, error_mark_node); | |
4056 | TREE_TYPE (error_mark_list) = error_mark_node; | |
4057 | ||
4058 | pushlevel (0); /* make the binding_level structure for global names. */ | |
4059 | global_binding_level = current_binding_level; | |
4060 | ||
4061 | this_identifier = get_identifier (THIS_NAME); | |
4062 | in_charge_identifier = get_identifier (IN_CHARGE_NAME); | |
4063 | ||
4064 | /* Define `int' and `char' first so that dbx will output them first. */ | |
4065 | ||
4066 | integer_type_node = make_signed_type (INT_TYPE_SIZE); | |
4067 | record_builtin_type (RID_INT, NULL_PTR, integer_type_node); | |
4068 | ||
4069 | /* Define `char', which is like either `signed char' or `unsigned char' | |
4070 | but not the same as either. */ | |
4071 | ||
4072 | char_type_node = | |
4073 | (flag_signed_char | |
4074 | ? make_signed_type (CHAR_TYPE_SIZE) | |
4075 | : make_unsigned_type (CHAR_TYPE_SIZE)); | |
4076 | record_builtin_type (RID_CHAR, "char", char_type_node); | |
4077 | ||
4078 | long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); | |
4079 | record_builtin_type (RID_LONG, "long int", long_integer_type_node); | |
4080 | ||
4081 | unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); | |
4082 | record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); | |
4083 | ||
4084 | long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); | |
4085 | record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node); | |
4086 | record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); | |
4087 | ||
4088 | /* `unsigned long' is the standard type for sizeof. | |
4089 | Traditionally, use a signed type. | |
4090 | Note that stddef.h uses `unsigned long', | |
4091 | and this must agree, even of long and int are the same size. */ | |
4092 | if (flag_traditional) | |
4093 | sizetype = long_integer_type_node; | |
4094 | else | |
4095 | sizetype | |
4096 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))); | |
4097 | ||
4098 | ptrdiff_type_node | |
4099 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); | |
4100 | ||
4101 | TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype; | |
4102 | TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype; | |
4103 | TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype; | |
4104 | TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype; | |
4105 | TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype; | |
4106 | ||
4107 | short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); | |
4108 | record_builtin_type (RID_SHORT, "short int", short_integer_type_node); | |
4109 | long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); | |
4110 | record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node); | |
4111 | short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); | |
4112 | record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); | |
4113 | record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); | |
4114 | long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); | |
4115 | record_builtin_type (RID_MAX, "long long unsigned int", long_long_unsigned_type_node); | |
4116 | record_builtin_type (RID_MAX, "long long unsigned", long_long_unsigned_type_node); | |
4117 | ||
4118 | /* Define both `signed char' and `unsigned char'. */ | |
4119 | signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); | |
4120 | record_builtin_type (RID_MAX, "signed char", signed_char_type_node); | |
4121 | unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); | |
4122 | record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); | |
4123 | ||
4124 | /* These are types that type_for_size and type_for_mode use. */ | |
4125 | intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); | |
4126 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); | |
4127 | intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); | |
4128 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); | |
4129 | intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); | |
4130 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); | |
4131 | intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); | |
4132 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); | |
4133 | unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); | |
4134 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); | |
4135 | unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); | |
4136 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); | |
4137 | unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); | |
4138 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); | |
4139 | unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); | |
4140 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); | |
4141 | ||
4142 | float_type_node = make_node (REAL_TYPE); | |
4143 | TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; | |
4144 | record_builtin_type (RID_FLOAT, NULL, float_type_node); | |
4145 | layout_type (float_type_node); | |
4146 | ||
4147 | double_type_node = make_node (REAL_TYPE); | |
4148 | if (flag_short_double) | |
4149 | TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; | |
4150 | else | |
4151 | TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; | |
4152 | record_builtin_type (RID_DOUBLE, NULL, double_type_node); | |
4153 | layout_type (double_type_node); | |
4154 | ||
4155 | long_double_type_node = make_node (REAL_TYPE); | |
4156 | TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; | |
4157 | record_builtin_type (RID_MAX, "long double", long_double_type_node); | |
4158 | layout_type (long_double_type_node); | |
4159 | ||
4160 | integer_zero_node = build_int_2 (0, 0); | |
4161 | TREE_TYPE (integer_zero_node) = integer_type_node; | |
4162 | integer_one_node = build_int_2 (1, 0); | |
4163 | TREE_TYPE (integer_one_node) = integer_type_node; | |
4164 | integer_two_node = build_int_2 (2, 0); | |
4165 | TREE_TYPE (integer_two_node) = integer_type_node; | |
4166 | integer_three_node = build_int_2 (3, 0); | |
4167 | TREE_TYPE (integer_three_node) = integer_type_node; | |
4168 | empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE); | |
4169 | ||
4170 | /* These are needed by stor-layout.c. */ | |
4171 | size_zero_node = size_int (0); | |
4172 | size_one_node = size_int (1); | |
4173 | ||
4174 | void_type_node = make_node (VOID_TYPE); | |
4175 | record_builtin_type (RID_VOID, NULL, void_type_node); | |
4176 | layout_type (void_type_node); /* Uses integer_zero_node. */ | |
4177 | void_list_node = build_tree_list (NULL_TREE, void_type_node); | |
4178 | TREE_PARMLIST (void_list_node) = 1; | |
4179 | ||
4180 | null_pointer_node = build_int_2 (0, 0); | |
4181 | TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); | |
4182 | layout_type (TREE_TYPE (null_pointer_node)); | |
4183 | ||
4184 | /* Used for expressions that do nothing, but are not errors. */ | |
4185 | void_zero_node = build_int_2 (0, 0); | |
4186 | TREE_TYPE (void_zero_node) = void_type_node; | |
4187 | ||
4188 | string_type_node = build_pointer_type (char_type_node); | |
4189 | const_string_type_node = build_pointer_type (build_type_variant (char_type_node, 1, 0)); | |
4190 | record_builtin_type (RID_MAX, NULL, string_type_node); | |
4191 | ||
4192 | /* make a type for arrays of 256 characters. | |
4193 | 256 is picked randomly because we have a type for integers from 0 to 255. | |
4194 | With luck nothing will ever really depend on the length of this | |
4195 | array type. */ | |
4196 | char_array_type_node | |
4197 | = build_array_type (char_type_node, unsigned_char_type_node); | |
4198 | /* Likewise for arrays of ints. */ | |
4199 | int_array_type_node | |
4200 | = build_array_type (integer_type_node, unsigned_char_type_node); | |
4201 | ||
4202 | /* This is just some anonymous class type. Nobody should ever | |
4203 | need to look inside this envelope. */ | |
4204 | class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE)); | |
4205 | ||
4206 | default_function_type | |
4207 | = build_function_type (integer_type_node, NULL_TREE); | |
4208 | build_pointer_type (default_function_type); | |
4209 | ||
4210 | ptr_type_node = build_pointer_type (void_type_node); | |
4211 | const_ptr_type_node = build_pointer_type (build_type_variant (void_type_node, 1, 0)); | |
4212 | record_builtin_type (RID_MAX, NULL, ptr_type_node); | |
4213 | endlink = void_list_node; | |
4214 | int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); | |
4215 | double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); | |
4216 | ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink); | |
4217 | ||
4218 | double_ftype_double | |
4219 | = build_function_type (double_type_node, double_endlink); | |
4220 | ||
4221 | double_ftype_double_double | |
4222 | = build_function_type (double_type_node, | |
4223 | tree_cons (NULL_TREE, double_type_node, double_endlink)); | |
4224 | ||
4225 | int_ftype_int | |
4226 | = build_function_type (integer_type_node, int_endlink); | |
4227 | ||
4228 | long_ftype_long | |
4229 | = build_function_type (long_integer_type_node, | |
4230 | tree_cons (NULL_TREE, long_integer_type_node, endlink)); | |
4231 | ||
4232 | void_ftype_ptr_ptr_int | |
4233 | = build_function_type (void_type_node, | |
4234 | tree_cons (NULL_TREE, ptr_type_node, | |
4235 | tree_cons (NULL_TREE, ptr_type_node, | |
4236 | int_endlink))); | |
4237 | ||
4238 | int_ftype_cptr_cptr_sizet | |
4239 | = build_function_type (integer_type_node, | |
4240 | tree_cons (NULL_TREE, const_ptr_type_node, | |
4241 | tree_cons (NULL_TREE, const_ptr_type_node, | |
4242 | tree_cons (NULL_TREE, | |
4243 | sizetype, | |
4244 | endlink)))); | |
4245 | ||
4246 | void_ftype_ptr_int_int | |
4247 | = build_function_type (void_type_node, | |
4248 | tree_cons (NULL_TREE, ptr_type_node, | |
4249 | tree_cons (NULL_TREE, integer_type_node, | |
4250 | int_endlink))); | |
4251 | ||
4252 | string_ftype_ptr_ptr /* strcpy prototype */ | |
4253 | = build_function_type (string_type_node, | |
4254 | tree_cons (NULL_TREE, string_type_node, | |
4255 | tree_cons (NULL_TREE, | |
4256 | const_string_type_node, | |
4257 | endlink))); | |
4258 | ||
4259 | int_ftype_string_string /* strcmp prototype */ | |
4260 | = build_function_type (integer_type_node, | |
4261 | tree_cons (NULL_TREE, const_string_type_node, | |
4262 | tree_cons (NULL_TREE, | |
4263 | const_string_type_node, | |
4264 | endlink))); | |
4265 | ||
4266 | sizet_ftype_string /* strlen prototype */ | |
4267 | = build_function_type (sizetype, | |
4268 | tree_cons (NULL_TREE, const_string_type_node, | |
4269 | endlink)); | |
4270 | ||
4271 | traditional_ptr_type_node | |
4272 | = (flag_traditional ? string_type_node : ptr_type_node); | |
4273 | ||
4274 | memcpy_ftype /* memcpy prototype */ | |
4275 | = build_function_type (traditional_ptr_type_node, | |
4276 | tree_cons (NULL_TREE, ptr_type_node, | |
4277 | tree_cons (NULL_TREE, const_ptr_type_node, | |
4278 | tree_cons (NULL_TREE, | |
4279 | sizetype, | |
4280 | endlink)))); | |
4281 | ||
4282 | #ifdef VTABLE_USES_MASK | |
4283 | /* This is primarily for virtual function definition. We | |
4284 | declare an array of `void *', which can later be | |
4285 | converted to the appropriate function pointer type. | |
4286 | To do pointers to members, we need a mask which can | |
4287 | distinguish an index value into a virtual function table | |
4288 | from an address. */ | |
4289 | vtbl_mask = build_int_2 (~((HOST_WIDE_INT) VINDEX_MAX - 1), -1); | |
4290 | #endif | |
4291 | ||
4292 | vtbl_type_node | |
4293 | = build_array_type (ptr_type_node, NULL_TREE); | |
4294 | layout_type (vtbl_type_node); | |
4295 | vtbl_type_node = build_type_variant (vtbl_type_node, 1, 0); | |
4296 | record_builtin_type (RID_MAX, NULL, vtbl_type_node); | |
4297 | ||
4298 | builtin_function ("__builtin_constant_p", int_ftype_int, | |
4299 | BUILT_IN_CONSTANT_P, NULL_PTR); | |
4300 | ||
4301 | builtin_function ("__builtin_alloca", | |
4302 | build_function_type (ptr_type_node, | |
4303 | tree_cons (NULL_TREE, | |
4304 | sizetype, | |
4305 | endlink)), | |
4306 | BUILT_IN_ALLOCA, "alloca"); | |
4307 | #if 0 | |
4308 | builtin_function ("alloca", | |
4309 | build_function_type (ptr_type_node, | |
4310 | tree_cons (NULL_TREE, | |
4311 | sizetype, | |
4312 | endlink)), | |
4313 | BUILT_IN_ALLOCA, NULL_PTR); | |
4314 | #endif | |
4315 | ||
4316 | builtin_function ("__builtin_abs", int_ftype_int, | |
4317 | BUILT_IN_ABS, NULL_PTR); | |
4318 | builtin_function ("__builtin_fabs", double_ftype_double, | |
4319 | BUILT_IN_FABS, NULL_PTR); | |
4320 | builtin_function ("__builtin_labs", long_ftype_long, | |
4321 | BUILT_IN_LABS, NULL_PTR); | |
4322 | builtin_function ("__builtin_ffs", int_ftype_int, | |
4323 | BUILT_IN_FFS, NULL_PTR); | |
4324 | builtin_function ("__builtin_fsqrt", double_ftype_double, | |
4325 | BUILT_IN_FSQRT, NULL_PTR); | |
4326 | builtin_function ("__builtin_sin", double_ftype_double, | |
4327 | BUILT_IN_SIN, "sin"); | |
4328 | builtin_function ("__builtin_cos", double_ftype_double, | |
4329 | BUILT_IN_COS, "cos"); | |
4330 | builtin_function ("__builtin_saveregs", | |
4331 | build_function_type (ptr_type_node, NULL_TREE), | |
4332 | BUILT_IN_SAVEREGS, NULL_PTR); | |
4333 | /* EXPAND_BUILTIN_VARARGS is obsolete. */ | |
4334 | #if 0 | |
4335 | builtin_function ("__builtin_varargs", | |
4336 | build_function_type (ptr_type_node, | |
4337 | tree_cons (NULL_TREE, | |
4338 | integer_type_node, | |
4339 | endlink)), | |
4340 | BUILT_IN_VARARGS, NULL_PTR); | |
4341 | #endif | |
4342 | builtin_function ("__builtin_classify_type", default_function_type, | |
4343 | BUILT_IN_CLASSIFY_TYPE, NULL_PTR); | |
4344 | builtin_function ("__builtin_next_arg", | |
4345 | build_function_type (ptr_type_node, endlink), | |
4346 | BUILT_IN_NEXT_ARG, NULL_PTR); | |
4347 | builtin_function ("__builtin_args_info", | |
4348 | build_function_type (integer_type_node, | |
4349 | tree_cons (NULL_TREE, | |
4350 | integer_type_node, | |
4351 | endlink)), | |
4352 | BUILT_IN_ARGS_INFO, NULL_PTR); | |
4353 | ||
4354 | /* Currently under experimentation. */ | |
4355 | builtin_function ("__builtin_memcpy", memcpy_ftype, | |
4356 | BUILT_IN_MEMCPY, "memcpy"); | |
4357 | builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, | |
4358 | BUILT_IN_MEMCMP, "memcmp"); | |
4359 | builtin_function ("__builtin_strcmp", int_ftype_string_string, | |
4360 | BUILT_IN_STRCMP, "strcmp"); | |
4361 | builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, | |
4362 | BUILT_IN_STRCPY, "strcpy"); | |
4363 | builtin_function ("__builtin_strlen", sizet_ftype_string, | |
4364 | BUILT_IN_STRLEN, "strlen"); | |
4365 | ||
4366 | if (!flag_no_builtin) | |
4367 | { | |
4368 | #if 0 /* These do not work well with libg++. */ | |
4369 | builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); | |
4370 | builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); | |
4371 | builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); | |
4372 | #endif | |
4373 | builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); | |
4374 | builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, | |
4375 | NULL_PTR); | |
4376 | builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR); | |
4377 | builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, NULL_PTR); | |
4378 | builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR); | |
4379 | builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); | |
4380 | builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); | |
4381 | } | |
4382 | ||
4383 | #if 0 | |
4384 | /* Support for these has not been written in either expand_builtin | |
4385 | or build_function_call. */ | |
4386 | builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0); | |
4387 | builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0); | |
4388 | builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, 0); | |
4389 | builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0); | |
4390 | builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD, 0); | |
4391 | builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM, 0); | |
4392 | builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, 0); | |
4393 | builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, 0); | |
4394 | builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, 0); | |
4395 | #endif | |
4396 | ||
4397 | /* C++ extensions */ | |
4398 | ||
4399 | unknown_type_node = make_node (UNKNOWN_TYPE); | |
4400 | #if 0 /* not yet, should get fixed properly later */ | |
4401 | pushdecl (make_type_decl (get_identifier ("unknown type"), | |
4402 | unknown_type_node)); | |
4403 | #else | |
4404 | decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"), | |
4405 | unknown_type_node)); | |
4406 | /* Make sure the "unknown type" typedecl gets ignored for debug info. */ | |
4407 | DECL_IGNORED_P (decl) = 1; | |
4408 | #endif | |
4409 | TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node); | |
4410 | TYPE_ALIGN (unknown_type_node) = 1; | |
4411 | TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node); | |
4412 | /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ | |
4413 | TREE_TYPE (unknown_type_node) = unknown_type_node; | |
4414 | /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */ | |
4415 | TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; | |
4416 | TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; | |
4417 | ||
4418 | /* This is special for C++ so functions can be overloaded. */ | |
4419 | wchar_type_node | |
4420 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); | |
4421 | wchar_type_size = TYPE_PRECISION (wchar_type_node); | |
4422 | signed_wchar_type_node = make_signed_type (wchar_type_size); | |
4423 | unsigned_wchar_type_node = make_unsigned_type (wchar_type_size); | |
4424 | wchar_type_node | |
4425 | = TREE_UNSIGNED (wchar_type_node) | |
4426 | ? unsigned_wchar_type_node | |
4427 | : signed_wchar_type_node; | |
4428 | record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node); | |
4429 | ||
4430 | /* This is for wide string constants. */ | |
4431 | wchar_array_type_node | |
4432 | = build_array_type (wchar_type_node, unsigned_char_type_node); | |
4433 | ||
4434 | /* This is a hack that should go away when we deliver the | |
4435 | real gc code. */ | |
4436 | if (flag_gc) | |
4437 | { | |
4438 | builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0); | |
4439 | pushdecl (lookup_name (get_identifier ("__gc_main"), 0)); | |
4440 | } | |
4441 | ||
4442 | /* Simplify life by making a "vtable_entry_type". Give its | |
4443 | fields names so that the debugger can use them. */ | |
4444 | ||
4445 | vtable_entry_type = make_lang_type (RECORD_TYPE); | |
4446 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_DELTA_NAME), short_integer_type_node); | |
4447 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_INDEX_NAME), short_integer_type_node); | |
4448 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_PFN_NAME), ptr_type_node); | |
4449 | finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2, | |
4450 | double_type_node); | |
4451 | ||
4452 | /* Make this part of an invisible union. */ | |
4453 | fields[3] = copy_node (fields[2]); | |
4454 | TREE_TYPE (fields[3]) = short_integer_type_node; | |
4455 | DECL_NAME (fields[3]) = get_identifier (VTABLE_DELTA2_NAME); | |
4456 | DECL_MODE (fields[3]) = TYPE_MODE (short_integer_type_node); | |
4457 | DECL_SIZE (fields[3]) = TYPE_SIZE (short_integer_type_node); | |
4458 | TREE_UNSIGNED (fields[3]) = 0; | |
4459 | TREE_CHAIN (fields[2]) = fields[3]; | |
4460 | vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0); | |
4461 | record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type); | |
4462 | ||
4463 | if (flag_dossier) | |
4464 | { | |
4465 | /* Must build __t_desc type. Currently, type descriptors look like this: | |
4466 | ||
4467 | struct __t_desc | |
4468 | { | |
4469 | const char *name; | |
4470 | int size; | |
4471 | int bits; | |
4472 | struct __t_desc *points_to; | |
4473 | int ivars_count, meths_count; | |
4474 | struct __i_desc *ivars[]; | |
4475 | struct __m_desc *meths[]; | |
4476 | struct __t_desc *parents[]; | |
4477 | struct __t_desc *vbases[]; | |
4478 | int offsets[]; | |
4479 | }; | |
4480 | ||
4481 | ...as per Linton's paper. */ | |
4482 | ||
4483 | __t_desc_type_node = make_lang_type (RECORD_TYPE); | |
4484 | __i_desc_type_node = make_lang_type (RECORD_TYPE); | |
4485 | __m_desc_type_node = make_lang_type (RECORD_TYPE); | |
4486 | __t_desc_array_type = build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE); | |
4487 | __i_desc_array_type = build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE); | |
4488 | __m_desc_array_type = build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE); | |
4489 | ||
4490 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), | |
4491 | string_type_node); | |
4492 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"), | |
4493 | unsigned_type_node); | |
4494 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"), | |
4495 | unsigned_type_node); | |
4496 | fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("points_to"), | |
4497 | TYPE_POINTER_TO (__t_desc_type_node)); | |
4498 | fields[4] = build_lang_field_decl (FIELD_DECL, | |
4499 | get_identifier ("ivars_count"), | |
4500 | integer_type_node); | |
4501 | fields[5] = build_lang_field_decl (FIELD_DECL, | |
4502 | get_identifier ("meths_count"), | |
4503 | integer_type_node); | |
4504 | fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"), | |
4505 | build_pointer_type (__i_desc_array_type)); | |
4506 | fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"), | |
4507 | build_pointer_type (__m_desc_array_type)); | |
4508 | fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"), | |
4509 | build_pointer_type (__t_desc_array_type)); | |
4510 | fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"), | |
4511 | build_pointer_type (__t_desc_array_type)); | |
4512 | fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"), | |
4513 | build_pointer_type (integer_type_node)); | |
4514 | finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node); | |
4515 | ||
4516 | /* ivar descriptors look like this: | |
4517 | ||
4518 | struct __i_desc | |
4519 | { | |
4520 | const char *name; | |
4521 | int offset; | |
4522 | struct __t_desc *type; | |
4523 | }; | |
4524 | */ | |
4525 | ||
4526 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), | |
4527 | string_type_node); | |
4528 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"), | |
4529 | integer_type_node); | |
4530 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"), | |
4531 | TYPE_POINTER_TO (__t_desc_type_node)); | |
4532 | finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, integer_type_node); | |
4533 | ||
4534 | /* method descriptors look like this: | |
4535 | ||
4536 | struct __m_desc | |
4537 | { | |
4538 | const char *name; | |
4539 | int vindex; | |
4540 | struct __t_desc *vcontext; | |
4541 | struct __t_desc *return_type; | |
4542 | void (*address)(); | |
4543 | short parm_count; | |
4544 | short required_parms; | |
4545 | struct __t_desc *parm_types[]; | |
4546 | }; | |
4547 | */ | |
4548 | ||
4549 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), | |
4550 | string_type_node); | |
4551 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"), | |
4552 | integer_type_node); | |
4553 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"), | |
4554 | TYPE_POINTER_TO (__t_desc_type_node)); | |
4555 | fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"), | |
4556 | TYPE_POINTER_TO (__t_desc_type_node)); | |
4557 | fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"), | |
4558 | build_pointer_type (default_function_type)); | |
4559 | fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"), | |
4560 | short_integer_type_node); | |
4561 | fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"), | |
4562 | short_integer_type_node); | |
4563 | fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"), | |
4564 | build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE))); | |
4565 | finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, integer_type_node); | |
4566 | } | |
4567 | ||
4568 | /* Now, C++. */ | |
4569 | current_lang_name = lang_name_cplusplus; | |
4570 | if (flag_dossier) | |
4571 | { | |
4572 | int i = builtin_type_tdescs_len; | |
4573 | while (i > 0) | |
4574 | { | |
4575 | tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0); | |
4576 | TREE_ASM_WRITTEN (tdesc) = 1; | |
4577 | TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1; | |
4578 | } | |
4579 | } | |
4580 | ||
4581 | auto_function (ansi_opname[(int) NEW_EXPR], | |
4582 | build_function_type (ptr_type_node, | |
4583 | tree_cons (NULL_TREE, sizetype, | |
4584 | void_list_node)), | |
4585 | NOT_BUILT_IN); | |
4586 | auto_function (ansi_opname[(int) DELETE_EXPR], | |
4587 | build_function_type (void_type_node, | |
4588 | tree_cons (NULL_TREE, ptr_type_node, | |
4589 | void_list_node)), | |
4590 | NOT_BUILT_IN); | |
4591 | ||
4592 | abort_fndecl | |
4593 | = define_function ("abort", | |
4594 | build_function_type (void_type_node, void_list_node), | |
4595 | NOT_BUILT_IN, 0, 0); | |
4596 | ||
4597 | unhandled_exception_fndecl | |
4598 | = define_function ("__unhandled_exception", | |
4599 | build_function_type (void_type_node, NULL_TREE), | |
4600 | NOT_BUILT_IN, 0, 0); | |
4601 | ||
4602 | /* Perform other language dependent initializations. */ | |
4603 | init_class_processing (); | |
4604 | init_init_processing (); | |
4605 | init_search_processing (); | |
4606 | ||
4607 | if (flag_handle_exceptions) | |
4608 | { | |
4609 | if (flag_handle_exceptions == 2) | |
4610 | /* Too much trouble to inline all the trys needed for this. */ | |
4611 | flag_this_is_variable = 2; | |
4612 | init_exception_processing (); | |
4613 | } | |
4614 | if (flag_gc) | |
4615 | init_gc_processing (); | |
4616 | if (flag_no_inline) | |
4617 | flag_inline_functions = 0, flag_default_inline = 0; | |
4618 | if (flag_cadillac) | |
4619 | init_cadillac (); | |
4620 | ||
4621 | /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ | |
4622 | declare_function_name (); | |
4623 | ||
4624 | /* Warnings about failure to return values are too valuable to forego. */ | |
4625 | warn_return_type = 1; | |
4626 | } | |
4627 | ||
4628 | /* Make a definition for a builtin function named NAME and whose data type | |
4629 | is TYPE. TYPE should be a function type with argument types. | |
4630 | FUNCTION_CODE tells later passes how to compile calls to this function. | |
4631 | See tree.h for its possible values. | |
4632 | ||
4633 | If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, | |
4634 | the name to be called if we can't opencode the function. */ | |
4635 | ||
4636 | tree | |
4637 | define_function (name, type, function_code, pfn, library_name) | |
4638 | char *name; | |
4639 | tree type; | |
4640 | enum built_in_function function_code; | |
4641 | void (*pfn)(); | |
4642 | char *library_name; | |
4643 | { | |
4644 | tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); | |
4645 | DECL_EXTERNAL (decl) = 1; | |
4646 | TREE_PUBLIC (decl) = 1; | |
4647 | ||
4648 | /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, | |
4649 | we cannot change DECL_ASSEMBLER_NAME until we have installed this | |
4650 | function in the namespace. */ | |
4651 | if (pfn) (*pfn) (decl); | |
4652 | if (library_name) | |
4653 | DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); | |
4654 | make_function_rtl (decl); | |
4655 | if (function_code != NOT_BUILT_IN) | |
4656 | { | |
4657 | DECL_BUILT_IN (decl) = 1; | |
4658 | DECL_SET_FUNCTION_CODE (decl, function_code); | |
4659 | } | |
4660 | return decl; | |
4661 | } | |
4662 | \f | |
4663 | /* Called when a declaration is seen that contains no names to declare. | |
4664 | If its type is a reference to a structure, union or enum inherited | |
4665 | from a containing scope, shadow that tag name for the current scope | |
4666 | with a forward reference. | |
4667 | If its type defines a new named structure or union | |
4668 | or defines an enum, it is valid but we need not do anything here. | |
4669 | Otherwise, it is an error. | |
4670 | ||
4671 | C++: may have to grok the declspecs to learn about static, | |
4672 | complain for anonymous unions. */ | |
4673 | ||
4674 | void | |
4675 | shadow_tag (declspecs) | |
4676 | tree declspecs; | |
4677 | { | |
4678 | int found_tag = 0; | |
4679 | int warned = 0; | |
4680 | register tree link; | |
4681 | register enum tree_code code, ok_code = ERROR_MARK; | |
4682 | register tree t = NULL_TREE; | |
4683 | ||
4684 | for (link = declspecs; link; link = TREE_CHAIN (link)) | |
4685 | { | |
4686 | register tree value = TREE_VALUE (link); | |
4687 | ||
4688 | code = TREE_CODE (value); | |
4689 | if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE) | |
4690 | /* Used to test also that TYPE_SIZE (value) != 0. | |
4691 | That caused warning for `struct foo;' at top level in the file. */ | |
4692 | { | |
4693 | register tree name = TYPE_NAME (value); | |
4694 | ||
4695 | if (name == NULL_TREE) | |
4696 | name = lookup_tag_reverse (value, NULL_TREE); | |
4697 | ||
4698 | if (name && TREE_CODE (name) == TYPE_DECL) | |
4699 | name = DECL_NAME (name); | |
4700 | ||
4701 | if (class_binding_level) | |
4702 | t = lookup_tag (code, name, class_binding_level, 1); | |
4703 | else | |
4704 | t = lookup_tag (code, name, current_binding_level, 1); | |
4705 | ||
4706 | if (t == NULL_TREE) | |
4707 | { | |
4708 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
4709 | if (IS_AGGR_TYPE_CODE (code)) | |
4710 | t = make_lang_type (code); | |
4711 | else | |
4712 | t = make_node (code); | |
4713 | pushtag (name, t); | |
4714 | pop_obstacks (); | |
4715 | ok_code = code; | |
4716 | break; | |
4717 | } | |
4718 | else if (name != NULL_TREE || code == ENUMERAL_TYPE) | |
4719 | ok_code = code; | |
4720 | ||
4721 | if (ok_code != ERROR_MARK) | |
4722 | found_tag++; | |
4723 | else | |
4724 | { | |
4725 | if (!warned) | |
4726 | pedwarn ("useless keyword or type name in declaration"); | |
4727 | warned = 1; | |
4728 | } | |
4729 | } | |
4730 | } | |
4731 | ||
4732 | /* This is where the variables in an anonymous union are | |
4733 | declared. An anonymous union declaration looks like: | |
4734 | union { ... } ; | |
4735 | because there is no declarator after the union, the parser | |
4736 | sends that declaration here. */ | |
4737 | if (ok_code == UNION_TYPE | |
4738 | && t != NULL_TREE | |
4739 | && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE | |
4740 | && ANON_AGGRNAME_P (TYPE_NAME (t))) | |
4741 | || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL | |
4742 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))) | |
4743 | { | |
4744 | /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have | |
4745 | function members. */ | |
4746 | if (TYPE_FIELDS (t)) | |
4747 | { | |
4748 | tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE); | |
4749 | finish_anon_union (decl); | |
4750 | } | |
4751 | else | |
4752 | error ("anonymous union cannot have a function member"); | |
4753 | } | |
4754 | else if (ok_code == RECORD_TYPE | |
4755 | && found_tag == 1 | |
4756 | && TYPE_LANG_SPECIFIC (t) | |
4757 | && CLASSTYPE_DECLARED_EXCEPTION (t)) | |
4758 | { | |
4759 | if (TYPE_SIZE (t)) | |
4760 | error_with_aggr_type (t, "redeclaration of exception `%s'"); | |
4761 | else | |
4762 | { | |
4763 | tree ename, decl; | |
4764 | ||
4765 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
4766 | ||
4767 | pushclass (t, 0); | |
4768 | finish_exception (t, NULL_TREE); | |
4769 | ||
4770 | ename = TYPE_NAME (t); | |
4771 | if (TREE_CODE (ename) == TYPE_DECL) | |
4772 | ename = DECL_NAME (ename); | |
4773 | decl = build_lang_field_decl (VAR_DECL, ename, t); | |
4774 | finish_exception_decl (current_class_name, decl); | |
4775 | end_exception_decls (); | |
4776 | ||
4777 | pop_obstacks (); | |
4778 | } | |
4779 | } | |
4780 | else if (!warned && found_tag > 1) | |
4781 | warning ("multiple types in one declaration"); | |
4782 | } | |
4783 | \f | |
4784 | /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ | |
4785 | ||
4786 | tree | |
4787 | groktypename (typename) | |
4788 | tree typename; | |
4789 | { | |
4790 | if (TREE_CODE (typename) != TREE_LIST) | |
4791 | return typename; | |
4792 | return grokdeclarator (TREE_VALUE (typename), | |
4793 | TREE_PURPOSE (typename), | |
4794 | TYPENAME, 0, NULL_TREE); | |
4795 | } | |
4796 | ||
4797 | /* Decode a declarator in an ordinary declaration or data definition. | |
4798 | This is called as soon as the type information and variable name | |
4799 | have been parsed, before parsing the initializer if any. | |
4800 | Here we create the ..._DECL node, fill in its type, | |
4801 | and put it on the list of decls for the current context. | |
4802 | The ..._DECL node is returned as the value. | |
4803 | ||
4804 | Exception: for arrays where the length is not specified, | |
4805 | the type is left null, to be filled in by `finish_decl'. | |
4806 | ||
4807 | Function definitions do not come here; they go to start_function | |
4808 | instead. However, external and forward declarations of functions | |
4809 | do go through here. Structure field declarations are done by | |
4810 | grokfield and not through here. */ | |
4811 | ||
4812 | /* Set this to zero to debug not using the temporary obstack | |
4813 | to parse initializers. */ | |
4814 | int debug_temp_inits = 1; | |
4815 | ||
4816 | tree | |
4817 | start_decl (declarator, declspecs, initialized, raises) | |
4818 | tree declspecs, declarator; | |
4819 | int initialized; | |
4820 | tree raises; | |
4821 | { | |
4822 | register tree decl; | |
4823 | register tree type, tem; | |
4824 | tree context; | |
4825 | extern int have_extern_spec; | |
4826 | extern int used_extern_spec; | |
4827 | ||
4828 | int init_written = initialized; | |
4829 | ||
4830 | /* This should only be done once on the top most decl. */ | |
4831 | if (have_extern_spec && !used_extern_spec) | |
4832 | { | |
4833 | declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); | |
4834 | used_extern_spec = 1; | |
4835 | } | |
4836 | ||
4837 | decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises); | |
4838 | if (decl == NULL_TREE || decl == void_type_node) | |
4839 | return NULL_TREE; | |
4840 | ||
4841 | type = TREE_TYPE (decl); | |
4842 | ||
4843 | /* Don't lose if destructors must be executed at file-level. */ | |
4844 | if (TREE_STATIC (decl) | |
4845 | && TYPE_NEEDS_DESTRUCTOR (type) | |
4846 | && !TREE_PERMANENT (decl)) | |
4847 | { | |
4848 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
4849 | decl = copy_node (decl); | |
4850 | if (TREE_CODE (type) == ARRAY_TYPE) | |
4851 | { | |
4852 | tree itype = TYPE_DOMAIN (type); | |
4853 | if (itype && ! TREE_PERMANENT (itype)) | |
4854 | { | |
4855 | itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype))); | |
4856 | type = build_cplus_array_type (TREE_TYPE (type), itype); | |
4857 | TREE_TYPE (decl) = type; | |
4858 | } | |
4859 | } | |
4860 | pop_obstacks (); | |
4861 | } | |
4862 | ||
4863 | /* Interesting work for this is done in `finish_exception_decl'. */ | |
4864 | if (TREE_CODE (type) == RECORD_TYPE | |
4865 | && CLASSTYPE_DECLARED_EXCEPTION (type)) | |
4866 | return decl; | |
4867 | ||
4868 | /* Corresponding pop_obstacks is done in `finish_decl'. */ | |
4869 | push_obstacks_nochange (); | |
4870 | ||
4871 | context | |
4872 | = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) | |
4873 | ? DECL_CLASS_CONTEXT (decl) | |
4874 | : DECL_CONTEXT (decl); | |
4875 | ||
4876 | if (processing_template_decl) | |
4877 | { | |
4878 | tree d; | |
4879 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
4880 | { | |
4881 | /* Declarator is a call_expr; extract arguments from it, since | |
4882 | grokdeclarator didn't do it. */ | |
4883 | tree args; | |
4884 | args = copy_to_permanent (last_function_parms); | |
4885 | if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) | |
4886 | { | |
4887 | tree t = TREE_TYPE (decl); | |
4888 | tree decl; | |
4889 | ||
4890 | t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */ | |
4891 | if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE) | |
4892 | { | |
4893 | t = build_pointer_type (t); /* base type of `this' */ | |
4894 | #if 1 | |
4895 | /* I suspect this is wrong. */ | |
4896 | t = build_type_variant (t, flag_this_is_variable <= 0, | |
4897 | 0); /* type of `this' */ | |
4898 | #else | |
4899 | t = build_type_variant (t, 0, 0); /* type of `this' */ | |
4900 | #endif | |
4901 | t = build (PARM_DECL, t, this_identifier); | |
4902 | TREE_CHAIN (t) = args; | |
4903 | args = t; | |
4904 | } | |
4905 | } | |
4906 | DECL_ARGUMENTS (decl) = args; | |
4907 | } | |
4908 | d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl)); | |
4909 | TREE_PUBLIC (d) = TREE_PUBLIC (decl) = 0; | |
4910 | TREE_STATIC (d) = TREE_STATIC (decl); | |
4911 | DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl) | |
4912 | && !(context && !DECL_THIS_EXTERN (decl))); | |
4913 | DECL_TEMPLATE_RESULT (d) = decl; | |
4914 | DECL_OVERLOADED (d) = 1; | |
4915 | decl = d; | |
4916 | } | |
4917 | ||
4918 | if (context && TYPE_SIZE (context) != NULL_TREE) | |
4919 | { | |
4920 | /* If it was not explicitly declared `extern', | |
4921 | revoke any previous claims of DECL_EXTERNAL. */ | |
4922 | if (DECL_THIS_EXTERN (decl) == 0) | |
4923 | DECL_EXTERNAL (decl) = 0; | |
4924 | if (DECL_LANG_SPECIFIC (decl)) | |
4925 | DECL_IN_AGGR_P (decl) = 0; | |
4926 | pushclass (context, 2); | |
4927 | } | |
4928 | ||
4929 | /* If this type of object needs a cleanup, and control may | |
4930 | jump past it, make a new binding level so that it is cleaned | |
4931 | up only when it is initialized first. */ | |
4932 | if (TYPE_NEEDS_DESTRUCTOR (type) | |
4933 | && current_binding_level->more_cleanups_ok == 0) | |
4934 | pushlevel_temporary (1); | |
4935 | ||
4936 | if (initialized) | |
4937 | /* Is it valid for this decl to have an initializer at all? | |
4938 | If not, set INITIALIZED to zero, which will indirectly | |
4939 | tell `finish_decl' to ignore the initializer once it is parsed. */ | |
4940 | switch (TREE_CODE (decl)) | |
4941 | { | |
4942 | case TYPE_DECL: | |
4943 | /* typedef foo = bar means give foo the same type as bar. | |
4944 | We haven't parsed bar yet, so `finish_decl' will fix that up. | |
4945 | Any other case of an initialization in a TYPE_DECL is an error. */ | |
4946 | if (pedantic || list_length (declspecs) > 1) | |
4947 | { | |
4948 | error ("typedef `%s' is initialized", | |
4949 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
4950 | initialized = 0; | |
4951 | } | |
4952 | break; | |
4953 | ||
4954 | case FUNCTION_DECL: | |
4955 | error ("function `%s' is initialized like a variable", | |
4956 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
4957 | initialized = 0; | |
4958 | break; | |
4959 | ||
4960 | default: | |
4961 | /* Don't allow initializations for incomplete types | |
4962 | except for arrays which might be completed by the initialization. */ | |
4963 | if (TYPE_SIZE (type) != NULL_TREE) | |
4964 | ; /* A complete type is ok. */ | |
4965 | else if (TREE_CODE (type) != ARRAY_TYPE) | |
4966 | { | |
4967 | error ("variable `%s' has initializer but incomplete type", | |
4968 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
4969 | initialized = 0; | |
4970 | } | |
4971 | else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE) | |
4972 | { | |
4973 | error ("elements of array `%s' have incomplete type", | |
4974 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
4975 | initialized = 0; | |
4976 | } | |
4977 | } | |
4978 | ||
4979 | if (!initialized | |
4980 | && TREE_CODE (decl) != TYPE_DECL | |
4981 | && TREE_CODE (decl) != TEMPLATE_DECL | |
4982 | && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) | |
4983 | { | |
4984 | if (TYPE_SIZE (type) == NULL_TREE) | |
4985 | { | |
4986 | error ("aggregate `%s' has incomplete type and cannot be initialized", | |
4987 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
4988 | /* Change the type so that assemble_variable will give | |
4989 | DECL an rtl we can live with: (mem (const_int 0)). */ | |
4990 | TREE_TYPE (decl) = error_mark_node; | |
4991 | type = error_mark_node; | |
4992 | } | |
4993 | else | |
4994 | { | |
4995 | /* If any base type in the hierarchy of TYPE needs a constructor, | |
4996 | then we set initialized to 1. This way any nodes which are | |
4997 | created for the purposes of initializing this aggregate | |
4998 | will live as long as it does. This is necessary for global | |
4999 | aggregates which do not have their initializers processed until | |
5000 | the end of the file. */ | |
5001 | initialized = TYPE_NEEDS_CONSTRUCTING (type); | |
5002 | } | |
5003 | } | |
5004 | ||
5005 | if (initialized) | |
5006 | { | |
5007 | if (current_binding_level != global_binding_level | |
5008 | && DECL_EXTERNAL (decl)) | |
5009 | warning ("declaration of `%s' has `extern' and is initialized", | |
5010 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
5011 | DECL_EXTERNAL (decl) = 0; | |
5012 | if (current_binding_level == global_binding_level) | |
5013 | TREE_STATIC (decl) = 1; | |
5014 | ||
5015 | /* Tell `pushdecl' this is an initialized decl | |
5016 | even though we don't yet have the initializer expression. | |
5017 | Also tell `finish_decl' it may store the real initializer. */ | |
5018 | DECL_INITIAL (decl) = error_mark_node; | |
5019 | } | |
5020 | ||
5021 | /* Add this decl to the current binding level, but not if it | |
5022 | comes from another scope, e.g. a static member variable. | |
5023 | TEM may equal DECL or it may be a previous decl of the same name. */ | |
5024 | if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE) | |
5025 | || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ()) | |
5026 | || TREE_CODE (type) == LANG_TYPE) | |
5027 | tem = decl; | |
5028 | else | |
5029 | { | |
5030 | tem = pushdecl (decl); | |
5031 | if (TREE_CODE (tem) == TREE_LIST) | |
5032 | { | |
5033 | tree tem2 = value_member (decl, tem); | |
5034 | if (tem2 != NULL_TREE) | |
5035 | tem = TREE_VALUE (tem2); | |
5036 | else | |
5037 | { | |
5038 | while (tem && ! decls_match (decl, TREE_VALUE (tem))) | |
5039 | tem = TREE_CHAIN (tem); | |
5040 | if (tem == NULL_TREE) | |
5041 | tem = decl; | |
5042 | else | |
5043 | tem = TREE_VALUE (tem); | |
5044 | } | |
5045 | } | |
5046 | } | |
5047 | ||
5048 | #if 0 | |
5049 | /* We don't do this yet for GNU C++. */ | |
5050 | /* For a local variable, define the RTL now. */ | |
5051 | if (current_binding_level != global_binding_level | |
5052 | /* But not if this is a duplicate decl | |
5053 | and we preserved the rtl from the previous one | |
5054 | (which may or may not happen). */ | |
5055 | && DECL_RTL (tem) == NULL_RTX) | |
5056 | { | |
5057 | if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) | |
5058 | expand_decl (tem); | |
5059 | else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE | |
5060 | && DECL_INITIAL (tem) != NULL_TREE) | |
5061 | expand_decl (tem); | |
5062 | } | |
5063 | #endif | |
5064 | ||
5065 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_OVERLOADED (decl)) | |
5066 | /* @@ Also done in start_function. */ | |
5067 | tem = push_overloaded_decl (tem, 1); | |
5068 | else if (TREE_CODE (decl) == TEMPLATE_DECL) | |
5069 | { | |
5070 | tree result = DECL_TEMPLATE_RESULT (decl); | |
5071 | if (DECL_CONTEXT (result) != NULL_TREE) | |
5072 | { | |
5073 | tree type; | |
5074 | type = DECL_CONTEXT (result); | |
5075 | my_friendly_assert (TREE_CODE (type) == UNINSTANTIATED_P_TYPE, 145); | |
5076 | if (/* TREE_CODE (result) == VAR_DECL */ 1) | |
5077 | { | |
5078 | #if 0 | |
5079 | tree tmpl = UPT_TEMPLATE (type); | |
5080 | ||
5081 | fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__); | |
5082 | print_node_brief (stderr, "", DECL_NAME (tem), 0); | |
5083 | fprintf (stderr, " to class %s\n", | |
5084 | IDENTIFIER_POINTER (DECL_NAME (tmpl))); | |
5085 | DECL_TEMPLATE_MEMBERS (tmpl) | |
5086 | = perm_tree_cons (DECL_NAME (tem), tem, | |
5087 | DECL_TEMPLATE_MEMBERS (tmpl)); | |
5088 | #endif | |
5089 | return tem; | |
5090 | } | |
5091 | my_friendly_abort (13); | |
5092 | } | |
5093 | else if (TREE_CODE (result) == FUNCTION_DECL) | |
5094 | tem = push_overloaded_decl (tem, 0); | |
5095 | else if (TREE_CODE (result) == VAR_DECL | |
5096 | || TREE_CODE (result) == TYPE_DECL) | |
5097 | { | |
5098 | error ("invalid template `%s'", | |
5099 | IDENTIFIER_POINTER (DECL_NAME (result))); | |
5100 | return NULL_TREE; | |
5101 | } | |
5102 | else | |
5103 | my_friendly_abort (14); | |
5104 | } | |
5105 | ||
5106 | if (init_written | |
5107 | && ! (TREE_CODE (tem) == PARM_DECL | |
5108 | || (TREE_READONLY (tem) | |
5109 | && (TREE_CODE (tem) == VAR_DECL | |
5110 | || TREE_CODE (tem) == FIELD_DECL)))) | |
5111 | { | |
5112 | /* When parsing and digesting the initializer, | |
5113 | use temporary storage. Do this even if we will ignore the value. */ | |
5114 | if (current_binding_level == global_binding_level && debug_temp_inits) | |
5115 | { | |
5116 | if (TYPE_NEEDS_CONSTRUCTING (type) || TREE_CODE (type) == REFERENCE_TYPE) | |
5117 | /* In this case, the initializer must lay down in permanent | |
5118 | storage, since it will be saved until `finish_file' is run. */ | |
5119 | ; | |
5120 | else | |
5121 | temporary_allocation (); | |
5122 | } | |
5123 | } | |
5124 | ||
5125 | if (flag_cadillac) | |
5126 | cadillac_start_decl (tem); | |
5127 | ||
5128 | return tem; | |
5129 | } | |
5130 | ||
5131 | static void | |
5132 | make_temporary_for_reference (decl, ctor_call, init, cleanupp) | |
5133 | tree decl, ctor_call, init; | |
5134 | tree *cleanupp; | |
5135 | { | |
5136 | tree type = TREE_TYPE (decl); | |
5137 | tree target_type = TREE_TYPE (type); | |
5138 | tree tmp, tmp_addr; | |
5139 | ||
5140 | if (ctor_call) | |
5141 | { | |
5142 | tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1)); | |
5143 | if (TREE_CODE (tmp_addr) == NOP_EXPR) | |
5144 | tmp_addr = TREE_OPERAND (tmp_addr, 0); | |
5145 | my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146); | |
5146 | tmp = TREE_OPERAND (tmp_addr, 0); | |
5147 | } | |
5148 | else | |
5149 | { | |
5150 | tmp = get_temp_name (target_type, | |
5151 | current_binding_level == global_binding_level); | |
5152 | tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0); | |
5153 | } | |
5154 | ||
5155 | TREE_TYPE (tmp_addr) = build_pointer_type (target_type); | |
5156 | DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr); | |
5157 | TREE_TYPE (DECL_INITIAL (decl)) = type; | |
5158 | if (TYPE_NEEDS_CONSTRUCTING (target_type)) | |
5159 | { | |
5160 | if (current_binding_level == global_binding_level) | |
5161 | { | |
5162 | /* lay this variable out now. Otherwise `output_addressed_constants' | |
5163 | gets confused by its initializer. */ | |
5164 | make_decl_rtl (tmp, NULL_PTR, 1); | |
5165 | static_aggregates = perm_tree_cons (init, tmp, static_aggregates); | |
5166 | } | |
5167 | else | |
5168 | { | |
5169 | if (ctor_call != NULL_TREE) | |
5170 | init = ctor_call; | |
5171 | else | |
5172 | init = build_method_call (tmp, constructor_name (target_type), | |
5173 | build_tree_list (NULL_TREE, init), | |
5174 | NULL_TREE, LOOKUP_NORMAL); | |
5175 | DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init, | |
5176 | DECL_INITIAL (decl)); | |
5177 | *cleanupp = maybe_build_cleanup (tmp); | |
5178 | } | |
5179 | } | |
5180 | else | |
5181 | { | |
5182 | DECL_INITIAL (tmp) = init; | |
5183 | TREE_STATIC (tmp) = current_binding_level == global_binding_level; | |
5184 | finish_decl (tmp, init, 0, 0); | |
5185 | } | |
5186 | if (TREE_STATIC (tmp)) | |
5187 | preserve_initializer (); | |
5188 | } | |
5189 | ||
5190 | /* Handle initialization of references. | |
5191 | These three arguments from from `finish_decl', and have the | |
5192 | same meaning here that they do there. */ | |
5193 | /* quotes on semantics can be found in ARM 8.4.3. */ | |
5194 | static void | |
5195 | grok_reference_init (decl, type, init, cleanupp) | |
5196 | tree decl, type, init; | |
5197 | tree *cleanupp; | |
5198 | { | |
5199 | char *errstr = NULL; | |
5200 | int is_reference; | |
5201 | tree tmp; | |
5202 | tree this_ptr_type, actual_init; | |
5203 | ||
5204 | if (init == NULL_TREE) | |
5205 | { | |
5206 | if (DECL_LANG_SPECIFIC (decl) == 0 | |
5207 | || DECL_IN_AGGR_P (decl) == 0) | |
5208 | { | |
5209 | error ("variable declared as reference not initialized"); | |
5210 | if (TREE_CODE (decl) == VAR_DECL) | |
5211 | SET_DECL_REFERENCE_SLOT (decl, error_mark_node); | |
5212 | } | |
5213 | return; | |
5214 | } | |
5215 | ||
5216 | if (TREE_CODE (init) == TREE_LIST) | |
5217 | init = build_compound_expr (init); | |
5218 | is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE; | |
5219 | tmp = is_reference ? convert_from_reference (init) : init; | |
5220 | ||
5221 | if (is_reference) | |
5222 | { | |
5223 | if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)), | |
5224 | TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0)) | |
5225 | errstr = "initialization of `%s' from dissimilar reference type"; | |
5226 | else if (TYPE_READONLY (TREE_TYPE (type)) | |
5227 | >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (init)))) | |
5228 | { | |
5229 | is_reference = 0; | |
5230 | init = tmp; | |
5231 | } | |
5232 | } | |
5233 | else | |
5234 | { | |
5235 | if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE | |
5236 | && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE) | |
5237 | { | |
5238 | /* Note: default conversion is only called in very | |
5239 | special cases. */ | |
5240 | init = default_conversion (init); | |
5241 | } | |
5242 | if (TREE_CODE (TREE_TYPE (type)) == TREE_CODE (TREE_TYPE (init))) | |
5243 | { | |
5244 | if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)), | |
5245 | TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0)) | |
5246 | { | |
5247 | /* This section implements ANSI C++ June 5 1992 WP 8.4.3.5. */ | |
5248 | ||
5249 | /* A reference to a volatile T cannot be initialized with | |
5250 | a const T, and vice-versa. */ | |
5251 | if (TYPE_VOLATILE (TREE_TYPE (type)) && TREE_READONLY (init)) | |
5252 | errstr = "cannot initialize a reference to a volatile T with a const T"; | |
5253 | else if (TYPE_READONLY (TREE_TYPE (type)) && TREE_THIS_VOLATILE (init)) | |
5254 | errstr = "cannot initialize a reference to a const T with a volatile T"; | |
5255 | /* A reference to a plain T can be initialized only with | |
5256 | a plain T. */ | |
5257 | else if (!TYPE_VOLATILE (TREE_TYPE (type)) | |
5258 | && !TYPE_READONLY (TREE_TYPE (type))) | |
5259 | { | |
5260 | if (TREE_READONLY (init)) | |
5261 | errstr = "cannot initialize a reference to T with a const T"; | |
5262 | else if (TREE_THIS_VOLATILE (init)) | |
5263 | errstr = "cannot initialize a reference to T with a volatile T"; | |
5264 | } | |
5265 | } | |
5266 | else | |
5267 | init = convert (TREE_TYPE (type), init); | |
5268 | } | |
5269 | else if (init != error_mark_node | |
5270 | && ! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)), | |
5271 | TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0)) | |
5272 | errstr = "invalid type conversion for reference"; | |
5273 | } | |
5274 | ||
5275 | if (errstr) | |
5276 | { | |
5277 | /* Things did not go smoothly; look for operator& type conversion. */ | |
5278 | if (IS_AGGR_TYPE (TREE_TYPE (tmp))) | |
5279 | { | |
5280 | tmp = build_type_conversion (CONVERT_EXPR, type, init, 0); | |
5281 | if (tmp != NULL_TREE) | |
5282 | { | |
5283 | init = tmp; | |
5284 | if (tmp == error_mark_node) | |
5285 | errstr = "ambiguous pointer conversion"; | |
5286 | else | |
5287 | errstr = NULL; | |
5288 | is_reference = 1; | |
5289 | } | |
5290 | else | |
5291 | { | |
5292 | tmp = build_type_conversion (CONVERT_EXPR, TREE_TYPE (type), init, 0); | |
5293 | if (tmp != NULL_TREE) | |
5294 | { | |
5295 | init = tmp; | |
5296 | if (tmp == error_mark_node) | |
5297 | errstr = "ambiguous pointer conversion"; | |
5298 | else | |
5299 | errstr = NULL; | |
5300 | is_reference = 0; | |
5301 | } | |
5302 | } | |
5303 | } | |
5304 | /* Look for constructor. */ | |
5305 | else if (IS_AGGR_TYPE (TREE_TYPE (type)) | |
5306 | && TYPE_HAS_CONSTRUCTOR (TREE_TYPE (type))) | |
5307 | { | |
5308 | tmp = get_temp_name (TREE_TYPE (type), | |
5309 | current_binding_level == global_binding_level); | |
5310 | tmp = build_method_call (tmp, constructor_name (TREE_TYPE (type)), | |
5311 | build_tree_list (NULL_TREE, init), | |
5312 | NULL_TREE, LOOKUP_NORMAL); | |
5313 | if (tmp == NULL_TREE || tmp == error_mark_node) | |
5314 | { | |
5315 | if (TREE_CODE (decl) == VAR_DECL) | |
5316 | SET_DECL_REFERENCE_SLOT (decl, error_mark_node); | |
5317 | error_with_decl (decl, "constructor failed to build reference initializer"); | |
5318 | return; | |
5319 | } | |
5320 | make_temporary_for_reference (decl, tmp, init, cleanupp); | |
5321 | goto done; | |
5322 | } | |
5323 | } | |
5324 | ||
5325 | if (errstr) | |
5326 | { | |
5327 | error_with_decl (decl, errstr); | |
5328 | if (TREE_CODE (decl) == VAR_DECL) | |
5329 | SET_DECL_REFERENCE_SLOT (decl, error_mark_node); | |
5330 | return; | |
5331 | } | |
5332 | ||
5333 | /* In the case of initialization, it is permissible | |
5334 | to assign one reference to another. */ | |
5335 | this_ptr_type = build_pointer_type (TREE_TYPE (type)); | |
5336 | ||
5337 | if (is_reference) | |
5338 | { | |
5339 | if (TREE_SIDE_EFFECTS (init)) | |
5340 | DECL_INITIAL (decl) = save_expr (init); | |
5341 | else | |
5342 | DECL_INITIAL (decl) = init; | |
5343 | } | |
5344 | else if (lvalue_p (init)) | |
5345 | { | |
5346 | tmp = build_unary_op (ADDR_EXPR, init, 0); | |
5347 | if (TREE_CODE (tmp) == ADDR_EXPR | |
5348 | && TREE_CODE (TREE_OPERAND (tmp, 0)) == WITH_CLEANUP_EXPR) | |
5349 | { | |
5350 | /* Associate the cleanup with the reference so that we | |
5351 | don't get burned by "aggressive" cleanup policy. */ | |
5352 | *cleanupp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 2); | |
5353 | TREE_OPERAND (TREE_OPERAND (tmp, 0), 2) = error_mark_node; | |
5354 | } | |
5355 | if (IS_AGGR_TYPE (TREE_TYPE (this_ptr_type))) | |
5356 | DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp); | |
5357 | else | |
5358 | DECL_INITIAL (decl) = convert (this_ptr_type, tmp); | |
5359 | ||
5360 | DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); | |
5361 | if (DECL_INITIAL (decl) == current_class_decl) | |
5362 | DECL_INITIAL (decl) = copy_node (current_class_decl); | |
5363 | TREE_TYPE (DECL_INITIAL (decl)) = type; | |
5364 | } | |
5365 | else if ((actual_init = unary_complex_lvalue (ADDR_EXPR, init))) | |
5366 | { | |
5367 | /* The initializer for this decl goes into its | |
5368 | DECL_REFERENCE_SLOT. Make sure that we can handle | |
5369 | multiple evaluations without ill effect. */ | |
5370 | if (TREE_CODE (actual_init) == ADDR_EXPR | |
5371 | && TREE_CODE (TREE_OPERAND (actual_init, 0)) == TARGET_EXPR) | |
5372 | actual_init = save_expr (actual_init); | |
5373 | DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init); | |
5374 | DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); | |
5375 | TREE_TYPE (DECL_INITIAL (decl)) = type; | |
5376 | } | |
5377 | else if (TYPE_READONLY (TREE_TYPE (type))) | |
5378 | /* Section 8.4.3 allows us to make a temporary for | |
5379 | the initialization of const&. */ | |
5380 | make_temporary_for_reference (decl, NULL_TREE, init, cleanupp); | |
5381 | else | |
5382 | { | |
5383 | error_with_decl (decl, "type mismatch in initialization of `%s' (use `const')"); | |
5384 | DECL_INITIAL (decl) = error_mark_node; | |
5385 | } | |
5386 | ||
5387 | done: | |
5388 | /* ?? Can this be optimized in some cases to | |
5389 | hand back the DECL_INITIAL slot?? */ | |
5390 | if (TYPE_SIZE (TREE_TYPE (type))) | |
5391 | { | |
5392 | init = convert_from_reference (decl); | |
5393 | if (TREE_PERMANENT (decl)) | |
5394 | init = copy_to_permanent (init); | |
5395 | SET_DECL_REFERENCE_SLOT (decl, init); | |
5396 | } | |
5397 | ||
5398 | if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl))) | |
5399 | { | |
5400 | expand_static_init (decl, DECL_INITIAL (decl)); | |
5401 | DECL_INITIAL (decl) = NULL_TREE; | |
5402 | } | |
5403 | } | |
5404 | ||
5405 | /* Finish processing of a declaration; | |
5406 | install its line number and initial value. | |
5407 | If the length of an array type is not known before, | |
5408 | it must be determined now, from the initial value, or it is an error. | |
5409 | ||
5410 | Call `pop_obstacks' iff NEED_POP is nonzero. | |
5411 | ||
5412 | For C++, `finish_decl' must be fairly evasive: it must keep initializers | |
5413 | for aggregates that have constructors alive on the permanent obstack, | |
5414 | so that the global initializing functions can be written at the end. | |
5415 | ||
5416 | INIT0 holds the value of an initializer that should be allowed to escape | |
5417 | the normal rules. | |
5418 | ||
5419 | For functions that take default parameters, DECL points to its | |
5420 | "maximal" instantiation. `finish_decl' must then also declared its | |
5421 | subsequently lower and lower forms of instantiation, checking for | |
5422 | ambiguity as it goes. This can be sped up later. */ | |
5423 | ||
5424 | void | |
5425 | finish_decl (decl, init, asmspec_tree, need_pop) | |
5426 | tree decl, init; | |
5427 | tree asmspec_tree; | |
5428 | int need_pop; | |
5429 | { | |
5430 | register tree type; | |
5431 | tree cleanup = NULL_TREE, ttype; | |
5432 | int was_incomplete; | |
5433 | int temporary = allocation_temporary_p (); | |
5434 | char *asmspec = NULL; | |
5435 | int was_readonly = 0; | |
5436 | ||
5437 | /* If this is 0, then we did not change obstacks. */ | |
5438 | if (! decl) | |
5439 | { | |
5440 | if (init) | |
5441 | error ("assignment (not initialization) in declaration"); | |
5442 | return; | |
5443 | } | |
5444 | ||
5445 | if (asmspec_tree) | |
5446 | { | |
5447 | asmspec = TREE_STRING_POINTER (asmspec_tree); | |
5448 | /* Zero out old RTL, since we will rewrite it. */ | |
5449 | DECL_RTL (decl) = NULL_RTX; | |
5450 | } | |
5451 | ||
5452 | /* If the type of the thing we are declaring either has | |
5453 | a constructor, or has a virtual function table pointer, | |
5454 | AND its initialization was accepted by `start_decl', | |
5455 | then we stayed on the permanent obstack through the | |
5456 | declaration, otherwise, changed obstacks as GCC would. */ | |
5457 | ||
5458 | type = TREE_TYPE (decl); | |
5459 | ||
5460 | was_incomplete = (DECL_SIZE (decl) == NULL_TREE); | |
5461 | ||
5462 | /* Take care of TYPE_DECLs up front. */ | |
5463 | if (TREE_CODE (decl) == TYPE_DECL) | |
5464 | { | |
5465 | if (init && DECL_INITIAL (decl)) | |
5466 | { | |
5467 | /* typedef foo = bar; store the type of bar as the type of foo. */ | |
5468 | TREE_TYPE (decl) = type = TREE_TYPE (init); | |
5469 | DECL_INITIAL (decl) = init = NULL_TREE; | |
5470 | } | |
5471 | if (IS_AGGR_TYPE (type) && DECL_NAME (decl)) | |
5472 | { | |
5473 | if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type) | |
5474 | warning ("shadowing previous type declaration of `%s'", | |
5475 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
5476 | set_identifier_type_value (DECL_NAME (decl), type); | |
5477 | CLASSTYPE_GOT_SEMICOLON (type) = 1; | |
5478 | } | |
5479 | GNU_xref_decl (current_function_decl, decl); | |
5480 | rest_of_decl_compilation (decl, NULL_PTR, | |
5481 | DECL_CONTEXT (decl) == NULL_TREE, 0); | |
5482 | goto finish_end; | |
5483 | } | |
5484 | if (type != error_mark_node && IS_AGGR_TYPE (type) | |
5485 | && CLASSTYPE_DECLARED_EXCEPTION (type)) | |
5486 | { | |
5487 | finish_exception_decl (NULL_TREE, decl); | |
5488 | CLASSTYPE_GOT_SEMICOLON (type) = 1; | |
5489 | goto finish_end; | |
5490 | } | |
5491 | if (TREE_CODE (decl) != FUNCTION_DECL) | |
5492 | { | |
5493 | ttype = target_type (type); | |
5494 | #if 0 /* WTF? -KR | |
5495 | Leave this out until we can figure out why it was | |
5496 | needed/desirable in the first place. Then put a comment | |
5497 | here explaining why. Or just delete the code if no ill | |
5498 | effects arise. */ | |
5499 | if (TYPE_NAME (ttype) | |
5500 | && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL | |
5501 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype))) | |
5502 | { | |
5503 | tree old_id = TYPE_IDENTIFIER (ttype); | |
5504 | char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2); | |
5505 | /* Need to preserve template data for UPT nodes. */ | |
5506 | tree old_template = IDENTIFIER_TEMPLATE (old_id); | |
5507 | newname[0] = '_'; | |
5508 | bcopy (IDENTIFIER_POINTER (old_id), newname + 1, | |
5509 | IDENTIFIER_LENGTH (old_id) + 1); | |
5510 | old_id = get_identifier (newname); | |
5511 | lookup_tag_reverse (ttype, old_id); | |
5512 | TYPE_IDENTIFIER (ttype) = old_id; | |
5513 | IDENTIFIER_TEMPLATE (old_id) = old_template; | |
5514 | } | |
5515 | #endif | |
5516 | } | |
5517 | ||
5518 | if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) | |
5519 | && TYPE_NEEDS_CONSTRUCTING (type)) | |
5520 | { | |
5521 | ||
5522 | /* Currently, GNU C++ puts constants in text space, making them | |
5523 | impossible to initialize. In the future, one would hope for | |
5524 | an operating system which understood the difference between | |
5525 | initialization and the running of a program. */ | |
5526 | was_readonly = 1; | |
5527 | TREE_READONLY (decl) = 0; | |
5528 | } | |
5529 | ||
5530 | if (TREE_CODE (decl) == FIELD_DECL) | |
5531 | { | |
5532 | if (init && init != error_mark_node) | |
5533 | my_friendly_assert (TREE_PERMANENT (init), 147); | |
5534 | ||
5535 | if (asmspec) | |
5536 | { | |
5537 | /* This must override the asm specifier which was placed | |
5538 | by grokclassfn. Lay this out fresh. | |
5539 | ||
5540 | @@ Should emit an error if this redefines an asm-specified | |
5541 | @@ name, or if we have already used the function's name. */ | |
5542 | DECL_RTL (TREE_TYPE (decl)) = NULL_RTX; | |
5543 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
5544 | make_decl_rtl (decl, asmspec, 0); | |
5545 | } | |
5546 | } | |
5547 | /* If `start_decl' didn't like having an initialization, ignore it now. */ | |
5548 | else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) | |
5549 | init = NULL_TREE; | |
5550 | else if (DECL_EXTERNAL (decl)) | |
5551 | ; | |
5552 | else if (TREE_CODE (type) == REFERENCE_TYPE) | |
5553 | { | |
5554 | grok_reference_init (decl, type, init, &cleanup); | |
5555 | init = NULL_TREE; | |
5556 | } | |
5557 | ||
5558 | GNU_xref_decl (current_function_decl, decl); | |
5559 | ||
5560 | if (TREE_CODE (decl) == FIELD_DECL || DECL_EXTERNAL (decl)) | |
5561 | ; | |
5562 | else if (TREE_CODE (decl) == CONST_DECL) | |
5563 | { | |
5564 | my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); | |
5565 | ||
5566 | DECL_INITIAL (decl) = init; | |
5567 | ||
5568 | /* This will keep us from needing to worry about our obstacks. */ | |
5569 | my_friendly_assert (init != NULL_TREE, 149); | |
5570 | init = NULL_TREE; | |
5571 | } | |
5572 | else if (init) | |
5573 | { | |
5574 | if (TYPE_NEEDS_CONSTRUCTING (type)) | |
5575 | { | |
5576 | if (TREE_CODE (type) == ARRAY_TYPE) | |
5577 | init = digest_init (type, init, (tree *) 0); | |
5578 | else if (TREE_CODE (init) == CONSTRUCTOR | |
5579 | && CONSTRUCTOR_ELTS (init) != NULL_TREE) | |
5580 | { | |
5581 | error_with_decl (decl, "`%s' must be initialized by constructor, not by `{...}'"); | |
5582 | init = error_mark_node; | |
5583 | } | |
5584 | #if 0 | |
5585 | /* fix this in `build_functional_cast' instead. | |
5586 | Here's the trigger code: | |
5587 | ||
5588 | struct ostream | |
5589 | { | |
5590 | ostream (); | |
5591 | ostream (int, char *); | |
5592 | ostream (char *); | |
5593 | operator char *(); | |
5594 | ostream (void *); | |
5595 | operator void *(); | |
5596 | operator << (int); | |
5597 | }; | |
5598 | int buf_size = 1024; | |
5599 | static char buf[buf_size]; | |
5600 | const char *debug(int i) { | |
5601 | char *b = &buf[0]; | |
5602 | ostream o = ostream(buf_size, b); | |
5603 | o << i; | |
5604 | return buf; | |
5605 | } | |
5606 | */ | |
5607 | ||
5608 | else if (TREE_CODE (init) == TARGET_EXPR | |
5609 | && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR)) | |
5610 | { | |
5611 | /* User wrote something like `foo x = foo (args)' */ | |
5612 | my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150); | |
5613 | my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151); | |
5614 | ||
5615 | /* User wrote exactly `foo x = foo (args)' */ | |
5616 | if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init)) | |
5617 | { | |
5618 | init = build (CALL_EXPR, TREE_TYPE (init), | |
5619 | TREE_OPERAND (TREE_OPERAND (init, 1), 0), | |
5620 | TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0); | |
5621 | TREE_SIDE_EFFECTS (init) = 1; | |
5622 | } | |
5623 | } | |
5624 | #endif | |
5625 | ||
5626 | /* We must hide the initializer so that expand_decl | |
5627 | won't try to do something it does not understand. */ | |
5628 | if (current_binding_level == global_binding_level) | |
5629 | { | |
5630 | tree value = digest_init (type, empty_init_node, (tree *) 0); | |
5631 | DECL_INITIAL (decl) = value; | |
5632 | } | |
5633 | else | |
5634 | DECL_INITIAL (decl) = error_mark_node; | |
5635 | } | |
5636 | else | |
5637 | { | |
5638 | if (TREE_CODE (init) != TREE_VEC) | |
5639 | init = store_init_value (decl, init); | |
5640 | ||
5641 | if (init) | |
5642 | /* Don't let anyone try to initialize this variable | |
5643 | until we are ready to do so. */ | |
5644 | DECL_INITIAL (decl) = error_mark_node; | |
5645 | } | |
5646 | } | |
5647 | else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't' | |
5648 | && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))) | |
5649 | { | |
5650 | tree ctype = type; | |
5651 | while (TREE_CODE (ctype) == ARRAY_TYPE) | |
5652 | ctype = TREE_TYPE (ctype); | |
5653 | if (! TYPE_NEEDS_CONSTRUCTOR (ctype)) | |
5654 | { | |
5655 | if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype)) | |
5656 | error_with_decl (decl, "structure `%s' with uninitialized const members"); | |
5657 | if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype)) | |
5658 | error_with_decl (decl, "structure `%s' with uninitialized reference members"); | |
5659 | } | |
5660 | ||
5661 | if (TREE_CODE (decl) == VAR_DECL | |
5662 | && !TYPE_NEEDS_CONSTRUCTING (type) | |
5663 | && (TYPE_READONLY (type) || TREE_READONLY (decl))) | |
5664 | error_with_decl (decl, "uninitialized const `%s'"); | |
5665 | ||
5666 | /* Initialize variables in need of static initialization | |
5667 | with `empty_init_node' to keep assemble_variable from putting them | |
5668 | in the wrong program space. (Common storage is okay for non-public | |
5669 | uninitialized data; the linker can't match it with storage from other | |
5670 | files, and we may save some disk space.) */ | |
5671 | if (flag_pic == 0 | |
5672 | && TREE_STATIC (decl) | |
5673 | && TREE_PUBLIC (decl) | |
5674 | && ! DECL_EXTERNAL (decl) | |
5675 | && TREE_CODE (decl) == VAR_DECL | |
5676 | && TYPE_NEEDS_CONSTRUCTING (type) | |
5677 | && (DECL_INITIAL (decl) == NULL_TREE | |
5678 | || DECL_INITIAL (decl) == error_mark_node)) | |
5679 | { | |
5680 | tree value = digest_init (type, empty_init_node, (tree *) 0); | |
5681 | DECL_INITIAL (decl) = value; | |
5682 | } | |
5683 | } | |
5684 | else if (TREE_CODE (decl) == VAR_DECL | |
5685 | && TREE_CODE (type) != REFERENCE_TYPE | |
5686 | && (TYPE_READONLY (type) || TREE_READONLY (decl))) | |
5687 | { | |
5688 | /* ``Unless explicitly declared extern, a const object does not have | |
5689 | external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 | |
5690 | However, if it's `const int foo = 1; const int foo;', don't complain | |
5691 | about the second decl, since it does have an initializer before. */ | |
5692 | if (! DECL_INITIAL (decl) && (!pedantic || !current_class_type)) | |
5693 | error_with_decl (decl, "uninitialized const `%s'"); | |
5694 | } | |
5695 | ||
5696 | /* For top-level declaration, the initial value was read in | |
5697 | the temporary obstack. MAXINDEX, rtl, etc. to be made below | |
5698 | must go in the permanent obstack; but don't discard the | |
5699 | temporary data yet. */ | |
5700 | ||
5701 | if (current_binding_level == global_binding_level && temporary) | |
5702 | end_temporary_allocation (); | |
5703 | ||
5704 | /* Deduce size of array from initialization, if not already known. */ | |
5705 | ||
5706 | if (TREE_CODE (type) == ARRAY_TYPE | |
5707 | && TYPE_DOMAIN (type) == NULL_TREE | |
5708 | && TREE_CODE (decl) != TYPE_DECL) | |
5709 | { | |
5710 | int do_default | |
5711 | = (TREE_STATIC (decl) | |
5712 | /* Even if pedantic, an external linkage array | |
5713 | may have incomplete type at first. */ | |
5714 | ? pedantic && DECL_EXTERNAL (decl) | |
5715 | : !DECL_EXTERNAL (decl)); | |
5716 | tree initializer = init ? init : DECL_INITIAL (decl); | |
5717 | int failure = complete_array_type (type, initializer, do_default); | |
5718 | ||
5719 | if (failure == 1) | |
5720 | error_with_decl (decl, "initializer fails to determine size of `%s'"); | |
5721 | ||
5722 | if (failure == 2) | |
5723 | { | |
5724 | if (do_default) | |
5725 | error_with_decl (decl, "array size missing in `%s'"); | |
5726 | else if (!pedantic && TREE_STATIC (decl)) | |
5727 | DECL_EXTERNAL (decl) = 1; | |
5728 | } | |
5729 | ||
5730 | if (pedantic && TYPE_DOMAIN (type) != NULL_TREE | |
5731 | && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), | |
5732 | integer_zero_node)) | |
5733 | error_with_decl (decl, "zero-size array `%s'"); | |
5734 | ||
5735 | layout_decl (decl, 0); | |
5736 | } | |
5737 | ||
5738 | if (TREE_CODE (decl) == VAR_DECL) | |
5739 | { | |
5740 | if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) | |
5741 | { | |
5742 | /* A static variable with an incomplete type: | |
5743 | that is an error if it is initialized or `static'. | |
5744 | Otherwise, let it through, but if it is not `extern' | |
5745 | then it may cause an error message later. */ | |
5746 | if (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl) != NULL_TREE) | |
5747 | error_with_decl (decl, "storage size of `%s' isn't known"); | |
5748 | init = NULL_TREE; | |
5749 | } | |
5750 | else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) | |
5751 | { | |
5752 | /* An automatic variable with an incomplete type: that is an error. | |
5753 | Don't talk about array types here, since we took care of that | |
5754 | message in grokdeclarator. */ | |
5755 | error_with_decl (decl, "storage size of `%s' isn't known"); | |
5756 | TREE_TYPE (decl) = error_mark_node; | |
5757 | } | |
5758 | else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) | |
5759 | /* Let debugger know it should output info for this type. */ | |
5760 | note_debug_info_needed (ttype); | |
5761 | ||
5762 | if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) | |
5763 | && DECL_SIZE (decl) != NULL_TREE | |
5764 | && ! TREE_CONSTANT (DECL_SIZE (decl))) | |
5765 | error_with_decl (decl, "storage size of `%s' isn't constant"); | |
5766 | ||
5767 | if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type)) | |
5768 | { | |
5769 | int yes = suspend_momentary (); | |
5770 | ||
5771 | /* If INIT comes from a functional cast, use the cleanup | |
5772 | we built for that. Otherwise, make our own cleanup. */ | |
5773 | if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR | |
5774 | && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1)) | |
5775 | { | |
5776 | cleanup = TREE_OPERAND (init, 2); | |
5777 | init = TREE_OPERAND (init, 0); | |
5778 | current_binding_level->have_cleanups = 1; | |
5779 | current_binding_level->more_exceptions_ok = 0; | |
5780 | } | |
5781 | else | |
5782 | cleanup = maybe_build_cleanup (decl); | |
5783 | resume_momentary (yes); | |
5784 | } | |
5785 | } | |
5786 | /* PARM_DECLs get cleanups, too. */ | |
5787 | else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type)) | |
5788 | { | |
5789 | if (temporary) | |
5790 | end_temporary_allocation (); | |
5791 | cleanup = maybe_build_cleanup (decl); | |
5792 | if (temporary) | |
5793 | resume_temporary_allocation (); | |
5794 | } | |
5795 | ||
5796 | /* Output the assembler code and/or RTL code for variables and functions, | |
5797 | unless the type is an undefined structure or union. | |
5798 | If not, it will get done when the type is completed. */ | |
5799 | ||
5800 | if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL | |
5801 | || TREE_CODE (decl) == RESULT_DECL) | |
5802 | { | |
5803 | int toplev = current_binding_level == global_binding_level; | |
5804 | int was_temp | |
5805 | = ((flag_traditional | |
5806 | || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type))) | |
5807 | && allocation_temporary_p ()); | |
5808 | ||
5809 | if (was_temp) | |
5810 | end_temporary_allocation (); | |
5811 | ||
5812 | /* If we are in need of a cleanup, get out of any implicit | |
5813 | handlers that have been established so far. */ | |
5814 | if (cleanup && current_binding_level->parm_flag == 3) | |
5815 | { | |
5816 | pop_implicit_try_blocks (decl); | |
5817 | current_binding_level->more_exceptions_ok = 0; | |
5818 | } | |
5819 | ||
5820 | if (TREE_CODE (decl) == VAR_DECL | |
5821 | && current_binding_level != global_binding_level | |
5822 | && ! TREE_STATIC (decl) | |
5823 | && type_needs_gc_entry (type)) | |
5824 | DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index); | |
5825 | ||
5826 | if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) | |
5827 | make_decl_rtl (decl, NULL_PTR, toplev); | |
5828 | else if (TREE_CODE (decl) == VAR_DECL | |
5829 | && TREE_READONLY (decl) | |
5830 | && DECL_INITIAL (decl) != NULL_TREE | |
5831 | && DECL_INITIAL (decl) != error_mark_node | |
5832 | && DECL_INITIAL (decl) != empty_init_node) | |
5833 | { | |
5834 | DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); | |
5835 | ||
5836 | if (asmspec) | |
5837 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
5838 | ||
5839 | if (! toplev | |
5840 | && TREE_STATIC (decl) | |
5841 | && ! TREE_SIDE_EFFECTS (decl) | |
5842 | && ! TREE_PUBLIC (decl) | |
5843 | && ! DECL_EXTERNAL (decl) | |
5844 | && ! TYPE_NEEDS_DESTRUCTOR (type) | |
5845 | && DECL_MODE (decl) != BLKmode) | |
5846 | { | |
5847 | /* If this variable is really a constant, then fill its DECL_RTL | |
5848 | slot with something which won't take up storage. | |
5849 | If something later should take its address, we can always give | |
5850 | it legitimate RTL at that time. */ | |
5851 | DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); | |
5852 | store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0); | |
5853 | TREE_ASM_WRITTEN (decl) = 1; | |
5854 | } | |
5855 | else if (toplev) | |
5856 | { | |
5857 | /* Keep GCC from complaining that this variable | |
5858 | is defined but never used. */ | |
5859 | TREE_USED (decl) = 1; | |
5860 | /* If this is a static const, change its apparent linkage | |
5861 | if it belongs to a #pragma interface. */ | |
5862 | if (TREE_STATIC (decl) && !interface_unknown) | |
5863 | { | |
5864 | TREE_PUBLIC (decl) = 1; | |
5865 | DECL_EXTERNAL (decl) = interface_only; | |
5866 | } | |
5867 | make_decl_rtl (decl, asmspec, toplev); | |
5868 | } | |
5869 | else | |
5870 | rest_of_decl_compilation (decl, asmspec, toplev, 0); | |
5871 | } | |
5872 | else if (TREE_CODE (decl) == VAR_DECL | |
5873 | && DECL_LANG_SPECIFIC (decl) | |
5874 | && DECL_IN_AGGR_P (decl)) | |
5875 | { | |
5876 | if (TREE_STATIC (decl)) | |
5877 | if (init == NULL_TREE | |
5878 | #ifdef DEFAULT_STATIC_DEFS | |
5879 | /* If this code is dead, then users must | |
5880 | explicitly declare static member variables | |
5881 | outside the class def'n as well. */ | |
5882 | && TYPE_NEEDS_CONSTRUCTING (type) | |
5883 | #endif | |
5884 | ) | |
5885 | { | |
5886 | DECL_EXTERNAL (decl) = 1; | |
5887 | make_decl_rtl (decl, asmspec, 1); | |
5888 | } | |
5889 | else | |
5890 | rest_of_decl_compilation (decl, asmspec, toplev, 0); | |
5891 | else | |
5892 | /* Just a constant field. Should not need any rtl. */ | |
5893 | goto finish_end0; | |
5894 | } | |
5895 | else | |
5896 | rest_of_decl_compilation (decl, asmspec, toplev, 0); | |
5897 | ||
5898 | if (was_temp) | |
5899 | resume_temporary_allocation (); | |
5900 | ||
5901 | if (type != error_mark_node | |
5902 | && TYPE_LANG_SPECIFIC (type) | |
5903 | && CLASSTYPE_ABSTRACT_VIRTUALS (type)) | |
5904 | abstract_virtuals_error (decl, type); | |
5905 | else if ((TREE_CODE (type) == FUNCTION_TYPE | |
5906 | || TREE_CODE (type) == METHOD_TYPE) | |
5907 | && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) | |
5908 | && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type))) | |
5909 | abstract_virtuals_error (decl, TREE_TYPE (type)); | |
5910 | ||
5911 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
5912 | { | |
5913 | /* C++: Handle overloaded functions with default parameters. */ | |
5914 | if (DECL_OVERLOADED (decl)) | |
5915 | { | |
5916 | tree parmtypes = TYPE_ARG_TYPES (type); | |
5917 | tree prev = NULL_TREE; | |
5918 | tree original_name = DECL_NAME (decl); | |
5919 | struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl); | |
5920 | /* All variants will share an uncollectible lang_decl. */ | |
5921 | copy_decl_lang_specific (decl); | |
5922 | ||
5923 | while (parmtypes && parmtypes != void_list_node) | |
5924 | { | |
5925 | if (TREE_PURPOSE (parmtypes)) | |
5926 | { | |
5927 | tree fnname, fndecl; | |
5928 | tree *argp = prev | |
5929 | ? & TREE_CHAIN (prev) | |
5930 | : & TYPE_ARG_TYPES (type); | |
5931 | ||
5932 | *argp = NULL_TREE; | |
5933 | fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0); | |
5934 | *argp = parmtypes; | |
5935 | fndecl = build_decl (FUNCTION_DECL, fnname, type); | |
5936 | DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl); | |
5937 | TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl); | |
5938 | DECL_INLINE (fndecl) = DECL_INLINE (decl); | |
5939 | /* Keep G++ from thinking this function is unused. | |
5940 | It is only used to speed up search in name space. */ | |
5941 | TREE_USED (fndecl) = 1; | |
5942 | TREE_ASM_WRITTEN (fndecl) = 1; | |
5943 | DECL_INITIAL (fndecl) = NULL_TREE; | |
5944 | DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl); | |
5945 | fndecl = pushdecl (fndecl); | |
5946 | DECL_INITIAL (fndecl) = error_mark_node; | |
5947 | DECL_RTL (fndecl) = DECL_RTL (decl); | |
5948 | } | |
5949 | prev = parmtypes; | |
5950 | parmtypes = TREE_CHAIN (parmtypes); | |
5951 | } | |
5952 | DECL_LANG_SPECIFIC (decl) = tmp_lang_decl; | |
5953 | } | |
5954 | } | |
5955 | else if (DECL_EXTERNAL (decl)) | |
5956 | ; | |
5957 | else if (TREE_STATIC (decl) && type != error_mark_node) | |
5958 | { | |
5959 | /* Cleanups for static variables are handled by `finish_file'. */ | |
5960 | if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE) | |
5961 | expand_static_init (decl, init); | |
5962 | else if (TYPE_NEEDS_DESTRUCTOR (type)) | |
5963 | static_aggregates = perm_tree_cons (NULL_TREE, decl, | |
5964 | static_aggregates); | |
5965 | ||
5966 | /* Make entry in appropriate vector. */ | |
5967 | if (flag_gc && type_needs_gc_entry (type)) | |
5968 | build_static_gc_entry (decl, type); | |
5969 | } | |
5970 | else if (current_binding_level != global_binding_level) | |
5971 | { | |
5972 | /* This is a declared decl which must live until the | |
5973 | end of the binding contour. It may need a cleanup. */ | |
5974 | ||
5975 | /* Recompute the RTL of a local array now | |
5976 | if it used to be an incomplete type. */ | |
5977 | if (was_incomplete && ! TREE_STATIC (decl)) | |
5978 | { | |
5979 | /* If we used it already as memory, it must stay in memory. */ | |
5980 | TREE_ADDRESSABLE (decl) = TREE_USED (decl); | |
5981 | /* If it's still incomplete now, no init will save it. */ | |
5982 | if (DECL_SIZE (decl) == NULL_TREE) | |
5983 | DECL_INITIAL (decl) = NULL_TREE; | |
5984 | expand_decl (decl); | |
5985 | } | |
5986 | else if (! TREE_ASM_WRITTEN (decl) | |
5987 | && (TYPE_SIZE (type) != NULL_TREE | |
5988 | || TREE_CODE (type) == ARRAY_TYPE)) | |
5989 | { | |
5990 | /* Do this here, because we did not expand this decl's | |
5991 | rtl in start_decl. */ | |
5992 | if (DECL_RTL (decl) == NULL_RTX) | |
5993 | expand_decl (decl); | |
5994 | else if (cleanup) | |
5995 | { | |
5996 | expand_decl_cleanup (NULL_TREE, cleanup); | |
5997 | /* Cleanup used up here. */ | |
5998 | cleanup = NULL_TREE; | |
5999 | } | |
6000 | } | |
6001 | ||
6002 | if (DECL_SIZE (decl) && type != error_mark_node) | |
6003 | { | |
6004 | /* Compute and store the initial value. */ | |
6005 | expand_decl_init (decl); | |
6006 | ||
6007 | if (init || TYPE_NEEDS_CONSTRUCTING (type)) | |
6008 | { | |
6009 | emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl)); | |
6010 | expand_aggr_init (decl, init, 0); | |
6011 | } | |
6012 | ||
6013 | /* Set this to 0 so we can tell whether an aggregate | |
6014 | which was initialized was ever used. */ | |
6015 | if (TYPE_NEEDS_CONSTRUCTING (type)) | |
6016 | TREE_USED (decl) = 0; | |
6017 | ||
6018 | /* Store the cleanup, if there was one. */ | |
6019 | if (cleanup) | |
6020 | { | |
6021 | if (! expand_decl_cleanup (decl, cleanup)) | |
6022 | error_with_decl (decl, "parser lost in parsing declaration of `%s'"); | |
6023 | } | |
6024 | } | |
6025 | } | |
6026 | finish_end0: | |
6027 | ||
6028 | /* Undo call to `pushclass' that was done in `start_decl' | |
6029 | due to initialization of qualified member variable. | |
6030 | I.e., Foo::x = 10; */ | |
6031 | { | |
6032 | tree context = DECL_CONTEXT (decl); | |
6033 | if (context | |
6034 | && TREE_CODE_CLASS (TREE_CODE (context)) == 't' | |
6035 | && (TREE_CODE (decl) == VAR_DECL | |
6036 | /* We also have a pushclass done that we need to undo here | |
6037 | if we're at top level and declare a method. */ | |
6038 | || (TREE_CODE (decl) == FUNCTION_DECL | |
6039 | /* If size hasn't been set, we're still defining it, | |
6040 | and therefore inside the class body; don't pop | |
6041 | the binding level.. */ | |
6042 | && TYPE_SIZE (context) != NULL_TREE | |
6043 | /* The binding level gets popped elsewhere for a | |
6044 | friend declaration inside another class. */ | |
6045 | && TYPE_IDENTIFIER (context) == current_class_name | |
6046 | ))) | |
6047 | popclass (1); | |
6048 | } | |
6049 | } | |
6050 | ||
6051 | finish_end: | |
6052 | ||
6053 | if (need_pop) | |
6054 | { | |
6055 | /* Resume permanent allocation, if not within a function. */ | |
6056 | /* The corresponding push_obstacks_nochange is in start_decl, | |
6057 | start_method, groktypename, and in grokfield. */ | |
6058 | pop_obstacks (); | |
6059 | } | |
6060 | ||
6061 | if (was_readonly) | |
6062 | TREE_READONLY (decl) = 1; | |
6063 | ||
6064 | if (flag_cadillac) | |
6065 | cadillac_finish_decl (decl); | |
6066 | } | |
6067 | ||
6068 | static void | |
6069 | expand_static_init (decl, init) | |
6070 | tree decl; | |
6071 | tree init; | |
6072 | { | |
6073 | tree oldstatic = value_member (decl, static_aggregates); | |
6074 | if (oldstatic) | |
6075 | { | |
6076 | if (TREE_PURPOSE (oldstatic)) | |
6077 | error_with_decl (decl, "multiple initializations given for `%s'"); | |
6078 | } | |
6079 | else if (current_binding_level != global_binding_level) | |
6080 | { | |
6081 | /* Emit code to perform this initialization but once. */ | |
6082 | tree temp; | |
6083 | ||
6084 | /* Remember this information until end of file. */ | |
6085 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
6086 | ||
6087 | /* Emit code to perform this initialization but once. */ | |
6088 | temp = get_temp_name (integer_type_node, 1); | |
6089 | rest_of_decl_compilation (temp, NULL_PTR, 0, 0); | |
6090 | expand_start_cond (build_binary_op (EQ_EXPR, temp, | |
6091 | integer_zero_node, 1), 0); | |
6092 | expand_assignment (temp, integer_one_node, 0, 0); | |
6093 | if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) | |
6094 | { | |
6095 | expand_aggr_init (decl, init, 0); | |
6096 | do_pending_stack_adjust (); | |
6097 | } | |
6098 | else | |
6099 | expand_assignment (decl, init, 0, 0); | |
6100 | expand_end_cond (); | |
6101 | if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) | |
6102 | { | |
6103 | static_aggregates = perm_tree_cons (temp, decl, static_aggregates); | |
6104 | TREE_STATIC (static_aggregates) = 1; | |
6105 | } | |
6106 | ||
6107 | /* Resume old (possibly temporary) allocation. */ | |
6108 | pop_obstacks (); | |
6109 | } | |
6110 | else | |
6111 | { | |
6112 | /* This code takes into account memory allocation | |
6113 | policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING | |
6114 | does not hold for this object, then we must make permanent | |
6115 | the storage currently in the temporary obstack. */ | |
6116 | if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) | |
6117 | preserve_initializer (); | |
6118 | static_aggregates = perm_tree_cons (init, decl, static_aggregates); | |
6119 | } | |
6120 | } | |
6121 | \f | |
6122 | /* Make TYPE a complete type based on INITIAL_VALUE. | |
6123 | Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, | |
6124 | 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ | |
6125 | ||
6126 | int | |
6127 | complete_array_type (type, initial_value, do_default) | |
6128 | tree type, initial_value; | |
6129 | int do_default; | |
6130 | { | |
6131 | register tree maxindex = NULL_TREE; | |
6132 | int value = 0; | |
6133 | ||
6134 | if (initial_value) | |
6135 | { | |
6136 | /* Note MAXINDEX is really the maximum index, | |
6137 | one less than the size. */ | |
6138 | if (TREE_CODE (initial_value) == STRING_CST) | |
6139 | maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0); | |
6140 | else if (TREE_CODE (initial_value) == CONSTRUCTOR) | |
6141 | { | |
6142 | register int nelts | |
6143 | = list_length (CONSTRUCTOR_ELTS (initial_value)); | |
6144 | maxindex = build_int_2 (nelts - 1, 0); | |
6145 | } | |
6146 | else | |
6147 | { | |
6148 | /* Make an error message unless that happened already. */ | |
6149 | if (initial_value != error_mark_node) | |
6150 | value = 1; | |
6151 | ||
6152 | /* Prevent further error messages. */ | |
6153 | maxindex = build_int_2 (1, 0); | |
6154 | } | |
6155 | } | |
6156 | ||
6157 | if (!maxindex) | |
6158 | { | |
6159 | if (do_default) | |
6160 | maxindex = build_int_2 (1, 0); | |
6161 | value = 2; | |
6162 | } | |
6163 | ||
6164 | if (maxindex) | |
6165 | { | |
6166 | TYPE_DOMAIN (type) = build_index_type (maxindex); | |
6167 | if (!TREE_TYPE (maxindex)) | |
6168 | TREE_TYPE (maxindex) = TYPE_DOMAIN (type); | |
6169 | } | |
6170 | ||
6171 | /* Lay out the type now that we can get the real answer. */ | |
6172 | ||
6173 | layout_type (type); | |
6174 | ||
6175 | return value; | |
6176 | } | |
6177 | \f | |
6178 | /* Return zero if something is declared to be a member of type | |
6179 | CTYPE when in the context of CUR_TYPE. STRING is the error | |
6180 | message to print in that case. Otherwise, quietly return 1. */ | |
6181 | static int | |
6182 | member_function_or_else (ctype, cur_type, string) | |
6183 | tree ctype, cur_type; | |
6184 | char *string; | |
6185 | { | |
6186 | if (ctype && ctype != cur_type) | |
6187 | { | |
6188 | error (string, TYPE_NAME_STRING (ctype)); | |
6189 | return 0; | |
6190 | } | |
6191 | return 1; | |
6192 | } | |
6193 | \f | |
6194 | /* Subroutine of `grokdeclarator'. */ | |
6195 | ||
6196 | /* CTYPE is class type, or null if non-class. | |
6197 | TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE | |
6198 | or METHOD_TYPE. | |
6199 | DECLARATOR is the function's name. | |
6200 | VIRTUALP is truthvalue of whether the function is virtual or not. | |
6201 | FLAGS are to be passed through to `grokclassfn'. | |
6202 | QUALS are qualifiers indicating whether the function is `const' | |
6203 | or `volatile'. | |
6204 | RAISES is a list of exceptions that this function can raise. | |
6205 | CHECK is 1 if we must find this method in CTYPE, 0 if we should | |
6206 | not look, and -1 if we should not call `grokclassfn' at all. */ | |
6207 | static tree | |
6208 | grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, check, publicp) | |
6209 | tree ctype, type; | |
6210 | tree declarator; | |
6211 | int virtualp; | |
6212 | enum overload_flags flags; | |
6213 | tree quals, raises; | |
6214 | int check, publicp; | |
6215 | { | |
6216 | tree cname, decl; | |
6217 | int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; | |
6218 | ||
6219 | if (ctype) | |
6220 | cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL | |
6221 | ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype); | |
6222 | else | |
6223 | cname = NULL_TREE; | |
6224 | ||
6225 | if (raises) | |
6226 | { | |
6227 | type = build_exception_variant (ctype, type, raises); | |
6228 | raises = TYPE_RAISES_EXCEPTIONS (type); | |
6229 | } | |
6230 | decl = build_lang_decl (FUNCTION_DECL, declarator, type); | |
6231 | /* propagate volatile out from type to decl */ | |
6232 | if (TYPE_VOLATILE (type)) | |
6233 | TREE_THIS_VOLATILE (decl) = 1; | |
6234 | ||
6235 | /* Should probably propagate const out from type to decl I bet (mrs). */ | |
6236 | if (staticp) | |
6237 | { | |
6238 | DECL_STATIC_FUNCTION_P (decl) = 1; | |
6239 | DECL_CONTEXT (decl) = ctype; | |
6240 | DECL_CLASS_CONTEXT (decl) = ctype; | |
6241 | } | |
6242 | ||
6243 | if (publicp) | |
6244 | TREE_PUBLIC (decl) = 1; | |
6245 | ||
6246 | DECL_EXTERNAL (decl) = 1; | |
6247 | if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) | |
6248 | { | |
6249 | error ("functions cannot have method qualifiers"); | |
6250 | quals = NULL_TREE; | |
6251 | } | |
6252 | ||
6253 | /* Only two styles of delete's are valid. */ | |
6254 | if (declarator == ansi_opname[(int) DELETE_EXPR]) | |
6255 | { | |
6256 | tree args = TYPE_ARG_TYPES (type); | |
6257 | int style1, style2; | |
6258 | ||
6259 | if (ctype && args && TREE_CODE (type) == METHOD_TYPE) | |
6260 | /* remove this */ | |
6261 | args = TREE_CHAIN (args); | |
6262 | ||
6263 | style1 = type_list_equal (args, | |
6264 | tree_cons (NULL_TREE, ptr_type_node, | |
6265 | void_list_node)); | |
6266 | style2 = style1 != 0 ? 0 : | |
6267 | type_list_equal (args, | |
6268 | tree_cons (NULL_TREE, ptr_type_node, | |
6269 | tree_cons (NULL_TREE, sizetype, | |
6270 | void_list_node))); | |
6271 | ||
6272 | if (ctype == NULL_TREE) | |
6273 | { | |
6274 | if (! style1) | |
6275 | /* ANSI C++ June 5 1992 WP 12.5.5.2 */ | |
6276 | error ("global operator delete must be declared as taking a single argument of type void*"); | |
6277 | } | |
6278 | else | |
6279 | if (! style1 && ! style2) | |
6280 | /* ANSI C++ June 5 1992 WP 12.5.4.1 */ | |
6281 | error ("operator delete cannot be overloaded"); | |
6282 | } | |
6283 | else if (DECL_NAME (decl) == ansi_opname[(int) POSTINCREMENT_EXPR] | |
6284 | || DECL_NAME (decl) == ansi_opname[(int) POSTDECREMENT_EXPR]) | |
6285 | { | |
6286 | /* According to ARM $13.4.7, postfix operator++ must take an int as | |
6287 | its second argument. */ | |
6288 | tree parmtypes, argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
6289 | ||
6290 | if (argtypes) | |
6291 | { | |
6292 | parmtypes = TREE_CHAIN (argtypes); | |
6293 | if (parmtypes != NULL_TREE | |
6294 | && TREE_VALUE (parmtypes) != void_type_node | |
6295 | && TREE_VALUE (parmtypes) != integer_type_node) | |
6296 | error ("postfix operator%s may only take `int' as its argument", | |
6297 | POSTINCREMENT_EXPR ? "++" : "--"); | |
6298 | } | |
6299 | } | |
6300 | ||
6301 | /* Caller will do the rest of this. */ | |
6302 | if (check < 0) | |
6303 | return decl; | |
6304 | ||
6305 | if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) | |
6306 | { | |
6307 | tree tmp; | |
6308 | /* Just handle constructors here. We could do this | |
6309 | inside the following if stmt, but I think | |
6310 | that the code is more legible by breaking this | |
6311 | case out. See comments below for what each of | |
6312 | the following calls is supposed to do. */ | |
6313 | DECL_CONSTRUCTOR_P (decl) = 1; | |
6314 | ||
6315 | grokclassfn (ctype, declarator, decl, flags, quals); | |
6316 | if (check) | |
6317 | check_classfn (ctype, declarator, decl); | |
6318 | grok_ctor_properties (ctype, decl); | |
6319 | if (check == 0) | |
6320 | { | |
6321 | /* FIXME: this should only need to look at IDENTIFIER_GLOBAL_VALUE. */ | |
6322 | tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); | |
6323 | if (tmp == NULL_TREE) | |
6324 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; | |
6325 | else if (TREE_CODE (tmp) != TREE_CODE (decl)) | |
6326 | error_with_decl (decl, "inconsistent declarations for `%s'"); | |
6327 | else | |
6328 | { | |
6329 | duplicate_decls (decl, tmp); | |
6330 | decl = tmp; | |
6331 | /* avoid creating circularities. */ | |
6332 | DECL_CHAIN (decl) = NULL_TREE; | |
6333 | } | |
6334 | make_decl_rtl (decl, NULL_PTR, 1); | |
6335 | } | |
6336 | } | |
6337 | else | |
6338 | { | |
6339 | tree tmp; | |
6340 | ||
6341 | /* Function gets the ugly name, field gets the nice one. | |
6342 | This call may change the type of the function (because | |
6343 | of default parameters)! */ | |
6344 | if (ctype != NULL_TREE) | |
6345 | grokclassfn (ctype, cname, decl, flags, quals); | |
6346 | ||
6347 | if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) | |
6348 | grok_op_properties (decl, virtualp); | |
6349 | ||
6350 | if (ctype != NULL_TREE && check) | |
6351 | check_classfn (ctype, cname, decl); | |
6352 | ||
6353 | if (ctype == NULL_TREE || check) | |
6354 | return decl; | |
6355 | ||
6356 | /* Now install the declaration of this function so that | |
6357 | others may find it (esp. its DECL_FRIENDLIST). | |
6358 | Pretend we are at top level, we will get true | |
6359 | reference later, perhaps. | |
6360 | ||
6361 | FIXME: This should only need to look at IDENTIFIER_GLOBAL_VALUE. */ | |
6362 | tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); | |
6363 | if (tmp == NULL_TREE) | |
6364 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; | |
6365 | else if (TREE_CODE (tmp) != TREE_CODE (decl)) | |
6366 | error_with_decl (decl, "inconsistent declarations for `%s'"); | |
6367 | else | |
6368 | { | |
6369 | duplicate_decls (decl, tmp); | |
6370 | decl = tmp; | |
6371 | /* avoid creating circularities. */ | |
6372 | DECL_CHAIN (decl) = NULL_TREE; | |
6373 | } | |
6374 | make_decl_rtl (decl, NULL_PTR, 1); | |
6375 | ||
6376 | /* If this declaration supersedes the declaration of | |
6377 | a method declared virtual in the base class, then | |
6378 | mark this field as being virtual as well. */ | |
6379 | { | |
6380 | tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype)); | |
6381 | int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; | |
6382 | ||
6383 | for (i = 0; i < n_baselinks; i++) | |
6384 | { | |
6385 | tree base_binfo = TREE_VEC_ELT (binfos, i); | |
6386 | if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)) || flag_all_virtual == 1) | |
6387 | { | |
6388 | tmp = get_first_matching_virtual (base_binfo, decl, | |
6389 | flags == DTOR_FLAG); | |
6390 | if (tmp) | |
6391 | { | |
6392 | /* The TMP we really want is the one from the deepest | |
6393 | baseclass on this path, taking care not to | |
6394 | duplicate if we have already found it (via another | |
6395 | path to its virtual baseclass. */ | |
6396 | if (staticp) | |
6397 | { | |
6398 | error_with_decl (decl, "method `%s' may not be declared static"); | |
6399 | error_with_decl (tmp, "(since `%s' declared virtual in base class.)"); | |
6400 | break; | |
6401 | } | |
6402 | virtualp = 1; | |
6403 | ||
6404 | if ((TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (base_binfo)) | |
6405 | || TYPE_USES_MULTIPLE_INHERITANCE (ctype)) | |
6406 | && BINFO_TYPE (base_binfo) != DECL_CONTEXT (tmp)) | |
6407 | tmp = get_first_matching_virtual (TYPE_BINFO (DECL_CONTEXT (tmp)), | |
6408 | decl, flags == DTOR_FLAG); | |
6409 | if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE) | |
6410 | { | |
6411 | /* The argument types may have changed... */ | |
6412 | tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
6413 | tree base_variant = TREE_TYPE (TREE_VALUE (argtypes)); | |
6414 | ||
6415 | argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))), | |
6416 | TREE_CHAIN (argtypes)); | |
6417 | /* But the return type has not. */ | |
6418 | type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes); | |
6419 | if (raises) | |
6420 | { | |
6421 | type = build_exception_variant (ctype, type, raises); | |
6422 | raises = TYPE_RAISES_EXCEPTIONS (type); | |
6423 | } | |
6424 | TREE_TYPE (decl) = type; | |
6425 | DECL_VINDEX (decl) | |
6426 | = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl)); | |
6427 | } | |
6428 | } | |
6429 | } | |
6430 | } | |
6431 | } | |
6432 | if (virtualp) | |
6433 | { | |
6434 | if (DECL_VINDEX (decl) == NULL_TREE) | |
6435 | DECL_VINDEX (decl) = error_mark_node; | |
6436 | IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; | |
6437 | if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) | |
6438 | /* If this function is derived from a template, don't | |
6439 | make it public. This shouldn't be here, but there's | |
6440 | no good way to override the interface pragmas for one | |
6441 | function or class only. Bletch. */ | |
6442 | && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE | |
6443 | && (write_virtuals == 2 | |
6444 | || (write_virtuals == 3 | |
6445 | && ! CLASSTYPE_INTERFACE_UNKNOWN (ctype)))) | |
6446 | TREE_PUBLIC (decl) = 1; | |
6447 | } | |
6448 | } | |
6449 | return decl; | |
6450 | } | |
6451 | ||
6452 | static tree | |
6453 | grokvardecl (type, declarator, specbits, initialized) | |
6454 | tree type; | |
6455 | tree declarator; | |
6456 | RID_BIT_TYPE specbits; | |
6457 | int initialized; | |
6458 | { | |
6459 | tree decl; | |
6460 | ||
6461 | /* This implements the "one definition rule" for global variables. | |
6462 | Note that declarator can come in as null when we're doing work | |
6463 | on an anonymous union. */ | |
6464 | if (declarator && IDENTIFIER_GLOBAL_VALUE (declarator) | |
6465 | && current_binding_level == global_binding_level | |
6466 | && TREE_STATIC (IDENTIFIER_GLOBAL_VALUE (declarator)) | |
6467 | && (! (specbits & RIDBIT (RID_EXTERN)) | |
6468 | || initialized)) | |
6469 | { | |
6470 | error ("redefinition of `%s'", IDENTIFIER_POINTER (declarator)); | |
6471 | error_with_decl (IDENTIFIER_GLOBAL_VALUE (declarator), | |
6472 | "previously defined here"); | |
6473 | } | |
6474 | ||
6475 | if (TREE_CODE (type) == OFFSET_TYPE) | |
6476 | { | |
6477 | /* If you declare a static member so that it | |
6478 | can be initialized, the code will reach here. */ | |
6479 | tree field = lookup_field (TYPE_OFFSET_BASETYPE (type), | |
6480 | declarator, 0, 0); | |
6481 | if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) | |
6482 | { | |
6483 | tree basetype = TYPE_OFFSET_BASETYPE (type); | |
6484 | error ("`%s' is not a static member of class `%s'", | |
6485 | IDENTIFIER_POINTER (declarator), | |
6486 | TYPE_NAME_STRING (basetype)); | |
6487 | type = TREE_TYPE (type); | |
6488 | decl = build_lang_field_decl (VAR_DECL, declarator, type); | |
6489 | DECL_CONTEXT (decl) = basetype; | |
6490 | DECL_CLASS_CONTEXT (decl) = basetype; | |
6491 | } | |
6492 | else | |
6493 | { | |
6494 | tree f_type = TREE_TYPE (field); | |
6495 | tree o_type = TREE_TYPE (type); | |
6496 | ||
6497 | if (TYPE_SIZE (f_type) == NULL_TREE) | |
6498 | { | |
6499 | if (TREE_CODE (f_type) != TREE_CODE (o_type) | |
6500 | || (TREE_CODE (f_type) == ARRAY_TYPE | |
6501 | && TREE_TYPE (f_type) != TREE_TYPE (o_type))) | |
6502 | error ("redeclaration of type for `%s'", | |
6503 | IDENTIFIER_POINTER (declarator)); | |
6504 | else if (TYPE_SIZE (o_type) != NULL_TREE) | |
6505 | TREE_TYPE (field) = type; | |
6506 | } | |
6507 | else if (f_type != o_type) | |
6508 | error ("redeclaration of type for `%s'", | |
6509 | IDENTIFIER_POINTER (declarator)); | |
6510 | decl = field; | |
6511 | if (initialized && DECL_INITIAL (decl) | |
6512 | /* Complain about multiply-initialized | |
6513 | member variables, but don't be faked | |
6514 | out if initializer is faked up from `empty_init_node'. */ | |
6515 | && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR | |
6516 | || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE)) | |
6517 | error_with_aggr_type (DECL_CONTEXT (decl), | |
6518 | "multiple initializations of static member `%s::%s'", | |
6519 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
6520 | } | |
6521 | } | |
6522 | else decl = build_decl (VAR_DECL, declarator, type); | |
6523 | ||
6524 | if (specbits & RIDBIT (RID_EXTERN)) | |
6525 | { | |
6526 | DECL_THIS_EXTERN (decl) = 1; | |
6527 | DECL_EXTERNAL (decl) = !initialized; | |
6528 | } | |
6529 | ||
6530 | /* In class context, static means one per class, | |
6531 | public visibility, and static storage. */ | |
6532 | if (DECL_FIELD_CONTEXT (decl) != NULL_TREE | |
6533 | && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl))) | |
6534 | { | |
6535 | TREE_PUBLIC (decl) = 1; | |
6536 | TREE_STATIC (decl) = 1; | |
6537 | DECL_EXTERNAL (decl) = !initialized; | |
6538 | } | |
6539 | /* At top level, either `static' or no s.c. makes a definition | |
6540 | (perhaps tentative), and absence of `static' makes it public. */ | |
6541 | else if (current_binding_level == global_binding_level) | |
6542 | { | |
6543 | TREE_PUBLIC (decl) = ! (specbits & RIDBIT (RID_STATIC)); | |
6544 | TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); | |
6545 | } | |
6546 | /* Not at top level, only `static' makes a static definition. */ | |
6547 | else | |
6548 | { | |
6549 | TREE_STATIC (decl) = !! (specbits & RIDBIT (RID_STATIC)); | |
6550 | TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); | |
6551 | } | |
6552 | return decl; | |
6553 | } | |
6554 | ||
6555 | /* Given declspecs and a declarator, | |
6556 | determine the name and type of the object declared | |
6557 | and construct a ..._DECL node for it. | |
6558 | (In one case we can return a ..._TYPE node instead. | |
6559 | For invalid input we sometimes return 0.) | |
6560 | ||
6561 | DECLSPECS is a chain of tree_list nodes whose value fields | |
6562 | are the storage classes and type specifiers. | |
6563 | ||
6564 | DECL_CONTEXT says which syntactic context this declaration is in: | |
6565 | NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. | |
6566 | FUNCDEF for a function definition. Like NORMAL but a few different | |
6567 | error messages in each case. Return value may be zero meaning | |
6568 | this definition is too screwy to try to parse. | |
6569 | MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to | |
6570 | handle member functions (which have FIELD context). | |
6571 | Return value may be zero meaning this definition is too screwy to | |
6572 | try to parse. | |
6573 | PARM for a parameter declaration (either within a function prototype | |
6574 | or before a function body). Make a PARM_DECL, or return void_type_node. | |
6575 | TYPENAME if for a typename (in a cast or sizeof). | |
6576 | Don't make a DECL node; just return the ..._TYPE node. | |
6577 | FIELD for a struct or union field; make a FIELD_DECL. | |
6578 | BITFIELD for a field with specified width. | |
6579 | INITIALIZED is 1 if the decl has an initializer. | |
6580 | ||
6581 | In the TYPENAME case, DECLARATOR is really an absolute declarator. | |
6582 | It may also be so in the PARM case, for a prototype where the | |
6583 | argument type is specified but not the name. | |
6584 | ||
6585 | This function is where the complicated C meanings of `static' | |
6586 | and `extern' are interpreted. | |
6587 | ||
6588 | For C++, if there is any monkey business to do, the function which | |
6589 | calls this one must do it, i.e., prepending instance variables, | |
6590 | renaming overloaded function names, etc. | |
6591 | ||
6592 | Note that for this C++, it is an error to define a method within a class | |
6593 | which does not belong to that class. | |
6594 | ||
6595 | Except in the case where SCOPE_REFs are implicitly known (such as | |
6596 | methods within a class being redundantly qualified), | |
6597 | declarations which involve SCOPE_REFs are returned as SCOPE_REFs | |
6598 | (class_name::decl_name). The caller must also deal with this. | |
6599 | ||
6600 | If a constructor or destructor is seen, and the context is FIELD, | |
6601 | then the type gains the attribute TREE_HAS_x. If such a declaration | |
6602 | is erroneous, NULL_TREE is returned. | |
6603 | ||
6604 | QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member | |
6605 | function, these are the qualifiers to give to the `this' pointer. | |
6606 | ||
6607 | May return void_type_node if the declarator turned out to be a friend. | |
6608 | See grokfield for details. */ | |
6609 | ||
6610 | enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; | |
6611 | ||
6612 | tree | |
6613 | grokdeclarator (declarator, declspecs, decl_context, initialized, raises) | |
6614 | tree declspecs; | |
6615 | tree declarator; | |
6616 | enum decl_context decl_context; | |
6617 | int initialized; | |
6618 | tree raises; | |
6619 | { | |
6620 | extern int current_class_depth; | |
6621 | ||
6622 | RID_BIT_TYPE specbits = 0; | |
6623 | int nclasses = 0; | |
6624 | tree spec; | |
6625 | tree type = NULL_TREE; | |
6626 | int longlong = 0; | |
6627 | int constp; | |
6628 | int volatilep; | |
6629 | int virtualp, friendp, inlinep, staticp; | |
6630 | int explicit_int = 0; | |
6631 | int explicit_char = 0; | |
6632 | tree typedef_decl = NULL_TREE; | |
6633 | char *name; | |
6634 | tree typedef_type = NULL_TREE; | |
6635 | int funcdef_flag = 0; | |
6636 | enum tree_code innermost_code = ERROR_MARK; | |
6637 | int bitfield = 0; | |
6638 | int size_varies = 0; | |
6639 | /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. | |
6640 | All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ | |
6641 | tree init = NULL_TREE; | |
6642 | ||
6643 | /* Keep track of what sort of function is being processed | |
6644 | so that we can warn about default return values, or explicit | |
6645 | return values which do not match prescribed defaults. */ | |
6646 | enum return_types return_type = return_normal; | |
6647 | ||
6648 | tree dname = NULL_TREE; | |
6649 | tree ctype = current_class_type; | |
6650 | tree ctor_return_type = NULL_TREE; | |
6651 | enum overload_flags flags = NO_SPECIAL; | |
6652 | int seen_scope_ref = 0; | |
6653 | tree quals = NULL_TREE; | |
6654 | ||
6655 | if (decl_context == FUNCDEF) | |
6656 | funcdef_flag = 1, decl_context = NORMAL; | |
6657 | else if (decl_context == MEMFUNCDEF) | |
6658 | funcdef_flag = -1, decl_context = FIELD; | |
6659 | else if (decl_context == BITFIELD) | |
6660 | bitfield = 1, decl_context = FIELD; | |
6661 | ||
6662 | if (flag_traditional && allocation_temporary_p ()) | |
6663 | end_temporary_allocation (); | |
6664 | ||
6665 | /* Look inside a declarator for the name being declared | |
6666 | and get it as a string, for an error message. */ | |
6667 | { | |
6668 | tree type, last = NULL_TREE; | |
6669 | register tree decl = declarator; | |
6670 | name = NULL; | |
6671 | ||
6672 | /* If we see something of the form `aggr_type xyzzy (a, b, c)' | |
6673 | it is either an old-style function declaration or a call to | |
6674 | a constructor. The following conditional makes recognizes this | |
6675 | case as being a call to a constructor. Too bad if it is not. */ | |
6676 | ||
6677 | /* For Doug Lea, also grok `aggr_type xyzzy (a, b, c)[10][10][10]'. */ | |
6678 | while (decl && TREE_CODE (decl) == ARRAY_REF) | |
6679 | { | |
6680 | last = decl; | |
6681 | decl = TREE_OPERAND (decl, 0); | |
6682 | } | |
6683 | ||
6684 | if (decl && declspecs | |
6685 | && TREE_CODE (decl) == CALL_EXPR | |
6686 | && TREE_OPERAND (decl, 0) | |
6687 | && (TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE | |
6688 | || TREE_CODE (TREE_OPERAND (decl, 0)) == SCOPE_REF)) | |
6689 | { | |
6690 | type = TREE_CODE (TREE_VALUE (declspecs)) == IDENTIFIER_NODE | |
6691 | ? lookup_name (TREE_VALUE (declspecs), 1) : | |
6692 | (IS_AGGR_TYPE (TREE_VALUE (declspecs)) | |
6693 | ? TYPE_NAME (TREE_VALUE (declspecs)) : NULL_TREE); | |
6694 | ||
6695 | if (type && TREE_CODE (type) == TYPE_DECL | |
6696 | && IS_AGGR_TYPE (TREE_TYPE (type)) | |
6697 | && parmlist_is_exprlist (TREE_OPERAND (decl, 1))) | |
6698 | { | |
6699 | if (decl_context == FIELD | |
6700 | && TREE_CHAIN (TREE_OPERAND (decl, 1))) | |
6701 | { | |
6702 | /* That was an initializer list. */ | |
6703 | sorry ("initializer lists for field declarations"); | |
6704 | decl = TREE_OPERAND (decl, 0); | |
6705 | if (last) | |
6706 | { | |
6707 | TREE_OPERAND (last, 0) = decl; | |
6708 | decl = declarator; | |
6709 | } | |
6710 | declarator = decl; | |
6711 | init = error_mark_node; | |
6712 | goto bot; | |
6713 | } | |
6714 | else | |
6715 | { | |
6716 | init = TREE_OPERAND (decl, 1); | |
6717 | if (last) | |
6718 | { | |
6719 | TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0); | |
6720 | if (pedantic && init) | |
6721 | { | |
6722 | error ("arrays cannot take initializers"); | |
6723 | init = error_mark_node; | |
6724 | } | |
6725 | } | |
6726 | else | |
6727 | declarator = TREE_OPERAND (declarator, 0); | |
6728 | decl = start_decl (declarator, declspecs, 1, NULL_TREE); | |
6729 | finish_decl (decl, init, NULL_TREE, 1); | |
6730 | return 0; | |
6731 | } | |
6732 | } | |
6733 | ||
6734 | if (parmlist_is_random (TREE_OPERAND (decl, 1))) | |
6735 | { | |
6736 | decl = TREE_OPERAND (decl, 0); | |
6737 | if (TREE_CODE (decl) == SCOPE_REF) | |
6738 | { | |
6739 | if (TREE_COMPLEXITY (decl)) | |
6740 | my_friendly_abort (15); | |
6741 | decl = TREE_OPERAND (decl, 1); | |
6742 | } | |
6743 | if (TREE_CODE (decl) == IDENTIFIER_NODE) | |
6744 | name = IDENTIFIER_POINTER (decl); | |
6745 | if (name) | |
6746 | error ("bad parameter list specification for function `%s'", | |
6747 | name); | |
6748 | else | |
6749 | error ("bad parameter list specification for function"); | |
6750 | return void_type_node; | |
6751 | } | |
6752 | bot: | |
6753 | ; | |
6754 | } | |
6755 | else | |
6756 | /* It didn't look like we thought it would, leave the ARRAY_REFs on. */ | |
6757 | decl = declarator; | |
6758 | ||
6759 | while (decl) | |
6760 | switch (TREE_CODE (decl)) | |
6761 | { | |
6762 | case COND_EXPR: | |
6763 | ctype = NULL_TREE; | |
6764 | decl = TREE_OPERAND (decl, 0); | |
6765 | break; | |
6766 | ||
6767 | case BIT_NOT_EXPR: /* for C++ destructors! */ | |
6768 | { | |
6769 | tree name = TREE_OPERAND (decl, 0); | |
6770 | tree rename = NULL_TREE; | |
6771 | ||
6772 | my_friendly_assert (flags == NO_SPECIAL, 152); | |
6773 | flags = DTOR_FLAG; | |
6774 | return_type = return_dtor; | |
6775 | my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); | |
6776 | if (ctype == NULL_TREE) | |
6777 | { | |
6778 | if (current_class_type == NULL_TREE) | |
6779 | { | |
6780 | error ("destructors must be member functions"); | |
6781 | flags = NO_SPECIAL; | |
6782 | } | |
6783 | else | |
6784 | { | |
6785 | tree t = constructor_name (current_class_name); | |
6786 | if (t != name) | |
6787 | rename = t; | |
6788 | } | |
6789 | } | |
6790 | else | |
6791 | { | |
6792 | tree t = constructor_name (ctype); | |
6793 | if (t != name) | |
6794 | rename = t; | |
6795 | } | |
6796 | ||
6797 | if (rename) | |
6798 | { | |
6799 | error ("destructor `%s' must match class name `%s'", | |
6800 | IDENTIFIER_POINTER (name), | |
6801 | IDENTIFIER_POINTER (rename)); | |
6802 | TREE_OPERAND (decl, 0) = rename; | |
6803 | } | |
6804 | decl = name; | |
6805 | } | |
6806 | break; | |
6807 | ||
6808 | case ADDR_EXPR: /* C++ reference declaration */ | |
6809 | /* fall through */ | |
6810 | case ARRAY_REF: | |
6811 | case INDIRECT_REF: | |
6812 | ctype = NULL_TREE; | |
6813 | innermost_code = TREE_CODE (decl); | |
6814 | decl = TREE_OPERAND (decl, 0); | |
6815 | break; | |
6816 | ||
6817 | case CALL_EXPR: | |
6818 | innermost_code = TREE_CODE (decl); | |
6819 | decl = TREE_OPERAND (decl, 0); | |
6820 | if (decl_context == FIELD && ctype == NULL_TREE) | |
6821 | ctype = current_class_type; | |
6822 | if (ctype != NULL_TREE | |
6823 | && decl != NULL_TREE && flags != DTOR_FLAG | |
6824 | && decl == constructor_name (ctype)) | |
6825 | { | |
6826 | return_type = return_ctor; | |
6827 | ctor_return_type = ctype; | |
6828 | } | |
6829 | ctype = NULL_TREE; | |
6830 | break; | |
6831 | ||
6832 | case IDENTIFIER_NODE: | |
6833 | dname = decl; | |
6834 | name = IDENTIFIER_POINTER (decl); | |
6835 | decl = NULL_TREE; | |
6836 | break; | |
6837 | ||
6838 | case RECORD_TYPE: | |
6839 | case UNION_TYPE: | |
6840 | case ENUMERAL_TYPE: | |
6841 | /* Parse error puts this typespec where | |
6842 | a declarator should go. */ | |
6843 | error ("declarator name missing"); | |
6844 | dname = TYPE_NAME (decl); | |
6845 | if (dname && TREE_CODE (dname) == TYPE_DECL) | |
6846 | dname = DECL_NAME (dname); | |
6847 | name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>"; | |
6848 | declspecs = temp_tree_cons (NULL_TREE, decl, declspecs); | |
6849 | decl = NULL_TREE; | |
6850 | break; | |
6851 | ||
6852 | case TYPE_EXPR: | |
6853 | if (ctype == NULL_TREE) | |
6854 | { | |
6855 | /* ANSI C++ June 5 1992 WP 12.3.2 only describes | |
6856 | conversion functions in terms of being declared | |
6857 | as a member function. */ | |
6858 | error ("operator `%s' must be declared as a member", | |
6859 | IDENTIFIER_POINTER (TREE_VALUE (TREE_TYPE (decl)))); | |
6860 | return NULL_TREE; | |
6861 | } | |
6862 | ||
6863 | ctype = NULL_TREE; | |
6864 | my_friendly_assert (flags == NO_SPECIAL, 154); | |
6865 | flags = TYPENAME_FLAG; | |
6866 | name = "operator <typename>"; | |
6867 | /* Go to the absdcl. */ | |
6868 | decl = TREE_OPERAND (decl, 0); | |
6869 | return_type = return_conversion; | |
6870 | break; | |
6871 | ||
6872 | /* C++ extension */ | |
6873 | case SCOPE_REF: | |
6874 | if (seen_scope_ref == 1) | |
6875 | error ("multiple `::' terms in declarator invalid"); | |
6876 | seen_scope_ref += 1; | |
6877 | { | |
6878 | /* Perform error checking, and convert class names to types. | |
6879 | We may call grokdeclarator multiple times for the same | |
6880 | tree structure, so only do the conversion once. In this | |
6881 | case, we have exactly what we want for `ctype'. */ | |
6882 | tree cname = TREE_OPERAND (decl, 0); | |
6883 | if (cname == NULL_TREE) | |
6884 | ctype = NULL_TREE; | |
6885 | /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */ | |
6886 | else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname)) | |
6887 | || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE) | |
6888 | ctype = cname; | |
6889 | else if (! is_aggr_typedef (cname, 1)) | |
6890 | { | |
6891 | TREE_OPERAND (decl, 0) = NULL_TREE; | |
6892 | } | |
6893 | /* Must test TREE_OPERAND (decl, 1), in case user gives | |
6894 | us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ | |
6895 | else if (TREE_OPERAND (decl, 1) | |
6896 | && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) | |
6897 | { | |
6898 | TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname); | |
6899 | } | |
6900 | else if (ctype == NULL_TREE) | |
6901 | { | |
6902 | ctype = IDENTIFIER_TYPE_VALUE (cname); | |
6903 | TREE_OPERAND (decl, 0) = ctype; | |
6904 | } | |
6905 | else if (TREE_COMPLEXITY (decl) == current_class_depth) | |
6906 | TREE_OPERAND (decl, 0) = ctype; | |
6907 | else | |
6908 | { | |
6909 | if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname), ctype)) | |
6910 | { | |
6911 | error ("type `%s' is not derived from type `%s'", | |
6912 | IDENTIFIER_POINTER (cname), | |
6913 | TYPE_NAME_STRING (ctype)); | |
6914 | TREE_OPERAND (decl, 0) = NULL_TREE; | |
6915 | } | |
6916 | else | |
6917 | { | |
6918 | ctype = IDENTIFIER_TYPE_VALUE (cname); | |
6919 | TREE_OPERAND (decl, 0) = ctype; | |
6920 | } | |
6921 | } | |
6922 | ||
6923 | decl = TREE_OPERAND (decl, 1); | |
6924 | if (ctype) | |
6925 | { | |
6926 | if (TREE_CODE (decl) == IDENTIFIER_NODE | |
6927 | && constructor_name (ctype) == decl) | |
6928 | { | |
6929 | return_type = return_ctor; | |
6930 | ctor_return_type = ctype; | |
6931 | } | |
6932 | else if (TREE_CODE (decl) == BIT_NOT_EXPR | |
6933 | && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE | |
6934 | && constructor_name (ctype) == TREE_OPERAND (decl, 0)) | |
6935 | { | |
6936 | return_type = return_dtor; | |
6937 | ctor_return_type = ctype; | |
6938 | flags = DTOR_FLAG; | |
6939 | decl = TREE_OPERAND (decl, 0); | |
6940 | } | |
6941 | } | |
6942 | } | |
6943 | break; | |
6944 | ||
6945 | case ERROR_MARK: | |
6946 | decl = NULL_TREE; | |
6947 | break; | |
6948 | ||
6949 | default: | |
6950 | my_friendly_abort (155); | |
6951 | } | |
6952 | if (name == NULL) | |
6953 | name = "type name"; | |
6954 | } | |
6955 | ||
6956 | /* A function definition's declarator must have the form of | |
6957 | a function declarator. */ | |
6958 | ||
6959 | if (funcdef_flag && innermost_code != CALL_EXPR) | |
6960 | return 0; | |
6961 | ||
6962 | /* Anything declared one level down from the top level | |
6963 | must be one of the parameters of a function | |
6964 | (because the body is at least two levels down). */ | |
6965 | ||
6966 | /* This heuristic cannot be applied to C++ nodes! Fixed, however, | |
6967 | by not allowing C++ class definitions to specify their parameters | |
6968 | with xdecls (must be spec.d in the parmlist). | |
6969 | ||
6970 | Since we now wait to push a class scope until we are sure that | |
6971 | we are in a legitimate method context, we must set oldcname | |
6972 | explicitly (since current_class_name is not yet alive). */ | |
6973 | ||
6974 | if (decl_context == NORMAL | |
6975 | && current_binding_level->level_chain == global_binding_level) | |
6976 | decl_context = PARM; | |
6977 | ||
6978 | /* Look through the decl specs and record which ones appear. | |
6979 | Some typespecs are defined as built-in typenames. | |
6980 | Others, the ones that are modifiers of other types, | |
6981 | are represented by bits in SPECBITS: set the bits for | |
6982 | the modifiers that appear. Storage class keywords are also in SPECBITS. | |
6983 | ||
6984 | If there is a typedef name or a type, store the type in TYPE. | |
6985 | This includes builtin typedefs such as `int'. | |
6986 | ||
6987 | Set EXPLICIT_INT if the type is `int' or `char' and did not | |
6988 | come from a user typedef. | |
6989 | ||
6990 | Set LONGLONG if `long' is mentioned twice. | |
6991 | ||
6992 | For C++, constructors and destructors have their own fast treatment. */ | |
6993 | ||
6994 | for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) | |
6995 | { | |
6996 | register int i; | |
6997 | register tree id = TREE_VALUE (spec); | |
6998 | ||
6999 | /* Certain parse errors slip through. For example, | |
7000 | `int class;' is not caught by the parser. Try | |
7001 | weakly to recover here. */ | |
7002 | if (TREE_CODE (spec) != TREE_LIST) | |
7003 | return 0; | |
7004 | ||
7005 | if (TREE_CODE (id) == IDENTIFIER_NODE) | |
7006 | { | |
7007 | if (id == ridpointers[(int) RID_INT]) | |
7008 | { | |
7009 | if (type) | |
7010 | error ("extraneous `int' ignored"); | |
7011 | else | |
7012 | { | |
7013 | explicit_int = 1; | |
7014 | type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); | |
7015 | } | |
7016 | goto found; | |
7017 | } | |
7018 | if (id == ridpointers[(int) RID_CHAR]) | |
7019 | { | |
7020 | if (type) | |
7021 | error ("extraneous `char' ignored"); | |
7022 | else | |
7023 | { | |
7024 | explicit_char = 1; | |
7025 | type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); | |
7026 | } | |
7027 | goto found; | |
7028 | } | |
7029 | if (id == ridpointers[(int) RID_WCHAR]) | |
7030 | { | |
7031 | if (type) | |
7032 | error ("extraneous `__wchar_t' ignored"); | |
7033 | else | |
7034 | { | |
7035 | type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); | |
7036 | } | |
7037 | goto found; | |
7038 | } | |
7039 | /* C++ aggregate types. */ | |
7040 | if (IDENTIFIER_HAS_TYPE_VALUE (id)) | |
7041 | { | |
7042 | if (type) | |
7043 | error ("multiple declarations `%s' and `%s'", | |
7044 | IDENTIFIER_POINTER (type), | |
7045 | IDENTIFIER_POINTER (id)); | |
7046 | else | |
7047 | type = IDENTIFIER_TYPE_VALUE (id); | |
7048 | goto found; | |
7049 | } | |
7050 | ||
7051 | for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++) | |
7052 | { | |
7053 | if (ridpointers[i] == id) | |
7054 | { | |
7055 | if (i == (int) RID_LONG && (specbits & RIDBIT (i))) | |
7056 | { | |
7057 | if (pedantic) | |
7058 | pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); | |
7059 | else if (longlong) | |
7060 | error ("`long long long' is too long for GCC"); | |
7061 | else | |
7062 | longlong = 1; | |
7063 | } | |
7064 | else if (specbits & RIDBIT (i)) | |
7065 | warning ("duplicate `%s'", IDENTIFIER_POINTER (id)); | |
7066 | specbits |= RIDBIT (i); | |
7067 | goto found; | |
7068 | } | |
7069 | } | |
7070 | } | |
7071 | if (type) | |
7072 | error ("two or more data types in declaration of `%s'", name); | |
7073 | else if (TREE_CODE (id) == IDENTIFIER_NODE) | |
7074 | { | |
7075 | register tree t = lookup_name (id, 1); | |
7076 | if (!t || TREE_CODE (t) != TYPE_DECL) | |
7077 | error ("`%s' fails to be a typedef or built in type", | |
7078 | IDENTIFIER_POINTER (id)); | |
7079 | else | |
7080 | { | |
7081 | type = TREE_TYPE (t); | |
7082 | typedef_decl = t; | |
7083 | } | |
7084 | } | |
7085 | else if (TREE_CODE (id) != ERROR_MARK) | |
7086 | /* Can't change CLASS nodes into RECORD nodes here! */ | |
7087 | type = id; | |
7088 | ||
7089 | found: {} | |
7090 | } | |
7091 | ||
7092 | typedef_type = type; | |
7093 | ||
7094 | /* No type at all: default to `int', and set EXPLICIT_INT | |
7095 | because it was not a user-defined typedef. */ | |
7096 | ||
7097 | if (type == NULL_TREE) | |
7098 | { | |
7099 | explicit_int = -1; | |
7100 | if (return_type == return_dtor) | |
7101 | type = void_type_node; | |
7102 | else if (return_type == return_ctor) | |
7103 | type = TYPE_POINTER_TO (ctor_return_type); | |
7104 | else | |
7105 | { | |
7106 | if (funcdef_flag && explicit_warn_return_type | |
7107 | && return_type == return_normal | |
7108 | && ! (specbits & (RIDBIT (RID_SIGNED) | RIDBIT (RID_UNSIGNED) | |
7109 | | RIDBIT (RID_LONG) | RIDBIT (RID_SHORT)))) | |
7110 | warn_about_return_type = 1; | |
7111 | /* Save warning until we know what is really going on. */ | |
7112 | type = integer_type_node; | |
7113 | } | |
7114 | } | |
7115 | else if (return_type == return_dtor) | |
7116 | { | |
7117 | error ("return type specification for destructor invalid"); | |
7118 | type = void_type_node; | |
7119 | } | |
7120 | else if (return_type == return_ctor) | |
7121 | { | |
7122 | error ("return type specification for constructor invalid"); | |
7123 | type = TYPE_POINTER_TO (ctor_return_type); | |
7124 | } | |
7125 | else if ((specbits & RIDBIT (RID_FRIEND)) | |
7126 | && IS_AGGR_TYPE (type) | |
7127 | && ! TYPE_BEING_DEFINED (type) | |
7128 | && TYPE_SIZE (type) == NULL_TREE | |
7129 | && ! ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)) | |
7130 | && current_function_decl == NULL_TREE | |
7131 | && decl_context != PARM) | |
7132 | { | |
7133 | /* xref_tag will make friend class declarations look like | |
7134 | nested class declarations. Retroactively change that | |
7135 | if the type has not yet been defined. | |
7136 | ||
7137 | ??? ANSI C++ doesn't say what to do in this case yet. */ | |
7138 | globalize_nested_type (type); | |
7139 | } | |
7140 | ||
7141 | ctype = NULL_TREE; | |
7142 | ||
7143 | /* Now process the modifiers that were specified | |
7144 | and check for invalid combinations. */ | |
7145 | ||
7146 | /* Long double is a special combination. */ | |
7147 | ||
7148 | if ((specbits & RIDBIT (RID_LONG)) | |
7149 | && TYPE_MAIN_VARIANT (type) == double_type_node) | |
7150 | { | |
7151 | specbits &= ~ RIDBIT (RID_LONG); | |
7152 | type = build_type_variant (long_double_type_node, TYPE_READONLY (type), | |
7153 | TYPE_VOLATILE (type)); | |
7154 | } | |
7155 | ||
7156 | /* Check all other uses of type modifiers. */ | |
7157 | ||
7158 | if (specbits & (RIDBIT (RID_UNSIGNED) | RIDBIT (RID_SIGNED) | |
7159 | | RIDBIT (RID_LONG) | RIDBIT (RID_SHORT))) | |
7160 | { | |
7161 | int ok = 0; | |
7162 | ||
7163 | if (TREE_CODE (type) == REAL_TYPE) | |
7164 | error ("short, signed or unsigned invalid for `%s'", name); | |
7165 | else if (TREE_CODE (type) != INTEGER_TYPE || type == wchar_type_node) | |
7166 | error ("long, short, signed or unsigned invalid for `%s'", name); | |
7167 | else if ((specbits & RIDBIT (RID_LONG)) | |
7168 | && (specbits & RIDBIT (RID_SHORT))) | |
7169 | error ("long and short specified together for `%s'", name); | |
7170 | else if (((specbits & RIDBIT (RID_LONG)) | |
7171 | || (specbits & RIDBIT (RID_SHORT))) | |
7172 | && explicit_char) | |
7173 | error ("long or short specified with char for `%s'", name); | |
7174 | else if (((specbits & RIDBIT (RID_LONG)) | |
7175 | || (specbits & RIDBIT (RID_SHORT))) | |
7176 | && TREE_CODE (type) == REAL_TYPE) | |
7177 | error ("long or short specified with floating type for `%s'", name); | |
7178 | else if ((specbits & RIDBIT (RID_SIGNED)) | |
7179 | && (specbits & RIDBIT (RID_UNSIGNED))) | |
7180 | error ("signed and unsigned given together for `%s'", name); | |
7181 | else | |
7182 | { | |
7183 | ok = 1; | |
7184 | if (!explicit_int && !explicit_char && pedantic) | |
7185 | { | |
7186 | pedwarn ("long, short, signed or unsigned used invalidly for `%s'", | |
7187 | name); | |
7188 | if (flag_pedantic_errors) | |
7189 | ok = 0; | |
7190 | } | |
7191 | } | |
7192 | ||
7193 | /* Discard the type modifiers if they are invalid. */ | |
7194 | if (! ok) | |
7195 | { | |
7196 | specbits &= ~ (RIDBIT (RID_UNSIGNED) | RIDBIT (RID_SIGNED) | |
7197 | | RIDBIT (RID_LONG) | RIDBIT (RID_SHORT)); | |
7198 | longlong = 0; | |
7199 | } | |
7200 | } | |
7201 | ||
7202 | /* Decide whether an integer type is signed or not. | |
7203 | Optionally treat bitfields as signed by default. */ | |
7204 | if ((specbits & RIDBIT (RID_UNSIGNED)) | |
7205 | /* Traditionally, all bitfields are unsigned. */ | |
7206 | || (bitfield && flag_traditional) | |
7207 | || (bitfield && ! flag_signed_bitfields | |
7208 | && (explicit_int || explicit_char | |
7209 | /* A typedef for plain `int' without `signed' | |
7210 | can be controlled just like plain `int'. */ | |
7211 | || ! (typedef_decl != NULL_TREE | |
7212 | && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
7213 | && TREE_CODE (type) != ENUMERAL_TYPE | |
7214 | && !(specbits & RIDBIT (RID_SIGNED)))) | |
7215 | { | |
7216 | if (longlong) | |
7217 | type = long_long_unsigned_type_node; | |
7218 | else if (specbits & RIDBIT (RID_LONG)) | |
7219 | type = long_unsigned_type_node; | |
7220 | else if (specbits & RIDBIT (RID_SHORT)) | |
7221 | type = short_unsigned_type_node; | |
7222 | else if (type == char_type_node) | |
7223 | type = unsigned_char_type_node; | |
7224 | else if (typedef_decl) | |
7225 | type = unsigned_type (type); | |
7226 | else | |
7227 | type = unsigned_type_node; | |
7228 | } | |
7229 | else if ((specbits & RIDBIT (RID_SIGNED)) | |
7230 | && type == char_type_node) | |
7231 | type = signed_char_type_node; | |
7232 | else if (longlong) | |
7233 | type = long_long_integer_type_node; | |
7234 | else if (specbits & RIDBIT (RID_LONG)) | |
7235 | type = long_integer_type_node; | |
7236 | else if (specbits & RIDBIT (RID_SHORT)) | |
7237 | type = short_integer_type_node; | |
7238 | ||
7239 | /* Set CONSTP if this declaration is `const', whether by | |
7240 | explicit specification or via a typedef. | |
7241 | Likewise for VOLATILEP. */ | |
7242 | ||
7243 | constp = !! (specbits & RIDBIT (RID_CONST)) + TYPE_READONLY (type); | |
7244 | volatilep = !! (specbits & RIDBIT (RID_VOLATILE)) + TYPE_VOLATILE (type); | |
7245 | staticp = 0; | |
7246 | inlinep = !! (specbits & RIDBIT (RID_INLINE)); | |
7247 | if (constp > 1) | |
7248 | warning ("duplicate `const'"); | |
7249 | if (volatilep > 1) | |
7250 | warning ("duplicate `volatile'"); | |
7251 | virtualp = specbits & RIDBIT (RID_VIRTUAL); | |
7252 | if (specbits & RIDBIT (RID_STATIC)) | |
7253 | staticp = 1 + (decl_context == FIELD); | |
7254 | ||
7255 | if (virtualp && staticp == 2) | |
7256 | { | |
7257 | error ("member `%s' cannot be declared both virtual and static", name); | |
7258 | staticp = 0; | |
7259 | } | |
7260 | friendp = specbits & RIDBIT (RID_FRIEND); | |
7261 | specbits &= ~ (RIDBIT (RID_VIRTUAL) | RIDBIT (RID_FRIEND)); | |
7262 | ||
7263 | /* Warn if two storage classes are given. Default to `auto'. */ | |
7264 | ||
7265 | if (specbits) | |
7266 | { | |
7267 | if (specbits & RIDBIT (RID_STATIC)) nclasses++; | |
7268 | if (specbits & RIDBIT (RID_EXTERN)) nclasses++; | |
7269 | if (decl_context == PARM && nclasses > 0) | |
7270 | error ("storage class specifiers invalid in parameter declarations"); | |
7271 | if (specbits & RIDBIT (RID_TYPEDEF)) | |
7272 | { | |
7273 | if (decl_context == PARM) | |
7274 | error ("typedef declaration invalid in parameter declaration"); | |
7275 | nclasses++; | |
7276 | } | |
7277 | if (specbits & RIDBIT (RID_AUTO)) nclasses++; | |
7278 | if (specbits & RIDBIT (RID_REGISTER)) nclasses++; | |
7279 | } | |
7280 | ||
7281 | /* Give error if `virtual' is used outside of class declaration. */ | |
7282 | if (virtualp && current_class_name == NULL_TREE) | |
7283 | { | |
7284 | error ("virtual outside class declaration"); | |
7285 | virtualp = 0; | |
7286 | } | |
7287 | ||
7288 | /* Warn about storage classes that are invalid for certain | |
7289 | kinds of declarations (parameters, typenames, etc.). */ | |
7290 | ||
7291 | if (nclasses > 1) | |
7292 | error ("multiple storage classes in declaration of `%s'", name); | |
7293 | else if (decl_context != NORMAL && nclasses > 0) | |
7294 | { | |
7295 | if (decl_context == PARM | |
7296 | && ((specbits & RIDBIT (RID_REGISTER)) | RIDBIT (RID_AUTO))) | |
7297 | ; | |
7298 | else if ((decl_context == FIELD | |
7299 | || decl_context == TYPENAME) | |
7300 | && (specbits & RIDBIT (RID_TYPEDEF))) | |
7301 | { | |
7302 | /* A typedef which was made in a class's scope. */ | |
7303 | tree loc_typedecl; | |
7304 | register int i = sizeof (struct lang_decl_flags) / sizeof (int); | |
7305 | register int *pi; | |
7306 | struct binding_level *local_binding_level; | |
7307 | ||
7308 | /* keep `grokdeclarator' from thinking we are in PARM context. */ | |
7309 | pushlevel (0); | |
7310 | /* poplevel_class may be called by grokdeclarator which is called in | |
7311 | start_decl which is called below. In this case, our pushed level | |
7312 | may vanish and poplevel mustn't be called. So remember what we | |
7313 | have pushed and pop only if that is matched by | |
7314 | current_binding_level later. mnl@dtro.e-technik.th-darmstadt.de */ | |
7315 | local_binding_level = current_binding_level; | |
7316 | ||
7317 | loc_typedecl = start_decl (declarator, declspecs, initialized, NULL_TREE); | |
7318 | ||
7319 | pi = (int *) permalloc (sizeof (struct lang_decl_flags)); | |
7320 | while (i > 0) | |
7321 | pi[--i] = 0; | |
7322 | DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi; | |
7323 | /* This poplevel conflicts with the popclass over in | |
7324 | grokdeclarator. See ``This popclass conflicts'' */ | |
7325 | if (current_binding_level == local_binding_level) | |
7326 | poplevel (0, 0, 0); | |
7327 | ||
7328 | #if 0 | |
7329 | if (TREE_CODE (TREE_TYPE (loc_typedecl)) == ENUMERAL_TYPE) | |
7330 | { | |
7331 | tree ref = lookup_tag (ENUMERAL_TYPE, DECL_NAME (loc_typedecl), current_binding_level, 0); | |
7332 | if (! ref) | |
7333 | pushtag (DECL_NAME (loc_typedecl), TREE_TYPE (loc_typedecl)); | |
7334 | } | |
7335 | #endif | |
7336 | ||
7337 | /* We used to check for a typedef hiding a previous decl in | |
7338 | class scope, but delete_duplicate_fields_1 will now do | |
7339 | that for us in the proper place. */ | |
7340 | ||
7341 | /* We reset loc_typedecl because the IDENTIFIER_CLASS_NAME is | |
7342 | set by pushdecl_class_level. */ | |
7343 | loc_typedecl = pushdecl_class_level (loc_typedecl); | |
7344 | ||
7345 | return loc_typedecl; | |
7346 | } | |
7347 | else if (decl_context == FIELD | |
7348 | /* C++ allows static class elements */ | |
7349 | && (specbits & RIDBIT (RID_STATIC))) | |
7350 | /* C++ also allows inlines and signed and unsigned elements, | |
7351 | but in those cases we don't come in here. */ | |
7352 | ; | |
7353 | else | |
7354 | { | |
7355 | if (decl_context == FIELD) | |
7356 | { | |
7357 | tree tmp = TREE_OPERAND (declarator, 0); | |
7358 | register int op = IDENTIFIER_OPNAME_P (tmp); | |
7359 | error ("storage class specified for %s `%s'", | |
7360 | op ? "member operator" : "structure field", | |
7361 | op ? operator_name_string (tmp) : name); | |
7362 | } | |
7363 | else | |
7364 | error ((decl_context == PARM | |
7365 | ? "storage class specified for parameter `%s'" | |
7366 | : "storage class specified for typename"), name); | |
7367 | specbits &= ~ (RIDBIT (RID_REGISTER) | RIDBIT (RID_AUTO) | |
7368 | | RIDBIT (RID_EXTERN)); | |
7369 | } | |
7370 | } | |
7371 | else if ((specbits & RIDBIT (RID_EXTERN)) && initialized && !funcdef_flag) | |
7372 | { | |
7373 | if (current_binding_level == global_binding_level) | |
7374 | { | |
7375 | /* It's common practice (and completely legal) to have a const | |
7376 | be initialized and declared extern. */ | |
7377 | if (! constp) | |
7378 | warning ("`%s' initialized and declared `extern'", name); | |
7379 | } | |
7380 | else | |
7381 | error ("`%s' has both `extern' and initializer", name); | |
7382 | } | |
7383 | else if ((specbits & RIDBIT (RID_EXTERN)) && funcdef_flag | |
7384 | && current_binding_level != global_binding_level) | |
7385 | error ("nested function `%s' declared `extern'", name); | |
7386 | else if (current_binding_level == global_binding_level) | |
7387 | { | |
7388 | if (specbits & RIDBIT (RID_AUTO)) | |
7389 | error ("top-level declaration of `%s' specifies `auto'", name); | |
7390 | #if 0 | |
7391 | if (specbits & RIDBIT (RID_REGISTER)) | |
7392 | error ("top-level declaration of `%s' specifies `register'", name); | |
7393 | #endif | |
7394 | #if 0 | |
7395 | /* I'm not sure under what circumstances we should turn | |
7396 | on the extern bit, and under what circumstances we should | |
7397 | warn if other bits are turned on. */ | |
7398 | if (decl_context == NORMAL | |
7399 | && ! (specbits & RIDBIT (RID_EXTERN)) | |
7400 | && ! root_lang_context_p ()) | |
7401 | { | |
7402 | specbits |= RIDBIT (RID_EXTERN); | |
7403 | } | |
7404 | #endif | |
7405 | } | |
7406 | ||
7407 | /* Now figure out the structure of the declarator proper. | |
7408 | Descend through it, creating more complex types, until we reach | |
7409 | the declared identifier (or NULL_TREE, in an absolute declarator). */ | |
7410 | ||
7411 | while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE) | |
7412 | { | |
7413 | /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), | |
7414 | an INDIRECT_REF (for *...), | |
7415 | a CALL_EXPR (for ...(...)), | |
7416 | an identifier (for the name being declared) | |
7417 | or a null pointer (for the place in an absolute declarator | |
7418 | where the name was omitted). | |
7419 | For the last two cases, we have just exited the loop. | |
7420 | ||
7421 | For C++ it could also be | |
7422 | a SCOPE_REF (for class :: ...). In this case, we have converted | |
7423 | sensible names to types, and those are the values we use to | |
7424 | qualify the member name. | |
7425 | an ADDR_EXPR (for &...), | |
7426 | a BIT_NOT_EXPR (for destructors) | |
7427 | a TYPE_EXPR (for operator typenames) | |
7428 | ||
7429 | At this point, TYPE is the type of elements of an array, | |
7430 | or for a function to return, or for a pointer to point to. | |
7431 | After this sequence of ifs, TYPE is the type of the | |
7432 | array or function or pointer, and DECLARATOR has had its | |
7433 | outermost layer removed. */ | |
7434 | ||
7435 | if (TREE_CODE (type) == ERROR_MARK) | |
7436 | { | |
7437 | if (TREE_CODE (declarator) == SCOPE_REF) | |
7438 | declarator = TREE_OPERAND (declarator, 1); | |
7439 | else | |
7440 | declarator = TREE_OPERAND (declarator, 0); | |
7441 | continue; | |
7442 | } | |
7443 | if (quals != NULL_TREE | |
7444 | && (declarator == NULL_TREE | |
7445 | || TREE_CODE (declarator) != SCOPE_REF)) | |
7446 | { | |
7447 | if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE) | |
7448 | ctype = TYPE_METHOD_BASETYPE (type); | |
7449 | if (ctype != NULL_TREE) | |
7450 | { | |
7451 | #if 0 /* not yet, should get fixed properly later */ | |
7452 | tree dummy = make_type_decl (NULL_TREE, type); | |
7453 | #else | |
7454 | tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); | |
7455 | #endif | |
7456 | ctype = grok_method_quals (ctype, dummy, quals); | |
7457 | type = TREE_TYPE (dummy); | |
7458 | quals = NULL_TREE; | |
7459 | } | |
7460 | } | |
7461 | switch (TREE_CODE (declarator)) | |
7462 | { | |
7463 | case ARRAY_REF: | |
7464 | maybe_globalize_type (type); | |
7465 | { | |
7466 | register tree itype = NULL_TREE; | |
7467 | register tree size = TREE_OPERAND (declarator, 1); | |
7468 | ||
7469 | declarator = TREE_OPERAND (declarator, 0); | |
7470 | ||
7471 | /* Check for some types that there cannot be arrays of. */ | |
7472 | ||
7473 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
7474 | { | |
7475 | error ("declaration of `%s' as array of voids", name); | |
7476 | type = error_mark_node; | |
7477 | } | |
7478 | ||
7479 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
7480 | { | |
7481 | error ("declaration of `%s' as array of functions", name); | |
7482 | type = error_mark_node; | |
7483 | } | |
7484 | ||
7485 | /* ARM $8.4.3: Since you can't have a pointer to a reference, | |
7486 | you can't have arrays of references. If we allowed them, | |
7487 | then we'd be saying x[i] is legal for an array x, but | |
7488 | then you'd have to ask: what does `*(x + i)' mean? */ | |
7489 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
7490 | error ("declaration of `%s' as array of references", name); | |
7491 | ||
7492 | if (size == error_mark_node) | |
7493 | type = error_mark_node; | |
7494 | ||
7495 | if (type == error_mark_node) | |
7496 | continue; | |
7497 | ||
7498 | if (size) | |
7499 | { | |
7500 | /* Must suspend_momentary here because the index | |
7501 | type may need to live until the end of the function. | |
7502 | For example, it is used in the declaration of a | |
7503 | variable which requires destructing at the end of | |
7504 | the function; then build_vec_delete will need this | |
7505 | value. */ | |
7506 | int yes = suspend_momentary (); | |
7507 | /* might be a cast */ | |
7508 | if (TREE_CODE (size) == NOP_EXPR | |
7509 | && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) | |
7510 | size = TREE_OPERAND (size, 0); | |
7511 | ||
7512 | /* If this is a template parameter, it'll be constant, but | |
7513 | we don't know what the value is yet. */ | |
7514 | if (TREE_CODE (size) == TEMPLATE_CONST_PARM) | |
7515 | goto dont_grok_size; | |
7516 | ||
7517 | if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE | |
7518 | && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) | |
7519 | { | |
7520 | error ("size of array `%s' has non-integer type", name); | |
7521 | size = integer_one_node; | |
7522 | } | |
7523 | if (TREE_READONLY_DECL_P (size)) | |
7524 | size = decl_constant_value (size); | |
7525 | if (pedantic && integer_zerop (size)) | |
7526 | pedwarn ("ANSI C++ forbids zero-size array `%s'", name); | |
7527 | if (TREE_CONSTANT (size)) | |
7528 | { | |
7529 | if (INT_CST_LT (size, integer_zero_node)) | |
7530 | { | |
7531 | error ("size of array `%s' is negative", name); | |
7532 | size = integer_one_node; | |
7533 | } | |
7534 | itype = build_index_type (size_binop (MINUS_EXPR, size, | |
7535 | integer_one_node)); | |
7536 | } | |
7537 | else | |
7538 | { | |
7539 | if (pedantic) | |
7540 | pedwarn ("ANSI C++ forbids variable-size array `%s'", name); | |
7541 | dont_grok_size: | |
7542 | itype = | |
7543 | build_binary_op (MINUS_EXPR, size, integer_one_node, 1); | |
7544 | /* Make sure the array size remains visibly nonconstant | |
7545 | even if it is (eg) a const variable with known value. */ | |
7546 | size_varies = 1; | |
7547 | itype = variable_size (itype); | |
7548 | itype = build_index_type (itype); | |
7549 | } | |
7550 | resume_momentary (yes); | |
7551 | } | |
7552 | ||
7553 | /* Build the array type itself. | |
7554 | Merge any constancy or volatility into the target type. */ | |
7555 | ||
7556 | if (constp || volatilep) | |
7557 | type = build_type_variant (type, constp, volatilep); | |
7558 | ||
7559 | type = build_cplus_array_type (type, itype); | |
7560 | ctype = NULL_TREE; | |
7561 | } | |
7562 | break; | |
7563 | ||
7564 | case CALL_EXPR: | |
7565 | maybe_globalize_type (type); | |
7566 | { | |
7567 | tree arg_types; | |
7568 | ||
7569 | /* Declaring a function type. | |
7570 | Make sure we have a valid type for the function to return. */ | |
7571 | #if 0 | |
7572 | /* Is this an error? Should they be merged into TYPE here? */ | |
7573 | if (pedantic && (constp || volatilep)) | |
7574 | pedwarn ("function declared to return const or volatile result"); | |
7575 | #else | |
7576 | /* Merge any constancy or volatility into the target type | |
7577 | for the pointer. */ | |
7578 | ||
7579 | if (constp || volatilep) | |
7580 | { | |
7581 | type = build_type_variant (type, constp, volatilep); | |
7582 | if (IS_AGGR_TYPE (type)) | |
7583 | build_pointer_type (type); | |
7584 | constp = 0; | |
7585 | volatilep = 0; | |
7586 | } | |
7587 | #endif | |
7588 | ||
7589 | /* Warn about some types functions can't return. */ | |
7590 | ||
7591 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
7592 | { | |
7593 | error ("`%s' declared as function returning a function", name); | |
7594 | type = integer_type_node; | |
7595 | } | |
7596 | if (TREE_CODE (type) == ARRAY_TYPE) | |
7597 | { | |
7598 | error ("`%s' declared as function returning an array", name); | |
7599 | type = integer_type_node; | |
7600 | } | |
7601 | ||
7602 | if (ctype == NULL_TREE | |
7603 | && decl_context == FIELD | |
7604 | && (friendp == 0 || dname == current_class_name)) | |
7605 | ctype = current_class_type; | |
7606 | ||
7607 | if (ctype && flags == TYPENAME_FLAG) | |
7608 | TYPE_HAS_CONVERSION (ctype) = 1; | |
7609 | if (ctype && constructor_name (ctype) == dname) | |
7610 | { | |
7611 | /* We are within a class's scope. If our declarator name | |
7612 | is the same as the class name, and we are defining | |
7613 | a function, then it is a constructor/destructor, and | |
7614 | therefore returns a void type. */ | |
7615 | ||
7616 | if (flags == DTOR_FLAG) | |
7617 | { | |
7618 | /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may | |
7619 | not be declared const or volatile. A destructor | |
7620 | may not be static. */ | |
7621 | if (staticp == 2) | |
7622 | error ("destructor cannot be static member function"); | |
7623 | if (TYPE_READONLY (type)) | |
7624 | { | |
7625 | error ("destructors cannot be declared `const'"); | |
7626 | return void_type_node; | |
7627 | } | |
7628 | if (TYPE_VOLATILE (type)) | |
7629 | { | |
7630 | error ("destructors cannot be declared `volatile'"); | |
7631 | return void_type_node; | |
7632 | } | |
7633 | if (decl_context == FIELD) | |
7634 | { | |
7635 | if (! member_function_or_else (ctype, current_class_type, | |
7636 | "destructor for alien class `%s' cannot be a member")) | |
7637 | return void_type_node; | |
7638 | } | |
7639 | } | |
7640 | else /* it's a constructor. */ | |
7641 | { | |
7642 | /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may | |
7643 | not be declared const or volatile. A constructor may | |
7644 | not be virtual. A constructor may not be static. */ | |
7645 | if (staticp == 2) | |
7646 | error ("constructor cannot be static member function"); | |
7647 | if (virtualp) | |
7648 | { | |
7649 | pedwarn ("constructors cannot be declared virtual"); | |
7650 | virtualp = 0; | |
7651 | } | |
7652 | if (TYPE_READONLY (type)) | |
7653 | { | |
7654 | error ("constructors cannot be declared `const'"); | |
7655 | return void_type_node; | |
7656 | } | |
7657 | if (TYPE_VOLATILE (type)) | |
7658 | { | |
7659 | error ("constructors cannot be declared `volatile'"); | |
7660 | return void_type_node; | |
7661 | } | |
7662 | if (specbits & ~(RIDBIT (RID_INLINE)|RIDBIT (RID_STATIC))) | |
7663 | error ("return value type specifier for constructor ignored"); | |
7664 | type = TYPE_POINTER_TO (ctype); | |
7665 | if (decl_context == FIELD) | |
7666 | { | |
7667 | if (! member_function_or_else (ctype, current_class_type, | |
7668 | "constructor for alien class `%s' cannot be member")) | |
7669 | return void_type_node; | |
7670 | TYPE_HAS_CONSTRUCTOR (ctype) = 1; | |
7671 | if (return_type != return_ctor) | |
7672 | return NULL_TREE; | |
7673 | } | |
7674 | } | |
7675 | if (decl_context == FIELD) | |
7676 | staticp = 0; | |
7677 | } | |
7678 | else if (friendp && virtualp) | |
7679 | { | |
7680 | /* Cannot be both friend and virtual. */ | |
7681 | error ("virtual functions cannot be friends"); | |
7682 | specbits &= ~ RIDBIT (RID_FRIEND); | |
7683 | } | |
7684 | ||
7685 | if (decl_context == NORMAL && friendp) | |
7686 | error ("friend declaration not in class definition"); | |
7687 | ||
7688 | /* Pick up type qualifiers which should be applied to `this'. */ | |
7689 | quals = TREE_OPERAND (declarator, 2); | |
7690 | ||
7691 | /* Traditionally, declaring return type float means double. */ | |
7692 | ||
7693 | if (flag_traditional | |
7694 | && TYPE_MAIN_VARIANT (type) == float_type_node) | |
7695 | { | |
7696 | type = build_type_variant (double_type_node, | |
7697 | TYPE_READONLY (type), | |
7698 | TYPE_VOLATILE (type)); | |
7699 | } | |
7700 | ||
7701 | /* Construct the function type and go to the next | |
7702 | inner layer of declarator. */ | |
7703 | ||
7704 | { | |
7705 | int funcdef_p; | |
7706 | tree inner_parms = TREE_OPERAND (declarator, 1); | |
7707 | tree inner_decl = TREE_OPERAND (declarator, 0); | |
7708 | ||
7709 | declarator = TREE_OPERAND (declarator, 0); | |
7710 | ||
7711 | if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) | |
7712 | inner_decl = TREE_OPERAND (inner_decl, 1); | |
7713 | ||
7714 | /* Say it's a definition only for the CALL_EXPR | |
7715 | closest to the identifier. */ | |
7716 | funcdef_p = | |
7717 | (inner_decl && | |
7718 | (TREE_CODE (inner_decl) == IDENTIFIER_NODE | |
7719 | || TREE_CODE (inner_decl) == TYPE_EXPR)) ? funcdef_flag : 0; | |
7720 | ||
7721 | arg_types = grokparms (inner_parms, funcdef_p); | |
7722 | } | |
7723 | ||
7724 | if (declarator) | |
7725 | { | |
7726 | /* Get past destructors, etc. | |
7727 | We know we have one because FLAGS will be non-zero. | |
7728 | ||
7729 | Complain about improper parameter lists here. */ | |
7730 | if (TREE_CODE (declarator) == BIT_NOT_EXPR) | |
7731 | { | |
7732 | declarator = TREE_OPERAND (declarator, 0); | |
7733 | ||
7734 | if (strict_prototype == 0 && arg_types == NULL_TREE) | |
7735 | arg_types = void_list_node; | |
7736 | else if (arg_types == NULL_TREE | |
7737 | || arg_types != void_list_node) | |
7738 | { | |
7739 | error ("destructors cannot be specified with parameters"); | |
7740 | arg_types = void_list_node; | |
7741 | } | |
7742 | } | |
7743 | } | |
7744 | /* the top level const or volatile is attached semantically only | |
7745 | to the function not the actual type. */ | |
7746 | if (TYPE_READONLY (type) || TYPE_VOLATILE (type)) | |
7747 | { | |
7748 | int constp = TYPE_READONLY (type); | |
7749 | int volatilep = TYPE_VOLATILE (type); | |
7750 | type = build_function_type (TYPE_MAIN_VARIANT (type), | |
7751 | flag_traditional | |
7752 | ? 0 | |
7753 | : arg_types); | |
7754 | type = build_type_variant (type, constp, volatilep); | |
7755 | } | |
7756 | else | |
7757 | type = build_function_type (type, | |
7758 | flag_traditional | |
7759 | ? 0 | |
7760 | : arg_types); | |
7761 | } | |
7762 | break; | |
7763 | ||
7764 | case ADDR_EXPR: | |
7765 | case INDIRECT_REF: | |
7766 | maybe_globalize_type (type); | |
7767 | ||
7768 | /* Filter out pointers-to-references and references-to-references. | |
7769 | We can get these if a TYPE_DECL is used. */ | |
7770 | ||
7771 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
7772 | { | |
7773 | error ("cannot declare %s to references", | |
7774 | TREE_CODE (declarator) == ADDR_EXPR | |
7775 | ? "references" : "pointers"); | |
7776 | declarator = TREE_OPERAND (declarator, 0); | |
7777 | continue; | |
7778 | } | |
7779 | ||
7780 | /* Merge any constancy or volatility into the target type | |
7781 | for the pointer. */ | |
7782 | ||
7783 | if (constp || volatilep) | |
7784 | { | |
7785 | type = build_type_variant (type, constp, volatilep); | |
7786 | if (IS_AGGR_TYPE (type)) | |
7787 | build_pointer_type (type); | |
7788 | constp = 0; | |
7789 | volatilep = 0; | |
7790 | } | |
7791 | ||
7792 | if (TREE_CODE (declarator) == ADDR_EXPR) | |
7793 | { | |
7794 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
7795 | { | |
7796 | error ("cannot declare references to functions; use pointer to function instead"); | |
7797 | type = build_pointer_type (type); | |
7798 | } | |
7799 | else | |
7800 | { | |
7801 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
7802 | error ("invalid type: `void &'"); | |
7803 | else | |
7804 | type = build_reference_type (type); | |
7805 | } | |
7806 | } | |
7807 | else | |
7808 | type = build_pointer_type (type); | |
7809 | ||
7810 | /* Process a list of type modifier keywords (such as | |
7811 | const or volatile) that were given inside the `*' or `&'. */ | |
7812 | ||
7813 | if (TREE_TYPE (declarator)) | |
7814 | { | |
7815 | register tree typemodlist; | |
7816 | int erred = 0; | |
7817 | for (typemodlist = TREE_TYPE (declarator); typemodlist; | |
7818 | typemodlist = TREE_CHAIN (typemodlist)) | |
7819 | { | |
7820 | if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST]) | |
7821 | constp++; | |
7822 | else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE]) | |
7823 | volatilep++; | |
7824 | else if (!erred) | |
7825 | { | |
7826 | erred = 1; | |
7827 | error ("invalid type modifier within %s declarator", | |
7828 | TREE_CODE (declarator) == ADDR_EXPR | |
7829 | ? "reference" : "pointer"); | |
7830 | } | |
7831 | } | |
7832 | if (constp > 1) | |
7833 | warning ("duplicate `const'"); | |
7834 | if (volatilep > 1) | |
7835 | warning ("duplicate `volatile'"); | |
7836 | } | |
7837 | declarator = TREE_OPERAND (declarator, 0); | |
7838 | ctype = NULL_TREE; | |
7839 | break; | |
7840 | ||
7841 | case SCOPE_REF: | |
7842 | { | |
7843 | /* We have converted type names to NULL_TREE if the | |
7844 | name was bogus, or to a _TYPE node, if not. | |
7845 | ||
7846 | The variable CTYPE holds the type we will ultimately | |
7847 | resolve to. The code here just needs to build | |
7848 | up appropriate member types. */ | |
7849 | tree sname = TREE_OPERAND (declarator, 1); | |
7850 | /* Destructors can have their visibilities changed as well. */ | |
7851 | if (TREE_CODE (sname) == BIT_NOT_EXPR) | |
7852 | sname = TREE_OPERAND (sname, 0); | |
7853 | ||
7854 | if (TREE_COMPLEXITY (declarator) == 0) | |
7855 | /* This needs to be here, in case we are called | |
7856 | multiple times. */ ; | |
7857 | else if (friendp && (TREE_COMPLEXITY (declarator) < 2)) | |
7858 | /* don't fall out into global scope. Hides real bug? --eichin */ ; | |
7859 | else if (TREE_COMPLEXITY (declarator) == current_class_depth) | |
7860 | { | |
7861 | TREE_COMPLEXITY (declarator) -= 1; | |
7862 | /* This popclass conflicts with the poplevel over in | |
7863 | grokdeclarator. See ``This poplevel conflicts'' */ | |
7864 | popclass (1); | |
7865 | } | |
7866 | else | |
7867 | my_friendly_abort (16); | |
7868 | ||
7869 | if (TREE_OPERAND (declarator, 0) == NULL_TREE) | |
7870 | { | |
7871 | /* We had a reference to a global decl, or | |
7872 | perhaps we were given a non-aggregate typedef, | |
7873 | in which case we cleared this out, and should just | |
7874 | keep going as though it wasn't there. */ | |
7875 | declarator = sname; | |
7876 | continue; | |
7877 | } | |
7878 | ctype = TREE_OPERAND (declarator, 0); | |
7879 | ||
7880 | if (sname == NULL_TREE) | |
7881 | goto done_scoping; | |
7882 | ||
7883 | if (TREE_CODE (sname) == IDENTIFIER_NODE) | |
7884 | { | |
7885 | /* This is the `standard' use of the scoping operator: | |
7886 | basetype :: member . */ | |
7887 | ||
7888 | if (TYPE_MAIN_VARIANT (ctype) == current_class_type || friendp) | |
7889 | { | |
7890 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
7891 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
7892 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
7893 | else | |
7894 | { | |
7895 | if (TYPE_MAIN_VARIANT (ctype) != current_class_type) | |
7896 | { | |
7897 | error ("cannot declare member `%s::%s' within this class", | |
7898 | TYPE_NAME_STRING (ctype), name); | |
7899 | return void_type_node; | |
7900 | } | |
7901 | else if (extra_warnings) | |
7902 | warning ("extra qualification `%s' on member `%s' ignored", | |
7903 | TYPE_NAME_STRING (ctype), name); | |
7904 | type = build_offset_type (ctype, type); | |
7905 | } | |
7906 | } | |
7907 | else if (TYPE_SIZE (ctype) != NULL_TREE | |
7908 | || (specbits & RIDBIT (RID_TYPEDEF))) | |
7909 | { | |
7910 | tree t; | |
7911 | /* have to move this code elsewhere in this function. | |
7912 | this code is used for i.e., typedef int A::M; M *pm; */ | |
7913 | ||
7914 | if (explicit_int == -1 && decl_context == FIELD | |
7915 | && funcdef_flag == 0) | |
7916 | { | |
7917 | /* The code in here should only be used to build | |
7918 | stuff that will be grokked as visibility decls. */ | |
7919 | t = lookup_field (ctype, sname, 0, 0); | |
7920 | if (t) | |
7921 | { | |
7922 | t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); | |
7923 | DECL_INITIAL (t) = init; | |
7924 | return t; | |
7925 | } | |
7926 | /* No such field, try member functions. */ | |
7927 | t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0); | |
7928 | if (t) | |
7929 | { | |
7930 | if (flags == DTOR_FLAG) | |
7931 | t = TREE_VALUE (t); | |
7932 | else if (CLASSTYPE_METHOD_VEC (ctype) | |
7933 | && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0)) | |
7934 | { | |
7935 | /* Don't include destructor with constructors. */ | |
7936 | t = DECL_CHAIN (TREE_VALUE (t)); | |
7937 | if (t == NULL_TREE) | |
7938 | error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname)); | |
7939 | t = build_tree_list (NULL_TREE, t); | |
7940 | } | |
7941 | t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); | |
7942 | DECL_INITIAL (t) = init; | |
7943 | return t; | |
7944 | } | |
7945 | ||
7946 | if (flags == TYPENAME_FLAG) | |
7947 | error_with_aggr_type (ctype, "type conversion is not a member of structure `%s'"); | |
7948 | else | |
7949 | error ("field `%s' is not a member of structure `%s'", | |
7950 | IDENTIFIER_POINTER (sname), | |
7951 | TYPE_NAME_STRING (ctype)); | |
7952 | } | |
7953 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
7954 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
7955 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
7956 | else | |
7957 | { | |
7958 | if (current_class_type) | |
7959 | { | |
7960 | if (TYPE_MAIN_VARIANT (ctype) != current_class_type) | |
7961 | { | |
7962 | error ("cannot declare member `%s::%s' within this class", | |
7963 | TYPE_NAME_STRING (ctype), name); | |
7964 | return void_type_node; | |
7965 | } | |
7966 | else if (extra_warnings) | |
7967 | warning ("extra qualification `%s' on member `%s' ignored", | |
7968 | TYPE_NAME_STRING (ctype), name); | |
7969 | } | |
7970 | type = build_offset_type (ctype, type); | |
7971 | } | |
7972 | } | |
7973 | else if (uses_template_parms (ctype)) | |
7974 | { | |
7975 | enum tree_code c; | |
7976 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
7977 | { | |
7978 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
7979 | TREE_TYPE (type), | |
7980 | TYPE_ARG_TYPES (type)); | |
7981 | c = FUNCTION_DECL; | |
7982 | } | |
7983 | } | |
7984 | else | |
7985 | sorry ("structure `%s' not yet defined", | |
7986 | TYPE_NAME_STRING (ctype)); | |
7987 | declarator = sname; | |
7988 | } | |
7989 | else if (TREE_CODE (sname) == TYPE_EXPR) | |
7990 | { | |
7991 | /* A TYPE_EXPR will change types out from under us. | |
7992 | So do the TYPE_EXPR now, and make this SCOPE_REF | |
7993 | inner to the TYPE_EXPR's CALL_EXPR. | |
7994 | ||
7995 | This does not work if we don't get a CALL_EXPR back. | |
7996 | I did not think about error recovery, hence the | |
7997 | my_friendly_abort. */ | |
7998 | ||
7999 | /* Get the CALL_EXPR. */ | |
8000 | sname = grokoptypename (sname, 0); | |
8001 | my_friendly_assert (TREE_CODE (sname) == CALL_EXPR, 157); | |
8002 | type = TREE_TYPE (TREE_OPERAND (sname, 0)); | |
8003 | /* Scope the CALL_EXPR's name. */ | |
8004 | TREE_OPERAND (declarator, 1) = TREE_OPERAND (sname, 0); | |
8005 | /* Put the SCOPE_EXPR in the CALL_EXPR's innermost position. */ | |
8006 | TREE_OPERAND (sname, 0) = declarator; | |
8007 | /* Now work from the CALL_EXPR. */ | |
8008 | declarator = sname; | |
8009 | continue; | |
8010 | } | |
8011 | else if (TREE_CODE (sname) == SCOPE_REF) | |
8012 | my_friendly_abort (17); | |
8013 | else | |
8014 | { | |
8015 | done_scoping: | |
8016 | declarator = TREE_OPERAND (declarator, 1); | |
8017 | if (declarator && TREE_CODE (declarator) == CALL_EXPR) | |
8018 | /* In this case, we will deal with it later. */ | |
8019 | ; | |
8020 | else | |
8021 | { | |
8022 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
8023 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
8024 | else | |
8025 | type = build_offset_type (ctype, type); | |
8026 | } | |
8027 | } | |
8028 | } | |
8029 | break; | |
8030 | ||
8031 | case BIT_NOT_EXPR: | |
8032 | declarator = TREE_OPERAND (declarator, 0); | |
8033 | break; | |
8034 | ||
8035 | case TYPE_EXPR: | |
8036 | declarator = grokoptypename (declarator, 0); | |
8037 | if (explicit_int != -1) | |
8038 | if (comp_target_types (type, | |
8039 | TREE_TYPE (TREE_OPERAND (declarator, 0)), | |
8040 | 1) == 0) | |
8041 | error ("type conversion function declared to return incongruent type"); | |
8042 | else | |
8043 | pedwarn ("return type specified for type conversion function"); | |
8044 | type = TREE_TYPE (TREE_OPERAND (declarator, 0)); | |
8045 | maybe_globalize_type (type); | |
8046 | break; | |
8047 | ||
8048 | case RECORD_TYPE: | |
8049 | case UNION_TYPE: | |
8050 | case ENUMERAL_TYPE: | |
8051 | declarator = NULL_TREE; | |
8052 | break; | |
8053 | ||
8054 | case ERROR_MARK: | |
8055 | declarator = NULL_TREE; | |
8056 | break; | |
8057 | ||
8058 | default: | |
8059 | my_friendly_abort (158); | |
8060 | } | |
8061 | } | |
8062 | ||
8063 | /* Now TYPE has the actual type. */ | |
8064 | ||
8065 | /* If this is declaring a typedef name, return a TYPE_DECL. */ | |
8066 | ||
8067 | if (specbits & RIDBIT (RID_TYPEDEF)) | |
8068 | { | |
8069 | tree decl; | |
8070 | ||
8071 | /* Note that the grammar rejects storage classes | |
8072 | in typenames, fields or parameters. */ | |
8073 | if (constp || volatilep) | |
8074 | type = build_type_variant (type, constp, volatilep); | |
8075 | ||
8076 | /* If the user declares "struct {...} foo" then `foo' will have | |
8077 | an anonymous name. Fill that name in now. Nothing can | |
8078 | refer to it, so nothing needs know about the name change. | |
8079 | The TYPE_NAME field was filled in by build_struct_xref. */ | |
8080 | if (TYPE_NAME (type) | |
8081 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
8082 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) | |
8083 | { | |
8084 | /* replace the anonymous name with the real name everywhere. */ | |
8085 | lookup_tag_reverse (type, declarator); | |
8086 | TYPE_IDENTIFIER (type) = declarator; | |
8087 | } | |
8088 | ||
8089 | #if 0 /* not yet, should get fixed properly later */ | |
8090 | decl = make_type_decl (declarator, type); | |
8091 | #else | |
8092 | decl = build_decl (TYPE_DECL, declarator, type); | |
8093 | #endif | |
8094 | if (quals) | |
8095 | { | |
8096 | if (ctype == NULL_TREE) | |
8097 | { | |
8098 | if (TREE_CODE (type) != METHOD_TYPE) | |
8099 | error_with_decl (decl, "invalid type qualifier for non-method type"); | |
8100 | else | |
8101 | ctype = TYPE_METHOD_BASETYPE (type); | |
8102 | } | |
8103 | if (ctype != NULL_TREE) | |
8104 | grok_method_quals (ctype, decl, quals); | |
8105 | } | |
8106 | ||
8107 | if ((specbits & RIDBIT (RID_SIGNED)) | |
8108 | || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
8109 | C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; | |
8110 | ||
8111 | return decl; | |
8112 | } | |
8113 | ||
8114 | /* Detect the case of an array type of unspecified size | |
8115 | which came, as such, direct from a typedef name. | |
8116 | We must copy the type, so that each identifier gets | |
8117 | a distinct type, so that each identifier's size can be | |
8118 | controlled separately by its own initializer. */ | |
8119 | ||
8120 | if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE | |
8121 | && TYPE_DOMAIN (type) == NULL_TREE) | |
8122 | { | |
8123 | type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); | |
8124 | } | |
8125 | ||
8126 | /* If this is a type name (such as, in a cast or sizeof), | |
8127 | compute the type and return it now. */ | |
8128 | ||
8129 | if (decl_context == TYPENAME) | |
8130 | { | |
8131 | /* Note that the grammar rejects storage classes | |
8132 | in typenames, fields or parameters. */ | |
8133 | if (constp || volatilep) | |
8134 | type = build_type_variant (type, constp, volatilep); | |
8135 | ||
8136 | /* Special case: "friend class foo" looks like a TYPENAME context. */ | |
8137 | if (friendp) | |
8138 | { | |
8139 | /* A friendly class? */ | |
8140 | if (current_class_type) | |
8141 | make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type)); | |
8142 | else | |
8143 | error("trying to make class `%s' a friend of global scope", | |
8144 | TYPE_NAME_STRING (type)); | |
8145 | type = void_type_node; | |
8146 | } | |
8147 | else if (quals) | |
8148 | { | |
8149 | #if 0 /* not yet, should get fixed properly later */ | |
8150 | tree dummy = make_type_decl (declarator, type); | |
8151 | #else | |
8152 | tree dummy = build_decl (TYPE_DECL, declarator, type); | |
8153 | #endif | |
8154 | if (ctype == NULL_TREE) | |
8155 | { | |
8156 | my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); | |
8157 | ctype = TYPE_METHOD_BASETYPE (type); | |
8158 | } | |
8159 | grok_method_quals (ctype, dummy, quals); | |
8160 | type = TREE_TYPE (dummy); | |
8161 | } | |
8162 | ||
8163 | return type; | |
8164 | } | |
8165 | ||
8166 | /* `void' at top level (not within pointer) | |
8167 | is allowed only in typedefs or type names. | |
8168 | We don't complain about parms either, but that is because | |
8169 | a better error message can be made later. */ | |
8170 | ||
8171 | if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM) | |
8172 | { | |
8173 | if (declarator != NULL_TREE | |
8174 | && TREE_CODE (declarator) == IDENTIFIER_NODE) | |
8175 | { | |
8176 | if (IDENTIFIER_OPNAME_P (declarator)) | |
8177 | error ("operator `%s' declared void", | |
8178 | operator_name_string (declarator)); | |
8179 | else | |
8180 | error ("variable or field `%s' declared void", name); | |
8181 | } | |
8182 | else | |
8183 | error ("variable or field declared void"); | |
8184 | type = integer_type_node; | |
8185 | } | |
8186 | ||
8187 | /* Now create the decl, which may be a VAR_DECL, a PARM_DECL | |
8188 | or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ | |
8189 | ||
8190 | { | |
8191 | register tree decl; | |
8192 | ||
8193 | if (decl_context == PARM) | |
8194 | { | |
8195 | tree parmtype = type; | |
8196 | ||
8197 | if (ctype) | |
8198 | error ("cannot use `::' in parameter declaration"); | |
8199 | bad_specifiers ("parameter", virtualp, quals != NULL_TREE, | |
8200 | friendp, raises != NULL_TREE); | |
8201 | ||
8202 | /* A parameter declared as an array of T is really a pointer to T. | |
8203 | One declared as a function is really a pointer to a function. | |
8204 | One declared as a member is really a pointer to member. | |
8205 | ||
8206 | Don't be misled by references. */ | |
8207 | ||
8208 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
8209 | type = TREE_TYPE (type); | |
8210 | ||
8211 | if (TREE_CODE (type) == ARRAY_TYPE) | |
8212 | { | |
8213 | if (parmtype == type) | |
8214 | { | |
8215 | /* Transfer const-ness of array into that of type | |
8216 | pointed to. */ | |
8217 | type = build_pointer_type | |
8218 | (build_type_variant (TREE_TYPE (type), constp, volatilep)); | |
8219 | volatilep = constp = 0; | |
8220 | } | |
8221 | else | |
8222 | type = build_pointer_type (TREE_TYPE (type)); | |
8223 | } | |
8224 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
8225 | type = build_pointer_type (type); | |
8226 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
8227 | type = build_pointer_type (type); | |
8228 | ||
8229 | if (TREE_CODE (parmtype) == REFERENCE_TYPE) | |
8230 | { | |
8231 | /* Transfer const-ness of reference into that of type pointed to. */ | |
8232 | type = build_type_variant (build_reference_type (type), constp, volatilep); | |
8233 | constp = volatilep = 0; | |
8234 | } | |
8235 | ||
8236 | decl = build_decl (PARM_DECL, declarator, type); | |
8237 | ||
8238 | /* Compute the type actually passed in the parmlist, | |
8239 | for the case where there is no prototype. | |
8240 | (For example, shorts and chars are passed as ints.) | |
8241 | When there is a prototype, this is overridden later. */ | |
8242 | ||
8243 | DECL_ARG_TYPE (decl) = type; | |
8244 | if (TYPE_MAIN_VARIANT (type) == float_type_node) | |
8245 | DECL_ARG_TYPE (decl) = build_type_variant (double_type_node, | |
8246 | TYPE_READONLY (type), | |
8247 | TYPE_VOLATILE (type)); | |
8248 | else if (C_PROMOTING_INTEGER_TYPE_P (type)) | |
8249 | { | |
8250 | tree argtype; | |
8251 | ||
8252 | /* Retain unsignedness if traditional or if not really | |
8253 | getting wider. */ | |
8254 | if (TREE_UNSIGNED (type) | |
8255 | && (flag_traditional | |
8256 | || TYPE_PRECISION (type) | |
8257 | == TYPE_PRECISION (integer_type_node))) | |
8258 | argtype = unsigned_type_node; | |
8259 | else | |
8260 | argtype = integer_type_node; | |
8261 | DECL_ARG_TYPE (decl) = build_type_variant (argtype, | |
8262 | TYPE_READONLY (type), | |
8263 | TYPE_VOLATILE (type)); | |
8264 | } | |
8265 | } | |
8266 | else if (decl_context == FIELD) | |
8267 | { | |
8268 | if (type == error_mark_node) | |
8269 | { | |
8270 | /* Happens when declaring arrays of sizes which | |
8271 | are error_mark_node, for example. */ | |
8272 | decl = NULL_TREE; | |
8273 | } | |
8274 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
8275 | { | |
8276 | int publicp = 0; | |
8277 | ||
8278 | if (friendp == 0) | |
8279 | { | |
8280 | if (ctype == NULL_TREE) | |
8281 | ctype = current_class_type; | |
8282 | ||
8283 | if (ctype == NULL_TREE) | |
8284 | { | |
8285 | register int op = IDENTIFIER_OPNAME_P (declarator); | |
8286 | error ("can't make %s `%s' into a method -- not in a class", | |
8287 | op ? "operator" : "function", | |
8288 | op ? operator_name_string (declarator) : IDENTIFIER_POINTER (declarator)); | |
8289 | return void_type_node; | |
8290 | } | |
8291 | ||
8292 | /* ``A union may [ ... ] not [ have ] virtual functions.'' | |
8293 | ARM 9.5 */ | |
8294 | if (virtualp && TREE_CODE (ctype) == UNION_TYPE) | |
8295 | { | |
8296 | error ("function `%s' declared virtual inside a union", | |
8297 | IDENTIFIER_POINTER (declarator)); | |
8298 | return void_type_node; | |
8299 | } | |
8300 | ||
8301 | /* Don't convert type of operators new and delete to | |
8302 | METHOD_TYPE; they remain FUNCTION_TYPEs. */ | |
8303 | if (staticp < 2 | |
8304 | && declarator != ansi_opname[(int) NEW_EXPR] | |
8305 | && declarator != ansi_opname[(int) DELETE_EXPR]) | |
8306 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
8307 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
8308 | } | |
8309 | ||
8310 | /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ | |
8311 | publicp = ((specbits & RIDBIT (RID_EXTERN)) | |
8312 | || (ctype != NULL_TREE && funcdef_flag >= 0) | |
8313 | #if 0 | |
8314 | /* These are replicated in each object, so we shouldn't | |
8315 | set TREE_PUBLIC. */ | |
8316 | || (friendp | |
8317 | && !(specbits & RIDBIT (RID_STATIC)) | |
8318 | && !(specbits & RIDBIT (RID_INLINE))) | |
8319 | #endif | |
8320 | ); | |
8321 | decl = grokfndecl (ctype, type, declarator, | |
8322 | virtualp, flags, quals, | |
8323 | raises, friendp ? -1 : 0, publicp); | |
8324 | DECL_INLINE (decl) = inlinep; | |
8325 | } | |
8326 | else if (TREE_CODE (type) == METHOD_TYPE) | |
8327 | { | |
8328 | /* All method decls are public, so tell grokfndecl to set | |
8329 | TREE_PUBLIC, also. */ | |
8330 | decl = grokfndecl (ctype, type, declarator, | |
8331 | virtualp, flags, quals, | |
8332 | raises, friendp ? -1 : 0, 1); | |
8333 | DECL_INLINE (decl) = inlinep; | |
8334 | } | |
8335 | else if (TREE_CODE (type) == RECORD_TYPE | |
8336 | && CLASSTYPE_DECLARED_EXCEPTION (type)) | |
8337 | { | |
8338 | /* Handle a class-local exception declaration. */ | |
8339 | decl = build_lang_field_decl (VAR_DECL, declarator, type); | |
8340 | if (ctype == NULL_TREE) | |
8341 | ctype = current_class_type; | |
8342 | finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL | |
8343 | ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype), decl); | |
8344 | return void_type_node; | |
8345 | } | |
8346 | else if (TYPE_SIZE (type) == NULL_TREE && !staticp | |
8347 | && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) | |
8348 | { | |
8349 | if (declarator) | |
8350 | error ("field `%s' has incomplete type", | |
8351 | IDENTIFIER_POINTER (declarator)); | |
8352 | else | |
8353 | error ("field has incomplete type"); | |
8354 | ||
8355 | /* If we're instantiating a template, tell them which | |
8356 | instantiation made the field's type be incomplete. */ | |
8357 | if (current_class_type | |
8358 | && IDENTIFIER_TEMPLATE (current_class_type) | |
8359 | && declspecs && TREE_VALUE (declspecs) | |
8360 | && TREE_TYPE (TREE_VALUE (declspecs)) == type) | |
8361 | error (" in instantiation of template `%s'", | |
8362 | TYPE_NAME_STRING (current_class_type)); | |
8363 | ||
8364 | type = error_mark_node; | |
8365 | decl = NULL_TREE; | |
8366 | } | |
8367 | else | |
8368 | { | |
8369 | if (friendp) | |
8370 | { | |
8371 | if (declarator) | |
8372 | error ("`%s' is neither function nor method; cannot be declared friend", | |
8373 | IDENTIFIER_POINTER (declarator)); | |
8374 | else | |
8375 | { | |
8376 | error ("invalid friend declaration"); | |
8377 | return void_type_node; | |
8378 | } | |
8379 | friendp = 0; | |
8380 | } | |
8381 | decl = NULL_TREE; | |
8382 | } | |
8383 | ||
8384 | if (friendp) | |
8385 | { | |
8386 | tree t; | |
8387 | ||
8388 | /* Friends are treated specially. */ | |
8389 | if (ctype == current_class_type) | |
8390 | warning ("member functions are implicitly friends of their class"); | |
8391 | else if (decl && (t = DECL_NAME (decl))) | |
8392 | { | |
8393 | /* ARM $13.4.3 */ | |
8394 | if (t == ansi_opname[(int) MODIFY_EXPR]) | |
8395 | pedwarn ("operator `=' must be a member function"); | |
8396 | else | |
8397 | return do_friend (ctype, declarator, decl, | |
8398 | last_function_parms, flags, quals); | |
8399 | } | |
8400 | else return void_type_node; | |
8401 | } | |
8402 | ||
8403 | /* Structure field. It may not be a function, except for C++ */ | |
8404 | ||
8405 | if (decl == NULL_TREE) | |
8406 | { | |
8407 | bad_specifiers ("field", virtualp, quals != NULL_TREE, | |
8408 | friendp, raises != NULL_TREE); | |
8409 | ||
8410 | /* ANSI C++ June 5 1992 WP 9.2.2 and 9.4.2. A member-declarator | |
8411 | cannot have an initializer, and a static member declaration must | |
8412 | be defined elsewhere. */ | |
8413 | if (initialized) | |
8414 | { | |
8415 | if (staticp) | |
8416 | error ("static member `%s' must be defined separately from its declaration", | |
8417 | IDENTIFIER_POINTER (declarator)); | |
8418 | /* Note that initialization of const members is not | |
8419 | mentioned in the ARM or draft ANSI standard explicitly, | |
8420 | and it appears to be in common practice. However, | |
8421 | reading the draft section 9.2.2, it does say that a | |
8422 | member declarator can't have an initializer--it does | |
8423 | not except constant members, which also qualify as | |
8424 | member-declarators. */ | |
8425 | else if (!pedantic && (!constp || flag_ansi)) | |
8426 | warning ("ANSI C++ forbids initialization of %s `%s'", | |
8427 | constp ? "const member" : "member", | |
8428 | IDENTIFIER_POINTER (declarator)); | |
8429 | } | |
8430 | ||
8431 | if (staticp || (constp && initialized)) | |
8432 | { | |
8433 | /* C++ allows static class members. | |
8434 | All other work for this is done by grokfield. | |
8435 | This VAR_DECL is built by build_lang_field_decl. | |
8436 | All other VAR_DECLs are built by build_decl. */ | |
8437 | decl = build_lang_field_decl (VAR_DECL, declarator, type); | |
8438 | if (staticp || TREE_CODE (type) == ARRAY_TYPE) | |
8439 | TREE_STATIC (decl) = 1; | |
8440 | /* In class context, static means public visibility. */ | |
8441 | TREE_PUBLIC (decl) = 1; | |
8442 | DECL_EXTERNAL (decl) = !initialized; | |
8443 | } | |
8444 | else | |
8445 | decl = build_lang_field_decl (FIELD_DECL, declarator, type); | |
8446 | } | |
8447 | } | |
8448 | else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | |
8449 | { | |
8450 | int was_overloaded = 0; | |
8451 | tree original_name = declarator; | |
8452 | int publicp = 0; | |
8453 | ||
8454 | if (! declarator) return NULL_TREE; | |
8455 | ||
8456 | if (specbits & (RIDBIT (RID_AUTO) | RIDBIT (RID_REGISTER))) | |
8457 | error ("invalid storage class for function `%s'", name); | |
8458 | /* Function declaration not at top level. | |
8459 | Storage classes other than `extern' are not allowed | |
8460 | and `extern' makes no difference. */ | |
8461 | if (current_binding_level != global_binding_level | |
8462 | && (specbits & (RIDBIT (RID_STATIC) | RIDBIT (RID_INLINE))) | |
8463 | && pedantic) | |
8464 | pedwarn ("invalid storage class for function `%s'", name); | |
8465 | ||
8466 | if (ctype == NULL_TREE) | |
8467 | { | |
8468 | if (virtualp) | |
8469 | { | |
8470 | error ("virtual non-class function `%s'", name); | |
8471 | virtualp = 0; | |
8472 | } | |
8473 | ||
8474 | /* ARM $13.4.3 */ | |
8475 | /* XXX: It's likely others should also be forbidden. (bpk) */ | |
8476 | if (declarator == ansi_opname[(int) MODIFY_EXPR]) | |
8477 | warning ("operator `=' must be a member function"); | |
8478 | ||
8479 | if (current_lang_name == lang_name_cplusplus | |
8480 | && ! (IDENTIFIER_LENGTH (original_name) == 4 | |
8481 | && IDENTIFIER_POINTER (original_name)[0] == 'm' | |
8482 | && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0) | |
8483 | && ! (IDENTIFIER_LENGTH (original_name) > 10 | |
8484 | && IDENTIFIER_POINTER (original_name)[0] == '_' | |
8485 | && IDENTIFIER_POINTER (original_name)[1] == '_' | |
8486 | && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0)) | |
8487 | { | |
8488 | /* Plain overloading: will not be grok'd by grokclassfn. */ | |
8489 | declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0); | |
8490 | was_overloaded = 1; | |
8491 | } | |
8492 | } | |
8493 | else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2) | |
8494 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
8495 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
8496 | ||
8497 | /* Record presence of `static'. In C++, `inline' is like `static'. | |
8498 | Methods of classes should be public, unless we're dropping them | |
8499 | into some other file, so we don't clear TREE_PUBLIC for them. */ | |
8500 | publicp | |
8501 | = ((ctype | |
8502 | && ! CLASSTYPE_INTERFACE_UNKNOWN (ctype) | |
8503 | && ! CLASSTYPE_INTERFACE_ONLY (ctype)) | |
8504 | || !(specbits & (RIDBIT (RID_STATIC) | |
8505 | | RIDBIT (RID_INLINE)))); | |
8506 | ||
8507 | decl = grokfndecl (ctype, type, original_name, | |
8508 | virtualp, flags, quals, | |
8509 | raises, | |
8510 | processing_template_decl ? 0 : friendp ? 2 : 1, | |
8511 | publicp); | |
8512 | ||
8513 | if (ctype == NULL_TREE) | |
8514 | DECL_ASSEMBLER_NAME (decl) = declarator; | |
8515 | ||
8516 | if (staticp == 1) | |
8517 | { | |
8518 | int illegal_static = 0; | |
8519 | ||
8520 | /* Don't allow a static member function in a class, and forbid | |
8521 | declaring main to be static. */ | |
8522 | if (TREE_CODE (type) == METHOD_TYPE) | |
8523 | { | |
8524 | error_with_decl (decl, | |
8525 | "cannot declare member function `%s' to have static linkage"); | |
8526 | illegal_static = 1; | |
8527 | } | |
8528 | else if (! was_overloaded | |
8529 | && ! ctype | |
8530 | && IDENTIFIER_LENGTH (original_name) == 4 | |
8531 | && IDENTIFIER_POINTER (original_name)[0] == 'm' | |
8532 | && ! strcmp (IDENTIFIER_POINTER (original_name), "main")) | |
8533 | { | |
8534 | error ("cannot declare function `main' to have static linkage"); | |
8535 | illegal_static = 1; | |
8536 | } | |
8537 | ||
8538 | if (illegal_static) | |
8539 | { | |
8540 | staticp = 0; | |
8541 | specbits &= ~ RIDBIT (RID_STATIC); | |
8542 | } | |
8543 | } | |
8544 | ||
8545 | /* Record presence of `inline', if it is reasonable. */ | |
8546 | if (inlinep) | |
8547 | { | |
8548 | tree last = tree_last (TYPE_ARG_TYPES (type)); | |
8549 | ||
8550 | if (! was_overloaded | |
8551 | && ! ctype | |
8552 | && ! strcmp (IDENTIFIER_POINTER (original_name), "main")) | |
8553 | warning ("cannot inline function `main'"); | |
8554 | else if (last && last != void_list_node) | |
8555 | warning ("inline declaration ignored for function with `...'"); | |
8556 | else | |
8557 | /* Assume that otherwise the function can be inlined. */ | |
8558 | DECL_INLINE (decl) = 1; | |
8559 | ||
8560 | if (specbits & RIDBIT (RID_EXTERN)) | |
8561 | { | |
8562 | current_extern_inline = 1; | |
8563 | if (pedantic) | |
8564 | error ("ANSI C++ does not permit `extern inline'"); | |
8565 | else if (flag_ansi) | |
8566 | warning ("ANSI C++ does not permit `extern inline'"); | |
8567 | } | |
8568 | } | |
8569 | if (was_overloaded) | |
8570 | DECL_OVERLOADED (decl) = 1; | |
8571 | } | |
8572 | else | |
8573 | { | |
8574 | /* It's a variable. */ | |
8575 | ||
8576 | bad_specifiers ("variable", virtualp, quals != NULL_TREE, | |
8577 | friendp, raises != NULL_TREE); | |
8578 | if (inlinep) | |
8579 | warning ("variable declared `inline'"); | |
8580 | ||
8581 | /* An uninitialized decl with `extern' is a reference. */ | |
8582 | decl = grokvardecl (type, declarator, specbits, initialized); | |
8583 | if (ctype) | |
8584 | { | |
8585 | if (staticp == 1) | |
8586 | { | |
8587 | error ("cannot declare member `%s' to have static linkage", | |
8588 | lang_printable_name (decl)); | |
8589 | staticp = 0; | |
8590 | specbits &= ~ RIDBIT (RID_STATIC); | |
8591 | } | |
8592 | if (specbits & RIDBIT (RID_EXTERN)) | |
8593 | { | |
8594 | error ("cannot explicitly declare member `%s' to have extern linkage", | |
8595 | lang_printable_name (decl)); | |
8596 | specbits &= ~ RIDBIT (RID_EXTERN); | |
8597 | } | |
8598 | } | |
8599 | } | |
8600 | ||
8601 | /* Record `register' declaration for warnings on & | |
8602 | and in case doing stupid register allocation. */ | |
8603 | ||
8604 | if (specbits & RIDBIT (RID_REGISTER)) | |
8605 | DECL_REGISTER (decl) = 1; | |
8606 | ||
8607 | /* Record constancy and volatility. */ | |
8608 | ||
8609 | if (constp) | |
8610 | TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE; | |
8611 | if (volatilep) | |
8612 | { | |
8613 | TREE_SIDE_EFFECTS (decl) = 1; | |
8614 | TREE_THIS_VOLATILE (decl) = 1; | |
8615 | } | |
8616 | ||
8617 | return decl; | |
8618 | } | |
8619 | } | |
8620 | \f | |
8621 | /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist. | |
8622 | An empty exprlist is a parmlist. An exprlist which | |
8623 | contains only identifiers at the global level | |
8624 | is a parmlist. Otherwise, it is an exprlist. */ | |
8625 | int | |
8626 | parmlist_is_exprlist (exprs) | |
8627 | tree exprs; | |
8628 | { | |
8629 | if (exprs == NULL_TREE || TREE_PARMLIST (exprs)) | |
8630 | return 0; | |
8631 | ||
8632 | if (current_binding_level == global_binding_level) | |
8633 | { | |
8634 | /* At the global level, if these are all identifiers, | |
8635 | then it is a parmlist. */ | |
8636 | while (exprs) | |
8637 | { | |
8638 | if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE) | |
8639 | return 1; | |
8640 | exprs = TREE_CHAIN (exprs); | |
8641 | } | |
8642 | return 0; | |
8643 | } | |
8644 | return 1; | |
8645 | } | |
8646 | ||
8647 | /* Make sure that the this list of PARMS has a chance of being | |
8648 | grokked by `grokparms'. | |
8649 | ||
8650 | @@ This is really weak, but the grammar does not allow us | |
8651 | @@ to easily reject things that this has to catch as syntax errors. */ | |
8652 | static int | |
8653 | parmlist_is_random (parms) | |
8654 | tree parms; | |
8655 | { | |
8656 | if (parms == NULL_TREE) | |
8657 | return 0; | |
8658 | ||
8659 | if (TREE_CODE (parms) != TREE_LIST) | |
8660 | return 1; | |
8661 | ||
8662 | while (parms) | |
8663 | { | |
8664 | if (parms == void_list_node) | |
8665 | return 0; | |
8666 | ||
8667 | if (TREE_CODE (TREE_VALUE (parms)) != TREE_LIST) | |
8668 | return 1; | |
8669 | /* Don't get faked out by overloaded functions, which | |
8670 | masquerade as TREE_LISTs! */ | |
8671 | if (TREE_TYPE (TREE_VALUE (parms)) == unknown_type_node) | |
8672 | return 1; | |
8673 | parms = TREE_CHAIN (parms); | |
8674 | } | |
8675 | return 0; | |
8676 | } | |
8677 | ||
8678 | /* Subroutine of `grokparms'. In a fcn definition, arg types must | |
8679 | be complete. | |
8680 | ||
8681 | C++: also subroutine of `start_function'. */ | |
8682 | static void | |
8683 | require_complete_types_for_parms (parms) | |
8684 | tree parms; | |
8685 | { | |
8686 | while (parms) | |
8687 | { | |
8688 | tree type = TREE_TYPE (parms); | |
8689 | if (TYPE_SIZE (type) == NULL_TREE) | |
8690 | { | |
8691 | if (DECL_NAME (parms)) | |
8692 | error ("parameter `%s' has incomplete type", | |
8693 | IDENTIFIER_POINTER (DECL_NAME (parms))); | |
8694 | else | |
8695 | error ("parameter has incomplete type"); | |
8696 | TREE_TYPE (parms) = error_mark_node; | |
8697 | } | |
8698 | #if 0 | |
8699 | /* If the arg types are incomplete in a declaration, | |
8700 | they must include undefined tags. | |
8701 | These tags can never be defined in the scope of the declaration, | |
8702 | so the types can never be completed, | |
8703 | and no call can be compiled successfully. */ | |
8704 | /* This is not the right behavior for C++, but not having | |
8705 | it is also probably wrong. */ | |
8706 | else | |
8707 | { | |
8708 | /* Now warn if is a pointer to an incomplete type. */ | |
8709 | while (TREE_CODE (type) == POINTER_TYPE | |
8710 | || TREE_CODE (type) == REFERENCE_TYPE) | |
8711 | type = TREE_TYPE (type); | |
8712 | type = TYPE_MAIN_VARIANT (type); | |
8713 | if (TYPE_SIZE (type) == NULL_TREE) | |
8714 | { | |
8715 | if (DECL_NAME (parm) != NULL_TREE) | |
8716 | warning ("parameter `%s' points to incomplete type", | |
8717 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
8718 | else | |
8719 | warning ("parameter points to incomplete type"); | |
8720 | } | |
8721 | } | |
8722 | #endif | |
8723 | parms = TREE_CHAIN (parms); | |
8724 | } | |
8725 | } | |
8726 | ||
8727 | /* Decode the list of parameter types for a function type. | |
8728 | Given the list of things declared inside the parens, | |
8729 | return a list of types. | |
8730 | ||
8731 | The list we receive can have three kinds of elements: | |
8732 | an IDENTIFIER_NODE for names given without types, | |
8733 | a TREE_LIST node for arguments given as typespecs or names with typespecs, | |
8734 | or void_type_node, to mark the end of an argument list | |
8735 | when additional arguments are not permitted (... was not used). | |
8736 | ||
8737 | FUNCDEF_FLAG is nonzero for a function definition, 0 for | |
8738 | a mere declaration. A nonempty identifier-list gets an error message | |
8739 | when FUNCDEF_FLAG is zero. | |
8740 | If FUNCDEF_FLAG is 1, then parameter types must be complete. | |
8741 | If FUNCDEF_FLAG is -1, then parameter types may be incomplete. | |
8742 | ||
8743 | If all elements of the input list contain types, | |
8744 | we return a list of the types. | |
8745 | If all elements contain no type (except perhaps a void_type_node | |
8746 | at the end), we return a null list. | |
8747 | If some have types and some do not, it is an error, and we | |
8748 | return a null list. | |
8749 | ||
8750 | Also set last_function_parms to either | |
8751 | a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs. | |
8752 | A list of names is converted to a chain of PARM_DECLs | |
8753 | by store_parm_decls so that ultimately it is always a chain of decls. | |
8754 | ||
8755 | Note that in C++, parameters can take default values. These default | |
8756 | values are in the TREE_PURPOSE field of the TREE_LIST. It is | |
8757 | an error to specify default values which are followed by parameters | |
8758 | that have no default values, or an ELLIPSES. For simplicities sake, | |
8759 | only parameters which are specified with their types can take on | |
8760 | default values. */ | |
8761 | ||
8762 | static tree | |
8763 | grokparms (first_parm, funcdef_flag) | |
8764 | tree first_parm; | |
8765 | int funcdef_flag; | |
8766 | { | |
8767 | tree result = NULL_TREE; | |
8768 | tree decls = NULL_TREE; | |
8769 | ||
8770 | if (first_parm != NULL_TREE | |
8771 | && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) | |
8772 | { | |
8773 | if (! funcdef_flag) | |
8774 | warning ("parameter names (without types) in function declaration"); | |
8775 | last_function_parms = first_parm; | |
8776 | return NULL_TREE; | |
8777 | } | |
8778 | else | |
8779 | { | |
8780 | /* Types were specified. This is a list of declarators | |
8781 | each represented as a TREE_LIST node. */ | |
8782 | register tree parm, chain; | |
8783 | int any_init = 0, any_error = 0, saw_void = 0; | |
8784 | ||
8785 | if (first_parm != NULL_TREE) | |
8786 | { | |
8787 | tree last_result = NULL_TREE; | |
8788 | tree last_decl = NULL_TREE; | |
8789 | ||
8790 | for (parm = first_parm; parm != NULL_TREE; parm = chain) | |
8791 | { | |
8792 | tree type, list_node = parm; | |
8793 | register tree decl = TREE_VALUE (parm); | |
8794 | tree init = TREE_PURPOSE (parm); | |
8795 | ||
8796 | chain = TREE_CHAIN (parm); | |
8797 | /* @@ weak defense against parse errors. */ | |
8798 | if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST) | |
8799 | { | |
8800 | /* Give various messages as the need arises. */ | |
8801 | if (TREE_CODE (decl) == STRING_CST) | |
8802 | error ("invalid string constant `%s'", | |
8803 | TREE_STRING_POINTER (decl)); | |
8804 | else if (TREE_CODE (decl) == INTEGER_CST) | |
8805 | error ("invalid integer constant in parameter list, did you forget to give parameter name?"); | |
8806 | continue; | |
8807 | } | |
8808 | ||
8809 | if (decl != void_type_node) | |
8810 | { | |
8811 | /* @@ May need to fetch out a `raises' here. */ | |
8812 | decl = grokdeclarator (TREE_VALUE (decl), | |
8813 | TREE_PURPOSE (decl), | |
8814 | PARM, init != NULL_TREE, NULL_TREE); | |
8815 | if (! decl) | |
8816 | continue; | |
8817 | type = TREE_TYPE (decl); | |
8818 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
8819 | decl = void_type_node; | |
8820 | else if (TREE_CODE (type) == METHOD_TYPE) | |
8821 | { | |
8822 | if (DECL_NAME (decl)) | |
8823 | /* Cannot use `error_with_decl' here because | |
8824 | we don't have DECL_CONTEXT set up yet. */ | |
8825 | error ("parameter `%s' invalidly declared method type", | |
8826 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
8827 | else | |
8828 | error ("parameter invalidly declared method type"); | |
8829 | type = build_pointer_type (type); | |
8830 | TREE_TYPE (decl) = type; | |
8831 | } | |
8832 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
8833 | { | |
8834 | if (DECL_NAME (decl)) | |
8835 | error ("parameter `%s' invalidly declared offset type", | |
8836 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
8837 | else | |
8838 | error ("parameter invalidly declared offset type"); | |
8839 | type = build_pointer_type (type); | |
8840 | TREE_TYPE (decl) = type; | |
8841 | } | |
8842 | else if (TREE_CODE (type) == RECORD_TYPE | |
8843 | && TYPE_LANG_SPECIFIC (type) | |
8844 | && CLASSTYPE_ABSTRACT_VIRTUALS (type)) | |
8845 | { | |
8846 | abstract_virtuals_error (decl, type); | |
8847 | any_error = 1; /* seems like a good idea */ | |
8848 | } | |
8849 | } | |
8850 | ||
8851 | if (decl == void_type_node) | |
8852 | { | |
8853 | if (result == NULL_TREE) | |
8854 | { | |
8855 | result = void_list_node; | |
8856 | last_result = result; | |
8857 | } | |
8858 | else | |
8859 | { | |
8860 | TREE_CHAIN (last_result) = void_list_node; | |
8861 | last_result = void_list_node; | |
8862 | } | |
8863 | saw_void = 1; | |
8864 | if (chain | |
8865 | && (chain != void_list_node || TREE_CHAIN (chain))) | |
8866 | error ("`void' in parameter list must be entire list"); | |
8867 | break; | |
8868 | } | |
8869 | ||
8870 | /* Since there is a prototype, args are passed in their own types. */ | |
8871 | DECL_ARG_TYPE (decl) = TREE_TYPE (decl); | |
8872 | #ifdef PROMOTE_PROTOTYPES | |
8873 | if (C_PROMOTING_INTEGER_TYPE_P (type)) | |
8874 | DECL_ARG_TYPE (decl) = integer_type_node; | |
8875 | #endif | |
8876 | if (!any_error) | |
8877 | { | |
8878 | if (init) | |
8879 | { | |
8880 | any_init++; | |
8881 | if (TREE_CODE (init) == SAVE_EXPR) | |
8882 | PARM_DECL_EXPR (init) = 1; | |
8883 | else if (TREE_CODE (init) == VAR_DECL) | |
8884 | { | |
8885 | if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init))) | |
8886 | { | |
8887 | /* ``Local variables may not be used in default | |
8888 | argument expressions.'' dpANSI C++ 8.2.6 */ | |
8889 | /* If extern int i; within a function is not | |
8890 | considered a local variable, then this code is | |
8891 | wrong. */ | |
8892 | error_with_decl (init, "local variable `%s' may not be used as a default argument"); | |
8893 | any_error = 1; | |
8894 | } | |
8895 | else if (TREE_READONLY_DECL_P (init)) | |
8896 | init = decl_constant_value (init); | |
8897 | } | |
8898 | else | |
8899 | init = require_instantiated_type (type, init, integer_zero_node); | |
8900 | } | |
8901 | else if (any_init) | |
8902 | { | |
8903 | error ("all trailing parameters must have default arguments"); | |
8904 | any_error = 1; | |
8905 | } | |
8906 | } | |
8907 | else | |
8908 | init = NULL_TREE; | |
8909 | ||
8910 | if (decls == NULL_TREE) | |
8911 | { | |
8912 | decls = decl; | |
8913 | last_decl = decls; | |
8914 | } | |
8915 | else | |
8916 | { | |
8917 | TREE_CHAIN (last_decl) = decl; | |
8918 | last_decl = decl; | |
8919 | } | |
8920 | if (TREE_PERMANENT (list_node)) | |
8921 | { | |
8922 | TREE_PURPOSE (list_node) = init; | |
8923 | TREE_VALUE (list_node) = type; | |
8924 | TREE_CHAIN (list_node) = NULL_TREE; | |
8925 | } | |
8926 | else | |
8927 | list_node = saveable_tree_cons (init, type, NULL_TREE); | |
8928 | if (result == NULL_TREE) | |
8929 | { | |
8930 | result = list_node; | |
8931 | last_result = result; | |
8932 | } | |
8933 | else | |
8934 | { | |
8935 | TREE_CHAIN (last_result) = list_node; | |
8936 | last_result = list_node; | |
8937 | } | |
8938 | } | |
8939 | if (last_result) | |
8940 | TREE_CHAIN (last_result) = NULL_TREE; | |
8941 | /* If there are no parameters, and the function does not end | |
8942 | with `...', then last_decl will be NULL_TREE. */ | |
8943 | if (last_decl != NULL_TREE) | |
8944 | TREE_CHAIN (last_decl) = NULL_TREE; | |
8945 | } | |
8946 | } | |
8947 | ||
8948 | last_function_parms = decls; | |
8949 | ||
8950 | /* In a fcn definition, arg types must be complete. */ | |
8951 | if (funcdef_flag > 0) | |
8952 | require_complete_types_for_parms (last_function_parms); | |
8953 | ||
8954 | return result; | |
8955 | } | |
8956 | \f | |
8957 | /* These memoizing functions keep track of special properties which | |
8958 | a class may have. `grok_ctor_properties' notices whether a class | |
8959 | has a constructor of the for X(X&), and also complains | |
8960 | if the class has a constructor of the form X(X). | |
8961 | `grok_op_properties' takes notice of the various forms of | |
8962 | operator= which are defined, as well as what sorts of type conversion | |
8963 | may apply. Both functions take a FUNCTION_DECL as an argument. */ | |
8964 | void | |
8965 | grok_ctor_properties (ctype, decl) | |
8966 | tree ctype, decl; | |
8967 | { | |
8968 | tree parmtypes = FUNCTION_ARG_CHAIN (decl); | |
8969 | tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; | |
8970 | ||
8971 | if (parmtypes && TREE_CHAIN (parmtypes) | |
8972 | && TREE_CODE (TREE_VALUE (TREE_CHAIN (parmtypes))) == REFERENCE_TYPE | |
8973 | && TYPE_USES_VIRTUAL_BASECLASSES (TREE_TYPE (TREE_VALUE (TREE_CHAIN (parmtypes))))) | |
8974 | { | |
8975 | parmtypes = TREE_CHAIN (parmtypes); | |
8976 | parmtype = TREE_VALUE (parmtypes); | |
8977 | } | |
8978 | ||
8979 | if (TREE_CODE (parmtype) == REFERENCE_TYPE | |
8980 | && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype) | |
8981 | { | |
8982 | if (TREE_CHAIN (parmtypes) == NULL_TREE | |
8983 | || TREE_CHAIN (parmtypes) == void_list_node | |
8984 | || TREE_PURPOSE (TREE_CHAIN (parmtypes))) | |
8985 | { | |
8986 | TYPE_HAS_INIT_REF (ctype) = 1; | |
8987 | TYPE_GETS_INIT_REF (ctype) = 1; | |
8988 | if (TYPE_READONLY (TREE_TYPE (parmtype))) | |
8989 | TYPE_GETS_CONST_INIT_REF (ctype) = 1; | |
8990 | } | |
8991 | else | |
8992 | TYPE_GETS_INIT_AGGR (ctype) = 1; | |
8993 | } | |
8994 | else if (TYPE_MAIN_VARIANT (parmtype) == ctype) | |
8995 | { | |
8996 | if (TREE_CHAIN (parmtypes) != NULL_TREE | |
8997 | && TREE_CHAIN (parmtypes) == void_list_node) | |
8998 | error ("invalid constructor; you probably meant `%s (%s&)'", | |
8999 | TYPE_NAME_STRING (ctype), | |
9000 | TYPE_NAME_STRING (ctype)); | |
9001 | SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); | |
9002 | TYPE_GETS_INIT_AGGR (ctype) = 1; | |
9003 | } | |
9004 | else if (TREE_CODE (parmtype) == VOID_TYPE | |
9005 | || TREE_PURPOSE (parmtypes) != NULL_TREE) | |
9006 | TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; | |
9007 | } | |
9008 | ||
9009 | /* Do a little sanity-checking on how they declared their operator. */ | |
9010 | static void | |
9011 | grok_op_properties (decl, virtualp) | |
9012 | tree decl; | |
9013 | int virtualp; | |
9014 | { | |
9015 | tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
9016 | ||
9017 | if (DECL_STATIC_FUNCTION_P (decl)) | |
9018 | { | |
9019 | if (DECL_NAME (decl) == ansi_opname[(int) NEW_EXPR]) | |
9020 | { | |
9021 | if (virtualp) | |
9022 | error ("`operator new' cannot be declared virtual"); | |
9023 | ||
9024 | /* Take care of function decl if we had syntax errors. */ | |
9025 | if (argtypes == NULL_TREE) | |
9026 | TREE_TYPE (decl) = | |
9027 | build_function_type (ptr_type_node, | |
9028 | hash_tree_chain (integer_type_node, | |
9029 | void_list_node)); | |
9030 | else | |
9031 | decl = coerce_new_type (TREE_TYPE (decl)); | |
9032 | } | |
9033 | else if (DECL_NAME (decl) == ansi_opname[(int) DELETE_EXPR]) | |
9034 | { | |
9035 | if (virtualp) | |
9036 | error ("`operator delete' cannot be declared virtual"); | |
9037 | ||
9038 | if (argtypes == NULL_TREE) | |
9039 | TREE_TYPE (decl) = | |
9040 | build_function_type (void_type_node, | |
9041 | hash_tree_chain (ptr_type_node, | |
9042 | void_list_node)); | |
9043 | else | |
9044 | decl = coerce_delete_type (TREE_TYPE (decl)); | |
9045 | } | |
9046 | else | |
9047 | error_with_decl (decl, "`%s' cannot be a static member function"); | |
9048 | } | |
9049 | else if (DECL_NAME (decl) == ansi_opname[(int) MODIFY_EXPR]) | |
9050 | { | |
9051 | tree parmtypes; | |
9052 | tree parmtype; | |
9053 | ||
9054 | if (argtypes == NULL_TREE) | |
9055 | { | |
9056 | error_with_decl (decl, "too few arguments to `%s'"); | |
9057 | return; | |
9058 | } | |
9059 | parmtypes = TREE_CHAIN (argtypes); | |
9060 | parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; | |
9061 | ||
9062 | if (TREE_CODE (parmtype) == REFERENCE_TYPE | |
9063 | && TREE_TYPE (parmtype) == current_class_type) | |
9064 | { | |
9065 | TYPE_HAS_ASSIGN_REF (current_class_type) = 1; | |
9066 | TYPE_GETS_ASSIGN_REF (current_class_type) = 1; | |
9067 | if (TYPE_READONLY (TREE_TYPE (parmtype))) | |
9068 | TYPE_GETS_CONST_INIT_REF (current_class_type) = 1; | |
9069 | } | |
9070 | } | |
9071 | } | |
9072 | \f | |
9073 | /* Get the struct, enum or union (CODE says which) with tag NAME. | |
9074 | Define the tag as a forward-reference if it is not defined. | |
9075 | ||
9076 | C++: If a class derivation is given, process it here, and report | |
9077 | an error if multiple derivation declarations are not identical. | |
9078 | ||
9079 | If this is a definition, come in through xref_tag and only look in | |
9080 | the current frame for the name (since C++ allows new names in any | |
9081 | scope.) */ | |
9082 | ||
9083 | /* avoid rewriting all callers of xref_tag */ | |
9084 | static int xref_next_defn = 0; | |
9085 | ||
9086 | tree | |
9087 | xref_defn_tag (code_type_node, name, binfo) | |
9088 | tree code_type_node; | |
9089 | tree name, binfo; | |
9090 | { | |
9091 | tree rv, ncp; | |
9092 | xref_next_defn = 1; | |
9093 | ||
9094 | if (class_binding_level) | |
9095 | { | |
9096 | tree n1; | |
9097 | char *buf; | |
9098 | /* we need to build a new IDENTIFIER_NODE for name which nukes | |
9099 | * the pieces... */ | |
9100 | n1 = IDENTIFIER_LOCAL_VALUE (current_class_name); | |
9101 | if (n1) | |
9102 | n1 = DECL_NAME (n1); | |
9103 | else | |
9104 | n1 = current_class_name; | |
9105 | ||
9106 | buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1) | |
9107 | + IDENTIFIER_LENGTH (name)); | |
9108 | ||
9109 | sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1), | |
9110 | IDENTIFIER_POINTER (name)); | |
9111 | ncp = get_identifier (buf); | |
9112 | #ifdef SPEW_DEBUG | |
9113 | if (spew_debug) | |
9114 | printf("*** %s ***\n", IDENTIFIER_POINTER (ncp)); | |
9115 | #endif | |
9116 | #if 0 | |
9117 | IDENTIFIER_LOCAL_VALUE (name) = | |
9118 | build_lang_decl (TYPE_DECL, ncp, NULL_TREE); | |
9119 | #endif | |
9120 | rv = xref_tag (code_type_node, name, binfo); | |
9121 | pushdecl_top_level (build_lang_decl (TYPE_DECL, ncp, rv)); | |
9122 | } | |
9123 | else | |
9124 | { | |
9125 | rv = xref_tag (code_type_node, name, binfo); | |
9126 | } | |
9127 | xref_next_defn = 0; | |
9128 | return rv; | |
9129 | } | |
9130 | ||
9131 | tree | |
9132 | xref_tag (code_type_node, name, binfo) | |
9133 | tree code_type_node; | |
9134 | tree name, binfo; | |
9135 | { | |
9136 | enum tag_types tag_code; | |
9137 | enum tree_code code; | |
9138 | int temp = 0; | |
9139 | int i, len; | |
9140 | register tree ref; | |
9141 | struct binding_level *b | |
9142 | = (class_binding_level ? class_binding_level : current_binding_level); | |
9143 | ||
9144 | tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); | |
9145 | switch (tag_code) | |
9146 | { | |
9147 | case record_type: | |
9148 | case class_type: | |
9149 | case exception_type: | |
9150 | code = RECORD_TYPE; | |
9151 | len = list_length (binfo); | |
9152 | break; | |
9153 | case union_type: | |
9154 | code = UNION_TYPE; | |
9155 | if (binfo) | |
9156 | { | |
9157 | error ("derived union `%s' invalid", IDENTIFIER_POINTER (name)); | |
9158 | binfo = NULL_TREE; | |
9159 | } | |
9160 | len = 0; | |
9161 | break; | |
9162 | case enum_type: | |
9163 | code = ENUMERAL_TYPE; | |
9164 | break; | |
9165 | default: | |
9166 | my_friendly_abort (18); | |
9167 | } | |
9168 | ||
9169 | /* If a cross reference is requested, look up the type | |
9170 | already defined for this tag and return it. */ | |
9171 | if (xref_next_defn) | |
9172 | { | |
9173 | /* If we know we are defining this tag, only look it up in this scope | |
9174 | * and don't try to find it as a type. */ | |
9175 | xref_next_defn = 0; | |
9176 | ref = lookup_tag (code, name, b, 1); | |
9177 | } | |
9178 | else | |
9179 | { | |
9180 | ref = lookup_tag (code, name, b, 0); | |
9181 | ||
9182 | if (! ref) | |
9183 | { | |
9184 | /* Try finding it as a type declaration. If that wins, use it. */ | |
9185 | ref = lookup_name (name, 1); | |
9186 | if (ref && TREE_CODE (ref) == TYPE_DECL | |
9187 | && TREE_CODE (TREE_TYPE (ref)) == code) | |
9188 | ref = TREE_TYPE (ref); | |
9189 | else | |
9190 | ref = NULL_TREE; | |
9191 | } | |
9192 | } | |
9193 | ||
9194 | push_obstacks_nochange (); | |
9195 | ||
9196 | if (! ref) | |
9197 | { | |
9198 | /* If no such tag is yet defined, create a forward-reference node | |
9199 | and record it as the "definition". | |
9200 | When a real declaration of this type is found, | |
9201 | the forward-reference will be altered into a real type. */ | |
9202 | ||
9203 | /* In C++, since these migrate into the global scope, we must | |
9204 | build them on the permanent obstack. */ | |
9205 | ||
9206 | temp = allocation_temporary_p (); | |
9207 | if (temp) | |
9208 | end_temporary_allocation (); | |
9209 | ||
9210 | if (code == ENUMERAL_TYPE) | |
9211 | { | |
9212 | ref = make_node (ENUMERAL_TYPE); | |
9213 | ||
9214 | /* Give the type a default layout like unsigned int | |
9215 | to avoid crashing if it does not get defined. */ | |
9216 | TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); | |
9217 | TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); | |
9218 | TREE_UNSIGNED (ref) = 1; | |
9219 | TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); | |
9220 | TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); | |
9221 | TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); | |
9222 | ||
9223 | /* Enable us to recognize when a type is created in class context. | |
9224 | To do nested classes correctly, this should probably be cleared | |
9225 | out when we leave this classes scope. Currently this in only | |
9226 | done in `start_enum'. */ | |
9227 | ||
9228 | pushtag (name, ref); | |
9229 | if (flag_cadillac) | |
9230 | cadillac_start_enum (ref); | |
9231 | } | |
9232 | else if (tag_code == exception_type) | |
9233 | { | |
9234 | ref = make_lang_type (code); | |
9235 | /* Enable us to recognize when an exception type is created in | |
9236 | class context. To do nested classes correctly, this should | |
9237 | probably be cleared out when we leave this class's scope. */ | |
9238 | CLASSTYPE_DECLARED_EXCEPTION (ref) = 1; | |
9239 | pushtag (name, ref); | |
9240 | if (flag_cadillac) | |
9241 | cadillac_start_struct (ref); | |
9242 | } | |
9243 | else | |
9244 | { | |
9245 | extern tree pending_vtables; | |
9246 | struct binding_level *old_b = class_binding_level; | |
9247 | int needs_writing; | |
9248 | ||
9249 | ref = make_lang_type (code); | |
9250 | ||
9251 | /* Record how to set the visibility of this class's | |
9252 | virtual functions. If write_virtuals == 2 or 3, then | |
9253 | inline virtuals are ``extern inline''. */ | |
9254 | switch (write_virtuals) | |
9255 | { | |
9256 | case 0: | |
9257 | case 1: | |
9258 | needs_writing = 1; | |
9259 | break; | |
9260 | case 2: | |
9261 | needs_writing = !! value_member (name, pending_vtables); | |
9262 | break; | |
9263 | case 3: | |
9264 | needs_writing | |
9265 | = ! (CLASSTYPE_INTERFACE_ONLY (ref) || CLASSTYPE_INTERFACE_UNKNOWN (ref)); | |
9266 | break; | |
9267 | default: | |
9268 | needs_writing = 0; | |
9269 | } | |
9270 | ||
9271 | CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing; | |
9272 | ||
9273 | #ifdef NONNESTED_CLASSES | |
9274 | /* Class types don't nest the way enums do. */ | |
9275 | class_binding_level = (struct binding_level *)0; | |
9276 | #endif | |
9277 | pushtag (name, ref); | |
9278 | class_binding_level = old_b; | |
9279 | ||
9280 | if (flag_cadillac) | |
9281 | cadillac_start_struct (ref); | |
9282 | } | |
9283 | } | |
9284 | else | |
9285 | { | |
9286 | if (IS_AGGR_TYPE_CODE (code)) | |
9287 | { | |
9288 | if (IS_AGGR_TYPE (ref) | |
9289 | && ((tag_code == exception_type) | |
9290 | != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1))) | |
9291 | { | |
9292 | error ("type `%s' is both exception and aggregate type", | |
9293 | IDENTIFIER_POINTER (name)); | |
9294 | CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type); | |
9295 | } | |
9296 | } | |
9297 | ||
9298 | /* If it no longer looks like a nested type, make sure it's | |
9299 | in global scope. */ | |
9300 | if (b == global_binding_level && !class_binding_level | |
9301 | && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE) | |
9302 | IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref); | |
9303 | ||
9304 | if (binfo) | |
9305 | { | |
9306 | tree tt1 = binfo; | |
9307 | tree tt2 = TYPE_BINFO_BASETYPES (ref); | |
9308 | ||
9309 | if (TYPE_BINFO_BASETYPES (ref)) | |
9310 | for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1)) | |
9311 | if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i)))) | |
9312 | { | |
9313 | error ("redeclaration of derivation chain of type `%s'", | |
9314 | IDENTIFIER_POINTER (name)); | |
9315 | break; | |
9316 | } | |
9317 | ||
9318 | if (tt1 == NULL_TREE) | |
9319 | /* The user told us something we already knew. */ | |
9320 | goto just_return; | |
9321 | ||
9322 | /* In C++, since these migrate into the global scope, we must | |
9323 | build them on the permanent obstack. */ | |
9324 | end_temporary_allocation (); | |
9325 | } | |
9326 | } | |
9327 | ||
9328 | if (binfo) | |
9329 | { | |
9330 | /* In the declaration `A : X, Y, ... Z' we mark all the types | |
9331 | (A, X, Y, ..., Z) so we can check for duplicates. */ | |
9332 | tree binfos; | |
9333 | ||
9334 | SET_CLASSTYPE_MARKED (ref); | |
9335 | BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len); | |
9336 | ||
9337 | for (i = 0; binfo; binfo = TREE_CHAIN (binfo)) | |
9338 | { | |
9339 | /* The base of a derived struct is public. */ | |
9340 | int via_public = (tag_code != class_type | |
9341 | || TREE_PURPOSE (binfo) == (tree)visibility_public | |
9342 | || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual); | |
9343 | int via_protected = TREE_PURPOSE (binfo) == (tree)visibility_protected; | |
9344 | int via_virtual = (TREE_PURPOSE (binfo) == (tree)visibility_private_virtual | |
9345 | || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual | |
9346 | || TREE_PURPOSE (binfo) == (tree)visibility_default_virtual); | |
9347 | tree basetype = TREE_TYPE (TREE_VALUE (binfo)); | |
9348 | tree base_binfo; | |
9349 | ||
9350 | GNU_xref_hier (IDENTIFIER_POINTER (name), | |
9351 | IDENTIFIER_POINTER (TREE_VALUE (binfo)), | |
9352 | via_public, via_virtual, 0); | |
9353 | ||
9354 | if (basetype && TREE_CODE (basetype) == TYPE_DECL) | |
9355 | basetype = TREE_TYPE (basetype); | |
9356 | if (!basetype || TREE_CODE (basetype) != RECORD_TYPE) | |
9357 | { | |
9358 | error ("base type `%s' fails to be a struct or class type", | |
9359 | IDENTIFIER_POINTER (TREE_VALUE (binfo))); | |
9360 | continue; | |
9361 | } | |
9362 | #if 1 | |
9363 | /* This code replaces similar code in layout_basetypes. */ | |
9364 | else if (TYPE_SIZE (basetype) == NULL_TREE) | |
9365 | { | |
9366 | error_with_aggr_type (basetype, "base class `%s' has incomplete type"); | |
9367 | continue; | |
9368 | } | |
9369 | #endif | |
9370 | else | |
9371 | { | |
9372 | if (CLASSTYPE_MARKED (basetype)) | |
9373 | { | |
9374 | if (basetype == ref) | |
9375 | error_with_aggr_type (basetype, "recursive type `%s' undefined"); | |
9376 | else | |
9377 | error_with_aggr_type (basetype, "duplicate base type `%s' invalid"); | |
9378 | continue; | |
9379 | } | |
9380 | ||
9381 | /* Note that the BINFO records which describe individual | |
9382 | inheritances are *not* shared in the lattice! They | |
9383 | cannot be shared because a given baseclass may be | |
9384 | inherited with different `accessibility' by different | |
9385 | derived classes. (Each BINFO record describing an | |
9386 | individual inheritance contains flags which say what | |
9387 | the `accessibility' of that particular inheritance is.) */ | |
9388 | ||
9389 | base_binfo = make_binfo (integer_zero_node, basetype, | |
9390 | TYPE_BINFO_VTABLE (basetype), | |
9391 | TYPE_BINFO_VIRTUALS (basetype), 0); | |
9392 | ||
9393 | TREE_VEC_ELT (binfos, i) = base_binfo; | |
9394 | TREE_VIA_PUBLIC (base_binfo) = via_public; | |
9395 | TREE_VIA_PROTECTED (base_binfo) = via_protected; | |
9396 | TREE_VIA_VIRTUAL (base_binfo) = via_virtual; | |
9397 | ||
9398 | SET_CLASSTYPE_MARKED (basetype); | |
9399 | #if 0 | |
9400 | /* XYZZY TEST VIRTUAL BASECLASSES */ | |
9401 | if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE | |
9402 | && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype) | |
9403 | && via_virtual == 0) | |
9404 | { | |
9405 | warning ("making type `%s' a virtual baseclass", | |
9406 | TYPE_NAME_STRING (basetype)); | |
9407 | via_virtual = 1; | |
9408 | } | |
9409 | #endif | |
9410 | /* We are free to modify these bits because they are meaningless | |
9411 | at top level, and BASETYPE is a top-level type. */ | |
9412 | if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) | |
9413 | { | |
9414 | TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1; | |
9415 | TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; | |
9416 | } | |
9417 | ||
9418 | TYPE_GETS_ASSIGNMENT (ref) |= TYPE_GETS_ASSIGNMENT (basetype); | |
9419 | TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype); | |
9420 | TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype); | |
9421 | TREE_GETS_DELETE (ref) |= TREE_GETS_DELETE (basetype); | |
9422 | CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype); | |
9423 | i += 1; | |
9424 | } | |
9425 | } | |
9426 | if (i) | |
9427 | TREE_VEC_LENGTH (binfos) = i; | |
9428 | else | |
9429 | BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE; | |
9430 | ||
9431 | if (i > 1) | |
9432 | TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; | |
9433 | else if (i == 1) | |
9434 | TYPE_USES_MULTIPLE_INHERITANCE (ref) | |
9435 | = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0))); | |
9436 | if (TYPE_USES_MULTIPLE_INHERITANCE (ref)) | |
9437 | TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; | |
9438 | ||
9439 | /* Unmark all the types. */ | |
9440 | while (--i >= 0) | |
9441 | CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i))); | |
9442 | CLEAR_CLASSTYPE_MARKED (ref); | |
9443 | } | |
9444 | ||
9445 | just_return: | |
9446 | ||
9447 | /* Until the type is defined, tentatively accept whatever | |
9448 | structure tag the user hands us. */ | |
9449 | if (TYPE_SIZE (ref) == NULL_TREE | |
9450 | && ref != current_class_type | |
9451 | /* Have to check this, in case we have contradictory tag info. */ | |
9452 | && IS_AGGR_TYPE_CODE (TREE_CODE (ref))) | |
9453 | { | |
9454 | if (tag_code == class_type) | |
9455 | CLASSTYPE_DECLARED_CLASS (ref) = 1; | |
9456 | else if (tag_code == record_type) | |
9457 | CLASSTYPE_DECLARED_CLASS (ref) = 0; | |
9458 | } | |
9459 | ||
9460 | pop_obstacks (); | |
9461 | ||
9462 | return ref; | |
9463 | } | |
9464 | \f | |
9465 | static tree current_local_enum = NULL_TREE; | |
9466 | ||
9467 | /* Begin compiling the definition of an enumeration type. | |
9468 | NAME is its name (or null if anonymous). | |
9469 | Returns the type object, as yet incomplete. | |
9470 | Also records info about it so that build_enumerator | |
9471 | may be used to declare the individual values as they are read. */ | |
9472 | ||
9473 | tree | |
9474 | start_enum (name) | |
9475 | tree name; | |
9476 | { | |
9477 | register tree enumtype = NULL_TREE; | |
9478 | struct binding_level *b | |
9479 | = (class_binding_level ? class_binding_level : current_binding_level); | |
9480 | ||
9481 | /* If this is the real definition for a previous forward reference, | |
9482 | fill in the contents in the same object that used to be the | |
9483 | forward reference. */ | |
9484 | ||
9485 | if (name != NULL_TREE) | |
9486 | enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); | |
9487 | ||
9488 | if (enumtype == NULL_TREE || TREE_CODE (enumtype) != ENUMERAL_TYPE) | |
9489 | { | |
9490 | enumtype = make_node (ENUMERAL_TYPE); | |
9491 | pushtag (name, enumtype); | |
9492 | } | |
9493 | ||
9494 | if (current_class_type) | |
9495 | TREE_ADDRESSABLE (b->tags) = 1; | |
9496 | current_local_enum = NULL_TREE; | |
9497 | ||
9498 | if (TYPE_VALUES (enumtype) != NULL_TREE) | |
9499 | { | |
9500 | /* This enum is a named one that has been declared already. */ | |
9501 | error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name)); | |
9502 | ||
9503 | /* Completely replace its old definition. | |
9504 | The old enumerators remain defined, however. */ | |
9505 | TYPE_VALUES (enumtype) = NULL_TREE; | |
9506 | } | |
9507 | ||
9508 | /* Initially, set up this enum as like `int' | |
9509 | so that we can create the enumerators' declarations and values. | |
9510 | Later on, the precision of the type may be changed and | |
9511 | it may be laid out again. */ | |
9512 | ||
9513 | TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); | |
9514 | TYPE_SIZE (enumtype) = NULL_TREE; | |
9515 | fixup_unsigned_type (enumtype); | |
9516 | ||
9517 | /* We copy this value because enumerated type constants | |
9518 | are really of the type of the enumerator, not integer_type_node. */ | |
9519 | enum_next_value = copy_node (integer_zero_node); | |
9520 | ||
9521 | GNU_xref_decl (current_function_decl, enumtype); | |
9522 | return enumtype; | |
9523 | } | |
9524 | ||
9525 | /* After processing and defining all the values of an enumeration type, | |
9526 | install their decls in the enumeration type and finish it off. | |
9527 | ENUMTYPE is the type object and VALUES a list of name-value pairs. | |
9528 | Returns ENUMTYPE. */ | |
9529 | ||
9530 | tree | |
9531 | finish_enum (enumtype, values) | |
9532 | register tree enumtype, values; | |
9533 | { | |
9534 | register tree pair; | |
9535 | register HOST_WIDE_INT maxvalue = 0; | |
9536 | register HOST_WIDE_INT minvalue = 0; | |
9537 | register HOST_WIDE_INT i; | |
9538 | ||
9539 | TYPE_VALUES (enumtype) = values; | |
9540 | ||
9541 | /* Calculate the maximum value of any enumerator in this type. */ | |
9542 | ||
9543 | if (values) | |
9544 | { | |
9545 | /* Speed up the main loop by performing some precalculations */ | |
9546 | ||
9547 | HOST_WIDE_INT value = TREE_INT_CST_LOW (TREE_VALUE (values)); | |
9548 | TREE_TYPE (TREE_VALUE (values)) = enumtype; | |
9549 | minvalue = maxvalue = value; | |
9550 | ||
9551 | for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) | |
9552 | { | |
9553 | value = TREE_INT_CST_LOW (TREE_VALUE (pair)); | |
9554 | if (value > maxvalue) | |
9555 | maxvalue = value; | |
9556 | else if (value < minvalue) | |
9557 | minvalue = value; | |
9558 | TREE_TYPE (TREE_VALUE (pair)) = enumtype; | |
9559 | } | |
9560 | } | |
9561 | ||
9562 | if (flag_short_enums) | |
9563 | { | |
9564 | /* Determine the precision this type needs, lay it out, and define it. */ | |
9565 | ||
9566 | for (i = maxvalue; i; i >>= 1) | |
9567 | TYPE_PRECISION (enumtype)++; | |
9568 | ||
9569 | if (!TYPE_PRECISION (enumtype)) | |
9570 | TYPE_PRECISION (enumtype) = 1; | |
9571 | ||
9572 | /* Cancel the laying out previously done for the enum type, | |
9573 | so that fixup_unsigned_type will do it over. */ | |
9574 | TYPE_SIZE (enumtype) = NULL_TREE; | |
9575 | ||
9576 | fixup_unsigned_type (enumtype); | |
9577 | } | |
9578 | ||
9579 | TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue; | |
9580 | ||
9581 | /* An enum can have some negative values; then it is signed. */ | |
9582 | if (minvalue < 0) | |
9583 | { | |
9584 | TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue; | |
9585 | TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1; | |
9586 | TREE_UNSIGNED (enumtype) = 0; | |
9587 | } | |
9588 | if (flag_cadillac) | |
9589 | cadillac_finish_enum (enumtype); | |
9590 | ||
9591 | /* Finish debugging output for this type. */ | |
9592 | #if 0 | |
9593 | /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging | |
9594 | information should *not* be generated? I think not. */ | |
9595 | if (! DECL_IGNORED_P (TYPE_NAME (enumtype))) | |
9596 | #endif | |
9597 | rest_of_type_compilation (enumtype, global_bindings_p ()); | |
9598 | ||
9599 | return enumtype; | |
9600 | } | |
9601 | ||
9602 | /* Build and install a CONST_DECL for one value of the | |
9603 | current enumeration type (one that was begun with start_enum). | |
9604 | Return a tree-list containing the name and its value. | |
9605 | Assignment of sequential values by default is handled here. */ | |
9606 | ||
9607 | tree | |
9608 | build_enumerator (name, value) | |
9609 | tree name, value; | |
9610 | { | |
9611 | tree decl, result; | |
9612 | /* Change this to zero if we find VALUE is not shareable. */ | |
9613 | int shareable = 1; | |
9614 | ||
9615 | /* Remove no-op casts from the value. */ | |
9616 | if (value) | |
9617 | STRIP_TYPE_NOPS (value); | |
9618 | ||
9619 | /* Validate and default VALUE. */ | |
9620 | if (value != NULL_TREE) | |
9621 | { | |
9622 | if (TREE_READONLY_DECL_P (value)) | |
9623 | { | |
9624 | value = decl_constant_value (value); | |
9625 | shareable = 0; | |
9626 | } | |
9627 | ||
9628 | if (TREE_CODE (value) != INTEGER_CST) | |
9629 | { | |
9630 | error ("enumerator value for `%s' not integer constant", | |
9631 | IDENTIFIER_POINTER (name)); | |
9632 | value = NULL_TREE; | |
9633 | } | |
9634 | } | |
9635 | /* The order of things is reversed here so that we | |
9636 | can check for possible sharing of enum values, | |
9637 | to keep that from happening. */ | |
9638 | /* Default based on previous value. */ | |
9639 | if (value == NULL_TREE) | |
9640 | value = enum_next_value; | |
9641 | ||
9642 | /* Remove no-op casts from the value. */ | |
9643 | if (value) | |
9644 | STRIP_TYPE_NOPS (value); | |
9645 | ||
9646 | /* Make up for hacks in cp-lex.c. */ | |
9647 | if (value == integer_zero_node) | |
9648 | value = build_int_2 (0, 0); | |
9649 | else if (value == integer_one_node) | |
9650 | value = build_int_2 (1, 0); | |
9651 | else if (TREE_CODE (value) == INTEGER_CST | |
9652 | && (shareable == 0 | |
9653 | || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)) | |
9654 | { | |
9655 | value = copy_node (value); | |
9656 | TREE_TYPE (value) = integer_type_node; | |
9657 | } | |
9658 | ||
9659 | result = saveable_tree_cons (name, value, NULL_TREE); | |
9660 | ||
9661 | /* C++ associates enums with global, function, or class declarations. */ | |
9662 | if (current_class_type == NULL_TREE || current_function_decl != NULL_TREE) | |
9663 | { | |
9664 | /* Create a declaration for the enum value name. */ | |
9665 | ||
9666 | decl = build_decl (CONST_DECL, name, integer_type_node); | |
9667 | DECL_INITIAL (decl) = value; | |
9668 | ||
9669 | pushdecl (decl); | |
9670 | GNU_xref_decl (current_function_decl, decl); | |
9671 | } | |
9672 | ||
9673 | if (current_class_type) | |
9674 | { | |
9675 | /* class-local enum declaration */ | |
9676 | decl = build_lang_field_decl (CONST_DECL, name, integer_type_node); | |
9677 | DECL_INITIAL (decl) = value; | |
9678 | TREE_READONLY (decl) = 1; | |
9679 | pushdecl_class_level (decl); | |
9680 | TREE_CHAIN (decl) = current_local_enum; | |
9681 | current_local_enum = decl; | |
9682 | } | |
9683 | ||
9684 | /* Set basis for default for next value. */ | |
9685 | enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, | |
9686 | integer_one_node, PLUS_EXPR); | |
9687 | if (enum_next_value == integer_one_node) | |
9688 | enum_next_value = copy_node (enum_next_value); | |
9689 | ||
9690 | return result; | |
9691 | } | |
9692 | ||
9693 | tree | |
9694 | grok_enum_decls (type, decl) | |
9695 | tree type, decl; | |
9696 | { | |
9697 | tree d = current_local_enum; | |
9698 | ||
9699 | if (d == NULL_TREE) | |
9700 | return decl; | |
9701 | ||
9702 | while (1) | |
9703 | { | |
9704 | TREE_TYPE (d) = type; | |
9705 | if (TREE_CHAIN (d) == NULL_TREE) | |
9706 | { | |
9707 | TREE_CHAIN (d) = decl; | |
9708 | break; | |
9709 | } | |
9710 | d = TREE_CHAIN (d); | |
9711 | } | |
9712 | ||
9713 | decl = current_local_enum; | |
9714 | current_local_enum = NULL_TREE; | |
9715 | ||
9716 | return decl; | |
9717 | } | |
9718 | \f | |
9719 | /* Create the FUNCTION_DECL for a function definition. | |
9720 | DECLSPECS and DECLARATOR are the parts of the declaration; | |
9721 | they describe the function's name and the type it returns, | |
9722 | but twisted together in a fashion that parallels the syntax of C. | |
9723 | ||
9724 | This function creates a binding context for the function body | |
9725 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
9726 | ||
9727 | Returns 1 on success. If the DECLARATOR is not suitable for a function | |
9728 | (it defines a datum instead), we return 0, which tells | |
9729 | yyparse to report a parse error. | |
9730 | ||
9731 | For C++, we must first check whether that datum makes any sense. | |
9732 | For example, "class A local_a(1,2);" means that variable local_a | |
9733 | is an aggregate of type A, which should have a constructor | |
9734 | applied to it with the argument list [1, 2]. | |
9735 | ||
9736 | @@ There is currently no way to retrieve the storage | |
9737 | @@ allocated to FUNCTION (or all of its parms) if we return | |
9738 | @@ something we had previously. */ | |
9739 | ||
9740 | int | |
9741 | start_function (declspecs, declarator, raises, pre_parsed_p) | |
9742 | tree declarator, declspecs, raises; | |
9743 | int pre_parsed_p; | |
9744 | { | |
9745 | extern tree EHS_decl; | |
9746 | tree decl1, olddecl; | |
9747 | tree ctype = NULL_TREE; | |
9748 | tree fntype; | |
9749 | tree restype; | |
9750 | extern int have_extern_spec; | |
9751 | extern int used_extern_spec; | |
9752 | int doing_friend = 0; | |
9753 | ||
9754 | if (flag_handle_exceptions && EHS_decl == NULL_TREE) | |
9755 | init_exception_processing_1 (); | |
9756 | ||
9757 | /* Sanity check. */ | |
9758 | my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160); | |
9759 | my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); | |
9760 | ||
9761 | /* Assume, until we see it does. */ | |
9762 | current_function_returns_value = 0; | |
9763 | current_function_returns_null = 0; | |
9764 | warn_about_return_type = 0; | |
9765 | current_extern_inline = 0; | |
9766 | current_function_assigns_this = 0; | |
9767 | current_function_just_assigned_this = 0; | |
9768 | current_function_parms_stored = 0; | |
9769 | original_result_rtx = NULL_RTX; | |
9770 | current_function_obstack_index = 0; | |
9771 | current_function_obstack_usage = 0; | |
9772 | ||
9773 | clear_temp_name (); | |
9774 | ||
9775 | /* This should only be done once on the top most decl. */ | |
9776 | if (have_extern_spec && !used_extern_spec) | |
9777 | { | |
9778 | declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); | |
9779 | used_extern_spec = 1; | |
9780 | } | |
9781 | ||
9782 | if (pre_parsed_p) | |
9783 | { | |
9784 | decl1 = declarator; | |
9785 | last_function_parms = DECL_ARGUMENTS (decl1); | |
9786 | last_function_parm_tags = NULL_TREE; | |
9787 | fntype = TREE_TYPE (decl1); | |
9788 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
9789 | ctype = TYPE_METHOD_BASETYPE (fntype); | |
9790 | ||
9791 | /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a | |
9792 | class is in the (lexical) scope of the class in which it is | |
9793 | defined. */ | |
9794 | if (!ctype && DECL_FRIEND_P (decl1)) | |
9795 | { | |
9796 | ctype = TREE_TYPE (TREE_CHAIN (decl1)); | |
2a5f595d PR |
9797 | |
9798 | /* CTYPE could be null here if we're dealing with a template; | |
9799 | for example, `inline friend float foo()' inside a template | |
9800 | will have no CTYPE set. */ | |
9801 | if (ctype && TREE_CODE (ctype) != RECORD_TYPE) | |
9bf86ebb PR |
9802 | ctype = NULL_TREE; |
9803 | else | |
9804 | doing_friend = 1; | |
9805 | } | |
9806 | ||
9807 | if ( !(DECL_VINDEX (decl1) | |
9808 | && write_virtuals >= 2 | |
9809 | && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype))) | |
9810 | current_extern_inline = TREE_PUBLIC (decl1) && DECL_INLINE (decl1); | |
9811 | ||
9812 | raises = TYPE_RAISES_EXCEPTIONS (fntype); | |
9813 | ||
9814 | /* In a fcn definition, arg types must be complete. */ | |
9815 | require_complete_types_for_parms (last_function_parms); | |
9816 | } | |
9817 | else | |
9818 | { | |
9819 | decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises); | |
9820 | /* If the declarator is not suitable for a function definition, | |
9821 | cause a syntax error. */ | |
9822 | if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0; | |
9823 | ||
9824 | fntype = TREE_TYPE (decl1); | |
9825 | ||
9826 | restype = TREE_TYPE (fntype); | |
9827 | if (IS_AGGR_TYPE (restype) | |
9828 | && ! CLASSTYPE_GOT_SEMICOLON (restype)) | |
9829 | { | |
9830 | error_with_aggr_type (restype, "semicolon missing after declaration of `%s'"); | |
9831 | shadow_tag (build_tree_list (NULL_TREE, restype)); | |
9832 | CLASSTYPE_GOT_SEMICOLON (restype) = 1; | |
9833 | if (TREE_CODE (fntype) == FUNCTION_TYPE) | |
9834 | fntype = build_function_type (integer_type_node, | |
9835 | TYPE_ARG_TYPES (fntype)); | |
9836 | else | |
9837 | fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)), | |
9838 | integer_type_node, | |
9839 | TYPE_ARG_TYPES (fntype)); | |
9840 | TREE_TYPE (decl1) = fntype; | |
9841 | } | |
9842 | ||
9843 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
9844 | ctype = TYPE_METHOD_BASETYPE (fntype); | |
9845 | else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4 | |
9846 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main") | |
9847 | && DECL_CONTEXT (decl1) == NULL_TREE) | |
9848 | { | |
9849 | /* If this doesn't return integer_type, complain. */ | |
9850 | if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node) | |
9851 | { | |
9852 | warning ("return type for `main' changed to integer type"); | |
9853 | TREE_TYPE (decl1) = fntype = default_function_type; | |
9854 | } | |
9855 | warn_about_return_type = 0; | |
9856 | } | |
9857 | } | |
9858 | ||
9859 | /* Warn if function was previously implicitly declared | |
9860 | (but not if we warned then). */ | |
9861 | if (! warn_implicit | |
9862 | && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE) | |
9863 | warning_with_decl (IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)), | |
9864 | "`%s' implicitly declared before its definition"); | |
9865 | ||
9866 | current_function_decl = decl1; | |
9867 | ||
9868 | if (flag_cadillac) | |
9869 | cadillac_start_function (decl1); | |
9870 | else | |
9871 | announce_function (decl1); | |
9872 | ||
9873 | if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE) | |
9874 | { | |
9875 | if (IS_AGGR_TYPE (TREE_TYPE (fntype))) | |
9876 | error_with_aggr_type (TREE_TYPE (fntype), | |
9877 | "return-type `%s' is an incomplete type"); | |
9878 | else | |
9879 | error ("return-type is an incomplete type"); | |
9880 | ||
9881 | /* Make it return void instead, but don't change the | |
9882 | type of the DECL_RESULT, in case we have a named return value. */ | |
9883 | if (ctype) | |
9884 | TREE_TYPE (decl1) | |
9885 | = build_cplus_method_type (build_type_variant (ctype, | |
9886 | TREE_READONLY (decl1), | |
9887 | TREE_SIDE_EFFECTS (decl1)), | |
9888 | void_type_node, | |
9889 | FUNCTION_ARG_CHAIN (decl1)); | |
9890 | else | |
9891 | TREE_TYPE (decl1) | |
9892 | = build_function_type (void_type_node, | |
9893 | TYPE_ARG_TYPES (TREE_TYPE (decl1))); | |
9894 | DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype)); | |
9895 | } | |
9896 | ||
9897 | if (warn_about_return_type) | |
9898 | warning ("return-type defaults to `int'"); | |
9899 | ||
9900 | /* Make the init_value nonzero so pushdecl knows this is not tentative. | |
9901 | error_mark_node is replaced below (in poplevel) with the BLOCK. */ | |
9902 | DECL_INITIAL (decl1) = error_mark_node; | |
9903 | ||
9904 | /* Didn't get anything from C. */ | |
9905 | olddecl = NULL_TREE; | |
9906 | ||
9907 | /* This function exists in static storage. | |
9908 | (This does not mean `static' in the C sense!) */ | |
9909 | TREE_STATIC (decl1) = 1; | |
9910 | ||
9911 | /* If this function belongs to an interface, it is public. | |
9912 | If it belongs to someone else's interface, it is also external. | |
9913 | It doesn't matter whether it's inline or not. */ | |
9914 | if (interface_unknown == 0) | |
9915 | { | |
9916 | TREE_PUBLIC (decl1) = 1; | |
9917 | DECL_EXTERNAL (decl1) = (interface_only | |
9918 | || (DECL_INLINE (decl1) | |
9919 | && ! flag_implement_inlines)); | |
9920 | } | |
9921 | else | |
9922 | /* This is a definition, not a reference. | |
9923 | So normally clear DECL_EXTERNAL. | |
9924 | However, `extern inline' acts like a declaration except for | |
9925 | defining how to inline. So set DECL_EXTERNAL in that case. */ | |
9926 | DECL_EXTERNAL (decl1) = current_extern_inline; | |
9927 | ||
9928 | /* Now see if this is the implementation of a function | |
9929 | declared with "C" linkage. */ | |
9930 | if (ctype == NULL_TREE && current_lang_name == lang_name_cplusplus | |
9931 | && !DECL_CONTEXT (decl1)) | |
9932 | { | |
9933 | olddecl = lookup_name_current_level (DECL_NAME (decl1)); | |
9934 | if (olddecl && TREE_CODE (olddecl) != FUNCTION_DECL) | |
9935 | olddecl = NULL_TREE; | |
9936 | if (olddecl && DECL_NAME (decl1) != DECL_NAME (olddecl)) | |
9937 | { | |
9938 | /* Collision between user and internal naming scheme. */ | |
9939 | olddecl = lookup_name_current_level (DECL_ASSEMBLER_NAME (decl1)); | |
9940 | if (olddecl == NULL_TREE) | |
9941 | olddecl = decl1; | |
9942 | } | |
9943 | if (olddecl && olddecl != decl1 | |
9944 | && DECL_NAME (decl1) == DECL_NAME (olddecl)) | |
9945 | { | |
9946 | if (TREE_CODE (olddecl) == FUNCTION_DECL | |
9947 | && decls_match (decl1, olddecl)) | |
9948 | { | |
9949 | olddecl = DECL_MAIN_VARIANT (olddecl); | |
9950 | /* The following copy is needed to handle forcing a function's | |
9951 | linkage to obey the linkage of the original decl. */ | |
9952 | DECL_ASSEMBLER_NAME (decl1) = DECL_ASSEMBLER_NAME (olddecl); | |
9953 | DECL_OVERLOADED (decl1) = DECL_OVERLOADED (olddecl); | |
9954 | if (DECL_INITIAL (olddecl)) | |
9955 | redeclaration_error_message (decl1, olddecl); | |
9956 | if (! duplicate_decls (decl1, olddecl)) | |
9957 | my_friendly_abort (19); | |
9958 | decl1 = olddecl; | |
9959 | } | |
9960 | else | |
9961 | olddecl = NULL_TREE; | |
9962 | } | |
9963 | } | |
9964 | ||
9965 | /* Record the decl so that the function name is defined. | |
9966 | If we already have a decl for this name, and it is a FUNCTION_DECL, | |
9967 | use the old decl. */ | |
9968 | ||
9969 | if (olddecl) | |
9970 | current_function_decl = olddecl; | |
9971 | else if (pre_parsed_p == 0) | |
9972 | { | |
9973 | current_function_decl = pushdecl (decl1); | |
9974 | if (TREE_CODE (current_function_decl) == TREE_LIST) | |
9975 | { | |
9976 | /* @@ revert to modified original declaration. */ | |
9977 | decl1 = DECL_MAIN_VARIANT (decl1); | |
9978 | current_function_decl = decl1; | |
9979 | } | |
9980 | else | |
9981 | { | |
9982 | decl1 = current_function_decl; | |
9983 | DECL_MAIN_VARIANT (decl1) = decl1; | |
9984 | } | |
9985 | fntype = TREE_TYPE (decl1); | |
9986 | } | |
9987 | else | |
9988 | current_function_decl = decl1; | |
9989 | ||
9990 | if (DECL_OVERLOADED (decl1)) | |
9991 | decl1 = push_overloaded_decl (decl1, 1); | |
9992 | ||
9993 | if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) | |
9994 | { | |
9995 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
9996 | TREE_TYPE (decl1) = fntype | |
9997 | = build_function_type (TREE_TYPE (fntype), | |
9998 | TREE_CHAIN (TYPE_ARG_TYPES (fntype))); | |
9999 | last_function_parms = TREE_CHAIN (last_function_parms); | |
10000 | DECL_ARGUMENTS (decl1) = last_function_parms; | |
10001 | ctype = NULL_TREE; | |
10002 | } | |
10003 | restype = TREE_TYPE (fntype); | |
10004 | ||
10005 | pushlevel (0); | |
10006 | current_binding_level->parm_flag = 1; | |
10007 | ||
10008 | /* Save the parm names or decls from this function's declarator | |
10009 | where store_parm_decls will find them. */ | |
10010 | current_function_parms = last_function_parms; | |
10011 | current_function_parm_tags = last_function_parm_tags; | |
10012 | ||
10013 | GNU_xref_function (decl1, current_function_parms); | |
10014 | ||
10015 | make_function_rtl (decl1); | |
10016 | ||
10017 | if (ctype) | |
10018 | { | |
10019 | pushclass (ctype, 1); | |
10020 | ||
10021 | /* If we're compiling a friend function, neither of the variables | |
10022 | current_class_decl nor current_class_type will have values. */ | |
10023 | if (! doing_friend) | |
10024 | { | |
10025 | /* We know that this was set up by `grokclassfn'. | |
10026 | We do not wait until `store_parm_decls', since evil | |
10027 | parse errors may never get us to that point. Here | |
10028 | we keep the consistency between `current_class_type' | |
10029 | and `current_class_decl'. */ | |
10030 | current_class_decl = last_function_parms; | |
10031 | my_friendly_assert (current_class_decl != NULL_TREE | |
10032 | && TREE_CODE (current_class_decl) == PARM_DECL, 162); | |
10033 | if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE) | |
10034 | { | |
10035 | tree variant = TREE_TYPE (TREE_TYPE (current_class_decl)); | |
10036 | if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE) | |
10037 | { | |
10038 | /* Can't call build_indirect_ref here, because it has special | |
10039 | logic to return C_C_D given this argument. */ | |
10040 | C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl); | |
10041 | CLASSTYPE_INST_VAR (ctype) = C_C_D; | |
10042 | } | |
10043 | else | |
10044 | { | |
10045 | C_C_D = CLASSTYPE_INST_VAR (ctype); | |
10046 | /* `current_class_decl' is different for every | |
10047 | function we compile. */ | |
10048 | TREE_OPERAND (C_C_D, 0) = current_class_decl; | |
10049 | } | |
10050 | TREE_READONLY (C_C_D) = TYPE_READONLY (variant); | |
10051 | TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant); | |
10052 | TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant); | |
10053 | } | |
10054 | else | |
10055 | C_C_D = current_class_decl; | |
10056 | } | |
10057 | } | |
10058 | else | |
10059 | { | |
10060 | if (DECL_STATIC_FUNCTION_P (decl1)) | |
10061 | pushclass (DECL_CONTEXT (decl1), 2); | |
10062 | else | |
10063 | push_memoized_context (0, 1); | |
10064 | } | |
10065 | ||
10066 | /* Allocate further tree nodes temporarily during compilation | |
10067 | of this function only. Tiemann moved up here from bottom of fn. */ | |
10068 | temporary_allocation (); | |
10069 | ||
10070 | /* Promote the value to int before returning it. */ | |
10071 | if (C_PROMOTING_INTEGER_TYPE_P (restype)) | |
10072 | { | |
10073 | /* It retains unsignedness if traditional or if it isn't | |
10074 | really getting wider. */ | |
10075 | if (TREE_UNSIGNED (restype) | |
10076 | && (flag_traditional | |
10077 | || TYPE_PRECISION (restype) | |
10078 | == TYPE_PRECISION (integer_type_node))) | |
10079 | restype = unsigned_type_node; | |
10080 | else | |
10081 | restype = integer_type_node; | |
10082 | } | |
10083 | if (DECL_RESULT (decl1) == NULL_TREE) | |
10084 | DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype); | |
10085 | ||
10086 | if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1))) | |
10087 | { | |
10088 | dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
10089 | ctor_label = NULL_TREE; | |
10090 | } | |
10091 | else | |
10092 | { | |
10093 | dtor_label = NULL_TREE; | |
10094 | if (DECL_CONSTRUCTOR_P (decl1)) | |
10095 | ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
10096 | } | |
10097 | ||
10098 | /* If this fcn was already referenced via a block-scope `extern' decl | |
10099 | (or an implicit decl), propagate certain information about the usage. */ | |
10100 | if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) | |
10101 | TREE_ADDRESSABLE (decl1) = 1; | |
10102 | ||
10103 | return 1; | |
10104 | } | |
10105 | \f | |
10106 | /* Store the parameter declarations into the current function declaration. | |
10107 | This is called after parsing the parameter declarations, before | |
10108 | digesting the body of the function. | |
10109 | ||
10110 | Also install to binding contour return value identifier, if any. */ | |
10111 | ||
10112 | void | |
10113 | store_parm_decls () | |
10114 | { | |
10115 | register tree fndecl = current_function_decl; | |
10116 | register tree parm; | |
10117 | int parms_have_cleanups = 0; | |
10118 | tree eh_decl; | |
10119 | ||
10120 | /* This is either a chain of PARM_DECLs (when a prototype is used). */ | |
10121 | tree specparms = current_function_parms; | |
10122 | ||
10123 | /* This is a list of types declared among parms in a prototype. */ | |
10124 | tree parmtags = current_function_parm_tags; | |
10125 | ||
10126 | /* This is a chain of any other decls that came in among the parm | |
10127 | declarations. If a parm is declared with enum {foo, bar} x; | |
10128 | then CONST_DECLs for foo and bar are put here. */ | |
10129 | tree nonparms = NULL_TREE; | |
10130 | ||
10131 | if (current_binding_level == global_binding_level) | |
10132 | fatal ("parse errors have confused me too much"); | |
10133 | ||
10134 | /* Initialize RTL machinery. */ | |
10135 | init_function_start (fndecl, input_filename, lineno); | |
10136 | ||
10137 | /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ | |
10138 | declare_function_name (); | |
10139 | ||
10140 | /* Create a binding level for the parms. */ | |
10141 | expand_start_bindings (0); | |
10142 | ||
10143 | /* Prepare to catch raises, if appropriate. */ | |
10144 | if (flag_handle_exceptions) | |
10145 | { | |
10146 | /* Get this cleanup to be run last, since it | |
10147 | is a call to `longjmp'. */ | |
10148 | setup_exception_throw_decl (); | |
10149 | eh_decl = current_binding_level->names; | |
10150 | current_binding_level->names = TREE_CHAIN (current_binding_level->names); | |
10151 | } | |
10152 | if (flag_handle_exceptions) | |
10153 | expand_start_try (integer_one_node, 0, 1); | |
10154 | ||
10155 | if (specparms != NULL_TREE) | |
10156 | { | |
10157 | /* This case is when the function was defined with an ANSI prototype. | |
10158 | The parms already have decls, so we need not do anything here | |
10159 | except record them as in effect | |
10160 | and complain if any redundant old-style parm decls were written. */ | |
10161 | ||
10162 | register tree next; | |
10163 | ||
10164 | /* Must clear this because it might contain TYPE_DECLs declared | |
10165 | at class level. */ | |
10166 | storedecls (NULL_TREE); | |
10167 | for (parm = nreverse (specparms); parm; parm = next) | |
10168 | { | |
10169 | next = TREE_CHAIN (parm); | |
10170 | if (TREE_CODE (parm) == PARM_DECL) | |
10171 | { | |
10172 | tree cleanup = maybe_build_cleanup (parm); | |
10173 | if (DECL_NAME (parm) == NULL_TREE) | |
10174 | { | |
10175 | #if 0 | |
10176 | error_with_decl (parm, "parameter name omitted"); | |
10177 | #else | |
10178 | /* for C++, this is not an error. */ | |
10179 | pushdecl (parm); | |
10180 | #endif | |
10181 | } | |
10182 | else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) | |
10183 | error_with_decl (parm, "parameter `%s' declared void"); | |
10184 | else | |
10185 | { | |
10186 | /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls. | |
10187 | A parameter is assumed not to have any side effects. | |
10188 | If this should change for any reason, then this | |
10189 | will have to wrap the bashed reference type in a save_expr. | |
10190 | ||
10191 | Also, if the parameter type is declared to be an X | |
10192 | and there is an X(X&) constructor, we cannot lay it | |
10193 | into the stack (any more), so we make this parameter | |
10194 | look like it is really of reference type. Functions | |
10195 | which pass parameters to this function will know to | |
10196 | create a temporary in their frame, and pass a reference | |
10197 | to that. */ | |
10198 | ||
10199 | if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE | |
10200 | && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm)))) | |
10201 | SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm)); | |
10202 | ||
10203 | pushdecl (parm); | |
10204 | } | |
10205 | if (cleanup) | |
10206 | { | |
10207 | expand_decl (parm); | |
10208 | expand_decl_cleanup (parm, cleanup); | |
10209 | parms_have_cleanups = 1; | |
10210 | } | |
10211 | } | |
10212 | else | |
10213 | { | |
10214 | /* If we find an enum constant or a type tag, | |
10215 | put it aside for the moment. */ | |
10216 | TREE_CHAIN (parm) = NULL_TREE; | |
10217 | nonparms = chainon (nonparms, parm); | |
10218 | } | |
10219 | } | |
10220 | ||
10221 | /* Get the decls in their original chain order | |
10222 | and record in the function. This is all and only the | |
10223 | PARM_DECLs that were pushed into scope by the loop above. */ | |
10224 | DECL_ARGUMENTS (fndecl) = getdecls (); | |
10225 | ||
10226 | storetags (chainon (parmtags, gettags ())); | |
10227 | } | |
10228 | else | |
10229 | DECL_ARGUMENTS (fndecl) = NULL_TREE; | |
10230 | ||
10231 | /* Now store the final chain of decls for the arguments | |
10232 | as the decl-chain of the current lexical scope. | |
10233 | Put the enumerators in as well, at the front so that | |
10234 | DECL_ARGUMENTS is not modified. */ | |
10235 | ||
10236 | storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); | |
10237 | ||
10238 | /* Initialize the RTL code for the function. */ | |
10239 | DECL_SAVED_INSNS (fndecl) = NULL_RTX; | |
10240 | expand_function_start (fndecl, parms_have_cleanups); | |
10241 | ||
10242 | if (flag_handle_exceptions) | |
10243 | { | |
10244 | /* Make the throw decl visible at this level, just | |
10245 | not in the way of the parameters. */ | |
10246 | pushdecl (eh_decl); | |
10247 | expand_decl_init (eh_decl); | |
10248 | } | |
10249 | ||
10250 | /* Create a binding contour which can be used to catch | |
10251 | cleanup-generated temporaries. Also, if the return value needs or | |
10252 | has initialization, deal with that now. */ | |
10253 | if (parms_have_cleanups) | |
10254 | { | |
10255 | pushlevel (0); | |
10256 | expand_start_bindings (0); | |
10257 | } | |
10258 | ||
10259 | current_function_parms_stored = 1; | |
10260 | ||
10261 | if (flag_gc) | |
10262 | { | |
10263 | maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node); | |
10264 | expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup); | |
10265 | } | |
10266 | ||
10267 | /* If this function is `main', emit a call to `__main' | |
10268 | to run global initializers, etc. */ | |
10269 | if (DECL_NAME (fndecl) | |
10270 | && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 | |
10271 | && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 | |
10272 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
10273 | { | |
10274 | expand_main_function (); | |
10275 | ||
10276 | if (flag_gc) | |
10277 | expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE), | |
10278 | 0, VOIDmode, 0); | |
10279 | ||
10280 | if (flag_dossier) | |
10281 | output_builtin_tdesc_entries (); | |
10282 | } | |
10283 | } | |
10284 | ||
10285 | /* Bind a name and initialization to the return value of | |
10286 | the current function. */ | |
10287 | void | |
10288 | store_return_init (return_id, init) | |
10289 | tree return_id, init; | |
10290 | { | |
10291 | tree decl = DECL_RESULT (current_function_decl); | |
10292 | ||
10293 | if (pedantic) | |
10294 | /* Give this error as many times as there are occurrences, | |
10295 | so that users can use Emacs compilation buffers to find | |
10296 | and fix all such places. */ | |
10297 | error ("ANSI C++ does not permit named return values"); | |
10298 | ||
10299 | if (return_id != NULL_TREE) | |
10300 | { | |
10301 | if (DECL_NAME (decl) == NULL_TREE) | |
10302 | { | |
10303 | DECL_NAME (decl) = return_id; | |
10304 | DECL_ASSEMBLER_NAME (decl) = return_id; | |
10305 | } | |
10306 | else | |
10307 | error ("return identifier `%s' already in place", | |
10308 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
10309 | } | |
10310 | ||
10311 | /* Can't let this happen for constructors. */ | |
10312 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
10313 | { | |
10314 | error ("can't redefine default return value for constructors"); | |
10315 | return; | |
10316 | } | |
10317 | ||
10318 | /* If we have a named return value, put that in our scope as well. */ | |
10319 | if (DECL_NAME (decl) != NULL_TREE) | |
10320 | { | |
10321 | /* If this named return value comes in a register, | |
10322 | put it in a pseudo-register. */ | |
10323 | if (DECL_REGISTER (decl)) | |
10324 | { | |
10325 | original_result_rtx = DECL_RTL (decl); | |
10326 | DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); | |
10327 | } | |
10328 | ||
10329 | /* Let `finish_decl' know that this initializer is ok. */ | |
10330 | DECL_INITIAL (decl) = init; | |
10331 | pushdecl (decl); | |
10332 | finish_decl (decl, init, 0, 0); | |
10333 | } | |
10334 | } | |
10335 | ||
10336 | /* Generate code for default X(X&) constructor. */ | |
10337 | static void | |
10338 | build_default_constructor (fndecl) | |
10339 | tree fndecl; | |
10340 | { | |
10341 | int i = CLASSTYPE_N_BASECLASSES (current_class_type); | |
10342 | tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); | |
10343 | tree fields = TYPE_FIELDS (current_class_type); | |
10344 | tree binfos = TYPE_BINFO_BASETYPES (current_class_type); | |
10345 | ||
10346 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) | |
10347 | parm = TREE_CHAIN (parm); | |
10348 | parm = DECL_REFERENCE_SLOT (parm); | |
10349 | ||
10350 | while (--i >= 0) | |
10351 | { | |
10352 | tree basetype = TREE_VEC_ELT (binfos, i); | |
10353 | if (TYPE_GETS_INIT_REF (basetype)) | |
10354 | { | |
10355 | tree name = TYPE_NAME (basetype); | |
10356 | if (TREE_CODE (name) == TYPE_DECL) | |
10357 | name = DECL_NAME (name); | |
10358 | current_base_init_list = tree_cons (name, parm, current_base_init_list); | |
10359 | } | |
10360 | } | |
10361 | for (; fields; fields = TREE_CHAIN (fields)) | |
10362 | { | |
10363 | tree name, init; | |
10364 | if (TREE_STATIC (fields)) | |
10365 | continue; | |
10366 | if (TREE_CODE (fields) != FIELD_DECL) | |
10367 | continue; | |
10368 | if (DECL_NAME (fields)) | |
10369 | { | |
10370 | if (VFIELD_NAME_P (DECL_NAME (fields))) | |
10371 | continue; | |
10372 | if (VBASE_NAME_P (DECL_NAME (fields))) | |
10373 | continue; | |
10374 | ||
10375 | /* True for duplicate members. */ | |
10376 | if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields) | |
10377 | continue; | |
10378 | } | |
10379 | ||
10380 | init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields); | |
10381 | ||
10382 | if (TREE_ANON_UNION_ELEM (fields)) | |
10383 | name = build (COMPONENT_REF, TREE_TYPE (fields), C_C_D, fields); | |
10384 | else | |
10385 | { | |
10386 | name = DECL_NAME (fields); | |
10387 | init = build_tree_list (NULL_TREE, init); | |
10388 | } | |
10389 | ||
10390 | current_member_init_list | |
10391 | = tree_cons (name, init, current_member_init_list); | |
10392 | } | |
10393 | } | |
10394 | ||
10395 | \f | |
10396 | /* Finish up a function declaration and compile that function | |
10397 | all the way to assembler language output. The free the storage | |
10398 | for the function definition. | |
10399 | ||
10400 | This is called after parsing the body of the function definition. | |
10401 | LINENO is the current line number. | |
10402 | ||
10403 | C++: CALL_POPLEVEL is non-zero if an extra call to poplevel | |
10404 | (and expand_end_bindings) must be made to take care of the binding | |
10405 | contour for the base initializers. This is only relevant for | |
10406 | constructors. */ | |
10407 | ||
10408 | void | |
10409 | finish_function (lineno, call_poplevel) | |
10410 | int lineno; | |
10411 | int call_poplevel; | |
10412 | { | |
10413 | register tree fndecl = current_function_decl; | |
10414 | tree fntype, ctype = NULL_TREE; | |
10415 | rtx head, last_parm_insn, mark; | |
10416 | extern int sets_exception_throw_decl; | |
10417 | /* Label to use if this function is supposed to return a value. */ | |
10418 | tree no_return_label = NULL_TREE; | |
10419 | ||
10420 | /* When we get some parse errors, we can end up without a | |
10421 | current_function_decl, so cope. */ | |
10422 | if (fndecl == NULL_TREE) | |
10423 | return; | |
10424 | ||
10425 | fntype = TREE_TYPE (fndecl); | |
10426 | ||
10427 | /* TREE_READONLY (fndecl) = 1; | |
10428 | This caused &foo to be of type ptr-to-const-function | |
10429 | which then got a warning when stored in a ptr-to-function variable. */ | |
10430 | ||
10431 | /* This happens on strange parse errors. */ | |
10432 | if (! current_function_parms_stored) | |
10433 | { | |
10434 | call_poplevel = 0; | |
10435 | store_parm_decls (); | |
10436 | } | |
10437 | ||
10438 | if (write_symbols != NO_DEBUG && TREE_CODE (fntype) != METHOD_TYPE) | |
10439 | { | |
10440 | tree ttype = target_type (fntype); | |
10441 | tree parmdecl; | |
10442 | ||
10443 | if (IS_AGGR_TYPE (ttype)) | |
10444 | /* Let debugger know it should output info for this type. */ | |
10445 | note_debug_info_needed (ttype); | |
10446 | ||
10447 | for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) | |
10448 | { | |
10449 | ttype = target_type (TREE_TYPE (parmdecl)); | |
10450 | if (IS_AGGR_TYPE (ttype)) | |
10451 | /* Let debugger know it should output info for this type. */ | |
10452 | note_debug_info_needed (ttype); | |
10453 | } | |
10454 | } | |
10455 | ||
10456 | /* Clean house because we will need to reorder insns here. */ | |
10457 | do_pending_stack_adjust (); | |
10458 | ||
10459 | if (dtor_label) | |
10460 | { | |
10461 | tree binfo = TYPE_BINFO (current_class_type); | |
10462 | tree cond = integer_one_node; | |
10463 | tree exprstmt, vfields; | |
10464 | tree in_charge_node = lookup_name (in_charge_identifier, 0); | |
10465 | tree virtual_size; | |
10466 | int ok_to_optimize_dtor = 0; | |
10467 | ||
10468 | if (current_function_assigns_this) | |
10469 | cond = build (NE_EXPR, integer_type_node, | |
10470 | current_class_decl, integer_zero_node); | |
10471 | else | |
10472 | { | |
10473 | int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); | |
10474 | ||
10475 | /* If this destructor is empty, then we don't need to check | |
10476 | whether `this' is NULL in some cases. */ | |
10477 | mark = get_last_insn (); | |
10478 | last_parm_insn = get_first_nonparm_insn (); | |
10479 | ||
10480 | if ((flag_this_is_variable & 1) == 0) | |
10481 | ok_to_optimize_dtor = 1; | |
10482 | else if (mark == last_parm_insn) | |
10483 | ok_to_optimize_dtor | |
10484 | = (n_baseclasses == 0 | |
10485 | || (n_baseclasses == 1 | |
10486 | && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); | |
10487 | } | |
10488 | ||
10489 | /* These initializations might go inline. Protect | |
10490 | the binding level of the parms. */ | |
10491 | pushlevel (0); | |
10492 | ||
10493 | if (current_function_assigns_this) | |
10494 | { | |
10495 | current_function_assigns_this = 0; | |
10496 | current_function_just_assigned_this = 0; | |
10497 | } | |
10498 | ||
10499 | /* Generate the code to call destructor on base class. | |
10500 | If this destructor belongs to a class with virtual | |
10501 | functions, then set the virtual function table | |
10502 | pointer to represent the type of our base class. */ | |
10503 | ||
10504 | /* This side-effect makes call to `build_delete' generate the | |
10505 | code we have to have at the end of this destructor. */ | |
10506 | TYPE_HAS_DESTRUCTOR (current_class_type) = 0; | |
10507 | ||
10508 | /* These are two cases where we cannot delegate deletion. */ | |
10509 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) | |
10510 | || TREE_GETS_DELETE (current_class_type)) | |
10511 | exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node, | |
10512 | LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0, 0); | |
10513 | else | |
10514 | exprstmt = build_delete (current_class_type, C_C_D, in_charge_node, | |
10515 | LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0, 0); | |
10516 | ||
10517 | /* If we did not assign to this, then `this' is non-zero at | |
10518 | the end of a destructor. As a special optimization, don't | |
10519 | emit test if this is an empty destructor. If it does nothing, | |
10520 | it does nothing. If it calls a base destructor, the base | |
10521 | destructor will perform the test. */ | |
10522 | ||
10523 | if (exprstmt != error_mark_node | |
10524 | && (TREE_CODE (exprstmt) != NOP_EXPR | |
10525 | || TREE_OPERAND (exprstmt, 0) != integer_zero_node | |
10526 | || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) | |
10527 | { | |
10528 | expand_label (dtor_label); | |
10529 | if (cond != integer_one_node) | |
10530 | expand_start_cond (cond, 0); | |
10531 | if (exprstmt != void_zero_node) | |
10532 | /* Don't call `expand_expr_stmt' if we're not going to do | |
10533 | anything, since -Wall will give a diagnostic. */ | |
10534 | expand_expr_stmt (exprstmt); | |
10535 | ||
10536 | /* Run destructor on all virtual baseclasses. */ | |
10537 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) | |
10538 | { | |
10539 | tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); | |
10540 | expand_start_cond (build (BIT_AND_EXPR, integer_type_node, | |
10541 | in_charge_node, integer_two_node), 0); | |
10542 | while (vbases) | |
10543 | { | |
10544 | if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) | |
10545 | { | |
10546 | tree ptr = convert_pointer_to_vbase (vbases, current_class_decl); | |
10547 | expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)), | |
10548 | ptr, integer_zero_node, | |
10549 | LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0, 0)); | |
10550 | } | |
10551 | vbases = TREE_CHAIN (vbases); | |
10552 | } | |
10553 | expand_end_cond (); | |
10554 | } | |
10555 | ||
10556 | do_pending_stack_adjust (); | |
10557 | if (cond != integer_one_node) | |
10558 | expand_end_cond (); | |
10559 | } | |
10560 | ||
10561 | TYPE_HAS_DESTRUCTOR (current_class_type) = 1; | |
10562 | ||
10563 | virtual_size = c_sizeof (current_class_type); | |
10564 | ||
10565 | /* At the end, call delete if that's what's requested. */ | |
10566 | if (TREE_GETS_DELETE (current_class_type)) | |
10567 | /* This NOP_EXPR means we are in a static call context. */ | |
10568 | exprstmt = | |
10569 | build_method_call | |
10570 | (build1 (NOP_EXPR, | |
10571 | TYPE_POINTER_TO (current_class_type), error_mark_node), | |
10572 | ansi_opname[(int) DELETE_EXPR], | |
10573 | tree_cons (NULL_TREE, current_class_decl, | |
10574 | build_tree_list (NULL_TREE, virtual_size)), | |
10575 | NULL_TREE, LOOKUP_NORMAL); | |
10576 | else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) | |
10577 | exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0, | |
10578 | virtual_size); | |
10579 | else | |
10580 | exprstmt = NULL_TREE; | |
10581 | ||
10582 | if (exprstmt) | |
10583 | { | |
10584 | cond = build (BIT_AND_EXPR, integer_type_node, | |
10585 | in_charge_node, integer_one_node); | |
10586 | expand_start_cond (cond, 0); | |
10587 | expand_expr_stmt (exprstmt); | |
10588 | expand_end_cond (); | |
10589 | } | |
10590 | ||
10591 | /* End of destructor. */ | |
10592 | poplevel (2, 0, 0); | |
10593 | ||
10594 | /* Back to the top of destructor. */ | |
10595 | /* Dont execute destructor code if `this' is NULL. */ | |
10596 | mark = get_last_insn (); | |
10597 | last_parm_insn = get_first_nonparm_insn (); | |
10598 | if (last_parm_insn == NULL_RTX) | |
10599 | last_parm_insn = mark; | |
10600 | else | |
10601 | last_parm_insn = previous_insn (last_parm_insn); | |
10602 | ||
10603 | /* Make all virtual function table pointers point to CURRENT_CLASS_TYPE's | |
10604 | virtual function tables. */ | |
10605 | if (CLASSTYPE_VFIELDS (current_class_type)) | |
10606 | { | |
10607 | for (vfields = CLASSTYPE_VFIELDS (current_class_type); | |
10608 | TREE_CHAIN (vfields); | |
10609 | vfields = TREE_CHAIN (vfields)) | |
10610 | { | |
10611 | tree vf_decl = current_class_decl; | |
10612 | /* ??? This may need to be a loop if there are multiple | |
10613 | levels of replication. */ | |
10614 | if (VF_BINFO_VALUE (vfields)) | |
10615 | vf_decl = convert_pointer_to (VF_BINFO_VALUE (vfields), vf_decl); | |
10616 | if (vf_decl != error_mark_node) | |
10617 | { | |
10618 | /* It is one of these two, or a combination... */ | |
10619 | /* basically speaking, I want to get down to the right | |
10620 | VF_BASETYPE_VALUE (vfields) */ | |
10621 | #if 0 | |
10622 | if (VF_NORMAL_VALUE (vfields) != VF_DERIVED_VALUE (vfields)) | |
10623 | warning ("hum, wonder if I am doing the right thing"); | |
10624 | #endif | |
10625 | expand_expr_stmt (build_virtual_init (binfo, | |
10626 | get_binfo (VF_BASETYPE_VALUE (vfields), | |
10627 | get_binfo (VF_DERIVED_VALUE (vfields), binfo, 0), 0), | |
10628 | vf_decl)); | |
10629 | } | |
10630 | } | |
10631 | expand_expr_stmt (build_virtual_init (binfo, binfo, | |
10632 | current_class_decl)); | |
10633 | } | |
10634 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) | |
10635 | expand_expr_stmt (build_vbase_vtables_init (binfo, binfo, | |
10636 | C_C_D, current_class_decl, 0)); | |
10637 | if (! ok_to_optimize_dtor) | |
10638 | { | |
10639 | cond = build_binary_op (NE_EXPR, | |
10640 | current_class_decl, integer_zero_node, 1); | |
10641 | expand_start_cond (cond, 0); | |
10642 | } | |
10643 | if (mark != get_last_insn ()) | |
10644 | reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn); | |
10645 | if (! ok_to_optimize_dtor) | |
10646 | expand_end_cond (); | |
10647 | } | |
10648 | else if (current_function_assigns_this) | |
10649 | { | |
10650 | /* Does not need to call emit_base_init, because | |
10651 | that is done (if needed) just after assignment to this | |
10652 | is seen. */ | |
10653 | ||
10654 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
10655 | { | |
10656 | expand_label (ctor_label); | |
10657 | ctor_label = NULL_TREE; | |
10658 | ||
10659 | if (call_poplevel) | |
10660 | { | |
10661 | tree decls = getdecls (); | |
10662 | if (flag_handle_exceptions == 2) | |
10663 | deactivate_exception_cleanups (); | |
10664 | expand_end_bindings (decls, decls != NULL_TREE, 0); | |
10665 | poplevel (decls != NULL_TREE, 0, 0); | |
10666 | } | |
10667 | c_expand_return (current_class_decl); | |
10668 | } | |
10669 | else if (TYPE_MAIN_VARIANT (TREE_TYPE ( | |
10670 | DECL_RESULT (current_function_decl))) != void_type_node | |
10671 | && return_label != NULL_RTX) | |
10672 | no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
10673 | ||
10674 | current_function_assigns_this = 0; | |
10675 | current_function_just_assigned_this = 0; | |
10676 | base_init_insns = NULL_RTX; | |
10677 | } | |
10678 | else if (DECL_CONSTRUCTOR_P (fndecl)) | |
10679 | { | |
10680 | tree allocated_this; | |
10681 | tree cond, thenclause; | |
10682 | /* Allow constructor for a type to get a new instance of the object | |
10683 | using `build_new'. */ | |
10684 | tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); | |
10685 | CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; | |
10686 | ||
10687 | DECL_RETURNS_FIRST_ARG (fndecl) = 1; | |
10688 | ||
10689 | if (flag_this_is_variable > 0) | |
10690 | { | |
10691 | cond = build_binary_op (EQ_EXPR, | |
10692 | current_class_decl, integer_zero_node, 1); | |
10693 | thenclause = build_modify_expr (current_class_decl, NOP_EXPR, | |
10694 | build_new (NULL_TREE, current_class_type, void_type_node, 0)); | |
10695 | if (flag_handle_exceptions == 2) | |
10696 | { | |
10697 | tree cleanup, cleanup_deallocate; | |
10698 | tree virtual_size; | |
10699 | ||
10700 | /* This is the size of the virtual object pointed to by | |
10701 | allocated_this. In this case, it is simple. */ | |
10702 | virtual_size = c_sizeof (current_class_type); | |
10703 | ||
10704 | allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node); | |
10705 | DECL_REGISTER (allocated_this) = 1; | |
10706 | DECL_INITIAL (allocated_this) = error_mark_node; | |
10707 | expand_decl (allocated_this); | |
10708 | expand_decl_init (allocated_this); | |
10709 | /* How we cleanup `this' if an exception was raised before | |
10710 | we are ready to bail out. */ | |
10711 | cleanup = TREE_GETS_DELETE (current_class_type) | |
10712 | ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this, virtual_size, NULL_TREE) | |
10713 | /* The size of allocated_this is wrong, and hence the | |
10714 | second argument to operator delete will be wrong. */ | |
10715 | : build_delete (TREE_TYPE (allocated_this), allocated_this, | |
10716 | integer_three_node, | |
10717 | LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1, 0); | |
10718 | cleanup_deallocate | |
10719 | = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node); | |
10720 | cleanup = tree_cons (NULL_TREE, cleanup, | |
10721 | build_tree_list (NULL_TREE, cleanup_deallocate)); | |
10722 | ||
10723 | expand_decl_cleanup (allocated_this, | |
10724 | build (COND_EXPR, integer_type_node, | |
10725 | build (NE_EXPR, integer_type_node, | |
10726 | allocated_this, integer_zero_node), | |
10727 | build_compound_expr (cleanup), | |
10728 | integer_zero_node)); | |
10729 | } | |
10730 | } | |
10731 | else if (TREE_GETS_NEW (current_class_type)) | |
10732 | /* Just check visibility here. */ | |
10733 | build_method_call (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type), error_mark_node), | |
10734 | ansi_opname[(int) NEW_EXPR], | |
10735 | build_tree_list (NULL_TREE, integer_zero_node), | |
10736 | NULL_TREE, LOOKUP_NORMAL); | |
10737 | ||
10738 | CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; | |
10739 | ||
10740 | /* must keep the first insn safe. */ | |
10741 | head = get_insns (); | |
10742 | ||
10743 | /* this note will come up to the top with us. */ | |
10744 | mark = get_last_insn (); | |
10745 | ||
10746 | if (flag_this_is_variable > 0) | |
10747 | { | |
10748 | expand_start_cond (cond, 0); | |
10749 | expand_expr_stmt (thenclause); | |
10750 | if (flag_handle_exceptions == 2) | |
10751 | expand_assignment (allocated_this, current_class_decl, 0, 0); | |
10752 | expand_end_cond (); | |
10753 | } | |
10754 | ||
10755 | if (DECL_NAME (fndecl) == NULL_TREE | |
10756 | && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE) | |
10757 | build_default_constructor (fndecl); | |
10758 | ||
10759 | /* Emit insns from `emit_base_init' which sets up virtual | |
10760 | function table pointer(s). */ | |
10761 | emit_insns (base_init_insns); | |
10762 | base_init_insns = NULL_RTX; | |
10763 | ||
10764 | /* This is where the body of the constructor begins. | |
10765 | If there were no insns in this function body, then the | |
10766 | last_parm_insn is also the last insn. | |
10767 | ||
10768 | If optimization is enabled, last_parm_insn may move, so | |
10769 | we don't hold on to it (across emit_base_init). */ | |
10770 | last_parm_insn = get_first_nonparm_insn (); | |
10771 | if (last_parm_insn == NULL_RTX) last_parm_insn = mark; | |
10772 | else last_parm_insn = previous_insn (last_parm_insn); | |
10773 | ||
10774 | if (mark != get_last_insn ()) | |
10775 | reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn); | |
10776 | ||
10777 | /* This is where the body of the constructor ends. */ | |
10778 | expand_label (ctor_label); | |
10779 | ctor_label = NULL_TREE; | |
10780 | if (flag_handle_exceptions == 2) | |
10781 | { | |
10782 | expand_assignment (allocated_this, integer_zero_node, 0, 0); | |
10783 | if (call_poplevel) | |
10784 | deactivate_exception_cleanups (); | |
10785 | } | |
10786 | ||
10787 | pop_implicit_try_blocks (NULL_TREE); | |
10788 | ||
10789 | if (call_poplevel) | |
10790 | { | |
10791 | expand_end_bindings (getdecls (), 1, 0); | |
10792 | poplevel (1, 1, 0); | |
10793 | } | |
10794 | ||
10795 | c_expand_return (current_class_decl); | |
10796 | ||
10797 | current_function_assigns_this = 0; | |
10798 | current_function_just_assigned_this = 0; | |
10799 | } | |
10800 | else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 | |
10801 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") | |
10802 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
10803 | { | |
10804 | /* Make it so that `main' always returns 0 by default. */ | |
10805 | #ifdef VMS | |
10806 | c_expand_return (integer_one_node); | |
10807 | #else | |
10808 | c_expand_return (integer_zero_node); | |
10809 | #endif | |
10810 | } | |
10811 | else if (return_label != NULL_RTX | |
10812 | && current_function_return_value == NULL_TREE | |
10813 | && ! DECL_NAME (DECL_RESULT (current_function_decl))) | |
10814 | no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
10815 | ||
10816 | if (flag_gc) | |
10817 | expand_gc_prologue_and_epilogue (); | |
10818 | ||
10819 | /* That's the end of the vtable decl's life. Need to mark it such | |
10820 | if doing stupid register allocation. | |
10821 | ||
10822 | Note that current_vtable_decl is really an INDIRECT_REF | |
10823 | on top of a VAR_DECL here. */ | |
10824 | if (obey_regdecls && current_vtable_decl) | |
10825 | use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0))); | |
10826 | ||
10827 | /* If this function is supposed to return a value, ensure that | |
10828 | we do not fall into the cleanups by mistake. The end of our | |
10829 | function will look like this: | |
10830 | ||
10831 | user code (may have return stmt somewhere) | |
10832 | goto no_return_label | |
10833 | cleanup_label: | |
10834 | cleanups | |
10835 | goto return_label | |
10836 | no_return_label: | |
10837 | NOTE_INSN_FUNCTION_END | |
10838 | return_label: | |
10839 | things for return | |
10840 | ||
10841 | If the user omits a return stmt in the USER CODE section, we | |
10842 | will have a control path which reaches NOTE_INSN_FUNCTION_END. | |
10843 | Otherwise, we won't. */ | |
10844 | if (no_return_label) | |
10845 | { | |
10846 | DECL_CONTEXT (no_return_label) = fndecl; | |
10847 | DECL_INITIAL (no_return_label) = error_mark_node; | |
10848 | DECL_SOURCE_FILE (no_return_label) = input_filename; | |
10849 | DECL_SOURCE_LINE (no_return_label) = lineno; | |
10850 | expand_goto (no_return_label); | |
10851 | } | |
10852 | ||
10853 | if (cleanup_label) | |
10854 | { | |
10855 | /* remove the binding contour which is used | |
10856 | to catch cleanup-generated temporaries. */ | |
10857 | expand_end_bindings (0, 0, 0); | |
10858 | poplevel (0, 0, 0); | |
10859 | } | |
10860 | ||
9bf86ebb PR |
10861 | if (cleanup_label) |
10862 | /* Emit label at beginning of cleanup code for parameters. */ | |
10863 | emit_label (cleanup_label); | |
10864 | ||
10865 | #if 1 | |
10866 | /* Cheap hack to get better code from GNU C++. Remove when cse is fixed. */ | |
10867 | if (exception_throw_decl && sets_exception_throw_decl == 0) | |
10868 | expand_assignment (exception_throw_decl, integer_zero_node, 0, 0); | |
10869 | #endif | |
10870 | ||
10871 | if (flag_handle_exceptions) | |
10872 | { | |
10873 | expand_end_try (); | |
10874 | expand_start_except (0, 0); | |
10875 | expand_end_except (); | |
10876 | } | |
10877 | expand_end_bindings (0, 0, 0); | |
10878 | ||
10879 | /* Get return value into register if that's where it's supposed to be. */ | |
10880 | if (original_result_rtx) | |
10881 | fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); | |
10882 | ||
10883 | /* Finish building code that will trigger warnings if users forget | |
10884 | to make their functions return values. */ | |
10885 | if (no_return_label || cleanup_label) | |
10886 | emit_jump (return_label); | |
10887 | if (no_return_label) | |
10888 | { | |
10889 | /* We don't need to call `expand_*_return' here because we | |
10890 | don't need any cleanups here--this path of code is only | |
10891 | for error checking purposes. */ | |
10892 | expand_label (no_return_label); | |
10893 | } | |
10894 | ||
10895 | /* reset scope for C++: if we were in the scope of a class, | |
10896 | then when we finish this function, we are not longer so. | |
10897 | This cannot be done until we know for sure that no more | |
10898 | class members will ever be referenced in this function | |
10899 | (i.e., calls to destructors). */ | |
10900 | if (current_class_name) | |
10901 | { | |
10902 | ctype = current_class_type; | |
10903 | popclass (1); | |
10904 | } | |
10905 | else | |
10906 | pop_memoized_context (1); | |
10907 | ||
10908 | /* Forget about all overloaded functions defined in | |
10909 | this scope which go away. */ | |
10910 | while (overloads_to_forget) | |
10911 | { | |
10912 | IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget)) | |
10913 | = TREE_VALUE (overloads_to_forget); | |
10914 | overloads_to_forget = TREE_CHAIN (overloads_to_forget); | |
10915 | } | |
10916 | ||
10917 | /* Generate rtl for function exit. */ | |
10918 | expand_function_end (input_filename, lineno); | |
10919 | ||
10920 | /* This must come after expand_function_end because cleanups might | |
10921 | have declarations (from inline functions) that need to go into | |
10922 | this function's blocks. */ | |
10923 | if (current_binding_level->parm_flag != 1) | |
10924 | my_friendly_abort (122); | |
10925 | poplevel (1, 0, 1); | |
10926 | ||
2a5f595d PR |
10927 | /* Must mark the RESULT_DECL as being in this function. */ |
10928 | DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl); | |
10929 | ||
10930 | /* Obey `register' declarations if `setjmp' is called in this fn. */ | |
10931 | if (flag_traditional && current_function_calls_setjmp) | |
10932 | setjmp_protect (DECL_INITIAL (fndecl)); | |
10933 | ||
9bf86ebb PR |
10934 | /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point |
10935 | to the FUNCTION_DECL node itself. */ | |
10936 | BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; | |
10937 | ||
10938 | /* So we can tell if jump_optimize sets it to 1. */ | |
10939 | can_reach_end = 0; | |
10940 | ||
10941 | /* ??? Compensate for Sun brain damage in dealing with data segments | |
10942 | of PIC code. */ | |
10943 | if (flag_pic | |
10944 | && (DECL_CONSTRUCTOR_P (fndecl) | |
10945 | || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) | |
10946 | && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype))) | |
10947 | DECL_INLINE (fndecl) = 0; | |
10948 | ||
10949 | if (DECL_EXTERNAL (fndecl) | |
10950 | /* This function is just along for the ride. If we can make | |
10951 | it inline, that's great. Otherwise, just punt it. */ | |
10952 | && (DECL_INLINE (fndecl) == 0 | |
10953 | || flag_no_inline | |
10954 | || function_cannot_inline_p (fndecl))) | |
10955 | { | |
10956 | extern int rtl_dump_and_exit; | |
10957 | int old_rtl_dump_and_exit = rtl_dump_and_exit; | |
10958 | int inline_spec = DECL_INLINE (fndecl); | |
10959 | ||
10960 | /* This throws away the code for FNDECL. */ | |
10961 | rtl_dump_and_exit = 1; | |
10962 | /* This throws away the memory of the code for FNDECL. */ | |
10963 | if (flag_no_inline) | |
10964 | DECL_INLINE (fndecl) = 0; | |
10965 | rest_of_compilation (fndecl); | |
10966 | rtl_dump_and_exit = old_rtl_dump_and_exit; | |
10967 | DECL_INLINE (fndecl) = inline_spec; | |
10968 | } | |
10969 | else | |
10970 | { | |
10971 | /* Run the optimizers and output the assembler code for this function. */ | |
10972 | rest_of_compilation (fndecl); | |
10973 | } | |
10974 | ||
10975 | if (ctype && TREE_ASM_WRITTEN (fndecl)) | |
10976 | note_debug_info_needed (ctype); | |
10977 | ||
10978 | current_function_returns_null |= can_reach_end; | |
10979 | ||
10980 | /* Since we don't normally go through c_expand_return for constructors, | |
10981 | this normally gets the wrong value. | |
10982 | Also, named return values have their return codes emitted after | |
10983 | NOTE_INSN_FUNCTION_END, confusing jump.c. */ | |
10984 | if (DECL_CONSTRUCTOR_P (fndecl) | |
10985 | || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) | |
10986 | current_function_returns_null = 0; | |
10987 | ||
10988 | if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) | |
10989 | warning ("`volatile' function does return"); | |
10990 | else if (warn_return_type && current_function_returns_null | |
10991 | && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node) | |
10992 | { | |
10993 | /* If this function returns non-void and control can drop through, | |
10994 | complain. */ | |
10995 | pedwarn ("control reaches end of non-void function"); | |
10996 | } | |
10997 | /* With just -W, complain only if function returns both with | |
10998 | and without a value. */ | |
10999 | else if (extra_warnings | |
11000 | && current_function_returns_value && current_function_returns_null) | |
11001 | warning ("this function may return with or without a value"); | |
11002 | ||
11003 | /* Free all the tree nodes making up this function. */ | |
11004 | /* Switch back to allocating nodes permanently | |
11005 | until we start another function. */ | |
11006 | permanent_allocation (); | |
11007 | ||
11008 | if (flag_cadillac) | |
11009 | cadillac_finish_function (fndecl); | |
11010 | ||
11011 | if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) | |
11012 | { | |
11013 | /* Stop pointing to the local nodes about to be freed. */ | |
11014 | /* But DECL_INITIAL must remain nonzero so we know this | |
11015 | was an actual function definition. */ | |
11016 | DECL_INITIAL (fndecl) = error_mark_node; | |
11017 | if (! DECL_CONSTRUCTOR_P (fndecl) | |
11018 | || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype))) | |
11019 | DECL_ARGUMENTS (fndecl) = NULL_TREE; | |
11020 | } | |
11021 | ||
11022 | /* Let the error reporting routines know that we're outside a function. */ | |
11023 | current_function_decl = NULL_TREE; | |
11024 | named_label_uses = NULL_TREE; | |
11025 | clear_anon_parm_name (); | |
11026 | } | |
11027 | \f | |
11028 | /* Create the FUNCTION_DECL for a function definition. | |
11029 | LINE1 is the line number that the definition absolutely begins on. | |
11030 | LINE2 is the line number that the name of the function appears on. | |
11031 | DECLSPECS and DECLARATOR are the parts of the declaration; | |
11032 | they describe the function's name and the type it returns, | |
11033 | but twisted together in a fashion that parallels the syntax of C. | |
11034 | ||
11035 | This function creates a binding context for the function body | |
11036 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
11037 | ||
11038 | Returns a FUNCTION_DECL on success. | |
11039 | ||
11040 | If the DECLARATOR is not suitable for a function (it defines a datum | |
11041 | instead), we return 0, which tells yyparse to report a parse error. | |
11042 | ||
11043 | May return void_type_node indicating that this method is actually | |
11044 | a friend. See grokfield for more details. | |
11045 | ||
11046 | Came here with a `.pushlevel' . | |
11047 | ||
11048 | DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING | |
11049 | CHANGES TO CODE IN `grokfield'. */ | |
11050 | tree | |
11051 | start_method (declspecs, declarator, raises) | |
11052 | tree declarator, declspecs, raises; | |
11053 | { | |
11054 | tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises); | |
11055 | ||
11056 | /* Something too ugly to handle. */ | |
11057 | if (fndecl == NULL_TREE) | |
11058 | return NULL_TREE; | |
11059 | ||
11060 | /* Pass friends other than inline friend functions back. */ | |
11061 | if (TYPE_MAIN_VARIANT (fndecl) == void_type_node) | |
11062 | return fndecl; | |
11063 | ||
11064 | if (TREE_CODE (fndecl) != FUNCTION_DECL) | |
11065 | /* Not a function, tell parser to report parse error. */ | |
11066 | return NULL_TREE; | |
11067 | ||
11068 | if (DECL_IN_AGGR_P (fndecl)) | |
11069 | { | |
11070 | if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) | |
11071 | { | |
11072 | if (DECL_CONTEXT (fndecl)) | |
11073 | error_with_decl (fndecl, "`%s' is already defined in class %s", | |
11074 | TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); | |
11075 | } | |
11076 | return void_type_node; | |
11077 | } | |
11078 | ||
11079 | /* If we're expanding a template, a function must be explicitly declared | |
11080 | inline if we're to compile it now. If it isn't, we have to wait to see | |
11081 | whether it's needed, and whether an override exists. */ | |
11082 | if (flag_default_inline && !processing_template_defn) | |
11083 | DECL_INLINE (fndecl) = 1; | |
11084 | ||
11085 | /* We read in the parameters on the maybepermanent_obstack, | |
11086 | but we won't be getting back to them until after we | |
11087 | may have clobbered them. So the call to preserve_data | |
11088 | will keep them safe. */ | |
11089 | preserve_data (); | |
11090 | ||
11091 | if (! DECL_FRIEND_P (fndecl)) | |
11092 | { | |
11093 | if (DECL_CHAIN (fndecl) != NULL_TREE) | |
11094 | { | |
11095 | /* Need a fresh node here so that we don't get circularity | |
11096 | when we link these together. If FNDECL was a friend, then | |
11097 | `pushdecl' does the right thing, which is nothing wrt its | |
11098 | current value of DECL_CHAIN. */ | |
11099 | fndecl = copy_node (fndecl); | |
11100 | } | |
11101 | if (TREE_CHAIN (fndecl)) | |
11102 | { | |
11103 | fndecl = copy_node (fndecl); | |
11104 | TREE_CHAIN (fndecl) = NULL_TREE; | |
11105 | } | |
11106 | ||
11107 | if (DECL_CONSTRUCTOR_P (fndecl)) | |
11108 | grok_ctor_properties (current_class_type, fndecl); | |
11109 | else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) | |
11110 | grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl)); | |
11111 | } | |
11112 | ||
11113 | finish_decl (fndecl, NULL_TREE, NULL_TREE, 0); | |
11114 | ||
11115 | /* Make a place for the parms */ | |
11116 | pushlevel (0); | |
11117 | current_binding_level->parm_flag = 1; | |
11118 | ||
11119 | DECL_IN_AGGR_P (fndecl) = 1; | |
11120 | return fndecl; | |
11121 | } | |
11122 | ||
11123 | /* Go through the motions of finishing a function definition. | |
11124 | We don't compile this method until after the whole class has | |
11125 | been processed. | |
11126 | ||
11127 | FINISH_METHOD must return something that looks as though it | |
11128 | came from GROKFIELD (since we are defining a method, after all). | |
11129 | ||
11130 | This is called after parsing the body of the function definition. | |
11131 | STMTS is the chain of statements that makes up the function body. | |
11132 | ||
11133 | DECL is the ..._DECL that `start_method' provided. */ | |
11134 | ||
11135 | tree | |
11136 | finish_method (decl) | |
11137 | tree decl; | |
11138 | { | |
11139 | register tree fndecl = decl; | |
11140 | tree old_initial; | |
11141 | tree context = DECL_CONTEXT (fndecl); | |
11142 | ||
11143 | register tree link; | |
11144 | ||
11145 | if (TYPE_MAIN_VARIANT (decl) == void_type_node) | |
11146 | return decl; | |
11147 | ||
11148 | #ifdef DEBUG_CP_BINDING_LEVELS | |
11149 | indent_to (stderr, debug_bindings_indentation); | |
11150 | fprintf (stderr, "finish_method"); | |
11151 | debug_bindings_indentation += 4; | |
11152 | #endif | |
11153 | ||
11154 | old_initial = DECL_INITIAL (fndecl); | |
11155 | ||
11156 | /* Undo the level for the parms (from start_method). | |
11157 | This is like poplevel, but it causes nothing to be | |
11158 | saved. Saving information here confuses symbol-table | |
11159 | output routines. Besides, this information will | |
11160 | be correctly output when this method is actually | |
11161 | compiled. */ | |
11162 | ||
11163 | /* Clear out the meanings of the local variables of this level; | |
11164 | also record in each decl which block it belongs to. */ | |
11165 | ||
11166 | for (link = current_binding_level->names; link; link = TREE_CHAIN (link)) | |
11167 | { | |
11168 | if (DECL_NAME (link) != NULL_TREE) | |
11169 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; | |
11170 | my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163); | |
11171 | DECL_CONTEXT (link) = NULL_TREE; | |
11172 | } | |
11173 | ||
11174 | /* Restore all name-meanings of the outer levels | |
11175 | that were shadowed by this level. */ | |
11176 | ||
11177 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
11178 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
11179 | for (link = current_binding_level->class_shadowed; | |
11180 | link; link = TREE_CHAIN (link)) | |
11181 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
11182 | for (link = current_binding_level->type_shadowed; | |
11183 | link; link = TREE_CHAIN (link)) | |
11184 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
11185 | ||
11186 | GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, | |
11187 | (HOST_WIDE_INT) current_binding_level->level_chain, | |
11188 | current_binding_level->parm_flag, | |
11189 | current_binding_level->keep, | |
11190 | current_binding_level->tag_transparent); | |
11191 | ||
11192 | pop_binding_level (); | |
11193 | ||
11194 | DECL_INITIAL (fndecl) = old_initial; | |
11195 | #if 0 | |
11196 | /* tiemann would like this, but is causes String.cc to not compile. */ | |
11197 | if (DECL_FRIEND_P (fndecl) || DECL_CONTEXT (fndecl) != current_class_type) | |
11198 | #else | |
11199 | if (DECL_FRIEND_P (fndecl)) | |
11200 | #endif | |
11201 | { | |
11202 | CLASSTYPE_INLINE_FRIENDS (current_class_type) | |
11203 | = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type)); | |
11204 | decl = void_type_node; | |
11205 | } | |
11206 | #if 0 | |
11207 | /* Work in progress, 9/17/92. */ | |
11208 | else if (context != current_class_type | |
11209 | && TREE_CHAIN (context) != NULL_TREE | |
11210 | && !DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl))) | |
11211 | { | |
11212 | /* Don't allow them to declare a function like this: | |
11213 | class A { | |
11214 | public: | |
11215 | class B { | |
11216 | public: | |
11217 | int f(); | |
11218 | }; | |
11219 | int B::f() {} | |
11220 | }; | |
11221 | ||
11222 | Note we can get in here if it's a friend (in which case we'll | |
11223 | avoid lots of nasty cruft), or it's a destructor. Compensate. | |
11224 | */ | |
11225 | tree tmp = DECL_ARGUMENTS (TREE_CHAIN (context)); | |
11226 | if (tmp | |
11227 | && TREE_CODE (tmp) == IDENTIFIER_NODE | |
11228 | && TREE_CHAIN (IDENTIFIER_GLOBAL_VALUE (tmp)) | |
11229 | && TREE_CODE (TREE_CHAIN (IDENTIFIER_GLOBAL_VALUE (tmp))) == TYPE_DECL) | |
11230 | { | |
11231 | error_with_decl (decl, | |
11232 | "qualified name used in declaration of `%s'"); | |
11233 | /* Make this node virtually unusable in the end. */ | |
11234 | TREE_CHAIN (decl) = NULL_TREE; | |
11235 | } | |
11236 | } | |
11237 | #endif | |
11238 | ||
11239 | #ifdef DEBUG_CP_BINDING_LEVELS | |
11240 | debug_bindings_indentation -= 4; | |
11241 | #endif | |
11242 | ||
11243 | return decl; | |
11244 | } | |
11245 | \f | |
11246 | /* Called when a new struct TYPE is defined. | |
11247 | If this structure or union completes the type of any previous | |
11248 | variable declaration, lay it out and output its rtl. */ | |
11249 | ||
11250 | void | |
11251 | hack_incomplete_structures (type) | |
11252 | tree type; | |
11253 | { | |
11254 | tree decl; | |
11255 | ||
11256 | if (current_binding_level->n_incomplete == 0) | |
11257 | return; | |
11258 | ||
11259 | if (!type) /* Don't do this for class templates. */ | |
11260 | return; | |
11261 | ||
11262 | for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl)) | |
11263 | if (TREE_TYPE (decl) == type | |
11264 | || (TREE_TYPE (decl) | |
11265 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
11266 | && TREE_TYPE (TREE_TYPE (decl)) == type)) | |
11267 | { | |
11268 | if (TREE_CODE (decl) == TYPE_DECL) | |
11269 | layout_type (TREE_TYPE (decl)); | |
11270 | else | |
11271 | { | |
11272 | int toplevel = global_binding_level == current_binding_level; | |
11273 | if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
11274 | && TREE_TYPE (TREE_TYPE (decl)) == type) | |
11275 | layout_type (TREE_TYPE (decl)); | |
11276 | layout_decl (decl, 0); | |
11277 | rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); | |
11278 | if (! toplevel) | |
11279 | { | |
11280 | expand_decl (decl); | |
11281 | expand_decl_cleanup (decl, maybe_build_cleanup (decl)); | |
11282 | expand_decl_init (decl); | |
11283 | } | |
11284 | } | |
11285 | my_friendly_assert (current_binding_level->n_incomplete > 0, 164); | |
11286 | --current_binding_level->n_incomplete; | |
11287 | } | |
11288 | } | |
11289 | ||
11290 | /* Nonzero if presently building a cleanup. Needed because | |
11291 | SAVE_EXPRs are not the right things to use inside of cleanups. | |
11292 | They are only ever evaluated once, where the cleanup | |
11293 | might be evaluated several times. In this case, a later evaluation | |
11294 | of the cleanup might fill in the SAVE_EXPR_RTL, and it will | |
11295 | not be valid for an earlier cleanup. */ | |
11296 | ||
11297 | int building_cleanup; | |
11298 | ||
11299 | /* If DECL is of a type which needs a cleanup, build that cleanup here. | |
11300 | We don't build cleanups if just going for syntax checking, since | |
11301 | fixup_cleanups does not know how to not handle them. | |
11302 | ||
11303 | Don't build these on the momentary obstack; they must live | |
11304 | the life of the binding contour. */ | |
11305 | tree | |
11306 | maybe_build_cleanup (decl) | |
11307 | tree decl; | |
11308 | { | |
11309 | tree type = TREE_TYPE (decl); | |
11310 | if (TYPE_NEEDS_DESTRUCTOR (type)) | |
11311 | { | |
11312 | int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; | |
11313 | tree rval; | |
11314 | int old_building_cleanup = building_cleanup; | |
11315 | building_cleanup = 1; | |
11316 | ||
11317 | if (TREE_CODE (decl) != PARM_DECL) | |
11318 | temp = suspend_momentary (); | |
11319 | ||
11320 | if (TREE_CODE (type) == ARRAY_TYPE) | |
11321 | rval = decl; | |
11322 | else | |
11323 | { | |
11324 | mark_addressable (decl); | |
11325 | rval = build_unary_op (ADDR_EXPR, decl, 0); | |
11326 | } | |
11327 | ||
11328 | /* Optimize for space over speed here. */ | |
11329 | if (! TYPE_USES_VIRTUAL_BASECLASSES (type) | |
11330 | || flag_expensive_optimizations) | |
11331 | flags |= LOOKUP_NONVIRTUAL; | |
11332 | ||
11333 | /* Use TYPE_MAIN_VARIANT so we don't get a warning about | |
11334 | calling delete on a `const' variable. */ | |
11335 | if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval)))) | |
11336 | rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval); | |
11337 | ||
11338 | rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0, 0); | |
11339 | ||
11340 | if (TYPE_USES_VIRTUAL_BASECLASSES (type) | |
11341 | && ! TYPE_HAS_DESTRUCTOR (type)) | |
11342 | rval = build_compound_expr (tree_cons (NULL_TREE, rval, | |
11343 | build_tree_list (NULL_TREE, build_vbase_delete (type, decl)))); | |
11344 | ||
11345 | current_binding_level->have_cleanups = 1; | |
11346 | current_binding_level->more_exceptions_ok = 0; | |
11347 | ||
11348 | if (TREE_CODE (decl) != PARM_DECL) | |
11349 | resume_momentary (temp); | |
11350 | ||
11351 | building_cleanup = old_building_cleanup; | |
11352 | ||
11353 | return rval; | |
11354 | } | |
11355 | return 0; | |
11356 | } | |
11357 | \f | |
11358 | /* Expand a C++ expression at the statement level. | |
11359 | This is needed to ferret out nodes which have UNKNOWN_TYPE. | |
11360 | The C++ type checker should get all of these out when | |
11361 | expressions are combined with other, type-providing, expressions, | |
11362 | leaving only orphan expressions, such as: | |
11363 | ||
11364 | &class::bar; / / takes its address, but does nothing with it. | |
11365 | ||
11366 | */ | |
11367 | void | |
11368 | cplus_expand_expr_stmt (exp) | |
11369 | tree exp; | |
11370 | { | |
11371 | if (TREE_TYPE (exp) == unknown_type_node) | |
11372 | { | |
11373 | if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST) | |
11374 | error ("address of overloaded function with no contextual type information"); | |
11375 | else if (TREE_CODE (exp) == COMPONENT_REF) | |
11376 | warning ("useless reference to a member function name, did you forget the ()?"); | |
11377 | } | |
11378 | else | |
11379 | { | |
11380 | int remove_implicit_immediately = 0; | |
11381 | ||
11382 | if (TREE_CODE (exp) == FUNCTION_DECL) | |
11383 | { | |
11384 | warning_with_decl (exp, "reference, not call, to function `%s'"); | |
11385 | warning ("at this point in file"); | |
11386 | } | |
11387 | if (TREE_RAISES (exp)) | |
11388 | { | |
11389 | my_friendly_assert (flag_handle_exceptions, 165); | |
11390 | if (flag_handle_exceptions == 2) | |
11391 | { | |
11392 | if (! current_binding_level->more_exceptions_ok) | |
11393 | { | |
11394 | extern struct nesting *nesting_stack, *block_stack; | |
11395 | ||
11396 | remove_implicit_immediately | |
11397 | = (nesting_stack != block_stack); | |
11398 | cplus_expand_start_try (1); | |
11399 | } | |
11400 | current_binding_level->have_exceptions = 1; | |
11401 | } | |
11402 | } | |
11403 | ||
11404 | expand_expr_stmt (break_out_cleanups (exp)); | |
11405 | ||
11406 | if (remove_implicit_immediately) | |
11407 | pop_implicit_try_blocks (NULL_TREE); | |
11408 | } | |
11409 | ||
11410 | /* Clean up any pending cleanups. This happens when a function call | |
11411 | returns a cleanup-needing value that nobody uses. */ | |
11412 | expand_cleanups_to (NULL_TREE); | |
11413 | } | |
11414 | ||
11415 | /* When a stmt has been parsed, this function is called. | |
11416 | ||
11417 | Currently, this function only does something within a | |
11418 | constructor's scope: if a stmt has just assigned to this, | |
11419 | and we are in a derived class, we call `emit_base_init'. */ | |
11420 | ||
11421 | void | |
11422 | finish_stmt () | |
11423 | { | |
11424 | extern struct nesting *cond_stack, *loop_stack, *case_stack; | |
11425 | ||
11426 | ||
11427 | if (current_function_assigns_this | |
11428 | || ! current_function_just_assigned_this) | |
11429 | return; | |
11430 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
11431 | { | |
11432 | /* Constructors must wait until we are out of control | |
11433 | zones before calling base constructors. */ | |
11434 | if (cond_stack || loop_stack || case_stack) | |
11435 | return; | |
11436 | emit_insns (base_init_insns); | |
11437 | check_base_init (current_class_type); | |
11438 | } | |
11439 | current_function_assigns_this = 1; | |
11440 | ||
11441 | if (flag_cadillac) | |
11442 | cadillac_finish_stmt (); | |
11443 | } | |
11444 | ||
11445 | void | |
11446 | pop_implicit_try_blocks (decl) | |
11447 | tree decl; | |
11448 | { | |
11449 | if (decl) | |
11450 | { | |
11451 | my_friendly_assert (current_binding_level->parm_flag == 3, 166); | |
11452 | current_binding_level->names = TREE_CHAIN (decl); | |
11453 | } | |
11454 | ||
11455 | while (current_binding_level->parm_flag == 3) | |
11456 | { | |
11457 | tree name = get_identifier ("(compiler error)"); | |
11458 | tree orig_ex_type = current_exception_type; | |
11459 | tree orig_ex_decl = current_exception_decl; | |
11460 | tree orig_ex_obj = current_exception_object; | |
11461 | tree decl = cplus_expand_end_try (2); | |
11462 | ||
11463 | /* @@ It would be nice to make all these point | |
11464 | to exactly the same handler. */ | |
11465 | /* Start hidden EXCEPT. */ | |
11466 | cplus_expand_start_except (name, decl); | |
11467 | /* reraise ALL. */ | |
11468 | cplus_expand_reraise (NULL_TREE); | |
11469 | current_exception_type = orig_ex_type; | |
11470 | current_exception_decl = orig_ex_decl; | |
11471 | current_exception_object = orig_ex_obj; | |
11472 | /* This will reraise for us. */ | |
11473 | cplus_expand_end_except (error_mark_node); | |
11474 | } | |
11475 | ||
11476 | if (decl) | |
11477 | { | |
11478 | TREE_CHAIN (decl) = current_binding_level->names; | |
11479 | current_binding_level->names = decl; | |
11480 | } | |
11481 | } | |
11482 | ||
11483 | /* Push a cleanup onto the current binding contour that will cause | |
11484 | ADDR to be cleaned up, in the case that an exception propagates | |
11485 | through its binding contour. */ | |
11486 | ||
11487 | void | |
11488 | push_exception_cleanup (addr) | |
11489 | tree addr; | |
11490 | { | |
11491 | tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node); | |
11492 | tree cleanup; | |
11493 | ||
11494 | decl = pushdecl (decl); | |
11495 | DECL_REGISTER (decl) = 1; | |
11496 | store_init_value (decl, addr); | |
11497 | expand_decl (decl); | |
11498 | expand_decl_init (decl); | |
11499 | ||
11500 | cleanup = build (COND_EXPR, integer_type_node, | |
11501 | build (NE_EXPR, integer_type_node, | |
11502 | decl, integer_zero_node), | |
11503 | build_delete (TREE_TYPE (addr), decl, | |
11504 | lookup_name (in_charge_identifier, 0), | |
11505 | LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0, 0), | |
11506 | integer_zero_node); | |
11507 | expand_decl_cleanup (decl, cleanup); | |
11508 | } | |
11509 | ||
11510 | /* For each binding contour, emit code that deactivates the | |
11511 | exception cleanups. All other cleanups are left as they were. */ | |
11512 | ||
11513 | static void | |
11514 | deactivate_exception_cleanups () | |
11515 | { | |
11516 | struct binding_level *b = current_binding_level; | |
11517 | tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME); | |
11518 | while (b != class_binding_level) | |
11519 | { | |
11520 | if (b->parm_flag == 3) | |
11521 | { | |
11522 | tree decls = b->names; | |
11523 | while (decls) | |
11524 | { | |
11525 | if (DECL_NAME (decls) == xyzzy) | |
11526 | expand_assignment (decls, integer_zero_node, 0, 0); | |
11527 | decls = TREE_CHAIN (decls); | |
11528 | } | |
11529 | } | |
11530 | b = b->level_chain; | |
11531 | } | |
11532 | } | |
11533 | ||
11534 | /* Change a static member function definition into a FUNCTION_TYPE, instead | |
11535 | of the METHOD_TYPE that we create when it's originally parsed. */ | |
11536 | void | |
11537 | revert_static_member_fn (fn, decl, argtypes) | |
11538 | tree *fn, *decl, *argtypes; | |
11539 | { | |
11540 | tree tmp, function = *fn; | |
11541 | ||
11542 | *argtypes = TREE_CHAIN (*argtypes); | |
11543 | tmp = build_function_type (TREE_TYPE (function), *argtypes); | |
11544 | tmp = build_type_variant (tmp, TYPE_READONLY (function), | |
11545 | TYPE_VOLATILE (function)); | |
11546 | tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp, | |
11547 | TYPE_RAISES_EXCEPTIONS (function)); | |
11548 | TREE_TYPE (*decl) = tmp; | |
11549 | *fn = tmp; | |
11550 | DECL_STATIC_FUNCTION_P (*decl) = 1; | |
11551 | } |