]>
Commit | Line | Data |
---|---|---|
9e28580c | 1 | /* Process declarations and variables for C++ compiler. |
956d6950 | 2 | Copyright (C) 1988, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc. |
8d08fdba MS |
3 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
e9fa0c7c RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
21 | |
22 | ||
23 | /* Process declarations and symbol lookup for C front end. | |
24 | Also constructs types; the standard scalar types at initialization, | |
25 | and structure, union, array and enum types when they are declared. */ | |
26 | ||
27 | /* ??? not all decl nodes are given the most useful possible | |
28 | line numbers. For example, the CONST_DECLs for enum values. */ | |
29 | ||
8d08fdba | 30 | #include "config.h" |
8d052bc7 | 31 | #include "system.h" |
8d08fdba MS |
32 | #include "tree.h" |
33 | #include "rtl.h" | |
34 | #include "flags.h" | |
35 | #include "cp-tree.h" | |
36 | #include "decl.h" | |
37 | #include "lex.h" | |
8d08fdba MS |
38 | #include <signal.h> |
39 | #include "obstack.h" | |
72b7eeff | 40 | #include "defaults.h" |
49c249e1 JM |
41 | #include "output.h" |
42 | #include "except.h" | |
8d08fdba MS |
43 | |
44 | #define obstack_chunk_alloc xmalloc | |
45 | #define obstack_chunk_free free | |
46 | ||
8d2733ca MS |
47 | extern tree builtin_return_address_fndecl; |
48 | ||
8d08fdba MS |
49 | extern struct obstack permanent_obstack; |
50 | ||
51 | extern int current_class_depth; | |
52 | ||
e1cd6e56 MS |
53 | extern tree static_ctors, static_dtors; |
54 | ||
42976354 BK |
55 | extern int static_labelno; |
56 | ||
30394414 JM |
57 | extern tree current_namespace; |
58 | extern tree global_namespace; | |
59 | ||
8d08fdba MS |
60 | /* Stack of places to restore the search obstack back to. */ |
61 | ||
62 | /* Obstack used for remembering local class declarations (like | |
63 | enums and static (const) members. */ | |
64 | #include "stack.h" | |
5566b478 | 65 | struct obstack decl_obstack; |
8d08fdba MS |
66 | static struct stack_level *decl_stack; |
67 | ||
68 | #ifndef CHAR_TYPE_SIZE | |
69 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
70 | #endif | |
71 | ||
72 | #ifndef SHORT_TYPE_SIZE | |
73 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) | |
74 | #endif | |
75 | ||
76 | #ifndef INT_TYPE_SIZE | |
77 | #define INT_TYPE_SIZE BITS_PER_WORD | |
78 | #endif | |
79 | ||
80 | #ifndef LONG_TYPE_SIZE | |
81 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
82 | #endif | |
83 | ||
84 | #ifndef LONG_LONG_TYPE_SIZE | |
85 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
86 | #endif | |
87 | ||
88 | #ifndef WCHAR_UNSIGNED | |
89 | #define WCHAR_UNSIGNED 0 | |
90 | #endif | |
91 | ||
92 | #ifndef FLOAT_TYPE_SIZE | |
93 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
94 | #endif | |
95 | ||
96 | #ifndef DOUBLE_TYPE_SIZE | |
97 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
98 | #endif | |
99 | ||
100 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
101 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
102 | #endif | |
103 | ||
255512c1 | 104 | #ifndef BOOL_TYPE_SIZE |
e1cd6e56 | 105 | #ifdef SLOW_BYTE_ACCESS |
d2e5ee5c | 106 | #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (POINTER_SIZE) : (CHAR_TYPE_SIZE)) |
e1cd6e56 | 107 | #else |
d2e5ee5c | 108 | #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE |
e1cd6e56 | 109 | #endif |
255512c1 JM |
110 | #endif |
111 | ||
8d08fdba MS |
112 | /* We let tm.h override the types used here, to handle trivial differences |
113 | such as the choice of unsigned int or long unsigned int for size_t. | |
114 | When machines start needing nontrivial differences in the size type, | |
115 | it would be best to do something here to figure out automatically | |
116 | from other information what type to use. */ | |
117 | ||
118 | #ifndef SIZE_TYPE | |
119 | #define SIZE_TYPE "long unsigned int" | |
120 | #endif | |
121 | ||
122 | #ifndef PTRDIFF_TYPE | |
123 | #define PTRDIFF_TYPE "long int" | |
124 | #endif | |
125 | ||
126 | #ifndef WCHAR_TYPE | |
127 | #define WCHAR_TYPE "int" | |
128 | #endif | |
129 | ||
8d08fdba MS |
130 | static tree grokparms PROTO((tree, int)); |
131 | static tree lookup_nested_type PROTO((tree, tree)); | |
132 | static char *redeclaration_error_message PROTO((tree, tree)); | |
bd6dd845 MS |
133 | static tree push_overloaded_decl PROTO((tree, int)); |
134 | static void push_overloaded_decl_top_level PROTO((tree, int)); | |
8d08fdba | 135 | |
49c249e1 JM |
136 | static struct stack_level *push_decl_level PROTO((struct stack_level *, |
137 | struct obstack *)); | |
138 | static void push_binding_level PROTO((struct binding_level *, int, | |
139 | int)); | |
140 | static void pop_binding_level PROTO((void)); | |
141 | static void suspend_binding_level PROTO((void)); | |
142 | static void resume_binding_level PROTO((struct binding_level *)); | |
143 | static struct binding_level *make_binding_level PROTO((void)); | |
144 | static int namespace_bindings_p PROTO((void)); | |
145 | static void declare_namespace_level PROTO((void)); | |
146 | static tree get_unique_name PROTO((void)); | |
147 | static void signal_catch PROTO((int)); | |
148 | static void storedecls PROTO((tree)); | |
149 | static void storetags PROTO((tree)); | |
150 | static void require_complete_types_for_parms PROTO((tree)); | |
151 | static void push_overloaded_decl_1 PROTO((tree)); | |
152 | static int ambi_op_p PROTO((tree)); | |
153 | static int unary_op_p PROTO((tree)); | |
154 | static tree store_bindings PROTO((tree, tree)); | |
155 | static tree lookup_tag_reverse PROTO((tree, tree)); | |
156 | static tree obscure_complex_init PROTO((tree, tree)); | |
157 | static tree maybe_build_cleanup_1 PROTO((tree, tree)); | |
158 | static tree lookup_name_real PROTO((tree, int, int)); | |
159 | static void warn_extern_redeclared_static PROTO((tree, tree)); | |
a703fb38 | 160 | static void grok_reference_init PROTO((tree, tree, tree)); |
386b8a85 | 161 | static tree grokfndecl PROTO((tree, tree, tree, tree, int, |
49c249e1 | 162 | enum overload_flags, |
386b8a85 | 163 | tree, tree, tree, int, int, int, int, int, int)); |
49c249e1 JM |
164 | static tree grokvardecl PROTO((tree, tree, RID_BIT_TYPE *, int, int)); |
165 | static tree lookup_tag PROTO((enum tree_code, tree, | |
166 | struct binding_level *, int)); | |
167 | static void set_identifier_type_value_with_scope | |
168 | PROTO((tree, tree, struct binding_level *)); | |
169 | static void record_builtin_type PROTO((enum rid, char *, tree)); | |
170 | static int member_function_or_else PROTO((tree, tree, char *)); | |
171 | static void bad_specifiers PROTO((tree, char *, int, int, int, int, | |
172 | int)); | |
1107c4b3 | 173 | static tree make_implicit_typename PROTO((tree, tree)); |
8d08fdba MS |
174 | |
175 | /* a node which has tree code ERROR_MARK, and whose type is itself. | |
176 | All erroneous expressions are replaced with this node. All functions | |
177 | that accept nodes as arguments should avoid generating error messages | |
178 | if this node is one of the arguments, since it is undesirable to get | |
179 | multiple error messages from one error in the input. */ | |
180 | ||
181 | tree error_mark_node; | |
182 | ||
183 | /* Erroneous argument lists can use this *IFF* they do not modify it. */ | |
184 | tree error_mark_list; | |
185 | ||
186 | /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ | |
187 | ||
188 | tree short_integer_type_node; | |
189 | tree integer_type_node; | |
190 | tree long_integer_type_node; | |
191 | tree long_long_integer_type_node; | |
192 | ||
193 | tree short_unsigned_type_node; | |
194 | tree unsigned_type_node; | |
195 | tree long_unsigned_type_node; | |
196 | tree long_long_unsigned_type_node; | |
197 | ||
198 | tree ptrdiff_type_node; | |
199 | ||
200 | tree unsigned_char_type_node; | |
201 | tree signed_char_type_node; | |
202 | tree char_type_node; | |
203 | tree wchar_type_node; | |
204 | tree signed_wchar_type_node; | |
205 | tree unsigned_wchar_type_node; | |
206 | ||
f376e137 MS |
207 | tree wchar_decl_node; |
208 | ||
8d08fdba MS |
209 | tree float_type_node; |
210 | tree double_type_node; | |
211 | tree long_double_type_node; | |
212 | ||
37c46b43 MS |
213 | tree complex_integer_type_node; |
214 | tree complex_float_type_node; | |
215 | tree complex_double_type_node; | |
216 | tree complex_long_double_type_node; | |
217 | ||
8d08fdba MS |
218 | tree intQI_type_node; |
219 | tree intHI_type_node; | |
220 | tree intSI_type_node; | |
221 | tree intDI_type_node; | |
222 | ||
223 | tree unsigned_intQI_type_node; | |
224 | tree unsigned_intHI_type_node; | |
225 | tree unsigned_intSI_type_node; | |
226 | tree unsigned_intDI_type_node; | |
227 | ||
228 | /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */ | |
229 | ||
230 | tree void_type_node, void_list_node; | |
231 | tree void_zero_node; | |
232 | ||
233 | /* Nodes for types `void *' and `const void *'. */ | |
234 | ||
bd6dd845 | 235 | tree ptr_type_node; |
6c20b7e9 | 236 | tree const_ptr_type_node; |
8d08fdba MS |
237 | |
238 | /* Nodes for types `char *' and `const char *'. */ | |
239 | ||
240 | tree string_type_node, const_string_type_node; | |
241 | ||
242 | /* Type `char[256]' or something like it. | |
243 | Used when an array of char is needed and the size is irrelevant. */ | |
244 | ||
245 | tree char_array_type_node; | |
246 | ||
247 | /* Type `int[256]' or something like it. | |
248 | Used when an array of int needed and the size is irrelevant. */ | |
249 | ||
250 | tree int_array_type_node; | |
251 | ||
252 | /* Type `wchar_t[256]' or something like it. | |
253 | Used when a wide string literal is created. */ | |
254 | ||
255 | tree wchar_array_type_node; | |
256 | ||
2986ae00 | 257 | /* The bool data type, and constants */ |
255512c1 | 258 | tree boolean_type_node, boolean_true_node, boolean_false_node; |
2986ae00 | 259 | |
8d08fdba MS |
260 | /* type `int ()' -- used for implicit declaration of functions. */ |
261 | ||
262 | tree default_function_type; | |
263 | ||
264 | /* function types `double (double)' and `double (double, double)', etc. */ | |
265 | ||
bd6dd845 MS |
266 | static tree double_ftype_double, double_ftype_double_double; |
267 | static tree int_ftype_int, long_ftype_long; | |
268 | static tree float_ftype_float; | |
269 | static tree ldouble_ftype_ldouble; | |
8d08fdba | 270 | |
8d08fdba | 271 | /* Function type `int (const void *, const void *, size_t)' */ |
5566b478 | 272 | static tree int_ftype_cptr_cptr_sizet; |
8d08fdba MS |
273 | |
274 | /* C++ extensions */ | |
700f8a87 | 275 | tree vtable_entry_type; |
8d08fdba | 276 | tree delta_type_node; |
db5ae43f | 277 | #if 0 |
e92cc029 | 278 | /* Old rtti stuff. */ |
db5ae43f MS |
279 | tree __baselist_desc_type_node; |
280 | tree __i_desc_type_node, __m_desc_type_node; | |
8d08fdba | 281 | tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; |
db5ae43f | 282 | #endif |
5566b478 MS |
283 | tree __t_desc_type_node; |
284 | #if 0 | |
285 | tree __tp_desc_type_node; | |
286 | #endif | |
db5ae43f MS |
287 | tree __access_mode_type_node; |
288 | tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node; | |
289 | tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node; | |
290 | tree __ptmf_desc_type_node, __ptmd_desc_type_node; | |
291 | #if 0 | |
292 | /* Not needed yet? May be needed one day? */ | |
293 | tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type; | |
294 | tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type; | |
295 | tree __ptmf_desc_array_type, __ptmd_desc_array_type; | |
296 | #endif | |
297 | ||
8d08fdba MS |
298 | tree class_star_type_node; |
299 | tree class_type_node, record_type_node, union_type_node, enum_type_node; | |
db5ae43f | 300 | tree unknown_type_node; |
8d08fdba MS |
301 | tree opaque_type_node, signature_type_node; |
302 | tree sigtable_entry_type; | |
8d08fdba | 303 | |
8d08fdba MS |
304 | /* Array type `vtable_entry_type[]' */ |
305 | tree vtbl_type_node; | |
306 | ||
6633d636 MS |
307 | /* namespace std */ |
308 | tree std_node; | |
309 | ||
8d08fdba MS |
310 | /* In a destructor, the point at which all derived class destroying |
311 | has been done, just before any base class destroying will be done. */ | |
312 | ||
313 | tree dtor_label; | |
314 | ||
72b7eeff MS |
315 | /* In a destructor, the last insn emitted after the start of the |
316 | function and the parms. */ | |
317 | ||
bd6dd845 | 318 | static rtx last_dtor_insn; |
72b7eeff | 319 | |
b87692e5 | 320 | /* In a constructor, the last insn emitted after the start of the |
9664b89e JM |
321 | function and the parms, the exception specification and any |
322 | function-try-block. The constructor initializers are emitted after | |
323 | this insn. */ | |
b87692e5 MS |
324 | |
325 | static rtx last_parm_cleanup_insn; | |
326 | ||
8d08fdba MS |
327 | /* In a constructor, the point at which we are ready to return |
328 | the pointer to the initialized object. */ | |
329 | ||
330 | tree ctor_label; | |
331 | ||
8d08fdba MS |
332 | /* A FUNCTION_DECL which can call `abort'. Not necessarily the |
333 | one that the user will declare, but sufficient to be called | |
334 | by routines that want to abort the program. */ | |
335 | ||
336 | tree abort_fndecl; | |
337 | ||
338 | extern rtx cleanup_label, return_label; | |
339 | ||
340 | /* If original DECL_RESULT of current function was a register, | |
341 | but due to being an addressable named return value, would up | |
342 | on the stack, this variable holds the named return value's | |
343 | original location. */ | |
bd6dd845 | 344 | static rtx original_result_rtx; |
8d08fdba MS |
345 | |
346 | /* Sequence of insns which represents base initialization. */ | |
a9aedbc2 | 347 | tree base_init_expr; |
8d08fdba MS |
348 | |
349 | /* C++: Keep these around to reduce calls to `get_identifier'. | |
350 | Identifiers for `this' in member functions and the auto-delete | |
351 | parameter for destructors. */ | |
352 | tree this_identifier, in_charge_identifier; | |
fc378698 | 353 | tree ctor_identifier, dtor_identifier; |
e92cc029 | 354 | /* Used in pointer to member functions, in vtables, and in sigtables. */ |
8d08fdba | 355 | tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; |
9dd70aa4 | 356 | tree pfn_or_delta2_identifier, tag_identifier; |
5566b478 | 357 | tree vt_off_identifier; |
8d08fdba | 358 | |
e349ee73 MS |
359 | struct named_label_list |
360 | { | |
361 | struct binding_level *binding_level; | |
362 | tree names_in_scope; | |
363 | tree label_decl; | |
364 | char *filename_o_goto; | |
365 | int lineno_o_goto; | |
366 | struct named_label_list *next; | |
367 | }; | |
368 | ||
8d08fdba MS |
369 | /* A list (chain of TREE_LIST nodes) of named label uses. |
370 | The TREE_PURPOSE field is the list of variables defined | |
371 | the the label's scope defined at the point of use. | |
372 | The TREE_VALUE field is the LABEL_DECL used. | |
373 | The TREE_TYPE field holds `current_binding_level' at the | |
374 | point of the label's use. | |
375 | ||
e349ee73 MS |
376 | BWAHAHAAHAHahhahahahaah. No, no, no, said the little chicken. |
377 | ||
378 | Look at the pretty struct named_label_list. See the pretty struct | |
379 | with the pretty named fields that describe what they do. See the | |
380 | pretty lack of gratuitous casts. Notice the code got a lot cleaner. | |
381 | ||
8d08fdba MS |
382 | Used only for jumps to as-yet undefined labels, since |
383 | jumps to defined labels can have their validity checked | |
384 | by stmt.c. */ | |
385 | ||
e349ee73 | 386 | static struct named_label_list *named_label_uses = NULL; |
8d08fdba MS |
387 | |
388 | /* A list of objects which have constructors or destructors | |
389 | which reside in the global scope. The decl is stored in | |
390 | the TREE_VALUE slot and the initializer is stored | |
391 | in the TREE_PURPOSE slot. */ | |
392 | tree static_aggregates; | |
393 | ||
8d08fdba MS |
394 | /* -- end of C++ */ |
395 | ||
396 | /* Two expressions that are constants with value zero. | |
397 | The first is of type `int', the second of type `void *'. */ | |
398 | ||
399 | tree integer_zero_node; | |
400 | tree null_pointer_node; | |
401 | ||
d11ad92e MS |
402 | /* The value for __null (NULL), either of type `void *' or, with -ansi, |
403 | an integer type of the same size. */ | |
404 | ||
405 | tree null_node; | |
406 | ||
8d08fdba MS |
407 | /* A node for the integer constants 1, 2, and 3. */ |
408 | ||
409 | tree integer_one_node, integer_two_node, integer_three_node; | |
410 | ||
8d08fdba MS |
411 | /* While defining an enum type, this is 1 plus the last enumerator |
412 | constant value. */ | |
413 | ||
414 | static tree enum_next_value; | |
415 | ||
7177d104 MS |
416 | /* Nonzero means that there was overflow computing enum_next_value. */ |
417 | ||
418 | static int enum_overflow; | |
419 | ||
8d08fdba MS |
420 | /* Parsing a function declarator leaves a list of parameter names |
421 | or a chain or parameter decls here. */ | |
422 | ||
423 | tree last_function_parms; | |
424 | ||
425 | /* Parsing a function declarator leaves here a chain of structure | |
426 | and enum types declared in the parmlist. */ | |
427 | ||
428 | static tree last_function_parm_tags; | |
429 | ||
430 | /* After parsing the declarator that starts a function definition, | |
431 | `start_function' puts here the list of parameter names or chain of decls. | |
432 | `store_parm_decls' finds it here. */ | |
433 | ||
434 | static tree current_function_parms; | |
435 | ||
436 | /* Similar, for last_function_parm_tags. */ | |
437 | static tree current_function_parm_tags; | |
438 | ||
439 | /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function | |
440 | that have names. Here so we can clear out their names' definitions | |
441 | at the end of the function. */ | |
442 | ||
443 | static tree named_labels; | |
444 | ||
445 | /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ | |
446 | ||
447 | static tree shadowed_labels; | |
448 | ||
8d08fdba MS |
449 | /* The FUNCTION_DECL for the function currently being compiled, |
450 | or 0 if between functions. */ | |
451 | tree current_function_decl; | |
452 | ||
453 | /* Set to 0 at beginning of a function definition, set to 1 if | |
454 | a return statement that specifies a return value is seen. */ | |
455 | ||
456 | int current_function_returns_value; | |
457 | ||
458 | /* Set to 0 at beginning of a function definition, set to 1 if | |
459 | a return statement with no argument is seen. */ | |
460 | ||
461 | int current_function_returns_null; | |
462 | ||
463 | /* Set to 0 at beginning of a function definition, and whenever | |
464 | a label (case or named) is defined. Set to value of expression | |
465 | returned from function when that value can be transformed into | |
466 | a named return value. */ | |
467 | ||
468 | tree current_function_return_value; | |
469 | ||
470 | /* Set to nonzero by `grokdeclarator' for a function | |
471 | whose return type is defaulted, if warnings for this are desired. */ | |
472 | ||
473 | static int warn_about_return_type; | |
474 | ||
8d08fdba MS |
475 | /* Nonzero means give `double' the same size as `float'. */ |
476 | ||
477 | extern int flag_short_double; | |
478 | ||
479 | /* Nonzero means don't recognize any builtin functions. */ | |
480 | ||
481 | extern int flag_no_builtin; | |
482 | ||
00595019 MS |
483 | /* Nonzero means don't recognize the non-ANSI builtin functions. |
484 | -ansi sets this. */ | |
485 | ||
486 | extern int flag_no_nonansi_builtin; | |
487 | ||
e1cd6e56 MS |
488 | /* Nonzero means enable obscure ANSI features and disable GNU extensions |
489 | that might cause ANSI-compliant code to be miscompiled. */ | |
8d08fdba MS |
490 | |
491 | extern int flag_ansi; | |
492 | ||
493 | /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) | |
e92cc029 | 494 | objects. */ |
8d08fdba MS |
495 | extern int flag_huge_objects; |
496 | ||
497 | /* Nonzero if we want to conserve space in the .o files. We do this | |
498 | by putting uninitialized data and runtime initialized data into | |
ddd5a7c1 | 499 | .common instead of .data at the expense of not flagging multiple |
8d08fdba MS |
500 | definitions. */ |
501 | extern int flag_conserve_space; | |
502 | ||
503 | /* Pointers to the base and current top of the language name stack. */ | |
504 | ||
505 | extern tree *current_lang_base, *current_lang_stack; | |
506 | \f | |
51c184be | 507 | /* C and C++ flags are in decl2.c. */ |
8d08fdba MS |
508 | |
509 | /* Set to 0 at beginning of a constructor, set to 1 | |
510 | if that function does an allocation before referencing its | |
511 | instance variable. */ | |
5566b478 | 512 | static int current_function_assigns_this; |
8d08fdba MS |
513 | int current_function_just_assigned_this; |
514 | ||
515 | /* Set to 0 at beginning of a function. Set non-zero when | |
516 | store_parm_decls is called. Don't call store_parm_decls | |
517 | if this flag is non-zero! */ | |
518 | int current_function_parms_stored; | |
519 | ||
51c184be | 520 | /* Flag used when debugging spew.c */ |
8d08fdba MS |
521 | |
522 | extern int spew_debug; | |
523 | ||
524 | /* This is a copy of the class_shadowed list of the previous class binding | |
525 | contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs | |
526 | when entering another class scope (i.e. a cache miss). */ | |
527 | extern tree previous_class_values; | |
528 | ||
e92cc029 MS |
529 | /* A expression of value 0 with the same precision as a sizetype |
530 | node, but signed. */ | |
531 | tree signed_size_zero_node; | |
532 | ||
8d08fdba MS |
533 | \f |
534 | /* Allocate a level of searching. */ | |
e92cc029 | 535 | |
824b9a4c | 536 | static |
8d08fdba MS |
537 | struct stack_level * |
538 | push_decl_level (stack, obstack) | |
539 | struct stack_level *stack; | |
540 | struct obstack *obstack; | |
541 | { | |
542 | struct stack_level tem; | |
543 | tem.prev = stack; | |
544 | ||
545 | return push_stack_level (obstack, (char *)&tem, sizeof (tem)); | |
546 | } | |
547 | \f | |
548 | /* For each binding contour we allocate a binding_level structure | |
e92cc029 MS |
549 | which records the names defined in that contour. |
550 | Contours include: | |
551 | 0) the global one | |
552 | 1) one for each function definition, | |
553 | where internal declarations of the parameters appear. | |
554 | 2) one for each compound statement, | |
555 | to record its declarations. | |
556 | ||
557 | The current meaning of a name can be found by searching the levels | |
558 | from the current one out to the global one. | |
559 | ||
560 | Off to the side, may be the class_binding_level. This exists only | |
561 | to catch class-local declarations. It is otherwise nonexistent. | |
562 | ||
563 | Also there may be binding levels that catch cleanups that must be | |
564 | run when exceptions occur. */ | |
8d08fdba MS |
565 | |
566 | /* Note that the information in the `names' component of the global contour | |
567 | is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ | |
568 | ||
569 | struct binding_level | |
570 | { | |
571 | /* A chain of _DECL nodes for all variables, constants, functions, | |
e92cc029 MS |
572 | and typedef types. These are in the reverse of the order |
573 | supplied. */ | |
8d08fdba MS |
574 | tree names; |
575 | ||
e92cc029 MS |
576 | /* A list of structure, union and enum definitions, for looking up |
577 | tag names. | |
578 | It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, | |
579 | or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, | |
580 | or ENUMERAL_TYPE node. | |
581 | ||
582 | C++: the TREE_VALUE nodes can be simple types for | |
583 | component_bindings. */ | |
8d08fdba MS |
584 | tree tags; |
585 | ||
586 | /* For each level, a list of shadowed outer-level local definitions | |
587 | to be restored when this level is popped. | |
588 | Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and | |
589 | whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ | |
590 | tree shadowed; | |
591 | ||
592 | /* Same, for IDENTIFIER_CLASS_VALUE. */ | |
593 | tree class_shadowed; | |
594 | ||
595 | /* Same, for IDENTIFIER_TYPE_VALUE. */ | |
596 | tree type_shadowed; | |
597 | ||
598 | /* For each level (except not the global one), | |
599 | a chain of BLOCK nodes for all the levels | |
600 | that were entered and exited one level down. */ | |
601 | tree blocks; | |
602 | ||
603 | /* The BLOCK node for this level, if one has been preallocated. | |
604 | If 0, the BLOCK is allocated (if needed) when the level is popped. */ | |
605 | tree this_block; | |
606 | ||
607 | /* The binding level which this one is contained in (inherits from). */ | |
608 | struct binding_level *level_chain; | |
609 | ||
f30432d7 | 610 | /* List of decls in `names' that have incomplete |
8d08fdba | 611 | structure or union types. */ |
f30432d7 | 612 | tree incomplete; |
8d08fdba | 613 | |
8d6e462b | 614 | /* List of VAR_DECLS saved from a previous for statement. |
abc95ed3 | 615 | These would be dead in ANSI-conforming code, but might |
d22c8596 | 616 | be referenced in ARM-era code. */ |
8d6e462b PB |
617 | tree dead_vars_from_for; |
618 | ||
8d08fdba MS |
619 | /* 1 for the level that holds the parameters of a function. |
620 | 2 for the level that holds a class declaration. | |
621 | 3 for levels that hold parameter declarations. */ | |
622 | unsigned parm_flag : 4; | |
623 | ||
624 | /* 1 means make a BLOCK for this level regardless of all else. | |
625 | 2 for temporary binding contours created by the compiler. */ | |
626 | unsigned keep : 3; | |
627 | ||
628 | /* Nonzero if this level "doesn't exist" for tags. */ | |
629 | unsigned tag_transparent : 1; | |
630 | ||
631 | /* Nonzero if this level can safely have additional | |
632 | cleanup-needing variables added to it. */ | |
633 | unsigned more_cleanups_ok : 1; | |
634 | unsigned have_cleanups : 1; | |
635 | ||
5566b478 MS |
636 | /* Nonzero if this level is for storing the decls for template |
637 | parameters and generic decls; these decls will be discarded and | |
638 | replaced with a TEMPLATE_DECL. */ | |
8d08fdba MS |
639 | unsigned pseudo_global : 1; |
640 | ||
a9aedbc2 MS |
641 | /* This is set for a namespace binding level. */ |
642 | unsigned namespace_p : 1; | |
643 | ||
2ee887f2 | 644 | /* True if this level is that of a for-statement where we need to |
d22c8596 | 645 | worry about ambiguous (ARM or ANSI) scope rules. */ |
8d6e462b PB |
646 | unsigned is_for_scope : 1; |
647 | ||
5566b478 | 648 | /* Two bits left for this word. */ |
8d08fdba MS |
649 | |
650 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
651 | /* Binding depth at which this level began. */ | |
652 | unsigned binding_depth; | |
653 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
654 | }; | |
655 | ||
656 | #define NULL_BINDING_LEVEL ((struct binding_level *) NULL) | |
657 | ||
658 | /* The (non-class) binding level currently in effect. */ | |
659 | ||
660 | static struct binding_level *current_binding_level; | |
661 | ||
662 | /* The binding level of the current class, if any. */ | |
663 | ||
664 | static struct binding_level *class_binding_level; | |
665 | ||
666 | /* The current (class or non-class) binding level currently in effect. */ | |
667 | ||
668 | #define inner_binding_level \ | |
669 | (class_binding_level ? class_binding_level : current_binding_level) | |
670 | ||
671 | /* A chain of binding_level structures awaiting reuse. */ | |
672 | ||
673 | static struct binding_level *free_binding_level; | |
674 | ||
675 | /* The outermost binding level, for names of file scope. | |
676 | This is created when the compiler is started and exists | |
677 | through the entire run. */ | |
678 | ||
679 | static struct binding_level *global_binding_level; | |
680 | ||
681 | /* Binding level structures are initialized by copying this one. */ | |
682 | ||
683 | static struct binding_level clear_binding_level; | |
684 | ||
685 | /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ | |
686 | ||
687 | static int keep_next_level_flag; | |
688 | ||
689 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
690 | static int binding_depth = 0; | |
691 | static int is_class_level = 0; | |
692 | ||
693 | static void | |
694 | indent () | |
695 | { | |
696 | register unsigned i; | |
697 | ||
698 | for (i = 0; i < binding_depth*2; i++) | |
699 | putc (' ', stderr); | |
700 | } | |
701 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
702 | ||
703 | static tree pushdecl_with_scope PROTO((tree, struct binding_level *)); | |
704 | ||
705 | static void | |
706 | push_binding_level (newlevel, tag_transparent, keep) | |
707 | struct binding_level *newlevel; | |
708 | int tag_transparent, keep; | |
709 | { | |
710 | /* Add this level to the front of the chain (stack) of levels that | |
711 | are active. */ | |
712 | *newlevel = clear_binding_level; | |
713 | if (class_binding_level) | |
714 | { | |
715 | newlevel->level_chain = class_binding_level; | |
716 | class_binding_level = (struct binding_level *)0; | |
717 | } | |
718 | else | |
719 | { | |
720 | newlevel->level_chain = current_binding_level; | |
721 | } | |
722 | current_binding_level = newlevel; | |
723 | newlevel->tag_transparent = tag_transparent; | |
724 | newlevel->more_cleanups_ok = 1; | |
8d08fdba MS |
725 | newlevel->keep = keep; |
726 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
727 | newlevel->binding_depth = binding_depth; | |
728 | indent (); | |
729 | fprintf (stderr, "push %s level 0x%08x line %d\n", | |
730 | (is_class_level) ? "class" : "block", newlevel, lineno); | |
731 | is_class_level = 0; | |
732 | binding_depth++; | |
733 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
734 | } | |
735 | ||
736 | static void | |
737 | pop_binding_level () | |
738 | { | |
739 | if (class_binding_level) | |
740 | current_binding_level = class_binding_level; | |
741 | ||
742 | if (global_binding_level) | |
743 | { | |
e92cc029 | 744 | /* cannot pop a level, if there are none left to pop. */ |
8d08fdba MS |
745 | if (current_binding_level == global_binding_level) |
746 | my_friendly_abort (123); | |
747 | } | |
748 | /* Pop the current level, and free the structure for reuse. */ | |
749 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
750 | binding_depth--; | |
751 | indent (); | |
752 | fprintf (stderr, "pop %s level 0x%08x line %d\n", | |
753 | (is_class_level) ? "class" : "block", | |
754 | current_binding_level, lineno); | |
755 | if (is_class_level != (current_binding_level == class_binding_level)) | |
9e9ff709 MS |
756 | { |
757 | indent (); | |
758 | fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); | |
759 | } | |
8d08fdba MS |
760 | is_class_level = 0; |
761 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
762 | { | |
763 | register struct binding_level *level = current_binding_level; | |
764 | current_binding_level = current_binding_level->level_chain; | |
765 | level->level_chain = free_binding_level; | |
766 | #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
767 | if (level->binding_depth != binding_depth) | |
768 | abort (); | |
769 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
770 | free_binding_level = level; | |
771 | ||
772 | class_binding_level = current_binding_level; | |
773 | if (class_binding_level->parm_flag != 2) | |
774 | class_binding_level = 0; | |
775 | while (current_binding_level->parm_flag == 2) | |
776 | current_binding_level = current_binding_level->level_chain; | |
777 | } | |
778 | } | |
a9aedbc2 MS |
779 | |
780 | static void | |
781 | suspend_binding_level () | |
782 | { | |
783 | if (class_binding_level) | |
784 | current_binding_level = class_binding_level; | |
785 | ||
786 | if (global_binding_level) | |
787 | { | |
e92cc029 | 788 | /* cannot suspend a level, if there are none left to suspend. */ |
a9aedbc2 MS |
789 | if (current_binding_level == global_binding_level) |
790 | my_friendly_abort (123); | |
791 | } | |
792 | /* Suspend the current level. */ | |
793 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
794 | binding_depth--; | |
795 | indent (); | |
796 | fprintf (stderr, "suspend %s level 0x%08x line %d\n", | |
797 | (is_class_level) ? "class" : "block", | |
798 | current_binding_level, lineno); | |
799 | if (is_class_level != (current_binding_level == class_binding_level)) | |
9e9ff709 MS |
800 | { |
801 | indent (); | |
802 | fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); | |
803 | } | |
a9aedbc2 MS |
804 | is_class_level = 0; |
805 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
806 | { | |
a9aedbc2 | 807 | current_binding_level = current_binding_level->level_chain; |
a9aedbc2 MS |
808 | class_binding_level = current_binding_level; |
809 | if (class_binding_level->parm_flag != 2) | |
810 | class_binding_level = 0; | |
811 | while (current_binding_level->parm_flag == 2) | |
812 | current_binding_level = current_binding_level->level_chain; | |
813 | } | |
814 | } | |
815 | ||
824b9a4c | 816 | static void |
a9aedbc2 MS |
817 | resume_binding_level (b) |
818 | struct binding_level *b; | |
819 | { | |
820 | if (class_binding_level) | |
821 | { | |
822 | #if 1 | |
e92cc029 | 823 | /* These are here because we cannot deal with shadows yet. */ |
a9aedbc2 MS |
824 | sorry ("cannot resume a namespace inside class"); |
825 | return; | |
826 | #else | |
827 | b->level_chain = class_binding_level; | |
828 | class_binding_level = (struct binding_level *)0; | |
829 | #endif | |
830 | } | |
831 | else | |
832 | { | |
833 | #if 1 | |
e92cc029 | 834 | /* These are here because we cannot deal with shadows yet. */ |
a9aedbc2 MS |
835 | if (b->level_chain != current_binding_level) |
836 | { | |
837 | sorry ("cannot resume a namespace inside a different namespace"); | |
838 | return; | |
839 | } | |
840 | #endif | |
841 | b->level_chain = current_binding_level; | |
842 | } | |
843 | current_binding_level = b; | |
844 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
845 | b->binding_depth = binding_depth; | |
846 | indent (); | |
847 | fprintf (stderr, "resume %s level 0x%08x line %d\n", | |
848 | (is_class_level) ? "class" : "block", b, lineno); | |
849 | is_class_level = 0; | |
850 | binding_depth++; | |
851 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
852 | } | |
8d08fdba | 853 | \f |
cffa8729 MS |
854 | /* Create a new `struct binding_level'. */ |
855 | ||
856 | static | |
857 | struct binding_level * | |
858 | make_binding_level () | |
859 | { | |
860 | /* NOSTRICT */ | |
861 | return (struct binding_level *) xmalloc (sizeof (struct binding_level)); | |
862 | } | |
863 | ||
8d08fdba MS |
864 | /* Nonzero if we are currently in the global binding level. */ |
865 | ||
866 | int | |
867 | global_bindings_p () | |
868 | { | |
869 | return current_binding_level == global_binding_level; | |
870 | } | |
871 | ||
a9aedbc2 MS |
872 | /* Nonzero if we are currently in a toplevel binding level. This |
873 | means either the global binding level or a namespace in a toplevel | |
874 | binding level. */ | |
875 | ||
876 | int | |
877 | toplevel_bindings_p () | |
878 | { | |
879 | struct binding_level *b = current_binding_level; | |
880 | ||
881 | while (1) | |
882 | { | |
883 | if (b == global_binding_level) | |
884 | return 1; | |
5566b478 MS |
885 | if (b->pseudo_global) |
886 | return 1; | |
a9aedbc2 MS |
887 | if (! b->namespace_p) |
888 | return 0; | |
889 | b=b->level_chain; | |
890 | } | |
891 | } | |
892 | ||
893 | /* Nonzero if this is a namespace scope. */ | |
894 | ||
824b9a4c | 895 | static int |
a9aedbc2 MS |
896 | namespace_bindings_p () |
897 | { | |
898 | return current_binding_level->namespace_p; | |
899 | } | |
900 | ||
8d08fdba MS |
901 | void |
902 | keep_next_level () | |
903 | { | |
904 | keep_next_level_flag = 1; | |
905 | } | |
906 | ||
907 | /* Nonzero if the current level needs to have a BLOCK made. */ | |
908 | ||
909 | int | |
910 | kept_level_p () | |
911 | { | |
912 | return (current_binding_level->blocks != NULL_TREE | |
913 | || current_binding_level->keep | |
914 | || current_binding_level->names != NULL_TREE | |
915 | || (current_binding_level->tags != NULL_TREE | |
916 | && !current_binding_level->tag_transparent)); | |
917 | } | |
918 | ||
919 | /* Identify this binding level as a level of parameters. */ | |
920 | ||
921 | void | |
922 | declare_parm_level () | |
923 | { | |
924 | current_binding_level->parm_flag = 1; | |
925 | } | |
926 | ||
8d08fdba MS |
927 | void |
928 | declare_pseudo_global_level () | |
929 | { | |
930 | current_binding_level->pseudo_global = 1; | |
931 | } | |
932 | ||
824b9a4c | 933 | static void |
a9aedbc2 MS |
934 | declare_namespace_level () |
935 | { | |
936 | current_binding_level->namespace_p = 1; | |
937 | } | |
938 | ||
8d08fdba MS |
939 | int |
940 | pseudo_global_level_p () | |
941 | { | |
942 | return current_binding_level->pseudo_global; | |
943 | } | |
944 | ||
945 | void | |
946 | set_class_shadows (shadows) | |
947 | tree shadows; | |
948 | { | |
949 | class_binding_level->class_shadowed = shadows; | |
950 | } | |
951 | ||
952 | /* Enter a new binding level. | |
953 | If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, | |
954 | not for that of tags. */ | |
955 | ||
956 | void | |
957 | pushlevel (tag_transparent) | |
958 | int tag_transparent; | |
959 | { | |
960 | register struct binding_level *newlevel = NULL_BINDING_LEVEL; | |
961 | ||
962 | /* If this is the top level of a function, | |
963 | just make sure that NAMED_LABELS is 0. | |
964 | They should have been set to 0 at the end of the previous function. */ | |
965 | ||
966 | if (current_binding_level == global_binding_level) | |
967 | my_friendly_assert (named_labels == NULL_TREE, 134); | |
968 | ||
969 | /* Reuse or create a struct for this binding level. */ | |
970 | ||
971 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
972 | if (0) | |
973 | #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
974 | if (free_binding_level) | |
975 | #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
976 | { | |
977 | newlevel = free_binding_level; | |
978 | free_binding_level = free_binding_level->level_chain; | |
979 | } | |
980 | else | |
981 | { | |
cffa8729 | 982 | newlevel = make_binding_level (); |
8d08fdba | 983 | } |
cffa8729 | 984 | |
8d08fdba MS |
985 | push_binding_level (newlevel, tag_transparent, keep_next_level_flag); |
986 | GNU_xref_start_scope ((HOST_WIDE_INT) newlevel); | |
987 | keep_next_level_flag = 0; | |
988 | } | |
989 | ||
5566b478 | 990 | void |
8d6e462b PB |
991 | note_level_for_for () |
992 | { | |
993 | current_binding_level->is_for_scope = 1; | |
994 | } | |
995 | ||
8d08fdba MS |
996 | void |
997 | pushlevel_temporary (tag_transparent) | |
998 | int tag_transparent; | |
999 | { | |
1000 | pushlevel (tag_transparent); | |
1001 | current_binding_level->keep = 2; | |
1002 | clear_last_expr (); | |
1003 | ||
1004 | /* Note we don't call push_momentary() here. Otherwise, it would cause | |
1005 | cleanups to be allocated on the momentary obstack, and they will be | |
1006 | overwritten by the next statement. */ | |
1007 | ||
1008 | expand_start_bindings (0); | |
1009 | } | |
1010 | ||
1011 | /* Exit a binding level. | |
1012 | Pop the level off, and restore the state of the identifier-decl mappings | |
1013 | that were in effect when this level was entered. | |
1014 | ||
1015 | If KEEP == 1, this level had explicit declarations, so | |
1016 | and create a "block" (a BLOCK node) for the level | |
1017 | to record its declarations and subblocks for symbol table output. | |
1018 | ||
1019 | If KEEP == 2, this level's subblocks go to the front, | |
1020 | not the back of the current binding level. This happens, | |
1021 | for instance, when code for constructors and destructors | |
1022 | need to generate code at the end of a function which must | |
1023 | be moved up to the front of the function. | |
1024 | ||
1025 | If FUNCTIONBODY is nonzero, this level is the body of a function, | |
1026 | so create a block as if KEEP were set and also clear out all | |
1027 | label names. | |
1028 | ||
1029 | If REVERSE is nonzero, reverse the order of decls before putting | |
1030 | them into the BLOCK. */ | |
1031 | ||
1032 | tree | |
1033 | poplevel (keep, reverse, functionbody) | |
1034 | int keep; | |
1035 | int reverse; | |
1036 | int functionbody; | |
1037 | { | |
1038 | register tree link; | |
1039 | /* The chain of decls was accumulated in reverse order. | |
1040 | Put it into forward order, just for cleanliness. */ | |
1041 | tree decls; | |
1042 | int tmp = functionbody; | |
8d08fdba MS |
1043 | int real_functionbody = current_binding_level->keep == 2 |
1044 | ? ((functionbody = 0), tmp) : functionbody; | |
1045 | tree tags = functionbody >= 0 ? current_binding_level->tags : 0; | |
1046 | tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; | |
1047 | tree block = NULL_TREE; | |
1048 | tree decl; | |
1049 | int block_previously_created; | |
1050 | ||
1051 | GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, | |
1052 | (HOST_WIDE_INT) current_binding_level->level_chain, | |
1053 | current_binding_level->parm_flag, | |
5566b478 | 1054 | current_binding_level->keep); |
8d08fdba MS |
1055 | |
1056 | if (current_binding_level->keep == 1) | |
1057 | keep = 1; | |
1058 | ||
8d08fdba MS |
1059 | /* Get the decls in the order they were written. |
1060 | Usually current_binding_level->names is in reverse order. | |
1061 | But parameter decls were previously put in forward order. */ | |
1062 | ||
1063 | if (reverse) | |
1064 | current_binding_level->names | |
1065 | = decls = nreverse (current_binding_level->names); | |
1066 | else | |
1067 | decls = current_binding_level->names; | |
1068 | ||
1069 | /* Output any nested inline functions within this block | |
1070 | if they weren't already output. */ | |
1071 | ||
1072 | for (decl = decls; decl; decl = TREE_CHAIN (decl)) | |
1073 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1074 | && ! TREE_ASM_WRITTEN (decl) | |
1075 | && DECL_INITIAL (decl) != NULL_TREE | |
6060a796 MS |
1076 | && TREE_ADDRESSABLE (decl) |
1077 | && decl_function_context (decl) == current_function_decl) | |
8d08fdba MS |
1078 | { |
1079 | /* If this decl was copied from a file-scope decl | |
1080 | on account of a block-scope extern decl, | |
1081 | propagate TREE_ADDRESSABLE to the file-scope decl. */ | |
1082 | if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) | |
1083 | TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; | |
1084 | else | |
1085 | { | |
1086 | push_function_context (); | |
1087 | output_inline_function (decl); | |
1088 | pop_function_context (); | |
1089 | } | |
1090 | } | |
1091 | ||
1092 | /* If there were any declarations or structure tags in that level, | |
1093 | or if this level is a function body, | |
1094 | create a BLOCK to record them for the life of this function. */ | |
1095 | ||
1096 | block = NULL_TREE; | |
1097 | block_previously_created = (current_binding_level->this_block != NULL_TREE); | |
1098 | if (block_previously_created) | |
1099 | block = current_binding_level->this_block; | |
1100 | else if (keep == 1 || functionbody) | |
1101 | block = make_node (BLOCK); | |
1102 | if (block != NULL_TREE) | |
1103 | { | |
72b7eeff MS |
1104 | if (block_previously_created) |
1105 | { | |
1106 | if (decls || tags || subblocks) | |
1107 | { | |
be99da77 | 1108 | if (BLOCK_VARS (block) || BLOCK_TYPE_TAGS (block)) |
72b7eeff MS |
1109 | { |
1110 | warning ("internal compiler error: debugging info corrupted"); | |
1111 | } | |
1112 | BLOCK_VARS (block) = decls; | |
1113 | BLOCK_TYPE_TAGS (block) = tags; | |
be99da77 MS |
1114 | |
1115 | /* We can have previous subblocks and new subblocks when | |
1116 | doing fixup_gotos with complex cleanups. We chain the new | |
1117 | subblocks onto the end of any pre-existing subblocks. */ | |
1118 | BLOCK_SUBBLOCKS (block) = chainon (BLOCK_SUBBLOCKS (block), | |
1119 | subblocks); | |
72b7eeff | 1120 | } |
be99da77 MS |
1121 | /* If we created the block earlier on, and we are just |
1122 | diddling it now, then it already should have a proper | |
1123 | BLOCK_END_NOTE value associated with it. */ | |
72b7eeff MS |
1124 | } |
1125 | else | |
1126 | { | |
1127 | BLOCK_VARS (block) = decls; | |
1128 | BLOCK_TYPE_TAGS (block) = tags; | |
1129 | BLOCK_SUBBLOCKS (block) = subblocks; | |
1130 | /* Otherwise, for a new block, install a new BLOCK_END_NOTE value. */ | |
1131 | remember_end_note (block); | |
1132 | } | |
8d08fdba MS |
1133 | } |
1134 | ||
1135 | /* In each subblock, record that this is its superior. */ | |
1136 | ||
1137 | if (keep >= 0) | |
1138 | for (link = subblocks; link; link = TREE_CHAIN (link)) | |
1139 | BLOCK_SUPERCONTEXT (link) = block; | |
1140 | ||
1141 | /* Clear out the meanings of the local variables of this level. */ | |
1142 | ||
8d6e462b PB |
1143 | if (current_binding_level->is_for_scope && flag_new_for_scope == 1) |
1144 | { | |
2ee887f2 | 1145 | struct binding_level *outer = current_binding_level->level_chain; |
8d6e462b PB |
1146 | for (link = decls; link; link = TREE_CHAIN (link)) |
1147 | { | |
1148 | if (TREE_CODE (link) == VAR_DECL) | |
1149 | DECL_DEAD_FOR_LOCAL (link) = 1; | |
e76a2646 MS |
1150 | else |
1151 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
8d6e462b | 1152 | } |
2ee887f2 MS |
1153 | |
1154 | /* Save declarations made in a 'for' statement so we can support pre-ANSI | |
e92cc029 | 1155 | 'for' scoping semantics. */ |
2ee887f2 MS |
1156 | |
1157 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1158 | { | |
1159 | tree id = TREE_PURPOSE (link); | |
1160 | tree decl = IDENTIFIER_LOCAL_VALUE (id); | |
1161 | ||
e76a2646 MS |
1162 | if (decl && DECL_DEAD_FOR_LOCAL (decl)) |
1163 | { | |
1164 | /* In this case keep the dead for-decl visible, | |
e92cc029 | 1165 | but remember what (if anything) it shadowed. */ |
e76a2646 MS |
1166 | DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link); |
1167 | TREE_CHAIN (decl) = outer->dead_vars_from_for; | |
1168 | outer->dead_vars_from_for = decl; | |
1169 | } | |
1170 | else | |
1171 | IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link); | |
2ee887f2 | 1172 | } |
8d6e462b | 1173 | } |
e92cc029 | 1174 | else /* Not special for scope. */ |
8d6e462b PB |
1175 | { |
1176 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1177 | { | |
1178 | if (DECL_NAME (link) != NULL_TREE) | |
8d08fdba | 1179 | { |
8d6e462b PB |
1180 | /* If the ident. was used or addressed via a local extern decl, |
1181 | don't forget that fact. */ | |
1182 | if (DECL_EXTERNAL (link)) | |
1183 | { | |
1184 | if (TREE_USED (link)) | |
1185 | TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; | |
1186 | if (TREE_ADDRESSABLE (link)) | |
1187 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1188 | } | |
1189 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
8d08fdba | 1190 | } |
8d08fdba | 1191 | } |
8d08fdba | 1192 | |
2ee887f2 MS |
1193 | /* Restore all name-meanings of the outer levels |
1194 | that were shadowed by this level. */ | |
8d08fdba | 1195 | |
2ee887f2 MS |
1196 | for (link = current_binding_level->shadowed; |
1197 | link; link = TREE_CHAIN (link)) | |
1198 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1199 | ||
1200 | /* We first restore the regular decls and *then* the dead_vars_from_for | |
1201 | to handle this case: | |
1202 | ||
1203 | int i; // i#1 | |
1204 | { | |
1205 | for (int i; ; ) { ...} // i#2 | |
1206 | int i; // i#3 | |
1207 | } // we are here | |
1208 | ||
1209 | In this case, we want remove the binding for i#3, restoring | |
1210 | that of i#2. Then we want to remove the binding for i#2, | |
e92cc029 | 1211 | and restore that of i#1. */ |
2ee887f2 MS |
1212 | |
1213 | link = current_binding_level->dead_vars_from_for; | |
1214 | for (; link != NULL_TREE; link = TREE_CHAIN (link)) | |
8d6e462b | 1215 | { |
2ee887f2 MS |
1216 | tree id = DECL_NAME (link); |
1217 | if (IDENTIFIER_LOCAL_VALUE (id) == link) | |
1218 | IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link); | |
8d6e462b PB |
1219 | } |
1220 | ||
2ee887f2 MS |
1221 | for (link = current_binding_level->class_shadowed; |
1222 | link; link = TREE_CHAIN (link)) | |
1223 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1224 | for (link = current_binding_level->type_shadowed; | |
1225 | link; link = TREE_CHAIN (link)) | |
1226 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
8d6e462b | 1227 | } |
8d08fdba MS |
1228 | |
1229 | /* If the level being exited is the top level of a function, | |
1230 | check over all the labels. */ | |
1231 | ||
1232 | if (functionbody) | |
1233 | { | |
1234 | /* If this is the top level block of a function, | |
1235 | the vars are the function's parameters. | |
1236 | Don't leave them in the BLOCK because they are | |
1237 | found in the FUNCTION_DECL instead. */ | |
1238 | ||
1239 | BLOCK_VARS (block) = 0; | |
1240 | ||
1241 | /* Clear out the definitions of all label names, | |
1242 | since their scopes end here. */ | |
1243 | ||
1244 | for (link = named_labels; link; link = TREE_CHAIN (link)) | |
1245 | { | |
1246 | register tree label = TREE_VALUE (link); | |
1247 | ||
1248 | if (DECL_INITIAL (label) == NULL_TREE) | |
1249 | { | |
1250 | cp_error_at ("label `%D' used but not defined", label); | |
1251 | /* Avoid crashing later. */ | |
1252 | define_label (input_filename, 1, DECL_NAME (label)); | |
1253 | } | |
1254 | else if (warn_unused && !TREE_USED (label)) | |
1255 | cp_warning_at ("label `%D' defined but not used", label); | |
1256 | SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE); | |
1257 | ||
1258 | /* Put the labels into the "variables" of the | |
1259 | top-level block, so debugger can see them. */ | |
1260 | TREE_CHAIN (label) = BLOCK_VARS (block); | |
1261 | BLOCK_VARS (block) = label; | |
1262 | } | |
1263 | ||
1264 | named_labels = NULL_TREE; | |
1265 | } | |
1266 | ||
1267 | /* Any uses of undefined labels now operate under constraints | |
1268 | of next binding contour. */ | |
1269 | { | |
1270 | struct binding_level *level_chain; | |
1271 | level_chain = current_binding_level->level_chain; | |
1272 | if (level_chain) | |
1273 | { | |
e349ee73 MS |
1274 | struct named_label_list *labels; |
1275 | for (labels = named_label_uses; labels; labels = labels->next) | |
1276 | if (labels->binding_level == current_binding_level) | |
8d08fdba | 1277 | { |
e349ee73 MS |
1278 | labels->binding_level = level_chain; |
1279 | labels->names_in_scope = level_chain->names; | |
8d08fdba MS |
1280 | } |
1281 | } | |
1282 | } | |
1283 | ||
1284 | tmp = current_binding_level->keep; | |
1285 | ||
1286 | pop_binding_level (); | |
1287 | if (functionbody) | |
1288 | DECL_INITIAL (current_function_decl) = block; | |
1289 | else if (block) | |
1290 | { | |
1291 | if (!block_previously_created) | |
1292 | current_binding_level->blocks | |
1293 | = chainon (current_binding_level->blocks, block); | |
1294 | } | |
1295 | /* If we did not make a block for the level just exited, | |
1296 | any blocks made for inner levels | |
1297 | (since they cannot be recorded as subblocks in that level) | |
1298 | must be carried forward so they will later become subblocks | |
1299 | of something else. */ | |
1300 | else if (subblocks) | |
1301 | { | |
1302 | if (keep == 2) | |
1303 | current_binding_level->blocks | |
1304 | = chainon (subblocks, current_binding_level->blocks); | |
1305 | else | |
1306 | current_binding_level->blocks | |
1307 | = chainon (current_binding_level->blocks, subblocks); | |
1308 | } | |
1309 | ||
1310 | /* Take care of compiler's internal binding structures. */ | |
a4443a08 | 1311 | if (tmp == 2) |
8d08fdba | 1312 | { |
8d08fdba MS |
1313 | expand_end_bindings (getdecls (), keep, 1); |
1314 | /* Each and every BLOCK node created here in `poplevel' is important | |
1315 | (e.g. for proper debugging information) so if we created one | |
1316 | earlier, mark it as "used". */ | |
1317 | if (block) | |
1318 | TREE_USED (block) = 1; | |
1319 | block = poplevel (keep, reverse, real_functionbody); | |
1320 | } | |
1321 | ||
1322 | /* Each and every BLOCK node created here in `poplevel' is important | |
1323 | (e.g. for proper debugging information) so if we created one | |
1324 | earlier, mark it as "used". */ | |
1325 | if (block) | |
1326 | TREE_USED (block) = 1; | |
1327 | return block; | |
1328 | } | |
1329 | ||
a9aedbc2 | 1330 | /* Resume a binding level for a namespace. */ |
e92cc029 | 1331 | |
a9aedbc2 MS |
1332 | void |
1333 | resume_level (b) | |
1334 | struct binding_level *b; | |
1335 | { | |
1336 | tree decls, link; | |
1337 | ||
1338 | resume_binding_level (b); | |
1339 | ||
1340 | /* Resume the variable caches. */ | |
1341 | decls = current_binding_level->names; | |
1342 | ||
1343 | /* Restore the meanings of the local variables of this level. */ | |
1344 | ||
1345 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1346 | { | |
cffa8729 MS |
1347 | /* If it doesn't have a name, there is nothing left to do with it. */ |
1348 | if (DECL_NAME (link) == NULL_TREE) | |
1349 | continue; | |
1350 | ||
1351 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link; | |
a9aedbc2 MS |
1352 | |
1353 | /* If this is a TYPE_DECL, push it into the type value slot. */ | |
1354 | if (TREE_CODE (link) == TYPE_DECL) | |
1355 | SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link)); | |
1356 | } | |
1357 | } | |
1358 | ||
8d08fdba MS |
1359 | /* Delete the node BLOCK from the current binding level. |
1360 | This is used for the block inside a stmt expr ({...}) | |
1361 | so that the block can be reinserted where appropriate. */ | |
1362 | ||
1363 | void | |
1364 | delete_block (block) | |
1365 | tree block; | |
1366 | { | |
1367 | tree t; | |
1368 | if (current_binding_level->blocks == block) | |
1369 | current_binding_level->blocks = TREE_CHAIN (block); | |
1370 | for (t = current_binding_level->blocks; t;) | |
1371 | { | |
1372 | if (TREE_CHAIN (t) == block) | |
1373 | TREE_CHAIN (t) = TREE_CHAIN (block); | |
1374 | else | |
1375 | t = TREE_CHAIN (t); | |
1376 | } | |
1377 | TREE_CHAIN (block) = NULL_TREE; | |
1378 | /* Clear TREE_USED which is always set by poplevel. | |
1379 | The flag is set again if insert_block is called. */ | |
1380 | TREE_USED (block) = 0; | |
1381 | } | |
1382 | ||
1383 | /* Insert BLOCK at the end of the list of subblocks of the | |
1384 | current binding level. This is used when a BIND_EXPR is expanded, | |
1385 | to handle the BLOCK node inside the BIND_EXPR. */ | |
1386 | ||
1387 | void | |
1388 | insert_block (block) | |
1389 | tree block; | |
1390 | { | |
1391 | TREE_USED (block) = 1; | |
1392 | current_binding_level->blocks | |
1393 | = chainon (current_binding_level->blocks, block); | |
1394 | } | |
1395 | ||
8d08fdba MS |
1396 | /* Set the BLOCK node for the innermost scope |
1397 | (the one we are currently in). */ | |
1398 | ||
1399 | void | |
1400 | set_block (block) | |
1401 | register tree block; | |
1402 | { | |
1403 | current_binding_level->this_block = block; | |
1404 | } | |
1405 | ||
1406 | /* Do a pushlevel for class declarations. */ | |
e92cc029 | 1407 | |
8d08fdba MS |
1408 | void |
1409 | pushlevel_class () | |
1410 | { | |
1411 | register struct binding_level *newlevel; | |
1412 | ||
1413 | /* Reuse or create a struct for this binding level. */ | |
1414 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
1415 | if (0) | |
1416 | #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
1417 | if (free_binding_level) | |
1418 | #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
1419 | { | |
1420 | newlevel = free_binding_level; | |
1421 | free_binding_level = free_binding_level->level_chain; | |
1422 | } | |
1423 | else | |
1424 | { | |
cffa8729 | 1425 | newlevel = make_binding_level (); |
8d08fdba MS |
1426 | } |
1427 | ||
1428 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
1429 | is_class_level = 1; | |
1430 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
1431 | ||
1432 | push_binding_level (newlevel, 0, 0); | |
1433 | ||
1434 | decl_stack = push_decl_level (decl_stack, &decl_obstack); | |
1435 | class_binding_level = current_binding_level; | |
1436 | class_binding_level->parm_flag = 2; | |
1437 | /* We have just pushed into a new binding level. Now, fake out the rest | |
1438 | of the compiler. Set the `current_binding_level' back to point to | |
1439 | the most closely containing non-class binding level. */ | |
1440 | do | |
1441 | { | |
1442 | current_binding_level = current_binding_level->level_chain; | |
1443 | } | |
1444 | while (current_binding_level->parm_flag == 2); | |
1445 | } | |
1446 | ||
700f8a87 MS |
1447 | /* ...and a poplevel for class declarations. FORCE is used to force |
1448 | clearing out of CLASS_VALUEs after a class definition. */ | |
e92cc029 | 1449 | |
8d08fdba | 1450 | tree |
700f8a87 MS |
1451 | poplevel_class (force) |
1452 | int force; | |
8d08fdba MS |
1453 | { |
1454 | register struct binding_level *level = class_binding_level; | |
1455 | tree block = NULL_TREE; | |
1456 | tree shadowed; | |
1457 | ||
1458 | my_friendly_assert (level != 0, 354); | |
1459 | ||
1460 | decl_stack = pop_stack_level (decl_stack); | |
1461 | for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
1462 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1463 | /* If we're leaving a toplevel class, don't bother to do the setting | |
ddd5a7c1 | 1464 | of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot |
8d08fdba | 1465 | shouldn't even be used when current_class_type isn't set, and second, |
ddd5a7c1 | 1466 | if we don't touch it here, we're able to use the cache effect if the |
8d08fdba | 1467 | next time we're entering a class scope, it is the same class. */ |
700f8a87 | 1468 | if (current_class_depth != 1 || force) |
8d08fdba MS |
1469 | for (shadowed = level->class_shadowed; |
1470 | shadowed; | |
1471 | shadowed = TREE_CHAIN (shadowed)) | |
1472 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1473 | else | |
1474 | /* Remember to save what IDENTIFIER's were bound in this scope so we | |
1475 | can recover from cache misses. */ | |
e76a2646 MS |
1476 | { |
1477 | previous_class_type = current_class_type; | |
1478 | previous_class_values = class_binding_level->class_shadowed; | |
1479 | } | |
8d08fdba MS |
1480 | for (shadowed = level->type_shadowed; |
1481 | shadowed; | |
1482 | shadowed = TREE_CHAIN (shadowed)) | |
1483 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1484 | ||
1485 | GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, | |
1486 | (HOST_WIDE_INT) class_binding_level->level_chain, | |
1487 | class_binding_level->parm_flag, | |
5566b478 | 1488 | class_binding_level->keep); |
8d08fdba MS |
1489 | |
1490 | if (class_binding_level->parm_flag != 2) | |
1491 | class_binding_level = (struct binding_level *)0; | |
1492 | ||
1493 | /* Now, pop out of the the binding level which we created up in the | |
1494 | `pushlevel_class' routine. */ | |
1495 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
1496 | is_class_level = 1; | |
1497 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
1498 | ||
1499 | pop_binding_level (); | |
1500 | ||
1501 | return block; | |
1502 | } | |
1503 | \f | |
1504 | /* For debugging. */ | |
5566b478 MS |
1505 | static int no_print_functions = 0; |
1506 | static int no_print_builtins = 0; | |
8d08fdba MS |
1507 | |
1508 | void | |
1509 | print_binding_level (lvl) | |
1510 | struct binding_level *lvl; | |
1511 | { | |
1512 | tree t; | |
1513 | int i = 0, len; | |
1514 | fprintf (stderr, " blocks="); | |
1515 | fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks); | |
1516 | fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d", | |
f30432d7 | 1517 | list_length (lvl->incomplete), lvl->parm_flag, lvl->keep); |
8d08fdba MS |
1518 | if (lvl->tag_transparent) |
1519 | fprintf (stderr, " tag-transparent"); | |
1520 | if (lvl->more_cleanups_ok) | |
1521 | fprintf (stderr, " more-cleanups-ok"); | |
1522 | if (lvl->have_cleanups) | |
1523 | fprintf (stderr, " have-cleanups"); | |
8d08fdba MS |
1524 | fprintf (stderr, "\n"); |
1525 | if (lvl->names) | |
1526 | { | |
1527 | fprintf (stderr, " names:\t"); | |
1528 | /* We can probably fit 3 names to a line? */ | |
1529 | for (t = lvl->names; t; t = TREE_CHAIN (t)) | |
1530 | { | |
fc378698 | 1531 | if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL)) |
8d08fdba MS |
1532 | continue; |
1533 | if (no_print_builtins | |
fc378698 MS |
1534 | && (TREE_CODE (t) == TYPE_DECL) |
1535 | && (!strcmp (DECL_SOURCE_FILE (t),"<built-in>"))) | |
8d08fdba MS |
1536 | continue; |
1537 | ||
1538 | /* Function decls tend to have longer names. */ | |
1539 | if (TREE_CODE (t) == FUNCTION_DECL) | |
1540 | len = 3; | |
1541 | else | |
1542 | len = 2; | |
1543 | i += len; | |
1544 | if (i > 6) | |
1545 | { | |
1546 | fprintf (stderr, "\n\t"); | |
1547 | i = len; | |
1548 | } | |
1549 | print_node_brief (stderr, "", t, 0); | |
bd6dd845 | 1550 | if (t == error_mark_node) |
8d08fdba MS |
1551 | break; |
1552 | } | |
1553 | if (i) | |
1554 | fprintf (stderr, "\n"); | |
1555 | } | |
1556 | if (lvl->tags) | |
1557 | { | |
1558 | fprintf (stderr, " tags:\t"); | |
1559 | i = 0; | |
1560 | for (t = lvl->tags; t; t = TREE_CHAIN (t)) | |
1561 | { | |
1562 | if (TREE_PURPOSE (t) == NULL_TREE) | |
1563 | len = 3; | |
1564 | else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) | |
1565 | len = 2; | |
1566 | else | |
1567 | len = 4; | |
1568 | i += len; | |
1569 | if (i > 5) | |
1570 | { | |
1571 | fprintf (stderr, "\n\t"); | |
1572 | i = len; | |
1573 | } | |
1574 | if (TREE_PURPOSE (t) == NULL_TREE) | |
1575 | { | |
1576 | print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0); | |
1577 | fprintf (stderr, ">"); | |
1578 | } | |
1579 | else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) | |
1580 | print_node_brief (stderr, "", TREE_VALUE (t), 0); | |
1581 | else | |
1582 | { | |
1583 | print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0); | |
1584 | print_node_brief (stderr, "", TREE_VALUE (t), 0); | |
1585 | fprintf (stderr, ">"); | |
1586 | } | |
1587 | } | |
1588 | if (i) | |
1589 | fprintf (stderr, "\n"); | |
1590 | } | |
1591 | if (lvl->shadowed) | |
1592 | { | |
1593 | fprintf (stderr, " shadowed:"); | |
1594 | for (t = lvl->shadowed; t; t = TREE_CHAIN (t)) | |
1595 | { | |
1596 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
1597 | } | |
1598 | fprintf (stderr, "\n"); | |
1599 | } | |
1600 | if (lvl->class_shadowed) | |
1601 | { | |
1602 | fprintf (stderr, " class-shadowed:"); | |
1603 | for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t)) | |
1604 | { | |
1605 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
1606 | } | |
1607 | fprintf (stderr, "\n"); | |
1608 | } | |
1609 | if (lvl->type_shadowed) | |
1610 | { | |
1611 | fprintf (stderr, " type-shadowed:"); | |
1612 | for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t)) | |
1613 | { | |
8d08fdba | 1614 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); |
8d08fdba MS |
1615 | } |
1616 | fprintf (stderr, "\n"); | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | void | |
1621 | print_other_binding_stack (stack) | |
1622 | struct binding_level *stack; | |
1623 | { | |
1624 | struct binding_level *level; | |
1625 | for (level = stack; level != global_binding_level; level = level->level_chain) | |
1626 | { | |
1627 | fprintf (stderr, "binding level "); | |
1628 | fprintf (stderr, HOST_PTR_PRINTF, level); | |
1629 | fprintf (stderr, "\n"); | |
1630 | print_binding_level (level); | |
1631 | } | |
1632 | } | |
1633 | ||
1634 | void | |
1635 | print_binding_stack () | |
1636 | { | |
1637 | struct binding_level *b; | |
1638 | fprintf (stderr, "current_binding_level="); | |
1639 | fprintf (stderr, HOST_PTR_PRINTF, current_binding_level); | |
1640 | fprintf (stderr, "\nclass_binding_level="); | |
1641 | fprintf (stderr, HOST_PTR_PRINTF, class_binding_level); | |
1642 | fprintf (stderr, "\nglobal_binding_level="); | |
1643 | fprintf (stderr, HOST_PTR_PRINTF, global_binding_level); | |
1644 | fprintf (stderr, "\n"); | |
1645 | if (class_binding_level) | |
1646 | { | |
1647 | for (b = class_binding_level; b; b = b->level_chain) | |
1648 | if (b == current_binding_level) | |
1649 | break; | |
1650 | if (b) | |
1651 | b = class_binding_level; | |
1652 | else | |
1653 | b = current_binding_level; | |
1654 | } | |
1655 | else | |
1656 | b = current_binding_level; | |
1657 | print_other_binding_stack (b); | |
1658 | fprintf (stderr, "global:\n"); | |
1659 | print_binding_level (global_binding_level); | |
1660 | } | |
a9aedbc2 | 1661 | |
30394414 JM |
1662 | /* Return the tree_binding for the name in the given scope |
1663 | If there are no bindings for the name in the scope, make a new | |
1664 | bindings node. This bindings list of this node will be empty, though. */ | |
1665 | ||
1666 | tree | |
1667 | binding_for_name (name, scope) | |
1668 | tree name; | |
1669 | tree scope; | |
1670 | { | |
1671 | tree iter; | |
1672 | for (iter = IDENTIFIER_NAMESPACE_BINDINGS (name); iter; | |
1673 | iter = TREE_CHAIN (iter)) | |
1674 | { | |
1675 | my_friendly_assert (TREE_CODE (iter) == CPLUS_BINDING, 374); | |
1676 | if (BINDING_SCOPE (iter) == scope) | |
1677 | return iter; | |
1678 | } | |
1679 | /* not found, make a new permanent one */ | |
1680 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
1681 | iter = make_node (CPLUS_BINDING); | |
1682 | TREE_CHAIN (iter) = IDENTIFIER_NAMESPACE_BINDINGS (name); | |
1683 | IDENTIFIER_NAMESPACE_BINDINGS (name) = iter; | |
1684 | BINDING_SCOPE (iter) = scope; | |
1685 | BINDING_VALUE (iter) = NULL_TREE; | |
1686 | pop_obstacks (); | |
1687 | return iter; | |
1688 | } | |
1689 | ||
dff6b454 RK |
1690 | extern char * first_global_object_name; |
1691 | ||
1692 | /* Get a unique name for each call to this routine for unnamed namespaces. | |
1693 | Mostly copied from get_file_function_name. */ | |
e92cc029 | 1694 | |
dff6b454 RK |
1695 | static tree |
1696 | get_unique_name () | |
1697 | { | |
1698 | static int temp_name_counter = 0; | |
1699 | char *buf; | |
1700 | register char *p; | |
1701 | ||
1702 | if (first_global_object_name) | |
1703 | p = first_global_object_name; | |
1704 | else if (main_input_filename) | |
1705 | p = main_input_filename; | |
1706 | else | |
1707 | p = input_filename; | |
1708 | ||
1709 | #define UNNAMED_NAMESPACE_FORMAT "__%s_%d" | |
1710 | ||
1711 | buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p)); | |
1712 | ||
1713 | sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++); | |
1714 | ||
1715 | /* Don't need to pull weird characters out of global names. */ | |
1716 | if (p != first_global_object_name) | |
1717 | { | |
30394414 | 1718 | for (p = buf+2; *p; p++) |
dff6b454 | 1719 | if (! ((*p >= '0' && *p <= '9') |
dff6b454 RK |
1720 | #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */ |
1721 | || *p == '$' | |
1722 | #endif | |
e92cc029 | 1723 | #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */ |
dff6b454 RK |
1724 | || *p == '.' |
1725 | #endif | |
1726 | || (*p >= 'A' && *p <= 'Z') | |
1727 | || (*p >= 'a' && *p <= 'z'))) | |
1728 | *p = '_'; | |
1729 | } | |
1730 | ||
1731 | return get_identifier (buf); | |
1732 | } | |
1733 | ||
1734 | /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we | |
1735 | select a name that is unique to this compilation unit. */ | |
e92cc029 | 1736 | |
a9aedbc2 MS |
1737 | void |
1738 | push_namespace (name) | |
1739 | tree name; | |
1740 | { | |
6633d636 | 1741 | #if 1 |
30394414 JM |
1742 | tree d; |
1743 | int need_new = 1; | |
1744 | int implicit_use = 0; | |
1745 | int nodecl = 0; | |
1746 | if (!global_namespace) | |
1747 | { | |
1748 | /* this must be :: */ | |
1749 | my_friendly_assert (name == get_identifier ("::"), 377); | |
1750 | nodecl = 1; | |
1751 | } | |
1752 | else if (!name) | |
1753 | { | |
1754 | name = get_unique_name (); | |
1755 | implicit_use = 1; | |
1756 | } | |
1757 | else | |
1758 | { | |
1759 | /* check whether this is an extended namespace definition */ | |
1760 | d = IDENTIFIER_NAMESPACE_VALUE (name); | |
1761 | if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL) | |
1762 | need_new = 0; | |
1763 | } | |
6633d636 | 1764 | |
30394414 JM |
1765 | if (need_new) |
1766 | { | |
1767 | /* make a new namespace, binding the name to it */ | |
1768 | d = build_lang_decl (NAMESPACE_DECL, name, void_type_node); | |
1769 | if (!nodecl) | |
1770 | d = pushdecl (d); | |
1771 | } | |
1772 | if (implicit_use) | |
1773 | do_using_directive (d); | |
1774 | /* enter the name space */ | |
1775 | current_namespace = d; | |
1776 | ||
6633d636 | 1777 | #else |
a9aedbc2 MS |
1778 | tree old_id = get_namespace_id (); |
1779 | char *buf; | |
72b7eeff | 1780 | tree d; |
a9aedbc2 | 1781 | |
dff6b454 RK |
1782 | if (! name) |
1783 | { | |
abc95ed3 | 1784 | /* Create a truly ugly name! */ |
dff6b454 RK |
1785 | name = get_unique_name (); |
1786 | } | |
1787 | ||
72b7eeff MS |
1788 | d = build_lang_decl (NAMESPACE_DECL, name, void_type_node); |
1789 | ||
a9aedbc2 | 1790 | /* Mark them as external, so redeclaration_error_message doesn't think |
e92cc029 | 1791 | they are duplicates. */ |
72b7eeff | 1792 | |
a9aedbc2 MS |
1793 | DECL_EXTERNAL (d) = 1; |
1794 | d = pushdecl (d); | |
1795 | ||
1796 | if (NAMESPACE_LEVEL (d) == 0) | |
1797 | { | |
1798 | /* This is new for this compilation unit. */ | |
1799 | pushlevel (0); | |
1800 | declare_namespace_level (); | |
72b7eeff | 1801 | NAMESPACE_LEVEL (d) = current_binding_level; |
a9aedbc2 MS |
1802 | } |
1803 | else | |
72b7eeff | 1804 | resume_level (NAMESPACE_LEVEL (d)); |
a9aedbc2 | 1805 | |
e92cc029 | 1806 | /* This code is just is bit old now... */ |
a9aedbc2 MS |
1807 | current_namespace = tree_cons (NULL_TREE, name, current_namespace); |
1808 | buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0) | |
1809 | + IDENTIFIER_LENGTH (name)); | |
1810 | sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "", | |
1811 | IDENTIFIER_POINTER (name)); | |
1812 | TREE_PURPOSE (current_namespace) = get_identifier (buf); | |
6633d636 | 1813 | #endif |
a9aedbc2 MS |
1814 | } |
1815 | ||
1816 | /* Pop from the scope of the current namespace. */ | |
e92cc029 | 1817 | |
a9aedbc2 MS |
1818 | void |
1819 | pop_namespace () | |
1820 | { | |
30394414 JM |
1821 | #if 1 |
1822 | current_namespace = DECL_NAMESPACE (current_namespace); | |
1823 | #else | |
a9aedbc2 MS |
1824 | tree decls, link; |
1825 | current_namespace = TREE_CHAIN (current_namespace); | |
1826 | ||
e92cc029 | 1827 | /* Just in case we get out of sync. */ |
a9aedbc2 MS |
1828 | if (! namespace_bindings_p ()) |
1829 | poplevel (0, 0, 0); | |
1830 | ||
1831 | decls = current_binding_level->names; | |
1832 | ||
1833 | /* Clear out the meanings of the local variables of this level. */ | |
1834 | ||
1835 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1836 | { | |
1837 | if (DECL_NAME (link) != NULL_TREE) | |
1838 | { | |
1839 | /* If the ident. was used or addressed via a local extern decl, | |
1840 | don't forget that fact. */ | |
1841 | if (DECL_EXTERNAL (link)) | |
1842 | { | |
1843 | if (TREE_USED (link)) | |
1844 | TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; | |
1845 | if (TREE_ADDRESSABLE (link)) | |
1846 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1847 | } | |
1848 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
1849 | } | |
1850 | } | |
1851 | ||
1852 | /* Restore all name-meanings of the outer levels | |
1853 | that were shadowed by this level. */ | |
1854 | ||
1855 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1856 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1857 | for (link = current_binding_level->class_shadowed; | |
1858 | link; link = TREE_CHAIN (link)) | |
1859 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1860 | for (link = current_binding_level->type_shadowed; | |
1861 | link; link = TREE_CHAIN (link)) | |
1862 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1863 | ||
1864 | /* suspend a level. */ | |
1865 | suspend_binding_level (); | |
6633d636 | 1866 | #endif |
a9aedbc2 | 1867 | } |
8d08fdba MS |
1868 | \f |
1869 | /* Subroutines for reverting temporarily to top-level for instantiation | |
1870 | of templates and such. We actually need to clear out the class- and | |
1871 | local-value slots of all identifiers, so that only the global values | |
1872 | are at all visible. Simply setting current_binding_level to the global | |
1873 | scope isn't enough, because more binding levels may be pushed. */ | |
1874 | struct saved_scope { | |
1875 | struct binding_level *old_binding_level; | |
1876 | tree old_bindings; | |
1877 | struct saved_scope *prev; | |
5f34005f | 1878 | tree class_name, class_type, function_decl; |
8d08fdba | 1879 | struct binding_level *class_bindings; |
51c184be MS |
1880 | tree *lang_base, *lang_stack, lang_name; |
1881 | int lang_stacksize; | |
5566b478 MS |
1882 | int minimal_parse_mode; |
1883 | tree last_function_parms; | |
e76a2646 | 1884 | tree template_parms; |
5156628f | 1885 | HOST_WIDE_INT processing_template_decl; |
a50f0918 | 1886 | tree previous_class_type, previous_class_values; |
e1467ff2 MM |
1887 | int processing_specialization; |
1888 | int processing_explicit_instantiation; | |
8d08fdba MS |
1889 | }; |
1890 | static struct saved_scope *current_saved_scope; | |
8d08fdba | 1891 | |
78957a2a JM |
1892 | /* A chain of the binding vecs created by store_bindings. We create a |
1893 | whole bunch of these during compilation, on permanent_obstack, so we | |
1894 | can't just throw them away. */ | |
1895 | static tree free_binding_vecs; | |
1896 | ||
e92cc029 | 1897 | static tree |
45537677 MS |
1898 | store_bindings (names, old_bindings) |
1899 | tree names, old_bindings; | |
1900 | { | |
1901 | tree t; | |
1902 | for (t = names; t; t = TREE_CHAIN (t)) | |
1903 | { | |
1904 | tree binding, t1, id; | |
1905 | ||
1906 | if (TREE_CODE (t) == TREE_LIST) | |
1907 | id = TREE_PURPOSE (t); | |
1908 | else | |
1909 | id = DECL_NAME (t); | |
1910 | ||
1911 | if (!id | |
1912 | || (!IDENTIFIER_LOCAL_VALUE (id) | |
1913 | && !IDENTIFIER_CLASS_VALUE (id))) | |
1914 | continue; | |
1915 | ||
1916 | for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) | |
1917 | if (TREE_VEC_ELT (t1, 0) == id) | |
1918 | goto skip_it; | |
78957a2a JM |
1919 | |
1920 | if (free_binding_vecs) | |
1921 | { | |
1922 | binding = free_binding_vecs; | |
1923 | free_binding_vecs = TREE_CHAIN (free_binding_vecs); | |
1924 | } | |
1925 | else | |
1926 | binding = make_tree_vec (4); | |
1927 | ||
45537677 MS |
1928 | if (id) |
1929 | { | |
1930 | my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); | |
1931 | TREE_VEC_ELT (binding, 0) = id; | |
1932 | TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id); | |
1933 | TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id); | |
1934 | TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); | |
1935 | IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE; | |
1936 | IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; | |
1937 | } | |
1938 | TREE_CHAIN (binding) = old_bindings; | |
1939 | old_bindings = binding; | |
1940 | skip_it: | |
1941 | ; | |
1942 | } | |
1943 | return old_bindings; | |
1944 | } | |
1945 | ||
8d08fdba | 1946 | void |
5566b478 MS |
1947 | maybe_push_to_top_level (pseudo) |
1948 | int pseudo; | |
8d08fdba | 1949 | { |
51c184be | 1950 | extern int current_lang_stacksize; |
beb53fb8 JM |
1951 | struct saved_scope *s |
1952 | = (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); | |
5566b478 | 1953 | struct binding_level *b = inner_binding_level; |
8d08fdba MS |
1954 | tree old_bindings = NULL_TREE; |
1955 | ||
e349ee73 MS |
1956 | if (current_function_decl) |
1957 | push_cp_function_context (NULL_TREE); | |
1958 | ||
a50f0918 MS |
1959 | if (previous_class_type) |
1960 | old_bindings = store_bindings (previous_class_values, old_bindings); | |
1961 | ||
8d08fdba MS |
1962 | /* Have to include global_binding_level, because class-level decls |
1963 | aren't listed anywhere useful. */ | |
1964 | for (; b; b = b->level_chain) | |
1965 | { | |
1966 | tree t; | |
1967 | ||
5566b478 MS |
1968 | if (b == global_binding_level || (pseudo && b->pseudo_global)) |
1969 | break; | |
8d08fdba | 1970 | |
45537677 | 1971 | old_bindings = store_bindings (b->names, old_bindings); |
cffa8729 | 1972 | /* We also need to check class_shadowed to save class-level type |
45537677 MS |
1973 | bindings, since pushclass doesn't fill in b->names. */ |
1974 | if (b->parm_flag == 2) | |
cffa8729 | 1975 | old_bindings = store_bindings (b->class_shadowed, old_bindings); |
8d08fdba | 1976 | |
8d08fdba MS |
1977 | /* Unwind type-value slots back to top level. */ |
1978 | for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) | |
1979 | SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); | |
1980 | } | |
8d08fdba MS |
1981 | |
1982 | s->old_binding_level = current_binding_level; | |
5566b478 | 1983 | current_binding_level = b; |
8d08fdba MS |
1984 | |
1985 | s->class_name = current_class_name; | |
1986 | s->class_type = current_class_type; | |
8d08fdba MS |
1987 | s->function_decl = current_function_decl; |
1988 | s->class_bindings = class_binding_level; | |
51c184be MS |
1989 | s->lang_stack = current_lang_stack; |
1990 | s->lang_base = current_lang_base; | |
1991 | s->lang_stacksize = current_lang_stacksize; | |
1992 | s->lang_name = current_lang_name; | |
5566b478 MS |
1993 | s->minimal_parse_mode = minimal_parse_mode; |
1994 | s->last_function_parms = last_function_parms; | |
e76a2646 | 1995 | s->template_parms = current_template_parms; |
5156628f | 1996 | s->processing_template_decl = processing_template_decl; |
a50f0918 MS |
1997 | s->previous_class_type = previous_class_type; |
1998 | s->previous_class_values = previous_class_values; | |
e1467ff2 MM |
1999 | s->processing_specialization = processing_specialization; |
2000 | s->processing_explicit_instantiation = processing_explicit_instantiation; | |
e349ee73 | 2001 | |
5f34005f | 2002 | current_class_name = current_class_type = NULL_TREE; |
8d08fdba MS |
2003 | current_function_decl = NULL_TREE; |
2004 | class_binding_level = (struct binding_level *)0; | |
51c184be MS |
2005 | current_lang_stacksize = 10; |
2006 | current_lang_stack = current_lang_base | |
2007 | = (tree *) xmalloc (current_lang_stacksize * sizeof (tree)); | |
2008 | current_lang_name = lang_name_cplusplus; | |
2009 | strict_prototype = strict_prototypes_lang_cplusplus; | |
2010 | named_labels = NULL_TREE; | |
5566b478 | 2011 | minimal_parse_mode = 0; |
a50f0918 | 2012 | previous_class_type = previous_class_values = NULL_TREE; |
e1467ff2 MM |
2013 | processing_specialization = 0; |
2014 | processing_explicit_instantiation = 0; | |
e76a2646 | 2015 | if (!pseudo) |
5156628f MS |
2016 | { |
2017 | current_template_parms = NULL_TREE; | |
2018 | processing_template_decl = 0; | |
2019 | } | |
8d08fdba MS |
2020 | |
2021 | s->prev = current_saved_scope; | |
2022 | s->old_bindings = old_bindings; | |
2023 | current_saved_scope = s; | |
5566b478 MS |
2024 | |
2025 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
2026 | } | |
2027 | ||
2028 | void | |
2029 | push_to_top_level () | |
2030 | { | |
2031 | maybe_push_to_top_level (0); | |
8d08fdba MS |
2032 | } |
2033 | ||
2034 | void | |
2035 | pop_from_top_level () | |
2036 | { | |
51c184be | 2037 | extern int current_lang_stacksize; |
8d08fdba MS |
2038 | struct saved_scope *s = current_saved_scope; |
2039 | tree t; | |
2040 | ||
e76a2646 | 2041 | /* Clear out class-level bindings cache. */ |
8d08fdba | 2042 | if (previous_class_type) |
e76a2646 MS |
2043 | { |
2044 | popclass (-1); | |
2045 | previous_class_type = NULL_TREE; | |
2046 | } | |
8d08fdba | 2047 | |
5566b478 MS |
2048 | pop_obstacks (); |
2049 | ||
8d08fdba MS |
2050 | current_binding_level = s->old_binding_level; |
2051 | current_saved_scope = s->prev; | |
78957a2a | 2052 | for (t = s->old_bindings; t; ) |
8d08fdba | 2053 | { |
78957a2a | 2054 | tree save = t; |
8d08fdba MS |
2055 | tree id = TREE_VEC_ELT (t, 0); |
2056 | if (id) | |
2057 | { | |
2058 | IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1); | |
2059 | IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2); | |
2060 | IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); | |
2061 | } | |
78957a2a JM |
2062 | t = TREE_CHAIN (t); |
2063 | TREE_CHAIN (save) = free_binding_vecs; | |
2064 | free_binding_vecs = save; | |
8d08fdba MS |
2065 | } |
2066 | current_class_name = s->class_name; | |
2067 | current_class_type = s->class_type; | |
8d08fdba MS |
2068 | current_function_decl = s->function_decl; |
2069 | class_binding_level = s->class_bindings; | |
51c184be MS |
2070 | free (current_lang_base); |
2071 | current_lang_base = s->lang_base; | |
2072 | current_lang_stack = s->lang_stack; | |
2073 | current_lang_name = s->lang_name; | |
2074 | current_lang_stacksize = s->lang_stacksize; | |
2075 | if (current_lang_name == lang_name_cplusplus) | |
2076 | strict_prototype = strict_prototypes_lang_cplusplus; | |
2077 | else if (current_lang_name == lang_name_c) | |
2078 | strict_prototype = strict_prototypes_lang_c; | |
5566b478 MS |
2079 | minimal_parse_mode = s->minimal_parse_mode; |
2080 | last_function_parms = s->last_function_parms; | |
e76a2646 | 2081 | current_template_parms = s->template_parms; |
5156628f | 2082 | processing_template_decl = s->processing_template_decl; |
a50f0918 MS |
2083 | previous_class_type = s->previous_class_type; |
2084 | previous_class_values = s->previous_class_values; | |
e1467ff2 MM |
2085 | processing_specialization = s->processing_specialization; |
2086 | processing_explicit_instantiation = s->processing_explicit_instantiation; | |
51c184be | 2087 | |
8d08fdba | 2088 | free (s); |
e349ee73 MS |
2089 | |
2090 | if (current_function_decl) | |
2091 | pop_cp_function_context (NULL_TREE); | |
8d08fdba MS |
2092 | } |
2093 | \f | |
2094 | /* Push a definition of struct, union or enum tag "name". | |
2095 | into binding_level "b". "type" should be the type node, | |
2096 | We assume that the tag "name" is not already defined. | |
2097 | ||
2098 | Note that the definition may really be just a forward reference. | |
2099 | In that case, the TYPE_SIZE will be a NULL_TREE. | |
2100 | ||
e92cc029 | 2101 | C++ gratuitously puts all these tags in the name space. */ |
8d08fdba MS |
2102 | |
2103 | /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID, | |
2104 | record the shadowed value for this binding contour. TYPE is | |
2105 | the type that ID maps to. */ | |
2106 | ||
2107 | static void | |
2108 | set_identifier_type_value_with_scope (id, type, b) | |
2109 | tree id; | |
2110 | tree type; | |
2111 | struct binding_level *b; | |
2112 | { | |
2113 | if (b != global_binding_level) | |
2114 | { | |
2115 | tree old_type_value = IDENTIFIER_TYPE_VALUE (id); | |
2116 | b->type_shadowed | |
2117 | = tree_cons (id, old_type_value, b->type_shadowed); | |
2118 | } | |
2119 | SET_IDENTIFIER_TYPE_VALUE (id, type); | |
2120 | } | |
2121 | ||
e92cc029 | 2122 | /* As set_identifier_type_value_with_scope, but using inner_binding_level. */ |
8d08fdba MS |
2123 | |
2124 | void | |
2125 | set_identifier_type_value (id, type) | |
2126 | tree id; | |
2127 | tree type; | |
2128 | { | |
2129 | set_identifier_type_value_with_scope (id, type, inner_binding_level); | |
2130 | } | |
2131 | ||
a9aedbc2 MS |
2132 | /* Pop off extraneous binding levels left over due to syntax errors. |
2133 | ||
2134 | We don't pop past namespaces, as they might be valid. */ | |
e92cc029 | 2135 | |
8926095f MS |
2136 | void |
2137 | pop_everything () | |
2138 | { | |
2139 | #ifdef DEBUG_CP_BINDING_LEVELS | |
2140 | fprintf (stderr, "XXX entering pop_everything ()\n"); | |
2141 | #endif | |
a9aedbc2 | 2142 | while (! toplevel_bindings_p () && ! pseudo_global_level_p ()) |
8926095f MS |
2143 | { |
2144 | if (class_binding_level) | |
2145 | pop_nested_class (1); | |
2146 | else | |
2147 | poplevel (0, 0, 0); | |
2148 | } | |
2149 | #ifdef DEBUG_CP_BINDING_LEVELS | |
2150 | fprintf (stderr, "XXX leaving pop_everything ()\n"); | |
2151 | #endif | |
2152 | } | |
2153 | ||
8d08fdba | 2154 | /* Push a tag name NAME for struct/class/union/enum type TYPE. |
ddd5a7c1 | 2155 | Normally put into into the inner-most non-tag-transparent scope, |
8d08fdba | 2156 | but if GLOBALIZE is true, put it in the inner-most non-class scope. |
e92cc029 | 2157 | The latter is needed for implicit declarations. */ |
8d08fdba MS |
2158 | |
2159 | void | |
2160 | pushtag (name, type, globalize) | |
2161 | tree name, type; | |
2162 | int globalize; | |
2163 | { | |
2164 | register struct binding_level *b; | |
7177d104 | 2165 | tree context = 0; |
2986ae00 | 2166 | tree c_decl = 0; |
8d08fdba MS |
2167 | |
2168 | b = inner_binding_level; | |
2169 | while (b->tag_transparent | |
2170 | || (globalize && b->parm_flag == 2)) | |
2171 | b = b->level_chain; | |
2172 | ||
a9aedbc2 | 2173 | if (toplevel_bindings_p ()) |
8d08fdba MS |
2174 | b->tags = perm_tree_cons (name, type, b->tags); |
2175 | else | |
2176 | b->tags = saveable_tree_cons (name, type, b->tags); | |
2177 | ||
2178 | if (name) | |
2179 | { | |
7177d104 | 2180 | context = type ? TYPE_CONTEXT (type) : NULL_TREE; |
297dcfb3 MM |
2181 | if (! context) |
2182 | { | |
2183 | tree cs = current_scope (); | |
2184 | ||
2185 | if (! globalize) | |
2186 | context = cs; | |
2187 | else if (cs != NULL_TREE | |
2188 | && TREE_CODE_CLASS (TREE_CODE (cs)) == 't') | |
2189 | /* When declaring a friend class of a local class, we want | |
2190 | to inject the newly named class into the scope | |
2191 | containing the local class, not the namespace scope. */ | |
2192 | context = hack_decl_function_context (get_type_decl (cs)); | |
2193 | } | |
7177d104 | 2194 | if (context) |
2986ae00 | 2195 | c_decl = TREE_CODE (context) == FUNCTION_DECL |
e1cd6e56 | 2196 | ? context : TYPE_MAIN_DECL (context); |
8d08fdba | 2197 | |
8d08fdba | 2198 | /* Do C++ gratuitous typedefing. */ |
db5ae43f | 2199 | if (IDENTIFIER_TYPE_VALUE (name) != type) |
8d08fdba | 2200 | { |
93cdc044 JM |
2201 | register tree d = NULL_TREE; |
2202 | int newdecl = 0, in_class = 0; | |
8d08fdba | 2203 | |
93cdc044 JM |
2204 | if ((b->pseudo_global && b->level_chain->parm_flag == 2) |
2205 | || b->parm_flag == 2) | |
2206 | in_class = 1; | |
8d08fdba | 2207 | else |
93cdc044 JM |
2208 | d = lookup_nested_type (type, c_decl); |
2209 | ||
2210 | if (d == NULL_TREE) | |
8d08fdba | 2211 | { |
8d08fdba | 2212 | newdecl = 1; |
a0a33927 | 2213 | d = build_decl (TYPE_DECL, name, type); |
00595019 | 2214 | SET_DECL_ARTIFICIAL (d); |
93cdc044 JM |
2215 | if (! in_class) |
2216 | set_identifier_type_value_with_scope (name, type, b); | |
2217 | } | |
2218 | else | |
2219 | d = TYPE_MAIN_DECL (d); | |
2220 | ||
2221 | TYPE_NAME (type) = d; | |
2222 | DECL_CONTEXT (d) = context; | |
e1cd6e56 | 2223 | |
93cdc044 JM |
2224 | if (! globalize && processing_template_decl |
2225 | && IS_AGGR_TYPE (type)) | |
2226 | { | |
2227 | d = push_template_decl (d); | |
2228 | if (b->pseudo_global && b->level_chain->parm_flag == 2) | |
2229 | pushdecl_with_scope (CLASSTYPE_TI_TEMPLATE (type), | |
2230 | b->level_chain); | |
8d08fdba | 2231 | } |
93cdc044 JM |
2232 | |
2233 | if (b->parm_flag == 2) | |
2234 | d = pushdecl_class_level (d); | |
2235 | else | |
2236 | d = pushdecl_with_scope (d, b); | |
2237 | ||
8ccc31eb | 2238 | if (newdecl) |
8d08fdba | 2239 | { |
d2e5ee5c MS |
2240 | if (ANON_AGGRNAME_P (name)) |
2241 | DECL_IGNORED_P (d) = 1; | |
8ccc31eb | 2242 | |
5566b478 | 2243 | TYPE_CONTEXT (type) = DECL_CONTEXT (d); |
1f06b267 | 2244 | DECL_ASSEMBLER_NAME (d) = DECL_NAME (d); |
8ccc31eb MS |
2245 | DECL_ASSEMBLER_NAME (d) |
2246 | = get_identifier (build_overload_name (type, 1, 1)); | |
8d08fdba | 2247 | } |
8d08fdba MS |
2248 | } |
2249 | if (b->parm_flag == 2) | |
2250 | { | |
2251 | TREE_NONLOCAL_FLAG (type) = 1; | |
2252 | if (TYPE_SIZE (current_class_type) == NULL_TREE) | |
2253 | CLASSTYPE_TAGS (current_class_type) = b->tags; | |
2254 | } | |
2255 | } | |
2256 | ||
2257 | if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) | |
2258 | /* Use the canonical TYPE_DECL for this node. */ | |
2259 | TYPE_STUB_DECL (type) = TYPE_NAME (type); | |
2260 | else | |
2261 | { | |
2262 | /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE | |
2263 | will be the tagged type we just added to the current | |
2264 | binding level. This fake NULL-named TYPE_DECL node helps | |
2265 | dwarfout.c to know when it needs to output a | |
2266 | representation of a tagged type, and it also gives us a | |
2267 | convenient place to record the "scope start" address for | |
2268 | the tagged type. */ | |
2269 | ||
8d08fdba | 2270 | tree d = build_decl (TYPE_DECL, NULL_TREE, type); |
8d08fdba MS |
2271 | TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b); |
2272 | } | |
2273 | } | |
2274 | ||
2275 | /* Counter used to create anonymous type names. */ | |
e92cc029 | 2276 | |
8d08fdba MS |
2277 | static int anon_cnt = 0; |
2278 | ||
2279 | /* Return an IDENTIFIER which can be used as a name for | |
2280 | anonymous structs and unions. */ | |
e92cc029 | 2281 | |
8d08fdba MS |
2282 | tree |
2283 | make_anon_name () | |
2284 | { | |
2285 | char buf[32]; | |
2286 | ||
2287 | sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++); | |
2288 | return get_identifier (buf); | |
2289 | } | |
2290 | ||
2291 | /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames. | |
2292 | This keeps dbxout from getting confused. */ | |
e92cc029 | 2293 | |
8d08fdba MS |
2294 | void |
2295 | clear_anon_tags () | |
2296 | { | |
2297 | register struct binding_level *b; | |
2298 | register tree tags; | |
2299 | static int last_cnt = 0; | |
2300 | ||
2301 | /* Fast out if no new anon names were declared. */ | |
2302 | if (last_cnt == anon_cnt) | |
2303 | return; | |
2304 | ||
2305 | b = current_binding_level; | |
2306 | while (b->tag_transparent) | |
2307 | b = b->level_chain; | |
2308 | tags = b->tags; | |
2309 | while (tags) | |
2310 | { | |
2311 | /* A NULL purpose means we have already processed all tags | |
2312 | from here to the end of the list. */ | |
2313 | if (TREE_PURPOSE (tags) == NULL_TREE) | |
2314 | break; | |
2315 | if (ANON_AGGRNAME_P (TREE_PURPOSE (tags))) | |
2316 | TREE_PURPOSE (tags) = NULL_TREE; | |
2317 | tags = TREE_CHAIN (tags); | |
2318 | } | |
2319 | last_cnt = anon_cnt; | |
2320 | } | |
2321 | \f | |
2322 | /* Subroutine of duplicate_decls: return truthvalue of whether | |
2323 | or not types of these decls match. | |
2324 | ||
2325 | For C++, we must compare the parameter list so that `int' can match | |
2326 | `int&' in a parameter position, but `int&' is not confused with | |
2327 | `const int&'. */ | |
e92cc029 | 2328 | |
6060a796 | 2329 | int |
8d08fdba MS |
2330 | decls_match (newdecl, olddecl) |
2331 | tree newdecl, olddecl; | |
2332 | { | |
2333 | int types_match; | |
2334 | ||
a28e3c7f MS |
2335 | if (TREE_CODE (newdecl) == FUNCTION_DECL |
2336 | && TREE_CODE (olddecl) == FUNCTION_DECL) | |
8d08fdba MS |
2337 | { |
2338 | tree f1 = TREE_TYPE (newdecl); | |
2339 | tree f2 = TREE_TYPE (olddecl); | |
2340 | tree p1 = TYPE_ARG_TYPES (f1); | |
2341 | tree p2 = TYPE_ARG_TYPES (f2); | |
2342 | ||
2343 | /* When we parse a static member function definition, | |
2344 | we put together a FUNCTION_DECL which thinks its type | |
2345 | is METHOD_TYPE. Change that to FUNCTION_TYPE, and | |
2346 | proceed. */ | |
2347 | if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl)) | |
700f8a87 | 2348 | revert_static_member_fn (&newdecl, &f1, &p1); |
8d08fdba MS |
2349 | else if (TREE_CODE (f2) == METHOD_TYPE |
2350 | && DECL_STATIC_FUNCTION_P (newdecl)) | |
700f8a87 | 2351 | revert_static_member_fn (&olddecl, &f2, &p2); |
8d08fdba MS |
2352 | |
2353 | /* Here we must take care of the case where new default | |
2354 | parameters are specified. Also, warn if an old | |
2355 | declaration becomes ambiguous because default | |
2356 | parameters may cause the two to be ambiguous. */ | |
2357 | if (TREE_CODE (f1) != TREE_CODE (f2)) | |
2358 | { | |
2359 | if (TREE_CODE (f1) == OFFSET_TYPE) | |
2360 | cp_compiler_error ("`%D' redeclared as member function", newdecl); | |
2361 | else | |
2362 | cp_compiler_error ("`%D' redeclared as non-member function", newdecl); | |
2363 | return 0; | |
2364 | } | |
2365 | ||
39211cd5 | 2366 | if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1)) |
8926095f | 2367 | { |
a28e3c7f | 2368 | if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c |
8926095f | 2369 | && p2 == NULL_TREE) |
a28e3c7f MS |
2370 | { |
2371 | types_match = self_promoting_args_p (p1); | |
2372 | if (p1 == void_list_node) | |
2373 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl); | |
2374 | } | |
2375 | else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c | |
2376 | && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE) | |
2377 | { | |
2378 | types_match = self_promoting_args_p (p2); | |
2379 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl); | |
2380 | } | |
8926095f | 2381 | else |
a4443a08 | 2382 | types_match = compparms (p1, p2, 3); |
8926095f | 2383 | } |
8d08fdba MS |
2384 | else |
2385 | types_match = 0; | |
2386 | } | |
51c184be MS |
2387 | else if (TREE_CODE (newdecl) == TEMPLATE_DECL |
2388 | && TREE_CODE (olddecl) == TEMPLATE_DECL) | |
2389 | { | |
f84b4be9 JM |
2390 | if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), |
2391 | DECL_TEMPLATE_PARMS (olddecl))) | |
2392 | return 0; | |
2393 | ||
2394 | if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) | |
2395 | types_match = 1; | |
2396 | else | |
2397 | types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl), | |
2398 | DECL_TEMPLATE_RESULT (newdecl)); | |
51c184be | 2399 | } |
8d08fdba MS |
2400 | else |
2401 | { | |
2402 | if (TREE_TYPE (newdecl) == error_mark_node) | |
2403 | types_match = TREE_TYPE (olddecl) == error_mark_node; | |
2404 | else if (TREE_TYPE (olddecl) == NULL_TREE) | |
2405 | types_match = TREE_TYPE (newdecl) == NULL_TREE; | |
a0a33927 MS |
2406 | else if (TREE_TYPE (newdecl) == NULL_TREE) |
2407 | types_match = 0; | |
72b7eeff MS |
2408 | /* Qualifiers must match, and they may be present on either, the type |
2409 | or the decl. */ | |
2410 | else if ((TREE_READONLY (newdecl) | |
2411 | || TYPE_READONLY (TREE_TYPE (newdecl))) | |
2412 | == (TREE_READONLY (olddecl) | |
2413 | || TYPE_READONLY (TREE_TYPE (olddecl))) | |
2414 | && (TREE_THIS_VOLATILE (newdecl) | |
2415 | || TYPE_VOLATILE (TREE_TYPE (newdecl))) | |
2416 | == (TREE_THIS_VOLATILE (olddecl) | |
2417 | || TYPE_VOLATILE (TREE_TYPE (olddecl)))) | |
2418 | types_match = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (newdecl)), | |
2419 | TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)), 1); | |
8d08fdba | 2420 | else |
72b7eeff | 2421 | types_match = 0; |
8d08fdba MS |
2422 | } |
2423 | ||
2424 | return types_match; | |
2425 | } | |
2426 | ||
2427 | /* If NEWDECL is `static' and an `extern' was seen previously, | |
2428 | warn about it. (OLDDECL may be NULL_TREE; NAME contains | |
2429 | information about previous usage as an `extern'.) | |
2430 | ||
2431 | Note that this does not apply to the C++ case of declaring | |
2432 | a variable `extern const' and then later `const'. | |
2433 | ||
8d08fdba MS |
2434 | Don't complain about built-in functions, since they are beyond |
2435 | the user's control. */ | |
2436 | ||
2437 | static void | |
2438 | warn_extern_redeclared_static (newdecl, olddecl) | |
2439 | tree newdecl, olddecl; | |
2440 | { | |
2441 | tree name; | |
2442 | ||
2443 | static char *explicit_extern_static_warning | |
2444 | = "`%D' was declared `extern' and later `static'"; | |
2445 | static char *implicit_extern_static_warning | |
2446 | = "`%D' was declared implicitly `extern' and later `static'"; | |
2447 | ||
d22c8596 | 2448 | if (TREE_CODE (newdecl) == TYPE_DECL) |
8d08fdba MS |
2449 | return; |
2450 | ||
2451 | name = DECL_ASSEMBLER_NAME (newdecl); | |
faae18ab | 2452 | if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl)) |
8d08fdba MS |
2453 | { |
2454 | /* It's okay to redeclare an ANSI built-in function as static, | |
2455 | or to declare a non-ANSI built-in function as anything. */ | |
2456 | if (! (TREE_CODE (newdecl) == FUNCTION_DECL | |
2457 | && olddecl != NULL_TREE | |
2458 | && TREE_CODE (olddecl) == FUNCTION_DECL | |
2459 | && (DECL_BUILT_IN (olddecl) | |
2460 | || DECL_BUILT_IN_NONANSI (olddecl)))) | |
2461 | { | |
a9aedbc2 | 2462 | cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name) |
8d08fdba MS |
2463 | ? implicit_extern_static_warning |
2464 | : explicit_extern_static_warning, newdecl); | |
2465 | if (olddecl != NULL_TREE) | |
a9aedbc2 | 2466 | cp_pedwarn_at ("previous declaration of `%D'", olddecl); |
8d08fdba MS |
2467 | } |
2468 | } | |
2469 | } | |
2470 | ||
2471 | /* Handle when a new declaration NEWDECL has the same name as an old | |
2472 | one OLDDECL in the same binding contour. Prints an error message | |
2473 | if appropriate. | |
2474 | ||
2475 | If safely possible, alter OLDDECL to look like NEWDECL, and return 1. | |
2476 | Otherwise, return 0. */ | |
2477 | ||
51c184be | 2478 | int |
8d08fdba | 2479 | duplicate_decls (newdecl, olddecl) |
824b9a4c | 2480 | tree newdecl, olddecl; |
8d08fdba MS |
2481 | { |
2482 | extern struct obstack permanent_obstack; | |
2483 | unsigned olddecl_uid = DECL_UID (olddecl); | |
2484 | int olddecl_friend = 0, types_match = 0; | |
2485 | int new_defines_function; | |
5566b478 MS |
2486 | |
2487 | if (newdecl == olddecl) | |
2488 | return 1; | |
8d08fdba | 2489 | |
f6abb50a | 2490 | if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd') |
d9525bec BK |
2491 | DECL_MACHINE_ATTRIBUTES (newdecl) |
2492 | = merge_machine_decl_attributes (olddecl, newdecl); | |
f6abb50a | 2493 | |
8926095f | 2494 | types_match = decls_match (newdecl, olddecl); |
8d08fdba MS |
2495 | |
2496 | if (TREE_CODE (olddecl) != TREE_LIST) | |
2497 | olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl); | |
2498 | ||
2499 | /* If either the type of the new decl or the type of the old decl is an | |
2500 | error_mark_node, then that implies that we have already issued an | |
2501 | error (earlier) for some bogus type specification, and in that case, | |
2502 | it is rather pointless to harass the user with yet more error message | |
2503 | about the same declaration, so well just pretent the types match here. */ | |
bd6dd845 MS |
2504 | if (TREE_TYPE (newdecl) == error_mark_node |
2505 | || TREE_TYPE (olddecl) == error_mark_node) | |
8d08fdba MS |
2506 | types_match = 1; |
2507 | ||
d22c8596 MS |
2508 | if (TREE_CODE (olddecl) == FUNCTION_DECL |
2509 | && DECL_ARTIFICIAL (olddecl) | |
2510 | && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl))) | |
8d08fdba MS |
2511 | { |
2512 | /* If you declare a built-in or predefined function name as static, | |
a4443a08 MS |
2513 | the old definition is overridden, but optionally warn this was a |
2514 | bad choice of name. Ditto for overloads. */ | |
893de33c | 2515 | if (! TREE_PUBLIC (newdecl) |
a4443a08 MS |
2516 | || (TREE_CODE (newdecl) == FUNCTION_DECL |
2517 | && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))) | |
2518 | { | |
2519 | if (warn_shadow) | |
2520 | cp_warning ("shadowing %s function `%#D'", | |
2521 | DECL_BUILT_IN (olddecl) ? "built-in" : "library", | |
2522 | olddecl); | |
2523 | /* Discard the old built-in function. */ | |
2524 | return 0; | |
2525 | } | |
2526 | else if (! types_match) | |
8d08fdba | 2527 | { |
a4443a08 MS |
2528 | if (TREE_CODE (newdecl) != FUNCTION_DECL) |
2529 | { | |
2530 | /* If the built-in is not ansi, then programs can override | |
2531 | it even globally without an error. */ | |
2532 | if (! DECL_BUILT_IN (olddecl)) | |
2533 | cp_warning ("library function `%#D' redeclared as non-function `%#D'", | |
2534 | olddecl, newdecl); | |
2535 | else | |
2536 | { | |
2537 | cp_error ("declaration of `%#D'", newdecl); | |
2538 | cp_error ("conflicts with built-in declaration `%#D'", | |
2539 | olddecl); | |
2540 | } | |
2541 | return 0; | |
2542 | } | |
2543 | ||
8d08fdba MS |
2544 | cp_warning ("declaration of `%#D'", newdecl); |
2545 | cp_warning ("conflicts with built-in declaration `%#D'", | |
2546 | olddecl); | |
8d08fdba | 2547 | } |
39211cd5 MS |
2548 | } |
2549 | else if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) | |
2550 | { | |
2551 | if ((TREE_CODE (newdecl) == FUNCTION_DECL | |
5566b478 | 2552 | && DECL_FUNCTION_TEMPLATE_P (olddecl)) |
39211cd5 | 2553 | || (TREE_CODE (olddecl) == FUNCTION_DECL |
5566b478 | 2554 | && DECL_FUNCTION_TEMPLATE_P (newdecl))) |
39211cd5 MS |
2555 | return 0; |
2556 | ||
2557 | cp_error ("`%#D' redeclared as different kind of symbol", newdecl); | |
2558 | if (TREE_CODE (olddecl) == TREE_LIST) | |
2559 | olddecl = TREE_VALUE (olddecl); | |
2560 | cp_error_at ("previous declaration of `%#D'", olddecl); | |
2561 | ||
2562 | /* New decl is completely inconsistent with the old one => | |
2563 | tell caller to replace the old one. */ | |
2564 | ||
2565 | return 0; | |
8d08fdba | 2566 | } |
8d08fdba MS |
2567 | else if (!types_match) |
2568 | { | |
8926095f | 2569 | if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
f0e01782 MS |
2570 | { |
2571 | /* The name of a class template may not be declared to refer to | |
2572 | any other template, class, function, object, namespace, value, | |
e92cc029 | 2573 | or type in the same scope. */ |
5566b478 MS |
2574 | if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL |
2575 | || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) | |
f0e01782 MS |
2576 | { |
2577 | cp_error ("declaration of template `%#D'", newdecl); | |
2578 | cp_error_at ("conflicts with previous declaration `%#D'", | |
2579 | olddecl); | |
2580 | } | |
ec255269 MS |
2581 | else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL |
2582 | && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL | |
2583 | && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))), | |
75650646 MM |
2584 | TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))), 3) |
2585 | && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), | |
2586 | DECL_TEMPLATE_PARMS (olddecl))) | |
ec255269 MS |
2587 | { |
2588 | cp_error ("new declaration `%#D'", newdecl); | |
2589 | cp_error_at ("ambiguates old declaration `%#D'", olddecl); | |
2590 | } | |
f0e01782 MS |
2591 | return 0; |
2592 | } | |
8926095f MS |
2593 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
2594 | { | |
2595 | if (DECL_LANGUAGE (newdecl) == lang_c | |
2596 | && DECL_LANGUAGE (olddecl) == lang_c) | |
2597 | { | |
2598 | cp_error ("declaration of C function `%#D' conflicts with", | |
2599 | newdecl); | |
2600 | cp_error_at ("previous declaration `%#D' here", olddecl); | |
2601 | } | |
00595019 | 2602 | else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)), |
28cbf42c | 2603 | TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3)) |
700f8a87 MS |
2604 | { |
2605 | cp_error ("new declaration `%#D'", newdecl); | |
2606 | cp_error_at ("ambiguates old declaration `%#D'", olddecl); | |
2607 | } | |
2608 | else | |
2609 | return 0; | |
8926095f | 2610 | } |
8d08fdba MS |
2611 | |
2612 | /* Already complained about this, so don't do so again. */ | |
a4443a08 | 2613 | else if (current_class_type == NULL_TREE |
8d08fdba MS |
2614 | || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) |
2615 | { | |
f376e137 | 2616 | cp_error ("conflicting types for `%#D'", newdecl); |
8926095f | 2617 | cp_error_at ("previous declaration as `%#D'", olddecl); |
8d08fdba MS |
2618 | } |
2619 | } | |
75650646 MM |
2620 | else if (TREE_CODE (newdecl) == FUNCTION_DECL |
2621 | && ((DECL_TEMPLATE_SPECIALIZATION (olddecl) | |
2622 | && (!DECL_TEMPLATE_INFO (newdecl) | |
2623 | || (DECL_TI_TEMPLATE (newdecl) | |
2624 | != DECL_TI_TEMPLATE (olddecl)))) | |
2625 | || (DECL_TEMPLATE_SPECIALIZATION (newdecl) | |
2626 | && (!DECL_TEMPLATE_INFO (olddecl) | |
2627 | || (DECL_TI_TEMPLATE (olddecl) | |
2628 | != DECL_TI_TEMPLATE (newdecl)))))) | |
386b8a85 JM |
2629 | /* It's OK to have a template specialization and a non-template |
2630 | with the same type, or to have specializations of two | |
75650646 MM |
2631 | different templates with the same type. Note that if one is a |
2632 | specialization, and the other is an instantiation of the same | |
2633 | template, that we do not exit at this point. That situation | |
2634 | can occur if we instantiate a template class, and then | |
2635 | specialize one of its methods. This situation is legal, but | |
2636 | the declarations must be merged in the usual way. */ | |
2637 | return 0; | |
2638 | else if (TREE_CODE (newdecl) == FUNCTION_DECL | |
2639 | && ((DECL_TEMPLATE_INSTANTIATION (olddecl) | |
2640 | && !DECL_USE_TEMPLATE (newdecl)) | |
2641 | || (DECL_TEMPLATE_INSTANTIATION (newdecl) | |
2642 | && !DECL_USE_TEMPLATE (olddecl)))) | |
2643 | /* One of the declarations is a template instantiation, and the | |
2644 | other is not a template at all. That's OK. */ | |
386b8a85 | 2645 | return 0; |
8d08fdba MS |
2646 | else |
2647 | { | |
2648 | char *errmsg = redeclaration_error_message (newdecl, olddecl); | |
2649 | if (errmsg) | |
2650 | { | |
51c184be | 2651 | cp_error (errmsg, newdecl); |
8d08fdba MS |
2652 | if (DECL_NAME (olddecl) != NULL_TREE) |
2653 | cp_error_at ((DECL_INITIAL (olddecl) | |
2654 | && current_binding_level == global_binding_level) | |
2655 | ? "`%#D' previously defined here" | |
2656 | : "`%#D' previously declared here", olddecl); | |
2657 | } | |
2658 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
2659 | && DECL_INITIAL (olddecl) != NULL_TREE | |
2660 | && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE | |
2661 | && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE) | |
2662 | { | |
2663 | /* Prototype decl follows defn w/o prototype. */ | |
2664 | cp_warning_at ("prototype for `%#D'", newdecl); | |
2665 | cp_warning_at ("follows non-prototype definition here", olddecl); | |
2666 | } | |
2667 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
2668 | && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)) | |
8926095f MS |
2669 | { |
2670 | /* extern "C" int foo (); | |
2671 | int foo () { bar (); } | |
2672 | is OK. */ | |
2673 | if (current_lang_stack == current_lang_base) | |
a28e3c7f | 2674 | DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); |
8926095f MS |
2675 | else |
2676 | { | |
2677 | cp_error_at ("previous declaration of `%#D' with %L linkage", | |
2678 | olddecl, DECL_LANGUAGE (olddecl)); | |
2679 | cp_error ("conflicts with new declaration with %L linkage", | |
2680 | DECL_LANGUAGE (newdecl)); | |
2681 | } | |
2682 | } | |
e1cd6e56 | 2683 | |
a6f02587 | 2684 | if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl)) |
c32381b1 JM |
2685 | ; |
2686 | else if (TREE_CODE (olddecl) == FUNCTION_DECL) | |
e1cd6e56 MS |
2687 | { |
2688 | tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl)); | |
2689 | tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)); | |
2690 | int i = 1; | |
2691 | ||
2692 | if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) | |
2693 | t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); | |
2694 | ||
2695 | for (; t1 && t1 != void_list_node; | |
2696 | t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) | |
2697 | if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) | |
2698 | { | |
2507f3b5 RK |
2699 | if (1 == simple_cst_equal (TREE_PURPOSE (t1), |
2700 | TREE_PURPOSE (t2))) | |
e1cd6e56 MS |
2701 | { |
2702 | if (pedantic) | |
2703 | { | |
2704 | cp_pedwarn ("default argument given for parameter %d of `%#D'", | |
2705 | i, newdecl); | |
2706 | cp_pedwarn_at ("after previous specification in `%#D'", | |
2707 | olddecl); | |
2708 | } | |
2709 | } | |
2710 | else | |
2711 | { | |
2712 | cp_error ("default argument given for parameter %d of `%#D'", | |
2713 | i, newdecl); | |
da20811c | 2714 | cp_error_at ("after previous specification in `%#D'", |
e1cd6e56 MS |
2715 | olddecl); |
2716 | } | |
2717 | } | |
a5894242 | 2718 | |
7fcdf4c2 MS |
2719 | if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl) |
2720 | && TREE_ADDRESSABLE (olddecl) && warn_inline) | |
dff6b454 | 2721 | { |
7fcdf4c2 MS |
2722 | cp_warning ("`%#D' was used before it was declared inline", |
2723 | newdecl); | |
2724 | cp_warning_at ("previous non-inline declaration here", | |
2725 | olddecl); | |
dff6b454 | 2726 | } |
e1cd6e56 | 2727 | } |
8ccc31eb MS |
2728 | /* These bits are logically part of the type for non-functions. */ |
2729 | else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) | |
2730 | || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)) | |
2731 | { | |
2732 | cp_pedwarn ("type qualifiers for `%#D'", newdecl); | |
2733 | cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl); | |
2734 | } | |
8d08fdba MS |
2735 | } |
2736 | ||
2737 | /* If new decl is `static' and an `extern' was seen previously, | |
2738 | warn about it. */ | |
2739 | warn_extern_redeclared_static (newdecl, olddecl); | |
2740 | ||
e92cc029 | 2741 | /* We have committed to returning 1 at this point. */ |
8d08fdba MS |
2742 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
2743 | { | |
2744 | /* Now that functions must hold information normally held | |
2745 | by field decls, there is extra work to do so that | |
2746 | declaration information does not get destroyed during | |
2747 | definition. */ | |
2748 | if (DECL_VINDEX (olddecl)) | |
2749 | DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl); | |
2750 | if (DECL_CONTEXT (olddecl)) | |
2751 | DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); | |
2752 | if (DECL_CLASS_CONTEXT (olddecl)) | |
2753 | DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); | |
2754 | if (DECL_CHAIN (newdecl) == NULL_TREE) | |
2755 | DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); | |
2756 | if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) | |
2757 | DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); | |
e1cd6e56 MS |
2758 | DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl); |
2759 | DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); | |
7215f9a0 | 2760 | DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl); |
864b83b9 | 2761 | DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl); |
4a67c9e9 | 2762 | DECL_NEEDS_FINAL_OVERRIDER_P (newdecl) |= DECL_NEEDS_FINAL_OVERRIDER_P (olddecl); |
8d08fdba MS |
2763 | } |
2764 | ||
2765 | /* Deal with C++: must preserve virtual function table size. */ | |
2766 | if (TREE_CODE (olddecl) == TYPE_DECL) | |
2767 | { | |
2768 | register tree newtype = TREE_TYPE (newdecl); | |
2769 | register tree oldtype = TREE_TYPE (olddecl); | |
2770 | ||
2771 | if (newtype != error_mark_node && oldtype != error_mark_node | |
2772 | && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype)) | |
2773 | { | |
2774 | CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype); | |
2775 | CLASSTYPE_FRIEND_CLASSES (newtype) | |
2776 | = CLASSTYPE_FRIEND_CLASSES (oldtype); | |
2777 | } | |
8d08fdba MS |
2778 | } |
2779 | ||
2780 | /* Special handling ensues if new decl is a function definition. */ | |
2781 | new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL | |
2782 | && DECL_INITIAL (newdecl) != NULL_TREE); | |
2783 | ||
2784 | /* Optionally warn about more than one declaration for the same name, | |
2785 | but don't warn about a function declaration followed by a definition. */ | |
2786 | if (warn_redundant_decls | |
700f8a87 | 2787 | && ! DECL_ARTIFICIAL (olddecl) |
8d08fdba MS |
2788 | && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE) |
2789 | /* Don't warn about extern decl followed by (tentative) definition. */ | |
2790 | && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) | |
2791 | { | |
2792 | cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); | |
44a8d0b3 | 2793 | cp_warning_at ("previous declaration of `%D'", olddecl); |
8d08fdba MS |
2794 | } |
2795 | ||
2796 | /* Copy all the DECL_... slots specified in the new decl | |
2797 | except for any that we copy here from the old type. */ | |
2798 | ||
5566b478 MS |
2799 | if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
2800 | { | |
37dac039 JM |
2801 | if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE) |
2802 | { | |
3ac3d9ea MM |
2803 | if (! duplicate_decls (DECL_TEMPLATE_RESULT (newdecl), |
2804 | DECL_TEMPLATE_RESULT (olddecl))) | |
2805 | cp_error ("invalid redeclaration of %D", newdecl); | |
2806 | TREE_TYPE (olddecl) = TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)); | |
37dac039 | 2807 | DECL_TEMPLATE_PARMS (olddecl) = DECL_TEMPLATE_PARMS (newdecl); |
f84b4be9 | 2808 | DECL_TEMPLATE_INFO (olddecl) = DECL_TEMPLATE_INFO (newdecl); |
37dac039 | 2809 | } |
5566b478 MS |
2810 | return 1; |
2811 | } | |
2812 | ||
8d08fdba MS |
2813 | if (types_match) |
2814 | { | |
2815 | /* Automatically handles default parameters. */ | |
2816 | tree oldtype = TREE_TYPE (olddecl); | |
e1cd6e56 | 2817 | tree newtype; |
8d08fdba | 2818 | |
e1cd6e56 MS |
2819 | /* Make sure we put the new type in the same obstack as the old one. */ |
2820 | if (oldtype) | |
39211cd5 MS |
2821 | push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); |
2822 | else | |
2823 | { | |
2824 | push_obstacks_nochange (); | |
2825 | end_temporary_allocation (); | |
2826 | } | |
2827 | ||
e1cd6e56 MS |
2828 | /* Merge the data types specified in the two decls. */ |
2829 | newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); | |
2830 | ||
8d08fdba MS |
2831 | if (TREE_CODE (newdecl) == VAR_DECL) |
2832 | DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl); | |
2833 | /* Do this after calling `common_type' so that default | |
2834 | parameters don't confuse us. */ | |
2835 | else if (TREE_CODE (newdecl) == FUNCTION_DECL | |
2836 | && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)) | |
2837 | != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)))) | |
2838 | { | |
f30432d7 | 2839 | TREE_TYPE (newdecl) = build_exception_variant (newtype, |
8d08fdba | 2840 | TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); |
f30432d7 | 2841 | TREE_TYPE (olddecl) = build_exception_variant (newtype, |
8d08fdba MS |
2842 | TYPE_RAISES_EXCEPTIONS (oldtype)); |
2843 | ||
047f64a3 JM |
2844 | if ((pedantic || (! DECL_IN_SYSTEM_HEADER (olddecl) |
2845 | && DECL_SOURCE_LINE (olddecl) != 0)) | |
da20811c | 2846 | && flag_exceptions |
824b9a4c | 2847 | && ! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl))) |
8d08fdba | 2848 | { |
824b9a4c | 2849 | cp_pedwarn ("declaration of `%D' throws different exceptions", |
a28e3c7f | 2850 | newdecl); |
824b9a4c | 2851 | cp_pedwarn_at ("previous declaration here", olddecl); |
8d08fdba MS |
2852 | } |
2853 | } | |
2854 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; | |
2855 | ||
2856 | /* Lay the type out, unless already done. */ | |
b7484fbe | 2857 | if (oldtype != TREE_TYPE (newdecl) |
5566b478 | 2858 | && TREE_TYPE (newdecl) != error_mark_node |
5156628f | 2859 | && !(processing_template_decl && uses_template_parms (newdecl))) |
b7484fbe MS |
2860 | layout_type (TREE_TYPE (newdecl)); |
2861 | ||
5566b478 MS |
2862 | if ((TREE_CODE (newdecl) == VAR_DECL |
2863 | || TREE_CODE (newdecl) == PARM_DECL | |
2864 | || TREE_CODE (newdecl) == RESULT_DECL | |
2865 | || TREE_CODE (newdecl) == FIELD_DECL | |
2866 | || TREE_CODE (newdecl) == TYPE_DECL) | |
5156628f | 2867 | && !(processing_template_decl && uses_template_parms (newdecl))) |
b7484fbe | 2868 | layout_decl (newdecl, 0); |
8d08fdba MS |
2869 | |
2870 | /* Merge the type qualifiers. */ | |
2871 | if (TREE_READONLY (newdecl)) | |
2872 | TREE_READONLY (olddecl) = 1; | |
2873 | if (TREE_THIS_VOLATILE (newdecl)) | |
2874 | TREE_THIS_VOLATILE (olddecl) = 1; | |
2875 | ||
2876 | /* Merge the initialization information. */ | |
8926095f MS |
2877 | if (DECL_INITIAL (newdecl) == NULL_TREE |
2878 | && DECL_INITIAL (olddecl) != NULL_TREE) | |
2879 | { | |
2880 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
2881 | DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); | |
2882 | DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); | |
2883 | } | |
39211cd5 MS |
2884 | |
2885 | /* Merge the section attribute. | |
2886 | We want to issue an error if the sections conflict but that must be | |
2887 | done later in decl_attributes since we are called before attributes | |
2888 | are assigned. */ | |
2889 | if (DECL_SECTION_NAME (newdecl) == NULL_TREE) | |
2890 | DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); | |
2891 | ||
8d08fdba MS |
2892 | /* Keep the old rtl since we can safely use it, unless it's the |
2893 | call to abort() used for abstract virtuals. */ | |
2894 | if ((DECL_LANG_SPECIFIC (olddecl) | |
2895 | && !DECL_ABSTRACT_VIRTUAL_P (olddecl)) | |
2896 | || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl)) | |
2897 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
39211cd5 MS |
2898 | |
2899 | pop_obstacks (); | |
8d08fdba MS |
2900 | } |
2901 | /* If cannot merge, then use the new type and qualifiers, | |
2902 | and don't preserve the old rtl. */ | |
2903 | else | |
2904 | { | |
2905 | /* Clean out any memory we had of the old declaration. */ | |
2906 | tree oldstatic = value_member (olddecl, static_aggregates); | |
2907 | if (oldstatic) | |
2908 | TREE_VALUE (oldstatic) = error_mark_node; | |
2909 | ||
2910 | TREE_TYPE (olddecl) = TREE_TYPE (newdecl); | |
2911 | TREE_READONLY (olddecl) = TREE_READONLY (newdecl); | |
2912 | TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); | |
2913 | TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); | |
2914 | } | |
2915 | ||
2916 | /* Merge the storage class information. */ | |
a9aedbc2 | 2917 | DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); |
e92cc029 | 2918 | DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl); |
a9aedbc2 MS |
2919 | TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); |
2920 | TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl); | |
2921 | if (! DECL_EXTERNAL (olddecl)) | |
2922 | DECL_EXTERNAL (newdecl) = 0; | |
8d08fdba | 2923 | |
5566b478 | 2924 | if (DECL_LANG_SPECIFIC (newdecl)) |
8d08fdba | 2925 | { |
a9aedbc2 MS |
2926 | DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl); |
2927 | DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl); | |
77be6f82 | 2928 | DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl); |
8d08fdba MS |
2929 | } |
2930 | ||
8d08fdba MS |
2931 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
2932 | { | |
75650646 MM |
2933 | if (DECL_TEMPLATE_INSTANTIATION (olddecl) |
2934 | && !DECL_TEMPLATE_INSTANTIATION (newdecl)) | |
2935 | { | |
2936 | /* If newdecl is not a specialization, then it is not a | |
2937 | template-related function at all. And that means that we | |
2938 | shoud have exited above, returning 0. */ | |
2939 | my_friendly_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl), | |
2940 | 0); | |
2941 | ||
2942 | if (TREE_USED (olddecl)) | |
2943 | /* From [temp.expl.spec]: | |
2944 | ||
2945 | If a template, a member template or the member of a class | |
2946 | template is explicitly specialized then that | |
2947 | specialization shall be declared before the first use of | |
2948 | that specialization that would cause an implicit | |
2949 | instantiation to take place, in every translation unit in | |
2950 | which such a use occurs. */ | |
2951 | cp_error ("explicit specialization of %D after first use", | |
2952 | olddecl); | |
2953 | ||
2954 | SET_DECL_TEMPLATE_SPECIALIZATION (olddecl); | |
2955 | } | |
faae18ab MS |
2956 | DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl); |
2957 | ||
2958 | /* If either decl says `inline', this fn is inline, unless its | |
2959 | definition was passed already. */ | |
2960 | if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE) | |
2961 | DECL_INLINE (olddecl) = 1; | |
2962 | DECL_INLINE (newdecl) = DECL_INLINE (olddecl); | |
2963 | ||
700f8a87 MS |
2964 | if (! types_match) |
2965 | { | |
2966 | DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl); | |
2967 | DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl); | |
5566b478 MS |
2968 | DECL_RTL (olddecl) = DECL_RTL (newdecl); |
2969 | } | |
2970 | if (! types_match || new_defines_function) | |
2971 | { | |
2972 | /* These need to be copied so that the names are available. */ | |
700f8a87 MS |
2973 | DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl); |
2974 | DECL_RESULT (olddecl) = DECL_RESULT (newdecl); | |
700f8a87 | 2975 | } |
8d08fdba MS |
2976 | if (new_defines_function) |
2977 | /* If defining a function declared with other language | |
2978 | linkage, use the previously declared language linkage. */ | |
2979 | DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); | |
2980 | else | |
2981 | { | |
2982 | /* If redeclaring a builtin function, and not a definition, | |
2983 | it stays built in. */ | |
2984 | if (DECL_BUILT_IN (olddecl)) | |
2985 | { | |
2986 | DECL_BUILT_IN (newdecl) = 1; | |
39211cd5 | 2987 | DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); |
8d08fdba MS |
2988 | /* If we're keeping the built-in definition, keep the rtl, |
2989 | regardless of declaration matches. */ | |
2990 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
2991 | } | |
2992 | else | |
2993 | DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); | |
2994 | ||
2995 | DECL_RESULT (newdecl) = DECL_RESULT (olddecl); | |
8926095f | 2996 | if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))) |
8d08fdba MS |
2997 | /* Previously saved insns go together with |
2998 | the function's previous definition. */ | |
2999 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
3000 | /* Don't clear out the arguments if we're redefining a function. */ | |
3001 | if (DECL_ARGUMENTS (olddecl)) | |
3002 | DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); | |
3003 | } | |
6060a796 MS |
3004 | if (DECL_LANG_SPECIFIC (olddecl)) |
3005 | DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl); | |
8d08fdba MS |
3006 | } |
3007 | ||
a9aedbc2 MS |
3008 | if (TREE_CODE (newdecl) == NAMESPACE_DECL) |
3009 | { | |
3010 | NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl); | |
3011 | } | |
3012 | ||
8926095f MS |
3013 | if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
3014 | { | |
75650646 MM |
3015 | DECL_TEMPLATE_SPECIALIZATIONS (newdecl) |
3016 | = DECL_TEMPLATE_SPECIALIZATIONS (olddecl); | |
f376e137 MS |
3017 | if (DECL_CHAIN (newdecl) == NULL_TREE) |
3018 | DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); | |
8926095f | 3019 | } |
5566b478 | 3020 | |
8d08fdba MS |
3021 | /* Now preserve various other info from the definition. */ |
3022 | TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); | |
3023 | TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); | |
3024 | DECL_COMMON (newdecl) = DECL_COMMON (olddecl); | |
f376e137 | 3025 | DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl); |
8d08fdba MS |
3026 | |
3027 | /* Don't really know how much of the language-specific | |
3028 | values we should copy from old to new. */ | |
3029 | if (DECL_LANG_SPECIFIC (olddecl)) | |
3030 | { | |
3031 | DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); | |
3032 | DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); | |
db5ae43f | 3033 | DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); |
5566b478 MS |
3034 | if (DECL_TEMPLATE_INFO (newdecl) == NULL_TREE) |
3035 | { | |
3036 | DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); | |
3037 | DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl); | |
3038 | } | |
8d08fdba MS |
3039 | } |
3040 | ||
3041 | if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
3042 | { | |
3043 | int function_size; | |
3044 | struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl); | |
3045 | struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl); | |
3046 | ||
3047 | function_size = sizeof (struct tree_decl); | |
3048 | ||
3049 | bcopy ((char *) newdecl + sizeof (struct tree_common), | |
3050 | (char *) olddecl + sizeof (struct tree_common), | |
3051 | function_size - sizeof (struct tree_common)); | |
3052 | ||
3053 | /* Can we safely free the storage used by newdecl? */ | |
3054 | ||
3055 | #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \ | |
3056 | & ~ obstack_alignment_mask (&permanent_obstack)) | |
3057 | ||
75650646 MM |
3058 | if (DECL_TEMPLATE_INSTANTIATION (newdecl)) |
3059 | { | |
3060 | /* If newdecl is a template instantiation, it is possible that | |
3061 | the following sequence of events has occurred: | |
3062 | ||
3063 | o A friend function was declared in a class template. The | |
3064 | class template was instantiated. | |
3065 | ||
3066 | o The instantiation of the friend declaration was | |
3067 | recorded on the instantiation list, and is newdecl. | |
3068 | ||
3069 | o Later, however, instantiate_class_template called pushdecl | |
3070 | on the newdecl to perform name injection. But, pushdecl in | |
3071 | turn called duplicate_decls when it discovered that another | |
3072 | declaration of a global function with the same name already | |
3073 | existed. | |
3074 | ||
3075 | o Here, in duplicate_decls, we decided to clobber newdecl. | |
3076 | ||
3077 | If we're going to do that, we'd better make sure that | |
3078 | olddecl, and not newdecl, is on the list of | |
3079 | instantiations so that if we try to do the instantiation | |
3080 | again we won't get the clobbered declaration. */ | |
3081 | ||
3082 | tree tmpl = DECL_TI_TEMPLATE (newdecl); | |
3083 | tree decls = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); | |
3084 | ||
3085 | for (; decls; decls = TREE_CHAIN (decls)) | |
3086 | if (TREE_VALUE (decls) == newdecl) | |
3087 | TREE_VALUE (decls) = olddecl; | |
3088 | } | |
3089 | ||
8d08fdba MS |
3090 | if ((char *)newdecl + ROUND (function_size) |
3091 | + ROUND (sizeof (struct lang_decl)) | |
3092 | == obstack_next_free (&permanent_obstack)) | |
3093 | { | |
3094 | DECL_MAIN_VARIANT (newdecl) = olddecl; | |
3095 | DECL_LANG_SPECIFIC (olddecl) = ol; | |
3096 | bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl)); | |
3097 | ||
3098 | obstack_free (&permanent_obstack, newdecl); | |
3099 | } | |
d22c8596 | 3100 | else if (LANG_DECL_PERMANENT (ol) && ol != nl) |
8d08fdba MS |
3101 | { |
3102 | if (DECL_MAIN_VARIANT (olddecl) == olddecl) | |
3103 | { | |
3104 | /* Save these lang_decls that would otherwise be lost. */ | |
3105 | extern tree free_lang_decl_chain; | |
3106 | tree free_lang_decl = (tree) ol; | |
d22c8596 MS |
3107 | |
3108 | if (DECL_LANG_SPECIFIC (olddecl) == ol) | |
3109 | abort (); | |
3110 | ||
8d08fdba MS |
3111 | TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; |
3112 | free_lang_decl_chain = free_lang_decl; | |
3113 | } | |
3114 | else | |
3115 | { | |
bd6dd845 | 3116 | /* Storage leak. */; |
8d08fdba MS |
3117 | } |
3118 | } | |
3119 | } | |
3120 | else | |
3121 | { | |
3122 | bcopy ((char *) newdecl + sizeof (struct tree_common), | |
3123 | (char *) olddecl + sizeof (struct tree_common), | |
3124 | sizeof (struct tree_decl) - sizeof (struct tree_common) | |
3125 | + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); | |
3126 | } | |
3127 | ||
3128 | DECL_UID (olddecl) = olddecl_uid; | |
3129 | if (olddecl_friend) | |
3130 | DECL_FRIEND_P (olddecl) = 1; | |
3131 | ||
d9525bec BK |
3132 | /* NEWDECL contains the merged attribute lists. |
3133 | Update OLDDECL to be the same. */ | |
3134 | DECL_MACHINE_ATTRIBUTES (olddecl) = DECL_MACHINE_ATTRIBUTES (newdecl); | |
3135 | ||
8d08fdba MS |
3136 | return 1; |
3137 | } | |
3138 | ||
3139 | /* Record a decl-node X as belonging to the current lexical scope. | |
3140 | Check for errors (such as an incompatible declaration for the same | |
3141 | name already seen in the same scope). | |
3142 | ||
3143 | Returns either X or an old decl for the same name. | |
3144 | If an old decl is returned, it may have been smashed | |
3145 | to agree with what X says. */ | |
3146 | ||
3147 | tree | |
3148 | pushdecl (x) | |
3149 | tree x; | |
3150 | { | |
3151 | register tree t; | |
8d08fdba | 3152 | register tree name = DECL_ASSEMBLER_NAME (x); |
8d08fdba MS |
3153 | register struct binding_level *b = current_binding_level; |
3154 | ||
8d08fdba | 3155 | if (x != current_function_decl |
700f8a87 MS |
3156 | /* Don't change DECL_CONTEXT of virtual methods. */ |
3157 | && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x)) | |
8d08fdba MS |
3158 | && ! DECL_CONTEXT (x)) |
3159 | DECL_CONTEXT (x) = current_function_decl; | |
3160 | /* A local declaration for a function doesn't constitute nesting. */ | |
3161 | if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0) | |
3162 | DECL_CONTEXT (x) = 0; | |
3163 | ||
8d08fdba | 3164 | /* Type are looked up using the DECL_NAME, as that is what the rest of the |
e92cc029 | 3165 | compiler wants to use. */ |
a9aedbc2 | 3166 | if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL |
73b0fce8 KL |
3167 | || TREE_CODE (x) == NAMESPACE_DECL || TREE_CODE (x) == TEMPLATE_TYPE_PARM |
3168 | || TREE_CODE (x) == TEMPLATE_TEMPLATE_PARM) | |
8d08fdba | 3169 | name = DECL_NAME (x); |
8d08fdba MS |
3170 | |
3171 | if (name) | |
3172 | { | |
5566b478 MS |
3173 | #if 0 |
3174 | /* Not needed...see below. */ | |
8d08fdba MS |
3175 | char *file; |
3176 | int line; | |
5566b478 | 3177 | #endif |
386b8a85 JM |
3178 | if (TREE_CODE (name) == TEMPLATE_ID_EXPR) |
3179 | name = TREE_OPERAND (name, 0); | |
3180 | ||
700f8a87 | 3181 | t = lookup_name_current_level (name); |
8d08fdba MS |
3182 | if (t == error_mark_node) |
3183 | { | |
3184 | /* error_mark_node is 0 for a while during initialization! */ | |
3185 | t = NULL_TREE; | |
3186 | cp_error_at ("`%#D' used prior to declaration", x); | |
3187 | } | |
3188 | ||
51c184be | 3189 | else if (t != NULL_TREE) |
8d08fdba | 3190 | { |
5566b478 MS |
3191 | #if 0 |
3192 | /* This is turned off until I have time to do it right (bpk). */ | |
e92cc029 | 3193 | /* With the code below that uses it... */ |
8d6e462b PB |
3194 | file = DECL_SOURCE_FILE (t); |
3195 | line = DECL_SOURCE_LINE (t); | |
5566b478 | 3196 | #endif |
2ee887f2 | 3197 | if (TREE_CODE (t) == PARM_DECL) |
8d08fdba MS |
3198 | { |
3199 | if (DECL_CONTEXT (t) == NULL_TREE) | |
3200 | fatal ("parse errors have confused me too much"); | |
be99da77 | 3201 | |
e92cc029 | 3202 | /* Check for duplicate params. */ |
be99da77 MS |
3203 | if (duplicate_decls (x, t)) |
3204 | return t; | |
8d08fdba | 3205 | } |
8d6e462b | 3206 | else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c) |
5566b478 MS |
3207 | || DECL_FUNCTION_TEMPLATE_P (x)) |
3208 | && is_overloaded_fn (t)) | |
8926095f | 3209 | /* don't do anything just yet */; |
e1cd6e56 MS |
3210 | else if (t == wchar_decl_node) |
3211 | { | |
3212 | if (pedantic && ! DECL_IN_SYSTEM_HEADER (x)) | |
3213 | cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x)); | |
3214 | ||
3215 | /* Throw away the redeclaration. */ | |
3216 | return t; | |
3217 | } | |
8926095f | 3218 | else if (TREE_CODE (t) != TREE_CODE (x)) |
8d08fdba | 3219 | { |
ec255269 MS |
3220 | if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t) |
3221 | && TREE_CODE (x) != TYPE_DECL | |
3222 | && ! (TREE_CODE (x) == TEMPLATE_DECL | |
3223 | && TREE_CODE (DECL_TEMPLATE_RESULT (x)) == TYPE_DECL)) | |
3224 | || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) | |
3225 | && TREE_CODE (t) != TYPE_DECL | |
3226 | && ! (TREE_CODE (t) == TEMPLATE_DECL | |
3227 | && (TREE_CODE (DECL_TEMPLATE_RESULT (t)) | |
3228 | == TYPE_DECL)))) | |
51c184be MS |
3229 | { |
3230 | /* We do nothing special here, because C++ does such nasty | |
3231 | things with TYPE_DECLs. Instead, just let the TYPE_DECL | |
3232 | get shadowed, and know that if we need to find a TYPE_DECL | |
3233 | for a given name, we can look in the IDENTIFIER_TYPE_VALUE | |
3234 | slot of the identifier. */ | |
3235 | ; | |
3236 | } | |
3237 | else if (duplicate_decls (x, t)) | |
3238 | return t; | |
8d08fdba MS |
3239 | } |
3240 | else if (duplicate_decls (x, t)) | |
51c184be | 3241 | { |
8d08fdba | 3242 | #if 0 |
8926095f | 3243 | /* This is turned off until I have time to do it right (bpk). */ |
8d08fdba | 3244 | |
8926095f MS |
3245 | /* Also warn if they did a prototype with `static' on it, but |
3246 | then later left the `static' off. */ | |
3247 | if (! TREE_PUBLIC (name) && TREE_PUBLIC (x)) | |
8d08fdba | 3248 | { |
8926095f MS |
3249 | if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t)) |
3250 | return t; | |
8d08fdba | 3251 | |
8926095f MS |
3252 | if (extra_warnings) |
3253 | { | |
a28e3c7f MS |
3254 | cp_warning ("`static' missing from declaration of `%D'", |
3255 | t); | |
8926095f MS |
3256 | warning_with_file_and_line (file, line, |
3257 | "previous declaration of `%s'", | |
3258 | decl_as_string (t, 0)); | |
3259 | } | |
8d08fdba | 3260 | |
8926095f MS |
3261 | /* Now fix things so it'll do what they expect. */ |
3262 | if (current_function_decl) | |
3263 | TREE_PUBLIC (current_function_decl) = 0; | |
3264 | } | |
51c184be MS |
3265 | /* Due to interference in memory reclamation (X may be |
3266 | obstack-deallocated at this point), we must guard against | |
8926095f MS |
3267 | one really special case. [jason: This should be handled |
3268 | by start_function] */ | |
51c184be MS |
3269 | if (current_function_decl == x) |
3270 | current_function_decl = t; | |
8926095f | 3271 | #endif |
7177d104 MS |
3272 | if (TREE_CODE (t) == TYPE_DECL) |
3273 | SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t)); | |
f30432d7 MS |
3274 | else if (TREE_CODE (t) == FUNCTION_DECL) |
3275 | check_default_args (t); | |
7177d104 | 3276 | |
51c184be MS |
3277 | return t; |
3278 | } | |
8d08fdba | 3279 | } |
8926095f MS |
3280 | |
3281 | if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x)) | |
3282 | { | |
3283 | t = push_overloaded_decl (x, 1); | |
3284 | if (t != x || DECL_LANGUAGE (x) == lang_c) | |
3285 | return t; | |
3286 | } | |
5566b478 | 3287 | else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_CONTEXT (x) == NULL_TREE) |
8926095f | 3288 | return push_overloaded_decl (x, 0); |
8d08fdba MS |
3289 | |
3290 | /* If declaring a type as a typedef, and the type has no known | |
3291 | typedef name, install this TYPE_DECL as its typedef name. */ | |
3292 | if (TREE_CODE (x) == TYPE_DECL) | |
3293 | { | |
3294 | tree type = TREE_TYPE (x); | |
3295 | tree name = (type != error_mark_node) ? TYPE_NAME (type) : x; | |
3296 | ||
3297 | if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL) | |
3298 | { | |
3299 | /* If these are different names, and we're at the global | |
3300 | binding level, make two equivalent definitions. */ | |
3301 | name = x; | |
3302 | if (global_bindings_p ()) | |
3303 | TYPE_NAME (type) = x; | |
3304 | } | |
8d08fdba MS |
3305 | my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140); |
3306 | ||
8d08fdba MS |
3307 | if (type != error_mark_node |
3308 | && TYPE_NAME (type) | |
3309 | && TYPE_IDENTIFIER (type)) | |
3310 | set_identifier_type_value_with_scope (DECL_NAME (x), type, b); | |
3311 | } | |
3312 | ||
3313 | /* Multiple external decls of the same identifier ought to match. | |
3314 | ||
3315 | We get warnings about inline functions where they are defined. | |
39211cd5 MS |
3316 | We get warnings about other functions from push_overloaded_decl. |
3317 | ||
8d08fdba | 3318 | Avoid duplicate warnings where they are used. */ |
39211cd5 | 3319 | if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL) |
8d08fdba MS |
3320 | { |
3321 | tree decl; | |
30394414 | 3322 | tree bindings = binding_for_name (name, current_namespace); |
8d08fdba | 3323 | |
30394414 JM |
3324 | if (BINDING_VALUE (bindings) != NULL_TREE |
3325 | && (DECL_EXTERNAL (BINDING_VALUE (bindings)) | |
3326 | || TREE_PUBLIC (BINDING_VALUE (bindings)))) | |
3327 | decl = BINDING_VALUE (bindings); | |
8d08fdba MS |
3328 | else |
3329 | decl = NULL_TREE; | |
3330 | ||
39211cd5 | 3331 | if (decl |
8d08fdba MS |
3332 | /* If different sort of thing, we already gave an error. */ |
3333 | && TREE_CODE (decl) == TREE_CODE (x) | |
39211cd5 | 3334 | && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1)) |
8d08fdba MS |
3335 | { |
3336 | cp_pedwarn ("type mismatch with previous external decl", x); | |
8926095f | 3337 | cp_pedwarn_at ("previous external decl of `%#D'", decl); |
8d08fdba MS |
3338 | } |
3339 | } | |
3340 | ||
8d08fdba MS |
3341 | /* This name is new in its binding level. |
3342 | Install the new declaration and return it. */ | |
3343 | if (b == global_binding_level) | |
3344 | { | |
3345 | /* Install a global value. */ | |
30394414 | 3346 | tree bindings = binding_for_name (name, current_namespace); |
8d08fdba | 3347 | |
8d08fdba MS |
3348 | /* If the first global decl has external linkage, |
3349 | warn if we later see static one. */ | |
30394414 | 3350 | if (BINDING_VALUE (bindings) == NULL_TREE && TREE_PUBLIC (x)) |
8d08fdba MS |
3351 | TREE_PUBLIC (name) = 1; |
3352 | ||
e1cd6e56 MS |
3353 | /* Don't install an artificial TYPE_DECL if we already have |
3354 | another _DECL with that name. */ | |
8d08fdba MS |
3355 | if (TREE_CODE (x) != TYPE_DECL |
3356 | || t == NULL_TREE | |
e1cd6e56 | 3357 | || ! DECL_ARTIFICIAL (x)) |
30394414 JM |
3358 | { |
3359 | if (TREE_CODE (x) == FUNCTION_DECL) | |
3360 | my_friendly_assert ((BINDING_VALUE (bindings) == NULL_TREE) | |
3361 | || BINDING_VALUE (bindings) == x, 378); | |
3362 | BINDING_VALUE (bindings) = x; | |
3363 | } | |
8d08fdba MS |
3364 | |
3365 | /* Don't forget if the function was used via an implicit decl. */ | |
3366 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
3367 | && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) | |
3368 | TREE_USED (x) = 1; | |
3369 | ||
3370 | /* Don't forget if its address was taken in that way. */ | |
3371 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
3372 | && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) | |
3373 | TREE_ADDRESSABLE (x) = 1; | |
3374 | ||
3375 | /* Warn about mismatches against previous implicit decl. */ | |
3376 | if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE | |
3377 | /* If this real decl matches the implicit, don't complain. */ | |
3378 | && ! (TREE_CODE (x) == FUNCTION_DECL | |
3379 | && TREE_TYPE (TREE_TYPE (x)) == integer_type_node)) | |
3380 | cp_warning | |
3381 | ("`%D' was previously implicitly declared to return `int'", x); | |
3382 | ||
3383 | /* If new decl is `static' and an `extern' was seen previously, | |
3384 | warn about it. */ | |
a0a33927 MS |
3385 | if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t)) |
3386 | warn_extern_redeclared_static (x, t); | |
8d08fdba MS |
3387 | } |
3388 | else | |
3389 | { | |
3390 | /* Here to install a non-global value. */ | |
3391 | tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); | |
30394414 | 3392 | tree oldglobal = binding_for_name (name, current_namespace); |
8d08fdba | 3393 | |
e1cd6e56 MS |
3394 | /* Don't install an artificial TYPE_DECL if we already have |
3395 | another _DECL with that name. */ | |
3396 | if (TREE_CODE (x) != TYPE_DECL | |
3397 | || t == NULL_TREE | |
3398 | || ! DECL_ARTIFICIAL (x)) | |
3399 | { | |
3400 | b->shadowed = tree_cons (name, oldlocal, b->shadowed); | |
3401 | IDENTIFIER_LOCAL_VALUE (name) = x; | |
3402 | } | |
8d08fdba MS |
3403 | |
3404 | /* If this is a TYPE_DECL, push it into the type value slot. */ | |
3405 | if (TREE_CODE (x) == TYPE_DECL) | |
3406 | set_identifier_type_value_with_scope (name, TREE_TYPE (x), b); | |
3407 | ||
a9aedbc2 MS |
3408 | /* Clear out any TYPE_DECL shadowed by a namespace so that |
3409 | we won't think this is a type. The C struct hack doesn't | |
3410 | go through namespaces. */ | |
3411 | if (TREE_CODE (x) == NAMESPACE_DECL) | |
3412 | set_identifier_type_value_with_scope (name, NULL_TREE, b); | |
3413 | ||
8d08fdba MS |
3414 | /* If this is an extern function declaration, see if we |
3415 | have a global definition or declaration for the function. */ | |
3416 | if (oldlocal == NULL_TREE | |
faae18ab | 3417 | && DECL_EXTERNAL (x) |
30394414 | 3418 | && BINDING_VALUE (oldglobal) != NULL_TREE |
8d08fdba | 3419 | && TREE_CODE (x) == FUNCTION_DECL |
30394414 | 3420 | && TREE_CODE (BINDING_VALUE (oldglobal)) == FUNCTION_DECL) |
8d08fdba MS |
3421 | { |
3422 | /* We have one. Their types must agree. */ | |
30394414 | 3423 | if (decls_match (x, BINDING_VALUE (oldglobal))) |
6060a796 MS |
3424 | /* OK */; |
3425 | else | |
8d08fdba MS |
3426 | { |
3427 | cp_warning ("extern declaration of `%#D' doesn't match", x); | |
30394414 | 3428 | cp_warning_at ("global declaration `%#D'", BINDING_VALUE (oldglobal)); |
8d08fdba | 3429 | } |
8d08fdba MS |
3430 | } |
3431 | /* If we have a local external declaration, | |
3432 | and no file-scope declaration has yet been seen, | |
3433 | then if we later have a file-scope decl it must not be static. */ | |
3434 | if (oldlocal == NULL_TREE | |
30394414 | 3435 | && BINDING_VALUE (oldglobal) == NULL_TREE |
8d08fdba MS |
3436 | && DECL_EXTERNAL (x) |
3437 | && TREE_PUBLIC (x)) | |
3438 | { | |
3439 | TREE_PUBLIC (name) = 1; | |
3440 | } | |
3441 | ||
3442 | if (DECL_FROM_INLINE (x)) | |
3443 | /* Inline decls shadow nothing. */; | |
3444 | ||
3445 | /* Warn if shadowing an argument at the top level of the body. */ | |
3446 | else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) | |
3447 | && TREE_CODE (oldlocal) == PARM_DECL | |
3448 | && TREE_CODE (x) != PARM_DECL) | |
3449 | { | |
3450 | /* Go to where the parms should be and see if we | |
3451 | find them there. */ | |
3452 | struct binding_level *b = current_binding_level->level_chain; | |
3453 | ||
3454 | if (cleanup_label) | |
3455 | b = b->level_chain; | |
3456 | ||
3457 | /* ARM $8.3 */ | |
3458 | if (b->parm_flag == 1) | |
3459 | cp_error ("declaration of `%#D' shadows a parameter", name); | |
3460 | } | |
72b7eeff | 3461 | else if (warn_shadow && oldlocal != NULL_TREE && b->is_for_scope |
8d6e462b PB |
3462 | && !DECL_DEAD_FOR_LOCAL (oldlocal)) |
3463 | { | |
3464 | warning ("variable `%s' shadows local", | |
3465 | IDENTIFIER_POINTER (name)); | |
3466 | cp_warning_at (" this is the shadowed declaration", oldlocal); | |
3467 | } | |
8d08fdba MS |
3468 | /* Maybe warn if shadowing something else. */ |
3469 | else if (warn_shadow && !DECL_EXTERNAL (x) | |
3470 | /* No shadow warnings for internally generated vars. */ | |
700f8a87 | 3471 | && ! DECL_ARTIFICIAL (x) |
8d08fdba MS |
3472 | /* No shadow warnings for vars made for inlining. */ |
3473 | && ! DECL_FROM_INLINE (x)) | |
3474 | { | |
3475 | char *warnstring = NULL; | |
3476 | ||
3477 | if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) | |
3478 | warnstring = "declaration of `%s' shadows a parameter"; | |
3479 | else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE | |
4ac14744 | 3480 | && current_class_ptr |
8d08fdba MS |
3481 | && !TREE_STATIC (name)) |
3482 | warnstring = "declaration of `%s' shadows a member of `this'"; | |
3483 | else if (oldlocal != NULL_TREE) | |
3484 | warnstring = "declaration of `%s' shadows previous local"; | |
30394414 JM |
3485 | else if (BINDING_VALUE (oldglobal) != NULL_TREE) |
3486 | /* XXX shadow warnings in outer-more namespaces */ | |
8d08fdba MS |
3487 | warnstring = "declaration of `%s' shadows global declaration"; |
3488 | ||
3489 | if (warnstring) | |
3490 | warning (warnstring, IDENTIFIER_POINTER (name)); | |
3491 | } | |
e1cd6e56 | 3492 | } |
8d08fdba | 3493 | |
e1cd6e56 | 3494 | if (TREE_CODE (x) == FUNCTION_DECL) |
f30432d7 | 3495 | check_default_args (x); |
8145f082 MS |
3496 | |
3497 | /* Keep count of variables in this level with incomplete type. */ | |
8145f082 | 3498 | if (TREE_CODE (x) == VAR_DECL |
28cbf42c | 3499 | && TREE_TYPE (x) != error_mark_node |
f30432d7 MS |
3500 | && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE |
3501 | && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) | |
3502 | /* RTTI TD entries are created while defining the type_info. */ | |
3503 | || (TYPE_LANG_SPECIFIC (TREE_TYPE (x)) | |
3504 | && TYPE_BEING_DEFINED (TREE_TYPE (x))))) | |
3505 | b->incomplete = tree_cons (NULL_TREE, x, b->incomplete); | |
8d08fdba MS |
3506 | } |
3507 | ||
8d08fdba MS |
3508 | /* Put decls on list in reverse order. |
3509 | We will reverse them later if necessary. */ | |
3510 | TREE_CHAIN (x) = b->names; | |
3511 | b->names = x; | |
3512 | if (! (b != global_binding_level || TREE_PERMANENT (x))) | |
3513 | my_friendly_abort (124); | |
3514 | ||
3515 | return x; | |
3516 | } | |
3517 | ||
5566b478 MS |
3518 | /* Same as pushdecl, but define X in binding-level LEVEL. We rely on the |
3519 | caller to set DECL_CONTEXT properly. */ | |
8d08fdba MS |
3520 | |
3521 | static tree | |
3522 | pushdecl_with_scope (x, level) | |
3523 | tree x; | |
3524 | struct binding_level *level; | |
3525 | { | |
8d019cef | 3526 | register struct binding_level *b; |
5566b478 | 3527 | tree function_decl = current_function_decl; |
8d08fdba | 3528 | |
5566b478 | 3529 | current_function_decl = NULL_TREE; |
8d019cef JM |
3530 | if (level->parm_flag == 2) |
3531 | { | |
3532 | b = class_binding_level; | |
3533 | class_binding_level = level; | |
3534 | pushdecl_class_level (x); | |
3535 | class_binding_level = b; | |
3536 | } | |
3537 | else | |
3538 | { | |
3539 | b = current_binding_level; | |
3540 | current_binding_level = level; | |
3541 | x = pushdecl (x); | |
3542 | current_binding_level = b; | |
3543 | } | |
5566b478 | 3544 | current_function_decl = function_decl; |
8d08fdba MS |
3545 | return x; |
3546 | } | |
3547 | ||
3548 | /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, | |
3549 | if appropriate. */ | |
e92cc029 | 3550 | |
8d08fdba MS |
3551 | tree |
3552 | pushdecl_top_level (x) | |
3553 | tree x; | |
3554 | { | |
3555 | register struct binding_level *b = inner_binding_level; | |
3556 | register tree t = pushdecl_with_scope (x, global_binding_level); | |
3557 | ||
3558 | /* Now, the type_shadowed stack may screw us. Munge it so it does | |
3559 | what we want. */ | |
3560 | if (TREE_CODE (x) == TYPE_DECL) | |
3561 | { | |
3562 | tree name = DECL_NAME (x); | |
3563 | tree newval; | |
3564 | tree *ptr = (tree *)0; | |
3565 | for (; b != global_binding_level; b = b->level_chain) | |
3566 | { | |
3567 | tree shadowed = b->type_shadowed; | |
3568 | for (; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
3569 | if (TREE_PURPOSE (shadowed) == name) | |
3570 | { | |
3571 | ptr = &TREE_VALUE (shadowed); | |
3572 | /* Can't break out of the loop here because sometimes | |
3573 | a binding level will have duplicate bindings for | |
3574 | PT names. It's gross, but I haven't time to fix it. */ | |
3575 | } | |
3576 | } | |
3577 | newval = TREE_TYPE (x); | |
3578 | if (ptr == (tree *)0) | |
3579 | { | |
3580 | /* @@ This shouldn't be needed. My test case "zstring.cc" trips | |
3581 | up here if this is changed to an assertion. --KR */ | |
3582 | SET_IDENTIFIER_TYPE_VALUE (name, newval); | |
3583 | } | |
3584 | else | |
3585 | { | |
8d08fdba MS |
3586 | *ptr = newval; |
3587 | } | |
3588 | } | |
3589 | return t; | |
3590 | } | |
3591 | ||
3592 | /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL, | |
3593 | if appropriate. */ | |
e92cc029 | 3594 | |
bd6dd845 | 3595 | static void |
8d08fdba MS |
3596 | push_overloaded_decl_top_level (x, forget) |
3597 | tree x; | |
3598 | int forget; | |
3599 | { | |
3600 | struct binding_level *b = current_binding_level; | |
3601 | ||
3602 | current_binding_level = global_binding_level; | |
3603 | push_overloaded_decl (x, forget); | |
3604 | current_binding_level = b; | |
3605 | } | |
3606 | ||
3607 | /* Make the declaration of X appear in CLASS scope. */ | |
e92cc029 | 3608 | |
8d08fdba MS |
3609 | tree |
3610 | pushdecl_class_level (x) | |
3611 | tree x; | |
3612 | { | |
3613 | /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class | |
3614 | scope looks for the pre-mangled name. */ | |
3615 | register tree name = DECL_NAME (x); | |
3616 | ||
3617 | if (name) | |
3618 | { | |
8d2733ca MS |
3619 | if (TYPE_BEING_DEFINED (current_class_type)) |
3620 | { | |
3621 | /* Check for inconsistent use of this name in the class body. | |
3622 | Types, enums, and static vars are checked here; other | |
3623 | members are checked in finish_struct. */ | |
3624 | tree icv = IDENTIFIER_CLASS_VALUE (name); | |
3625 | ||
5566b478 | 3626 | if (icv && icv != x |
a4443a08 MS |
3627 | /* Don't complain about inherited names. */ |
3628 | && id_in_current_class (name) | |
3629 | /* Or shadowed tags. */ | |
3630 | && !(TREE_CODE (icv) == TYPE_DECL | |
3631 | && DECL_CONTEXT (icv) == current_class_type)) | |
8d2733ca MS |
3632 | { |
3633 | cp_error ("declaration of identifier `%D' as `%#D'", name, x); | |
3634 | cp_error_at ("conflicts with previous use in class as `%#D'", | |
3635 | icv); | |
3636 | } | |
3637 | } | |
3638 | ||
8d08fdba MS |
3639 | push_class_level_binding (name, x); |
3640 | if (TREE_CODE (x) == TYPE_DECL) | |
3641 | { | |
3642 | set_identifier_type_value (name, TREE_TYPE (x)); | |
8d08fdba MS |
3643 | } |
3644 | } | |
3645 | return x; | |
3646 | } | |
3647 | ||
bd6dd845 | 3648 | #if 0 |
7177d104 MS |
3649 | /* This function is used to push the mangled decls for nested types into |
3650 | the appropriate scope. Previously pushdecl_top_level was used, but that | |
3651 | is incorrect for members of local classes. */ | |
e92cc029 | 3652 | |
5566b478 | 3653 | void |
7177d104 MS |
3654 | pushdecl_nonclass_level (x) |
3655 | tree x; | |
3656 | { | |
3657 | struct binding_level *b = current_binding_level; | |
3658 | ||
7177d104 | 3659 | my_friendly_assert (b->parm_flag != 2, 180); |
7177d104 | 3660 | |
5566b478 | 3661 | #if 0 |
7177d104 MS |
3662 | /* Get out of template binding levels */ |
3663 | while (b->pseudo_global) | |
3664 | b = b->level_chain; | |
5566b478 | 3665 | #endif |
7177d104 MS |
3666 | |
3667 | pushdecl_with_scope (x, b); | |
3668 | } | |
bd6dd845 | 3669 | #endif |
7177d104 | 3670 | |
8d08fdba MS |
3671 | /* Make the declaration(s) of X appear in CLASS scope |
3672 | under the name NAME. */ | |
e92cc029 | 3673 | |
8d08fdba MS |
3674 | void |
3675 | push_class_level_binding (name, x) | |
3676 | tree name; | |
3677 | tree x; | |
3678 | { | |
98c1c668 JM |
3679 | /* The class_binding_level will be NULL if x is a template |
3680 | parameter name in a member template. */ | |
3681 | if (!class_binding_level) | |
3682 | return; | |
3683 | ||
e1cd6e56 MS |
3684 | if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) |
3685 | && purpose_member (name, class_binding_level->class_shadowed)) | |
3686 | return; | |
3687 | ||
8d08fdba MS |
3688 | maybe_push_cache_obstack (); |
3689 | class_binding_level->class_shadowed | |
3690 | = tree_cons (name, IDENTIFIER_CLASS_VALUE (name), | |
3691 | class_binding_level->class_shadowed); | |
3692 | pop_obstacks (); | |
3693 | IDENTIFIER_CLASS_VALUE (name) = x; | |
3694 | obstack_ptr_grow (&decl_obstack, x); | |
3695 | } | |
3696 | ||
3697 | /* Tell caller how to interpret a TREE_LIST which contains | |
3698 | chains of FUNCTION_DECLS. */ | |
e92cc029 | 3699 | |
8d08fdba MS |
3700 | int |
3701 | overloaded_globals_p (list) | |
3702 | tree list; | |
3703 | { | |
3704 | my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142); | |
3705 | ||
3706 | /* Don't commit caller to seeing them as globals. */ | |
3707 | if (TREE_NONLOCAL_FLAG (list)) | |
3708 | return -1; | |
8d08fdba | 3709 | /* Do commit caller to not seeing them as globals. */ |
5566b478 MS |
3710 | if (TREE_CODE (TREE_VALUE (list)) == TREE_LIST) |
3711 | return 0; | |
3712 | /* Do commit caller to seeing them as globals. */ | |
3713 | return 1; | |
8d08fdba MS |
3714 | } |
3715 | ||
700f8a87 MS |
3716 | /* DECL is a FUNCTION_DECL which may have other definitions already in |
3717 | place. We get around this by making the value of the identifier point | |
3718 | to a list of all the things that want to be referenced by that name. It | |
3719 | is then up to the users of that name to decide what to do with that | |
8d08fdba MS |
3720 | list. |
3721 | ||
3722 | DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT | |
3723 | slot. It is dealt with the same way. | |
3724 | ||
3725 | The value returned may be a previous declaration if we guessed wrong | |
3726 | about what language DECL should belong to (C or C++). Otherwise, | |
3727 | it's always DECL (and never something that's not a _DECL). */ | |
e92cc029 | 3728 | |
bd6dd845 | 3729 | static tree |
8d08fdba MS |
3730 | push_overloaded_decl (decl, forgettable) |
3731 | tree decl; | |
3732 | int forgettable; | |
3733 | { | |
3734 | tree orig_name = DECL_NAME (decl); | |
700f8a87 | 3735 | tree old; |
5566b478 | 3736 | int doing_global = (global_bindings_p () || ! forgettable); |
700f8a87 MS |
3737 | |
3738 | if (doing_global) | |
3739 | { | |
30394414 | 3740 | old = IDENTIFIER_NAMESPACE_VALUE (orig_name); |
700f8a87 | 3741 | if (old && TREE_CODE (old) == FUNCTION_DECL |
a4443a08 | 3742 | && DECL_ARTIFICIAL (old) |
700f8a87 MS |
3743 | && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old))) |
3744 | { | |
a4443a08 MS |
3745 | if (duplicate_decls (decl, old)) |
3746 | return old; | |
700f8a87 MS |
3747 | old = NULL_TREE; |
3748 | } | |
3749 | } | |
3750 | else | |
3751 | { | |
3752 | old = IDENTIFIER_LOCAL_VALUE (orig_name); | |
a4443a08 | 3753 | |
700f8a87 MS |
3754 | if (! purpose_member (orig_name, current_binding_level->shadowed)) |
3755 | { | |
3756 | current_binding_level->shadowed | |
3757 | = tree_cons (orig_name, old, current_binding_level->shadowed); | |
3758 | old = NULL_TREE; | |
3759 | } | |
3760 | } | |
8d08fdba | 3761 | |
700f8a87 | 3762 | if (old) |
8d08fdba | 3763 | { |
e1cd6e56 | 3764 | if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) |
8926095f | 3765 | { |
700f8a87 | 3766 | tree t = TREE_TYPE (old); |
cdf5b885 MS |
3767 | if (IS_AGGR_TYPE (t) && warn_shadow |
3768 | && (! DECL_IN_SYSTEM_HEADER (decl) | |
3769 | || ! DECL_IN_SYSTEM_HEADER (old))) | |
8926095f | 3770 | cp_warning ("`%#D' hides constructor for `%#T'", decl, t); |
5b605f68 | 3771 | old = NULL_TREE; |
8926095f | 3772 | } |
700f8a87 | 3773 | else if (is_overloaded_fn (old)) |
8d08fdba | 3774 | { |
8d08fdba MS |
3775 | tree tmp; |
3776 | ||
700f8a87 MS |
3777 | for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp)) |
3778 | if (decl == tmp || duplicate_decls (decl, tmp)) | |
3779 | return tmp; | |
8d08fdba | 3780 | } |
e1cd6e56 MS |
3781 | else |
3782 | { | |
3783 | cp_error_at ("previous non-function declaration `%#D'", old); | |
3784 | cp_error ("conflicts with function declaration `%#D'", decl); | |
a9aedbc2 | 3785 | return decl; |
e1cd6e56 | 3786 | } |
8d08fdba | 3787 | } |
7177d104 | 3788 | |
700f8a87 | 3789 | if (old || TREE_CODE (decl) == TEMPLATE_DECL) |
8d08fdba | 3790 | { |
700f8a87 MS |
3791 | if (old && is_overloaded_fn (old)) |
3792 | DECL_CHAIN (decl) = get_first_fn (old); | |
8d08fdba MS |
3793 | else |
3794 | DECL_CHAIN (decl) = NULL_TREE; | |
700f8a87 MS |
3795 | old = tree_cons (orig_name, decl, NULL_TREE); |
3796 | TREE_TYPE (old) = unknown_type_node; | |
8d08fdba MS |
3797 | } |
3798 | else | |
3799 | /* orig_name is not ambiguous. */ | |
700f8a87 MS |
3800 | old = decl; |
3801 | ||
3802 | if (doing_global) | |
30394414 | 3803 | IDENTIFIER_NAMESPACE_VALUE (orig_name) = old; |
700f8a87 MS |
3804 | else |
3805 | IDENTIFIER_LOCAL_VALUE (orig_name) = old; | |
3806 | ||
8d08fdba MS |
3807 | return decl; |
3808 | } | |
3809 | \f | |
3810 | /* Generate an implicit declaration for identifier FUNCTIONID | |
3811 | as a function of type int (). Print a warning if appropriate. */ | |
3812 | ||
3813 | tree | |
3814 | implicitly_declare (functionid) | |
3815 | tree functionid; | |
3816 | { | |
3817 | register tree decl; | |
3818 | int temp = allocation_temporary_p (); | |
3819 | ||
3820 | push_obstacks_nochange (); | |
3821 | ||
3822 | /* Save the decl permanently so we can warn if definition follows. | |
3823 | In ANSI C, warn_implicit is usually false, so the saves little space. | |
3824 | But in C++, it's usually true, hence the extra code. */ | |
d22c8596 | 3825 | if (temp && (! warn_implicit || toplevel_bindings_p ())) |
8d08fdba MS |
3826 | end_temporary_allocation (); |
3827 | ||
3828 | /* We used to reuse an old implicit decl here, | |
3829 | but this loses with inline functions because it can clobber | |
3830 | the saved decl chains. */ | |
3831 | decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type); | |
3832 | ||
3833 | DECL_EXTERNAL (decl) = 1; | |
3834 | TREE_PUBLIC (decl) = 1; | |
3835 | ||
3836 | /* ANSI standard says implicit declarations are in the innermost block. | |
d22c8596 | 3837 | So we record the decl in the standard fashion. */ |
8d08fdba MS |
3838 | pushdecl (decl); |
3839 | rest_of_decl_compilation (decl, NULL_PTR, 0, 0); | |
3840 | ||
3841 | if (warn_implicit | |
3842 | /* Only one warning per identifier. */ | |
3843 | && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE) | |
3844 | { | |
3845 | cp_pedwarn ("implicit declaration of function `%#D'", decl); | |
3846 | } | |
3847 | ||
3848 | SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl); | |
3849 | ||
3850 | pop_obstacks (); | |
3851 | ||
3852 | return decl; | |
3853 | } | |
3854 | ||
3855 | /* Return zero if the declaration NEWDECL is valid | |
3856 | when the declaration OLDDECL (assumed to be for the same name) | |
3857 | has already been seen. | |
3858 | Otherwise return an error message format string with a %s | |
3859 | where the identifier should go. */ | |
3860 | ||
3861 | static char * | |
3862 | redeclaration_error_message (newdecl, olddecl) | |
3863 | tree newdecl, olddecl; | |
3864 | { | |
3865 | if (TREE_CODE (newdecl) == TYPE_DECL) | |
3866 | { | |
3867 | /* Because C++ can put things into name space for free, | |
3868 | constructs like "typedef struct foo { ... } foo" | |
3869 | would look like an erroneous redeclaration. */ | |
8926095f | 3870 | if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0)) |
8d08fdba MS |
3871 | return 0; |
3872 | else | |
51c184be | 3873 | return "redefinition of `%#D'"; |
8d08fdba MS |
3874 | } |
3875 | else if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
3876 | { | |
3877 | /* If this is a pure function, its olddecl will actually be | |
3878 | the original initialization to `0' (which we force to call | |
3879 | abort()). Don't complain about redefinition in this case. */ | |
3880 | if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) | |
3881 | return 0; | |
3882 | ||
db5ae43f MS |
3883 | /* We'll complain about linkage mismatches in |
3884 | warn_extern_redeclared_static. */ | |
3885 | ||
3886 | /* defining the same name twice is no good. */ | |
8d08fdba | 3887 | if (DECL_INITIAL (olddecl) != NULL_TREE |
faae18ab | 3888 | && DECL_INITIAL (newdecl) != NULL_TREE) |
8d08fdba MS |
3889 | { |
3890 | if (DECL_NAME (olddecl) == NULL_TREE) | |
51c184be | 3891 | return "`%#D' not declared in class"; |
8d08fdba | 3892 | else |
51c184be | 3893 | return "redefinition of `%#D'"; |
8d08fdba MS |
3894 | } |
3895 | return 0; | |
3896 | } | |
51c184be MS |
3897 | else if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
3898 | { | |
ec255269 MS |
3899 | if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL |
3900 | && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) | |
3901 | && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl))) | |
3902 | || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL | |
3903 | && TYPE_SIZE (TREE_TYPE (newdecl)) | |
3904 | && TYPE_SIZE (TREE_TYPE (olddecl)))) | |
51c184be MS |
3905 | return "redefinition of `%#D'"; |
3906 | return 0; | |
3907 | } | |
5566b478 | 3908 | else if (toplevel_bindings_p ()) |
8d08fdba MS |
3909 | { |
3910 | /* Objects declared at top level: */ | |
3911 | /* If at least one is a reference, it's ok. */ | |
3912 | if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) | |
3913 | return 0; | |
8926095f MS |
3914 | /* Reject two definitions. */ |
3915 | return "redefinition of `%#D'"; | |
8d08fdba MS |
3916 | } |
3917 | else | |
3918 | { | |
3919 | /* Objects declared with block scope: */ | |
3920 | /* Reject two definitions, and reject a definition | |
3921 | together with an external reference. */ | |
3922 | if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))) | |
51c184be | 3923 | return "redeclaration of `%#D'"; |
8d08fdba MS |
3924 | return 0; |
3925 | } | |
3926 | } | |
3927 | \f | |
3928 | /* Get the LABEL_DECL corresponding to identifier ID as a label. | |
3929 | Create one if none exists so far for the current function. | |
3930 | This function is called for both label definitions and label references. */ | |
3931 | ||
3932 | tree | |
3933 | lookup_label (id) | |
3934 | tree id; | |
3935 | { | |
3936 | register tree decl = IDENTIFIER_LABEL_VALUE (id); | |
3937 | ||
3938 | if (current_function_decl == NULL_TREE) | |
3939 | { | |
3940 | error ("label `%s' referenced outside of any function", | |
3941 | IDENTIFIER_POINTER (id)); | |
3942 | return NULL_TREE; | |
3943 | } | |
3944 | ||
3945 | if ((decl == NULL_TREE | |
3946 | || DECL_SOURCE_LINE (decl) == 0) | |
e349ee73 MS |
3947 | && (named_label_uses == NULL |
3948 | || named_label_uses->names_in_scope != current_binding_level->names | |
3949 | || named_label_uses->label_decl != decl)) | |
3950 | { | |
3951 | struct named_label_list *new_ent; | |
3952 | new_ent | |
3953 | = (struct named_label_list*)oballoc (sizeof (struct named_label_list)); | |
3954 | new_ent->label_decl = decl; | |
3955 | new_ent->names_in_scope = current_binding_level->names; | |
3956 | new_ent->binding_level = current_binding_level; | |
3957 | new_ent->lineno_o_goto = lineno; | |
3958 | new_ent->filename_o_goto = input_filename; | |
3959 | new_ent->next = named_label_uses; | |
3960 | named_label_uses = new_ent; | |
8d08fdba MS |
3961 | } |
3962 | ||
3963 | /* Use a label already defined or ref'd with this name. */ | |
3964 | if (decl != NULL_TREE) | |
3965 | { | |
3966 | /* But not if it is inherited and wasn't declared to be inheritable. */ | |
3967 | if (DECL_CONTEXT (decl) != current_function_decl | |
3968 | && ! C_DECLARED_LABEL_FLAG (decl)) | |
3969 | return shadow_label (id); | |
3970 | return decl; | |
3971 | } | |
3972 | ||
3973 | decl = build_decl (LABEL_DECL, id, void_type_node); | |
3974 | ||
cffa8729 MS |
3975 | /* Make sure every label has an rtx. */ |
3976 | label_rtx (decl); | |
3977 | ||
8d08fdba MS |
3978 | /* A label not explicitly declared must be local to where it's ref'd. */ |
3979 | DECL_CONTEXT (decl) = current_function_decl; | |
3980 | ||
3981 | DECL_MODE (decl) = VOIDmode; | |
3982 | ||
3983 | /* Say where one reference is to the label, | |
3984 | for the sake of the error if it is not defined. */ | |
3985 | DECL_SOURCE_LINE (decl) = lineno; | |
3986 | DECL_SOURCE_FILE (decl) = input_filename; | |
3987 | ||
3988 | SET_IDENTIFIER_LABEL_VALUE (id, decl); | |
3989 | ||
3990 | named_labels = tree_cons (NULL_TREE, decl, named_labels); | |
e349ee73 | 3991 | named_label_uses->label_decl = decl; |
8d08fdba MS |
3992 | |
3993 | return decl; | |
3994 | } | |
3995 | ||
3996 | /* Make a label named NAME in the current function, | |
3997 | shadowing silently any that may be inherited from containing functions | |
3998 | or containing scopes. | |
3999 | ||
4000 | Note that valid use, if the label being shadowed | |
4001 | comes from another scope in the same function, | |
4002 | requires calling declare_nonlocal_label right away. */ | |
4003 | ||
4004 | tree | |
4005 | shadow_label (name) | |
4006 | tree name; | |
4007 | { | |
4008 | register tree decl = IDENTIFIER_LABEL_VALUE (name); | |
4009 | ||
4010 | if (decl != NULL_TREE) | |
4011 | { | |
4012 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
4013 | SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); | |
4014 | SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE); | |
4015 | } | |
4016 | ||
4017 | return lookup_label (name); | |
4018 | } | |
4019 | ||
4020 | /* Define a label, specifying the location in the source file. | |
4021 | Return the LABEL_DECL node for the label, if the definition is valid. | |
4022 | Otherwise return 0. */ | |
4023 | ||
4024 | tree | |
4025 | define_label (filename, line, name) | |
4026 | char *filename; | |
4027 | int line; | |
4028 | tree name; | |
4029 | { | |
5566b478 MS |
4030 | tree decl; |
4031 | ||
4032 | if (minimal_parse_mode) | |
4033 | { | |
4034 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
4035 | decl = build_decl (LABEL_DECL, name, void_type_node); | |
4036 | pop_obstacks (); | |
4037 | DECL_SOURCE_LINE (decl) = line; | |
4038 | DECL_SOURCE_FILE (decl) = filename; | |
4039 | add_tree (decl); | |
4040 | return decl; | |
4041 | } | |
4042 | ||
4043 | decl = lookup_label (name); | |
8d08fdba MS |
4044 | |
4045 | /* After labels, make any new cleanups go into their | |
4046 | own new (temporary) binding contour. */ | |
4047 | current_binding_level->more_cleanups_ok = 0; | |
4048 | ||
4049 | /* If label with this name is known from an outer context, shadow it. */ | |
4050 | if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl) | |
4051 | { | |
4052 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
4053 | SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); | |
4054 | decl = lookup_label (name); | |
4055 | } | |
4056 | ||
e1cd6e56 MS |
4057 | if (name == get_identifier ("wchar_t")) |
4058 | cp_pedwarn ("label named wchar_t"); | |
4059 | ||
8d08fdba MS |
4060 | if (DECL_INITIAL (decl) != NULL_TREE) |
4061 | { | |
4062 | cp_error ("duplicate label `%D'", decl); | |
4063 | return 0; | |
4064 | } | |
4065 | else | |
4066 | { | |
e349ee73 | 4067 | struct named_label_list *uses, *prev; |
28cbf42c | 4068 | int identified = 0; |
8d08fdba MS |
4069 | |
4070 | /* Mark label as having been defined. */ | |
4071 | DECL_INITIAL (decl) = error_mark_node; | |
4072 | /* Say where in the source. */ | |
4073 | DECL_SOURCE_FILE (decl) = filename; | |
4074 | DECL_SOURCE_LINE (decl) = line; | |
4075 | ||
e349ee73 MS |
4076 | prev = NULL; |
4077 | uses = named_label_uses; | |
4078 | while (uses != NULL) | |
4079 | if (uses->label_decl == decl) | |
8d08fdba MS |
4080 | { |
4081 | struct binding_level *b = current_binding_level; | |
4082 | while (b) | |
4083 | { | |
4084 | tree new_decls = b->names; | |
e349ee73 MS |
4085 | tree old_decls = (b == uses->binding_level) |
4086 | ? uses->names_in_scope : NULL_TREE; | |
8d08fdba MS |
4087 | while (new_decls != old_decls) |
4088 | { | |
4089 | if (TREE_CODE (new_decls) == VAR_DECL | |
4090 | /* Don't complain about crossing initialization | |
4091 | of internal entities. They can't be accessed, | |
4092 | and they should be cleaned up | |
4093 | by the time we get to the label. */ | |
700f8a87 | 4094 | && ! DECL_ARTIFICIAL (new_decls) |
8d08fdba MS |
4095 | && ((DECL_INITIAL (new_decls) != NULL_TREE |
4096 | && DECL_INITIAL (new_decls) != error_mark_node) | |
4097 | || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) | |
4098 | { | |
e349ee73 MS |
4099 | if (! identified) |
4100 | { | |
4101 | cp_error ("jump to label `%D'", decl); | |
4102 | error_with_file_and_line (uses->filename_o_goto, | |
4103 | uses->lineno_o_goto, | |
4104 | " from here"); | |
4105 | identified = 1; | |
4106 | } | |
28cbf42c MS |
4107 | cp_error_at (" crosses initialization of `%#D'", |
4108 | new_decls); | |
8d08fdba MS |
4109 | } |
4110 | new_decls = TREE_CHAIN (new_decls); | |
4111 | } | |
e349ee73 | 4112 | if (b == uses->binding_level) |
8d08fdba MS |
4113 | break; |
4114 | b = b->level_chain; | |
4115 | } | |
4116 | ||
e349ee73 MS |
4117 | if (prev != NULL) |
4118 | prev->next = uses->next; | |
8d08fdba | 4119 | else |
e349ee73 MS |
4120 | named_label_uses = uses->next; |
4121 | ||
4122 | uses = uses->next; | |
4123 | } | |
4124 | else | |
4125 | { | |
4126 | prev = uses; | |
4127 | uses = uses->next; | |
8d08fdba MS |
4128 | } |
4129 | current_function_return_value = NULL_TREE; | |
4130 | return decl; | |
4131 | } | |
4132 | } | |
4133 | ||
a5894242 MS |
4134 | struct cp_switch |
4135 | { | |
4136 | struct binding_level *level; | |
4137 | struct cp_switch *next; | |
4138 | }; | |
4139 | ||
4140 | static struct cp_switch *switch_stack; | |
4141 | ||
4142 | void | |
4143 | push_switch () | |
4144 | { | |
4145 | struct cp_switch *p | |
4146 | = (struct cp_switch *) oballoc (sizeof (struct cp_switch)); | |
4147 | p->level = current_binding_level; | |
4148 | p->next = switch_stack; | |
4149 | switch_stack = p; | |
4150 | } | |
4151 | ||
4152 | void | |
4153 | pop_switch () | |
4154 | { | |
4155 | switch_stack = switch_stack->next; | |
4156 | } | |
4157 | ||
8d08fdba MS |
4158 | /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ |
4159 | /* XXX Note decl is never actually used. (bpk) */ | |
e92cc029 | 4160 | |
8d08fdba MS |
4161 | void |
4162 | define_case_label (decl) | |
4163 | tree decl; | |
4164 | { | |
4165 | tree cleanup = last_cleanup_this_contour (); | |
a5894242 MS |
4166 | struct binding_level *b = current_binding_level; |
4167 | int identified = 0; | |
4168 | ||
8d08fdba MS |
4169 | if (cleanup) |
4170 | { | |
4171 | static int explained = 0; | |
a5894242 MS |
4172 | cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup)); |
4173 | warning ("where case label appears here"); | |
8d08fdba MS |
4174 | if (!explained) |
4175 | { | |
a5894242 MS |
4176 | warning ("(enclose actions of previous case statements requiring"); |
4177 | warning ("destructors in their own binding contours.)"); | |
8d08fdba MS |
4178 | explained = 1; |
4179 | } | |
4180 | } | |
4181 | ||
a5894242 MS |
4182 | for (; b && b != switch_stack->level; b = b->level_chain) |
4183 | { | |
4184 | tree new_decls = b->names; | |
4185 | for (; new_decls; new_decls = TREE_CHAIN (new_decls)) | |
4186 | { | |
4187 | if (TREE_CODE (new_decls) == VAR_DECL | |
4188 | /* Don't complain about crossing initialization | |
4189 | of internal entities. They can't be accessed, | |
4190 | and they should be cleaned up | |
4191 | by the time we get to the label. */ | |
4192 | && ! DECL_ARTIFICIAL (new_decls) | |
4193 | && ((DECL_INITIAL (new_decls) != NULL_TREE | |
4194 | && DECL_INITIAL (new_decls) != error_mark_node) | |
4195 | || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) | |
4196 | { | |
4197 | if (! identified) | |
4198 | error ("jump to case label"); | |
4199 | identified = 1; | |
4200 | cp_error_at (" crosses initialization of `%#D'", | |
4201 | new_decls); | |
4202 | } | |
4203 | } | |
4204 | } | |
4205 | ||
8d08fdba MS |
4206 | /* After labels, make any new cleanups go into their |
4207 | own new (temporary) binding contour. */ | |
4208 | ||
4209 | current_binding_level->more_cleanups_ok = 0; | |
4210 | current_function_return_value = NULL_TREE; | |
4211 | } | |
4212 | \f | |
4213 | /* Return the list of declarations of the current level. | |
4214 | Note that this list is in reverse order unless/until | |
4215 | you nreverse it; and when you do nreverse it, you must | |
4216 | store the result back using `storedecls' or you will lose. */ | |
4217 | ||
4218 | tree | |
4219 | getdecls () | |
4220 | { | |
4221 | return current_binding_level->names; | |
4222 | } | |
4223 | ||
4224 | /* Return the list of type-tags (for structs, etc) of the current level. */ | |
4225 | ||
4226 | tree | |
4227 | gettags () | |
4228 | { | |
4229 | return current_binding_level->tags; | |
4230 | } | |
4231 | ||
4232 | /* Store the list of declarations of the current level. | |
4233 | This is done for the parameter declarations of a function being defined, | |
4234 | after they are modified in the light of any missing parameters. */ | |
4235 | ||
4236 | static void | |
4237 | storedecls (decls) | |
4238 | tree decls; | |
4239 | { | |
4240 | current_binding_level->names = decls; | |
4241 | } | |
4242 | ||
4243 | /* Similarly, store the list of tags of the current level. */ | |
4244 | ||
4245 | static void | |
4246 | storetags (tags) | |
4247 | tree tags; | |
4248 | { | |
4249 | current_binding_level->tags = tags; | |
4250 | } | |
4251 | \f | |
4252 | /* Given NAME, an IDENTIFIER_NODE, | |
4253 | return the structure (or union or enum) definition for that name. | |
4254 | Searches binding levels from BINDING_LEVEL up to the global level. | |
4255 | If THISLEVEL_ONLY is nonzero, searches only the specified context | |
4256 | (but skips any tag-transparent contexts to find one that is | |
4257 | meaningful for tags). | |
4258 | FORM says which kind of type the caller wants; | |
4259 | it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. | |
4260 | If the wrong kind of type is found, and it's not a template, an error is | |
4261 | reported. */ | |
4262 | ||
4263 | static tree | |
4264 | lookup_tag (form, name, binding_level, thislevel_only) | |
4265 | enum tree_code form; | |
8d08fdba | 4266 | tree name; |
cffa8729 | 4267 | struct binding_level *binding_level; |
8d08fdba MS |
4268 | int thislevel_only; |
4269 | { | |
4270 | register struct binding_level *level; | |
4271 | ||
4272 | for (level = binding_level; level; level = level->level_chain) | |
4273 | { | |
4274 | register tree tail; | |
4275 | if (ANON_AGGRNAME_P (name)) | |
4276 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
4277 | { | |
4278 | /* There's no need for error checking here, because | |
4279 | anon names are unique throughout the compilation. */ | |
4280 | if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name) | |
4281 | return TREE_VALUE (tail); | |
4282 | } | |
4283 | else | |
4284 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
4285 | { | |
a80e4195 | 4286 | if (TREE_PURPOSE (tail) == name) |
8d08fdba MS |
4287 | { |
4288 | enum tree_code code = TREE_CODE (TREE_VALUE (tail)); | |
4289 | /* Should tighten this up; it'll probably permit | |
4290 | UNION_TYPE and a struct template, for example. */ | |
4291 | if (code != form | |
5566b478 | 4292 | && !(form != ENUMERAL_TYPE && code == TEMPLATE_DECL)) |
8d08fdba MS |
4293 | { |
4294 | /* Definition isn't the kind we were looking for. */ | |
4295 | cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail), | |
4296 | form); | |
72b7eeff | 4297 | return NULL_TREE; |
8d08fdba MS |
4298 | } |
4299 | return TREE_VALUE (tail); | |
4300 | } | |
4301 | } | |
4302 | if (thislevel_only && ! level->tag_transparent) | |
5566b478 MS |
4303 | { |
4304 | if (level->pseudo_global) | |
4305 | { | |
30394414 JM |
4306 | /* XXX MvL */ |
4307 | tree t = IDENTIFIER_NAMESPACE_VALUE (name); | |
5566b478 MS |
4308 | if (t && TREE_CODE (t) == TEMPLATE_DECL |
4309 | && TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL) | |
4310 | return TREE_TYPE (t); | |
4311 | } | |
4312 | return NULL_TREE; | |
4313 | } | |
8d08fdba MS |
4314 | if (current_class_type && level->level_chain == global_binding_level) |
4315 | { | |
4316 | /* Try looking in this class's tags before heading into | |
4317 | global binding level. */ | |
4318 | tree context = current_class_type; | |
4319 | while (context) | |
4320 | { | |
4321 | switch (TREE_CODE_CLASS (TREE_CODE (context))) | |
4322 | { | |
4323 | tree these_tags; | |
4324 | case 't': | |
4325 | these_tags = CLASSTYPE_TAGS (context); | |
4326 | if (ANON_AGGRNAME_P (name)) | |
4327 | while (these_tags) | |
4328 | { | |
4329 | if (TYPE_IDENTIFIER (TREE_VALUE (these_tags)) | |
4330 | == name) | |
4331 | return TREE_VALUE (tail); | |
4332 | these_tags = TREE_CHAIN (these_tags); | |
4333 | } | |
4334 | else | |
4335 | while (these_tags) | |
4336 | { | |
4337 | if (TREE_PURPOSE (these_tags) == name) | |
4338 | { | |
4339 | if (TREE_CODE (TREE_VALUE (these_tags)) != form) | |
4340 | { | |
4341 | cp_error ("`%#D' redeclared as %C in class scope", | |
4342 | TREE_VALUE (tail), form); | |
72b7eeff | 4343 | return NULL_TREE; |
8d08fdba MS |
4344 | } |
4345 | return TREE_VALUE (tail); | |
4346 | } | |
4347 | these_tags = TREE_CHAIN (these_tags); | |
4348 | } | |
4349 | /* If this type is not yet complete, then don't | |
4350 | look at its context. */ | |
4351 | if (TYPE_SIZE (context) == NULL_TREE) | |
4352 | goto no_context; | |
4353 | /* Go to next enclosing type, if any. */ | |
d2e5ee5c | 4354 | context = DECL_CONTEXT (TYPE_MAIN_DECL (context)); |
8d08fdba MS |
4355 | break; |
4356 | case 'd': | |
4357 | context = DECL_CONTEXT (context); | |
4358 | break; | |
4359 | default: | |
4360 | my_friendly_abort (10); | |
4361 | } | |
4362 | continue; | |
4363 | no_context: | |
4364 | break; | |
4365 | } | |
4366 | } | |
4367 | } | |
4368 | return NULL_TREE; | |
4369 | } | |
4370 | ||
bd6dd845 | 4371 | #if 0 |
8d08fdba MS |
4372 | void |
4373 | set_current_level_tags_transparency (tags_transparent) | |
4374 | int tags_transparent; | |
4375 | { | |
4376 | current_binding_level->tag_transparent = tags_transparent; | |
4377 | } | |
bd6dd845 | 4378 | #endif |
8d08fdba MS |
4379 | |
4380 | /* Given a type, find the tag that was defined for it and return the tag name. | |
4381 | Otherwise return 0. However, the value can never be 0 | |
4382 | in the cases in which this is used. | |
4383 | ||
4384 | C++: If NAME is non-zero, this is the new name to install. This is | |
4385 | done when replacing anonymous tags with real tag names. */ | |
4386 | ||
4387 | static tree | |
4388 | lookup_tag_reverse (type, name) | |
4389 | tree type; | |
4390 | tree name; | |
4391 | { | |
4392 | register struct binding_level *level; | |
4393 | ||
4394 | for (level = current_binding_level; level; level = level->level_chain) | |
4395 | { | |
4396 | register tree tail; | |
4397 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
4398 | { | |
4399 | if (TREE_VALUE (tail) == type) | |
4400 | { | |
4401 | if (name) | |
4402 | TREE_PURPOSE (tail) = name; | |
4403 | return TREE_PURPOSE (tail); | |
4404 | } | |
4405 | } | |
4406 | } | |
4407 | return NULL_TREE; | |
4408 | } | |
8d08fdba MS |
4409 | \f |
4410 | /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). | |
4411 | Return the type value, or NULL_TREE if not found. */ | |
e92cc029 | 4412 | |
8d08fdba MS |
4413 | static tree |
4414 | lookup_nested_type (type, context) | |
4415 | tree type; | |
4416 | tree context; | |
4417 | { | |
4418 | if (context == NULL_TREE) | |
4419 | return NULL_TREE; | |
4420 | while (context) | |
4421 | { | |
4422 | switch (TREE_CODE (context)) | |
4423 | { | |
4424 | case TYPE_DECL: | |
4425 | { | |
4426 | tree ctype = TREE_TYPE (context); | |
4427 | tree match = value_member (type, CLASSTYPE_TAGS (ctype)); | |
4428 | if (match) | |
4429 | return TREE_VALUE (match); | |
4430 | context = DECL_CONTEXT (context); | |
4431 | ||
4432 | /* When we have a nested class whose member functions have | |
4433 | local types (e.g., a set of enums), we'll arrive here | |
4434 | with the DECL_CONTEXT as the actual RECORD_TYPE node for | |
4435 | the enclosing class. Instead, we want to make sure we | |
4436 | come back in here with the TYPE_DECL, not the RECORD_TYPE. */ | |
4437 | if (context && TREE_CODE (context) == RECORD_TYPE) | |
4438 | context = TREE_CHAIN (context); | |
4439 | } | |
4440 | break; | |
4441 | case FUNCTION_DECL: | |
e1cd6e56 MS |
4442 | if (TYPE_NAME (type) && TYPE_IDENTIFIER (type)) |
4443 | return lookup_name (TYPE_IDENTIFIER (type), 1); | |
4444 | return NULL_TREE; | |
8d08fdba MS |
4445 | default: |
4446 | my_friendly_abort (12); | |
4447 | } | |
4448 | } | |
4449 | return NULL_TREE; | |
4450 | } | |
4451 | ||
a9aedbc2 | 4452 | /* Look up NAME in the NAMESPACE. */ |
e92cc029 | 4453 | |
a9aedbc2 MS |
4454 | tree |
4455 | lookup_namespace_name (namespace, name) | |
4456 | tree namespace, name; | |
4457 | { | |
30394414 JM |
4458 | #if 1 |
4459 | tree val; | |
4460 | my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 370); | |
4461 | my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 373); | |
4462 | ||
4463 | val = qualified_lookup_using_namespace (name, namespace); | |
4464 | if (val) | |
4465 | return val; | |
4466 | cp_error ("`%D' undeclared in namespace `%D'", name, namespace); | |
4467 | return error_mark_node; | |
4468 | #else | |
a9aedbc2 | 4469 | struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace); |
fc378698 | 4470 | tree x = NULL_TREE; |
fc378698 MS |
4471 | #if 1 |
4472 | /* This searches just one level. */ | |
4473 | if (b) | |
a9aedbc2 MS |
4474 | { |
4475 | for (x = b->names; x; x = TREE_CHAIN (x)) | |
4476 | if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name) | |
4477 | break; | |
a9aedbc2 | 4478 | } |
fc378698 MS |
4479 | #else |
4480 | /* This searches all levels. */ | |
4481 | for (; b && !x; b = b->level_chain) | |
4482 | { | |
4483 | for (x = b->names; x; x = TREE_CHAIN (x)) | |
4484 | if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name) | |
4485 | break; | |
4486 | } | |
4487 | #endif | |
a9aedbc2 | 4488 | return x; |
30394414 | 4489 | #endif |
a9aedbc2 MS |
4490 | } |
4491 | ||
5566b478 MS |
4492 | tree |
4493 | make_typename_type (context, name) | |
4494 | tree context, name; | |
4495 | { | |
a80e4195 | 4496 | tree t, d; |
b2b7d40a | 4497 | tree fullname; |
a80e4195 | 4498 | |
653cc74a JM |
4499 | if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') |
4500 | name = TYPE_IDENTIFIER (name); | |
4501 | else if (TREE_CODE (name) == TYPE_DECL) | |
a80e4195 | 4502 | name = DECL_NAME (name); |
b2b7d40a JM |
4503 | |
4504 | fullname = name; | |
4505 | ||
4506 | if (TREE_CODE (name) == TEMPLATE_ID_EXPR) | |
11686454 JM |
4507 | { |
4508 | name = TREE_OPERAND (name, 0); | |
4509 | if (TREE_CODE (name) == TEMPLATE_DECL) | |
4510 | name = TREE_OPERAND (fullname, 0) = DECL_NAME (name); | |
4511 | } | |
b2b7d40a | 4512 | if (TREE_CODE (name) != IDENTIFIER_NODE) |
a80e4195 | 4513 | my_friendly_abort (2000); |
5566b478 | 4514 | |
85b71cf2 | 4515 | if (! uses_template_parms (context) |
7fcdf4c2 | 4516 | || context == current_class_type) |
5566b478 | 4517 | { |
b2b7d40a JM |
4518 | if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR) |
4519 | { | |
4520 | if (IS_AGGR_TYPE (context)) | |
4521 | t = lookup_field (context, name, 0, 0); | |
4522 | else | |
4523 | t = NULL_TREE; | |
4524 | ||
4525 | if (t == NULL_TREE || TREE_CODE (t) != TEMPLATE_DECL | |
4526 | || TREE_CODE (DECL_RESULT (t)) != TYPE_DECL) | |
4527 | { | |
4528 | cp_error ("no class template named `%#T' in `%#T'", | |
4529 | name, context); | |
4530 | return error_mark_node; | |
4531 | } | |
ffb690bd | 4532 | |
b2b7d40a JM |
4533 | return lookup_template_class (t, TREE_OPERAND (fullname, 1), |
4534 | NULL_TREE, context); | |
4535 | } | |
4536 | else | |
5566b478 | 4537 | { |
b2b7d40a JM |
4538 | if (IS_AGGR_TYPE (context)) |
4539 | t = lookup_field (context, name, 0, 1); | |
4540 | else | |
4541 | t = NULL_TREE; | |
4542 | ||
4543 | if (t == NULL_TREE) | |
4544 | { | |
4545 | cp_error ("no type named `%#T' in `%#T'", name, context); | |
4546 | return error_mark_node; | |
4547 | } | |
1107c4b3 | 4548 | |
b2b7d40a | 4549 | return TREE_TYPE (t); |
5566b478 | 4550 | } |
5566b478 MS |
4551 | } |
4552 | ||
5156628f | 4553 | if (processing_template_decl) |
5566b478 MS |
4554 | push_obstacks (&permanent_obstack, &permanent_obstack); |
4555 | t = make_lang_type (TYPENAME_TYPE); | |
b2b7d40a | 4556 | TYPENAME_TYPE_FULLNAME (t) = fullname; |
5566b478 | 4557 | d = build_decl (TYPE_DECL, name, t); |
5156628f | 4558 | if (processing_template_decl) |
5566b478 MS |
4559 | pop_obstacks (); |
4560 | ||
4561 | TYPE_CONTEXT (t) = context; | |
d2e5ee5c MS |
4562 | TYPE_NAME (TREE_TYPE (d)) = d; |
4563 | TYPE_STUB_DECL (TREE_TYPE (d)) = d; | |
5566b478 | 4564 | DECL_CONTEXT (d) = context; |
7fcdf4c2 | 4565 | CLASSTYPE_GOT_SEMICOLON (t) = 1; |
5566b478 MS |
4566 | |
4567 | return t; | |
4568 | } | |
4569 | ||
8d08fdba MS |
4570 | /* Look up NAME in the current binding level and its superiors in the |
4571 | namespace of variables, functions and typedefs. Return a ..._DECL | |
4572 | node of some kind representing its definition if there is only one | |
4573 | such declaration, or return a TREE_LIST with all the overloaded | |
4574 | definitions if there are many, or return 0 if it is undefined. | |
4575 | ||
4576 | If PREFER_TYPE is > 0, we prefer TYPE_DECLs. | |
a28e3c7f | 4577 | If PREFER_TYPE is -2, we're being called from yylex(). (UGLY) |
f84b4be9 JM |
4578 | Otherwise we prefer non-TYPE_DECLs. |
4579 | ||
4580 | If NONCLASS is non-zero, we don't look for the NAME in class scope, | |
4581 | using IDENTIFIER_CLASS_VALUE. */ | |
8d08fdba | 4582 | |
824b9a4c | 4583 | static tree |
700f8a87 | 4584 | lookup_name_real (name, prefer_type, nonclass) |
8d08fdba | 4585 | tree name; |
700f8a87 | 4586 | int prefer_type, nonclass; |
8d08fdba MS |
4587 | { |
4588 | register tree val; | |
a28e3c7f | 4589 | int yylex = 0; |
e1cd6e56 | 4590 | tree from_obj = NULL_TREE; |
e76a2646 | 4591 | tree locval, classval; |
8d08fdba | 4592 | |
a28e3c7f MS |
4593 | if (prefer_type == -2) |
4594 | { | |
4595 | extern int looking_for_typename; | |
fc378698 | 4596 | tree type = NULL_TREE; |
a28e3c7f MS |
4597 | |
4598 | yylex = 1; | |
4599 | prefer_type = looking_for_typename; | |
e1cd6e56 | 4600 | |
653cc74a JM |
4601 | /* std:: becomes :: for now. */ |
4602 | if (got_scope == std_node) | |
4603 | got_scope = void_type_node; | |
4604 | ||
e1cd6e56 MS |
4605 | if (got_scope) |
4606 | type = got_scope; | |
dff6b454 | 4607 | else if (got_object != error_mark_node) |
e1cd6e56 | 4608 | type = got_object; |
a28e3c7f | 4609 | |
e1cd6e56 | 4610 | if (type) |
a28e3c7f | 4611 | { |
e1cd6e56 | 4612 | if (type == error_mark_node) |
f376e137 | 4613 | return error_mark_node; |
a80e4195 MS |
4614 | if (TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type)) |
4615 | type = TREE_TYPE (type); | |
5566b478 MS |
4616 | |
4617 | type = complete_type (type); | |
4618 | ||
4619 | if (type == void_type_node) | |
a28e3c7f | 4620 | val = IDENTIFIER_GLOBAL_VALUE (name); |
a9aedbc2 MS |
4621 | else if (TREE_CODE (type) == NAMESPACE_DECL) |
4622 | { | |
30394414 | 4623 | val = NAMESPACE_BINDING (name, type); |
a9aedbc2 | 4624 | } |
5566b478 | 4625 | else if (! IS_AGGR_TYPE (type) |
5156628f | 4626 | || TREE_CODE (type) == TEMPLATE_TYPE_PARM |
73b0fce8 | 4627 | || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM |
5156628f | 4628 | || TREE_CODE (type) == TYPENAME_TYPE) |
e92cc029 | 4629 | /* Someone else will give an error about this if needed. */ |
a28e3c7f | 4630 | val = NULL_TREE; |
e1cd6e56 | 4631 | else if (TYPE_BEING_DEFINED (type)) |
700f8a87 MS |
4632 | { |
4633 | val = IDENTIFIER_CLASS_VALUE (name); | |
e1cd6e56 | 4634 | if (val && DECL_CONTEXT (val) != type) |
700f8a87 MS |
4635 | { |
4636 | struct binding_level *b = class_binding_level; | |
4637 | for (val = NULL_TREE; b; b = b->level_chain) | |
4638 | { | |
4639 | tree t = purpose_member (name, b->class_shadowed); | |
4640 | if (t && TREE_VALUE (t) | |
e1cd6e56 | 4641 | && DECL_CONTEXT (TREE_VALUE (t)) == type) |
700f8a87 MS |
4642 | { |
4643 | val = TREE_VALUE (t); | |
4644 | break; | |
4645 | } | |
4646 | } | |
4647 | } | |
5566b478 | 4648 | if (val == NULL_TREE) |
e1cd6e56 | 4649 | val = lookup_field (type, name, 0, 1); |
700f8a87 | 4650 | } |
e1cd6e56 | 4651 | else if (type == current_class_type) |
a28e3c7f | 4652 | val = IDENTIFIER_CLASS_VALUE (name); |
a28e3c7f | 4653 | else |
e1cd6e56 | 4654 | val = lookup_field (type, name, 0, prefer_type); |
a28e3c7f | 4655 | } |
e1cd6e56 MS |
4656 | else |
4657 | val = NULL_TREE; | |
4658 | ||
594740f3 | 4659 | if (got_scope) |
e1cd6e56 | 4660 | goto done; |
594740f3 | 4661 | else if (got_object && val) |
e1cd6e56 | 4662 | from_obj = val; |
a28e3c7f | 4663 | } |
e76a2646 MS |
4664 | |
4665 | locval = classval = NULL_TREE; | |
4666 | ||
8d08fdba MS |
4667 | if (current_binding_level != global_binding_level |
4668 | && IDENTIFIER_LOCAL_VALUE (name)) | |
e76a2646 MS |
4669 | locval = IDENTIFIER_LOCAL_VALUE (name); |
4670 | ||
8d08fdba MS |
4671 | /* In C++ class fields are between local and global scope, |
4672 | just before the global scope. */ | |
e76a2646 | 4673 | if (current_class_type && ! nonclass) |
8d08fdba | 4674 | { |
e76a2646 MS |
4675 | classval = IDENTIFIER_CLASS_VALUE (name); |
4676 | if (classval == NULL_TREE && TYPE_BEING_DEFINED (current_class_type)) | |
700f8a87 MS |
4677 | /* Try to find values from base classes if we are presently |
4678 | defining a type. We are presently only interested in | |
4679 | TYPE_DECLs. */ | |
e76a2646 | 4680 | classval = lookup_field (current_class_type, name, 0, 1); |
8d08fdba MS |
4681 | |
4682 | /* yylex() calls this with -2, since we should never start digging for | |
4683 | the nested name at the point where we haven't even, for example, | |
4684 | created the COMPONENT_REF or anything like that. */ | |
e76a2646 MS |
4685 | if (classval == NULL_TREE) |
4686 | classval = lookup_nested_field (name, ! yylex); | |
85b71cf2 | 4687 | |
b3709d9b JM |
4688 | /* Add implicit 'typename' to types from template bases. lookup_field |
4689 | will do this for us. */ | |
85b71cf2 JM |
4690 | if (processing_template_decl |
4691 | && classval && TREE_CODE (classval) == TYPE_DECL | |
4692 | && DECL_CONTEXT (classval) != current_class_type | |
b3709d9b | 4693 | && uses_template_parms (current_class_type) |
85b71cf2 | 4694 | && ! DECL_ARTIFICIAL (classval)) |
b3709d9b | 4695 | classval = lookup_field (current_class_type, name, 0, 1); |
e76a2646 | 4696 | } |
8d08fdba | 4697 | |
e76a2646 MS |
4698 | if (locval && classval) |
4699 | { | |
4700 | if (current_scope () == current_function_decl | |
4701 | && ! hack_decl_function_context (current_function_decl)) | |
4702 | /* Not in a nested function. */ | |
4703 | val = locval; | |
4704 | else | |
4705 | { | |
4706 | /* This is incredibly horrible. The whole concept of | |
4707 | IDENTIFIER_LOCAL_VALUE / IDENTIFIER_CLASS_VALUE / | |
4708 | IDENTIFIER_GLOBAL_VALUE needs to be scrapped for local | |
4709 | classes. */ | |
4710 | tree lctx = hack_decl_function_context (locval); | |
4711 | tree cctx = hack_decl_function_context (classval); | |
4712 | ||
4713 | if (lctx == current_scope ()) | |
4714 | val = locval; | |
4715 | else if (lctx == cctx) | |
4716 | val = classval; | |
4717 | else | |
4718 | /* I don't know which is right; let's just guess for now. */ | |
4719 | val = locval; | |
4720 | } | |
8d08fdba | 4721 | } |
e76a2646 MS |
4722 | else if (locval) |
4723 | val = locval; | |
4724 | else if (classval) | |
4725 | val = classval; | |
8d08fdba | 4726 | else |
30394414 JM |
4727 | { |
4728 | /* unscoped lookup of a global, iterate over namespaces, | |
4729 | considering using namespace statements */ | |
4730 | tree binding; | |
4731 | tree scope = current_namespace; | |
4732 | do | |
4733 | { | |
4734 | binding = binding_for_name (name, scope); | |
4735 | val = BINDING_VALUE (binding); | |
4736 | val = lookup_using_namespace (name, val, current_namespace, scope); | |
4737 | if (scope == global_namespace) | |
4738 | break; | |
4739 | scope = DECL_NAMESPACE (scope); | |
4740 | } | |
4741 | while (!val); | |
4742 | } | |
8d08fdba | 4743 | |
a28e3c7f | 4744 | done: |
8d08fdba MS |
4745 | if (val) |
4746 | { | |
c91a56d2 | 4747 | /* This should only warn about types used in qualified-ids. */ |
e1cd6e56 | 4748 | if (from_obj && from_obj != val) |
5566b478 | 4749 | { |
c91a56d2 MS |
4750 | if (looking_for_typename && TREE_CODE (from_obj) == TYPE_DECL |
4751 | && TREE_CODE (val) == TYPE_DECL | |
4752 | && TREE_TYPE (from_obj) != TREE_TYPE (val)) | |
4753 | { | |
4754 | cp_pedwarn ("lookup of `%D' in the scope of `%#T' (`%#T')", | |
4755 | name, got_object, TREE_TYPE (from_obj)); | |
4756 | cp_pedwarn (" does not match lookup in the current scope (`%#T')", | |
4757 | TREE_TYPE (val)); | |
4758 | } | |
594740f3 MS |
4759 | |
4760 | val = from_obj; | |
5566b478 | 4761 | } |
e1cd6e56 | 4762 | |
cf776105 | 4763 | if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template) |
a0a33927 | 4764 | || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0) |
e1cd6e56 MS |
4765 | ; |
4766 | else if (IDENTIFIER_HAS_TYPE_VALUE (name)) | |
d2e5ee5c | 4767 | val = TYPE_MAIN_DECL (IDENTIFIER_TYPE_VALUE (name)); |
e1cd6e56 MS |
4768 | else if (TREE_TYPE (val) == error_mark_node) |
4769 | val = error_mark_node; | |
8d08fdba | 4770 | } |
e1cd6e56 MS |
4771 | else if (from_obj) |
4772 | val = from_obj; | |
8d08fdba MS |
4773 | |
4774 | return val; | |
4775 | } | |
4776 | ||
700f8a87 MS |
4777 | tree |
4778 | lookup_name_nonclass (name) | |
4779 | tree name; | |
4780 | { | |
4781 | return lookup_name_real (name, 0, 1); | |
4782 | } | |
4783 | ||
4784 | tree | |
4785 | lookup_name (name, prefer_type) | |
4786 | tree name; | |
4787 | int prefer_type; | |
4788 | { | |
4789 | return lookup_name_real (name, prefer_type, 0); | |
4790 | } | |
4791 | ||
8d08fdba MS |
4792 | /* Similar to `lookup_name' but look only at current binding level. */ |
4793 | ||
4794 | tree | |
4795 | lookup_name_current_level (name) | |
4796 | tree name; | |
4797 | { | |
4798 | register tree t = NULL_TREE; | |
4799 | ||
4800 | if (current_binding_level == global_binding_level) | |
4801 | { | |
30394414 | 4802 | t = IDENTIFIER_NAMESPACE_VALUE (name); |
8d08fdba MS |
4803 | |
4804 | /* extern "C" function() */ | |
4805 | if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST) | |
4806 | t = TREE_VALUE (t); | |
4807 | } | |
4808 | else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE) | |
4809 | { | |
a4443a08 MS |
4810 | struct binding_level *b = current_binding_level; |
4811 | while (1) | |
4812 | { | |
4813 | for (t = b->names; t; t = TREE_CHAIN (t)) | |
e1cd6e56 | 4814 | if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name) |
a4443a08 MS |
4815 | goto out; |
4816 | if (b->keep == 2) | |
4817 | b = b->level_chain; | |
4818 | else | |
4819 | break; | |
4820 | } | |
4821 | out: | |
4822 | ; | |
8d08fdba MS |
4823 | } |
4824 | ||
4825 | return t; | |
4826 | } | |
4827 | \f | |
4828 | /* Arrange for the user to get a source line number, even when the | |
4829 | compiler is going down in flames, so that she at least has a | |
4830 | chance of working around problems in the compiler. We used to | |
4831 | call error(), but that let the segmentation fault continue | |
4832 | through; now, it's much more passive by asking them to send the | |
4833 | maintainers mail about the problem. */ | |
4834 | ||
4835 | static void | |
4836 | signal_catch (sig) | |
4837 | int sig; | |
4838 | { | |
4839 | signal (SIGSEGV, SIG_DFL); | |
4840 | #ifdef SIGIOT | |
4841 | signal (SIGIOT, SIG_DFL); | |
4842 | #endif | |
4843 | #ifdef SIGILL | |
4844 | signal (SIGILL, SIG_DFL); | |
4845 | #endif | |
4846 | #ifdef SIGABRT | |
4847 | signal (SIGABRT, SIG_DFL); | |
4848 | #endif | |
4849 | #ifdef SIGBUS | |
4850 | signal (SIGBUS, SIG_DFL); | |
4851 | #endif | |
4852 | my_friendly_abort (0); | |
4853 | } | |
4854 | ||
de22184b MS |
4855 | #if 0 |
4856 | /* Unused -- brendan 970107 */ | |
8d08fdba MS |
4857 | /* Array for holding types considered "built-in". These types |
4858 | are output in the module in which `main' is defined. */ | |
4859 | static tree *builtin_type_tdescs_arr; | |
4860 | static int builtin_type_tdescs_len, builtin_type_tdescs_max; | |
de22184b | 4861 | #endif |
8d08fdba MS |
4862 | |
4863 | /* Push the declarations of builtin types into the namespace. | |
4864 | RID_INDEX, if < RID_MAX is the index of the builtin type | |
4865 | in the array RID_POINTERS. NAME is the name used when looking | |
4866 | up the builtin type. TYPE is the _TYPE node for the builtin type. */ | |
4867 | ||
4868 | static void | |
4869 | record_builtin_type (rid_index, name, type) | |
4870 | enum rid rid_index; | |
4871 | char *name; | |
4872 | tree type; | |
4873 | { | |
4874 | tree rname = NULL_TREE, tname = NULL_TREE; | |
a703fb38 | 4875 | tree tdecl = NULL_TREE; |
8d08fdba MS |
4876 | |
4877 | if ((int) rid_index < (int) RID_MAX) | |
4878 | rname = ridpointers[(int) rid_index]; | |
4879 | if (name) | |
4880 | tname = get_identifier (name); | |
4881 | ||
4882 | TYPE_BUILT_IN (type) = 1; | |
4883 | ||
4884 | if (tname) | |
4885 | { | |
8d08fdba | 4886 | tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); |
8d08fdba MS |
4887 | set_identifier_type_value (tname, NULL_TREE); |
4888 | if ((int) rid_index < (int) RID_MAX) | |
30394414 | 4889 | /* builtin types live in the global namespace */ |
8d08fdba MS |
4890 | IDENTIFIER_GLOBAL_VALUE (tname) = tdecl; |
4891 | } | |
4892 | if (rname != NULL_TREE) | |
4893 | { | |
4894 | if (tname != NULL_TREE) | |
4895 | { | |
4896 | set_identifier_type_value (rname, NULL_TREE); | |
4897 | IDENTIFIER_GLOBAL_VALUE (rname) = tdecl; | |
4898 | } | |
4899 | else | |
4900 | { | |
8d08fdba | 4901 | tdecl = pushdecl (build_decl (TYPE_DECL, rname, type)); |
8d08fdba MS |
4902 | set_identifier_type_value (rname, NULL_TREE); |
4903 | } | |
4904 | } | |
8d08fdba MS |
4905 | } |
4906 | ||
8d08fdba MS |
4907 | /* Push overloaded decl, in global scope, with one argument so it |
4908 | can be used as a callback from define_function. */ | |
e92cc029 | 4909 | |
8d08fdba MS |
4910 | static void |
4911 | push_overloaded_decl_1 (x) | |
4912 | tree x; | |
4913 | { | |
4914 | push_overloaded_decl (x, 0); | |
4915 | } | |
4916 | ||
8ccc31eb MS |
4917 | #ifdef __GNUC__ |
4918 | __inline | |
4919 | #endif | |
6b5fbb55 MS |
4920 | tree |
4921 | auto_function (name, type, code) | |
8ccc31eb MS |
4922 | tree name, type; |
4923 | enum built_in_function code; | |
4924 | { | |
4925 | return define_function | |
49c249e1 | 4926 | (IDENTIFIER_POINTER (name), type, code, push_overloaded_decl_1, |
8ccc31eb MS |
4927 | IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type), |
4928 | 0))); | |
4929 | } | |
4930 | ||
8d08fdba MS |
4931 | /* Create the predefined scalar types of C, |
4932 | and some nodes representing standard constants (0, 1, (void *)0). | |
4933 | Initialize the global binding level. | |
4934 | Make definitions for built-in primitive functions. */ | |
4935 | ||
4936 | void | |
4937 | init_decl_processing () | |
4938 | { | |
4939 | tree decl; | |
de22184b | 4940 | register tree endlink, int_endlink, double_endlink, unsigned_endlink; |
8d08fdba | 4941 | tree fields[20]; |
8d08fdba | 4942 | /* Data type of memcpy. */ |
cffa8729 | 4943 | tree memcpy_ftype, strlen_ftype; |
8d08fdba MS |
4944 | int wchar_type_size; |
4945 | tree temp; | |
4946 | tree array_domain_type; | |
e1cd6e56 | 4947 | extern int flag_strict_prototype; |
a703fb38 | 4948 | tree vb_off_identifier = NULL_TREE; |
5566b478 MS |
4949 | /* Function type `char *(char *, char *)' and similar ones */ |
4950 | tree string_ftype_ptr_ptr, int_ftype_string_string; | |
de22184b MS |
4951 | tree sizetype_endlink; |
4952 | tree ptr_ftype, ptr_ftype_unsigned, ptr_ftype_sizetype; | |
ca55abae | 4953 | tree void_ftype, void_ftype_int, void_ftype_ptr, ptr_ftype_void; |
8d08fdba MS |
4954 | |
4955 | /* Have to make these distinct before we try using them. */ | |
4956 | lang_name_cplusplus = get_identifier ("C++"); | |
4957 | lang_name_c = get_identifier ("C"); | |
4958 | ||
30394414 JM |
4959 | /* enter the global namespace */ |
4960 | my_friendly_assert (global_namespace == NULL_TREE, 375); | |
4961 | my_friendly_assert (current_lang_name == NULL_TREE, 375); | |
4962 | current_lang_name = lang_name_cplusplus; | |
4963 | push_namespace (get_identifier ("::")); | |
4964 | global_namespace = current_namespace; | |
4965 | current_lang_name = NULL_TREE; | |
4966 | ||
e1cd6e56 MS |
4967 | if (flag_strict_prototype == 2) |
4968 | { | |
4969 | if (pedantic) | |
4970 | strict_prototypes_lang_c = strict_prototypes_lang_cplusplus; | |
4971 | } | |
4972 | else | |
4973 | strict_prototypes_lang_c = flag_strict_prototype; | |
8926095f | 4974 | |
8d08fdba MS |
4975 | /* Initially, C. */ |
4976 | current_lang_name = lang_name_c; | |
4977 | ||
4978 | current_function_decl = NULL_TREE; | |
4979 | named_labels = NULL_TREE; | |
e349ee73 | 4980 | named_label_uses = NULL; |
8d08fdba MS |
4981 | current_binding_level = NULL_BINDING_LEVEL; |
4982 | free_binding_level = NULL_BINDING_LEVEL; | |
4983 | ||
42976354 | 4984 | #ifndef __CYGWIN32__ |
8d08fdba MS |
4985 | /* Because most segmentation signals can be traced back into user |
4986 | code, catch them and at least give the user a chance of working | |
e92cc029 | 4987 | around compiler bugs. */ |
8d08fdba MS |
4988 | signal (SIGSEGV, signal_catch); |
4989 | ||
4990 | /* We will also catch aborts in the back-end through signal_catch and | |
4991 | give the user a chance to see where the error might be, and to defeat | |
4992 | aborts in the back-end when there have been errors previously in their | |
e92cc029 | 4993 | code. */ |
8d08fdba MS |
4994 | #ifdef SIGIOT |
4995 | signal (SIGIOT, signal_catch); | |
4996 | #endif | |
4997 | #ifdef SIGILL | |
4998 | signal (SIGILL, signal_catch); | |
4999 | #endif | |
5000 | #ifdef SIGABRT | |
5001 | signal (SIGABRT, signal_catch); | |
5002 | #endif | |
5003 | #ifdef SIGBUS | |
5004 | signal (SIGBUS, signal_catch); | |
5005 | #endif | |
7834ab39 MS |
5006 | #else /* ndef __CYGWIN32__ */ |
5007 | /* Cygwin32 cannot handle catching signals other than | |
5008 | SIGABRT yet. We hope this will cease to be the case soon. */ | |
5009 | #ifdef SIGABRT | |
5010 | signal (SIGABRT, signal_catch); | |
5011 | #endif | |
5012 | #endif /* ndef __CYGWIN32__ */ | |
8d08fdba MS |
5013 | |
5014 | gcc_obstack_init (&decl_obstack); | |
8d08fdba MS |
5015 | |
5016 | /* Must lay these out before anything else gets laid out. */ | |
5017 | error_mark_node = make_node (ERROR_MARK); | |
5018 | TREE_PERMANENT (error_mark_node) = 1; | |
5019 | TREE_TYPE (error_mark_node) = error_mark_node; | |
5020 | error_mark_list = build_tree_list (error_mark_node, error_mark_node); | |
5021 | TREE_TYPE (error_mark_list) = error_mark_node; | |
5022 | ||
a28e3c7f MS |
5023 | /* Make the binding_level structure for global names. */ |
5024 | pushlevel (0); | |
8d08fdba MS |
5025 | global_binding_level = current_binding_level; |
5026 | ||
5027 | this_identifier = get_identifier (THIS_NAME); | |
5028 | in_charge_identifier = get_identifier (IN_CHARGE_NAME); | |
fc378698 MS |
5029 | ctor_identifier = get_identifier (CTOR_NAME); |
5030 | dtor_identifier = get_identifier (DTOR_NAME); | |
8d08fdba MS |
5031 | pfn_identifier = get_identifier (VTABLE_PFN_NAME); |
5032 | index_identifier = get_identifier (VTABLE_INDEX_NAME); | |
5033 | delta_identifier = get_identifier (VTABLE_DELTA_NAME); | |
5034 | delta2_identifier = get_identifier (VTABLE_DELTA2_NAME); | |
5035 | pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2"); | |
dff6b454 RK |
5036 | if (flag_handle_signatures) |
5037 | { | |
5038 | tag_identifier = get_identifier (SIGTABLE_TAG_NAME); | |
9dd70aa4 GB |
5039 | vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME); |
5040 | vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME); | |
dff6b454 | 5041 | } |
8d08fdba MS |
5042 | |
5043 | /* Define `int' and `char' first so that dbx will output them first. */ | |
5044 | ||
5045 | integer_type_node = make_signed_type (INT_TYPE_SIZE); | |
5046 | record_builtin_type (RID_INT, NULL_PTR, integer_type_node); | |
5047 | ||
5048 | /* Define `char', which is like either `signed char' or `unsigned char' | |
5049 | but not the same as either. */ | |
5050 | ||
beb53fb8 JM |
5051 | char_type_node |
5052 | = (flag_signed_char | |
5053 | ? make_signed_type (CHAR_TYPE_SIZE) | |
5054 | : make_unsigned_type (CHAR_TYPE_SIZE)); | |
8d08fdba MS |
5055 | record_builtin_type (RID_CHAR, "char", char_type_node); |
5056 | ||
5057 | long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); | |
5058 | record_builtin_type (RID_LONG, "long int", long_integer_type_node); | |
5059 | ||
5060 | unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); | |
5061 | record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); | |
5062 | ||
5063 | long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); | |
5064 | record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node); | |
5065 | record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); | |
5066 | ||
5067 | long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); | |
5068 | record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node); | |
5069 | ||
5070 | long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); | |
5071 | record_builtin_type (RID_MAX, "long long unsigned int", | |
5072 | long_long_unsigned_type_node); | |
5073 | record_builtin_type (RID_MAX, "long long unsigned", | |
5074 | long_long_unsigned_type_node); | |
5075 | ||
5156628f MS |
5076 | short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); |
5077 | record_builtin_type (RID_SHORT, "short int", short_integer_type_node); | |
5078 | short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); | |
5079 | record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); | |
5080 | record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); | |
5081 | ||
8d08fdba | 5082 | /* `unsigned long' is the standard type for sizeof. |
8d08fdba | 5083 | Note that stddef.h uses `unsigned long', |
f5426d1e R |
5084 | and this must agree, even if long and int are the same size. */ |
5085 | set_sizetype | |
5086 | (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)))); | |
8d08fdba MS |
5087 | |
5088 | ptrdiff_type_node | |
5089 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); | |
5090 | ||
8d08fdba MS |
5091 | /* Define both `signed char' and `unsigned char'. */ |
5092 | signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); | |
5093 | record_builtin_type (RID_MAX, "signed char", signed_char_type_node); | |
5094 | unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); | |
5095 | record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); | |
5096 | ||
5097 | /* These are types that type_for_size and type_for_mode use. */ | |
5098 | intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); | |
5099 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); | |
5100 | intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); | |
5101 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); | |
5102 | intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); | |
5103 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); | |
5104 | intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); | |
5105 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); | |
5106 | unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); | |
5107 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); | |
5108 | unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); | |
5109 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); | |
5110 | unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); | |
5111 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); | |
5112 | unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); | |
5113 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); | |
5114 | ||
5115 | float_type_node = make_node (REAL_TYPE); | |
5116 | TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; | |
5117 | record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node); | |
5118 | layout_type (float_type_node); | |
5119 | ||
5120 | double_type_node = make_node (REAL_TYPE); | |
5121 | if (flag_short_double) | |
5122 | TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; | |
5123 | else | |
5124 | TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; | |
5125 | record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node); | |
5126 | layout_type (double_type_node); | |
5127 | ||
5128 | long_double_type_node = make_node (REAL_TYPE); | |
5129 | TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; | |
5130 | record_builtin_type (RID_MAX, "long double", long_double_type_node); | |
5131 | layout_type (long_double_type_node); | |
5132 | ||
37c46b43 MS |
5133 | complex_integer_type_node = make_node (COMPLEX_TYPE); |
5134 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"), | |
5135 | complex_integer_type_node)); | |
5136 | TREE_TYPE (complex_integer_type_node) = integer_type_node; | |
5137 | layout_type (complex_integer_type_node); | |
5138 | ||
5139 | complex_float_type_node = make_node (COMPLEX_TYPE); | |
5140 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"), | |
5141 | complex_float_type_node)); | |
5142 | TREE_TYPE (complex_float_type_node) = float_type_node; | |
5143 | layout_type (complex_float_type_node); | |
5144 | ||
5145 | complex_double_type_node = make_node (COMPLEX_TYPE); | |
5146 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"), | |
5147 | complex_double_type_node)); | |
5148 | TREE_TYPE (complex_double_type_node) = double_type_node; | |
5149 | layout_type (complex_double_type_node); | |
5150 | ||
5151 | complex_long_double_type_node = make_node (COMPLEX_TYPE); | |
5152 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"), | |
5153 | complex_long_double_type_node)); | |
5154 | TREE_TYPE (complex_long_double_type_node) = long_double_type_node; | |
5155 | layout_type (complex_long_double_type_node); | |
5156 | ||
8d08fdba MS |
5157 | integer_zero_node = build_int_2 (0, 0); |
5158 | TREE_TYPE (integer_zero_node) = integer_type_node; | |
5159 | integer_one_node = build_int_2 (1, 0); | |
5160 | TREE_TYPE (integer_one_node) = integer_type_node; | |
5161 | integer_two_node = build_int_2 (2, 0); | |
5162 | TREE_TYPE (integer_two_node) = integer_type_node; | |
5163 | integer_three_node = build_int_2 (3, 0); | |
5164 | TREE_TYPE (integer_three_node) = integer_type_node; | |
8d08fdba | 5165 | |
255512c1 JM |
5166 | boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); |
5167 | TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); | |
c1ea6a0b BK |
5168 | TYPE_MAX_VALUE (boolean_type_node) = build_int_2 (1, 0); |
5169 | TREE_TYPE (TYPE_MAX_VALUE (boolean_type_node)) = boolean_type_node; | |
5170 | TYPE_PRECISION (boolean_type_node) = 1; | |
255512c1 JM |
5171 | record_builtin_type (RID_BOOL, "bool", boolean_type_node); |
5172 | boolean_false_node = build_int_2 (0, 0); | |
5173 | TREE_TYPE (boolean_false_node) = boolean_type_node; | |
5174 | boolean_true_node = build_int_2 (1, 0); | |
5175 | TREE_TYPE (boolean_true_node) = boolean_type_node; | |
2986ae00 | 5176 | |
8d08fdba MS |
5177 | /* These are needed by stor-layout.c. */ |
5178 | size_zero_node = size_int (0); | |
5179 | size_one_node = size_int (1); | |
5180 | ||
e92cc029 MS |
5181 | signed_size_zero_node = build_int_2 (0, 0); |
5182 | TREE_TYPE (signed_size_zero_node) = make_signed_type (TYPE_PRECISION (sizetype)); | |
5183 | ||
8d08fdba MS |
5184 | void_type_node = make_node (VOID_TYPE); |
5185 | record_builtin_type (RID_VOID, NULL_PTR, void_type_node); | |
5186 | layout_type (void_type_node); /* Uses integer_zero_node. */ | |
5187 | void_list_node = build_tree_list (NULL_TREE, void_type_node); | |
5188 | TREE_PARMLIST (void_list_node) = 1; | |
5189 | ||
d11ad92e | 5190 | null_pointer_node = build_int_2 (0, 0); |
8d08fdba | 5191 | TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); |
d11ad92e MS |
5192 | layout_type (TREE_TYPE (null_pointer_node)); |
5193 | ||
8d08fdba MS |
5194 | /* Used for expressions that do nothing, but are not errors. */ |
5195 | void_zero_node = build_int_2 (0, 0); | |
5196 | TREE_TYPE (void_zero_node) = void_type_node; | |
5197 | ||
5198 | string_type_node = build_pointer_type (char_type_node); | |
beb53fb8 JM |
5199 | const_string_type_node |
5200 | = build_pointer_type (build_type_variant (char_type_node, 1, 0)); | |
6b5fbb55 | 5201 | #if 0 |
8d08fdba | 5202 | record_builtin_type (RID_MAX, NULL_PTR, string_type_node); |
6b5fbb55 | 5203 | #endif |
8d08fdba MS |
5204 | |
5205 | /* Make a type to be the domain of a few array types | |
5206 | whose domains don't really matter. | |
5207 | 200 is small enough that it always fits in size_t | |
5208 | and large enough that it can hold most function names for the | |
5209 | initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ | |
5210 | array_domain_type = build_index_type (build_int_2 (200, 0)); | |
5211 | ||
5212 | /* make a type for arrays of characters. | |
5213 | With luck nothing will ever really depend on the length of this | |
5214 | array type. */ | |
5215 | char_array_type_node | |
5216 | = build_array_type (char_type_node, array_domain_type); | |
5217 | /* Likewise for arrays of ints. */ | |
5218 | int_array_type_node | |
5219 | = build_array_type (integer_type_node, array_domain_type); | |
5220 | ||
5221 | /* This is just some anonymous class type. Nobody should ever | |
5222 | need to look inside this envelope. */ | |
5223 | class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE)); | |
5224 | ||
5225 | default_function_type | |
5226 | = build_function_type (integer_type_node, NULL_TREE); | |
8d08fdba MS |
5227 | |
5228 | ptr_type_node = build_pointer_type (void_type_node); | |
beb53fb8 JM |
5229 | const_ptr_type_node |
5230 | = build_pointer_type (build_type_variant (void_type_node, 1, 0)); | |
6b5fbb55 | 5231 | #if 0 |
8d08fdba | 5232 | record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node); |
6b5fbb55 | 5233 | #endif |
8d08fdba MS |
5234 | endlink = void_list_node; |
5235 | int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); | |
5236 | double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); | |
de22184b MS |
5237 | unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink); |
5238 | ||
5239 | ptr_ftype = build_function_type (ptr_type_node, NULL_TREE); | |
5240 | ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink); | |
5241 | sizetype_endlink = tree_cons (NULL_TREE, sizetype, endlink); | |
5242 | /* We realloc here because sizetype could be int or unsigned. S'ok. */ | |
5243 | ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink); | |
5244 | ||
5245 | void_ftype = build_function_type (void_type_node, endlink); | |
5246 | void_ftype_int = build_function_type (void_type_node, int_endlink); | |
5247 | void_ftype_ptr | |
5248 | = build_function_type (void_type_node, | |
5249 | tree_cons (NULL_TREE, ptr_type_node, endlink)); | |
824b9a4c MS |
5250 | void_ftype_ptr |
5251 | = build_exception_variant (void_ftype_ptr, | |
5252 | tree_cons (NULL_TREE, NULL_TREE, NULL_TREE)); | |
8d08fdba | 5253 | |
cffa8729 MS |
5254 | float_ftype_float |
5255 | = build_function_type (float_type_node, | |
5256 | tree_cons (NULL_TREE, float_type_node, endlink)); | |
5257 | ||
8d08fdba MS |
5258 | double_ftype_double |
5259 | = build_function_type (double_type_node, double_endlink); | |
5260 | ||
cffa8729 MS |
5261 | ldouble_ftype_ldouble |
5262 | = build_function_type (long_double_type_node, | |
5263 | tree_cons (NULL_TREE, long_double_type_node, | |
5264 | endlink)); | |
5265 | ||
8d08fdba MS |
5266 | double_ftype_double_double |
5267 | = build_function_type (double_type_node, | |
a28e3c7f MS |
5268 | tree_cons (NULL_TREE, double_type_node, |
5269 | double_endlink)); | |
8d08fdba MS |
5270 | |
5271 | int_ftype_int | |
5272 | = build_function_type (integer_type_node, int_endlink); | |
5273 | ||
5274 | long_ftype_long | |
5275 | = build_function_type (long_integer_type_node, | |
a28e3c7f MS |
5276 | tree_cons (NULL_TREE, long_integer_type_node, |
5277 | endlink)); | |
8d08fdba | 5278 | |
8d08fdba MS |
5279 | int_ftype_cptr_cptr_sizet |
5280 | = build_function_type (integer_type_node, | |
5281 | tree_cons (NULL_TREE, const_ptr_type_node, | |
5282 | tree_cons (NULL_TREE, const_ptr_type_node, | |
5283 | tree_cons (NULL_TREE, | |
5284 | sizetype, | |
5285 | endlink)))); | |
5286 | ||
8d08fdba MS |
5287 | string_ftype_ptr_ptr /* strcpy prototype */ |
5288 | = build_function_type (string_type_node, | |
5289 | tree_cons (NULL_TREE, string_type_node, | |
5290 | tree_cons (NULL_TREE, | |
5291 | const_string_type_node, | |
5292 | endlink))); | |
5293 | ||
8d08fdba MS |
5294 | int_ftype_string_string /* strcmp prototype */ |
5295 | = build_function_type (integer_type_node, | |
5296 | tree_cons (NULL_TREE, const_string_type_node, | |
5297 | tree_cons (NULL_TREE, | |
5298 | const_string_type_node, | |
5299 | endlink))); | |
5300 | ||
cffa8729 | 5301 | strlen_ftype /* strlen prototype */ |
8d08fdba MS |
5302 | = build_function_type (sizetype, |
5303 | tree_cons (NULL_TREE, const_string_type_node, | |
5304 | endlink)); | |
5305 | ||
8d08fdba | 5306 | memcpy_ftype /* memcpy prototype */ |
d22c8596 | 5307 | = build_function_type (ptr_type_node, |
8d08fdba MS |
5308 | tree_cons (NULL_TREE, ptr_type_node, |
5309 | tree_cons (NULL_TREE, const_ptr_type_node, | |
de22184b | 5310 | sizetype_endlink))); |
8d08fdba MS |
5311 | |
5312 | if (flag_huge_objects) | |
5313 | delta_type_node = long_integer_type_node; | |
5314 | else | |
5315 | delta_type_node = short_integer_type_node; | |
5316 | ||
b9620d0e | 5317 | builtin_function ("__builtin_constant_p", default_function_type, |
8d08fdba MS |
5318 | BUILT_IN_CONSTANT_P, NULL_PTR); |
5319 | ||
beb53fb8 JM |
5320 | builtin_return_address_fndecl |
5321 | = builtin_function ("__builtin_return_address", ptr_ftype_unsigned, | |
5322 | BUILT_IN_RETURN_ADDRESS, NULL_PTR); | |
8926095f | 5323 | |
de22184b | 5324 | builtin_function ("__builtin_frame_address", ptr_ftype_unsigned, |
8926095f MS |
5325 | BUILT_IN_FRAME_ADDRESS, NULL_PTR); |
5326 | ||
ca55abae JM |
5327 | ptr_ftype_void = build_function_type (ptr_type_node, endlink); |
5328 | builtin_function ("__builtin_fp", ptr_ftype_void, BUILT_IN_FP, NULL_PTR); | |
5329 | builtin_function ("__builtin_sp", ptr_ftype_void, BUILT_IN_SP, NULL_PTR); | |
5330 | ||
de22184b | 5331 | builtin_function ("__builtin_alloca", ptr_ftype_sizetype, |
8d08fdba | 5332 | BUILT_IN_ALLOCA, "alloca"); |
cffa8729 | 5333 | builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); |
00595019 MS |
5334 | /* Define alloca, ffs as builtins. |
5335 | Declare _exit just to mark it as volatile. */ | |
5336 | if (! flag_no_builtin && !flag_no_nonansi_builtin) | |
5337 | { | |
de22184b | 5338 | temp = builtin_function ("alloca", ptr_ftype_sizetype, |
00595019 MS |
5339 | BUILT_IN_ALLOCA, NULL_PTR); |
5340 | /* Suppress error if redefined as a non-function. */ | |
5341 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
00595019 MS |
5342 | temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); |
5343 | /* Suppress error if redefined as a non-function. */ | |
5344 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
de22184b | 5345 | temp = builtin_function ("_exit", void_ftype_int, |
00595019 MS |
5346 | NOT_BUILT_IN, NULL_PTR); |
5347 | TREE_THIS_VOLATILE (temp) = 1; | |
5348 | TREE_SIDE_EFFECTS (temp) = 1; | |
5349 | /* Suppress error if redefined as a non-function. */ | |
5350 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
5351 | } | |
8d08fdba | 5352 | |
cffa8729 MS |
5353 | builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); |
5354 | builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS, | |
5355 | NULL_PTR); | |
5356 | builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, | |
5357 | NULL_PTR); | |
5358 | builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, | |
5359 | NULL_PTR); | |
8d08fdba MS |
5360 | builtin_function ("__builtin_labs", long_ftype_long, |
5361 | BUILT_IN_LABS, NULL_PTR); | |
de22184b | 5362 | builtin_function ("__builtin_saveregs", ptr_ftype, |
8d08fdba | 5363 | BUILT_IN_SAVEREGS, NULL_PTR); |
8d08fdba MS |
5364 | builtin_function ("__builtin_classify_type", default_function_type, |
5365 | BUILT_IN_CLASSIFY_TYPE, NULL_PTR); | |
de22184b | 5366 | builtin_function ("__builtin_next_arg", ptr_ftype, |
8d08fdba | 5367 | BUILT_IN_NEXT_ARG, NULL_PTR); |
de22184b | 5368 | builtin_function ("__builtin_args_info", int_ftype_int, |
8d08fdba | 5369 | BUILT_IN_ARGS_INFO, NULL_PTR); |
eb66be0e MS |
5370 | builtin_function ("__builtin_setjmp", |
5371 | build_function_type (integer_type_node, | |
5372 | tree_cons (NULL_TREE, ptr_type_node, | |
5373 | endlink)), | |
5374 | BUILT_IN_SETJMP, NULL_PTR); | |
5375 | builtin_function ("__builtin_longjmp", | |
5376 | build_function_type (integer_type_node, | |
5377 | tree_cons (NULL_TREE, ptr_type_node, | |
5378 | tree_cons (NULL_TREE, | |
5379 | integer_type_node, | |
5380 | endlink))), | |
5381 | BUILT_IN_LONGJMP, NULL_PTR); | |
8d08fdba MS |
5382 | |
5383 | /* Untyped call and return. */ | |
de22184b | 5384 | builtin_function ("__builtin_apply_args", ptr_ftype, |
8d08fdba MS |
5385 | BUILT_IN_APPLY_ARGS, NULL_PTR); |
5386 | ||
5387 | temp = tree_cons (NULL_TREE, | |
5388 | build_pointer_type (build_function_type (void_type_node, | |
5389 | NULL_TREE)), | |
de22184b | 5390 | ptr_ftype_sizetype); |
8d08fdba MS |
5391 | builtin_function ("__builtin_apply", |
5392 | build_function_type (ptr_type_node, temp), | |
5393 | BUILT_IN_APPLY, NULL_PTR); | |
de22184b | 5394 | builtin_function ("__builtin_return", void_ftype_ptr, |
8d08fdba MS |
5395 | BUILT_IN_RETURN, NULL_PTR); |
5396 | ||
5397 | /* Currently under experimentation. */ | |
5398 | builtin_function ("__builtin_memcpy", memcpy_ftype, | |
5399 | BUILT_IN_MEMCPY, "memcpy"); | |
5400 | builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, | |
5401 | BUILT_IN_MEMCMP, "memcmp"); | |
5402 | builtin_function ("__builtin_strcmp", int_ftype_string_string, | |
5403 | BUILT_IN_STRCMP, "strcmp"); | |
5404 | builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, | |
5405 | BUILT_IN_STRCPY, "strcpy"); | |
cffa8729 | 5406 | builtin_function ("__builtin_strlen", strlen_ftype, |
8d08fdba | 5407 | BUILT_IN_STRLEN, "strlen"); |
cffa8729 MS |
5408 | builtin_function ("__builtin_sqrtf", float_ftype_float, |
5409 | BUILT_IN_FSQRT, "sqrtf"); | |
5410 | builtin_function ("__builtin_fsqrt", double_ftype_double, | |
5411 | BUILT_IN_FSQRT, NULL_PTR); | |
5412 | builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble, | |
5413 | BUILT_IN_FSQRT, "sqrtl"); | |
5414 | builtin_function ("__builtin_sinf", float_ftype_float, | |
5415 | BUILT_IN_SIN, "sinf"); | |
5416 | builtin_function ("__builtin_sin", double_ftype_double, | |
5417 | BUILT_IN_SIN, "sin"); | |
5418 | builtin_function ("__builtin_sinl", ldouble_ftype_ldouble, | |
5419 | BUILT_IN_SIN, "sinl"); | |
5420 | builtin_function ("__builtin_cosf", float_ftype_float, | |
5421 | BUILT_IN_COS, "cosf"); | |
5422 | builtin_function ("__builtin_cos", double_ftype_double, | |
5423 | BUILT_IN_COS, "cos"); | |
5424 | builtin_function ("__builtin_cosl", ldouble_ftype_ldouble, | |
5425 | BUILT_IN_COS, "cosl"); | |
8d08fdba MS |
5426 | |
5427 | if (!flag_no_builtin) | |
5428 | { | |
8d08fdba MS |
5429 | builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); |
5430 | builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); | |
5431 | builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); | |
cffa8729 MS |
5432 | builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR); |
5433 | builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, | |
5434 | NULL_PTR); | |
8d08fdba MS |
5435 | builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); |
5436 | builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, | |
5437 | NULL_PTR); | |
cffa8729 MS |
5438 | builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, |
5439 | NULL_PTR); | |
a28e3c7f MS |
5440 | builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, |
5441 | NULL_PTR); | |
cffa8729 MS |
5442 | builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR); |
5443 | builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR); | |
5444 | builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR); | |
5445 | builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT, | |
5446 | NULL_PTR); | |
5447 | builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR); | |
8d08fdba | 5448 | builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); |
cffa8729 MS |
5449 | builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR); |
5450 | builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR); | |
8d08fdba | 5451 | builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); |
cffa8729 | 5452 | builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR); |
00595019 MS |
5453 | |
5454 | /* Declare these functions volatile | |
5455 | to avoid spurious "control drops through" warnings. */ | |
de22184b | 5456 | temp = builtin_function ("abort", void_ftype, |
00595019 MS |
5457 | NOT_BUILT_IN, NULL_PTR); |
5458 | TREE_THIS_VOLATILE (temp) = 1; | |
5459 | TREE_SIDE_EFFECTS (temp) = 1; | |
5460 | /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on | |
5461 | them... */ | |
5462 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
de22184b | 5463 | temp = builtin_function ("exit", void_ftype_int, |
00595019 MS |
5464 | NOT_BUILT_IN, NULL_PTR); |
5465 | TREE_THIS_VOLATILE (temp) = 1; | |
5466 | TREE_SIDE_EFFECTS (temp) = 1; | |
5467 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
8d08fdba MS |
5468 | } |
5469 | ||
5470 | #if 0 | |
5471 | /* Support for these has not been written in either expand_builtin | |
5472 | or build_function_call. */ | |
72b7eeff MS |
5473 | builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR); |
5474 | builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR); | |
a28e3c7f | 5475 | builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, |
72b7eeff | 5476 | NULL_PTR); |
cffa8729 MS |
5477 | builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, |
5478 | NULL_PTR); | |
a28e3c7f | 5479 | builtin_function ("__builtin_fmod", double_ftype_double_double, |
72b7eeff | 5480 | BUILT_IN_FMOD, NULL_PTR); |
a28e3c7f | 5481 | builtin_function ("__builtin_frem", double_ftype_double_double, |
72b7eeff | 5482 | BUILT_IN_FREM, NULL_PTR); |
cffa8729 MS |
5483 | builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, |
5484 | BUILT_IN_MEMSET, NULL_PTR); | |
a28e3c7f | 5485 | builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, |
72b7eeff | 5486 | NULL_PTR); |
a28e3c7f | 5487 | builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, |
72b7eeff | 5488 | NULL_PTR); |
8d08fdba MS |
5489 | #endif |
5490 | ||
5491 | /* C++ extensions */ | |
5492 | ||
5493 | unknown_type_node = make_node (UNKNOWN_TYPE); | |
8d08fdba MS |
5494 | decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"), |
5495 | unknown_type_node)); | |
5496 | /* Make sure the "unknown type" typedecl gets ignored for debug info. */ | |
5497 | DECL_IGNORED_P (decl) = 1; | |
39211cd5 | 5498 | TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; |
8d08fdba MS |
5499 | TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node); |
5500 | TYPE_ALIGN (unknown_type_node) = 1; | |
5501 | TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node); | |
5502 | /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ | |
5503 | TREE_TYPE (unknown_type_node) = unknown_type_node; | |
a6967cc0 JM |
5504 | |
5505 | if (flag_ansi) | |
5506 | TREE_TYPE (null_node) = type_for_size (POINTER_SIZE, 0); | |
5507 | else | |
5508 | TREE_TYPE (null_node) = build_pointer_type (unknown_type_node); | |
5509 | ||
5510 | /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same | |
5511 | result. */ | |
8d08fdba MS |
5512 | TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; |
5513 | TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; | |
5514 | ||
5515 | /* This is for handling opaque types in signatures. */ | |
5516 | opaque_type_node = copy_node (ptr_type_node); | |
5517 | TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node; | |
5518 | record_builtin_type (RID_MAX, 0, opaque_type_node); | |
5519 | ||
e92cc029 | 5520 | /* This is special for C++ so functions can be overloaded. */ |
8d08fdba MS |
5521 | wchar_type_node |
5522 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); | |
5523 | wchar_type_size = TYPE_PRECISION (wchar_type_node); | |
5524 | signed_wchar_type_node = make_signed_type (wchar_type_size); | |
5525 | unsigned_wchar_type_node = make_unsigned_type (wchar_type_size); | |
5526 | wchar_type_node | |
5527 | = TREE_UNSIGNED (wchar_type_node) | |
5528 | ? unsigned_wchar_type_node | |
5529 | : signed_wchar_type_node; | |
5530 | record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node); | |
5531 | ||
f376e137 MS |
5532 | /* Artificial declaration of wchar_t -- can be bashed */ |
5533 | wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"), | |
5534 | wchar_type_node); | |
5535 | pushdecl (wchar_decl_node); | |
5536 | ||
8d08fdba MS |
5537 | /* This is for wide string constants. */ |
5538 | wchar_array_type_node | |
5539 | = build_array_type (wchar_type_node, array_domain_type); | |
5540 | ||
8926095f | 5541 | if (flag_vtable_thunks) |
700f8a87 MS |
5542 | { |
5543 | /* Make sure we get a unique function type, so we can give | |
5544 | its pointer type a name. (This wins for gdb.) */ | |
5545 | tree vfunc_type = make_node (FUNCTION_TYPE); | |
5546 | TREE_TYPE (vfunc_type) = integer_type_node; | |
5547 | TYPE_ARG_TYPES (vfunc_type) = NULL_TREE; | |
5548 | layout_type (vfunc_type); | |
5549 | ||
5550 | vtable_entry_type = build_pointer_type (vfunc_type); | |
5551 | } | |
8926095f | 5552 | else |
700f8a87 MS |
5553 | { |
5554 | vtable_entry_type = make_lang_type (RECORD_TYPE); | |
5555 | fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, | |
5556 | delta_type_node); | |
5557 | fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, | |
5558 | delta_type_node); | |
5559 | fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, | |
5560 | ptr_type_node); | |
5561 | finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2, | |
5562 | double_type_node); | |
5563 | ||
5564 | /* Make this part of an invisible union. */ | |
5565 | fields[3] = copy_node (fields[2]); | |
5566 | TREE_TYPE (fields[3]) = delta_type_node; | |
5567 | DECL_NAME (fields[3]) = delta2_identifier; | |
5568 | DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node); | |
5569 | DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node); | |
5570 | TREE_UNSIGNED (fields[3]) = 0; | |
5571 | TREE_CHAIN (fields[2]) = fields[3]; | |
5572 | vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0); | |
5573 | } | |
5574 | record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type); | |
8d08fdba | 5575 | |
8d08fdba MS |
5576 | vtbl_type_node |
5577 | = build_array_type (vtable_entry_type, NULL_TREE); | |
5578 | layout_type (vtbl_type_node); | |
f376e137 | 5579 | vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0); |
8d08fdba MS |
5580 | record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node); |
5581 | ||
5582 | /* Simplify life by making a "sigtable_entry_type". Give its | |
5583 | fields names so that the debugger can use them. */ | |
5584 | ||
5585 | if (flag_handle_signatures) | |
5586 | { | |
5587 | sigtable_entry_type = make_lang_type (RECORD_TYPE); | |
dff6b454 RK |
5588 | fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier, |
5589 | delta_type_node); | |
9dd70aa4 | 5590 | fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier, |
dff6b454 | 5591 | delta_type_node); |
9dd70aa4 | 5592 | fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier, |
dff6b454 RK |
5593 | delta_type_node); |
5594 | fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier, | |
5595 | delta_type_node); | |
9dd70aa4 GB |
5596 | fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier, |
5597 | ptr_type_node); | |
5598 | ||
5599 | /* Set the alignment to the max of the alignment of ptr_type_node and | |
5600 | delta_type_node. Double alignment wastes a word on the Sparc. */ | |
5601 | finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4, | |
5602 | (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node)) | |
5603 | ? ptr_type_node | |
5604 | : delta_type_node); | |
dff6b454 RK |
5605 | |
5606 | /* Make this part of an invisible union. */ | |
9dd70aa4 GB |
5607 | fields[5] = copy_node (fields[4]); |
5608 | TREE_TYPE (fields[5]) = delta_type_node; | |
5609 | DECL_NAME (fields[5]) = vt_off_identifier; | |
5610 | DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node); | |
5611 | DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node); | |
5612 | TREE_UNSIGNED (fields[5]) = 0; | |
5613 | TREE_CHAIN (fields[4]) = fields[5]; | |
dff6b454 | 5614 | |
8d08fdba MS |
5615 | sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0); |
5616 | record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type); | |
5617 | } | |
5618 | ||
6633d636 MS |
5619 | std_node = build_decl (NAMESPACE_DECL, get_identifier ("std"), |
5620 | void_type_node); | |
5621 | pushdecl (std_node); | |
5622 | ||
db5ae43f MS |
5623 | /* Now, C++. */ |
5624 | current_lang_name = lang_name_cplusplus; | |
8d08fdba | 5625 | |
ced78d8b JM |
5626 | { |
5627 | tree bad_alloc_type_node = xref_tag | |
5628 | (class_type_node, get_identifier ("bad_alloc"), NULL_TREE, 1); | |
5629 | tree newtype = build_exception_variant | |
5630 | (ptr_ftype_sizetype, build_tree_list (NULL_TREE, bad_alloc_type_node)); | |
5631 | tree deltype = build_exception_variant | |
5632 | (void_ftype_ptr, build_tree_list (NULL_TREE, NULL_TREE)); | |
5633 | auto_function (ansi_opname[(int) NEW_EXPR], newtype, NOT_BUILT_IN); | |
5634 | auto_function (ansi_opname[(int) VEC_NEW_EXPR], newtype, NOT_BUILT_IN); | |
5635 | auto_function (ansi_opname[(int) DELETE_EXPR], deltype, NOT_BUILT_IN); | |
5636 | auto_function (ansi_opname[(int) VEC_DELETE_EXPR], deltype, NOT_BUILT_IN); | |
5637 | } | |
8d08fdba MS |
5638 | |
5639 | abort_fndecl | |
de22184b | 5640 | = define_function ("__pure_virtual", void_ftype, |
8d08fdba MS |
5641 | NOT_BUILT_IN, 0, 0); |
5642 | ||
8d08fdba MS |
5643 | /* Perform other language dependent initializations. */ |
5644 | init_class_processing (); | |
5645 | init_init_processing (); | |
5646 | init_search_processing (); | |
1737fe20 BK |
5647 | if (flag_rtti) |
5648 | init_rtti_processing (); | |
8d08fdba | 5649 | |
6467930b | 5650 | if (flag_exceptions) |
8d2733ca | 5651 | init_exception_processing (); |
8d08fdba MS |
5652 | if (flag_no_inline) |
5653 | { | |
5654 | flag_inline_functions = 0; | |
8d08fdba | 5655 | } |
9e9ff709 | 5656 | |
7fcdf4c2 | 5657 | if (! supports_one_only ()) |
72b7eeff | 5658 | flag_weak = 0; |
8d08fdba MS |
5659 | |
5660 | /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ | |
5661 | declare_function_name (); | |
5662 | ||
5663 | /* Prepare to check format strings against argument lists. */ | |
5664 | init_function_format_info (); | |
e9a25f70 JL |
5665 | |
5666 | /* Show we use EH for cleanups. */ | |
5667 | using_eh_for_cleanups (); | |
8d08fdba MS |
5668 | } |
5669 | ||
5670 | /* Make a definition for a builtin function named NAME and whose data type | |
5671 | is TYPE. TYPE should be a function type with argument types. | |
5672 | FUNCTION_CODE tells later passes how to compile calls to this function. | |
5673 | See tree.h for its possible values. | |
5674 | ||
5675 | If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, | |
5676 | the name to be called if we can't opencode the function. */ | |
5677 | ||
5678 | tree | |
5679 | define_function (name, type, function_code, pfn, library_name) | |
5680 | char *name; | |
5681 | tree type; | |
5682 | enum built_in_function function_code; | |
49c249e1 | 5683 | void (*pfn) PROTO((tree)); |
8d08fdba MS |
5684 | char *library_name; |
5685 | { | |
5686 | tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); | |
5687 | DECL_EXTERNAL (decl) = 1; | |
5688 | TREE_PUBLIC (decl) = 1; | |
863adfc0 | 5689 | DECL_ARTIFICIAL (decl) = 1; |
8d08fdba MS |
5690 | |
5691 | /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, | |
5692 | we cannot change DECL_ASSEMBLER_NAME until we have installed this | |
5693 | function in the namespace. */ | |
5694 | if (pfn) (*pfn) (decl); | |
5695 | if (library_name) | |
5696 | DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); | |
5697 | make_function_rtl (decl); | |
5698 | if (function_code != NOT_BUILT_IN) | |
5699 | { | |
5700 | DECL_BUILT_IN (decl) = 1; | |
39211cd5 | 5701 | DECL_FUNCTION_CODE (decl) = function_code; |
8d08fdba MS |
5702 | } |
5703 | return decl; | |
5704 | } | |
5705 | \f | |
5706 | /* Called when a declaration is seen that contains no names to declare. | |
5707 | If its type is a reference to a structure, union or enum inherited | |
5708 | from a containing scope, shadow that tag name for the current scope | |
5709 | with a forward reference. | |
5710 | If its type defines a new named structure or union | |
5711 | or defines an enum, it is valid but we need not do anything here. | |
5712 | Otherwise, it is an error. | |
5713 | ||
5714 | C++: may have to grok the declspecs to learn about static, | |
5715 | complain for anonymous unions. */ | |
5716 | ||
5717 | void | |
5718 | shadow_tag (declspecs) | |
5719 | tree declspecs; | |
5720 | { | |
5721 | int found_tag = 0; | |
2986ae00 | 5722 | tree ob_modifier = NULL_TREE; |
8d08fdba MS |
5723 | register tree link; |
5724 | register enum tree_code code, ok_code = ERROR_MARK; | |
5725 | register tree t = NULL_TREE; | |
5726 | ||
5727 | for (link = declspecs; link; link = TREE_CHAIN (link)) | |
5728 | { | |
5729 | register tree value = TREE_VALUE (link); | |
5730 | ||
5731 | code = TREE_CODE (value); | |
5732 | if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE) | |
8d08fdba | 5733 | { |
d2e5ee5c | 5734 | my_friendly_assert (TYPE_MAIN_DECL (value) != NULL_TREE, 261); |
8d08fdba | 5735 | |
fc378698 | 5736 | if (IS_AGGR_TYPE (value) && CLASSTYPE_USE_TEMPLATE (value)) |
5566b478 MS |
5737 | { |
5738 | if (CLASSTYPE_IMPLICIT_INSTANTIATION (value) | |
5739 | && TYPE_SIZE (value) == NULL_TREE) | |
73aad9b9 JM |
5740 | { |
5741 | SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (value); | |
5156628f | 5742 | if (processing_template_decl) |
73aad9b9 JM |
5743 | push_template_decl (TYPE_MAIN_DECL (value)); |
5744 | } | |
5566b478 MS |
5745 | else if (CLASSTYPE_TEMPLATE_INSTANTIATION (value)) |
5746 | cp_error ("specialization after instantiation of `%T'", value); | |
5747 | } | |
5748 | ||
b8bca6f2 JM |
5749 | t = value; |
5750 | ok_code = code; | |
5751 | found_tag++; | |
8d08fdba MS |
5752 | } |
5753 | else if (value == ridpointers[(int) RID_STATIC] | |
2986ae00 MS |
5754 | || value == ridpointers[(int) RID_EXTERN] |
5755 | || value == ridpointers[(int) RID_AUTO] | |
28cbf42c MS |
5756 | || value == ridpointers[(int) RID_REGISTER] |
5757 | || value == ridpointers[(int) RID_INLINE] | |
5758 | || value == ridpointers[(int) RID_VIRTUAL] | |
5759 | || value == ridpointers[(int) RID_EXPLICIT]) | |
2986ae00 | 5760 | ob_modifier = value; |
8d08fdba MS |
5761 | } |
5762 | ||
5763 | /* This is where the variables in an anonymous union are | |
5764 | declared. An anonymous union declaration looks like: | |
5765 | union { ... } ; | |
5766 | because there is no declarator after the union, the parser | |
5767 | sends that declaration here. */ | |
5768 | if (ok_code == UNION_TYPE | |
5769 | && t != NULL_TREE | |
5770 | && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE | |
5771 | && ANON_AGGRNAME_P (TYPE_NAME (t))) | |
5772 | || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL | |
5773 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))) | |
5774 | { | |
d2e5ee5c | 5775 | /* See also grok_x_components. */ |
d2e5ee5c MS |
5776 | tree *q; |
5777 | ||
5778 | /* Wipe out memory of synthesized methods */ | |
5779 | TYPE_HAS_CONSTRUCTOR (t) = 0; | |
5780 | TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0; | |
5781 | TYPE_HAS_INIT_REF (t) = 0; | |
5782 | TYPE_HAS_CONST_INIT_REF (t) = 0; | |
5783 | TYPE_HAS_ASSIGN_REF (t) = 0; | |
5784 | TYPE_HAS_ASSIGNMENT (t) = 0; | |
5785 | TYPE_HAS_CONST_ASSIGN_REF (t) = 0; | |
5786 | ||
5787 | q = &TYPE_METHODS (t); | |
5788 | while (*q) | |
5789 | { | |
5790 | if (DECL_ARTIFICIAL (*q)) | |
5791 | *q = TREE_CHAIN (*q); | |
5792 | else | |
5793 | q = &TREE_CHAIN (*q); | |
5794 | } | |
f49422da | 5795 | |
8d08fdba MS |
5796 | /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have |
5797 | function members. */ | |
d2e5ee5c MS |
5798 | if (TYPE_METHODS (t)) |
5799 | error ("an anonymous union cannot have function members"); | |
c91a56d2 | 5800 | |
8d08fdba MS |
5801 | if (TYPE_FIELDS (t)) |
5802 | { | |
a28e3c7f | 5803 | tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, |
c11b6f21 | 5804 | NULL_TREE); |
8d08fdba MS |
5805 | finish_anon_union (decl); |
5806 | } | |
8d08fdba MS |
5807 | } |
5808 | else | |
5809 | { | |
5810 | /* Anonymous unions are objects, that's why we only check for | |
2986ae00 | 5811 | inappropriate specifiers in this branch. */ |
28cbf42c | 5812 | |
2986ae00 | 5813 | if (ob_modifier) |
28cbf42c MS |
5814 | { |
5815 | if (ob_modifier == ridpointers[(int) RID_INLINE] | |
5816 | || ob_modifier == ridpointers[(int) RID_VIRTUAL]) | |
5817 | cp_error ("`%D' can only be specified for functions", ob_modifier); | |
5818 | else if (ob_modifier == ridpointers[(int) RID_EXPLICIT]) | |
5819 | cp_error ("`%D' can only be specified for constructors", | |
5820 | ob_modifier); | |
5821 | else | |
5822 | cp_error ("`%D' can only be specified for objects and functions", | |
5823 | ob_modifier); | |
5824 | } | |
8d08fdba | 5825 | |
b8bca6f2 | 5826 | if (found_tag == 0) |
2df06032 | 5827 | cp_error ("abstract declarator used as declaration"); |
b8bca6f2 | 5828 | else if (found_tag > 1) |
2986ae00 | 5829 | pedwarn ("multiple types in one declaration"); |
8d08fdba MS |
5830 | } |
5831 | } | |
5832 | \f | |
5833 | /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ | |
5834 | ||
5835 | tree | |
5836 | groktypename (typename) | |
5837 | tree typename; | |
5838 | { | |
5839 | if (TREE_CODE (typename) != TREE_LIST) | |
5840 | return typename; | |
5841 | return grokdeclarator (TREE_VALUE (typename), | |
5842 | TREE_PURPOSE (typename), | |
c11b6f21 | 5843 | TYPENAME, 0, NULL_TREE); |
8d08fdba MS |
5844 | } |
5845 | ||
5846 | /* Decode a declarator in an ordinary declaration or data definition. | |
5847 | This is called as soon as the type information and variable name | |
5848 | have been parsed, before parsing the initializer if any. | |
5849 | Here we create the ..._DECL node, fill in its type, | |
5850 | and put it on the list of decls for the current context. | |
5851 | The ..._DECL node is returned as the value. | |
5852 | ||
5853 | Exception: for arrays where the length is not specified, | |
82580166 | 5854 | the type is left null, to be filled in by `cp_finish_decl'. |
8d08fdba MS |
5855 | |
5856 | Function definitions do not come here; they go to start_function | |
5857 | instead. However, external and forward declarations of functions | |
5858 | do go through here. Structure field declarations are done by | |
5859 | grokfield and not through here. */ | |
5860 | ||
5861 | /* Set this to zero to debug not using the temporary obstack | |
5862 | to parse initializers. */ | |
5863 | int debug_temp_inits = 1; | |
5864 | ||
5865 | tree | |
c11b6f21 | 5866 | start_decl (declarator, declspecs, initialized) |
8d08fdba MS |
5867 | tree declarator, declspecs; |
5868 | int initialized; | |
8d08fdba MS |
5869 | { |
5870 | register tree decl; | |
5871 | register tree type, tem; | |
5872 | tree context; | |
5873 | extern int have_extern_spec; | |
5874 | extern int used_extern_spec; | |
5875 | ||
5566b478 MS |
5876 | #if 0 |
5877 | /* See code below that used this. */ | |
8d08fdba | 5878 | int init_written = initialized; |
5566b478 | 5879 | #endif |
8d08fdba | 5880 | |
e92cc029 | 5881 | /* This should only be done once on the top most decl. */ |
8d08fdba MS |
5882 | if (have_extern_spec && !used_extern_spec) |
5883 | { | |
a28e3c7f MS |
5884 | declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), |
5885 | declspecs); | |
8d08fdba MS |
5886 | used_extern_spec = 1; |
5887 | } | |
5888 | ||
c11b6f21 | 5889 | decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, |
f30432d7 | 5890 | NULL_TREE); |
8d08fdba MS |
5891 | if (decl == NULL_TREE || decl == void_type_node) |
5892 | return NULL_TREE; | |
5893 | ||
5894 | type = TREE_TYPE (decl); | |
5895 | ||
5896 | /* Don't lose if destructors must be executed at file-level. */ | |
5156628f | 5897 | if (! processing_template_decl && TREE_STATIC (decl) |
ec255269 | 5898 | && TYPE_NEEDS_DESTRUCTOR (complete_type (type)) |
8d08fdba MS |
5899 | && !TREE_PERMANENT (decl)) |
5900 | { | |
5901 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
5902 | decl = copy_node (decl); | |
5903 | if (TREE_CODE (type) == ARRAY_TYPE) | |
5904 | { | |
5905 | tree itype = TYPE_DOMAIN (type); | |
5906 | if (itype && ! TREE_PERMANENT (itype)) | |
5907 | { | |
5908 | itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype))); | |
5909 | type = build_cplus_array_type (TREE_TYPE (type), itype); | |
5910 | TREE_TYPE (decl) = type; | |
5911 | } | |
5912 | } | |
5913 | pop_obstacks (); | |
5914 | } | |
5915 | ||
8d08fdba MS |
5916 | context |
5917 | = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) | |
5918 | ? DECL_CLASS_CONTEXT (decl) | |
5919 | : DECL_CONTEXT (decl); | |
5920 | ||
8d08fdba MS |
5921 | if (initialized) |
5922 | /* Is it valid for this decl to have an initializer at all? | |
5923 | If not, set INITIALIZED to zero, which will indirectly | |
82580166 | 5924 | tell `cp_finish_decl' to ignore the initializer once it is parsed. */ |
8d08fdba MS |
5925 | switch (TREE_CODE (decl)) |
5926 | { | |
5927 | case TYPE_DECL: | |
5928 | /* typedef foo = bar means give foo the same type as bar. | |
82580166 | 5929 | We haven't parsed bar yet, so `cp_finish_decl' will fix that up. |
8d08fdba MS |
5930 | Any other case of an initialization in a TYPE_DECL is an error. */ |
5931 | if (pedantic || list_length (declspecs) > 1) | |
5932 | { | |
5933 | cp_error ("typedef `%D' is initialized", decl); | |
5934 | initialized = 0; | |
5935 | } | |
5936 | break; | |
5937 | ||
5938 | case FUNCTION_DECL: | |
5939 | cp_error ("function `%#D' is initialized like a variable", decl); | |
5940 | initialized = 0; | |
5941 | break; | |
5942 | ||
5943 | default: | |
5156628f | 5944 | if (! processing_template_decl) |
8d08fdba | 5945 | { |
bd6dd845 | 5946 | if (type != error_mark_node) |
5156628f | 5947 | { |
bd6dd845 MS |
5948 | if (TYPE_SIZE (type) != NULL_TREE |
5949 | && ! TREE_CONSTANT (TYPE_SIZE (type))) | |
5950 | { | |
5951 | cp_error | |
5952 | ("variable-sized object `%D' may not be initialized", | |
5953 | decl); | |
5954 | initialized = 0; | |
5955 | } | |
5156628f | 5956 | |
bd6dd845 MS |
5957 | if (TREE_CODE (type) == ARRAY_TYPE |
5958 | && TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) | |
5959 | { | |
5960 | cp_error | |
5961 | ("elements of array `%#D' have incomplete type", decl); | |
5962 | initialized = 0; | |
5963 | } | |
5156628f | 5964 | } |
8d08fdba MS |
5965 | } |
5966 | } | |
5967 | ||
8d08fdba MS |
5968 | if (initialized) |
5969 | { | |
a9aedbc2 | 5970 | if (! toplevel_bindings_p () |
8d08fdba MS |
5971 | && DECL_EXTERNAL (decl)) |
5972 | cp_warning ("declaration of `%#D' has `extern' and is initialized", | |
5973 | decl); | |
5974 | DECL_EXTERNAL (decl) = 0; | |
5566b478 | 5975 | if (toplevel_bindings_p ()) |
8d08fdba MS |
5976 | TREE_STATIC (decl) = 1; |
5977 | ||
5978 | /* Tell `pushdecl' this is an initialized decl | |
5979 | even though we don't yet have the initializer expression. | |
82580166 | 5980 | Also tell `cp_finish_decl' it may store the real initializer. */ |
8d08fdba MS |
5981 | DECL_INITIAL (decl) = error_mark_node; |
5982 | } | |
5983 | ||
5566b478 | 5984 | if (context && TYPE_SIZE (complete_type (context)) != NULL_TREE) |
5b605f68 MS |
5985 | { |
5986 | if (TREE_CODE (decl) == VAR_DECL) | |
5987 | { | |
5988 | tree field = lookup_field (context, DECL_NAME (decl), 0, 0); | |
5989 | if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) | |
5990 | cp_error ("`%#D' is not a static member of `%#T'", decl, context); | |
e349ee73 MS |
5991 | else |
5992 | { | |
5993 | if (DECL_CONTEXT (field) != context) | |
f2d773a2 JM |
5994 | { |
5995 | cp_pedwarn ("ANSI C++ does not permit `%T::%D' to be defined as `%T::%D'", | |
5996 | DECL_CONTEXT (field), DECL_NAME (decl), | |
5997 | context, DECL_NAME (decl)); | |
5998 | DECL_CONTEXT (decl) = DECL_CONTEXT (field); | |
5999 | } | |
75650646 MM |
6000 | /* Static data member are tricky; an in-class initialization |
6001 | still doesn't provide a definition, so the in-class | |
6002 | declaration will have DECL_EXTERNAL set, but will have an | |
6003 | initialization. Thus, duplicate_decls won't warn | |
6004 | about this situation, and so we check here. */ | |
6005 | if (DECL_INITIAL (decl) && DECL_INITIAL (field)) | |
6006 | cp_error ("duplicate initialization of %D", decl); | |
e349ee73 MS |
6007 | if (duplicate_decls (decl, field)) |
6008 | decl = field; | |
6009 | } | |
5b605f68 | 6010 | } |
f30432d7 MS |
6011 | else |
6012 | { | |
5566b478 | 6013 | tree field = check_classfn (context, decl); |
f30432d7 MS |
6014 | if (field && duplicate_decls (decl, field)) |
6015 | decl = field; | |
6016 | } | |
6017 | ||
6018 | /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */ | |
5b605f68 MS |
6019 | if (DECL_LANG_SPECIFIC (decl)) |
6020 | DECL_IN_AGGR_P (decl) = 0; | |
f30432d7 MS |
6021 | if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context)) |
6022 | SET_DECL_TEMPLATE_SPECIALIZATION (decl); | |
6023 | ||
6024 | /* Stupid stupid stupid stupid (jason 7/21/95) */ | |
6025 | if (pedantic && DECL_EXTERNAL (decl) | |
6026 | && ! DECL_TEMPLATE_SPECIALIZATION (decl)) | |
6027 | cp_pedwarn ("declaration of `%#D' outside of class is not definition", | |
6028 | decl); | |
6029 | ||
5b605f68 MS |
6030 | pushclass (context, 2); |
6031 | } | |
6032 | ||
8d08fdba MS |
6033 | /* Add this decl to the current binding level, but not if it |
6034 | comes from another scope, e.g. a static member variable. | |
6035 | TEM may equal DECL or it may be a previous decl of the same name. */ | |
5b605f68 | 6036 | |
8d08fdba MS |
6037 | if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE) |
6038 | || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ()) | |
75650646 MM |
6039 | || TREE_CODE (type) == LANG_TYPE |
6040 | /* The declaration of template specializations does not affect | |
6041 | the functions available for overload resolution, so we do not | |
6042 | call pushdecl. */ | |
e1467ff2 | 6043 | || (TREE_CODE (decl) == FUNCTION_DECL |
75650646 | 6044 | && DECL_TEMPLATE_SPECIALIZATION (decl))) |
8d08fdba MS |
6045 | tem = decl; |
6046 | else | |
8926095f | 6047 | tem = pushdecl (decl); |
2ee887f2 | 6048 | |
5156628f | 6049 | if (processing_template_decl) |
5566b478 MS |
6050 | { |
6051 | if (! current_function_decl) | |
3ac3d9ea | 6052 | tem = push_template_decl (tem); |
5566b478 MS |
6053 | else if (minimal_parse_mode) |
6054 | DECL_VINDEX (decl) | |
6055 | = build_min_nt (DECL_STMT, copy_to_permanent (declarator), | |
6056 | copy_to_permanent (declspecs), | |
c11b6f21 | 6057 | NULL_TREE); |
5566b478 MS |
6058 | } |
6059 | ||
6060 | ||
2ee887f2 | 6061 | #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) |
a3203465 | 6062 | /* Tell the back-end to use or not use .common as appropriate. If we say |
a50f0918 MS |
6063 | -fconserve-space, we want this to save .data space, at the expense of |
6064 | wrong semantics. If we say -fno-conserve-space, we want this to | |
6065 | produce errors about redefs; to do this we force variables into the | |
6066 | data segment. */ | |
a3203465 | 6067 | DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem); |
2ee887f2 | 6068 | #endif |
8d08fdba | 6069 | |
5156628f | 6070 | if (! processing_template_decl) |
5566b478 | 6071 | start_decl_1 (tem); |
8d08fdba | 6072 | |
5566b478 MS |
6073 | /* Corresponding pop_obstacks is done in `cp_finish_decl'. */ |
6074 | push_obstacks_nochange (); | |
8d08fdba | 6075 | |
5566b478 MS |
6076 | #if 0 |
6077 | /* We have no way of knowing whether the initializer will need to be | |
6078 | evaluated at run-time or not until we've parsed it, so let's just put | |
6079 | it in the permanent obstack. (jason) */ | |
8d08fdba MS |
6080 | if (init_written |
6081 | && ! (TREE_CODE (tem) == PARM_DECL | |
6082 | || (TREE_READONLY (tem) | |
6083 | && (TREE_CODE (tem) == VAR_DECL | |
6084 | || TREE_CODE (tem) == FIELD_DECL)))) | |
6085 | { | |
6086 | /* When parsing and digesting the initializer, | |
6087 | use temporary storage. Do this even if we will ignore the value. */ | |
a9aedbc2 | 6088 | if (toplevel_bindings_p () && debug_temp_inits) |
8d08fdba | 6089 | { |
5156628f | 6090 | if (processing_template_decl |
5566b478 | 6091 | || TYPE_NEEDS_CONSTRUCTING (type) |
a28e3c7f | 6092 | || TREE_CODE (type) == REFERENCE_TYPE) |
8d08fdba MS |
6093 | /* In this case, the initializer must lay down in permanent |
6094 | storage, since it will be saved until `finish_file' is run. */ | |
6095 | ; | |
6096 | else | |
6097 | temporary_allocation (); | |
6098 | } | |
6099 | } | |
5566b478 | 6100 | #endif |
8d08fdba | 6101 | |
8d08fdba MS |
6102 | return tem; |
6103 | } | |
6104 | ||
5566b478 MS |
6105 | void |
6106 | start_decl_1 (decl) | |
6107 | tree decl; | |
8d08fdba | 6108 | { |
5566b478 MS |
6109 | tree type = TREE_TYPE (decl); |
6110 | int initialized = (DECL_INITIAL (decl) != NULL_TREE); | |
8d08fdba | 6111 | |
5566b478 MS |
6112 | /* If this type of object needs a cleanup, and control may |
6113 | jump past it, make a new binding level so that it is cleaned | |
6114 | up only when it is initialized first. */ | |
6115 | if (TYPE_NEEDS_DESTRUCTOR (type) | |
6116 | && current_binding_level->more_cleanups_ok == 0) | |
6117 | pushlevel_temporary (1); | |
6118 | ||
6119 | if (initialized) | |
6120 | /* Is it valid for this decl to have an initializer at all? | |
6121 | If not, set INITIALIZED to zero, which will indirectly | |
6122 | tell `cp_finish_decl' to ignore the initializer once it is parsed. */ | |
8d08fdba | 6123 | { |
5566b478 MS |
6124 | /* Don't allow initializations for incomplete types except for |
6125 | arrays which might be completed by the initialization. */ | |
6126 | if (type == error_mark_node) | |
6127 | ; /* Don't complain again. */ | |
6128 | else if (TYPE_SIZE (complete_type (type)) != NULL_TREE) | |
6129 | ; /* A complete type is ok. */ | |
6130 | else if (TREE_CODE (type) != ARRAY_TYPE) | |
8d08fdba | 6131 | { |
5566b478 MS |
6132 | cp_error ("variable `%#D' has initializer but incomplete type", |
6133 | decl); | |
6134 | initialized = 0; | |
6135 | } | |
6136 | else if (TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) | |
6137 | { | |
6138 | if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)) | |
6139 | cp_error ("elements of array `%#D' have incomplete type", decl); | |
6140 | /* else we already gave an error in start_decl. */ | |
6141 | initialized = 0; | |
8d08fdba | 6142 | } |
8d08fdba MS |
6143 | } |
6144 | ||
5566b478 MS |
6145 | if (!initialized |
6146 | && TREE_CODE (decl) != TYPE_DECL | |
6147 | && TREE_CODE (decl) != TEMPLATE_DECL | |
6148 | && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) | |
8d08fdba | 6149 | { |
5156628f | 6150 | if ((! processing_template_decl || ! uses_template_parms (type)) |
7fcdf4c2 | 6151 | && TYPE_SIZE (complete_type (type)) == NULL_TREE) |
5566b478 MS |
6152 | { |
6153 | cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", | |
6154 | decl); | |
6155 | /* Change the type so that assemble_variable will give | |
6156 | DECL an rtl we can live with: (mem (const_int 0)). */ | |
6157 | TREE_TYPE (decl) = error_mark_node; | |
6158 | type = error_mark_node; | |
6159 | } | |
6160 | else | |
6161 | { | |
6162 | /* If any base type in the hierarchy of TYPE needs a constructor, | |
6163 | then we set initialized to 1. This way any nodes which are | |
6164 | created for the purposes of initializing this aggregate | |
6165 | will live as long as it does. This is necessary for global | |
6166 | aggregates which do not have their initializers processed until | |
6167 | the end of the file. */ | |
6168 | initialized = TYPE_NEEDS_CONSTRUCTING (type); | |
6169 | } | |
6170 | } | |
6171 | ||
6172 | #if 0 | |
6173 | /* We don't do this yet for GNU C++. */ | |
6174 | /* For a local variable, define the RTL now. */ | |
6175 | if (! toplevel_bindings_p () | |
6176 | /* But not if this is a duplicate decl | |
6177 | and we preserved the rtl from the previous one | |
6178 | (which may or may not happen). */ | |
6179 | && DECL_RTL (tem) == NULL_RTX) | |
6180 | { | |
6181 | if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) | |
6182 | expand_decl (tem); | |
6183 | else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE | |
6184 | && DECL_INITIAL (tem) != NULL_TREE) | |
6185 | expand_decl (tem); | |
6186 | } | |
6187 | #endif | |
6188 | ||
6189 | if (! initialized) | |
6190 | DECL_INITIAL (decl) = NULL_TREE; | |
6191 | } | |
6192 | ||
6193 | /* Handle initialization of references. | |
6194 | These three arguments from from `cp_finish_decl', and have the | |
e92cc029 MS |
6195 | same meaning here that they do there. |
6196 | ||
6197 | Quotes on semantics can be found in ARM 8.4.3. */ | |
6198 | ||
5566b478 | 6199 | static void |
a703fb38 | 6200 | grok_reference_init (decl, type, init) |
5566b478 | 6201 | tree decl, type, init; |
5566b478 MS |
6202 | { |
6203 | tree tmp; | |
6204 | ||
6205 | if (init == NULL_TREE) | |
6206 | { | |
6207 | if ((DECL_LANG_SPECIFIC (decl) == 0 | |
6208 | || DECL_IN_AGGR_P (decl) == 0) | |
6209 | && ! DECL_THIS_EXTERN (decl)) | |
6210 | { | |
6211 | cp_error ("`%D' declared as reference but not initialized", decl); | |
6212 | if (TREE_CODE (decl) == VAR_DECL) | |
6213 | SET_DECL_REFERENCE_SLOT (decl, error_mark_node); | |
6214 | } | |
6215 | return; | |
6216 | } | |
6217 | ||
6218 | if (init == error_mark_node) | |
6219 | return; | |
6220 | ||
6221 | if (TREE_CODE (type) == REFERENCE_TYPE | |
6222 | && TREE_CODE (init) == CONSTRUCTOR) | |
6223 | { | |
6224 | cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl); | |
8d08fdba MS |
6225 | return; |
6226 | } | |
6227 | ||
ec255269 MS |
6228 | if (TREE_TYPE (init) && TREE_CODE (TREE_TYPE (init)) == UNKNOWN_TYPE) |
6229 | /* decay_conversion is probably wrong for references to functions. */ | |
6230 | init = decay_conversion (instantiate_type (TREE_TYPE (type), init, 1)); | |
6231 | ||
8d08fdba MS |
6232 | if (TREE_CODE (init) == TREE_LIST) |
6233 | init = build_compound_expr (init); | |
8d08fdba | 6234 | |
8ccc31eb MS |
6235 | if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE) |
6236 | init = convert_from_reference (init); | |
6237 | ||
8d08fdba MS |
6238 | if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE |
6239 | && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE) | |
6240 | { | |
a3203465 | 6241 | /* Note: default conversion is only called in very special cases. */ |
8d08fdba MS |
6242 | init = default_conversion (init); |
6243 | } | |
6244 | ||
a3203465 | 6245 | tmp = convert_to_reference |
9a3b49ac MS |
6246 | (type, init, CONV_IMPLICIT, |
6247 | LOOKUP_SPECULATIVELY|LOOKUP_NORMAL|DIRECT_BIND, decl); | |
8d08fdba | 6248 | |
a3203465 MS |
6249 | if (tmp == error_mark_node) |
6250 | goto fail; | |
6251 | else if (tmp != NULL_TREE) | |
8d08fdba | 6252 | { |
a3203465 | 6253 | init = tmp; |
4c7bdca6 | 6254 | DECL_INITIAL (decl) = save_expr (init); |
8d08fdba | 6255 | } |
a3203465 | 6256 | else |
8d08fdba | 6257 | { |
a3203465 MS |
6258 | cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init)); |
6259 | goto fail; | |
8d08fdba | 6260 | } |
8d08fdba | 6261 | |
8d08fdba MS |
6262 | /* ?? Can this be optimized in some cases to |
6263 | hand back the DECL_INITIAL slot?? */ | |
6264 | if (TYPE_SIZE (TREE_TYPE (type))) | |
6265 | { | |
6266 | init = convert_from_reference (decl); | |
6267 | if (TREE_PERMANENT (decl)) | |
6268 | init = copy_to_permanent (init); | |
6269 | SET_DECL_REFERENCE_SLOT (decl, init); | |
6270 | } | |
6271 | ||
6272 | if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl))) | |
6273 | { | |
6274 | expand_static_init (decl, DECL_INITIAL (decl)); | |
6275 | DECL_INITIAL (decl) = NULL_TREE; | |
6276 | } | |
6277 | return; | |
6278 | ||
6279 | fail: | |
6280 | if (TREE_CODE (decl) == VAR_DECL) | |
6281 | SET_DECL_REFERENCE_SLOT (decl, error_mark_node); | |
6282 | return; | |
6283 | } | |
6284 | ||
6060a796 MS |
6285 | /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from |
6286 | mucking with forces it does not comprehend (i.e. initialization with a | |
6287 | constructor). If we are at global scope and won't go into COMMON, fill | |
6288 | it in with a dummy CONSTRUCTOR to force the variable into .data; | |
6289 | otherwise we can use error_mark_node. */ | |
6290 | ||
28cbf42c MS |
6291 | static tree |
6292 | obscure_complex_init (decl, init) | |
6293 | tree decl, init; | |
6060a796 | 6294 | { |
28cbf42c MS |
6295 | if (! flag_no_inline && TREE_STATIC (decl)) |
6296 | { | |
6297 | if (extract_init (decl, init)) | |
6298 | return NULL_TREE; | |
6299 | } | |
6300 | ||
2ee887f2 | 6301 | #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) |
a9aedbc2 | 6302 | if (toplevel_bindings_p () && ! DECL_COMMON (decl)) |
6060a796 MS |
6303 | DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE, |
6304 | NULL_TREE); | |
6305 | else | |
2ee887f2 | 6306 | #endif |
6060a796 | 6307 | DECL_INITIAL (decl) = error_mark_node; |
28cbf42c MS |
6308 | |
6309 | return init; | |
6060a796 MS |
6310 | } |
6311 | ||
8d08fdba MS |
6312 | /* Finish processing of a declaration; |
6313 | install its line number and initial value. | |
6314 | If the length of an array type is not known before, | |
6315 | it must be determined now, from the initial value, or it is an error. | |
6316 | ||
6317 | Call `pop_obstacks' iff NEED_POP is nonzero. | |
6318 | ||
82580166 | 6319 | For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers |
8d08fdba MS |
6320 | for aggregates that have constructors alive on the permanent obstack, |
6321 | so that the global initializing functions can be written at the end. | |
6322 | ||
6323 | INIT0 holds the value of an initializer that should be allowed to escape | |
6324 | the normal rules. | |
6325 | ||
6060a796 MS |
6326 | FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0 |
6327 | if the (init) syntax was used. | |
6328 | ||
8d08fdba | 6329 | For functions that take default parameters, DECL points to its |
82580166 | 6330 | "maximal" instantiation. `cp_finish_decl' must then also declared its |
8d08fdba MS |
6331 | subsequently lower and lower forms of instantiation, checking for |
6332 | ambiguity as it goes. This can be sped up later. */ | |
6333 | ||
6334 | void | |
82580166 | 6335 | cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) |
8d08fdba MS |
6336 | tree decl, init; |
6337 | tree asmspec_tree; | |
6338 | int need_pop; | |
6060a796 | 6339 | int flags; |
8d08fdba MS |
6340 | { |
6341 | register tree type; | |
a703fb38 | 6342 | tree cleanup = NULL_TREE, ttype = NULL_TREE; |
8d08fdba MS |
6343 | int was_incomplete; |
6344 | int temporary = allocation_temporary_p (); | |
6345 | char *asmspec = NULL; | |
6346 | int was_readonly = 0; | |
0c4b14c4 | 6347 | int already_used = 0; |
8d08fdba MS |
6348 | |
6349 | /* If this is 0, then we did not change obstacks. */ | |
6350 | if (! decl) | |
6351 | { | |
6352 | if (init) | |
6353 | error ("assignment (not initialization) in declaration"); | |
6354 | return; | |
6355 | } | |
6356 | ||
a4443a08 | 6357 | /* If a name was specified, get the string. */ |
8d08fdba | 6358 | if (asmspec_tree) |
8d08fdba | 6359 | asmspec = TREE_STRING_POINTER (asmspec_tree); |
8d08fdba MS |
6360 | |
6361 | /* If the type of the thing we are declaring either has | |
6362 | a constructor, or has a virtual function table pointer, | |
6363 | AND its initialization was accepted by `start_decl', | |
6364 | then we stayed on the permanent obstack through the | |
6365 | declaration, otherwise, changed obstacks as GCC would. */ | |
6366 | ||
6367 | type = TREE_TYPE (decl); | |
6368 | ||
f376e137 | 6369 | if (type == error_mark_node) |
eac293a1 | 6370 | { |
a9aedbc2 | 6371 | if (toplevel_bindings_p () && temporary) |
eac293a1 MS |
6372 | end_temporary_allocation (); |
6373 | ||
6374 | return; | |
6375 | } | |
f376e137 | 6376 | |
5156628f | 6377 | if (processing_template_decl) |
5566b478 MS |
6378 | { |
6379 | if (init && DECL_INITIAL (decl)) | |
6380 | DECL_INITIAL (decl) = init; | |
faf5394a | 6381 | if (minimal_parse_mode && ! DECL_ARTIFICIAL (decl)) |
5566b478 MS |
6382 | { |
6383 | tree stmt = DECL_VINDEX (decl); | |
e1467ff2 | 6384 | /* If the decl is declaring a member of a local class (in a |
8857f91e MM |
6385 | template function), the DECL_VINDEX will either be NULL, |
6386 | or it will be an actual virtual function index, not a | |
6387 | DECL_STMT. */ | |
6388 | if (stmt != NULL_TREE && TREE_CODE (stmt) == DECL_STMT) | |
75650646 MM |
6389 | { |
6390 | DECL_VINDEX (decl) = NULL_TREE; | |
6391 | TREE_OPERAND (stmt, 2) = copy_to_permanent (init); | |
6392 | add_tree (stmt); | |
6393 | } | |
5566b478 | 6394 | } |
8d08fdba | 6395 | |
5566b478 MS |
6396 | goto finish_end0; |
6397 | } | |
8d08fdba MS |
6398 | /* Take care of TYPE_DECLs up front. */ |
6399 | if (TREE_CODE (decl) == TYPE_DECL) | |
6400 | { | |
6401 | if (init && DECL_INITIAL (decl)) | |
6402 | { | |
6403 | /* typedef foo = bar; store the type of bar as the type of foo. */ | |
6404 | TREE_TYPE (decl) = type = TREE_TYPE (init); | |
6405 | DECL_INITIAL (decl) = init = NULL_TREE; | |
6406 | } | |
a0a33927 MS |
6407 | if (type != error_mark_node |
6408 | && IS_AGGR_TYPE (type) && DECL_NAME (decl)) | |
8d08fdba MS |
6409 | { |
6410 | if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type) | |
6411 | cp_warning ("shadowing previous type declaration of `%#D'", decl); | |
6412 | set_identifier_type_value (DECL_NAME (decl), type); | |
6413 | CLASSTYPE_GOT_SEMICOLON (type) = 1; | |
6414 | } | |
6415 | GNU_xref_decl (current_function_decl, decl); | |
cffa8729 MS |
6416 | |
6417 | /* If we have installed this as the canonical typedef for this | |
6418 | type, and that type has not been defined yet, delay emitting | |
956d6950 | 6419 | the debug information for it, as we will emit it later. */ |
d2e5ee5c | 6420 | if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl |
cffa8729 MS |
6421 | && TYPE_SIZE (TREE_TYPE (decl)) == NULL_TREE) |
6422 | TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; | |
6423 | ||
8d08fdba | 6424 | rest_of_decl_compilation (decl, NULL_PTR, |
5566b478 | 6425 | DECL_CONTEXT (decl) == NULL_TREE, at_eof); |
8d08fdba MS |
6426 | goto finish_end; |
6427 | } | |
8d08fdba MS |
6428 | if (TREE_CODE (decl) != FUNCTION_DECL) |
6429 | { | |
6430 | ttype = target_type (type); | |
8d08fdba MS |
6431 | } |
6432 | ||
6433 | if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) | |
6434 | && TYPE_NEEDS_CONSTRUCTING (type)) | |
6435 | { | |
6436 | ||
6437 | /* Currently, GNU C++ puts constants in text space, making them | |
6438 | impossible to initialize. In the future, one would hope for | |
6439 | an operating system which understood the difference between | |
6440 | initialization and the running of a program. */ | |
6441 | was_readonly = 1; | |
6442 | TREE_READONLY (decl) = 0; | |
6443 | } | |
6444 | ||
6445 | if (TREE_CODE (decl) == FIELD_DECL) | |
6446 | { | |
6447 | if (init && init != error_mark_node) | |
6448 | my_friendly_assert (TREE_PERMANENT (init), 147); | |
6449 | ||
6450 | if (asmspec) | |
6451 | { | |
6452 | /* This must override the asm specifier which was placed | |
6060a796 | 6453 | by grokclassfn. Lay this out fresh. */ |
8d08fdba MS |
6454 | DECL_RTL (TREE_TYPE (decl)) = NULL_RTX; |
6455 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
6456 | make_decl_rtl (decl, asmspec, 0); | |
6457 | } | |
6458 | } | |
6459 | /* If `start_decl' didn't like having an initialization, ignore it now. */ | |
6460 | else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) | |
6461 | init = NULL_TREE; | |
6462 | else if (DECL_EXTERNAL (decl)) | |
6463 | ; | |
6464 | else if (TREE_CODE (type) == REFERENCE_TYPE | |
6465 | || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type))) | |
6466 | { | |
f376e137 MS |
6467 | if (TREE_STATIC (decl)) |
6468 | make_decl_rtl (decl, NULL_PTR, | |
a9aedbc2 | 6469 | toplevel_bindings_p () |
f376e137 | 6470 | || pseudo_global_level_p ()); |
a703fb38 | 6471 | grok_reference_init (decl, type, init); |
8d08fdba MS |
6472 | init = NULL_TREE; |
6473 | } | |
6474 | ||
6475 | GNU_xref_decl (current_function_decl, decl); | |
6476 | ||
a0a33927 | 6477 | if (TREE_CODE (decl) == FIELD_DECL) |
8d08fdba MS |
6478 | ; |
6479 | else if (TREE_CODE (decl) == CONST_DECL) | |
6480 | { | |
6481 | my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); | |
6482 | ||
6483 | DECL_INITIAL (decl) = init; | |
6484 | ||
6485 | /* This will keep us from needing to worry about our obstacks. */ | |
6486 | my_friendly_assert (init != NULL_TREE, 149); | |
6487 | init = NULL_TREE; | |
6488 | } | |
6489 | else if (init) | |
6490 | { | |
6491 | if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type)) | |
6492 | { | |
6493 | if (TREE_CODE (type) == ARRAY_TYPE) | |
6494 | init = digest_init (type, init, (tree *) 0); | |
a3203465 | 6495 | else if (TREE_CODE (init) == CONSTRUCTOR) |
8d08fdba | 6496 | { |
f30432d7 | 6497 | if (TYPE_NON_AGGREGATE_CLASS (type)) |
8d08fdba | 6498 | { |
a28e3c7f MS |
6499 | cp_error ("`%D' must be initialized by constructor, not by `{...}'", |
6500 | decl); | |
8d08fdba MS |
6501 | init = error_mark_node; |
6502 | } | |
6503 | else | |
6504 | goto dont_use_constructor; | |
6505 | } | |
8d08fdba MS |
6506 | } |
6507 | else | |
6508 | { | |
6509 | dont_use_constructor: | |
6510 | if (TREE_CODE (init) != TREE_VEC) | |
6511 | init = store_init_value (decl, init); | |
8d08fdba | 6512 | } |
28cbf42c MS |
6513 | |
6514 | if (init) | |
6515 | /* We must hide the initializer so that expand_decl | |
6516 | won't try to do something it does not understand. */ | |
6517 | init = obscure_complex_init (decl, init); | |
8d08fdba | 6518 | } |
a0a33927 MS |
6519 | else if (DECL_EXTERNAL (decl)) |
6520 | ; | |
8d08fdba MS |
6521 | else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't' |
6522 | && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))) | |
6523 | { | |
6524 | tree ctype = type; | |
6525 | while (TREE_CODE (ctype) == ARRAY_TYPE) | |
6526 | ctype = TREE_TYPE (ctype); | |
6527 | if (! TYPE_NEEDS_CONSTRUCTING (ctype)) | |
6528 | { | |
6529 | if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype)) | |
6530 | cp_error ("structure `%D' with uninitialized const members", decl); | |
6531 | if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype)) | |
a28e3c7f MS |
6532 | cp_error ("structure `%D' with uninitialized reference members", |
6533 | decl); | |
8d08fdba MS |
6534 | } |
6535 | ||
6536 | if (TREE_CODE (decl) == VAR_DECL | |
6537 | && !DECL_INITIAL (decl) | |
6538 | && !TYPE_NEEDS_CONSTRUCTING (type) | |
6539 | && (TYPE_READONLY (type) || TREE_READONLY (decl))) | |
6540 | cp_error ("uninitialized const `%D'", decl); | |
6541 | ||
6060a796 MS |
6542 | if (TYPE_SIZE (type) != NULL_TREE |
6543 | && TYPE_NEEDS_CONSTRUCTING (type)) | |
28cbf42c | 6544 | init = obscure_complex_init (decl, NULL_TREE); |
8d08fdba MS |
6545 | } |
6546 | else if (TREE_CODE (decl) == VAR_DECL | |
6547 | && TREE_CODE (type) != REFERENCE_TYPE | |
6548 | && (TYPE_READONLY (type) || TREE_READONLY (decl))) | |
6549 | { | |
6550 | /* ``Unless explicitly declared extern, a const object does not have | |
6551 | external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 | |
6552 | However, if it's `const int foo = 1; const int foo;', don't complain | |
6553 | about the second decl, since it does have an initializer before. | |
6554 | We deliberately don't complain about arrays, because they're | |
6555 | supposed to be initialized by a constructor. */ | |
6556 | if (! DECL_INITIAL (decl) | |
6557 | && TREE_CODE (type) != ARRAY_TYPE | |
6558 | && (!pedantic || !current_class_type)) | |
6559 | cp_error ("uninitialized const `%#D'", decl); | |
6560 | } | |
6561 | ||
6562 | /* For top-level declaration, the initial value was read in | |
6563 | the temporary obstack. MAXINDEX, rtl, etc. to be made below | |
6564 | must go in the permanent obstack; but don't discard the | |
6565 | temporary data yet. */ | |
6566 | ||
a9aedbc2 | 6567 | if (toplevel_bindings_p () && temporary) |
8d08fdba MS |
6568 | end_temporary_allocation (); |
6569 | ||
6570 | /* Deduce size of array from initialization, if not already known. */ | |
6571 | ||
6572 | if (TREE_CODE (type) == ARRAY_TYPE | |
6573 | && TYPE_DOMAIN (type) == NULL_TREE | |
6574 | && TREE_CODE (decl) != TYPE_DECL) | |
6575 | { | |
6576 | int do_default | |
6577 | = (TREE_STATIC (decl) | |
6578 | /* Even if pedantic, an external linkage array | |
6579 | may have incomplete type at first. */ | |
6580 | ? pedantic && ! DECL_EXTERNAL (decl) | |
6581 | : !DECL_EXTERNAL (decl)); | |
6582 | tree initializer = init ? init : DECL_INITIAL (decl); | |
6583 | int failure = complete_array_type (type, initializer, do_default); | |
6584 | ||
6585 | if (failure == 1) | |
6586 | cp_error ("initializer fails to determine size of `%D'", decl); | |
6587 | ||
6588 | if (failure == 2) | |
6589 | { | |
6590 | if (do_default) | |
6591 | cp_error ("array size missing in `%D'", decl); | |
6592 | /* If a `static' var's size isn't known, make it extern as | |
6593 | well as static, so it does not get allocated. If it's not | |
6594 | `static', then don't mark it extern; finish_incomplete_decl | |
6595 | will give it a default size and it will get allocated. */ | |
6596 | else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) | |
6597 | DECL_EXTERNAL (decl) = 1; | |
6598 | } | |
6599 | ||
6600 | if (pedantic && TYPE_DOMAIN (type) != NULL_TREE | |
6601 | && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), | |
6602 | integer_zero_node)) | |
6603 | cp_error ("zero-size array `%D'", decl); | |
6604 | ||
6605 | layout_decl (decl, 0); | |
6606 | } | |
6607 | ||
6608 | if (TREE_CODE (decl) == VAR_DECL) | |
6609 | { | |
6610 | if (DECL_SIZE (decl) == NULL_TREE | |
ec255269 | 6611 | && TYPE_SIZE (complete_type (TREE_TYPE (decl))) != NULL_TREE) |
8d08fdba MS |
6612 | layout_decl (decl, 0); |
6613 | ||
6614 | if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) | |
6615 | { | |
6616 | /* A static variable with an incomplete type: | |
6617 | that is an error if it is initialized. | |
6618 | Otherwise, let it through, but if it is not `extern' | |
6619 | then it may cause an error message later. */ | |
6620 | if (DECL_INITIAL (decl) != NULL_TREE) | |
6621 | cp_error ("storage size of `%D' isn't known", decl); | |
6622 | init = NULL_TREE; | |
6623 | } | |
6624 | else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) | |
6625 | { | |
6626 | /* An automatic variable with an incomplete type: that is an error. | |
6627 | Don't talk about array types here, since we took care of that | |
6628 | message in grokdeclarator. */ | |
6629 | cp_error ("storage size of `%D' isn't known", decl); | |
6630 | TREE_TYPE (decl) = error_mark_node; | |
6631 | } | |
6632 | else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) | |
6633 | /* Let debugger know it should output info for this type. */ | |
6634 | note_debug_info_needed (ttype); | |
6635 | ||
d2e5ee5c MS |
6636 | if (TREE_STATIC (decl) && DECL_CONTEXT (decl) |
6637 | && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't') | |
6638 | note_debug_info_needed (DECL_CONTEXT (decl)); | |
6639 | ||
8d08fdba MS |
6640 | if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) |
6641 | && DECL_SIZE (decl) != NULL_TREE | |
6642 | && ! TREE_CONSTANT (DECL_SIZE (decl))) | |
6643 | { | |
6644 | if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) | |
6645 | constant_expression_warning (DECL_SIZE (decl)); | |
6646 | else | |
6647 | cp_error ("storage size of `%D' isn't constant", decl); | |
6648 | } | |
6649 | ||
c91a56d2 MS |
6650 | if (! DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type) |
6651 | /* Cleanups for static variables are handled by `finish_file'. */ | |
6652 | && ! TREE_STATIC (decl)) | |
8d08fdba MS |
6653 | { |
6654 | int yes = suspend_momentary (); | |
2ee887f2 | 6655 | cleanup = maybe_build_cleanup (decl); |
8d08fdba MS |
6656 | resume_momentary (yes); |
6657 | } | |
6658 | } | |
6659 | /* PARM_DECLs get cleanups, too. */ | |
6660 | else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type)) | |
6661 | { | |
6662 | if (temporary) | |
6663 | end_temporary_allocation (); | |
6664 | cleanup = maybe_build_cleanup (decl); | |
6665 | if (temporary) | |
6666 | resume_temporary_allocation (); | |
6667 | } | |
6668 | ||
6669 | /* Output the assembler code and/or RTL code for variables and functions, | |
6670 | unless the type is an undefined structure or union. | |
6671 | If not, it will get done when the type is completed. */ | |
6672 | ||
5566b478 MS |
6673 | was_incomplete = (DECL_SIZE (decl) == NULL_TREE); |
6674 | ||
8d08fdba MS |
6675 | if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL |
6676 | || TREE_CODE (decl) == RESULT_DECL) | |
6677 | { | |
6678 | /* ??? FIXME: What about nested classes? */ | |
e1467ff2 | 6679 | int toplev = toplevel_bindings_p () || pseudo_global_level_p (); |
8d08fdba | 6680 | int was_temp |
d22c8596 | 6681 | = (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type) |
8d08fdba MS |
6682 | && allocation_temporary_p ()); |
6683 | ||
6684 | if (was_temp) | |
6685 | end_temporary_allocation (); | |
6686 | ||
42976354 BK |
6687 | /* Extern inline function static data has external linkage. */ |
6688 | if (TREE_CODE (decl) == VAR_DECL | |
6689 | && TREE_STATIC (decl) | |
6690 | && current_function_decl | |
6691 | && DECL_CONTEXT (decl) == current_function_decl | |
6692 | && DECL_THIS_INLINE (current_function_decl) | |
893de33c | 6693 | && TREE_PUBLIC (current_function_decl)) |
42976354 | 6694 | { |
818045b6 JM |
6695 | if (DECL_INTERFACE_KNOWN (current_function_decl)) |
6696 | { | |
6697 | TREE_PUBLIC (decl) = 1; | |
6698 | DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl); | |
6699 | } | |
42976354 BK |
6700 | /* We can only do this if we can use common or weak, and we |
6701 | can't if it has been initialized and we don't support weak. */ | |
818045b6 JM |
6702 | else if (DECL_INITIAL (decl) == NULL_TREE |
6703 | || DECL_INITIAL (decl) == error_mark_node) | |
42976354 BK |
6704 | { |
6705 | TREE_PUBLIC (decl) = 1; | |
6706 | DECL_COMMON (decl) = 1; | |
6707 | } | |
6708 | else if (flag_weak) | |
6709 | make_decl_one_only (decl); | |
6710 | ||
6711 | if (TREE_PUBLIC (decl)) | |
6712 | DECL_ASSEMBLER_NAME (decl) | |
6713 | = build_static_name (current_function_decl, DECL_NAME (decl)); | |
6714 | else if (! DECL_ARTIFICIAL (decl)) | |
6715 | cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl); | |
6716 | } | |
6717 | ||
77be6f82 JM |
6718 | else if (TREE_CODE (decl) == VAR_DECL |
6719 | && DECL_LANG_SPECIFIC (decl) | |
6720 | && DECL_COMDAT (decl)) | |
6721 | { | |
6722 | /* Dynamically initialized vars go into common. */ | |
6723 | if (DECL_INITIAL (decl) == NULL_TREE | |
6724 | || DECL_INITIAL (decl) == error_mark_node) | |
6725 | DECL_COMMON (decl) = 1; | |
6726 | else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) | |
6727 | { | |
6728 | DECL_COMMON (decl) = 1; | |
6729 | DECL_INITIAL (decl) = error_mark_node; | |
6730 | } | |
6731 | else | |
6732 | { | |
6733 | /* Statically initialized vars are weak or comdat, if | |
6734 | supported. */ | |
6735 | if (flag_weak) | |
6736 | make_decl_one_only (decl); | |
6737 | else | |
be343556 JM |
6738 | { |
6739 | /* we can't do anything useful; leave vars for explicit | |
6740 | instantiation. */ | |
6741 | DECL_EXTERNAL (decl) = 1; | |
6742 | DECL_NOT_REALLY_EXTERN (decl) = 0; | |
6743 | } | |
77be6f82 JM |
6744 | } |
6745 | } | |
6746 | ||
8d08fdba MS |
6747 | if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) |
6748 | make_decl_rtl (decl, NULL_PTR, toplev); | |
6749 | else if (TREE_CODE (decl) == VAR_DECL | |
6750 | && TREE_READONLY (decl) | |
6751 | && DECL_INITIAL (decl) != NULL_TREE | |
6752 | && DECL_INITIAL (decl) != error_mark_node | |
a3203465 | 6753 | && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) |
8d08fdba MS |
6754 | { |
6755 | DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); | |
6756 | ||
6757 | if (asmspec) | |
6758 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
6759 | ||
6760 | if (! toplev | |
6761 | && TREE_STATIC (decl) | |
6762 | && ! TREE_SIDE_EFFECTS (decl) | |
6763 | && ! TREE_PUBLIC (decl) | |
6764 | && ! DECL_EXTERNAL (decl) | |
6765 | && ! TYPE_NEEDS_DESTRUCTOR (type) | |
6766 | && DECL_MODE (decl) != BLKmode) | |
6767 | { | |
6768 | /* If this variable is really a constant, then fill its DECL_RTL | |
6769 | slot with something which won't take up storage. | |
6770 | If something later should take its address, we can always give | |
6771 | it legitimate RTL at that time. */ | |
6772 | DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); | |
6773 | store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0); | |
6774 | TREE_ASM_WRITTEN (decl) = 1; | |
6775 | } | |
a0a33927 | 6776 | else if (toplev && ! TREE_PUBLIC (decl)) |
8d08fdba | 6777 | { |
8d08fdba | 6778 | /* If this is a static const, change its apparent linkage |
db5ae43f | 6779 | if it belongs to a #pragma interface. */ |
a0a33927 | 6780 | if (!interface_unknown) |
8d08fdba MS |
6781 | { |
6782 | TREE_PUBLIC (decl) = 1; | |
6783 | DECL_EXTERNAL (decl) = interface_only; | |
6784 | } | |
6785 | make_decl_rtl (decl, asmspec, toplev); | |
6786 | } | |
6787 | else | |
5566b478 | 6788 | rest_of_decl_compilation (decl, asmspec, toplev, at_eof); |
8d08fdba MS |
6789 | } |
6790 | else if (TREE_CODE (decl) == VAR_DECL | |
6791 | && DECL_LANG_SPECIFIC (decl) | |
6792 | && DECL_IN_AGGR_P (decl)) | |
6793 | { | |
6794 | if (TREE_STATIC (decl)) | |
6795 | { | |
6796 | if (init == NULL_TREE | |
6797 | #ifdef DEFAULT_STATIC_DEFS | |
6798 | /* If this code is dead, then users must | |
6799 | explicitly declare static member variables | |
6800 | outside the class def'n as well. */ | |
6801 | && TYPE_NEEDS_CONSTRUCTING (type) | |
6802 | #endif | |
6803 | ) | |
6804 | { | |
6805 | DECL_EXTERNAL (decl) = 1; | |
6806 | make_decl_rtl (decl, asmspec, 1); | |
6807 | } | |
6808 | else | |
5566b478 | 6809 | rest_of_decl_compilation (decl, asmspec, toplev, at_eof); |
8d08fdba MS |
6810 | } |
6811 | else | |
6812 | /* Just a constant field. Should not need any rtl. */ | |
6813 | goto finish_end0; | |
6814 | } | |
6815 | else | |
5566b478 | 6816 | rest_of_decl_compilation (decl, asmspec, toplev, at_eof); |
8d08fdba MS |
6817 | |
6818 | if (was_temp) | |
6819 | resume_temporary_allocation (); | |
6820 | ||
6821 | if (type != error_mark_node | |
6822 | && TYPE_LANG_SPECIFIC (type) | |
6823 | && CLASSTYPE_ABSTRACT_VIRTUALS (type)) | |
6824 | abstract_virtuals_error (decl, type); | |
6825 | else if ((TREE_CODE (type) == FUNCTION_TYPE | |
6826 | || TREE_CODE (type) == METHOD_TYPE) | |
6827 | && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) | |
6828 | && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type))) | |
6829 | abstract_virtuals_error (decl, TREE_TYPE (type)); | |
6830 | ||
6831 | if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type)) | |
6832 | signature_error (decl, type); | |
6833 | else if ((TREE_CODE (type) == FUNCTION_TYPE | |
6834 | || TREE_CODE (type) == METHOD_TYPE) | |
6835 | && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) | |
6836 | && IS_SIGNATURE (TREE_TYPE (type))) | |
6837 | signature_error (decl, TREE_TYPE (type)); | |
6838 | ||
6839 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
faae18ab | 6840 | ; |
67d743fe MS |
6841 | else if (DECL_EXTERNAL (decl) |
6842 | && ! (DECL_LANG_SPECIFIC (decl) | |
6843 | && DECL_NOT_REALLY_EXTERN (decl))) | |
5566b478 MS |
6844 | { |
6845 | if (init) | |
6846 | DECL_INITIAL (decl) = init; | |
6847 | } | |
8d08fdba MS |
6848 | else if (TREE_STATIC (decl) && type != error_mark_node) |
6849 | { | |
6850 | /* Cleanups for static variables are handled by `finish_file'. */ | |
f30432d7 MS |
6851 | if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE |
6852 | || TYPE_NEEDS_DESTRUCTOR (type)) | |
8d08fdba | 6853 | expand_static_init (decl, init); |
8d08fdba MS |
6854 | } |
6855 | else if (! toplev) | |
6856 | { | |
6857 | /* This is a declared decl which must live until the | |
6858 | end of the binding contour. It may need a cleanup. */ | |
6859 | ||
6860 | /* Recompute the RTL of a local array now | |
6861 | if it used to be an incomplete type. */ | |
6862 | if (was_incomplete && ! TREE_STATIC (decl)) | |
6863 | { | |
6864 | /* If we used it already as memory, it must stay in memory. */ | |
6865 | TREE_ADDRESSABLE (decl) = TREE_USED (decl); | |
6866 | /* If it's still incomplete now, no init will save it. */ | |
6867 | if (DECL_SIZE (decl) == NULL_TREE) | |
6868 | DECL_INITIAL (decl) = NULL_TREE; | |
6869 | expand_decl (decl); | |
6870 | } | |
6871 | else if (! TREE_ASM_WRITTEN (decl) | |
6872 | && (TYPE_SIZE (type) != NULL_TREE | |
6873 | || TREE_CODE (type) == ARRAY_TYPE)) | |
6874 | { | |
6875 | /* Do this here, because we did not expand this decl's | |
6876 | rtl in start_decl. */ | |
6877 | if (DECL_RTL (decl) == NULL_RTX) | |
6878 | expand_decl (decl); | |
6879 | else if (cleanup) | |
6880 | { | |
8d2733ca MS |
6881 | /* XXX: Why don't we use decl here? */ |
6882 | /* Ans: Because it was already expanded? */ | |
e349ee73 | 6883 | if (! expand_decl_cleanup (NULL_TREE, cleanup)) |
8d2733ca MS |
6884 | cp_error ("parser lost in parsing declaration of `%D'", |
6885 | decl); | |
8d08fdba MS |
6886 | /* Cleanup used up here. */ |
6887 | cleanup = NULL_TREE; | |
6888 | } | |
6889 | } | |
6890 | ||
2ee887f2 MS |
6891 | if (current_binding_level->is_for_scope) |
6892 | { | |
6893 | struct binding_level *outer = current_binding_level->level_chain; | |
6894 | ||
6895 | /* Check to see if the same name is already bound at | |
6896 | the outer level, either because it was directly declared, | |
6897 | or because a dead for-decl got preserved. In either case, | |
d22c8596 | 6898 | the code would not have been valid under the ARM |
2ee887f2 MS |
6899 | scope rules, so clear is_for_scope for the |
6900 | current_binding_level. | |
6901 | ||
6902 | Otherwise, we need to preserve the temp slot for decl | |
e92cc029 | 6903 | to last into the outer binding level. */ |
2ee887f2 MS |
6904 | |
6905 | int handling_dead_for_vars = 0; | |
6906 | tree link = outer->names; | |
6907 | for (; ; link = TREE_CHAIN (link)) | |
6908 | { | |
6909 | if (link == NULL && handling_dead_for_vars == 0) | |
6910 | { | |
6911 | link = outer->dead_vars_from_for; | |
6912 | handling_dead_for_vars = 1; | |
6913 | } | |
6914 | if (link == NULL) | |
6915 | { | |
cffa8729 | 6916 | if (DECL_IN_MEMORY_P (decl)) |
2ee887f2 MS |
6917 | preserve_temp_slots (DECL_RTL (decl)); |
6918 | break; | |
6919 | } | |
6920 | if (DECL_NAME (link) == DECL_NAME (decl)) | |
6921 | { | |
6922 | if (handling_dead_for_vars) | |
6923 | { | |
6924 | tree shadowing | |
6925 | = purpose_member (DECL_NAME (decl), | |
6926 | current_binding_level->shadowed); | |
6927 | if (shadowing && TREE_VALUE (shadowing) == link) | |
6928 | TREE_VALUE (shadowing) | |
6929 | = DECL_SHADOWED_FOR_VAR (link); | |
6930 | } | |
6931 | current_binding_level->is_for_scope = 0; | |
6932 | break; | |
6933 | } | |
6934 | } | |
6935 | } | |
6936 | ||
eb66be0e | 6937 | expand_start_target_temps (); |
72b7eeff | 6938 | |
8d08fdba MS |
6939 | if (DECL_SIZE (decl) && type != error_mark_node) |
6940 | { | |
6941 | /* Compute and store the initial value. */ | |
6942 | expand_decl_init (decl); | |
0c4b14c4 | 6943 | already_used = TREE_USED (decl) || TREE_USED (type); |
8d08fdba MS |
6944 | |
6945 | if (init || TYPE_NEEDS_CONSTRUCTING (type)) | |
6946 | { | |
a28e3c7f MS |
6947 | emit_line_note (DECL_SOURCE_FILE (decl), |
6948 | DECL_SOURCE_LINE (decl)); | |
6060a796 | 6949 | expand_aggr_init (decl, init, 0, flags); |
8d08fdba MS |
6950 | } |
6951 | ||
00595019 MS |
6952 | /* Set this to 0 so we can tell whether an aggregate which |
6953 | was initialized was ever used. Don't do this if it has a | |
6954 | destructor, so we don't complain about the 'resource | |
6955 | allocation is initialization' idiom. */ | |
249555b0 BK |
6956 | /* Now set attribute((unused)) on types so decls of |
6957 | of that type will be marked used. (see TREE_USED, above.) | |
6958 | This avoids the warning problems this particular code | |
6959 | tried to work around. */ | |
0c4b14c4 | 6960 | |
be99da77 | 6961 | if (TYPE_NEEDS_CONSTRUCTING (type) |
0c4b14c4 | 6962 | && ! already_used |
be99da77 MS |
6963 | && cleanup == NULL_TREE |
6964 | && DECL_NAME (decl)) | |
8d08fdba | 6965 | TREE_USED (decl) = 0; |
0c4b14c4 JM |
6966 | |
6967 | if (already_used) | |
6968 | TREE_USED (decl) = 1; | |
934c6b13 | 6969 | } |
eb66be0e | 6970 | |
934c6b13 | 6971 | /* Cleanup any temporaries needed for the initial value. */ |
eb66be0e | 6972 | expand_end_target_temps (); |
8d08fdba | 6973 | |
934c6b13 MS |
6974 | if (DECL_SIZE (decl) && type != error_mark_node) |
6975 | { | |
8d08fdba MS |
6976 | /* Store the cleanup, if there was one. */ |
6977 | if (cleanup) | |
6978 | { | |
e349ee73 | 6979 | if (! expand_decl_cleanup (decl, cleanup)) |
a28e3c7f MS |
6980 | cp_error ("parser lost in parsing declaration of `%D'", |
6981 | decl); | |
8d08fdba MS |
6982 | } |
6983 | } | |
6984 | } | |
6985 | finish_end0: | |
6986 | ||
6987 | /* Undo call to `pushclass' that was done in `start_decl' | |
6988 | due to initialization of qualified member variable. | |
6989 | I.e., Foo::x = 10; */ | |
6990 | { | |
f30432d7 | 6991 | tree context = DECL_REAL_CONTEXT (decl); |
8d08fdba MS |
6992 | if (context |
6993 | && TREE_CODE_CLASS (TREE_CODE (context)) == 't' | |
6994 | && (TREE_CODE (decl) == VAR_DECL | |
6995 | /* We also have a pushclass done that we need to undo here | |
6996 | if we're at top level and declare a method. */ | |
5566b478 MS |
6997 | || TREE_CODE (decl) == FUNCTION_DECL) |
6998 | /* If size hasn't been set, we're still defining it, | |
6999 | and therefore inside the class body; don't pop | |
7000 | the binding level.. */ | |
7001 | && TYPE_SIZE (context) != NULL_TREE | |
7002 | && context == current_class_type) | |
8d08fdba MS |
7003 | popclass (1); |
7004 | } | |
7005 | } | |
7006 | ||
7007 | finish_end: | |
7008 | ||
39211cd5 MS |
7009 | /* If requested, warn about definitions of large data objects. */ |
7010 | ||
7011 | if (warn_larger_than | |
5156628f | 7012 | && ! processing_template_decl |
39211cd5 MS |
7013 | && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) |
7014 | && !DECL_EXTERNAL (decl)) | |
7015 | { | |
7016 | register tree decl_size = DECL_SIZE (decl); | |
7017 | ||
7018 | if (decl_size && TREE_CODE (decl_size) == INTEGER_CST) | |
7019 | { | |
7020 | unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT; | |
7021 | ||
7022 | if (units > larger_than_size) | |
7023 | warning_with_decl (decl, "size of `%s' is %u bytes", units); | |
7024 | } | |
7025 | } | |
7026 | ||
8d08fdba MS |
7027 | if (need_pop) |
7028 | { | |
7029 | /* Resume permanent allocation, if not within a function. */ | |
7030 | /* The corresponding push_obstacks_nochange is in start_decl, | |
7031 | start_method, groktypename, and in grokfield. */ | |
7032 | pop_obstacks (); | |
7033 | } | |
7034 | ||
7035 | if (was_readonly) | |
7036 | TREE_READONLY (decl) = 1; | |
8d08fdba MS |
7037 | } |
7038 | ||
82580166 | 7039 | /* This is here for a midend callback from c-common.c */ |
e92cc029 | 7040 | |
82580166 MS |
7041 | void |
7042 | finish_decl (decl, init, asmspec_tree) | |
7043 | tree decl, init; | |
7044 | tree asmspec_tree; | |
7045 | { | |
7046 | cp_finish_decl (decl, init, asmspec_tree, 1, 0); | |
7047 | } | |
7048 | ||
8d08fdba MS |
7049 | void |
7050 | expand_static_init (decl, init) | |
7051 | tree decl; | |
7052 | tree init; | |
7053 | { | |
7054 | tree oldstatic = value_member (decl, static_aggregates); | |
a4443a08 | 7055 | |
8d08fdba MS |
7056 | if (oldstatic) |
7057 | { | |
7058 | if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) | |
7059 | cp_error ("multiple initializations given for `%D'", decl); | |
7060 | } | |
a9aedbc2 | 7061 | else if (! toplevel_bindings_p () && ! pseudo_global_level_p ()) |
8d08fdba MS |
7062 | { |
7063 | /* Emit code to perform this initialization but once. */ | |
7064 | tree temp; | |
7065 | ||
e92cc029 | 7066 | /* Remember this information until end of file. */ |
8d08fdba MS |
7067 | push_obstacks (&permanent_obstack, &permanent_obstack); |
7068 | ||
7069 | /* Emit code to perform this initialization but once. */ | |
7070 | temp = get_temp_name (integer_type_node, 1); | |
7071 | rest_of_decl_compilation (temp, NULL_PTR, 0, 0); | |
7072 | expand_start_cond (build_binary_op (EQ_EXPR, temp, | |
7073 | integer_zero_node, 1), 0); | |
eb66be0e | 7074 | expand_start_target_temps (); |
72b7eeff | 7075 | |
8d08fdba | 7076 | expand_assignment (temp, integer_one_node, 0, 0); |
28cbf42c | 7077 | if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)) |
f30432d7 | 7078 | || (init && TREE_CODE (init) == TREE_LIST)) |
8d08fdba | 7079 | { |
6060a796 | 7080 | expand_aggr_init (decl, init, 0, 0); |
8d08fdba MS |
7081 | do_pending_stack_adjust (); |
7082 | } | |
f30432d7 | 7083 | else if (init) |
8d08fdba | 7084 | expand_assignment (decl, init, 0, 0); |
f30432d7 | 7085 | |
a4443a08 | 7086 | /* Cleanup any temporaries needed for the initial value. */ |
eb66be0e | 7087 | expand_end_target_temps (); |
72b7eeff MS |
7088 | |
7089 | if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) | |
7090 | { | |
7091 | tree cleanup, fcall; | |
7092 | static tree Atexit = 0; | |
7093 | if (Atexit == 0) | |
7094 | { | |
7095 | tree atexit_fndecl, PFV, pfvlist; | |
e92cc029 | 7096 | /* Remember this information until end of file. */ |
72b7eeff MS |
7097 | push_obstacks (&permanent_obstack, &permanent_obstack); |
7098 | PFV = build_pointer_type (build_function_type | |
7099 | (void_type_node, void_list_node)); | |
7100 | ||
7101 | pfvlist = tree_cons (NULL_TREE, PFV, void_list_node); | |
7102 | ||
7103 | push_lang_context (lang_name_c); | |
beb53fb8 JM |
7104 | atexit_fndecl |
7105 | = builtin_function ("atexit", | |
7106 | build_function_type (void_type_node, | |
7107 | pfvlist), | |
7108 | NOT_BUILT_IN, NULL_PTR); | |
be99da77 | 7109 | assemble_external (atexit_fndecl); |
72b7eeff MS |
7110 | Atexit = default_conversion (atexit_fndecl); |
7111 | pop_lang_context (); | |
7112 | pop_obstacks (); | |
7113 | } | |
7114 | ||
7115 | cleanup = start_anon_func (); | |
7116 | expand_expr_stmt (build_cleanup (decl)); | |
7117 | end_anon_func (); | |
7118 | mark_addressable (cleanup); | |
7119 | cleanup = build_unary_op (ADDR_EXPR, cleanup, 0); | |
e66d884e | 7120 | fcall = build_function_call (Atexit, expr_tree_cons (NULL_TREE, cleanup, NULL_TREE)); |
72b7eeff MS |
7121 | expand_expr_stmt (fcall); |
7122 | } | |
7123 | ||
8d08fdba MS |
7124 | expand_end_cond (); |
7125 | if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) | |
7126 | { | |
7127 | static_aggregates = perm_tree_cons (temp, decl, static_aggregates); | |
7128 | TREE_STATIC (static_aggregates) = 1; | |
7129 | } | |
7130 | ||
e92cc029 | 7131 | /* Resume old (possibly temporary) allocation. */ |
8d08fdba MS |
7132 | pop_obstacks (); |
7133 | } | |
7134 | else | |
7135 | { | |
7136 | /* This code takes into account memory allocation | |
7137 | policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING | |
7138 | does not hold for this object, then we must make permanent | |
7139 | the storage currently in the temporary obstack. */ | |
7140 | if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) | |
7141 | preserve_initializer (); | |
7142 | static_aggregates = perm_tree_cons (init, decl, static_aggregates); | |
7143 | } | |
7144 | } | |
7145 | \f | |
7146 | /* Make TYPE a complete type based on INITIAL_VALUE. | |
7147 | Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, | |
7148 | 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ | |
7149 | ||
7150 | int | |
7151 | complete_array_type (type, initial_value, do_default) | |
7152 | tree type, initial_value; | |
7153 | int do_default; | |
7154 | { | |
7155 | register tree maxindex = NULL_TREE; | |
7156 | int value = 0; | |
7157 | ||
7158 | if (initial_value) | |
7159 | { | |
7160 | /* Note MAXINDEX is really the maximum index, | |
7161 | one less than the size. */ | |
7162 | if (TREE_CODE (initial_value) == STRING_CST) | |
e1cd6e56 MS |
7163 | { |
7164 | int eltsize | |
7165 | = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); | |
7166 | maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) | |
7167 | / eltsize) - 1, 0); | |
7168 | } | |
8d08fdba MS |
7169 | else if (TREE_CODE (initial_value) == CONSTRUCTOR) |
7170 | { | |
e1cd6e56 MS |
7171 | tree elts = CONSTRUCTOR_ELTS (initial_value); |
7172 | maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node); | |
7173 | for (; elts; elts = TREE_CHAIN (elts)) | |
7174 | { | |
7175 | if (TREE_PURPOSE (elts)) | |
7176 | maxindex = TREE_PURPOSE (elts); | |
7177 | else | |
7178 | maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node); | |
7179 | } | |
7180 | maxindex = copy_node (maxindex); | |
8d08fdba MS |
7181 | } |
7182 | else | |
7183 | { | |
7184 | /* Make an error message unless that happened already. */ | |
7185 | if (initial_value != error_mark_node) | |
7186 | value = 1; | |
7187 | ||
7188 | /* Prevent further error messages. */ | |
7189 | maxindex = build_int_2 (0, 0); | |
7190 | } | |
7191 | } | |
7192 | ||
7193 | if (!maxindex) | |
7194 | { | |
7195 | if (do_default) | |
7196 | maxindex = build_int_2 (0, 0); | |
7197 | value = 2; | |
7198 | } | |
7199 | ||
7200 | if (maxindex) | |
7201 | { | |
51c184be MS |
7202 | tree itype; |
7203 | ||
8d08fdba | 7204 | TYPE_DOMAIN (type) = build_index_type (maxindex); |
dff6b454 | 7205 | if (! TREE_TYPE (maxindex)) |
8d08fdba | 7206 | TREE_TYPE (maxindex) = TYPE_DOMAIN (type); |
51c184be MS |
7207 | if (initial_value) |
7208 | itype = TREE_TYPE (initial_value); | |
7209 | else | |
7210 | itype = NULL; | |
7211 | if (itype && !TYPE_DOMAIN (itype)) | |
7212 | TYPE_DOMAIN (itype) = TYPE_DOMAIN (type); | |
dff6b454 RK |
7213 | /* The type of the main variant should never be used for arrays |
7214 | of different sizes. It should only ever be completed with the | |
7215 | size of the array. */ | |
7216 | if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type))) | |
7217 | TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type); | |
8d08fdba MS |
7218 | } |
7219 | ||
7220 | /* Lay out the type now that we can get the real answer. */ | |
7221 | ||
7222 | layout_type (type); | |
7223 | ||
7224 | return value; | |
7225 | } | |
7226 | \f | |
7227 | /* Return zero if something is declared to be a member of type | |
7228 | CTYPE when in the context of CUR_TYPE. STRING is the error | |
7229 | message to print in that case. Otherwise, quietly return 1. */ | |
e92cc029 | 7230 | |
8d08fdba MS |
7231 | static int |
7232 | member_function_or_else (ctype, cur_type, string) | |
7233 | tree ctype, cur_type; | |
7234 | char *string; | |
7235 | { | |
7236 | if (ctype && ctype != cur_type) | |
7237 | { | |
7238 | error (string, TYPE_NAME_STRING (ctype)); | |
7239 | return 0; | |
7240 | } | |
7241 | return 1; | |
7242 | } | |
7243 | \f | |
7244 | /* Subroutine of `grokdeclarator'. */ | |
7245 | ||
7246 | /* Generate errors possibly applicable for a given set of specifiers. | |
7247 | This is for ARM $7.1.2. */ | |
e92cc029 | 7248 | |
8d08fdba MS |
7249 | static void |
7250 | bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) | |
7251 | tree object; | |
7252 | char *type; | |
7253 | int virtualp, quals, friendp, raises, inlinep; | |
7254 | { | |
7255 | if (virtualp) | |
7256 | cp_error ("`%D' declared as a `virtual' %s", object, type); | |
7257 | if (inlinep) | |
7258 | cp_error ("`%D' declared as an `inline' %s", object, type); | |
7259 | if (quals) | |
a28e3c7f MS |
7260 | cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", |
7261 | object, type); | |
8d08fdba MS |
7262 | if (friendp) |
7263 | cp_error_at ("invalid friend declaration", object); | |
7264 | if (raises) | |
6060a796 | 7265 | cp_error_at ("invalid exception specifications", object); |
8d08fdba MS |
7266 | } |
7267 | ||
7268 | /* CTYPE is class type, or null if non-class. | |
7269 | TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE | |
7270 | or METHOD_TYPE. | |
7271 | DECLARATOR is the function's name. | |
7272 | VIRTUALP is truthvalue of whether the function is virtual or not. | |
7273 | FLAGS are to be passed through to `grokclassfn'. | |
7274 | QUALS are qualifiers indicating whether the function is `const' | |
7275 | or `volatile'. | |
7276 | RAISES is a list of exceptions that this function can raise. | |
7277 | CHECK is 1 if we must find this method in CTYPE, 0 if we should | |
7278 | not look, and -1 if we should not call `grokclassfn' at all. */ | |
e92cc029 | 7279 | |
8d08fdba | 7280 | static tree |
386b8a85 JM |
7281 | grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, |
7282 | raises, attrlist, check, friendp, publicp, inlinep, funcdef_flag, | |
7283 | template_count) | |
8d08fdba MS |
7284 | tree ctype, type; |
7285 | tree declarator; | |
386b8a85 | 7286 | tree orig_declarator; |
8d08fdba MS |
7287 | int virtualp; |
7288 | enum overload_flags flags; | |
f30432d7 | 7289 | tree quals, raises, attrlist; |
386b8a85 | 7290 | int check, friendp, publicp, inlinep, funcdef_flag, template_count; |
8d08fdba MS |
7291 | { |
7292 | tree cname, decl; | |
7293 | int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; | |
42976354 | 7294 | tree t; |
8d08fdba MS |
7295 | |
7296 | if (ctype) | |
7297 | cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL | |
7298 | ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype); | |
7299 | else | |
7300 | cname = NULL_TREE; | |
7301 | ||
7302 | if (raises) | |
7303 | { | |
f30432d7 | 7304 | type = build_exception_variant (type, raises); |
8d08fdba | 7305 | } |
c11b6f21 | 7306 | |
8d08fdba MS |
7307 | decl = build_lang_decl (FUNCTION_DECL, declarator, type); |
7308 | /* propagate volatile out from type to decl */ | |
7309 | if (TYPE_VOLATILE (type)) | |
893de33c | 7310 | TREE_THIS_VOLATILE (decl) = 1; |
8d08fdba MS |
7311 | |
7312 | /* Should probably propagate const out from type to decl I bet (mrs). */ | |
7313 | if (staticp) | |
7314 | { | |
7315 | DECL_STATIC_FUNCTION_P (decl) = 1; | |
7316 | DECL_CONTEXT (decl) = ctype; | |
8d08fdba MS |
7317 | } |
7318 | ||
e76a2646 MS |
7319 | if (ctype) |
7320 | DECL_CLASS_CONTEXT (decl) = ctype; | |
7321 | ||
faae18ab MS |
7322 | if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main")) |
7323 | { | |
7324 | if (inlinep) | |
7325 | error ("cannot declare `main' to be inline"); | |
7326 | else if (! publicp) | |
7327 | error ("cannot declare `main' to be static"); | |
7328 | inlinep = 0; | |
7329 | publicp = 1; | |
7330 | } | |
7331 | ||
893de33c | 7332 | TREE_PUBLIC (decl) = publicp; |
faae18ab | 7333 | if (! publicp) |
893de33c JM |
7334 | { |
7335 | DECL_INTERFACE_KNOWN (decl) = 1; | |
7336 | DECL_NOT_REALLY_EXTERN (decl) = 1; | |
7337 | } | |
faae18ab MS |
7338 | |
7339 | if (inlinep) | |
7340 | DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1; | |
8d08fdba MS |
7341 | |
7342 | DECL_EXTERNAL (decl) = 1; | |
7343 | if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) | |
7344 | { | |
7345 | cp_error ("%smember function `%D' cannot have `%T' method qualifier", | |
7346 | (ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); | |
7347 | quals = NULL_TREE; | |
7348 | } | |
7349 | ||
7350 | if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) | |
7351 | grok_op_properties (decl, virtualp, check < 0); | |
7352 | ||
e76a2646 | 7353 | if (ctype && hack_decl_function_context (decl)) |
893de33c | 7354 | DECL_NO_STATIC_CHAIN (decl) = 1; |
e76a2646 | 7355 | |
42976354 BK |
7356 | for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t)) |
7357 | if (TREE_PURPOSE (t) | |
7358 | && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) | |
7359 | { | |
7360 | add_defarg_fn (decl); | |
7361 | break; | |
7362 | } | |
7363 | ||
75650646 MM |
7364 | if (friendp && |
7365 | TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR) | |
f84b4be9 JM |
7366 | { |
7367 | /* A friend declaration of the form friend void f<>(). Record | |
7368 | the information in the TEMPLATE_ID_EXPR. */ | |
7369 | SET_DECL_IMPLICIT_INSTANTIATION (decl); | |
7370 | DECL_TEMPLATE_INFO (decl) | |
7371 | = perm_tree_cons (TREE_OPERAND (orig_declarator, 0), | |
7372 | TREE_OPERAND (orig_declarator, 1), | |
7373 | NULL_TREE); | |
7374 | } | |
386b8a85 | 7375 | |
75650646 | 7376 | /* Caller will do the rest of this. */ |
8d08fdba MS |
7377 | if (check < 0) |
7378 | return decl; | |
7379 | ||
5566b478 | 7380 | if (check && funcdef_flag) |
d2e5ee5c | 7381 | DECL_INITIAL (decl) = error_mark_node; |
5566b478 | 7382 | |
8d08fdba MS |
7383 | if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) |
7384 | { | |
7385 | tree tmp; | |
7386 | /* Just handle constructors here. We could do this | |
7387 | inside the following if stmt, but I think | |
7388 | that the code is more legible by breaking this | |
7389 | case out. See comments below for what each of | |
7390 | the following calls is supposed to do. */ | |
7391 | DECL_CONSTRUCTOR_P (decl) = 1; | |
7392 | ||
7393 | grokclassfn (ctype, declarator, decl, flags, quals); | |
386b8a85 | 7394 | |
e1467ff2 MM |
7395 | decl = check_explicit_specialization (orig_declarator, decl, |
7396 | template_count, | |
f84b4be9 JM |
7397 | 2 * (funcdef_flag != 0) + |
7398 | 4 * (friendp != 0)); | |
75650646 | 7399 | |
8d08fdba | 7400 | if (check) |
5566b478 MS |
7401 | { |
7402 | tmp = check_classfn (ctype, decl); | |
98c1c668 JM |
7403 | |
7404 | if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) | |
7405 | tmp = DECL_TEMPLATE_RESULT(tmp); | |
7406 | ||
e349ee73 MS |
7407 | if (tmp && DECL_ARTIFICIAL (tmp)) |
7408 | cp_error ("definition of implicitly-declared `%D'", tmp); | |
5566b478 MS |
7409 | if (tmp && duplicate_decls (decl, tmp)) |
7410 | return tmp; | |
7411 | } | |
a0a33927 MS |
7412 | if (! grok_ctor_properties (ctype, decl)) |
7413 | return NULL_TREE; | |
7414 | ||
7177d104 | 7415 | if (check == 0 && ! current_function_decl) |
8d08fdba | 7416 | { |
30394414 | 7417 | /* assembler names live in the global namespace */ |
37c46b43 | 7418 | tmp = IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)); |
8d08fdba MS |
7419 | if (tmp == NULL_TREE) |
7420 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; | |
7421 | else if (TREE_CODE (tmp) != TREE_CODE (decl)) | |
7422 | cp_error ("inconsistent declarations for `%D'", decl); | |
7423 | else | |
7424 | { | |
7425 | duplicate_decls (decl, tmp); | |
7426 | decl = tmp; | |
7427 | /* avoid creating circularities. */ | |
7428 | DECL_CHAIN (decl) = NULL_TREE; | |
7429 | } | |
7430 | make_decl_rtl (decl, NULL_PTR, 1); | |
7431 | } | |
7432 | } | |
7433 | else | |
7434 | { | |
7435 | tree tmp; | |
7436 | ||
7437 | /* Function gets the ugly name, field gets the nice one. | |
7438 | This call may change the type of the function (because | |
7439 | of default parameters)! */ | |
7440 | if (ctype != NULL_TREE) | |
7441 | grokclassfn (ctype, cname, decl, flags, quals); | |
7442 | ||
e1467ff2 MM |
7443 | decl = check_explicit_specialization (orig_declarator, decl, |
7444 | template_count, | |
f84b4be9 JM |
7445 | 2 * (funcdef_flag != 0) + |
7446 | 4 * (friendp != 0)); | |
75650646 | 7447 | |
8d08fdba | 7448 | if (ctype != NULL_TREE && check) |
5566b478 MS |
7449 | { |
7450 | tmp = check_classfn (ctype, decl); | |
98c1c668 JM |
7451 | |
7452 | if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) | |
75650646 | 7453 | tmp = DECL_TEMPLATE_RESULT (tmp); |
98c1c668 | 7454 | |
5566b478 MS |
7455 | if (tmp && DECL_STATIC_FUNCTION_P (tmp) |
7456 | && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) | |
7457 | { | |
7458 | /* Remove the `this' parm added by grokclassfn. | |
7459 | XXX Isn't this done in start_function, too? */ | |
7460 | revert_static_member_fn (&decl, NULL, NULL); | |
7461 | last_function_parms = TREE_CHAIN (last_function_parms); | |
7462 | } | |
e349ee73 MS |
7463 | if (tmp && DECL_ARTIFICIAL (tmp)) |
7464 | cp_error ("definition of implicitly-declared `%D'", tmp); | |
7834ab39 MS |
7465 | if (tmp) |
7466 | { | |
7467 | if (!duplicate_decls (decl, tmp)) | |
7468 | my_friendly_abort (892); | |
7469 | return tmp; | |
7470 | } | |
5566b478 | 7471 | } |
8d08fdba MS |
7472 | |
7473 | if (ctype == NULL_TREE || check) | |
7474 | return decl; | |
7475 | ||
7177d104 MS |
7476 | /* Now install the declaration of this function so that others may |
7477 | find it (esp. its DECL_FRIENDLIST). Don't do this for local class | |
7478 | methods, though. */ | |
7479 | if (! current_function_decl) | |
8d08fdba | 7480 | { |
75650646 | 7481 | if (!DECL_TEMPLATE_SPECIALIZATION (decl)) |
7177d104 | 7482 | { |
75650646 MM |
7483 | /* We don't do this for specializations since the |
7484 | equivalent checks will be done later. Also, at this | |
7485 | point the DECL_ASSEMBLER_NAME is not yet fully | |
7486 | accurate. */ | |
7487 | ||
7488 | /* FIXME: this should only need to look at | |
7489 | IDENTIFIER_GLOBAL_VALUE. */ | |
7490 | tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); | |
7491 | if (tmp == NULL_TREE) | |
7492 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; | |
7493 | else if (TREE_CODE (tmp) != TREE_CODE (decl)) | |
7494 | cp_error ("inconsistent declarations for `%D'", decl); | |
7495 | else | |
7496 | { | |
7497 | duplicate_decls (decl, tmp); | |
7498 | decl = tmp; | |
7499 | /* avoid creating circularities. */ | |
7500 | DECL_CHAIN (decl) = NULL_TREE; | |
7501 | } | |
7177d104 | 7502 | } |
f30432d7 MS |
7503 | |
7504 | if (attrlist) | |
7505 | cplus_decl_attributes (decl, TREE_PURPOSE (attrlist), | |
7506 | TREE_VALUE (attrlist)); | |
7177d104 | 7507 | make_decl_rtl (decl, NULL_PTR, 1); |
8d08fdba | 7508 | } |
8d08fdba MS |
7509 | if (virtualp) |
7510 | { | |
2ee887f2 | 7511 | DECL_VIRTUAL_P (decl) = 1; |
8d08fdba MS |
7512 | if (DECL_VINDEX (decl) == NULL_TREE) |
7513 | DECL_VINDEX (decl) = error_mark_node; | |
7514 | IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; | |
8d08fdba MS |
7515 | } |
7516 | } | |
7517 | return decl; | |
7518 | } | |
7519 | ||
7520 | static tree | |
d2e5ee5c | 7521 | grokvardecl (type, declarator, specbits_in, initialized, constp) |
8d08fdba MS |
7522 | tree type; |
7523 | tree declarator; | |
d2e5ee5c | 7524 | RID_BIT_TYPE *specbits_in; |
8d08fdba | 7525 | int initialized; |
a9aedbc2 | 7526 | int constp; |
8d08fdba MS |
7527 | { |
7528 | tree decl; | |
f7da6097 MS |
7529 | RID_BIT_TYPE specbits; |
7530 | ||
7531 | specbits = *specbits_in; | |
8d08fdba MS |
7532 | |
7533 | if (TREE_CODE (type) == OFFSET_TYPE) | |
7534 | { | |
7535 | /* If you declare a static member so that it | |
7536 | can be initialized, the code will reach here. */ | |
5b605f68 MS |
7537 | tree basetype = TYPE_OFFSET_BASETYPE (type); |
7538 | type = TREE_TYPE (type); | |
7539 | decl = build_lang_field_decl (VAR_DECL, declarator, type); | |
7540 | DECL_CONTEXT (decl) = basetype; | |
7541 | DECL_CLASS_CONTEXT (decl) = basetype; | |
f376e137 | 7542 | DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator); |
8d08fdba MS |
7543 | } |
7544 | else | |
30394414 JM |
7545 | { |
7546 | decl = build_decl (VAR_DECL, declarator, complete_type (type)); | |
7547 | if (current_namespace != global_namespace) | |
7548 | DECL_ASSEMBLER_NAME (decl) = build_static_name (current_namespace, | |
7549 | declarator); | |
7550 | } | |
6060a796 | 7551 | |
8d08fdba MS |
7552 | if (RIDBIT_SETP (RID_EXTERN, specbits)) |
7553 | { | |
7554 | DECL_THIS_EXTERN (decl) = 1; | |
7555 | DECL_EXTERNAL (decl) = !initialized; | |
7556 | } | |
7557 | ||
7558 | /* In class context, static means one per class, | |
7559 | public access, and static storage. */ | |
7560 | if (DECL_FIELD_CONTEXT (decl) != NULL_TREE | |
7561 | && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl))) | |
7562 | { | |
7563 | TREE_PUBLIC (decl) = 1; | |
7564 | TREE_STATIC (decl) = 1; | |
5b605f68 | 7565 | DECL_EXTERNAL (decl) = 0; |
8d08fdba MS |
7566 | } |
7567 | /* At top level, either `static' or no s.c. makes a definition | |
7568 | (perhaps tentative), and absence of `static' makes it public. */ | |
a9aedbc2 | 7569 | else if (toplevel_bindings_p ()) |
8d08fdba | 7570 | { |
a9aedbc2 | 7571 | TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits) |
9fffd093 | 7572 | && (DECL_THIS_EXTERN (decl) || ! constp)); |
8d08fdba MS |
7573 | TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); |
7574 | } | |
7575 | /* Not at top level, only `static' makes a static definition. */ | |
7576 | else | |
7577 | { | |
7578 | TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits); | |
7579 | TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); | |
7580 | } | |
7581 | return decl; | |
7582 | } | |
7583 | ||
e92cc029 | 7584 | /* Create a canonical pointer to member function type. */ |
8d08fdba MS |
7585 | |
7586 | tree | |
7587 | build_ptrmemfunc_type (type) | |
7588 | tree type; | |
7589 | { | |
7590 | tree fields[4]; | |
7591 | tree t; | |
7592 | tree u; | |
7593 | ||
7594 | /* If a canonical type already exists for this type, use it. We use | |
7595 | this method instead of type_hash_canon, because it only does a | |
7596 | simple equality check on the list of field members. */ | |
7597 | ||
7598 | if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type))) | |
7599 | return t; | |
7600 | ||
7601 | push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); | |
7602 | ||
7603 | u = make_lang_type (UNION_TYPE); | |
f30432d7 | 7604 | IS_AGGR_TYPE (u) = 0; |
8d08fdba | 7605 | fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type); |
a28e3c7f MS |
7606 | fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, |
7607 | delta_type_node); | |
8d08fdba MS |
7608 | finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node); |
7609 | TYPE_NAME (u) = NULL_TREE; | |
7610 | ||
7611 | t = make_lang_type (RECORD_TYPE); | |
7612 | ||
e92cc029 | 7613 | /* Let the front-end know this is a pointer to member function. */ |
db5ae43f | 7614 | TYPE_PTRMEMFUNC_FLAG (t) = 1; |
f376e137 MS |
7615 | /* and not really an aggregate. */ |
7616 | IS_AGGR_TYPE (t) = 0; | |
8d08fdba | 7617 | |
a28e3c7f MS |
7618 | fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, |
7619 | delta_type_node); | |
7620 | fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, | |
7621 | delta_type_node); | |
8d08fdba MS |
7622 | fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u); |
7623 | finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node); | |
7624 | ||
7625 | pop_obstacks (); | |
7626 | ||
7627 | /* Zap out the name so that the back-end will give us the debugging | |
7628 | information for this anonymous RECORD_TYPE. */ | |
7629 | TYPE_NAME (t) = NULL_TREE; | |
7630 | ||
7631 | TYPE_SET_PTRMEMFUNC_TYPE (type, t); | |
7632 | ||
e92cc029 | 7633 | /* Seems to be wanted. */ |
8d08fdba MS |
7634 | CLASSTYPE_GOT_SEMICOLON (t) = 1; |
7635 | return t; | |
7636 | } | |
7637 | ||
7638 | /* Given declspecs and a declarator, | |
7639 | determine the name and type of the object declared | |
7640 | and construct a ..._DECL node for it. | |
7641 | (In one case we can return a ..._TYPE node instead. | |
7642 | For invalid input we sometimes return 0.) | |
7643 | ||
7644 | DECLSPECS is a chain of tree_list nodes whose value fields | |
7645 | are the storage classes and type specifiers. | |
7646 | ||
7647 | DECL_CONTEXT says which syntactic context this declaration is in: | |
7648 | NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. | |
7649 | FUNCDEF for a function definition. Like NORMAL but a few different | |
7650 | error messages in each case. Return value may be zero meaning | |
7651 | this definition is too screwy to try to parse. | |
7652 | MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to | |
7653 | handle member functions (which have FIELD context). | |
7654 | Return value may be zero meaning this definition is too screwy to | |
7655 | try to parse. | |
7656 | PARM for a parameter declaration (either within a function prototype | |
7657 | or before a function body). Make a PARM_DECL, or return void_type_node. | |
db5ae43f | 7658 | CATCHPARM for a parameter declaration before a catch clause. |
8d08fdba MS |
7659 | TYPENAME if for a typename (in a cast or sizeof). |
7660 | Don't make a DECL node; just return the ..._TYPE node. | |
7661 | FIELD for a struct or union field; make a FIELD_DECL. | |
7662 | BITFIELD for a field with specified width. | |
7663 | INITIALIZED is 1 if the decl has an initializer. | |
7664 | ||
7665 | In the TYPENAME case, DECLARATOR is really an absolute declarator. | |
7666 | It may also be so in the PARM case, for a prototype where the | |
7667 | argument type is specified but not the name. | |
7668 | ||
7669 | This function is where the complicated C meanings of `static' | |
7670 | and `extern' are interpreted. | |
7671 | ||
7672 | For C++, if there is any monkey business to do, the function which | |
7673 | calls this one must do it, i.e., prepending instance variables, | |
7674 | renaming overloaded function names, etc. | |
7675 | ||
7676 | Note that for this C++, it is an error to define a method within a class | |
7677 | which does not belong to that class. | |
7678 | ||
7679 | Except in the case where SCOPE_REFs are implicitly known (such as | |
7680 | methods within a class being redundantly qualified), | |
7681 | declarations which involve SCOPE_REFs are returned as SCOPE_REFs | |
7682 | (class_name::decl_name). The caller must also deal with this. | |
7683 | ||
7684 | If a constructor or destructor is seen, and the context is FIELD, | |
7685 | then the type gains the attribute TREE_HAS_x. If such a declaration | |
7686 | is erroneous, NULL_TREE is returned. | |
7687 | ||
7688 | QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member | |
7689 | function, these are the qualifiers to give to the `this' pointer. | |
7690 | ||
7691 | May return void_type_node if the declarator turned out to be a friend. | |
7692 | See grokfield for details. */ | |
7693 | ||
7694 | enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; | |
7695 | ||
7696 | tree | |
c11b6f21 | 7697 | grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) |
8d08fdba MS |
7698 | tree declspecs; |
7699 | tree declarator; | |
7700 | enum decl_context decl_context; | |
7701 | int initialized; | |
c11b6f21 | 7702 | tree attrlist; |
8d08fdba MS |
7703 | { |
7704 | RID_BIT_TYPE specbits; | |
7705 | int nclasses = 0; | |
7706 | tree spec; | |
7707 | tree type = NULL_TREE; | |
7708 | int longlong = 0; | |
7709 | int constp; | |
7710 | int volatilep; | |
db5ae43f | 7711 | int virtualp, explicitp, friendp, inlinep, staticp; |
8d08fdba MS |
7712 | int explicit_int = 0; |
7713 | int explicit_char = 0; | |
37c46b43 | 7714 | int defaulted_int = 0; |
8d08fdba MS |
7715 | int opaque_typedef = 0; |
7716 | tree typedef_decl = NULL_TREE; | |
7717 | char *name; | |
7718 | tree typedef_type = NULL_TREE; | |
7719 | int funcdef_flag = 0; | |
7720 | enum tree_code innermost_code = ERROR_MARK; | |
7721 | int bitfield = 0; | |
6125f3be DE |
7722 | #if 0 |
7723 | /* See the code below that used this. */ | |
f6abb50a | 7724 | tree decl_machine_attr = NULL_TREE; |
6125f3be | 7725 | #endif |
8d08fdba MS |
7726 | /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. |
7727 | All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ | |
7728 | tree init = NULL_TREE; | |
7729 | ||
7730 | /* Keep track of what sort of function is being processed | |
7731 | so that we can warn about default return values, or explicit | |
7732 | return values which do not match prescribed defaults. */ | |
7733 | enum return_types return_type = return_normal; | |
7734 | ||
7735 | tree dname = NULL_TREE; | |
7736 | tree ctype = current_class_type; | |
7737 | tree ctor_return_type = NULL_TREE; | |
7738 | enum overload_flags flags = NO_SPECIAL; | |
8d08fdba | 7739 | tree quals = NULL_TREE; |
c11b6f21 | 7740 | tree raises = NULL_TREE; |
386b8a85 | 7741 | int template_count = 0; |
8d08fdba MS |
7742 | |
7743 | RIDBIT_RESET_ALL (specbits); | |
7744 | if (decl_context == FUNCDEF) | |
7745 | funcdef_flag = 1, decl_context = NORMAL; | |
7746 | else if (decl_context == MEMFUNCDEF) | |
7747 | funcdef_flag = -1, decl_context = FIELD; | |
7748 | else if (decl_context == BITFIELD) | |
7749 | bitfield = 1, decl_context = FIELD; | |
7750 | ||
8d08fdba MS |
7751 | /* Look inside a declarator for the name being declared |
7752 | and get it as a string, for an error message. */ | |
7753 | { | |
be99da77 MS |
7754 | tree *next = &declarator; |
7755 | register tree decl; | |
8d08fdba MS |
7756 | name = NULL; |
7757 | ||
be99da77 MS |
7758 | while (next && *next) |
7759 | { | |
7760 | decl = *next; | |
7761 | switch (TREE_CODE (decl)) | |
8d08fdba | 7762 | { |
be99da77 MS |
7763 | case COND_EXPR: |
7764 | ctype = NULL_TREE; | |
7765 | next = &TREE_OPERAND (decl, 0); | |
7766 | break; | |
8d08fdba | 7767 | |
be99da77 | 7768 | case BIT_NOT_EXPR: /* for C++ destructors! */ |
8d08fdba | 7769 | { |
be99da77 MS |
7770 | tree name = TREE_OPERAND (decl, 0); |
7771 | tree rename = NULL_TREE; | |
7772 | ||
7773 | my_friendly_assert (flags == NO_SPECIAL, 152); | |
7774 | flags = DTOR_FLAG; | |
7775 | return_type = return_dtor; | |
5566b478 MS |
7776 | if (TREE_CODE (name) == TYPE_DECL) |
7777 | TREE_OPERAND (decl, 0) = name = constructor_name (name); | |
be99da77 MS |
7778 | my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); |
7779 | if (ctype == NULL_TREE) | |
7780 | { | |
7781 | if (current_class_type == NULL_TREE) | |
7782 | { | |
7783 | error ("destructors must be member functions"); | |
7784 | flags = NO_SPECIAL; | |
7785 | } | |
7786 | else | |
7787 | { | |
7788 | tree t = constructor_name (current_class_name); | |
7789 | if (t != name) | |
7790 | rename = t; | |
7791 | } | |
7792 | } | |
8d08fdba | 7793 | else |
be99da77 MS |
7794 | { |
7795 | tree t = constructor_name (ctype); | |
7796 | if (t != name) | |
7797 | rename = t; | |
7798 | } | |
51c184be | 7799 | |
be99da77 | 7800 | if (rename) |
39211cd5 | 7801 | { |
5566b478 MS |
7802 | cp_error ("destructor `%T' must match class name `%T'", |
7803 | name, rename); | |
be99da77 | 7804 | TREE_OPERAND (decl, 0) = rename; |
39211cd5 | 7805 | } |
be99da77 | 7806 | next = &name; |
51c184be | 7807 | } |
be99da77 | 7808 | break; |
8d08fdba | 7809 | |
be99da77 MS |
7810 | case ADDR_EXPR: /* C++ reference declaration */ |
7811 | /* fall through */ | |
7812 | case ARRAY_REF: | |
7813 | case INDIRECT_REF: | |
7814 | ctype = NULL_TREE; | |
7815 | innermost_code = TREE_CODE (decl); | |
7816 | next = &TREE_OPERAND (decl, 0); | |
7817 | break; | |
8d08fdba | 7818 | |
be99da77 MS |
7819 | case CALL_EXPR: |
7820 | if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) | |
8d08fdba | 7821 | { |
be99da77 MS |
7822 | /* This is actually a variable declaration using constructor |
7823 | syntax. We need to call start_decl and cp_finish_decl so we | |
7824 | can get the variable initialized... */ | |
7825 | ||
7826 | *next = TREE_OPERAND (decl, 0); | |
7827 | init = TREE_OPERAND (decl, 1); | |
7828 | ||
c11b6f21 | 7829 | decl = start_decl (declarator, declspecs, 1); |
249555b0 BK |
7830 | /* Look for __unused__ attribute */ |
7831 | if (TREE_USED (TREE_TYPE (decl))) | |
7832 | TREE_USED (decl) = 1; | |
be99da77 MS |
7833 | finish_decl (decl, init, NULL_TREE); |
7834 | return 0; | |
8d08fdba | 7835 | } |
be99da77 MS |
7836 | innermost_code = TREE_CODE (decl); |
7837 | if (decl_context == FIELD && ctype == NULL_TREE) | |
7838 | ctype = current_class_type; | |
45537677 | 7839 | if (ctype |
c11b6f21 | 7840 | && TREE_OPERAND (decl, 0) |
45537677 MS |
7841 | && (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL |
7842 | && ((DECL_NAME (TREE_OPERAND (decl, 0)) | |
7843 | == constructor_name_full (ctype)) | |
7844 | || (DECL_NAME (TREE_OPERAND (decl, 0)) | |
7845 | == constructor_name (ctype))))) | |
be99da77 MS |
7846 | TREE_OPERAND (decl, 0) = constructor_name (ctype); |
7847 | next = &TREE_OPERAND (decl, 0); | |
7848 | decl = *next; | |
7849 | if (ctype != NULL_TREE | |
7850 | && decl != NULL_TREE && flags != DTOR_FLAG | |
7851 | && decl == constructor_name (ctype)) | |
8d08fdba | 7852 | { |
be99da77 MS |
7853 | return_type = return_ctor; |
7854 | ctor_return_type = ctype; | |
8d08fdba | 7855 | } |
be99da77 MS |
7856 | ctype = NULL_TREE; |
7857 | break; | |
386b8a85 JM |
7858 | |
7859 | case TEMPLATE_ID_EXPR: | |
7860 | { | |
7861 | tree fns = TREE_OPERAND (decl, 0); | |
7862 | ||
7863 | if (TREE_CODE (fns) == LOOKUP_EXPR) | |
7864 | fns = TREE_OPERAND (fns, 0); | |
7865 | ||
7866 | if (TREE_CODE (fns) == IDENTIFIER_NODE) | |
7867 | dname = fns; | |
f84b4be9 | 7868 | else if (is_overloaded_fn (fns)) |
386b8a85 JM |
7869 | dname = DECL_NAME (get_first_fn (fns)); |
7870 | else | |
f84b4be9 | 7871 | my_friendly_abort (0); |
386b8a85 JM |
7872 | } |
7873 | /* fall through */ | |
be99da77 MS |
7874 | |
7875 | case IDENTIFIER_NODE: | |
386b8a85 JM |
7876 | if (TREE_CODE (decl) == IDENTIFIER_NODE) |
7877 | dname = decl; | |
7878 | ||
be99da77 MS |
7879 | next = 0; |
7880 | ||
7881 | if (is_rid (dname)) | |
8d08fdba | 7882 | { |
be99da77 MS |
7883 | cp_error ("declarator-id missing; using reserved word `%D'", |
7884 | dname); | |
7885 | name = IDENTIFIER_POINTER (dname); | |
8d08fdba | 7886 | } |
be99da77 | 7887 | if (! IDENTIFIER_OPNAME_P (dname) |
956d6950 | 7888 | /* GNU/Linux headers use '__op'. Arrgh. */ |
a703fb38 | 7889 | || (IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))) |
be99da77 | 7890 | name = IDENTIFIER_POINTER (dname); |
8d08fdba MS |
7891 | else |
7892 | { | |
be99da77 | 7893 | if (IDENTIFIER_TYPENAME_P (dname)) |
8d08fdba | 7894 | { |
be99da77 MS |
7895 | my_friendly_assert (flags == NO_SPECIAL, 154); |
7896 | flags = TYPENAME_FLAG; | |
7897 | ctor_return_type = TREE_TYPE (dname); | |
7898 | return_type = return_conversion; | |
8d08fdba | 7899 | } |
be99da77 | 7900 | name = operator_name_string (dname); |
8d08fdba | 7901 | } |
be99da77 | 7902 | break; |
8d08fdba | 7903 | |
be99da77 MS |
7904 | /* C++ extension */ |
7905 | case SCOPE_REF: | |
7906 | { | |
7907 | /* Perform error checking, and decide on a ctype. */ | |
7908 | tree cname = TREE_OPERAND (decl, 0); | |
7909 | if (cname == NULL_TREE) | |
7910 | ctype = NULL_TREE; | |
7911 | else if (! is_aggr_type (cname, 1)) | |
7912 | TREE_OPERAND (decl, 0) = NULL_TREE; | |
7913 | /* Must test TREE_OPERAND (decl, 1), in case user gives | |
7914 | us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ | |
7915 | else if (TREE_OPERAND (decl, 1) | |
7916 | && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) | |
7917 | ctype = cname; | |
73b0fce8 KL |
7918 | else if (TREE_CODE (cname) == TEMPLATE_TYPE_PARM |
7919 | || TREE_CODE (cname) == TEMPLATE_TEMPLATE_PARM) | |
5566b478 MS |
7920 | { |
7921 | cp_error ("`%T::%D' is not a valid declarator", cname, | |
7922 | TREE_OPERAND (decl, 1)); | |
7923 | cp_error (" perhaps you want `typename %T::%D' to make it a type", | |
7924 | cname, TREE_OPERAND (decl, 1)); | |
7925 | return void_type_node; | |
7926 | } | |
be99da77 MS |
7927 | else if (ctype == NULL_TREE) |
7928 | ctype = cname; | |
7929 | else if (TREE_COMPLEXITY (decl) == current_class_depth) | |
7930 | TREE_OPERAND (decl, 0) = ctype; | |
7931 | else | |
7932 | { | |
7933 | if (! UNIQUELY_DERIVED_FROM_P (cname, ctype)) | |
7934 | { | |
7935 | cp_error ("type `%T' is not derived from type `%T'", | |
7936 | cname, ctype); | |
7937 | TREE_OPERAND (decl, 0) = NULL_TREE; | |
7938 | } | |
7939 | else | |
7940 | ctype = cname; | |
7941 | } | |
7942 | ||
c91a56d2 MS |
7943 | if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL |
7944 | && ((DECL_NAME (TREE_OPERAND (decl, 1)) | |
7945 | == constructor_name_full (ctype)) | |
7946 | || (DECL_NAME (TREE_OPERAND (decl, 1)) | |
7947 | == constructor_name (ctype)))) | |
be99da77 MS |
7948 | TREE_OPERAND (decl, 1) = constructor_name (ctype); |
7949 | next = &TREE_OPERAND (decl, 1); | |
7950 | decl = *next; | |
7951 | if (ctype) | |
7952 | { | |
7953 | if (TREE_CODE (decl) == IDENTIFIER_NODE | |
7954 | && constructor_name (ctype) == decl) | |
7955 | { | |
7956 | return_type = return_ctor; | |
7957 | ctor_return_type = ctype; | |
7958 | } | |
7959 | else if (TREE_CODE (decl) == BIT_NOT_EXPR | |
7960 | && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE | |
7961 | && (constructor_name (ctype) == TREE_OPERAND (decl, 0) | |
7962 | || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) | |
7963 | { | |
7964 | return_type = return_dtor; | |
7965 | ctor_return_type = ctype; | |
7966 | flags = DTOR_FLAG; | |
7967 | TREE_OPERAND (decl, 0) = constructor_name (ctype); | |
7968 | next = &TREE_OPERAND (decl, 0); | |
7969 | } | |
7970 | } | |
7971 | } | |
7972 | break; | |
7973 | ||
7974 | case ERROR_MARK: | |
7975 | next = 0; | |
7976 | break; | |
7977 | ||
45537677 MS |
7978 | case TYPE_DECL: |
7979 | /* Parse error puts this typespec where | |
7980 | a declarator should go. */ | |
7981 | cp_error ("`%T' specified as declarator-id", DECL_NAME (decl)); | |
7982 | if (TREE_TYPE (decl) == current_class_type) | |
7983 | cp_error (" perhaps you want `%T' for a constructor", | |
7984 | current_class_name); | |
7985 | dname = DECL_NAME (decl); | |
7986 | name = IDENTIFIER_POINTER (dname); | |
7987 | ||
e92cc029 | 7988 | /* Avoid giving two errors for this. */ |
45537677 MS |
7989 | IDENTIFIER_CLASS_VALUE (dname) = NULL_TREE; |
7990 | ||
7991 | declspecs = temp_tree_cons (NULL_TREE, integer_type_node, | |
7992 | declspecs); | |
7993 | *next = dname; | |
7994 | next = 0; | |
7995 | break; | |
7996 | ||
be99da77 | 7997 | default: |
be99da77 MS |
7998 | cp_compiler_error ("`%D' as declarator", decl); |
7999 | return 0; /* We used to do a 155 abort here. */ | |
8d08fdba | 8000 | } |
be99da77 | 8001 | } |
8d08fdba MS |
8002 | if (name == NULL) |
8003 | name = "type name"; | |
8004 | } | |
8005 | ||
8006 | /* A function definition's declarator must have the form of | |
8007 | a function declarator. */ | |
8008 | ||
8009 | if (funcdef_flag && innermost_code != CALL_EXPR) | |
8010 | return 0; | |
8011 | ||
e1cd6e56 MS |
8012 | if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG) |
8013 | && innermost_code != CALL_EXPR | |
8014 | && ! (ctype && declspecs == NULL_TREE)) | |
8015 | { | |
8016 | cp_error ("declaration of `%D' as non-function", dname); | |
8017 | return void_type_node; | |
8018 | } | |
8019 | ||
8d08fdba MS |
8020 | /* Anything declared one level down from the top level |
8021 | must be one of the parameters of a function | |
8022 | (because the body is at least two levels down). */ | |
8023 | ||
8024 | /* This heuristic cannot be applied to C++ nodes! Fixed, however, | |
8025 | by not allowing C++ class definitions to specify their parameters | |
8026 | with xdecls (must be spec.d in the parmlist). | |
8027 | ||
8028 | Since we now wait to push a class scope until we are sure that | |
8029 | we are in a legitimate method context, we must set oldcname | |
a9aedbc2 MS |
8030 | explicitly (since current_class_name is not yet alive). |
8031 | ||
8032 | We also want to avoid calling this a PARM if it is in a namespace. */ | |
8d08fdba | 8033 | |
5566b478 MS |
8034 | if (decl_context == NORMAL && ! namespace_bindings_p () |
8035 | && ! pseudo_global_level_p ()) | |
a9aedbc2 MS |
8036 | { |
8037 | struct binding_level *b = current_binding_level; | |
8038 | current_binding_level = b->level_chain; | |
8039 | if (current_binding_level != 0 && toplevel_bindings_p ()) | |
8040 | decl_context = PARM; | |
8041 | current_binding_level = b; | |
8042 | } | |
8d08fdba MS |
8043 | |
8044 | /* Look through the decl specs and record which ones appear. | |
8045 | Some typespecs are defined as built-in typenames. | |
8046 | Others, the ones that are modifiers of other types, | |
8047 | are represented by bits in SPECBITS: set the bits for | |
8048 | the modifiers that appear. Storage class keywords are also in SPECBITS. | |
8049 | ||
8050 | If there is a typedef name or a type, store the type in TYPE. | |
8051 | This includes builtin typedefs such as `int'. | |
8052 | ||
8053 | Set EXPLICIT_INT if the type is `int' or `char' and did not | |
8054 | come from a user typedef. | |
8055 | ||
8056 | Set LONGLONG if `long' is mentioned twice. | |
8057 | ||
8058 | For C++, constructors and destructors have their own fast treatment. */ | |
8059 | ||
8060 | for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) | |
8061 | { | |
8062 | register int i; | |
8063 | register tree id; | |
8064 | ||
8065 | /* Certain parse errors slip through. For example, | |
8066 | `int class;' is not caught by the parser. Try | |
8067 | weakly to recover here. */ | |
8068 | if (TREE_CODE (spec) != TREE_LIST) | |
8069 | return 0; | |
8070 | ||
8071 | id = TREE_VALUE (spec); | |
8072 | ||
8073 | if (TREE_CODE (id) == IDENTIFIER_NODE) | |
8074 | { | |
a3203465 MS |
8075 | if (id == ridpointers[(int) RID_INT] |
8076 | || id == ridpointers[(int) RID_CHAR] | |
8077 | || id == ridpointers[(int) RID_BOOL] | |
8078 | || id == ridpointers[(int) RID_WCHAR]) | |
8d08fdba MS |
8079 | { |
8080 | if (type) | |
8ccc31eb MS |
8081 | { |
8082 | if (id == ridpointers[(int) RID_BOOL]) | |
8083 | error ("`bool' is now a keyword"); | |
8084 | else | |
8085 | cp_error ("extraneous `%T' ignored", id); | |
8086 | } | |
8d08fdba MS |
8087 | else |
8088 | { | |
a3203465 MS |
8089 | if (id == ridpointers[(int) RID_INT]) |
8090 | explicit_int = 1; | |
8091 | else if (id == ridpointers[(int) RID_CHAR]) | |
8092 | explicit_char = 1; | |
8d08fdba MS |
8093 | type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); |
8094 | } | |
8095 | goto found; | |
8096 | } | |
e92cc029 | 8097 | /* C++ aggregate types. */ |
8d08fdba MS |
8098 | if (IDENTIFIER_HAS_TYPE_VALUE (id)) |
8099 | { | |
8100 | if (type) | |
8101 | cp_error ("multiple declarations `%T' and `%T'", type, id); | |
8102 | else | |
8103 | type = IDENTIFIER_TYPE_VALUE (id); | |
8104 | goto found; | |
8105 | } | |
8106 | ||
f376e137 | 8107 | for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++) |
8d08fdba MS |
8108 | { |
8109 | if (ridpointers[i] == id) | |
8110 | { | |
8111 | if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) | |
8112 | { | |
e1cd6e56 MS |
8113 | if (pedantic && ! in_system_header) |
8114 | pedwarn ("ANSI C++ does not support `long long'"); | |
9a3b49ac | 8115 | if (longlong) |
a0a33927 | 8116 | error ("`long long long' is too long for GCC"); |
8d08fdba MS |
8117 | else |
8118 | longlong = 1; | |
8119 | } | |
8120 | else if (RIDBIT_SETP (i, specbits)) | |
a0a33927 | 8121 | pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); |
8d08fdba MS |
8122 | RIDBIT_SET (i, specbits); |
8123 | goto found; | |
8124 | } | |
8125 | } | |
8126 | } | |
e92cc029 | 8127 | /* C++ aggregate types. */ |
73b0fce8 | 8128 | else if (TREE_CODE (id) == TYPE_DECL || TREE_CODE (id) == TEMPLATE_DECL) |
45537677 MS |
8129 | { |
8130 | if (type) | |
8131 | cp_error ("multiple declarations `%T' and `%T'", type, | |
8132 | TREE_TYPE (id)); | |
8133 | else | |
5566b478 MS |
8134 | { |
8135 | type = TREE_TYPE (id); | |
8136 | TREE_VALUE (spec) = type; | |
8137 | } | |
45537677 MS |
8138 | goto found; |
8139 | } | |
8d08fdba MS |
8140 | if (type) |
8141 | error ("two or more data types in declaration of `%s'", name); | |
8142 | else if (TREE_CODE (id) == IDENTIFIER_NODE) | |
8143 | { | |
8144 | register tree t = lookup_name (id, 1); | |
8145 | if (!t || TREE_CODE (t) != TYPE_DECL) | |
8146 | error ("`%s' fails to be a typedef or built in type", | |
8147 | IDENTIFIER_POINTER (id)); | |
8148 | else | |
8149 | { | |
8150 | type = TREE_TYPE (t); | |
6125f3be DE |
8151 | #if 0 |
8152 | /* See the code below that used this. */ | |
f6abb50a | 8153 | decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); |
6125f3be | 8154 | #endif |
8d08fdba MS |
8155 | typedef_decl = t; |
8156 | } | |
8157 | } | |
bd6dd845 | 8158 | else if (id != error_mark_node) |
8d08fdba MS |
8159 | /* Can't change CLASS nodes into RECORD nodes here! */ |
8160 | type = id; | |
8161 | ||
8162 | found: ; | |
8163 | } | |
8164 | ||
8165 | typedef_type = type; | |
8166 | ||
37c46b43 | 8167 | /* No type at all: default to `int', and set DEFAULTED_INT |
8d08fdba MS |
8168 | because it was not a user-defined typedef. |
8169 | Except when we have a `typedef' inside a signature, in | |
8170 | which case the type defaults to `unknown type' and is | |
8171 | instantiated when assigning to a signature pointer or ref. */ | |
8172 | ||
a3203465 MS |
8173 | if (type == NULL_TREE |
8174 | && (RIDBIT_SETP (RID_SIGNED, specbits) | |
8175 | || RIDBIT_SETP (RID_UNSIGNED, specbits) | |
8176 | || RIDBIT_SETP (RID_LONG, specbits) | |
8177 | || RIDBIT_SETP (RID_SHORT, specbits))) | |
8178 | { | |
8179 | /* These imply 'int'. */ | |
8180 | type = integer_type_node; | |
37c46b43 | 8181 | defaulted_int = 1; |
a3203465 MS |
8182 | } |
8183 | ||
8d08fdba MS |
8184 | if (type == NULL_TREE) |
8185 | { | |
8186 | explicit_int = -1; | |
8187 | if (return_type == return_dtor) | |
8188 | type = void_type_node; | |
8189 | else if (return_type == return_ctor) | |
f30432d7 | 8190 | type = build_pointer_type (ctor_return_type); |
51c184be MS |
8191 | else if (return_type == return_conversion) |
8192 | type = ctor_return_type; | |
8d08fdba MS |
8193 | else if (current_class_type |
8194 | && IS_SIGNATURE (current_class_type) | |
fc378698 | 8195 | && RIDBIT_SETP (RID_TYPEDEF, specbits) |
8d08fdba MS |
8196 | && (decl_context == FIELD || decl_context == NORMAL)) |
8197 | { | |
8198 | explicit_int = 0; | |
8199 | opaque_typedef = 1; | |
8200 | type = copy_node (opaque_type_node); | |
8201 | } | |
8202 | else | |
8203 | { | |
a28e3c7f MS |
8204 | if (funcdef_flag) |
8205 | { | |
8206 | if (warn_return_type | |
a3203465 | 8207 | && return_type == return_normal) |
a28e3c7f MS |
8208 | /* Save warning until we know what is really going on. */ |
8209 | warn_about_return_type = 1; | |
8210 | } | |
a3203465 MS |
8211 | else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) |
8212 | pedwarn ("ANSI C++ forbids typedef which does not specify a type"); | |
343fdf03 JM |
8213 | else if (innermost_code != CALL_EXPR || pedantic |
8214 | || (warn_return_type && return_type == return_normal)) | |
8215 | { | |
8216 | if (innermost_code == CALL_EXPR) | |
8217 | cp_pedwarn ("return-type of `%D' defaults to `int'", dname); | |
8218 | else | |
8219 | cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type", | |
8220 | dname); | |
8221 | } | |
8d08fdba MS |
8222 | type = integer_type_node; |
8223 | } | |
8224 | } | |
8225 | else if (return_type == return_dtor) | |
8226 | { | |
8227 | error ("return type specification for destructor invalid"); | |
8228 | type = void_type_node; | |
8229 | } | |
8230 | else if (return_type == return_ctor) | |
8231 | { | |
8232 | error ("return type specification for constructor invalid"); | |
f30432d7 | 8233 | type = build_pointer_type (ctor_return_type); |
8d08fdba | 8234 | } |
51c184be MS |
8235 | else if (return_type == return_conversion) |
8236 | { | |
e1cd6e56 | 8237 | if (comptypes (type, ctor_return_type, 1) == 0) |
51c184be MS |
8238 | cp_error ("operator `%T' declared to return `%T'", |
8239 | ctor_return_type, type); | |
8240 | else | |
8241 | cp_pedwarn ("return type specified for `operator %T'", | |
8242 | ctor_return_type); | |
8243 | ||
8244 | type = ctor_return_type; | |
8245 | } | |
8d08fdba MS |
8246 | |
8247 | ctype = NULL_TREE; | |
8248 | ||
8249 | /* Now process the modifiers that were specified | |
8250 | and check for invalid combinations. */ | |
8251 | ||
8252 | /* Long double is a special combination. */ | |
8253 | ||
8254 | if (RIDBIT_SETP (RID_LONG, specbits) | |
8255 | && TYPE_MAIN_VARIANT (type) == double_type_node) | |
8256 | { | |
8257 | RIDBIT_RESET (RID_LONG, specbits); | |
8258 | type = build_type_variant (long_double_type_node, TYPE_READONLY (type), | |
8259 | TYPE_VOLATILE (type)); | |
8260 | } | |
8261 | ||
8262 | /* Check all other uses of type modifiers. */ | |
8263 | ||
8264 | if (RIDBIT_SETP (RID_UNSIGNED, specbits) | |
8265 | || RIDBIT_SETP (RID_SIGNED, specbits) | |
8266 | || RIDBIT_SETP (RID_LONG, specbits) | |
8267 | || RIDBIT_SETP (RID_SHORT, specbits)) | |
8268 | { | |
8269 | int ok = 0; | |
8270 | ||
8271 | if (TREE_CODE (type) == REAL_TYPE) | |
8272 | error ("short, signed or unsigned invalid for `%s'", name); | |
b7484fbe | 8273 | else if (TREE_CODE (type) != INTEGER_TYPE) |
8d08fdba MS |
8274 | error ("long, short, signed or unsigned invalid for `%s'", name); |
8275 | else if (RIDBIT_SETP (RID_LONG, specbits) | |
8276 | && RIDBIT_SETP (RID_SHORT, specbits)) | |
8277 | error ("long and short specified together for `%s'", name); | |
8278 | else if ((RIDBIT_SETP (RID_LONG, specbits) | |
8279 | || RIDBIT_SETP (RID_SHORT, specbits)) | |
8280 | && explicit_char) | |
8281 | error ("long or short specified with char for `%s'", name); | |
8282 | else if ((RIDBIT_SETP (RID_LONG, specbits) | |
8283 | || RIDBIT_SETP (RID_SHORT, specbits)) | |
8284 | && TREE_CODE (type) == REAL_TYPE) | |
8285 | error ("long or short specified with floating type for `%s'", name); | |
8286 | else if (RIDBIT_SETP (RID_SIGNED, specbits) | |
8287 | && RIDBIT_SETP (RID_UNSIGNED, specbits)) | |
8288 | error ("signed and unsigned given together for `%s'", name); | |
8289 | else | |
8290 | { | |
8291 | ok = 1; | |
37c46b43 | 8292 | if (!explicit_int && !defaulted_int && !explicit_char && pedantic) |
8d08fdba MS |
8293 | { |
8294 | pedwarn ("long, short, signed or unsigned used invalidly for `%s'", | |
8295 | name); | |
8296 | if (flag_pedantic_errors) | |
8297 | ok = 0; | |
8298 | } | |
8299 | } | |
8300 | ||
8301 | /* Discard the type modifiers if they are invalid. */ | |
8302 | if (! ok) | |
8303 | { | |
8304 | RIDBIT_RESET (RID_UNSIGNED, specbits); | |
8305 | RIDBIT_RESET (RID_SIGNED, specbits); | |
8306 | RIDBIT_RESET (RID_LONG, specbits); | |
8307 | RIDBIT_RESET (RID_SHORT, specbits); | |
8308 | longlong = 0; | |
8309 | } | |
8310 | } | |
8311 | ||
37c46b43 MS |
8312 | if (RIDBIT_SETP (RID_COMPLEX, specbits) |
8313 | && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) | |
8314 | { | |
8315 | error ("complex invalid for `%s'", name); | |
8316 | RIDBIT_RESET (RID_COMPLEX, specbits); | |
8317 | } | |
8318 | ||
8d08fdba MS |
8319 | /* Decide whether an integer type is signed or not. |
8320 | Optionally treat bitfields as signed by default. */ | |
8321 | if (RIDBIT_SETP (RID_UNSIGNED, specbits) | |
8d08fdba | 8322 | || (bitfield && ! flag_signed_bitfields |
37c46b43 | 8323 | && (explicit_int || defaulted_int || explicit_char |
8d08fdba MS |
8324 | /* A typedef for plain `int' without `signed' |
8325 | can be controlled just like plain `int'. */ | |
8326 | || ! (typedef_decl != NULL_TREE | |
8327 | && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
8328 | && TREE_CODE (type) != ENUMERAL_TYPE | |
8329 | && RIDBIT_NOTSETP (RID_SIGNED, specbits))) | |
8330 | { | |
8331 | if (longlong) | |
8332 | type = long_long_unsigned_type_node; | |
8333 | else if (RIDBIT_SETP (RID_LONG, specbits)) | |
8334 | type = long_unsigned_type_node; | |
8335 | else if (RIDBIT_SETP (RID_SHORT, specbits)) | |
8336 | type = short_unsigned_type_node; | |
8337 | else if (type == char_type_node) | |
8338 | type = unsigned_char_type_node; | |
8339 | else if (typedef_decl) | |
8340 | type = unsigned_type (type); | |
8341 | else | |
8342 | type = unsigned_type_node; | |
8343 | } | |
8344 | else if (RIDBIT_SETP (RID_SIGNED, specbits) | |
8345 | && type == char_type_node) | |
8346 | type = signed_char_type_node; | |
8347 | else if (longlong) | |
8348 | type = long_long_integer_type_node; | |
8349 | else if (RIDBIT_SETP (RID_LONG, specbits)) | |
8350 | type = long_integer_type_node; | |
8351 | else if (RIDBIT_SETP (RID_SHORT, specbits)) | |
8352 | type = short_integer_type_node; | |
8353 | ||
37c46b43 MS |
8354 | if (RIDBIT_SETP (RID_COMPLEX, specbits)) |
8355 | { | |
8356 | /* If we just have "complex", it is equivalent to | |
8357 | "complex double", but if any modifiers at all are specified it is | |
8358 | the complex form of TYPE. E.g, "complex short" is | |
8359 | "complex short int". */ | |
8360 | ||
8361 | if (defaulted_int && ! longlong | |
8362 | && ! (RIDBIT_SETP (RID_LONG, specbits) | |
8363 | || RIDBIT_SETP (RID_SHORT, specbits) | |
8364 | || RIDBIT_SETP (RID_SIGNED, specbits) | |
8365 | || RIDBIT_SETP (RID_UNSIGNED, specbits))) | |
8366 | type = complex_double_type_node; | |
8367 | else if (type == integer_type_node) | |
8368 | type = complex_integer_type_node; | |
8369 | else if (type == float_type_node) | |
8370 | type = complex_float_type_node; | |
8371 | else if (type == double_type_node) | |
8372 | type = complex_double_type_node; | |
8373 | else if (type == long_double_type_node) | |
8374 | type = complex_long_double_type_node; | |
8375 | else | |
8376 | type = build_complex_type (type); | |
8377 | } | |
8378 | ||
3ac3d9ea MM |
8379 | if (return_type == return_conversion |
8380 | && (RIDBIT_SETP (RID_CONST, specbits) | |
8381 | || RIDBIT_SETP (RID_VOLATILE, specbits))) | |
8382 | cp_error ("`operator %T' cannot be cv-qualified", | |
8383 | ctor_return_type); | |
8384 | ||
8d08fdba MS |
8385 | /* Set CONSTP if this declaration is `const', whether by |
8386 | explicit specification or via a typedef. | |
8387 | Likewise for VOLATILEP. */ | |
8388 | ||
8389 | constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type); | |
8390 | volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type); | |
18922a6b | 8391 | type = TYPE_MAIN_VARIANT (type); |
8d08fdba MS |
8392 | staticp = 0; |
8393 | inlinep = !! RIDBIT_SETP (RID_INLINE, specbits); | |
8d08fdba | 8394 | virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits); |
db5ae43f MS |
8395 | RIDBIT_RESET (RID_VIRTUAL, specbits); |
8396 | explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0; | |
8397 | RIDBIT_RESET (RID_EXPLICIT, specbits); | |
8d08fdba | 8398 | |
8d08fdba MS |
8399 | if (RIDBIT_SETP (RID_STATIC, specbits)) |
8400 | staticp = 1 + (decl_context == FIELD); | |
8401 | ||
8402 | if (virtualp && staticp == 2) | |
8403 | { | |
8404 | cp_error ("member `%D' cannot be declared both virtual and static", | |
8405 | dname); | |
8406 | staticp = 0; | |
8407 | } | |
8408 | friendp = RIDBIT_SETP (RID_FRIEND, specbits); | |
8d08fdba MS |
8409 | RIDBIT_RESET (RID_FRIEND, specbits); |
8410 | ||
8411 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
8412 | { | |
8413 | if (decl_context == PARM) | |
8414 | { | |
db5ae43f | 8415 | error ("non-member `%s' cannot be declared `mutable'", name); |
8d08fdba MS |
8416 | RIDBIT_RESET (RID_MUTABLE, specbits); |
8417 | } | |
8418 | else if (friendp || decl_context == TYPENAME) | |
8419 | { | |
db5ae43f | 8420 | error ("non-object member `%s' cannot be declared `mutable'", name); |
8d08fdba MS |
8421 | RIDBIT_RESET (RID_MUTABLE, specbits); |
8422 | } | |
8d08fdba MS |
8423 | } |
8424 | ||
8425 | /* Warn if two storage classes are given. Default to `auto'. */ | |
8426 | ||
8427 | if (RIDBIT_ANY_SET (specbits)) | |
8428 | { | |
8429 | if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++; | |
8430 | if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++; | |
8431 | if (decl_context == PARM && nclasses > 0) | |
8432 | error ("storage class specifiers invalid in parameter declarations"); | |
8433 | if (RIDBIT_SETP (RID_TYPEDEF, specbits)) | |
8434 | { | |
8435 | if (decl_context == PARM) | |
8436 | error ("typedef declaration invalid in parameter declaration"); | |
8437 | nclasses++; | |
8438 | } | |
8439 | if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++; | |
8440 | if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++; | |
8441 | } | |
8442 | ||
8443 | /* Give error if `virtual' is used outside of class declaration. */ | |
b7484fbe MS |
8444 | if (virtualp |
8445 | && (current_class_name == NULL_TREE || decl_context != FIELD)) | |
8d08fdba MS |
8446 | { |
8447 | error ("virtual outside class declaration"); | |
8448 | virtualp = 0; | |
8449 | } | |
8450 | if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits)) | |
8451 | { | |
8452 | error ("only members can be declared mutable"); | |
8453 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
8454 | } | |
8455 | ||
8456 | /* Static anonymous unions are dealt with here. */ | |
8457 | if (staticp && decl_context == TYPENAME | |
8458 | && TREE_CODE (declspecs) == TREE_LIST | |
8459 | && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE | |
8460 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs)))) | |
8461 | decl_context = FIELD; | |
8462 | ||
8463 | /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual' | |
8464 | is used in a signature member function declaration. */ | |
8465 | if (decl_context == FIELD | |
8466 | && IS_SIGNATURE (current_class_type) | |
fc378698 | 8467 | && RIDBIT_NOTSETP (RID_TYPEDEF, specbits)) |
8d08fdba MS |
8468 | { |
8469 | if (constp) | |
8470 | { | |
8471 | error ("`const' specified for signature member function `%s'", name); | |
8472 | constp = 0; | |
8473 | } | |
8474 | if (volatilep) | |
8475 | { | |
a28e3c7f MS |
8476 | error ("`volatile' specified for signature member function `%s'", |
8477 | name); | |
8d08fdba MS |
8478 | volatilep = 0; |
8479 | } | |
8480 | if (inlinep) | |
8481 | { | |
8482 | error ("`inline' specified for signature member function `%s'", name); | |
8483 | /* Later, we'll make signature member functions inline. */ | |
8484 | inlinep = 0; | |
8485 | } | |
8486 | if (friendp) | |
8487 | { | |
8488 | error ("`friend' declaration in signature definition"); | |
8489 | friendp = 0; | |
8490 | } | |
8491 | if (virtualp) | |
8492 | { | |
a28e3c7f MS |
8493 | error ("`virtual' specified for signature member function `%s'", |
8494 | name); | |
8d08fdba MS |
8495 | /* Later, we'll make signature member functions virtual. */ |
8496 | virtualp = 0; | |
8497 | } | |
8498 | } | |
8499 | ||
8500 | /* Warn about storage classes that are invalid for certain | |
8501 | kinds of declarations (parameters, typenames, etc.). */ | |
8502 | ||
8503 | if (nclasses > 1) | |
8504 | error ("multiple storage classes in declaration of `%s'", name); | |
8505 | else if (decl_context != NORMAL && nclasses > 0) | |
8506 | { | |
db5ae43f | 8507 | if ((decl_context == PARM || decl_context == CATCHPARM) |
8d08fdba MS |
8508 | && (RIDBIT_SETP (RID_REGISTER, specbits) |
8509 | || RIDBIT_SETP (RID_AUTO, specbits))) | |
8510 | ; | |
fc378698 MS |
8511 | else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) |
8512 | ; | |
8d08fdba | 8513 | else if (decl_context == FIELD |
fc378698 | 8514 | && ! IS_SIGNATURE (current_class_type) |
8d08fdba MS |
8515 | /* C++ allows static class elements */ |
8516 | && RIDBIT_SETP (RID_STATIC, specbits)) | |
8517 | /* C++ also allows inlines and signed and unsigned elements, | |
8518 | but in those cases we don't come in here. */ | |
8519 | ; | |
8520 | else | |
8521 | { | |
8522 | if (decl_context == FIELD) | |
8523 | { | |
b7484fbe MS |
8524 | tree tmp = NULL_TREE; |
8525 | register int op = 0; | |
8526 | ||
8527 | if (declarator) | |
8528 | { | |
9e9ff709 MS |
8529 | /* Avoid trying to get an operand off an identifier node. */ |
8530 | if (TREE_CODE (declarator) == IDENTIFIER_NODE) | |
8531 | tmp = declarator; | |
8532 | else | |
8533 | tmp = TREE_OPERAND (declarator, 0); | |
b7484fbe MS |
8534 | op = IDENTIFIER_OPNAME_P (tmp); |
8535 | } | |
8d08fdba MS |
8536 | error ("storage class specified for %s `%s'", |
8537 | IS_SIGNATURE (current_class_type) | |
8538 | ? (op | |
8539 | ? "signature member operator" | |
8540 | : "signature member function") | |
b7484fbe | 8541 | : (op ? "member operator" : "field"), |
8d08fdba MS |
8542 | op ? operator_name_string (tmp) : name); |
8543 | } | |
8544 | else | |
db5ae43f | 8545 | error (((decl_context == PARM || decl_context == CATCHPARM) |
8d08fdba MS |
8546 | ? "storage class specified for parameter `%s'" |
8547 | : "storage class specified for typename"), name); | |
8548 | RIDBIT_RESET (RID_REGISTER, specbits); | |
8549 | RIDBIT_RESET (RID_AUTO, specbits); | |
8550 | RIDBIT_RESET (RID_EXTERN, specbits); | |
8551 | ||
8552 | if (decl_context == FIELD && IS_SIGNATURE (current_class_type)) | |
8553 | { | |
8554 | RIDBIT_RESET (RID_STATIC, specbits); | |
8555 | staticp = 0; | |
8556 | } | |
8557 | } | |
8558 | } | |
8559 | else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag) | |
8560 | { | |
a9aedbc2 | 8561 | if (toplevel_bindings_p ()) |
8d08fdba | 8562 | { |
59be0cdd | 8563 | /* It's common practice (and completely valid) to have a const |
8d08fdba MS |
8564 | be initialized and declared extern. */ |
8565 | if (! constp) | |
8566 | warning ("`%s' initialized and declared `extern'", name); | |
8567 | } | |
8568 | else | |
8569 | error ("`%s' has both `extern' and initializer", name); | |
8570 | } | |
8571 | else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag | |
a9aedbc2 | 8572 | && ! toplevel_bindings_p ()) |
8d08fdba | 8573 | error ("nested function `%s' declared `extern'", name); |
a9aedbc2 | 8574 | else if (toplevel_bindings_p ()) |
8d08fdba MS |
8575 | { |
8576 | if (RIDBIT_SETP (RID_AUTO, specbits)) | |
8577 | error ("top-level declaration of `%s' specifies `auto'", name); | |
8d08fdba MS |
8578 | } |
8579 | ||
909e536a MS |
8580 | if (nclasses > 0 && friendp) |
8581 | error ("storage class specifiers invalid in friend function declarations"); | |
8582 | ||
8d08fdba MS |
8583 | /* Now figure out the structure of the declarator proper. |
8584 | Descend through it, creating more complex types, until we reach | |
8585 | the declared identifier (or NULL_TREE, in an absolute declarator). */ | |
8586 | ||
386b8a85 JM |
8587 | while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE |
8588 | && TREE_CODE (declarator) != TEMPLATE_ID_EXPR) | |
8d08fdba MS |
8589 | { |
8590 | /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), | |
8591 | an INDIRECT_REF (for *...), | |
8592 | a CALL_EXPR (for ...(...)), | |
8593 | an identifier (for the name being declared) | |
8594 | or a null pointer (for the place in an absolute declarator | |
8595 | where the name was omitted). | |
8596 | For the last two cases, we have just exited the loop. | |
8597 | ||
8598 | For C++ it could also be | |
8599 | a SCOPE_REF (for class :: ...). In this case, we have converted | |
8600 | sensible names to types, and those are the values we use to | |
8601 | qualify the member name. | |
8602 | an ADDR_EXPR (for &...), | |
8603 | a BIT_NOT_EXPR (for destructors) | |
8d08fdba MS |
8604 | |
8605 | At this point, TYPE is the type of elements of an array, | |
8606 | or for a function to return, or for a pointer to point to. | |
8607 | After this sequence of ifs, TYPE is the type of the | |
8608 | array or function or pointer, and DECLARATOR has had its | |
8609 | outermost layer removed. */ | |
8610 | ||
bd6dd845 | 8611 | if (type == error_mark_node) |
8d08fdba MS |
8612 | { |
8613 | if (TREE_CODE (declarator) == SCOPE_REF) | |
8614 | declarator = TREE_OPERAND (declarator, 1); | |
8615 | else | |
8616 | declarator = TREE_OPERAND (declarator, 0); | |
8617 | continue; | |
8618 | } | |
8619 | if (quals != NULL_TREE | |
8620 | && (declarator == NULL_TREE | |
8621 | || TREE_CODE (declarator) != SCOPE_REF)) | |
8622 | { | |
8623 | if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE) | |
8624 | ctype = TYPE_METHOD_BASETYPE (type); | |
8625 | if (ctype != NULL_TREE) | |
8626 | { | |
8d08fdba | 8627 | tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); |
8d08fdba MS |
8628 | ctype = grok_method_quals (ctype, dummy, quals); |
8629 | type = TREE_TYPE (dummy); | |
8630 | quals = NULL_TREE; | |
8631 | } | |
8632 | } | |
8633 | switch (TREE_CODE (declarator)) | |
8634 | { | |
8635 | case ARRAY_REF: | |
8636 | { | |
8637 | register tree itype = NULL_TREE; | |
8638 | register tree size = TREE_OPERAND (declarator, 1); | |
b7484fbe MS |
8639 | /* The index is a signed object `sizetype' bits wide. */ |
8640 | tree index_type = signed_type (sizetype); | |
8d08fdba MS |
8641 | |
8642 | declarator = TREE_OPERAND (declarator, 0); | |
8643 | ||
8644 | /* Check for some types that there cannot be arrays of. */ | |
8645 | ||
8646 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
8647 | { | |
8648 | cp_error ("declaration of `%D' as array of voids", dname); | |
8649 | type = error_mark_node; | |
8650 | } | |
8651 | ||
8652 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
8653 | { | |
8654 | cp_error ("declaration of `%D' as array of functions", dname); | |
8655 | type = error_mark_node; | |
8656 | } | |
8657 | ||
8658 | /* ARM $8.4.3: Since you can't have a pointer to a reference, | |
8659 | you can't have arrays of references. If we allowed them, | |
59be0cdd | 8660 | then we'd be saying x[i] is valid for an array x, but |
8d08fdba MS |
8661 | then you'd have to ask: what does `*(x + i)' mean? */ |
8662 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
8663 | { | |
8664 | if (decl_context == TYPENAME) | |
8665 | cp_error ("cannot make arrays of references"); | |
8666 | else | |
8667 | cp_error ("declaration of `%D' as array of references", | |
8668 | dname); | |
8669 | type = error_mark_node; | |
8670 | } | |
8671 | ||
8672 | if (TREE_CODE (type) == OFFSET_TYPE) | |
8673 | { | |
8674 | cp_error ("declaration of `%D' as array of data members", | |
8675 | dname); | |
8676 | type = error_mark_node; | |
8677 | } | |
8678 | ||
8679 | if (TREE_CODE (type) == METHOD_TYPE) | |
8680 | { | |
8681 | cp_error ("declaration of `%D' as array of function members", | |
8682 | dname); | |
8683 | type = error_mark_node; | |
8684 | } | |
8685 | ||
8686 | if (size == error_mark_node) | |
8687 | type = error_mark_node; | |
8688 | ||
8689 | if (type == error_mark_node) | |
8690 | continue; | |
8691 | ||
8692 | if (size) | |
8693 | { | |
8694 | /* Must suspend_momentary here because the index | |
8695 | type may need to live until the end of the function. | |
8696 | For example, it is used in the declaration of a | |
8697 | variable which requires destructing at the end of | |
8698 | the function; then build_vec_delete will need this | |
8699 | value. */ | |
8700 | int yes = suspend_momentary (); | |
8701 | /* might be a cast */ | |
8702 | if (TREE_CODE (size) == NOP_EXPR | |
8703 | && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) | |
8704 | size = TREE_OPERAND (size, 0); | |
8705 | ||
5566b478 MS |
8706 | /* If this involves a template parameter, it'll be |
8707 | constant, but we don't know what the value is yet. */ | |
5156628f | 8708 | if (processing_template_decl) |
5566b478 MS |
8709 | { |
8710 | itype = make_node (INTEGER_TYPE); | |
8711 | TYPE_MIN_VALUE (itype) = size_zero_node; | |
8712 | TYPE_MAX_VALUE (itype) = build_min | |
8713 | (MINUS_EXPR, sizetype, size, integer_one_node); | |
8714 | goto dont_grok_size; | |
8715 | } | |
8d08fdba MS |
8716 | |
8717 | if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE | |
8718 | && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) | |
8719 | { | |
8720 | cp_error ("size of array `%D' has non-integer type", | |
8721 | dname); | |
8722 | size = integer_one_node; | |
8723 | } | |
8724 | if (TREE_READONLY_DECL_P (size)) | |
8725 | size = decl_constant_value (size); | |
e1cd6e56 | 8726 | if (pedantic && integer_zerop (size)) |
8d08fdba MS |
8727 | cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname); |
8728 | if (TREE_CONSTANT (size)) | |
8729 | { | |
dff6b454 RK |
8730 | int old_flag_pedantic_errors = flag_pedantic_errors; |
8731 | int old_pedantic = pedantic; | |
8732 | pedantic = flag_pedantic_errors = 1; | |
8733 | /* Always give overflow errors on array subscripts. */ | |
8d08fdba | 8734 | constant_expression_warning (size); |
dff6b454 RK |
8735 | pedantic = old_pedantic; |
8736 | flag_pedantic_errors = old_flag_pedantic_errors; | |
8d08fdba MS |
8737 | if (INT_CST_LT (size, integer_zero_node)) |
8738 | { | |
8739 | cp_error ("size of array `%D' is negative", dname); | |
8740 | size = integer_one_node; | |
8741 | } | |
8d08fdba MS |
8742 | } |
8743 | else | |
8744 | { | |
e1cd6e56 | 8745 | if (pedantic) |
a0a33927 MS |
8746 | { |
8747 | if (dname) | |
8748 | cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", | |
8749 | dname); | |
8750 | else | |
8751 | cp_pedwarn ("ANSI C++ forbids variable-size array"); | |
8752 | } | |
8d08fdba | 8753 | } |
b7484fbe | 8754 | |
beb53fb8 JM |
8755 | itype |
8756 | = fold (build_binary_op (MINUS_EXPR, | |
37c46b43 MS |
8757 | cp_convert (index_type, size), |
8758 | cp_convert (index_type, | |
8759 | integer_one_node), 1)); | |
b7484fbe MS |
8760 | if (! TREE_CONSTANT (itype)) |
8761 | itype = variable_size (itype); | |
594740f3 MS |
8762 | else if (TREE_OVERFLOW (itype)) |
8763 | { | |
8764 | error ("overflow in array dimension"); | |
8765 | TREE_OVERFLOW (itype) = 0; | |
8766 | } | |
fc378698 MS |
8767 | |
8768 | /* If we're a parm, we need to have a permanent type so | |
8769 | mangling checks for re-use will work right. If both the | |
8770 | element and index types are permanent, the array type | |
8771 | will be, too. */ | |
8772 | if (decl_context == PARM | |
8773 | && allocation_temporary_p () && TREE_PERMANENT (type)) | |
8774 | { | |
8775 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
8776 | itype = build_index_type (itype); | |
8777 | pop_obstacks (); | |
8778 | } | |
8779 | else | |
8780 | itype = build_index_type (itype); | |
8781 | ||
5566b478 | 8782 | dont_grok_size: |
8d08fdba MS |
8783 | resume_momentary (yes); |
8784 | } | |
8785 | ||
8786 | /* Build the array type itself, then merge any constancy or | |
8787 | volatility into the target type. We must do it in this order | |
8788 | to ensure that the TYPE_MAIN_VARIANT field of the array type | |
8789 | is set correctly. */ | |
8790 | ||
8791 | type = build_cplus_array_type (type, itype); | |
8792 | if (constp || volatilep) | |
f376e137 | 8793 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
8794 | |
8795 | ctype = NULL_TREE; | |
8796 | } | |
8797 | break; | |
8798 | ||
8799 | case CALL_EXPR: | |
8800 | { | |
8801 | tree arg_types; | |
f376e137 MS |
8802 | int funcdecl_p; |
8803 | tree inner_parms = TREE_OPERAND (declarator, 1); | |
8804 | tree inner_decl = TREE_OPERAND (declarator, 0); | |
8d08fdba MS |
8805 | |
8806 | /* Declaring a function type. | |
8807 | Make sure we have a valid type for the function to return. */ | |
8808 | #if 0 | |
8809 | /* Is this an error? Should they be merged into TYPE here? */ | |
8810 | if (pedantic && (constp || volatilep)) | |
8811 | pedwarn ("function declared to return const or volatile result"); | |
8812 | #else | |
21474714 MS |
8813 | /* Merge any constancy or volatility into the function return |
8814 | type. */ | |
8d08fdba MS |
8815 | |
8816 | if (constp || volatilep) | |
8817 | { | |
f376e137 | 8818 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
8819 | if (IS_AGGR_TYPE (type)) |
8820 | build_pointer_type (type); | |
8821 | constp = 0; | |
8822 | volatilep = 0; | |
8823 | } | |
8824 | #endif | |
8825 | ||
8826 | /* Warn about some types functions can't return. */ | |
8827 | ||
8828 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
8829 | { | |
8830 | error ("`%s' declared as function returning a function", name); | |
8831 | type = integer_type_node; | |
8832 | } | |
8833 | if (TREE_CODE (type) == ARRAY_TYPE) | |
8834 | { | |
8835 | error ("`%s' declared as function returning an array", name); | |
8836 | type = integer_type_node; | |
8837 | } | |
8838 | ||
f376e137 MS |
8839 | if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) |
8840 | inner_decl = TREE_OPERAND (inner_decl, 1); | |
8841 | ||
386b8a85 JM |
8842 | if (inner_decl && TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR) |
8843 | inner_decl = dname; | |
8844 | ||
b7484fbe MS |
8845 | /* Pick up type qualifiers which should be applied to `this'. */ |
8846 | quals = TREE_OPERAND (declarator, 2); | |
8847 | ||
c11b6f21 MS |
8848 | /* Pick up the exception specifications. */ |
8849 | raises = TREE_TYPE (declarator); | |
8850 | ||
f376e137 MS |
8851 | /* Say it's a definition only for the CALL_EXPR |
8852 | closest to the identifier. */ | |
beb53fb8 | 8853 | funcdecl_p |
386b8a85 JM |
8854 | = inner_decl |
8855 | && (TREE_CODE (inner_decl) == IDENTIFIER_NODE | |
8856 | || TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR | |
8857 | || TREE_CODE (inner_decl) == BIT_NOT_EXPR); | |
8858 | ||
8d08fdba MS |
8859 | if (ctype == NULL_TREE |
8860 | && decl_context == FIELD | |
f376e137 | 8861 | && funcdecl_p |
8d08fdba MS |
8862 | && (friendp == 0 || dname == current_class_name)) |
8863 | ctype = current_class_type; | |
8864 | ||
51c184be | 8865 | if (ctype && return_type == return_conversion) |
8d08fdba MS |
8866 | TYPE_HAS_CONVERSION (ctype) = 1; |
8867 | if (ctype && constructor_name (ctype) == dname) | |
8868 | { | |
8869 | /* We are within a class's scope. If our declarator name | |
8870 | is the same as the class name, and we are defining | |
8871 | a function, then it is a constructor/destructor, and | |
8872 | therefore returns a void type. */ | |
8873 | ||
8874 | if (flags == DTOR_FLAG) | |
8875 | { | |
8876 | /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may | |
8877 | not be declared const or volatile. A destructor | |
8878 | may not be static. */ | |
8879 | if (staticp == 2) | |
8880 | error ("destructor cannot be static member function"); | |
b7484fbe | 8881 | if (quals) |
8d08fdba | 8882 | { |
b7484fbe | 8883 | error ("destructors cannot be declared `const' or `volatile'"); |
8d08fdba MS |
8884 | return void_type_node; |
8885 | } | |
8886 | if (decl_context == FIELD) | |
8887 | { | |
8888 | if (! member_function_or_else (ctype, current_class_type, | |
8889 | "destructor for alien class `%s' cannot be a member")) | |
8890 | return void_type_node; | |
8891 | } | |
8892 | } | |
e92cc029 | 8893 | else /* it's a constructor. */ |
8d08fdba | 8894 | { |
db5ae43f MS |
8895 | if (explicitp == 1) |
8896 | explicitp = 2; | |
8d08fdba MS |
8897 | /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may |
8898 | not be declared const or volatile. A constructor may | |
8899 | not be virtual. A constructor may not be static. */ | |
8900 | if (staticp == 2) | |
8901 | error ("constructor cannot be static member function"); | |
8902 | if (virtualp) | |
8903 | { | |
8904 | pedwarn ("constructors cannot be declared virtual"); | |
8905 | virtualp = 0; | |
8906 | } | |
b7484fbe | 8907 | if (quals) |
8d08fdba | 8908 | { |
b7484fbe | 8909 | error ("constructors cannot be declared `const' or `volatile'"); |
8d08fdba MS |
8910 | return void_type_node; |
8911 | } | |
8d08fdba | 8912 | { |
51c184be | 8913 | RID_BIT_TYPE tmp_bits; |
fc378698 | 8914 | bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof (RID_BIT_TYPE)); |
51c184be MS |
8915 | RIDBIT_RESET (RID_INLINE, tmp_bits); |
8916 | RIDBIT_RESET (RID_STATIC, tmp_bits); | |
8917 | if (RIDBIT_ANY_SET (tmp_bits)) | |
8d08fdba | 8918 | error ("return value type specifier for constructor ignored"); |
8d08fdba | 8919 | } |
f30432d7 | 8920 | type = build_pointer_type (ctype); |
beb53fb8 JM |
8921 | if (decl_context == FIELD |
8922 | && IS_SIGNATURE (current_class_type)) | |
8d08fdba MS |
8923 | { |
8924 | error ("constructor not allowed in signature"); | |
8925 | return void_type_node; | |
8926 | } | |
8927 | else if (decl_context == FIELD) | |
8928 | { | |
8929 | if (! member_function_or_else (ctype, current_class_type, | |
8930 | "constructor for alien class `%s' cannot be member")) | |
8931 | return void_type_node; | |
8932 | TYPE_HAS_CONSTRUCTOR (ctype) = 1; | |
8933 | if (return_type != return_ctor) | |
8934 | return NULL_TREE; | |
8935 | } | |
8936 | } | |
8937 | if (decl_context == FIELD) | |
8938 | staticp = 0; | |
8939 | } | |
b7484fbe | 8940 | else if (friendp) |
8d08fdba | 8941 | { |
b7484fbe MS |
8942 | if (initialized) |
8943 | error ("can't initialize friend function `%s'", name); | |
8944 | if (virtualp) | |
8945 | { | |
8946 | /* Cannot be both friend and virtual. */ | |
8947 | error ("virtual functions cannot be friends"); | |
8948 | RIDBIT_RESET (RID_FRIEND, specbits); | |
8949 | friendp = 0; | |
8950 | } | |
28cbf42c MS |
8951 | if (decl_context == NORMAL) |
8952 | error ("friend declaration not in class definition"); | |
8953 | if (current_function_decl && funcdef_flag) | |
8954 | cp_error ("can't define friend function `%s' in a local class definition", | |
8955 | name); | |
8d08fdba MS |
8956 | } |
8957 | ||
8d08fdba MS |
8958 | /* Construct the function type and go to the next |
8959 | inner layer of declarator. */ | |
8960 | ||
f376e137 | 8961 | declarator = TREE_OPERAND (declarator, 0); |
8d08fdba | 8962 | |
f376e137 MS |
8963 | /* FIXME: This is where default args should be fully |
8964 | processed. */ | |
8d08fdba | 8965 | |
f376e137 | 8966 | arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0); |
8d08fdba MS |
8967 | |
8968 | if (declarator) | |
8969 | { | |
8970 | /* Get past destructors, etc. | |
8971 | We know we have one because FLAGS will be non-zero. | |
8972 | ||
8973 | Complain about improper parameter lists here. */ | |
8974 | if (TREE_CODE (declarator) == BIT_NOT_EXPR) | |
8975 | { | |
8976 | declarator = TREE_OPERAND (declarator, 0); | |
8977 | ||
8978 | if (strict_prototype == 0 && arg_types == NULL_TREE) | |
8979 | arg_types = void_list_node; | |
8980 | else if (arg_types == NULL_TREE | |
8981 | || arg_types != void_list_node) | |
8982 | { | |
8983 | error ("destructors cannot be specified with parameters"); | |
8984 | arg_types = void_list_node; | |
8985 | } | |
8986 | } | |
8987 | } | |
8988 | ||
d22c8596 | 8989 | /* ANSI says that `const int foo ();' |
8d08fdba | 8990 | does not make the function foo const. */ |
d22c8596 | 8991 | type = build_function_type (type, arg_types); |
42976354 BK |
8992 | |
8993 | { | |
8994 | tree t; | |
8995 | for (t = arg_types; t; t = TREE_CHAIN (t)) | |
8996 | if (TREE_PURPOSE (t) | |
8997 | && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) | |
8998 | { | |
8999 | add_defarg_fn (type); | |
9000 | break; | |
9001 | } | |
9002 | } | |
8d08fdba MS |
9003 | } |
9004 | break; | |
9005 | ||
9006 | case ADDR_EXPR: | |
9007 | case INDIRECT_REF: | |
9008 | /* Filter out pointers-to-references and references-to-references. | |
9009 | We can get these if a TYPE_DECL is used. */ | |
9010 | ||
9011 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
9012 | { | |
9013 | error ("cannot declare %s to references", | |
9014 | TREE_CODE (declarator) == ADDR_EXPR | |
9015 | ? "references" : "pointers"); | |
9016 | declarator = TREE_OPERAND (declarator, 0); | |
9017 | continue; | |
9018 | } | |
9019 | ||
a5894242 MS |
9020 | if (TREE_CODE (type) == OFFSET_TYPE |
9021 | && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE | |
9022 | || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE)) | |
9023 | { | |
9024 | cp_error ("cannot declare pointer to `%#T' member", | |
9025 | TREE_TYPE (type)); | |
9026 | type = TREE_TYPE (type); | |
9027 | } | |
9028 | ||
8d08fdba MS |
9029 | /* Merge any constancy or volatility into the target type |
9030 | for the pointer. */ | |
9031 | ||
9032 | if (constp || volatilep) | |
9033 | { | |
9034 | /* A const or volatile signature pointer/reference is | |
9035 | pointing to a const or volatile object, i.e., the | |
9036 | `optr' is const or volatile, respectively, not the | |
9037 | signature pointer/reference itself. */ | |
9038 | if (! IS_SIGNATURE (type)) | |
9039 | { | |
f376e137 | 9040 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
9041 | if (IS_AGGR_TYPE (type)) |
9042 | build_pointer_type (type); | |
9043 | constp = 0; | |
9044 | volatilep = 0; | |
9045 | } | |
9046 | } | |
9047 | ||
9048 | if (IS_SIGNATURE (type)) | |
9049 | { | |
9050 | if (TREE_CODE (declarator) == ADDR_EXPR) | |
9051 | { | |
63718c49 GB |
9052 | if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE |
9053 | && TYPE_SIZE (type)) | |
9054 | cp_warning ("empty signature `%T' used in signature reference declaration", | |
9055 | type); | |
8d08fdba MS |
9056 | #if 0 |
9057 | type = build_signature_reference_type (type, | |
9058 | constp, volatilep); | |
9059 | #else | |
9060 | sorry ("signature reference"); | |
9061 | return NULL_TREE; | |
9062 | #endif | |
9063 | } | |
9064 | else | |
9065 | { | |
63718c49 GB |
9066 | if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE |
9067 | && TYPE_SIZE (type)) | |
9068 | cp_warning ("empty signature `%T' used in signature pointer declaration", | |
9069 | type); | |
8d08fdba MS |
9070 | type = build_signature_pointer_type (type, |
9071 | constp, volatilep); | |
9072 | } | |
9073 | constp = 0; | |
9074 | volatilep = 0; | |
9075 | } | |
9076 | else if (TREE_CODE (declarator) == ADDR_EXPR) | |
9077 | { | |
9078 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
9079 | { | |
9080 | error ("cannot declare references to functions; use pointer to function instead"); | |
9081 | type = build_pointer_type (type); | |
9082 | } | |
9083 | else | |
9084 | { | |
9085 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
9086 | error ("invalid type: `void &'"); | |
9087 | else | |
9088 | type = build_reference_type (type); | |
9089 | } | |
9090 | } | |
9091 | else if (TREE_CODE (type) == METHOD_TYPE) | |
9092 | { | |
9093 | type = build_ptrmemfunc_type (build_pointer_type (type)); | |
9094 | } | |
9095 | else | |
9096 | type = build_pointer_type (type); | |
9097 | ||
9098 | /* Process a list of type modifier keywords (such as | |
9099 | const or volatile) that were given inside the `*' or `&'. */ | |
9100 | ||
9101 | if (TREE_TYPE (declarator)) | |
9102 | { | |
9103 | register tree typemodlist; | |
9104 | int erred = 0; | |
9105 | for (typemodlist = TREE_TYPE (declarator); typemodlist; | |
9106 | typemodlist = TREE_CHAIN (typemodlist)) | |
9107 | { | |
9108 | if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST]) | |
9109 | constp++; | |
9110 | else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE]) | |
9111 | volatilep++; | |
9112 | else if (!erred) | |
9113 | { | |
9114 | erred = 1; | |
9115 | error ("invalid type modifier within %s declarator", | |
9116 | TREE_CODE (declarator) == ADDR_EXPR | |
9117 | ? "reference" : "pointer"); | |
9118 | } | |
9119 | } | |
9120 | if (constp > 1) | |
a0a33927 | 9121 | pedwarn ("duplicate `const'"); |
8d08fdba | 9122 | if (volatilep > 1) |
a0a33927 MS |
9123 | pedwarn ("duplicate `volatile'"); |
9124 | if (TREE_CODE (declarator) == ADDR_EXPR | |
9125 | && (constp || volatilep)) | |
9126 | { | |
9127 | if (constp) | |
e1cd6e56 | 9128 | pedwarn ("discarding `const' applied to a reference"); |
a0a33927 | 9129 | if (volatilep) |
e1cd6e56 | 9130 | pedwarn ("discarding `volatile' applied to a reference"); |
a0a33927 MS |
9131 | constp = volatilep = 0; |
9132 | } | |
8d08fdba MS |
9133 | } |
9134 | declarator = TREE_OPERAND (declarator, 0); | |
9135 | ctype = NULL_TREE; | |
9136 | break; | |
9137 | ||
9138 | case SCOPE_REF: | |
9139 | { | |
9140 | /* We have converted type names to NULL_TREE if the | |
9141 | name was bogus, or to a _TYPE node, if not. | |
9142 | ||
9143 | The variable CTYPE holds the type we will ultimately | |
9144 | resolve to. The code here just needs to build | |
9145 | up appropriate member types. */ | |
9146 | tree sname = TREE_OPERAND (declarator, 1); | |
386b8a85 JM |
9147 | tree t; |
9148 | ||
8d08fdba MS |
9149 | /* Destructors can have their visibilities changed as well. */ |
9150 | if (TREE_CODE (sname) == BIT_NOT_EXPR) | |
9151 | sname = TREE_OPERAND (sname, 0); | |
9152 | ||
9153 | if (TREE_COMPLEXITY (declarator) == 0) | |
9154 | /* This needs to be here, in case we are called | |
9155 | multiple times. */ ; | |
9156 | else if (friendp && (TREE_COMPLEXITY (declarator) < 2)) | |
9157 | /* don't fall out into global scope. Hides real bug? --eichin */ ; | |
5566b478 MS |
9158 | else if (! IS_AGGR_TYPE_CODE |
9159 | (TREE_CODE (TREE_OPERAND (declarator, 0)))) | |
9160 | ; | |
8d08fdba MS |
9161 | else if (TREE_COMPLEXITY (declarator) == current_class_depth) |
9162 | { | |
9a3b49ac MS |
9163 | /* Resolve any TYPENAME_TYPEs from the decl-specifier-seq |
9164 | that refer to ctype. They couldn't be resolved earlier | |
9165 | because we hadn't pushed into the class yet. | |
9166 | Example: resolve 'B<T>::type' in | |
9167 | 'B<typename B<T>::type> B<T>::f () { }'. */ | |
9168 | if (current_template_parms | |
9169 | && uses_template_parms (type) | |
9170 | && uses_template_parms (current_class_type)) | |
9171 | { | |
9172 | tree args = current_template_args (); | |
f7d98d58 | 9173 | type = tsubst (type, args, NULL_TREE); |
9a3b49ac MS |
9174 | } |
9175 | ||
a28e3c7f MS |
9176 | /* This pop_nested_class corresponds to the |
9177 | push_nested_class used to push into class scope for | |
9178 | parsing the argument list of a function decl, in | |
9179 | qualified_id. */ | |
8d08fdba MS |
9180 | pop_nested_class (1); |
9181 | TREE_COMPLEXITY (declarator) = current_class_depth; | |
9182 | } | |
9183 | else | |
9184 | my_friendly_abort (16); | |
9185 | ||
9186 | if (TREE_OPERAND (declarator, 0) == NULL_TREE) | |
9187 | { | |
9188 | /* We had a reference to a global decl, or | |
9189 | perhaps we were given a non-aggregate typedef, | |
9190 | in which case we cleared this out, and should just | |
9191 | keep going as though it wasn't there. */ | |
9192 | declarator = sname; | |
9193 | continue; | |
9194 | } | |
9195 | ctype = TREE_OPERAND (declarator, 0); | |
9196 | ||
386b8a85 JM |
9197 | t = ctype; |
9198 | while (t != NULL_TREE) | |
9199 | { | |
75650646 MM |
9200 | if (CLASSTYPE_TEMPLATE_INFO (t) && |
9201 | !CLASSTYPE_TEMPLATE_SPECIALIZATION (t)) | |
386b8a85 JM |
9202 | template_count += 1; |
9203 | t = TYPE_MAIN_DECL (t); | |
9204 | if (DECL_LANG_SPECIFIC (t)) | |
9205 | t = DECL_CLASS_CONTEXT (t); | |
9206 | else | |
9207 | t = NULL_TREE; | |
9208 | } | |
9209 | ||
8d08fdba MS |
9210 | if (sname == NULL_TREE) |
9211 | goto done_scoping; | |
9212 | ||
9213 | if (TREE_CODE (sname) == IDENTIFIER_NODE) | |
9214 | { | |
9215 | /* This is the `standard' use of the scoping operator: | |
9216 | basetype :: member . */ | |
9217 | ||
db5ae43f | 9218 | if (ctype == current_class_type) |
28cbf42c MS |
9219 | { |
9220 | /* class A { | |
9221 | void A::f (); | |
9222 | }; | |
9223 | ||
9224 | Is this ill-formed? */ | |
9225 | ||
9226 | if (pedantic) | |
9227 | cp_pedwarn ("extra qualification `%T::' on member `%s' ignored", | |
9228 | ctype, name); | |
9229 | } | |
db5ae43f | 9230 | else if (TREE_CODE (type) == FUNCTION_TYPE) |
8d08fdba MS |
9231 | { |
9232 | if (current_class_type == NULL_TREE | |
8d08fdba MS |
9233 | || friendp) |
9234 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
9235 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9236 | else | |
9237 | { | |
5b605f68 | 9238 | cp_error ("cannot declare member function `%T::%s' within `%T'", |
a3203465 | 9239 | ctype, name, current_class_type); |
8d08fdba MS |
9240 | return void_type_node; |
9241 | } | |
9242 | } | |
5566b478 MS |
9243 | else if (RIDBIT_SETP (RID_TYPEDEF, specbits) |
9244 | || TYPE_SIZE (complete_type (ctype)) != NULL_TREE) | |
8d08fdba | 9245 | { |
8d08fdba | 9246 | /* have to move this code elsewhere in this function. |
db5ae43f MS |
9247 | this code is used for i.e., typedef int A::M; M *pm; |
9248 | ||
9249 | It is? How? jason 10/2/94 */ | |
8d08fdba | 9250 | |
8d08fdba MS |
9251 | if (current_class_type) |
9252 | { | |
db5ae43f MS |
9253 | cp_error ("cannot declare member `%T::%s' within `%T'", |
9254 | ctype, name, current_class_type); | |
9255 | return void_type_node; | |
8d08fdba MS |
9256 | } |
9257 | type = build_offset_type (ctype, type); | |
9258 | } | |
9259 | else if (uses_template_parms (ctype)) | |
9260 | { | |
8d08fdba | 9261 | if (TREE_CODE (type) == FUNCTION_TYPE) |
beb53fb8 JM |
9262 | type |
9263 | = build_cplus_method_type (build_type_variant (ctype, | |
9264 | constp, | |
9265 | volatilep), | |
9266 | TREE_TYPE (type), | |
9267 | TYPE_ARG_TYPES (type)); | |
8d08fdba MS |
9268 | } |
9269 | else | |
9270 | { | |
9271 | cp_error ("structure `%T' not yet defined", ctype); | |
9272 | return error_mark_node; | |
9273 | } | |
9274 | ||
9275 | declarator = sname; | |
9276 | } | |
8d08fdba MS |
9277 | else if (TREE_CODE (sname) == SCOPE_REF) |
9278 | my_friendly_abort (17); | |
9279 | else | |
9280 | { | |
9281 | done_scoping: | |
9282 | declarator = TREE_OPERAND (declarator, 1); | |
9283 | if (declarator && TREE_CODE (declarator) == CALL_EXPR) | |
9284 | /* In this case, we will deal with it later. */ | |
9285 | ; | |
9286 | else | |
9287 | { | |
9288 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
9289 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9290 | else | |
9291 | type = build_offset_type (ctype, type); | |
9292 | } | |
9293 | } | |
9294 | } | |
9295 | break; | |
9296 | ||
9297 | case BIT_NOT_EXPR: | |
9298 | declarator = TREE_OPERAND (declarator, 0); | |
9299 | break; | |
9300 | ||
8d08fdba MS |
9301 | case RECORD_TYPE: |
9302 | case UNION_TYPE: | |
9303 | case ENUMERAL_TYPE: | |
9304 | declarator = NULL_TREE; | |
9305 | break; | |
9306 | ||
9307 | case ERROR_MARK: | |
9308 | declarator = NULL_TREE; | |
9309 | break; | |
9310 | ||
9311 | default: | |
9312 | my_friendly_abort (158); | |
9313 | } | |
9314 | } | |
9315 | ||
db5ae43f MS |
9316 | if (explicitp == 1) |
9317 | { | |
9318 | error ("only constructors can be declared `explicit'"); | |
9319 | explicitp = 0; | |
9320 | } | |
9321 | ||
8d08fdba MS |
9322 | /* Now TYPE has the actual type. */ |
9323 | ||
9324 | /* If this is declaring a typedef name, return a TYPE_DECL. */ | |
9325 | ||
f30432d7 MS |
9326 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) |
9327 | { | |
9328 | if (constp) | |
9329 | { | |
9330 | error ("const `%s' cannot be declared `mutable'", name); | |
9331 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
9332 | } | |
9333 | else if (staticp) | |
9334 | { | |
9335 | error ("static `%s' cannot be declared `mutable'", name); | |
9336 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
9337 | } | |
9338 | } | |
9339 | ||
fc378698 | 9340 | if (RIDBIT_SETP (RID_TYPEDEF, specbits) && decl_context != TYPENAME) |
8d08fdba MS |
9341 | { |
9342 | tree decl; | |
9343 | ||
9344 | /* Note that the grammar rejects storage classes | |
9345 | in typenames, fields or parameters. */ | |
9346 | if (constp || volatilep) | |
f376e137 | 9347 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba | 9348 | |
d2e5ee5c MS |
9349 | if (decl_context == FIELD) |
9350 | { | |
9351 | if (declarator == current_class_name) | |
9352 | cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class", | |
9353 | declarator); | |
9354 | decl = build_lang_decl (TYPE_DECL, declarator, type); | |
9355 | if (IS_SIGNATURE (current_class_type) && opaque_typedef) | |
9356 | SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; | |
9357 | } | |
9358 | else | |
9359 | decl = build_decl (TYPE_DECL, declarator, type); | |
9360 | ||
8d08fdba MS |
9361 | /* If the user declares "struct {...} foo" then `foo' will have |
9362 | an anonymous name. Fill that name in now. Nothing can | |
9363 | refer to it, so nothing needs know about the name change. | |
9364 | The TYPE_NAME field was filled in by build_struct_xref. */ | |
9365 | if (type != error_mark_node | |
9366 | && TYPE_NAME (type) | |
9367 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
9368 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) | |
9369 | { | |
9370 | /* replace the anonymous name with the real name everywhere. */ | |
9371 | lookup_tag_reverse (type, declarator); | |
d2e5ee5c | 9372 | TYPE_NAME (type) = decl; |
8d08fdba MS |
9373 | |
9374 | if (TYPE_LANG_SPECIFIC (type)) | |
9375 | TYPE_WAS_ANONYMOUS (type) = 1; | |
9376 | ||
d2e5ee5c MS |
9377 | DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl); |
9378 | DECL_ASSEMBLER_NAME (decl) | |
9379 | = get_identifier (build_overload_name (type, 1, 1)); | |
fc378698 | 9380 | } |
fc378698 | 9381 | |
8d08fdba MS |
9382 | if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE) |
9383 | { | |
9384 | cp_error_at ("typedef name may not be class-qualified", decl); | |
a3203465 | 9385 | return NULL_TREE; |
8d08fdba MS |
9386 | } |
9387 | else if (quals) | |
9388 | { | |
9389 | if (ctype == NULL_TREE) | |
9390 | { | |
9391 | if (TREE_CODE (type) != METHOD_TYPE) | |
9392 | cp_error_at ("invalid type qualifier for non-method type", decl); | |
9393 | else | |
9394 | ctype = TYPE_METHOD_BASETYPE (type); | |
9395 | } | |
9396 | if (ctype != NULL_TREE) | |
9397 | grok_method_quals (ctype, decl, quals); | |
9398 | } | |
9399 | ||
9400 | if (RIDBIT_SETP (RID_SIGNED, specbits) | |
9401 | || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
9402 | C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; | |
9403 | ||
9404 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
9405 | { | |
9406 | error ("non-object member `%s' cannot be declared mutable", name); | |
9407 | } | |
9408 | ||
c91a56d2 MS |
9409 | bad_specifiers (decl, "type", virtualp, quals != NULL_TREE, |
9410 | inlinep, friendp, raises != NULL_TREE); | |
9411 | ||
9412 | if (initialized) | |
9413 | error ("typedef declaration includes an initializer"); | |
9414 | ||
8d08fdba MS |
9415 | return decl; |
9416 | } | |
9417 | ||
9418 | /* Detect the case of an array type of unspecified size | |
9419 | which came, as such, direct from a typedef name. | |
9420 | We must copy the type, so that each identifier gets | |
9421 | a distinct type, so that each identifier's size can be | |
9422 | controlled separately by its own initializer. */ | |
9423 | ||
9424 | if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE | |
9425 | && TYPE_DOMAIN (type) == NULL_TREE) | |
9426 | { | |
9427 | type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); | |
9428 | } | |
9429 | ||
9430 | /* If this is a type name (such as, in a cast or sizeof), | |
9431 | compute the type and return it now. */ | |
9432 | ||
9433 | if (decl_context == TYPENAME) | |
9434 | { | |
9435 | /* Note that the grammar rejects storage classes | |
9436 | in typenames, fields or parameters. */ | |
9437 | if (constp || volatilep) | |
a703fb38 KG |
9438 | { |
9439 | if (IS_SIGNATURE (type)) | |
9440 | error ("`const' or `volatile' specified with signature type"); | |
9441 | else | |
9442 | type = cp_build_type_variant (type, constp, volatilep); | |
9443 | } | |
8d08fdba MS |
9444 | |
9445 | /* Special case: "friend class foo" looks like a TYPENAME context. */ | |
9446 | if (friendp) | |
9447 | { | |
b7484fbe MS |
9448 | if (volatilep) |
9449 | { | |
9450 | cp_error ("`volatile' specified for friend class declaration"); | |
9451 | volatilep = 0; | |
9452 | } | |
9453 | if (inlinep) | |
9454 | { | |
9455 | cp_error ("`inline' specified for friend class declaration"); | |
9456 | inlinep = 0; | |
9457 | } | |
9458 | ||
9459 | /* Only try to do this stuff if we didn't already give up. */ | |
9460 | if (type != integer_type_node) | |
9461 | { | |
9462 | /* A friendly class? */ | |
9463 | if (current_class_type) | |
9464 | make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type)); | |
9465 | else | |
9466 | error ("trying to make class `%s' a friend of global scope", | |
9467 | TYPE_NAME_STRING (type)); | |
9468 | type = void_type_node; | |
9469 | } | |
8d08fdba MS |
9470 | } |
9471 | else if (quals) | |
9472 | { | |
8d08fdba | 9473 | tree dummy = build_decl (TYPE_DECL, declarator, type); |
8d08fdba MS |
9474 | if (ctype == NULL_TREE) |
9475 | { | |
9476 | my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); | |
9477 | ctype = TYPE_METHOD_BASETYPE (type); | |
9478 | } | |
9479 | grok_method_quals (ctype, dummy, quals); | |
9480 | type = TREE_TYPE (dummy); | |
9481 | } | |
9482 | ||
9483 | return type; | |
9484 | } | |
9485 | else if (declarator == NULL_TREE && decl_context != PARM | |
db5ae43f | 9486 | && decl_context != CATCHPARM |
8d08fdba MS |
9487 | && TREE_CODE (type) != UNION_TYPE |
9488 | && ! bitfield) | |
9489 | { | |
9490 | cp_error ("abstract declarator `%T' used as declaration", type); | |
9491 | declarator = make_anon_name (); | |
9492 | } | |
9493 | ||
9494 | /* `void' at top level (not within pointer) | |
9495 | is allowed only in typedefs or type names. | |
9496 | We don't complain about parms either, but that is because | |
9497 | a better error message can be made later. */ | |
9498 | ||
9499 | if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM) | |
9500 | { | |
b7484fbe MS |
9501 | if (! declarator) |
9502 | error ("unnamed variable or field declared void"); | |
9503 | else if (TREE_CODE (declarator) == IDENTIFIER_NODE) | |
8d08fdba MS |
9504 | { |
9505 | if (IDENTIFIER_OPNAME_P (declarator)) | |
8d08fdba | 9506 | my_friendly_abort (356); |
8d08fdba MS |
9507 | else |
9508 | error ("variable or field `%s' declared void", name); | |
9509 | } | |
9510 | else | |
9511 | error ("variable or field declared void"); | |
9512 | type = integer_type_node; | |
9513 | } | |
9514 | ||
9515 | /* Now create the decl, which may be a VAR_DECL, a PARM_DECL | |
9516 | or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ | |
9517 | ||
9518 | { | |
9519 | register tree decl; | |
9520 | ||
9521 | if (decl_context == PARM) | |
9522 | { | |
8d08fdba MS |
9523 | if (ctype) |
9524 | error ("cannot use `::' in parameter declaration"); | |
9525 | ||
9526 | /* A parameter declared as an array of T is really a pointer to T. | |
9527 | One declared as a function is really a pointer to a function. | |
39211cd5 | 9528 | One declared as a member is really a pointer to member. */ |
8d08fdba MS |
9529 | |
9530 | if (TREE_CODE (type) == ARRAY_TYPE) | |
9531 | { | |
e92cc029 | 9532 | /* Transfer const-ness of array into that of type pointed to. */ |
39211cd5 | 9533 | type = build_pointer_type |
f376e137 | 9534 | (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); |
39211cd5 | 9535 | volatilep = constp = 0; |
8d08fdba MS |
9536 | } |
9537 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
9538 | type = build_pointer_type (type); | |
9539 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
9540 | type = build_pointer_type (type); | |
b7484fbe MS |
9541 | else if (type == void_type_node && declarator) |
9542 | { | |
9543 | error ("declaration of `%s' as void", name); | |
9544 | return NULL_TREE; | |
9545 | } | |
8d08fdba | 9546 | |
e349ee73 | 9547 | decl = build_decl (PARM_DECL, declarator, complete_type (type)); |
8d08fdba MS |
9548 | |
9549 | bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, | |
9550 | inlinep, friendp, raises != NULL_TREE); | |
9551 | if (current_class_type | |
9552 | && IS_SIGNATURE (current_class_type)) | |
9553 | { | |
9554 | if (inlinep) | |
9555 | error ("parameter of signature member function declared `inline'"); | |
9556 | if (RIDBIT_SETP (RID_AUTO, specbits)) | |
9557 | error ("parameter of signature member function declared `auto'"); | |
9558 | if (RIDBIT_SETP (RID_REGISTER, specbits)) | |
9559 | error ("parameter of signature member function declared `register'"); | |
9560 | } | |
9561 | ||
9562 | /* Compute the type actually passed in the parmlist, | |
9563 | for the case where there is no prototype. | |
9564 | (For example, shorts and chars are passed as ints.) | |
9565 | When there is a prototype, this is overridden later. */ | |
9566 | ||
39211cd5 | 9567 | DECL_ARG_TYPE (decl) = type_promotes_to (type); |
8d08fdba MS |
9568 | } |
9569 | else if (decl_context == FIELD) | |
9570 | { | |
9571 | if (type == error_mark_node) | |
9572 | { | |
9573 | /* Happens when declaring arrays of sizes which | |
9574 | are error_mark_node, for example. */ | |
9575 | decl = NULL_TREE; | |
9576 | } | |
9577 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
9578 | { | |
9579 | int publicp = 0; | |
e1467ff2 | 9580 | tree function_context; |
8d08fdba | 9581 | |
72b7eeff MS |
9582 | /* We catch the others as conflicts with the builtin |
9583 | typedefs. */ | |
9584 | if (friendp && declarator == ridpointers[(int) RID_SIGNED]) | |
9585 | { | |
9586 | cp_error ("function `%D' cannot be declared friend", | |
9587 | declarator); | |
9588 | friendp = 0; | |
9589 | } | |
9590 | ||
8d08fdba MS |
9591 | if (friendp == 0) |
9592 | { | |
9593 | if (ctype == NULL_TREE) | |
9594 | ctype = current_class_type; | |
9595 | ||
9596 | if (ctype == NULL_TREE) | |
9597 | { | |
9598 | cp_error ("can't make `%D' into a method -- not in a class", | |
9599 | declarator); | |
9600 | return void_type_node; | |
9601 | } | |
9602 | ||
9603 | /* ``A union may [ ... ] not [ have ] virtual functions.'' | |
9604 | ARM 9.5 */ | |
9605 | if (virtualp && TREE_CODE (ctype) == UNION_TYPE) | |
9606 | { | |
9607 | cp_error ("function `%D' declared virtual inside a union", | |
9608 | declarator); | |
9609 | return void_type_node; | |
9610 | } | |
9611 | ||
9612 | if (declarator == ansi_opname[(int) NEW_EXPR] | |
a28e3c7f MS |
9613 | || declarator == ansi_opname[(int) VEC_NEW_EXPR] |
9614 | || declarator == ansi_opname[(int) DELETE_EXPR] | |
9615 | || declarator == ansi_opname[(int) VEC_DELETE_EXPR]) | |
8d08fdba MS |
9616 | { |
9617 | if (virtualp) | |
9618 | { | |
9619 | cp_error ("`%D' cannot be declared virtual, since it is always static", | |
9620 | declarator); | |
9621 | virtualp = 0; | |
9622 | } | |
9623 | } | |
9624 | else if (staticp < 2) | |
9625 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
9626 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9627 | } | |
9628 | ||
9629 | /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ | |
e1467ff2 MM |
9630 | function_context = (ctype != NULL_TREE) ? |
9631 | hack_decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE; | |
9632 | publicp = (! friendp || ! staticp) | |
9633 | && function_context == NULL_TREE; | |
386b8a85 JM |
9634 | decl = grokfndecl (ctype, type, |
9635 | TREE_CODE (declarator) != TEMPLATE_ID_EXPR | |
9636 | ? declarator : dname, | |
9637 | declarator, | |
f30432d7 | 9638 | virtualp, flags, quals, raises, attrlist, |
386b8a85 JM |
9639 | friendp ? -1 : 0, friendp, publicp, inlinep, |
9640 | funcdef_flag, template_count); | |
f0e01782 MS |
9641 | if (decl == NULL_TREE) |
9642 | return NULL_TREE; | |
6125f3be DE |
9643 | #if 0 |
9644 | /* This clobbers the attrs stored in `decl' from `attrlist'. */ | |
9645 | /* The decl and setting of decl_machine_attr is also turned off. */ | |
71851aaa | 9646 | decl = build_decl_attribute_variant (decl, decl_machine_attr); |
6125f3be | 9647 | #endif |
f0e01782 | 9648 | |
db5ae43f MS |
9649 | if (explicitp == 2) |
9650 | DECL_NONCONVERTING_P (decl) = 1; | |
8d08fdba MS |
9651 | } |
9652 | else if (TREE_CODE (type) == METHOD_TYPE) | |
9653 | { | |
faae18ab MS |
9654 | /* We only get here for friend declarations of |
9655 | members of other classes. */ | |
8d08fdba MS |
9656 | /* All method decls are public, so tell grokfndecl to set |
9657 | TREE_PUBLIC, also. */ | |
386b8a85 | 9658 | decl = grokfndecl (ctype, type, declarator, declarator, |
f30432d7 | 9659 | virtualp, flags, quals, raises, attrlist, |
386b8a85 JM |
9660 | friendp ? -1 : 0, friendp, 1, 0, funcdef_flag, |
9661 | template_count); | |
f0e01782 MS |
9662 | if (decl == NULL_TREE) |
9663 | return NULL_TREE; | |
8d08fdba | 9664 | } |
5566b478 MS |
9665 | else if (!staticp && ! processing_template_decl |
9666 | && TYPE_SIZE (complete_type (type)) == NULL_TREE | |
8d08fdba MS |
9667 | && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) |
9668 | { | |
b7484fbe MS |
9669 | if (declarator) |
9670 | cp_error ("field `%D' has incomplete type", declarator); | |
9671 | else | |
9672 | cp_error ("name `%T' has incomplete type", type); | |
8d08fdba MS |
9673 | |
9674 | /* If we're instantiating a template, tell them which | |
9675 | instantiation made the field's type be incomplete. */ | |
9676 | if (current_class_type | |
9677 | && TYPE_NAME (current_class_type) | |
d2e5ee5c | 9678 | && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type)) |
8d08fdba MS |
9679 | && declspecs && TREE_VALUE (declspecs) |
9680 | && TREE_TYPE (TREE_VALUE (declspecs)) == type) | |
db5ae43f MS |
9681 | cp_error (" in instantiation of template `%T'", |
9682 | current_class_type); | |
9683 | ||
8d08fdba MS |
9684 | type = error_mark_node; |
9685 | decl = NULL_TREE; | |
9686 | } | |
9687 | else | |
9688 | { | |
9689 | if (friendp) | |
9690 | { | |
9691 | error ("`%s' is neither function nor method; cannot be declared friend", | |
9692 | IDENTIFIER_POINTER (declarator)); | |
9693 | friendp = 0; | |
9694 | } | |
9695 | decl = NULL_TREE; | |
9696 | } | |
9697 | ||
9698 | if (friendp) | |
9699 | { | |
9700 | /* Friends are treated specially. */ | |
9701 | if (ctype == current_class_type) | |
9702 | warning ("member functions are implicitly friends of their class"); | |
9703 | else | |
9704 | { | |
9705 | tree t = NULL_TREE; | |
9706 | if (decl && DECL_NAME (decl)) | |
9707 | t = do_friend (ctype, declarator, decl, | |
5566b478 MS |
9708 | last_function_parms, flags, quals, |
9709 | funcdef_flag); | |
8d08fdba MS |
9710 | if (t && funcdef_flag) |
9711 | return t; | |
9712 | ||
9713 | return void_type_node; | |
9714 | } | |
9715 | } | |
9716 | ||
9717 | /* Structure field. It may not be a function, except for C++ */ | |
9718 | ||
9719 | if (decl == NULL_TREE) | |
9720 | { | |
8d08fdba MS |
9721 | if (initialized) |
9722 | { | |
3ac3d9ea MM |
9723 | if (!staticp) |
9724 | { | |
9725 | /* An attempt is being made to initialize a non-static | |
9726 | member. But, from [class.mem]: | |
9727 | ||
9728 | 4 A member-declarator can contain a | |
9729 | constant-initializer only if it declares a static | |
9730 | member (_class.static_) of integral or enumeration | |
9731 | type, see _class.static.data_. | |
9732 | ||
9733 | This used to be relatively common practice, but | |
9734 | the rest of the compiler does not correctly | |
9735 | handle the initialization unless the member is | |
9736 | static so we make it static below. */ | |
9737 | cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'", | |
9738 | constp ? "const member" : "member", | |
9739 | declarator); | |
9740 | cp_pedwarn ("making `%D' static", declarator); | |
9741 | staticp = 1; | |
9742 | } | |
9743 | ||
a0a33927 MS |
9744 | /* Motion 10 at San Diego: If a static const integral data |
9745 | member is initialized with an integral constant | |
9746 | expression, the initializer may appear either in the | |
9747 | declaration (within the class), or in the definition, | |
9748 | but not both. If it appears in the class, the member is | |
9749 | a member constant. The file-scope definition is always | |
9750 | required. */ | |
3ac3d9ea MM |
9751 | if (! constp) |
9752 | /* According to Mike Stump, we generate bad code for | |
9753 | this case, so we might as well always make it an | |
9754 | error. */ | |
9755 | cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'", | |
9756 | declarator); | |
9757 | ||
9758 | if (pedantic && ! INTEGRAL_TYPE_P (type)) | |
9759 | cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", declarator, type); | |
8d08fdba MS |
9760 | } |
9761 | ||
3ac3d9ea | 9762 | if (staticp) |
8d08fdba | 9763 | { |
f30432d7 | 9764 | /* ANSI C++ Apr '95 wp 9.2 */ |
3ac3d9ea | 9765 | if (declarator == current_class_name) |
f30432d7 MS |
9766 | cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class", |
9767 | declarator); | |
9768 | ||
8d08fdba MS |
9769 | /* C++ allows static class members. |
9770 | All other work for this is done by grokfield. | |
9771 | This VAR_DECL is built by build_lang_field_decl. | |
9772 | All other VAR_DECLs are built by build_decl. */ | |
9773 | decl = build_lang_field_decl (VAR_DECL, declarator, type); | |
5b605f68 MS |
9774 | TREE_STATIC (decl) = 1; |
9775 | /* In class context, 'static' means public access. */ | |
3ac3d9ea | 9776 | TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = 1; |
8d08fdba MS |
9777 | } |
9778 | else | |
9779 | { | |
9780 | decl = build_lang_field_decl (FIELD_DECL, declarator, type); | |
9781 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
9782 | { | |
9783 | DECL_MUTABLE_P (decl) = 1; | |
9784 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
9785 | } | |
9786 | } | |
9787 | ||
9788 | bad_specifiers (decl, "field", virtualp, quals != NULL_TREE, | |
9789 | inlinep, friendp, raises != NULL_TREE); | |
9790 | } | |
9791 | } | |
9792 | else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | |
9793 | { | |
386b8a85 | 9794 | tree original_name; |
8d08fdba MS |
9795 | int publicp = 0; |
9796 | ||
9797 | if (! declarator) | |
9798 | return NULL_TREE; | |
9799 | ||
386b8a85 JM |
9800 | if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) |
9801 | original_name = dname; | |
9802 | else | |
9803 | original_name = declarator; | |
9804 | ||
8926095f MS |
9805 | if (RIDBIT_SETP (RID_AUTO, specbits)) |
9806 | error ("storage class `auto' invalid for function `%s'", name); | |
9807 | else if (RIDBIT_SETP (RID_REGISTER, specbits)) | |
9808 | error ("storage class `register' invalid for function `%s'", name); | |
8d08fdba MS |
9809 | |
9810 | /* Function declaration not at top level. | |
9811 | Storage classes other than `extern' are not allowed | |
9812 | and `extern' makes no difference. */ | |
a9aedbc2 | 9813 | if (! toplevel_bindings_p () |
8926095f MS |
9814 | && (RIDBIT_SETP (RID_STATIC, specbits) |
9815 | || RIDBIT_SETP (RID_INLINE, specbits)) | |
8d08fdba | 9816 | && pedantic) |
8926095f MS |
9817 | { |
9818 | if (RIDBIT_SETP (RID_STATIC, specbits)) | |
9819 | pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name); | |
9820 | else | |
9821 | pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name); | |
9822 | } | |
9823 | ||
8d08fdba MS |
9824 | if (ctype == NULL_TREE) |
9825 | { | |
9826 | if (virtualp) | |
9827 | { | |
9828 | error ("virtual non-class function `%s'", name); | |
9829 | virtualp = 0; | |
9830 | } | |
9831 | ||
9832 | if (current_lang_name == lang_name_cplusplus | |
5156628f | 9833 | && ! processing_template_decl |
8d08fdba MS |
9834 | && ! (IDENTIFIER_LENGTH (original_name) == 4 |
9835 | && IDENTIFIER_POINTER (original_name)[0] == 'm' | |
9836 | && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0) | |
9837 | && ! (IDENTIFIER_LENGTH (original_name) > 10 | |
9838 | && IDENTIFIER_POINTER (original_name)[0] == '_' | |
9839 | && IDENTIFIER_POINTER (original_name)[1] == '_' | |
9840 | && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0)) | |
8926095f | 9841 | /* Plain overloading: will not be grok'd by grokclassfn. */ |
386b8a85 JM |
9842 | if (name_mangling_version < 1 |
9843 | || TREE_CODE (declarator) != TEMPLATE_ID_EXPR) | |
9844 | declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0); | |
8d08fdba MS |
9845 | } |
9846 | else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2) | |
9847 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
9848 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9849 | ||
eb66be0e | 9850 | /* Record presence of `static'. */ |
faae18ab | 9851 | publicp = (ctype != NULL_TREE |
a9aedbc2 | 9852 | || RIDBIT_SETP (RID_EXTERN, specbits) |
eb66be0e | 9853 | || !RIDBIT_SETP (RID_STATIC, specbits)); |
8d08fdba | 9854 | |
386b8a85 | 9855 | decl = grokfndecl (ctype, type, original_name, declarator, |
f30432d7 | 9856 | virtualp, flags, quals, raises, attrlist, |
75650646 | 9857 | 1, friendp, |
386b8a85 JM |
9858 | publicp, inlinep, funcdef_flag, |
9859 | template_count); | |
f0e01782 MS |
9860 | if (decl == NULL_TREE) |
9861 | return NULL_TREE; | |
8d08fdba | 9862 | |
386b8a85 | 9863 | if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c |
71cc65bd | 9864 | && (! DECL_USE_TEMPLATE (decl) || |
386b8a85 | 9865 | name_mangling_version < 1)) |
30394414 JM |
9866 | #if 0 |
9867 | /* XXX is support for the old __ns_ mangling really needed? MvL */ | |
6060a796 | 9868 | DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator); |
30394414 JM |
9869 | #else |
9870 | DECL_ASSEMBLER_NAME (decl) = declarator; | |
9871 | #endif | |
386b8a85 | 9872 | |
8d08fdba MS |
9873 | if (staticp == 1) |
9874 | { | |
9875 | int illegal_static = 0; | |
9876 | ||
9877 | /* Don't allow a static member function in a class, and forbid | |
9878 | declaring main to be static. */ | |
9879 | if (TREE_CODE (type) == METHOD_TYPE) | |
9880 | { | |
00595019 | 9881 | cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl); |
8d08fdba MS |
9882 | illegal_static = 1; |
9883 | } | |
8d08fdba MS |
9884 | else if (current_function_decl) |
9885 | { | |
9886 | /* FIXME need arm citation */ | |
9887 | error ("cannot declare static function inside another function"); | |
9888 | illegal_static = 1; | |
9889 | } | |
9890 | ||
9891 | if (illegal_static) | |
9892 | { | |
9893 | staticp = 0; | |
9894 | RIDBIT_RESET (RID_STATIC, specbits); | |
9895 | } | |
9896 | } | |
8d08fdba MS |
9897 | } |
9898 | else | |
9899 | { | |
9900 | /* It's a variable. */ | |
9901 | ||
db5ae43f MS |
9902 | if (decl_context == CATCHPARM) |
9903 | { | |
9904 | if (ctype) | |
9905 | { | |
9906 | ctype = NULL_TREE; | |
9907 | error ("cannot use `::' in parameter declaration"); | |
9908 | } | |
9909 | ||
9910 | /* A parameter declared as an array of T is really a pointer to T. | |
9911 | One declared as a function is really a pointer to a function. | |
9912 | One declared as a member is really a pointer to member. */ | |
9913 | ||
9914 | if (TREE_CODE (type) == ARRAY_TYPE) | |
9915 | { | |
e92cc029 MS |
9916 | /* Transfer const-ness of array into that of type |
9917 | pointed to. */ | |
db5ae43f MS |
9918 | type = build_pointer_type |
9919 | (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); | |
9920 | volatilep = constp = 0; | |
9921 | } | |
9922 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
9923 | type = build_pointer_type (type); | |
9924 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
9925 | type = build_pointer_type (type); | |
9926 | } | |
9927 | ||
8d08fdba | 9928 | /* An uninitialized decl with `extern' is a reference. */ |
d2e5ee5c | 9929 | decl = grokvardecl (type, declarator, &specbits, initialized, constp); |
8d08fdba MS |
9930 | bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, |
9931 | inlinep, friendp, raises != NULL_TREE); | |
9932 | ||
9933 | if (ctype) | |
9934 | { | |
f0e01782 | 9935 | DECL_CONTEXT (decl) = ctype; |
8d08fdba MS |
9936 | if (staticp == 1) |
9937 | { | |
f30432d7 | 9938 | cp_pedwarn ("static member `%D' re-declared as static", decl); |
8d08fdba MS |
9939 | staticp = 0; |
9940 | RIDBIT_RESET (RID_STATIC, specbits); | |
9941 | } | |
b7484fbe MS |
9942 | if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl)) |
9943 | { | |
9944 | cp_error ("static member `%D' declared `register'", decl); | |
9945 | RIDBIT_RESET (RID_REGISTER, specbits); | |
9946 | } | |
f30432d7 | 9947 | if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic) |
8d08fdba | 9948 | { |
f30432d7 MS |
9949 | cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage", |
9950 | decl); | |
8d08fdba MS |
9951 | RIDBIT_RESET (RID_EXTERN, specbits); |
9952 | } | |
9953 | } | |
9954 | } | |
9955 | ||
9956 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
9957 | { | |
9958 | error ("`%s' cannot be declared mutable", name); | |
9959 | } | |
9960 | ||
9961 | /* Record `register' declaration for warnings on & | |
9962 | and in case doing stupid register allocation. */ | |
9963 | ||
9964 | if (RIDBIT_SETP (RID_REGISTER, specbits)) | |
9965 | DECL_REGISTER (decl) = 1; | |
9966 | ||
8926095f MS |
9967 | if (RIDBIT_SETP (RID_EXTERN, specbits)) |
9968 | DECL_THIS_EXTERN (decl) = 1; | |
9969 | ||
faae18ab MS |
9970 | if (RIDBIT_SETP (RID_STATIC, specbits)) |
9971 | DECL_THIS_STATIC (decl) = 1; | |
9972 | ||
8d08fdba MS |
9973 | /* Record constancy and volatility. */ |
9974 | ||
9975 | if (constp) | |
9976 | TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE; | |
9977 | if (volatilep) | |
9978 | { | |
9979 | TREE_SIDE_EFFECTS (decl) = 1; | |
9980 | TREE_THIS_VOLATILE (decl) = 1; | |
9981 | } | |
9982 | ||
9983 | return decl; | |
9984 | } | |
9985 | } | |
9986 | \f | |
9987 | /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist. | |
9988 | An empty exprlist is a parmlist. An exprlist which | |
9989 | contains only identifiers at the global level | |
9990 | is a parmlist. Otherwise, it is an exprlist. */ | |
e92cc029 | 9991 | |
8d08fdba MS |
9992 | int |
9993 | parmlist_is_exprlist (exprs) | |
9994 | tree exprs; | |
9995 | { | |
9996 | if (exprs == NULL_TREE || TREE_PARMLIST (exprs)) | |
9997 | return 0; | |
9998 | ||
a9aedbc2 | 9999 | if (toplevel_bindings_p ()) |
8d08fdba MS |
10000 | { |
10001 | /* At the global level, if these are all identifiers, | |
10002 | then it is a parmlist. */ | |
10003 | while (exprs) | |
10004 | { | |
10005 | if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE) | |
10006 | return 1; | |
10007 | exprs = TREE_CHAIN (exprs); | |
10008 | } | |
10009 | return 0; | |
10010 | } | |
10011 | return 1; | |
10012 | } | |
10013 | ||
10014 | /* Subroutine of `grokparms'. In a fcn definition, arg types must | |
10015 | be complete. | |
10016 | ||
10017 | C++: also subroutine of `start_function'. */ | |
e92cc029 | 10018 | |
8d08fdba MS |
10019 | static void |
10020 | require_complete_types_for_parms (parms) | |
10021 | tree parms; | |
10022 | { | |
5566b478 MS |
10023 | if (processing_template_decl) |
10024 | return; | |
10025 | ||
8d08fdba MS |
10026 | while (parms) |
10027 | { | |
10028 | tree type = TREE_TYPE (parms); | |
5566b478 | 10029 | if (TYPE_SIZE (complete_type (type)) == NULL_TREE) |
8d08fdba MS |
10030 | { |
10031 | if (DECL_NAME (parms)) | |
10032 | error ("parameter `%s' has incomplete type", | |
10033 | IDENTIFIER_POINTER (DECL_NAME (parms))); | |
10034 | else | |
10035 | error ("parameter has incomplete type"); | |
10036 | TREE_TYPE (parms) = error_mark_node; | |
10037 | } | |
10038 | #if 0 | |
10039 | /* If the arg types are incomplete in a declaration, | |
10040 | they must include undefined tags. | |
10041 | These tags can never be defined in the scope of the declaration, | |
10042 | so the types can never be completed, | |
10043 | and no call can be compiled successfully. */ | |
10044 | /* This is not the right behavior for C++, but not having | |
10045 | it is also probably wrong. */ | |
10046 | else | |
10047 | { | |
10048 | /* Now warn if is a pointer to an incomplete type. */ | |
10049 | while (TREE_CODE (type) == POINTER_TYPE | |
10050 | || TREE_CODE (type) == REFERENCE_TYPE) | |
10051 | type = TREE_TYPE (type); | |
10052 | type = TYPE_MAIN_VARIANT (type); | |
10053 | if (TYPE_SIZE (type) == NULL_TREE) | |
10054 | { | |
10055 | if (DECL_NAME (parm) != NULL_TREE) | |
10056 | warning ("parameter `%s' points to incomplete type", | |
10057 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
10058 | else | |
10059 | warning ("parameter points to incomplete type"); | |
10060 | } | |
10061 | } | |
10062 | #endif | |
10063 | parms = TREE_CHAIN (parms); | |
10064 | } | |
10065 | } | |
10066 | ||
10067 | /* Decode the list of parameter types for a function type. | |
10068 | Given the list of things declared inside the parens, | |
10069 | return a list of types. | |
10070 | ||
10071 | The list we receive can have three kinds of elements: | |
10072 | an IDENTIFIER_NODE for names given without types, | |
10073 | a TREE_LIST node for arguments given as typespecs or names with typespecs, | |
10074 | or void_type_node, to mark the end of an argument list | |
10075 | when additional arguments are not permitted (... was not used). | |
10076 | ||
10077 | FUNCDEF_FLAG is nonzero for a function definition, 0 for | |
10078 | a mere declaration. A nonempty identifier-list gets an error message | |
10079 | when FUNCDEF_FLAG is zero. | |
10080 | If FUNCDEF_FLAG is 1, then parameter types must be complete. | |
10081 | If FUNCDEF_FLAG is -1, then parameter types may be incomplete. | |
10082 | ||
10083 | If all elements of the input list contain types, | |
10084 | we return a list of the types. | |
10085 | If all elements contain no type (except perhaps a void_type_node | |
10086 | at the end), we return a null list. | |
10087 | If some have types and some do not, it is an error, and we | |
10088 | return a null list. | |
10089 | ||
10090 | Also set last_function_parms to either | |
10091 | a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs. | |
10092 | A list of names is converted to a chain of PARM_DECLs | |
10093 | by store_parm_decls so that ultimately it is always a chain of decls. | |
10094 | ||
10095 | Note that in C++, parameters can take default values. These default | |
10096 | values are in the TREE_PURPOSE field of the TREE_LIST. It is | |
10097 | an error to specify default values which are followed by parameters | |
10098 | that have no default values, or an ELLIPSES. For simplicities sake, | |
10099 | only parameters which are specified with their types can take on | |
10100 | default values. */ | |
10101 | ||
10102 | static tree | |
10103 | grokparms (first_parm, funcdef_flag) | |
10104 | tree first_parm; | |
10105 | int funcdef_flag; | |
10106 | { | |
10107 | tree result = NULL_TREE; | |
10108 | tree decls = NULL_TREE; | |
10109 | ||
10110 | if (first_parm != NULL_TREE | |
10111 | && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) | |
10112 | { | |
10113 | if (! funcdef_flag) | |
10114 | pedwarn ("parameter names (without types) in function declaration"); | |
10115 | last_function_parms = first_parm; | |
10116 | return NULL_TREE; | |
10117 | } | |
10118 | else if (first_parm != NULL_TREE | |
10119 | && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST | |
10120 | && TREE_VALUE (first_parm) != void_type_node) | |
10121 | my_friendly_abort (145); | |
10122 | else | |
10123 | { | |
10124 | /* Types were specified. This is a list of declarators | |
10125 | each represented as a TREE_LIST node. */ | |
10126 | register tree parm, chain; | |
5566b478 | 10127 | int any_init = 0, any_error = 0; |
8d08fdba MS |
10128 | |
10129 | if (first_parm != NULL_TREE) | |
10130 | { | |
10131 | tree last_result = NULL_TREE; | |
10132 | tree last_decl = NULL_TREE; | |
10133 | ||
10134 | for (parm = first_parm; parm != NULL_TREE; parm = chain) | |
10135 | { | |
a703fb38 | 10136 | tree type = NULL_TREE, list_node = parm; |
8d08fdba MS |
10137 | register tree decl = TREE_VALUE (parm); |
10138 | tree init = TREE_PURPOSE (parm); | |
10139 | ||
10140 | chain = TREE_CHAIN (parm); | |
10141 | /* @@ weak defense against parse errors. */ | |
10142 | if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST) | |
10143 | { | |
10144 | /* Give various messages as the need arises. */ | |
10145 | if (TREE_CODE (decl) == STRING_CST) | |
fc378698 | 10146 | cp_error ("invalid string constant `%E'", decl); |
8d08fdba MS |
10147 | else if (TREE_CODE (decl) == INTEGER_CST) |
10148 | error ("invalid integer constant in parameter list, did you forget to give parameter name?"); | |
10149 | continue; | |
10150 | } | |
10151 | ||
10152 | if (decl != void_type_node) | |
10153 | { | |
8d08fdba MS |
10154 | decl = grokdeclarator (TREE_VALUE (decl), |
10155 | TREE_PURPOSE (decl), | |
f30432d7 | 10156 | PARM, init != NULL_TREE, |
c11b6f21 | 10157 | NULL_TREE); |
8d08fdba MS |
10158 | if (! decl) |
10159 | continue; | |
10160 | type = TREE_TYPE (decl); | |
10161 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
10162 | decl = void_type_node; | |
10163 | else if (TREE_CODE (type) == METHOD_TYPE) | |
10164 | { | |
10165 | if (DECL_NAME (decl)) | |
fc378698 | 10166 | /* Cannot use the decl here because |
8d08fdba | 10167 | we don't have DECL_CONTEXT set up yet. */ |
fc378698 MS |
10168 | cp_error ("parameter `%D' invalidly declared method type", |
10169 | DECL_NAME (decl)); | |
8d08fdba MS |
10170 | else |
10171 | error ("parameter invalidly declared method type"); | |
10172 | type = build_pointer_type (type); | |
10173 | TREE_TYPE (decl) = type; | |
10174 | } | |
10175 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
10176 | { | |
10177 | if (DECL_NAME (decl)) | |
fc378698 MS |
10178 | cp_error ("parameter `%D' invalidly declared offset type", |
10179 | DECL_NAME (decl)); | |
8d08fdba MS |
10180 | else |
10181 | error ("parameter invalidly declared offset type"); | |
10182 | type = build_pointer_type (type); | |
10183 | TREE_TYPE (decl) = type; | |
10184 | } | |
10185 | else if (TREE_CODE (type) == RECORD_TYPE | |
10186 | && TYPE_LANG_SPECIFIC (type) | |
10187 | && CLASSTYPE_ABSTRACT_VIRTUALS (type)) | |
10188 | { | |
10189 | abstract_virtuals_error (decl, type); | |
10190 | any_error = 1; /* seems like a good idea */ | |
10191 | } | |
10192 | else if (TREE_CODE (type) == RECORD_TYPE | |
10193 | && TYPE_LANG_SPECIFIC (type) | |
10194 | && IS_SIGNATURE (type)) | |
10195 | { | |
10196 | signature_error (decl, type); | |
10197 | any_error = 1; /* seems like a good idea */ | |
10198 | } | |
10199 | } | |
10200 | ||
10201 | if (decl == void_type_node) | |
10202 | { | |
10203 | if (result == NULL_TREE) | |
10204 | { | |
10205 | result = void_list_node; | |
10206 | last_result = result; | |
10207 | } | |
10208 | else | |
10209 | { | |
10210 | TREE_CHAIN (last_result) = void_list_node; | |
10211 | last_result = void_list_node; | |
10212 | } | |
8d08fdba MS |
10213 | if (chain |
10214 | && (chain != void_list_node || TREE_CHAIN (chain))) | |
10215 | error ("`void' in parameter list must be entire list"); | |
10216 | break; | |
10217 | } | |
10218 | ||
10219 | /* Since there is a prototype, args are passed in their own types. */ | |
10220 | DECL_ARG_TYPE (decl) = TREE_TYPE (decl); | |
10221 | #ifdef PROMOTE_PROTOTYPES | |
10222 | if ((TREE_CODE (type) == INTEGER_TYPE | |
10223 | || TREE_CODE (type) == ENUMERAL_TYPE) | |
10224 | && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) | |
10225 | DECL_ARG_TYPE (decl) = integer_type_node; | |
10226 | #endif | |
10227 | if (!any_error) | |
10228 | { | |
10229 | if (init) | |
10230 | { | |
10231 | any_init++; | |
10232 | if (TREE_CODE (init) == SAVE_EXPR) | |
10233 | PARM_DECL_EXPR (init) = 1; | |
5156628f | 10234 | else if (processing_template_decl) |
5566b478 | 10235 | ; |
42976354 BK |
10236 | /* Unparsed default arg from in-class decl. */ |
10237 | else if (TREE_CODE (init) == DEFAULT_ARG) | |
10238 | ; | |
b7484fbe MS |
10239 | else if (TREE_CODE (init) == VAR_DECL |
10240 | || TREE_CODE (init) == PARM_DECL) | |
8d08fdba MS |
10241 | { |
10242 | if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init))) | |
10243 | { | |
10244 | /* ``Local variables may not be used in default | |
10245 | argument expressions.'' dpANSI C++ 8.2.6 */ | |
10246 | /* If extern int i; within a function is not | |
10247 | considered a local variable, then this code is | |
e92cc029 | 10248 | wrong. */ |
8d08fdba MS |
10249 | cp_error ("local variable `%D' may not be used as a default argument", init); |
10250 | any_error = 1; | |
10251 | } | |
10252 | else if (TREE_READONLY_DECL_P (init)) | |
10253 | init = decl_constant_value (init); | |
10254 | } | |
10255 | else | |
10256 | init = require_instantiated_type (type, init, integer_zero_node); | |
5156628f | 10257 | if (! processing_template_decl |
42976354 | 10258 | && TREE_CODE (init) != DEFAULT_ARG |
c11b6f21 | 10259 | && ! can_convert_arg (type, TREE_TYPE (init), init)) |
c73964b2 MS |
10260 | cp_pedwarn ("invalid type `%T' for default argument to `%#D'", |
10261 | TREE_TYPE (init), decl); | |
8d08fdba MS |
10262 | } |
10263 | } | |
10264 | else | |
10265 | init = NULL_TREE; | |
10266 | ||
10267 | if (decls == NULL_TREE) | |
10268 | { | |
10269 | decls = decl; | |
10270 | last_decl = decls; | |
10271 | } | |
10272 | else | |
10273 | { | |
10274 | TREE_CHAIN (last_decl) = decl; | |
10275 | last_decl = decl; | |
10276 | } | |
66f2e88d | 10277 | if (! current_function_decl && TREE_PERMANENT (list_node)) |
8d08fdba MS |
10278 | { |
10279 | TREE_PURPOSE (list_node) = init; | |
10280 | TREE_VALUE (list_node) = type; | |
10281 | TREE_CHAIN (list_node) = NULL_TREE; | |
10282 | } | |
10283 | else | |
10284 | list_node = saveable_tree_cons (init, type, NULL_TREE); | |
10285 | if (result == NULL_TREE) | |
10286 | { | |
10287 | result = list_node; | |
10288 | last_result = result; | |
10289 | } | |
10290 | else | |
10291 | { | |
10292 | TREE_CHAIN (last_result) = list_node; | |
10293 | last_result = list_node; | |
10294 | } | |
10295 | } | |
10296 | if (last_result) | |
10297 | TREE_CHAIN (last_result) = NULL_TREE; | |
10298 | /* If there are no parameters, and the function does not end | |
10299 | with `...', then last_decl will be NULL_TREE. */ | |
10300 | if (last_decl != NULL_TREE) | |
10301 | TREE_CHAIN (last_decl) = NULL_TREE; | |
10302 | } | |
10303 | } | |
10304 | ||
10305 | last_function_parms = decls; | |
10306 | ||
10307 | /* In a fcn definition, arg types must be complete. */ | |
10308 | if (funcdef_flag > 0) | |
10309 | require_complete_types_for_parms (last_function_parms); | |
10310 | ||
10311 | return result; | |
10312 | } | |
42976354 BK |
10313 | |
10314 | /* Called from the parser to update an element of TYPE_ARG_TYPES for some | |
10315 | FUNCTION_TYPE with the newly parsed version of its default argument, which | |
10316 | was previously digested as text. See snarf_defarg et al in lex.c. */ | |
10317 | ||
10318 | void | |
10319 | replace_defarg (arg, init) | |
10320 | tree arg, init; | |
10321 | { | |
aa5f3bad | 10322 | if (! processing_template_decl |
42976354 BK |
10323 | && ! can_convert_arg (TREE_VALUE (arg), TREE_TYPE (init), init)) |
10324 | cp_pedwarn ("invalid type `%T' for default argument to `%T'", | |
10325 | TREE_TYPE (init), TREE_VALUE (arg)); | |
10326 | TREE_PURPOSE (arg) = init; | |
10327 | } | |
8d08fdba | 10328 | \f |
c11b6f21 MS |
10329 | int |
10330 | copy_args_p (d) | |
10331 | tree d; | |
10332 | { | |
10333 | tree t = FUNCTION_ARG_CHAIN (d); | |
67437d5b JM |
10334 | if (DECL_CONSTRUCTOR_P (d) |
10335 | && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (d))) | |
10336 | t = TREE_CHAIN (t); | |
c11b6f21 MS |
10337 | if (t && TREE_CODE (TREE_VALUE (t)) == REFERENCE_TYPE |
10338 | && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (t))) | |
10339 | == DECL_CLASS_CONTEXT (d)) | |
10340 | && (TREE_CHAIN (t) == NULL_TREE | |
10341 | || TREE_CHAIN (t) == void_list_node | |
10342 | || TREE_PURPOSE (TREE_CHAIN (t)))) | |
10343 | return 1; | |
10344 | return 0; | |
10345 | } | |
10346 | ||
8d08fdba MS |
10347 | /* These memoizing functions keep track of special properties which |
10348 | a class may have. `grok_ctor_properties' notices whether a class | |
10349 | has a constructor of the form X(X&), and also complains | |
10350 | if the class has a constructor of the form X(X). | |
10351 | `grok_op_properties' takes notice of the various forms of | |
10352 | operator= which are defined, as well as what sorts of type conversion | |
10353 | may apply. Both functions take a FUNCTION_DECL as an argument. */ | |
e92cc029 | 10354 | |
a0a33927 | 10355 | int |
8d08fdba MS |
10356 | grok_ctor_properties (ctype, decl) |
10357 | tree ctype, decl; | |
10358 | { | |
10359 | tree parmtypes = FUNCTION_ARG_CHAIN (decl); | |
10360 | tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; | |
10361 | ||
10362 | /* When a type has virtual baseclasses, a magical first int argument is | |
10363 | added to any ctor so we can tell if the class has been initialized | |
10364 | yet. This could screw things up in this function, so we deliberately | |
10365 | ignore the leading int if we're in that situation. */ | |
10366 | if (parmtypes | |
10367 | && TREE_VALUE (parmtypes) == integer_type_node | |
10368 | && TYPE_USES_VIRTUAL_BASECLASSES (ctype)) | |
10369 | { | |
10370 | parmtypes = TREE_CHAIN (parmtypes); | |
10371 | parmtype = TREE_VALUE (parmtypes); | |
10372 | } | |
10373 | ||
10374 | if (TREE_CODE (parmtype) == REFERENCE_TYPE | |
0b41abe6 JM |
10375 | && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype |
10376 | && (TREE_CHAIN (parmtypes) == NULL_TREE | |
8d08fdba | 10377 | || TREE_CHAIN (parmtypes) == void_list_node |
0b41abe6 JM |
10378 | || TREE_PURPOSE (TREE_CHAIN (parmtypes)))) |
10379 | { | |
10380 | TYPE_HAS_INIT_REF (ctype) = 1; | |
10381 | if (TYPE_READONLY (TREE_TYPE (parmtype))) | |
10382 | TYPE_HAS_CONST_INIT_REF (ctype) = 1; | |
8d08fdba | 10383 | } |
0b41abe6 JM |
10384 | else if (TYPE_MAIN_VARIANT (parmtype) == ctype |
10385 | && TREE_CHAIN (parmtypes) != NULL_TREE | |
10386 | && TREE_CHAIN (parmtypes) == void_list_node) | |
8d08fdba | 10387 | { |
0b41abe6 JM |
10388 | cp_error ("invalid constructor; you probably meant `%T (const %T&)'", |
10389 | ctype, ctype); | |
10390 | SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); | |
10391 | return 0; | |
8d08fdba MS |
10392 | } |
10393 | else if (TREE_CODE (parmtype) == VOID_TYPE | |
10394 | || TREE_PURPOSE (parmtypes) != NULL_TREE) | |
10395 | TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; | |
a0a33927 MS |
10396 | |
10397 | return 1; | |
8d08fdba MS |
10398 | } |
10399 | ||
10400 | /* An operator with this name can be either unary or binary. */ | |
e92cc029 | 10401 | |
a28e3c7f MS |
10402 | static int |
10403 | ambi_op_p (name) | |
8d08fdba MS |
10404 | tree name; |
10405 | { | |
10406 | return (name == ansi_opname [(int) INDIRECT_REF] | |
10407 | || name == ansi_opname [(int) ADDR_EXPR] | |
10408 | || name == ansi_opname [(int) NEGATE_EXPR] | |
10409 | || name == ansi_opname[(int) POSTINCREMENT_EXPR] | |
10410 | || name == ansi_opname[(int) POSTDECREMENT_EXPR] | |
10411 | || name == ansi_opname [(int) CONVERT_EXPR]); | |
10412 | } | |
10413 | ||
10414 | /* An operator with this name can only be unary. */ | |
e92cc029 | 10415 | |
a28e3c7f MS |
10416 | static int |
10417 | unary_op_p (name) | |
8d08fdba MS |
10418 | tree name; |
10419 | { | |
10420 | return (name == ansi_opname [(int) TRUTH_NOT_EXPR] | |
10421 | || name == ansi_opname [(int) BIT_NOT_EXPR] | |
10422 | || name == ansi_opname [(int) COMPONENT_REF] | |
10423 | || OPERATOR_TYPENAME_P (name)); | |
10424 | } | |
10425 | ||
10426 | /* Do a little sanity-checking on how they declared their operator. */ | |
e92cc029 | 10427 | |
5566b478 | 10428 | void |
8d08fdba MS |
10429 | grok_op_properties (decl, virtualp, friendp) |
10430 | tree decl; | |
10431 | int virtualp, friendp; | |
10432 | { | |
10433 | tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
10434 | int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); | |
10435 | tree name = DECL_NAME (decl); | |
8d08fdba | 10436 | |
a28e3c7f MS |
10437 | if (current_class_type == NULL_TREE) |
10438 | friendp = 1; | |
8d08fdba | 10439 | |
a28e3c7f MS |
10440 | if (! friendp) |
10441 | { | |
10442 | if (name == ansi_opname[(int) MODIFY_EXPR]) | |
10443 | TYPE_HAS_ASSIGNMENT (current_class_type) = 1; | |
10444 | else if (name == ansi_opname[(int) CALL_EXPR]) | |
10445 | TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1; | |
10446 | else if (name == ansi_opname[(int) ARRAY_REF]) | |
10447 | TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1; | |
10448 | else if (name == ansi_opname[(int) COMPONENT_REF] | |
10449 | || name == ansi_opname[(int) MEMBER_REF]) | |
10450 | TYPE_OVERLOADS_ARROW (current_class_type) = 1; | |
10451 | else if (name == ansi_opname[(int) NEW_EXPR]) | |
10452 | TYPE_GETS_NEW (current_class_type) |= 1; | |
10453 | else if (name == ansi_opname[(int) DELETE_EXPR]) | |
10454 | TYPE_GETS_DELETE (current_class_type) |= 1; | |
10455 | else if (name == ansi_opname[(int) VEC_NEW_EXPR]) | |
10456 | TYPE_GETS_NEW (current_class_type) |= 2; | |
10457 | else if (name == ansi_opname[(int) VEC_DELETE_EXPR]) | |
10458 | TYPE_GETS_DELETE (current_class_type) |= 2; | |
10459 | } | |
10460 | ||
10461 | if (name == ansi_opname[(int) NEW_EXPR] | |
10462 | || name == ansi_opname[(int) VEC_NEW_EXPR]) | |
8d08fdba | 10463 | { |
8d08fdba MS |
10464 | /* When the compiler encounters the definition of A::operator new, it |
10465 | doesn't look at the class declaration to find out if it's static. */ | |
a28e3c7f | 10466 | if (methodp) |
700f8a87 | 10467 | revert_static_member_fn (&decl, NULL, NULL); |
8d08fdba MS |
10468 | |
10469 | /* Take care of function decl if we had syntax errors. */ | |
10470 | if (argtypes == NULL_TREE) | |
beb53fb8 JM |
10471 | TREE_TYPE (decl) |
10472 | = build_function_type (ptr_type_node, | |
10473 | hash_tree_chain (integer_type_node, | |
10474 | void_list_node)); | |
8d08fdba | 10475 | else |
a28e3c7f | 10476 | TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); |
8d08fdba | 10477 | } |
a28e3c7f MS |
10478 | else if (name == ansi_opname[(int) DELETE_EXPR] |
10479 | || name == ansi_opname[(int) VEC_DELETE_EXPR]) | |
8d08fdba | 10480 | { |
a28e3c7f | 10481 | if (methodp) |
700f8a87 | 10482 | revert_static_member_fn (&decl, NULL, NULL); |
8d08fdba MS |
10483 | |
10484 | if (argtypes == NULL_TREE) | |
beb53fb8 JM |
10485 | TREE_TYPE (decl) |
10486 | = build_function_type (void_type_node, | |
10487 | hash_tree_chain (ptr_type_node, | |
10488 | void_list_node)); | |
8d08fdba | 10489 | else |
a28e3c7f MS |
10490 | { |
10491 | TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); | |
10492 | ||
10493 | if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR] | |
10494 | && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))) | |
10495 | != void_list_node)) | |
10496 | TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1; | |
10497 | } | |
8d08fdba | 10498 | } |
8d08fdba MS |
10499 | else |
10500 | { | |
10501 | /* An operator function must either be a non-static member function | |
10502 | or have at least one parameter of a class, a reference to a class, | |
10503 | an enumeration, or a reference to an enumeration. 13.4.0.6 */ | |
700f8a87 | 10504 | if (! methodp || DECL_STATIC_FUNCTION_P (decl)) |
8d08fdba MS |
10505 | { |
10506 | if (OPERATOR_TYPENAME_P (name) | |
10507 | || name == ansi_opname[(int) CALL_EXPR] | |
10508 | || name == ansi_opname[(int) MODIFY_EXPR] | |
10509 | || name == ansi_opname[(int) COMPONENT_REF] | |
10510 | || name == ansi_opname[(int) ARRAY_REF]) | |
10511 | cp_error ("`%D' must be a nonstatic member function", decl); | |
10512 | else | |
10513 | { | |
10514 | tree p = argtypes; | |
10515 | ||
700f8a87 MS |
10516 | if (DECL_STATIC_FUNCTION_P (decl)) |
10517 | cp_error ("`%D' must be either a non-static member function or a non-member function", decl); | |
10518 | ||
8d08fdba MS |
10519 | if (p) |
10520 | for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p)) | |
10521 | { | |
10522 | tree arg = TREE_VALUE (p); | |
10523 | if (TREE_CODE (arg) == REFERENCE_TYPE) | |
10524 | arg = TREE_TYPE (arg); | |
10525 | ||
10526 | /* This lets bad template code slip through. */ | |
10527 | if (IS_AGGR_TYPE (arg) | |
10528 | || TREE_CODE (arg) == ENUMERAL_TYPE | |
73b0fce8 KL |
10529 | || TREE_CODE (arg) == TEMPLATE_TYPE_PARM |
10530 | || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM) | |
8d08fdba MS |
10531 | goto foundaggr; |
10532 | } | |
10533 | cp_error | |
10534 | ("`%D' must have an argument of class or enumerated type", | |
10535 | decl); | |
10536 | foundaggr: | |
10537 | ; | |
10538 | } | |
10539 | } | |
10540 | ||
277294d7 | 10541 | if (name == ansi_opname[(int) CALL_EXPR]) |
8d08fdba MS |
10542 | return; /* no restrictions on args */ |
10543 | ||
9a3b49ac | 10544 | if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl)) |
a0a33927 MS |
10545 | { |
10546 | tree t = TREE_TYPE (name); | |
10547 | if (TREE_CODE (t) == VOID_TYPE) | |
10548 | pedwarn ("void is not a valid type conversion operator"); | |
10549 | else if (! friendp) | |
10550 | { | |
10551 | int ref = (TREE_CODE (t) == REFERENCE_TYPE); | |
10552 | char *what = 0; | |
10553 | if (ref) | |
10554 | t = TYPE_MAIN_VARIANT (TREE_TYPE (t)); | |
10555 | ||
10556 | if (t == current_class_type) | |
10557 | what = "the same type"; | |
9a3b49ac | 10558 | /* Don't force t to be complete here. */ |
a0a33927 | 10559 | else if (IS_AGGR_TYPE (t) |
9a3b49ac | 10560 | && TYPE_SIZE (t) |
a0a33927 MS |
10561 | && DERIVED_FROM_P (t, current_class_type)) |
10562 | what = "a base class"; | |
10563 | ||
10564 | if (what) | |
10565 | warning ("conversion to %s%s will never use a type conversion operator", | |
10566 | ref ? "a reference to " : "", what); | |
10567 | } | |
10568 | } | |
10569 | ||
8d08fdba MS |
10570 | if (name == ansi_opname[(int) MODIFY_EXPR]) |
10571 | { | |
10572 | tree parmtype; | |
10573 | ||
10574 | if (list_length (argtypes) != 3 && methodp) | |
10575 | { | |
10576 | cp_error ("`%D' must take exactly one argument", decl); | |
10577 | return; | |
10578 | } | |
10579 | parmtype = TREE_VALUE (TREE_CHAIN (argtypes)); | |
10580 | ||
f0e01782 | 10581 | if (copy_assignment_arg_p (parmtype, virtualp) |
a28e3c7f | 10582 | && ! friendp) |
8d08fdba MS |
10583 | { |
10584 | TYPE_HAS_ASSIGN_REF (current_class_type) = 1; | |
f0e01782 MS |
10585 | if (TREE_CODE (parmtype) != REFERENCE_TYPE |
10586 | || TYPE_READONLY (TREE_TYPE (parmtype))) | |
8d08fdba MS |
10587 | TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1; |
10588 | } | |
10589 | } | |
10590 | else if (name == ansi_opname[(int) COND_EXPR]) | |
10591 | { | |
10592 | /* 13.4.0.3 */ | |
10593 | pedwarn ("ANSI C++ prohibits overloading operator ?:"); | |
10594 | if (list_length (argtypes) != 4) | |
10595 | cp_error ("`%D' must take exactly three arguments", decl); | |
10596 | } | |
10597 | else if (ambi_op_p (name)) | |
10598 | { | |
10599 | if (list_length (argtypes) == 2) | |
10600 | /* prefix */; | |
10601 | else if (list_length (argtypes) == 3) | |
10602 | { | |
10603 | if ((name == ansi_opname[(int) POSTINCREMENT_EXPR] | |
10604 | || name == ansi_opname[(int) POSTDECREMENT_EXPR]) | |
5156628f | 10605 | && ! processing_template_decl |
8d08fdba MS |
10606 | && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node) |
10607 | { | |
10608 | if (methodp) | |
10609 | cp_error ("postfix `%D' must take `int' as its argument", | |
10610 | decl); | |
10611 | else | |
10612 | cp_error | |
10613 | ("postfix `%D' must take `int' as its second argument", | |
10614 | decl); | |
10615 | } | |
10616 | } | |
10617 | else | |
10618 | { | |
10619 | if (methodp) | |
10620 | cp_error ("`%D' must take either zero or one argument", decl); | |
10621 | else | |
10622 | cp_error ("`%D' must take either one or two arguments", decl); | |
10623 | } | |
824b9a4c MS |
10624 | |
10625 | /* More Effective C++ rule 6. */ | |
eb448459 | 10626 | if (warn_ecpp |
824b9a4c MS |
10627 | && (name == ansi_opname[(int) POSTINCREMENT_EXPR] |
10628 | || name == ansi_opname[(int) POSTDECREMENT_EXPR])) | |
10629 | { | |
10630 | tree arg = TREE_VALUE (argtypes); | |
10631 | tree ret = TREE_TYPE (TREE_TYPE (decl)); | |
10632 | if (methodp || TREE_CODE (arg) == REFERENCE_TYPE) | |
10633 | arg = TREE_TYPE (arg); | |
10634 | arg = TYPE_MAIN_VARIANT (arg); | |
10635 | if (list_length (argtypes) == 2) | |
10636 | { | |
10637 | if (TREE_CODE (ret) != REFERENCE_TYPE | |
10638 | || !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), | |
10639 | arg, 1)) | |
10640 | cp_warning ("prefix `%D' should return `%T'", decl, | |
10641 | build_reference_type (arg)); | |
10642 | } | |
10643 | else | |
10644 | { | |
10645 | if (!comptypes (TYPE_MAIN_VARIANT (ret), arg, 1)) | |
10646 | cp_warning ("postfix `%D' should return `%T'", decl, arg); | |
10647 | } | |
10648 | } | |
8d08fdba MS |
10649 | } |
10650 | else if (unary_op_p (name)) | |
10651 | { | |
10652 | if (list_length (argtypes) != 2) | |
10653 | { | |
10654 | if (methodp) | |
10655 | cp_error ("`%D' must take `void'", decl); | |
10656 | else | |
10657 | cp_error ("`%D' must take exactly one argument", decl); | |
10658 | } | |
10659 | } | |
10660 | else /* if (binary_op_p (name)) */ | |
10661 | { | |
10662 | if (list_length (argtypes) != 3) | |
10663 | { | |
10664 | if (methodp) | |
10665 | cp_error ("`%D' must take exactly one argument", decl); | |
10666 | else | |
10667 | cp_error ("`%D' must take exactly two arguments", decl); | |
10668 | } | |
824b9a4c MS |
10669 | |
10670 | /* More Effective C++ rule 7. */ | |
eb448459 | 10671 | if (warn_ecpp |
824b9a4c MS |
10672 | && (name == ansi_opname [TRUTH_ANDIF_EXPR] |
10673 | || name == ansi_opname [TRUTH_ORIF_EXPR] | |
10674 | || name == ansi_opname [COMPOUND_EXPR])) | |
10675 | cp_warning ("user-defined `%D' always evaluates both arguments", | |
10676 | decl); | |
10677 | } | |
10678 | ||
10679 | /* Effective C++ rule 23. */ | |
eb448459 | 10680 | if (warn_ecpp |
824b9a4c MS |
10681 | && list_length (argtypes) == 3 |
10682 | && (name == ansi_opname [PLUS_EXPR] | |
10683 | || name == ansi_opname [MINUS_EXPR] | |
10684 | || name == ansi_opname [TRUNC_DIV_EXPR] | |
10685 | || name == ansi_opname [MULT_EXPR]) | |
10686 | && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE) | |
10687 | cp_warning ("`%D' should return by value", decl); | |
8d08fdba MS |
10688 | |
10689 | /* 13.4.0.8 */ | |
10690 | if (argtypes) | |
10691 | for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes)) | |
10692 | if (TREE_PURPOSE (argtypes)) | |
10693 | { | |
10694 | TREE_PURPOSE (argtypes) = NULL_TREE; | |
10695 | if (name == ansi_opname[(int) POSTINCREMENT_EXPR] | |
10696 | || name == ansi_opname[(int) POSTDECREMENT_EXPR]) | |
10697 | { | |
10698 | if (pedantic) | |
10699 | cp_pedwarn ("`%D' cannot have default arguments", decl); | |
10700 | } | |
10701 | else | |
10702 | cp_error ("`%D' cannot have default arguments", decl); | |
10703 | } | |
10704 | } | |
10705 | } | |
10706 | \f | |
10707 | /* Get the struct, enum or union (CODE says which) with tag NAME. | |
10708 | Define the tag as a forward-reference if it is not defined. | |
10709 | ||
10710 | C++: If a class derivation is given, process it here, and report | |
10711 | an error if multiple derivation declarations are not identical. | |
10712 | ||
10713 | If this is a definition, come in through xref_tag and only look in | |
10714 | the current frame for the name (since C++ allows new names in any | |
10715 | scope.) */ | |
10716 | ||
8d08fdba MS |
10717 | tree |
10718 | xref_tag (code_type_node, name, binfo, globalize) | |
10719 | tree code_type_node; | |
10720 | tree name, binfo; | |
10721 | int globalize; | |
10722 | { | |
10723 | enum tag_types tag_code; | |
10724 | enum tree_code code; | |
10725 | int temp = 0; | |
8d08fdba MS |
10726 | register tree ref, t; |
10727 | struct binding_level *b = inner_binding_level; | |
a80e4195 | 10728 | int got_type = 0; |
8d08fdba MS |
10729 | |
10730 | tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); | |
10731 | switch (tag_code) | |
10732 | { | |
10733 | case record_type: | |
10734 | case class_type: | |
8d08fdba MS |
10735 | case signature_type: |
10736 | code = RECORD_TYPE; | |
8d08fdba MS |
10737 | break; |
10738 | case union_type: | |
10739 | code = UNION_TYPE; | |
8d08fdba MS |
10740 | break; |
10741 | case enum_type: | |
10742 | code = ENUMERAL_TYPE; | |
10743 | break; | |
10744 | default: | |
10745 | my_friendly_abort (18); | |
10746 | } | |
10747 | ||
10748 | /* If a cross reference is requested, look up the type | |
10749 | already defined for this tag and return it. */ | |
be99da77 MS |
10750 | if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') |
10751 | { | |
10752 | t = name; | |
a80e4195 MS |
10753 | name = TYPE_IDENTIFIER (t); |
10754 | got_type = 1; | |
be99da77 MS |
10755 | } |
10756 | else | |
10757 | t = IDENTIFIER_TYPE_VALUE (name); | |
73b0fce8 KL |
10758 | if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM |
10759 | && TREE_CODE (t) != TEMPLATE_TEMPLATE_PARM) | |
a0a33927 MS |
10760 | t = NULL_TREE; |
10761 | ||
8ccc31eb | 10762 | if (! globalize) |
8d08fdba | 10763 | { |
73b0fce8 KL |
10764 | if (pedantic && t && (TREE_CODE (t) == TEMPLATE_TYPE_PARM |
10765 | || TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)) | |
ec255269 MS |
10766 | { |
10767 | cp_pedwarn ("redeclaration of template type-parameter `%T'", name); | |
10768 | cp_pedwarn_at (" previously declared here", t); | |
10769 | } | |
a80e4195 | 10770 | if (t && TYPE_CONTEXT (t) && got_type) |
8ccc31eb | 10771 | ref = t; |
8d08fdba | 10772 | else |
e92cc029 MS |
10773 | { |
10774 | /* If we know we are defining this tag, only look it up in | |
10775 | this scope and don't try to find it as a type. */ | |
10776 | ref = lookup_tag (code, name, b, 1); | |
10777 | } | |
8d08fdba MS |
10778 | } |
10779 | else | |
10780 | { | |
10781 | if (t) | |
10782 | ref = t; | |
10783 | else | |
10784 | ref = lookup_tag (code, name, b, 0); | |
10785 | ||
10786 | if (! ref) | |
10787 | { | |
10788 | /* Try finding it as a type declaration. If that wins, use it. */ | |
10789 | ref = lookup_name (name, 1); | |
10790 | if (ref && TREE_CODE (ref) == TYPE_DECL | |
10791 | && TREE_CODE (TREE_TYPE (ref)) == code) | |
10792 | ref = TREE_TYPE (ref); | |
10793 | else | |
10794 | ref = NULL_TREE; | |
10795 | } | |
10796 | } | |
10797 | ||
10798 | push_obstacks_nochange (); | |
10799 | ||
10800 | if (! ref) | |
10801 | { | |
10802 | /* If no such tag is yet defined, create a forward-reference node | |
10803 | and record it as the "definition". | |
10804 | When a real declaration of this type is found, | |
10805 | the forward-reference will be altered into a real type. */ | |
10806 | ||
10807 | /* In C++, since these migrate into the global scope, we must | |
10808 | build them on the permanent obstack. */ | |
10809 | ||
10810 | temp = allocation_temporary_p (); | |
10811 | if (temp) | |
10812 | end_temporary_allocation (); | |
10813 | ||
10814 | if (code == ENUMERAL_TYPE) | |
10815 | { | |
fc378698 MS |
10816 | cp_error ("use of enum `%#D' without previous declaration", name); |
10817 | ||
8d08fdba MS |
10818 | ref = make_node (ENUMERAL_TYPE); |
10819 | ||
10820 | /* Give the type a default layout like unsigned int | |
10821 | to avoid crashing if it does not get defined. */ | |
10822 | TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); | |
10823 | TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); | |
10824 | TREE_UNSIGNED (ref) = 1; | |
10825 | TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); | |
10826 | TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); | |
10827 | TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); | |
10828 | ||
10829 | /* Enable us to recognize when a type is created in class context. | |
10830 | To do nested classes correctly, this should probably be cleared | |
10831 | out when we leave this classes scope. Currently this in only | |
10832 | done in `start_enum'. */ | |
10833 | ||
10834 | pushtag (name, ref, globalize); | |
8d08fdba | 10835 | } |
8d08fdba MS |
10836 | else |
10837 | { | |
8d08fdba | 10838 | struct binding_level *old_b = class_binding_level; |
8d08fdba MS |
10839 | |
10840 | ref = make_lang_type (code); | |
10841 | ||
8d08fdba MS |
10842 | if (tag_code == signature_type) |
10843 | { | |
10844 | SET_SIGNATURE (ref); | |
f376e137 MS |
10845 | /* Since a signature type will be turned into the type |
10846 | of signature tables, it's not only an interface. */ | |
8d08fdba | 10847 | CLASSTYPE_INTERFACE_ONLY (ref) = 0; |
f376e137 MS |
10848 | SET_CLASSTYPE_INTERFACE_KNOWN (ref); |
10849 | /* A signature doesn't have a vtable. */ | |
00595019 | 10850 | CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0; |
8d08fdba MS |
10851 | } |
10852 | ||
8d08fdba MS |
10853 | #ifdef NONNESTED_CLASSES |
10854 | /* Class types don't nest the way enums do. */ | |
10855 | class_binding_level = (struct binding_level *)0; | |
10856 | #endif | |
10857 | pushtag (name, ref, globalize); | |
10858 | class_binding_level = old_b; | |
8d08fdba MS |
10859 | } |
10860 | } | |
10861 | else | |
10862 | { | |
8d08fdba | 10863 | /* If it no longer looks like a nested type, make sure it's |
30394414 JM |
10864 | in global scope. |
10865 | If it is not an IDENTIFIER, this is not a declaration */ | |
8d08fdba | 10866 | if (b == global_binding_level && !class_binding_level |
30394414 JM |
10867 | && TREE_CODE (name) == IDENTIFIER_NODE) |
10868 | { | |
10869 | tree binding; | |
10870 | binding = binding_for_name (name, current_namespace); | |
10871 | if (BINDING_VALUE (binding) == NULL_TREE) | |
10872 | BINDING_VALUE (binding) = TYPE_NAME (ref); | |
10873 | } | |
7fe6899f MM |
10874 | |
10875 | if (!globalize && processing_template_decl && IS_AGGR_TYPE (ref)) | |
10876 | redeclare_class_template (ref); | |
8d08fdba MS |
10877 | } |
10878 | ||
10879 | if (binfo) | |
8ccc31eb | 10880 | xref_basetypes (code_type_node, name, ref, binfo); |
8d08fdba | 10881 | |
8d08fdba MS |
10882 | /* Until the type is defined, tentatively accept whatever |
10883 | structure tag the user hands us. */ | |
10884 | if (TYPE_SIZE (ref) == NULL_TREE | |
10885 | && ref != current_class_type | |
10886 | /* Have to check this, in case we have contradictory tag info. */ | |
10887 | && IS_AGGR_TYPE_CODE (TREE_CODE (ref))) | |
10888 | { | |
10889 | if (tag_code == class_type) | |
10890 | CLASSTYPE_DECLARED_CLASS (ref) = 1; | |
10891 | else if (tag_code == record_type || tag_code == signature_type) | |
10892 | CLASSTYPE_DECLARED_CLASS (ref) = 0; | |
10893 | } | |
10894 | ||
10895 | pop_obstacks (); | |
10896 | ||
10897 | return ref; | |
10898 | } | |
8ccc31eb | 10899 | |
fc378698 MS |
10900 | tree |
10901 | xref_tag_from_type (old, id, globalize) | |
10902 | tree old, id; | |
10903 | int globalize; | |
10904 | { | |
10905 | tree code_type_node; | |
10906 | ||
10907 | if (TREE_CODE (old) == RECORD_TYPE) | |
10908 | code_type_node = (CLASSTYPE_DECLARED_CLASS (old) | |
10909 | ? class_type_node : record_type_node); | |
10910 | else | |
10911 | code_type_node = union_type_node; | |
10912 | ||
10913 | if (id == NULL_TREE) | |
10914 | id = TYPE_IDENTIFIER (old); | |
10915 | ||
10916 | return xref_tag (code_type_node, id, NULL_TREE, globalize); | |
10917 | } | |
10918 | ||
8ccc31eb MS |
10919 | void |
10920 | xref_basetypes (code_type_node, name, ref, binfo) | |
10921 | tree code_type_node; | |
10922 | tree name, ref; | |
10923 | tree binfo; | |
10924 | { | |
10925 | /* In the declaration `A : X, Y, ... Z' we mark all the types | |
10926 | (A, X, Y, ..., Z) so we can check for duplicates. */ | |
10927 | tree binfos; | |
10928 | int i, len; | |
10929 | enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); | |
10930 | ||
10931 | if (tag_code == union_type) | |
10932 | { | |
10933 | cp_error ("derived union `%T' invalid", ref); | |
10934 | return; | |
10935 | } | |
10936 | ||
10937 | len = list_length (binfo); | |
10938 | push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref)); | |
10939 | ||
10940 | SET_CLASSTYPE_MARKED (ref); | |
10941 | BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len); | |
10942 | ||
10943 | for (i = 0; binfo; binfo = TREE_CHAIN (binfo)) | |
10944 | { | |
10945 | /* The base of a derived struct is public by default. */ | |
10946 | int via_public | |
be99da77 MS |
10947 | = (TREE_PURPOSE (binfo) == access_public_node |
10948 | || TREE_PURPOSE (binfo) == access_public_virtual_node | |
8ccc31eb | 10949 | || (tag_code != class_type |
be99da77 MS |
10950 | && (TREE_PURPOSE (binfo) == access_default_node |
10951 | || TREE_PURPOSE (binfo) == access_default_virtual_node))); | |
d8b55a76 JM |
10952 | int via_protected |
10953 | = (TREE_PURPOSE (binfo) == access_protected_node | |
10954 | || TREE_PURPOSE (binfo) == access_protected_virtual_node); | |
8ccc31eb | 10955 | int via_virtual |
be99da77 | 10956 | = (TREE_PURPOSE (binfo) == access_private_virtual_node |
d8b55a76 | 10957 | || TREE_PURPOSE (binfo) == access_protected_virtual_node |
be99da77 MS |
10958 | || TREE_PURPOSE (binfo) == access_public_virtual_node |
10959 | || TREE_PURPOSE (binfo) == access_default_virtual_node); | |
10960 | tree basetype = TREE_VALUE (binfo); | |
8ccc31eb MS |
10961 | tree base_binfo; |
10962 | ||
10963 | GNU_xref_hier (IDENTIFIER_POINTER (name), | |
10964 | IDENTIFIER_POINTER (TREE_VALUE (binfo)), | |
10965 | via_public, via_virtual, 0); | |
10966 | ||
10967 | if (basetype && TREE_CODE (basetype) == TYPE_DECL) | |
10968 | basetype = TREE_TYPE (basetype); | |
5566b478 MS |
10969 | if (!basetype |
10970 | || (TREE_CODE (basetype) != RECORD_TYPE | |
a80e4195 | 10971 | && TREE_CODE (basetype) != TYPENAME_TYPE |
73b0fce8 KL |
10972 | && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM |
10973 | && TREE_CODE (basetype) != TEMPLATE_TEMPLATE_PARM)) | |
8ccc31eb MS |
10974 | { |
10975 | cp_error ("base type `%T' fails to be a struct or class type", | |
10976 | TREE_VALUE (binfo)); | |
10977 | continue; | |
10978 | } | |
10979 | #if 1 | |
8adf5b5e JM |
10980 | /* This code replaces similar code in layout_basetypes. |
10981 | We put the complete_type first for implicit `typename'. */ | |
10982 | else if (TYPE_SIZE (complete_type (basetype)) == NULL_TREE | |
10983 | && ! (current_template_parms && uses_template_parms (basetype))) | |
8ccc31eb MS |
10984 | { |
10985 | cp_error ("base class `%T' has incomplete type", basetype); | |
10986 | continue; | |
10987 | } | |
10988 | #endif | |
10989 | else | |
10990 | { | |
10991 | if (CLASSTYPE_MARKED (basetype)) | |
10992 | { | |
10993 | if (basetype == ref) | |
10994 | cp_error ("recursive type `%T' undefined", basetype); | |
10995 | else | |
10996 | cp_error ("duplicate base type `%T' invalid", basetype); | |
10997 | continue; | |
10998 | } | |
10999 | ||
11000 | /* Note that the BINFO records which describe individual | |
11001 | inheritances are *not* shared in the lattice! They | |
11002 | cannot be shared because a given baseclass may be | |
11003 | inherited with different `accessibility' by different | |
11004 | derived classes. (Each BINFO record describing an | |
11005 | individual inheritance contains flags which say what | |
11006 | the `accessibility' of that particular inheritance is.) */ | |
11007 | ||
11008 | base_binfo = make_binfo (integer_zero_node, basetype, | |
11009 | TYPE_BINFO_VTABLE (basetype), | |
11010 | TYPE_BINFO_VIRTUALS (basetype), NULL_TREE); | |
11011 | ||
11012 | TREE_VEC_ELT (binfos, i) = base_binfo; | |
11013 | TREE_VIA_PUBLIC (base_binfo) = via_public; | |
11014 | TREE_VIA_PROTECTED (base_binfo) = via_protected; | |
11015 | TREE_VIA_VIRTUAL (base_binfo) = via_virtual; | |
11016 | BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref); | |
11017 | ||
11018 | SET_CLASSTYPE_MARKED (basetype); | |
9e9ff709 | 11019 | |
8ccc31eb MS |
11020 | /* We are free to modify these bits because they are meaningless |
11021 | at top level, and BASETYPE is a top-level type. */ | |
11022 | if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) | |
11023 | { | |
11024 | TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1; | |
11025 | TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; | |
11026 | } | |
11027 | ||
8ccc31eb MS |
11028 | TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype); |
11029 | TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype); | |
11030 | CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype); | |
11031 | i += 1; | |
11032 | } | |
11033 | } | |
11034 | if (i) | |
11035 | TREE_VEC_LENGTH (binfos) = i; | |
11036 | else | |
11037 | BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE; | |
11038 | ||
11039 | if (i > 1) | |
11040 | TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; | |
11041 | else if (i == 1) | |
11042 | TYPE_USES_MULTIPLE_INHERITANCE (ref) | |
11043 | = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0))); | |
11044 | if (TYPE_USES_MULTIPLE_INHERITANCE (ref)) | |
11045 | TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; | |
11046 | ||
11047 | /* Unmark all the types. */ | |
11048 | while (--i >= 0) | |
11049 | CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i))); | |
11050 | CLEAR_CLASSTYPE_MARKED (ref); | |
11051 | ||
11052 | pop_obstacks (); | |
11053 | } | |
11054 | ||
8d08fdba | 11055 | \f |
b3d5a58b | 11056 | tree current_local_enum = NULL_TREE; |
8d08fdba MS |
11057 | |
11058 | /* Begin compiling the definition of an enumeration type. | |
11059 | NAME is its name (or null if anonymous). | |
11060 | Returns the type object, as yet incomplete. | |
11061 | Also records info about it so that build_enumerator | |
11062 | may be used to declare the individual values as they are read. */ | |
11063 | ||
11064 | tree | |
11065 | start_enum (name) | |
11066 | tree name; | |
11067 | { | |
11068 | register tree enumtype = NULL_TREE; | |
11069 | struct binding_level *b = inner_binding_level; | |
11070 | ||
b87692e5 MS |
11071 | if (processing_template_decl && current_function_decl) |
11072 | end_temporary_allocation (); | |
11073 | ||
8d08fdba MS |
11074 | /* If this is the real definition for a previous forward reference, |
11075 | fill in the contents in the same object that used to be the | |
11076 | forward reference. */ | |
11077 | ||
11078 | if (name != NULL_TREE) | |
11079 | enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); | |
11080 | ||
11081 | if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE) | |
c91a56d2 | 11082 | cp_error ("multiple definition of `%#T'", enumtype); |
8d08fdba MS |
11083 | else |
11084 | { | |
11085 | enumtype = make_node (ENUMERAL_TYPE); | |
11086 | pushtag (name, enumtype, 0); | |
11087 | } | |
11088 | ||
c91a56d2 MS |
11089 | if (b->pseudo_global) |
11090 | cp_error ("template declaration of `%#T'", enumtype); | |
11091 | ||
8d08fdba MS |
11092 | if (current_class_type) |
11093 | TREE_ADDRESSABLE (b->tags) = 1; | |
c91a56d2 | 11094 | |
8d08fdba MS |
11095 | current_local_enum = NULL_TREE; |
11096 | ||
e92cc029 MS |
11097 | /* We don't copy this value because build_enumerator needs to do it. */ |
11098 | enum_next_value = integer_zero_node; | |
7177d104 | 11099 | enum_overflow = 0; |
8d08fdba MS |
11100 | |
11101 | GNU_xref_decl (current_function_decl, enumtype); | |
11102 | return enumtype; | |
11103 | } | |
11104 | ||
11105 | /* After processing and defining all the values of an enumeration type, | |
11106 | install their decls in the enumeration type and finish it off. | |
11107 | ENUMTYPE is the type object and VALUES a list of name-value pairs. | |
11108 | Returns ENUMTYPE. */ | |
11109 | ||
11110 | tree | |
11111 | finish_enum (enumtype, values) | |
11112 | register tree enumtype, values; | |
11113 | { | |
a703fb38 | 11114 | register tree minnode = NULL_TREE, maxnode = NULL_TREE; |
8d08fdba MS |
11115 | /* Calculate the maximum value of any enumerator in this type. */ |
11116 | ||
11117 | if (values) | |
11118 | { | |
f376e137 MS |
11119 | register tree pair; |
11120 | register tree value = DECL_INITIAL (TREE_VALUE (values)); | |
5566b478 | 11121 | |
5156628f | 11122 | if (! processing_template_decl) |
5566b478 MS |
11123 | { |
11124 | /* Speed up the main loop by performing some precalculations */ | |
11125 | TREE_TYPE (TREE_VALUE (values)) = enumtype; | |
11126 | TREE_TYPE (value) = enumtype; | |
11127 | minnode = maxnode = value; | |
11128 | } | |
f376e137 | 11129 | TREE_VALUE (values) = value; |
8d08fdba MS |
11130 | |
11131 | for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) | |
11132 | { | |
f376e137 | 11133 | value = DECL_INITIAL (TREE_VALUE (pair)); |
5156628f | 11134 | if (! processing_template_decl) |
5566b478 MS |
11135 | { |
11136 | TREE_TYPE (TREE_VALUE (pair)) = enumtype; | |
11137 | TREE_TYPE (value) = enumtype; | |
11138 | if (tree_int_cst_lt (maxnode, value)) | |
11139 | maxnode = value; | |
11140 | else if (tree_int_cst_lt (value, minnode)) | |
11141 | minnode = value; | |
11142 | } | |
f376e137 | 11143 | TREE_VALUE (pair) = value; |
8d08fdba MS |
11144 | } |
11145 | } | |
f376e137 MS |
11146 | else |
11147 | maxnode = minnode = integer_zero_node; | |
8d08fdba | 11148 | |
de22184b | 11149 | TYPE_VALUES (enumtype) = nreverse (values); |
2986ae00 | 11150 | |
5156628f | 11151 | if (processing_template_decl) |
b87692e5 MS |
11152 | { |
11153 | if (current_function_decl) | |
11154 | { | |
11155 | add_tree (build_min (TAG_DEFN, enumtype)); | |
11156 | resume_temporary_allocation (); | |
11157 | } | |
11158 | return enumtype; | |
11159 | } | |
5566b478 | 11160 | |
f376e137 MS |
11161 | { |
11162 | int unsignedp = tree_int_cst_sgn (minnode) >= 0; | |
11163 | int lowprec = min_precision (minnode, unsignedp); | |
11164 | int highprec = min_precision (maxnode, unsignedp); | |
11165 | int precision = MAX (lowprec, highprec); | |
8d08fdba | 11166 | |
6060a796 | 11167 | TYPE_SIZE (enumtype) = NULL_TREE; |
13fbb038 | 11168 | |
8ccc31eb | 11169 | /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */ |
8d08fdba | 11170 | |
f376e137 | 11171 | TYPE_PRECISION (enumtype) = precision; |
f376e137 | 11172 | if (unsignedp) |
8d08fdba | 11173 | fixup_unsigned_type (enumtype); |
f376e137 MS |
11174 | else |
11175 | fixup_signed_type (enumtype); | |
8ccc31eb | 11176 | |
5566b478 | 11177 | if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node))) |
8ccc31eb MS |
11178 | /* Use the width of the narrowest normal C type which is wide enough. */ |
11179 | TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size | |
11180 | (precision, 1)); | |
11181 | else | |
11182 | TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); | |
11183 | ||
11184 | TYPE_SIZE (enumtype) = 0; | |
11185 | layout_type (enumtype); | |
f376e137 | 11186 | } |
8d08fdba | 11187 | |
f376e137 MS |
11188 | { |
11189 | register tree tem; | |
11190 | ||
11191 | /* Fix up all variant types of this enum type. */ | |
11192 | for (tem = TYPE_MAIN_VARIANT (enumtype); tem; | |
11193 | tem = TYPE_NEXT_VARIANT (tem)) | |
11194 | { | |
11195 | TYPE_VALUES (tem) = TYPE_VALUES (enumtype); | |
11196 | TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); | |
11197 | TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); | |
11198 | TYPE_SIZE (tem) = TYPE_SIZE (enumtype); | |
11199 | TYPE_MODE (tem) = TYPE_MODE (enumtype); | |
11200 | TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); | |
11201 | TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); | |
11202 | TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); | |
11203 | } | |
11204 | } | |
8d08fdba MS |
11205 | |
11206 | /* Finish debugging output for this type. */ | |
d2e5ee5c | 11207 | rest_of_type_compilation (enumtype, global_bindings_p ()); |
8d08fdba MS |
11208 | |
11209 | return enumtype; | |
11210 | } | |
11211 | ||
11212 | /* Build and install a CONST_DECL for one value of the | |
11213 | current enumeration type (one that was begun with start_enum). | |
11214 | Return a tree-list containing the name and its value. | |
11215 | Assignment of sequential values by default is handled here. */ | |
11216 | ||
11217 | tree | |
11218 | build_enumerator (name, value) | |
11219 | tree name, value; | |
11220 | { | |
11221 | tree decl, result; | |
8d08fdba MS |
11222 | |
11223 | /* Remove no-op casts from the value. */ | |
11224 | if (value) | |
11225 | STRIP_TYPE_NOPS (value); | |
11226 | ||
5156628f | 11227 | if (! processing_template_decl) |
5566b478 MS |
11228 | { |
11229 | /* Validate and default VALUE. */ | |
11230 | if (value != NULL_TREE) | |
11231 | { | |
11232 | if (TREE_READONLY_DECL_P (value)) | |
e92cc029 | 11233 | value = decl_constant_value (value); |
5566b478 MS |
11234 | |
11235 | if (TREE_CODE (value) == INTEGER_CST) | |
11236 | { | |
11237 | value = default_conversion (value); | |
11238 | constant_expression_warning (value); | |
11239 | } | |
11240 | else | |
11241 | { | |
11242 | cp_error ("enumerator value for `%D' not integer constant", name); | |
11243 | value = NULL_TREE; | |
11244 | } | |
11245 | } | |
11246 | ||
5566b478 | 11247 | /* Default based on previous value. */ |
5156628f | 11248 | if (value == NULL_TREE && ! processing_template_decl) |
5566b478 MS |
11249 | { |
11250 | value = enum_next_value; | |
11251 | if (enum_overflow) | |
11252 | cp_error ("overflow in enumeration values at `%D'", name); | |
11253 | } | |
11254 | ||
11255 | /* Remove no-op casts from the value. */ | |
11256 | if (value) | |
11257 | STRIP_TYPE_NOPS (value); | |
11258 | ||
e92cc029 MS |
11259 | /* We have to always copy here; not all INTEGER_CSTs are unshared, |
11260 | and there's no wedding ring. Look at size_int()...*/ | |
11261 | value = copy_node (value); | |
013bc8af MS |
11262 | #if 0 |
11263 | /* To fix MAX_VAL enum consts. (bkoz) */ | |
e92cc029 | 11264 | TREE_TYPE (value) = integer_type_node; |
013bc8af | 11265 | #endif |
5566b478 | 11266 | } |
8d08fdba | 11267 | |
8d08fdba MS |
11268 | /* C++ associates enums with global, function, or class declarations. */ |
11269 | ||
7177d104 MS |
11270 | decl = current_scope (); |
11271 | if (decl && decl == current_class_type) | |
8d08fdba MS |
11272 | { |
11273 | /* This enum declaration is local to the class, so we must put | |
11274 | it in that class's list of decls. */ | |
11275 | decl = build_lang_field_decl (CONST_DECL, name, integer_type_node); | |
11276 | DECL_INITIAL (decl) = value; | |
11277 | TREE_READONLY (decl) = 1; | |
11278 | pushdecl_class_level (decl); | |
11279 | TREE_CHAIN (decl) = current_local_enum; | |
11280 | current_local_enum = decl; | |
11281 | } | |
11282 | else | |
11283 | { | |
11284 | /* It's a global enum, or it's local to a function. (Note local to | |
11285 | a function could mean local to a class method. */ | |
11286 | decl = build_decl (CONST_DECL, name, integer_type_node); | |
11287 | DECL_INITIAL (decl) = value; | |
42976354 | 11288 | TREE_READONLY (decl) = 1; |
8d08fdba MS |
11289 | |
11290 | pushdecl (decl); | |
11291 | GNU_xref_decl (current_function_decl, decl); | |
11292 | } | |
11293 | ||
5156628f | 11294 | if (! processing_template_decl) |
5566b478 MS |
11295 | { |
11296 | /* Set basis for default for next value. */ | |
11297 | enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, | |
11298 | integer_one_node, PLUS_EXPR); | |
11299 | enum_overflow = tree_int_cst_lt (enum_next_value, value); | |
5566b478 | 11300 | } |
8d08fdba | 11301 | |
8d2733ca | 11302 | result = saveable_tree_cons (name, decl, NULL_TREE); |
8d08fdba MS |
11303 | return result; |
11304 | } | |
11305 | ||
11306 | tree | |
86052cc3 JM |
11307 | grok_enum_decls (decl) |
11308 | tree decl; | |
8d08fdba MS |
11309 | { |
11310 | tree d = current_local_enum; | |
11311 | ||
11312 | if (d == NULL_TREE) | |
11313 | return decl; | |
11314 | ||
11315 | while (1) | |
11316 | { | |
8d08fdba MS |
11317 | if (TREE_CHAIN (d) == NULL_TREE) |
11318 | { | |
11319 | TREE_CHAIN (d) = decl; | |
11320 | break; | |
11321 | } | |
11322 | d = TREE_CHAIN (d); | |
11323 | } | |
11324 | ||
11325 | decl = current_local_enum; | |
11326 | current_local_enum = NULL_TREE; | |
11327 | ||
11328 | return decl; | |
11329 | } | |
11330 | \f | |
5566b478 MS |
11331 | static int function_depth; |
11332 | ||
8d08fdba MS |
11333 | /* Create the FUNCTION_DECL for a function definition. |
11334 | DECLSPECS and DECLARATOR are the parts of the declaration; | |
11335 | they describe the function's name and the type it returns, | |
11336 | but twisted together in a fashion that parallels the syntax of C. | |
11337 | ||
11338 | This function creates a binding context for the function body | |
11339 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
11340 | ||
11341 | Returns 1 on success. If the DECLARATOR is not suitable for a function | |
11342 | (it defines a datum instead), we return 0, which tells | |
11343 | yyparse to report a parse error. | |
11344 | ||
11345 | For C++, we must first check whether that datum makes any sense. | |
11346 | For example, "class A local_a(1,2);" means that variable local_a | |
11347 | is an aggregate of type A, which should have a constructor | |
11348 | applied to it with the argument list [1, 2]. | |
11349 | ||
11350 | @@ There is currently no way to retrieve the storage | |
11351 | @@ allocated to FUNCTION (or all of its parms) if we return | |
11352 | @@ something we had previously. */ | |
11353 | ||
11354 | int | |
c11b6f21 MS |
11355 | start_function (declspecs, declarator, attrs, pre_parsed_p) |
11356 | tree declspecs, declarator, attrs; | |
8d08fdba MS |
11357 | int pre_parsed_p; |
11358 | { | |
5566b478 | 11359 | tree decl1; |
8d08fdba MS |
11360 | tree ctype = NULL_TREE; |
11361 | tree fntype; | |
11362 | tree restype; | |
11363 | extern int have_extern_spec; | |
11364 | extern int used_extern_spec; | |
11365 | int doing_friend = 0; | |
11366 | ||
8d08fdba MS |
11367 | /* Sanity check. */ |
11368 | my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160); | |
11369 | my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); | |
11370 | ||
e92cc029 | 11371 | /* Assume, until we see it does. */ |
8d08fdba MS |
11372 | current_function_returns_value = 0; |
11373 | current_function_returns_null = 0; | |
11374 | warn_about_return_type = 0; | |
fd378c9d JM |
11375 | named_labels = 0; |
11376 | shadowed_labels = 0; | |
8d08fdba MS |
11377 | current_function_assigns_this = 0; |
11378 | current_function_just_assigned_this = 0; | |
11379 | current_function_parms_stored = 0; | |
11380 | original_result_rtx = NULL_RTX; | |
a9aedbc2 | 11381 | base_init_expr = NULL_TREE; |
79ff2c6c MS |
11382 | current_base_init_list = NULL_TREE; |
11383 | current_member_init_list = NULL_TREE; | |
f30432d7 | 11384 | ctor_label = dtor_label = NULL_TREE; |
42976354 | 11385 | static_labelno = 0; |
8d08fdba MS |
11386 | |
11387 | clear_temp_name (); | |
11388 | ||
e92cc029 | 11389 | /* This should only be done once on the top most decl. */ |
8d08fdba MS |
11390 | if (have_extern_spec && !used_extern_spec) |
11391 | { | |
11392 | declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); | |
11393 | used_extern_spec = 1; | |
11394 | } | |
11395 | ||
11396 | if (pre_parsed_p) | |
11397 | { | |
11398 | decl1 = declarator; | |
11399 | ||
11400 | if (! DECL_ARGUMENTS (decl1) | |
11401 | && !DECL_STATIC_FUNCTION_P (decl1) | |
11402 | && DECL_CONTEXT (decl1) | |
d2e5ee5c MS |
11403 | && TYPE_IDENTIFIER (DECL_CONTEXT (decl1)) |
11404 | && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (DECL_CONTEXT (decl1)))) | |
8d08fdba | 11405 | { |
30394414 JM |
11406 | tree binding = binding_for_name (DECL_NAME (decl1), |
11407 | current_namespace); | |
8d08fdba MS |
11408 | cp_error ("redeclaration of `%#D'", decl1); |
11409 | if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))) | |
11410 | cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))); | |
30394414 JM |
11411 | else if (BINDING_VALUE (binding)) |
11412 | cp_error_at ("previous declaration here", BINDING_VALUE (binding)); | |
8d08fdba MS |
11413 | } |
11414 | ||
8d08fdba MS |
11415 | fntype = TREE_TYPE (decl1); |
11416 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
11417 | ctype = TYPE_METHOD_BASETYPE (fntype); | |
11418 | ||
11419 | /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a | |
11420 | class is in the (lexical) scope of the class in which it is | |
11421 | defined. */ | |
11422 | if (!ctype && DECL_FRIEND_P (decl1)) | |
11423 | { | |
11424 | ctype = DECL_CLASS_CONTEXT (decl1); | |
11425 | ||
11426 | /* CTYPE could be null here if we're dealing with a template; | |
11427 | for example, `inline friend float foo()' inside a template | |
11428 | will have no CTYPE set. */ | |
11429 | if (ctype && TREE_CODE (ctype) != RECORD_TYPE) | |
11430 | ctype = NULL_TREE; | |
11431 | else | |
11432 | doing_friend = 1; | |
11433 | } | |
11434 | ||
8d08fdba | 11435 | /* In a fcn definition, arg types must be complete. */ |
5566b478 | 11436 | require_complete_types_for_parms (DECL_ARGUMENTS (decl1)); |
9fffd093 RK |
11437 | |
11438 | /* In case some arg types were completed since the declaration was | |
11439 | parsed, fix up the decls. */ | |
11440 | { | |
5566b478 | 11441 | tree t = DECL_ARGUMENTS (decl1); |
9fffd093 RK |
11442 | for (; t; t = TREE_CHAIN (t)) |
11443 | layout_decl (t, 0); | |
11444 | } | |
5566b478 MS |
11445 | |
11446 | last_function_parms = DECL_ARGUMENTS (decl1); | |
11447 | last_function_parm_tags = NULL_TREE; | |
8d08fdba MS |
11448 | } |
11449 | else | |
11450 | { | |
c11b6f21 | 11451 | decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL_TREE); |
8d08fdba MS |
11452 | /* If the declarator is not suitable for a function definition, |
11453 | cause a syntax error. */ | |
11454 | if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0; | |
11455 | ||
11456 | fntype = TREE_TYPE (decl1); | |
11457 | ||
11458 | restype = TREE_TYPE (fntype); | |
11459 | if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype) | |
11460 | && ! CLASSTYPE_GOT_SEMICOLON (restype)) | |
11461 | { | |
11462 | cp_error ("semicolon missing after declaration of `%#T'", restype); | |
e66d884e | 11463 | shadow_tag (build_expr_list (NULL_TREE, restype)); |
8d08fdba MS |
11464 | CLASSTYPE_GOT_SEMICOLON (restype) = 1; |
11465 | if (TREE_CODE (fntype) == FUNCTION_TYPE) | |
11466 | fntype = build_function_type (integer_type_node, | |
11467 | TYPE_ARG_TYPES (fntype)); | |
11468 | else | |
11469 | fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)), | |
11470 | integer_type_node, | |
11471 | TYPE_ARG_TYPES (fntype)); | |
11472 | TREE_TYPE (decl1) = fntype; | |
11473 | } | |
11474 | ||
11475 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
11476 | ctype = TYPE_METHOD_BASETYPE (fntype); | |
11477 | else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4 | |
11478 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main") | |
11479 | && DECL_CONTEXT (decl1) == NULL_TREE) | |
11480 | { | |
11481 | /* If this doesn't return integer_type, complain. */ | |
11482 | if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node) | |
11483 | { | |
a28e3c7f | 11484 | if (pedantic || warn_return_type) |
5566b478 | 11485 | pedwarn ("return type for `main' changed to `int'"); |
8d08fdba MS |
11486 | TREE_TYPE (decl1) = fntype = default_function_type; |
11487 | } | |
11488 | warn_about_return_type = 0; | |
11489 | } | |
11490 | } | |
11491 | ||
11492 | /* Warn if function was previously implicitly declared | |
11493 | (but not if we warned then). */ | |
11494 | if (! warn_implicit | |
11495 | && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE) | |
11496 | cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))); | |
11497 | ||
11498 | current_function_decl = decl1; | |
5566b478 MS |
11499 | /* Save the parm names or decls from this function's declarator |
11500 | where store_parm_decls will find them. */ | |
11501 | current_function_parms = last_function_parms; | |
11502 | current_function_parm_tags = last_function_parm_tags; | |
8d08fdba | 11503 | |
9e9ff709 | 11504 | announce_function (decl1); |
8d08fdba | 11505 | |
5156628f | 11506 | if (! processing_template_decl) |
8d08fdba | 11507 | { |
5566b478 MS |
11508 | if (TYPE_SIZE (complete_type (TREE_TYPE (fntype))) == NULL_TREE) |
11509 | { | |
11510 | cp_error ("return-type `%#T' is an incomplete type", | |
11511 | TREE_TYPE (fntype)); | |
8d08fdba | 11512 | |
5566b478 MS |
11513 | /* Make it return void instead, but don't change the |
11514 | type of the DECL_RESULT, in case we have a named return value. */ | |
11515 | if (ctype) | |
11516 | TREE_TYPE (decl1) | |
11517 | = build_cplus_method_type (build_type_variant (ctype, | |
11518 | TREE_READONLY (decl1), | |
11519 | TREE_SIDE_EFFECTS (decl1)), | |
11520 | void_type_node, | |
11521 | FUNCTION_ARG_CHAIN (decl1)); | |
11522 | else | |
11523 | TREE_TYPE (decl1) | |
11524 | = build_function_type (void_type_node, | |
11525 | TYPE_ARG_TYPES (TREE_TYPE (decl1))); | |
11526 | DECL_RESULT (decl1) | |
11527 | = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype))); | |
11528 | TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype)); | |
11529 | TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype)); | |
11530 | } | |
11531 | ||
11532 | if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype)) | |
11533 | && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype))) | |
11534 | abstract_virtuals_error (decl1, TREE_TYPE (fntype)); | |
11535 | } | |
b7484fbe | 11536 | |
8d08fdba | 11537 | if (warn_about_return_type) |
59f1f2c4 | 11538 | pedwarn ("return-type defaults to `int'"); |
8d08fdba | 11539 | |
824b9a4c | 11540 | /* Effective C++ rule 15. See also c_expand_return. */ |
eb448459 | 11541 | if (warn_ecpp |
824b9a4c MS |
11542 | && DECL_NAME (decl1) == ansi_opname[(int) MODIFY_EXPR] |
11543 | && TREE_TYPE (fntype) == void_type_node) | |
11544 | cp_warning ("`operator=' should return a reference to `*this'"); | |
11545 | ||
8d08fdba MS |
11546 | /* Make the init_value nonzero so pushdecl knows this is not tentative. |
11547 | error_mark_node is replaced below (in poplevel) with the BLOCK. */ | |
11548 | DECL_INITIAL (decl1) = error_mark_node; | |
11549 | ||
8d08fdba MS |
11550 | /* This function exists in static storage. |
11551 | (This does not mean `static' in the C sense!) */ | |
11552 | TREE_STATIC (decl1) = 1; | |
11553 | ||
878cd289 MS |
11554 | /* Record the decl so that the function name is defined. |
11555 | If we already have a decl for this name, and it is a FUNCTION_DECL, | |
11556 | use the old decl. */ | |
11557 | ||
5156628f | 11558 | if (processing_template_decl) |
3ac3d9ea | 11559 | decl1 = push_template_decl (decl1); |
5566b478 | 11560 | else if (pre_parsed_p == 0) |
878cd289 | 11561 | { |
75650646 MM |
11562 | /* A specialization is not used to guide overload resolution. */ |
11563 | if (flag_guiding_decls | |
11564 | || !DECL_TEMPLATE_SPECIALIZATION (decl1)) | |
11565 | decl1 = pushdecl (decl1); | |
878cd289 MS |
11566 | DECL_MAIN_VARIANT (decl1) = decl1; |
11567 | fntype = TREE_TYPE (decl1); | |
11568 | } | |
5566b478 MS |
11569 | |
11570 | current_function_decl = decl1; | |
878cd289 | 11571 | |
db5ae43f | 11572 | if (DECL_INTERFACE_KNOWN (decl1)) |
faae18ab | 11573 | { |
86052cc3 JM |
11574 | tree ctx = hack_decl_function_context (decl1); |
11575 | ||
faae18ab MS |
11576 | if (DECL_NOT_REALLY_EXTERN (decl1)) |
11577 | DECL_EXTERNAL (decl1) = 0; | |
86052cc3 JM |
11578 | |
11579 | if (ctx != NULL_TREE && DECL_THIS_INLINE (ctx) | |
11580 | && TREE_PUBLIC (ctx)) | |
11581 | /* This is a function in a local class in an extern inline | |
11582 | function. */ | |
11583 | comdat_linkage (decl1); | |
faae18ab | 11584 | } |
8d08fdba MS |
11585 | /* If this function belongs to an interface, it is public. |
11586 | If it belongs to someone else's interface, it is also external. | |
11587 | It doesn't matter whether it's inline or not. */ | |
5566b478 MS |
11588 | else if (interface_unknown == 0 |
11589 | && (! DECL_TEMPLATE_INSTANTIATION (decl1) | |
d11ad92e | 11590 | || flag_alt_external_templates)) |
8d08fdba | 11591 | { |
5566b478 | 11592 | if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1) |
5156628f | 11593 | || processing_template_decl) |
db5ae43f MS |
11594 | DECL_EXTERNAL (decl1) |
11595 | = (interface_only | |
faae18ab | 11596 | || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines)); |
db5ae43f | 11597 | else |
893de33c | 11598 | DECL_EXTERNAL (decl1) = 0; |
e8abc66f | 11599 | DECL_NOT_REALLY_EXTERN (decl1) = 0; |
db5ae43f | 11600 | DECL_INTERFACE_KNOWN (decl1) = 1; |
8d08fdba MS |
11601 | } |
11602 | else | |
a0a33927 MS |
11603 | { |
11604 | /* This is a definition, not a reference. | |
b7484fbe MS |
11605 | So clear DECL_EXTERNAL. */ |
11606 | DECL_EXTERNAL (decl1) = 0; | |
faae18ab | 11607 | |
5566b478 MS |
11608 | if ((DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)) |
11609 | && ! DECL_INTERFACE_KNOWN (decl1) | |
11610 | /* Don't try to defer nested functions for now. */ | |
e76a2646 | 11611 | && ! hack_decl_function_context (decl1)) |
878cd289 MS |
11612 | DECL_DEFER_OUTPUT (decl1) = 1; |
11613 | else | |
893de33c | 11614 | DECL_INTERFACE_KNOWN (decl1) = 1; |
db5ae43f | 11615 | } |
a9aedbc2 | 11616 | |
8d08fdba MS |
11617 | if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) |
11618 | { | |
11619 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
11620 | TREE_TYPE (decl1) = fntype | |
11621 | = build_function_type (TREE_TYPE (fntype), | |
11622 | TREE_CHAIN (TYPE_ARG_TYPES (fntype))); | |
5566b478 MS |
11623 | current_function_parms = TREE_CHAIN (current_function_parms); |
11624 | DECL_ARGUMENTS (decl1) = current_function_parms; | |
8d08fdba MS |
11625 | ctype = NULL_TREE; |
11626 | } | |
11627 | restype = TREE_TYPE (fntype); | |
11628 | ||
8d08fdba MS |
11629 | if (ctype) |
11630 | { | |
11631 | push_nested_class (ctype, 1); | |
11632 | ||
11633 | /* If we're compiling a friend function, neither of the variables | |
4ac14744 | 11634 | current_class_ptr nor current_class_type will have values. */ |
8d08fdba MS |
11635 | if (! doing_friend) |
11636 | { | |
11637 | /* We know that this was set up by `grokclassfn'. | |
11638 | We do not wait until `store_parm_decls', since evil | |
11639 | parse errors may never get us to that point. Here | |
11640 | we keep the consistency between `current_class_type' | |
4ac14744 | 11641 | and `current_class_ptr'. */ |
5566b478 | 11642 | tree t = current_function_parms; |
5f34005f RK |
11643 | |
11644 | my_friendly_assert (t != NULL_TREE | |
11645 | && TREE_CODE (t) == PARM_DECL, 162); | |
11646 | ||
dff6b454 RK |
11647 | if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE) |
11648 | { | |
11649 | int i = suspend_momentary (); | |
11650 | ||
11651 | /* Fool build_indirect_ref. */ | |
4ac14744 MS |
11652 | current_class_ptr = NULL_TREE; |
11653 | current_class_ref = build_indirect_ref (t, NULL_PTR); | |
11654 | current_class_ptr = t; | |
dff6b454 RK |
11655 | resume_momentary (i); |
11656 | } | |
11657 | else | |
11658 | /* We're having a signature pointer here. */ | |
4ac14744 | 11659 | current_class_ref = current_class_ptr = t; |
dff6b454 | 11660 | |
8d08fdba MS |
11661 | } |
11662 | } | |
11663 | else | |
11664 | { | |
11665 | if (DECL_STATIC_FUNCTION_P (decl1)) | |
11666 | push_nested_class (DECL_CONTEXT (decl1), 2); | |
11667 | else | |
11668 | push_memoized_context (0, 1); | |
4ac14744 | 11669 | current_class_ptr = current_class_ref = NULL_TREE; |
8d08fdba MS |
11670 | } |
11671 | ||
db5ae43f MS |
11672 | pushlevel (0); |
11673 | current_binding_level->parm_flag = 1; | |
11674 | ||
db5ae43f MS |
11675 | GNU_xref_function (decl1, current_function_parms); |
11676 | ||
f30432d7 MS |
11677 | if (attrs) |
11678 | cplus_decl_attributes (decl1, NULL_TREE, attrs); | |
db5ae43f MS |
11679 | make_function_rtl (decl1); |
11680 | ||
8d08fdba MS |
11681 | /* Promote the value to int before returning it. */ |
11682 | if (C_PROMOTING_INTEGER_TYPE_P (restype)) | |
5566b478 MS |
11683 | restype = type_promotes_to (restype); |
11684 | ||
11685 | /* If this fcn was already referenced via a block-scope `extern' decl | |
11686 | (or an implicit decl), propagate certain information about the usage. */ | |
11687 | if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) | |
11688 | TREE_ADDRESSABLE (decl1) = 1; | |
11689 | ||
8d08fdba | 11690 | if (DECL_RESULT (decl1) == NULL_TREE) |
f30432d7 MS |
11691 | { |
11692 | DECL_RESULT (decl1) | |
11693 | = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype)); | |
11694 | TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype); | |
11695 | TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype); | |
11696 | } | |
8d08fdba | 11697 | |
948edfa7 JW |
11698 | /* Allocate further tree nodes temporarily during compilation |
11699 | of this function only. Tiemann moved up here from bottom of fn. */ | |
11700 | /* If this is a nested function, then we must continue to allocate RTL | |
11701 | on the permanent obstack in case we need to inline it later. */ | |
11702 | if (! hack_decl_function_context (decl1)) | |
5566b478 MS |
11703 | temporary_allocation (); |
11704 | ||
5156628f | 11705 | if (processing_template_decl) |
5566b478 | 11706 | { |
5566b478 MS |
11707 | ++minimal_parse_mode; |
11708 | last_tree = DECL_SAVED_TREE (decl1) | |
11709 | = build_nt (EXPR_STMT, void_zero_node); | |
11710 | } | |
11711 | ||
11712 | ++function_depth; | |
11713 | ||
f30432d7 MS |
11714 | if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)) |
11715 | && DECL_LANGUAGE (decl1) == lang_cplusplus) | |
8d08fdba MS |
11716 | { |
11717 | dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
11718 | ctor_label = NULL_TREE; | |
11719 | } | |
11720 | else | |
11721 | { | |
11722 | dtor_label = NULL_TREE; | |
11723 | if (DECL_CONSTRUCTOR_P (decl1)) | |
11724 | ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
11725 | } | |
11726 | ||
8d08fdba MS |
11727 | return 1; |
11728 | } | |
11729 | \f | |
9664b89e JM |
11730 | /* Called after store_parm_decls for a function-try-block. We need to update |
11731 | last_parm_cleanup_insn so that the base initializers for a constructor | |
11732 | are run within this block, not before it. */ | |
6467930b MS |
11733 | |
11734 | void | |
11735 | expand_start_early_try_stmts () | |
11736 | { | |
6467930b | 11737 | expand_start_try_stmts (); |
9664b89e | 11738 | last_parm_cleanup_insn = get_last_insn (); |
f30432d7 MS |
11739 | } |
11740 | ||
8d08fdba MS |
11741 | /* Store the parameter declarations into the current function declaration. |
11742 | This is called after parsing the parameter declarations, before | |
11743 | digesting the body of the function. | |
11744 | ||
11745 | Also install to binding contour return value identifier, if any. */ | |
11746 | ||
11747 | void | |
11748 | store_parm_decls () | |
11749 | { | |
11750 | register tree fndecl = current_function_decl; | |
11751 | register tree parm; | |
11752 | int parms_have_cleanups = 0; | |
eb66be0e | 11753 | tree cleanups = NULL_TREE; |
8d08fdba MS |
11754 | |
11755 | /* This is either a chain of PARM_DECLs (when a prototype is used). */ | |
11756 | tree specparms = current_function_parms; | |
11757 | ||
11758 | /* This is a list of types declared among parms in a prototype. */ | |
11759 | tree parmtags = current_function_parm_tags; | |
11760 | ||
11761 | /* This is a chain of any other decls that came in among the parm | |
11762 | declarations. If a parm is declared with enum {foo, bar} x; | |
11763 | then CONST_DECLs for foo and bar are put here. */ | |
11764 | tree nonparms = NULL_TREE; | |
11765 | ||
a9aedbc2 | 11766 | if (toplevel_bindings_p ()) |
8d08fdba MS |
11767 | fatal ("parse errors have confused me too much"); |
11768 | ||
11769 | /* Initialize RTL machinery. */ | |
11770 | init_function_start (fndecl, input_filename, lineno); | |
11771 | ||
11772 | /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ | |
11773 | declare_function_name (); | |
11774 | ||
11775 | /* Create a binding level for the parms. */ | |
11776 | expand_start_bindings (0); | |
11777 | ||
8d08fdba MS |
11778 | if (specparms != NULL_TREE) |
11779 | { | |
11780 | /* This case is when the function was defined with an ANSI prototype. | |
11781 | The parms already have decls, so we need not do anything here | |
11782 | except record them as in effect | |
11783 | and complain if any redundant old-style parm decls were written. */ | |
11784 | ||
11785 | register tree next; | |
11786 | ||
11787 | /* Must clear this because it might contain TYPE_DECLs declared | |
11788 | at class level. */ | |
11789 | storedecls (NULL_TREE); | |
5566b478 | 11790 | |
8d08fdba MS |
11791 | for (parm = nreverse (specparms); parm; parm = next) |
11792 | { | |
11793 | next = TREE_CHAIN (parm); | |
11794 | if (TREE_CODE (parm) == PARM_DECL) | |
11795 | { | |
5566b478 | 11796 | tree cleanup; |
8d08fdba MS |
11797 | if (DECL_NAME (parm) == NULL_TREE) |
11798 | { | |
8d08fdba | 11799 | pushdecl (parm); |
8d08fdba MS |
11800 | } |
11801 | else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) | |
11802 | cp_error ("parameter `%D' declared void", parm); | |
11803 | else | |
11804 | { | |
11805 | /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls. | |
11806 | A parameter is assumed not to have any side effects. | |
11807 | If this should change for any reason, then this | |
11808 | will have to wrap the bashed reference type in a save_expr. | |
11809 | ||
11810 | Also, if the parameter type is declared to be an X | |
11811 | and there is an X(X&) constructor, we cannot lay it | |
11812 | into the stack (any more), so we make this parameter | |
11813 | look like it is really of reference type. Functions | |
11814 | which pass parameters to this function will know to | |
11815 | create a temporary in their frame, and pass a reference | |
11816 | to that. */ | |
11817 | ||
11818 | if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE | |
11819 | && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm)))) | |
11820 | SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm)); | |
11821 | ||
11822 | pushdecl (parm); | |
11823 | } | |
5156628f | 11824 | if (! processing_template_decl |
5566b478 | 11825 | && (cleanup = maybe_build_cleanup (parm), cleanup)) |
8d08fdba MS |
11826 | { |
11827 | expand_decl (parm); | |
8d08fdba | 11828 | parms_have_cleanups = 1; |
eb66be0e MS |
11829 | |
11830 | /* Keep track of the cleanups. */ | |
11831 | cleanups = tree_cons (parm, cleanup, cleanups); | |
8d08fdba MS |
11832 | } |
11833 | } | |
11834 | else | |
11835 | { | |
11836 | /* If we find an enum constant or a type tag, | |
11837 | put it aside for the moment. */ | |
11838 | TREE_CHAIN (parm) = NULL_TREE; | |
11839 | nonparms = chainon (nonparms, parm); | |
11840 | } | |
11841 | } | |
11842 | ||
11843 | /* Get the decls in their original chain order | |
11844 | and record in the function. This is all and only the | |
11845 | PARM_DECLs that were pushed into scope by the loop above. */ | |
11846 | DECL_ARGUMENTS (fndecl) = getdecls (); | |
11847 | ||
11848 | storetags (chainon (parmtags, gettags ())); | |
11849 | } | |
11850 | else | |
11851 | DECL_ARGUMENTS (fndecl) = NULL_TREE; | |
11852 | ||
11853 | /* Now store the final chain of decls for the arguments | |
11854 | as the decl-chain of the current lexical scope. | |
11855 | Put the enumerators in as well, at the front so that | |
11856 | DECL_ARGUMENTS is not modified. */ | |
11857 | ||
11858 | storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); | |
11859 | ||
11860 | /* Initialize the RTL code for the function. */ | |
11861 | DECL_SAVED_INSNS (fndecl) = NULL_RTX; | |
5156628f | 11862 | if (! processing_template_decl) |
5566b478 | 11863 | expand_function_start (fndecl, parms_have_cleanups); |
8d08fdba | 11864 | |
eb448459 MS |
11865 | current_function_parms_stored = 1; |
11866 | ||
11867 | /* If this function is `main', emit a call to `__main' | |
11868 | to run global initializers, etc. */ | |
11869 | if (DECL_NAME (fndecl) | |
11870 | && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 | |
11871 | && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 | |
11872 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
11873 | { | |
11874 | expand_main_function (); | |
11875 | } | |
11876 | ||
eb66be0e MS |
11877 | /* Now that we have initialized the parms, we can start their |
11878 | cleanups. We cannot do this before, since expand_decl_cleanup | |
11879 | should not be called before the parm can be used. */ | |
eb448459 | 11880 | if (cleanups |
eb66be0e MS |
11881 | && ! processing_template_decl) |
11882 | { | |
11883 | for (cleanups = nreverse (cleanups); cleanups; cleanups = TREE_CHAIN (cleanups)) | |
11884 | { | |
11885 | if (! expand_decl_cleanup (TREE_PURPOSE (cleanups), TREE_VALUE (cleanups))) | |
11886 | cp_error ("parser lost in parsing declaration of `%D'", | |
11887 | TREE_PURPOSE (cleanups)); | |
11888 | } | |
11889 | } | |
11890 | ||
8d08fdba MS |
11891 | /* Create a binding contour which can be used to catch |
11892 | cleanup-generated temporaries. Also, if the return value needs or | |
11893 | has initialization, deal with that now. */ | |
11894 | if (parms_have_cleanups) | |
11895 | { | |
11896 | pushlevel (0); | |
11897 | expand_start_bindings (0); | |
11898 | } | |
11899 | ||
5156628f | 11900 | if (! processing_template_decl && flag_exceptions) |
f30432d7 | 11901 | { |
f30432d7 MS |
11902 | /* Do the starting of the exception specifications, if we have any. */ |
11903 | if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) | |
11904 | expand_start_eh_spec (); | |
f30432d7 | 11905 | } |
eb448459 | 11906 | |
5c825fc2 | 11907 | last_parm_cleanup_insn = get_last_insn (); |
72b7eeff | 11908 | last_dtor_insn = get_last_insn (); |
8d08fdba MS |
11909 | } |
11910 | ||
11911 | /* Bind a name and initialization to the return value of | |
11912 | the current function. */ | |
e92cc029 | 11913 | |
8d08fdba MS |
11914 | void |
11915 | store_return_init (return_id, init) | |
11916 | tree return_id, init; | |
11917 | { | |
11918 | tree decl = DECL_RESULT (current_function_decl); | |
11919 | ||
e1cd6e56 | 11920 | if (pedantic) |
8d08fdba MS |
11921 | /* Give this error as many times as there are occurrences, |
11922 | so that users can use Emacs compilation buffers to find | |
11923 | and fix all such places. */ | |
8926095f | 11924 | pedwarn ("ANSI C++ does not permit named return values"); |
8d08fdba MS |
11925 | |
11926 | if (return_id != NULL_TREE) | |
11927 | { | |
11928 | if (DECL_NAME (decl) == NULL_TREE) | |
11929 | { | |
11930 | DECL_NAME (decl) = return_id; | |
11931 | DECL_ASSEMBLER_NAME (decl) = return_id; | |
11932 | } | |
11933 | else | |
e76a2646 | 11934 | cp_error ("return identifier `%D' already in place", decl); |
8d08fdba MS |
11935 | } |
11936 | ||
11937 | /* Can't let this happen for constructors. */ | |
11938 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
11939 | { | |
11940 | error ("can't redefine default return value for constructors"); | |
11941 | return; | |
11942 | } | |
11943 | ||
11944 | /* If we have a named return value, put that in our scope as well. */ | |
11945 | if (DECL_NAME (decl) != NULL_TREE) | |
11946 | { | |
11947 | /* If this named return value comes in a register, | |
11948 | put it in a pseudo-register. */ | |
11949 | if (DECL_REGISTER (decl)) | |
11950 | { | |
11951 | original_result_rtx = DECL_RTL (decl); | |
11952 | DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); | |
11953 | } | |
11954 | ||
82580166 | 11955 | /* Let `cp_finish_decl' know that this initializer is ok. */ |
8d08fdba MS |
11956 | DECL_INITIAL (decl) = init; |
11957 | pushdecl (decl); | |
e76a2646 MS |
11958 | |
11959 | if (minimal_parse_mode) | |
11960 | add_tree (build_min_nt (RETURN_INIT, return_id, | |
11961 | copy_to_permanent (init))); | |
11962 | else | |
dae1d6f6 | 11963 | cp_finish_decl (decl, init, NULL_TREE, 0, 0); |
8d08fdba MS |
11964 | } |
11965 | } | |
11966 | ||
8d08fdba MS |
11967 | \f |
11968 | /* Finish up a function declaration and compile that function | |
11969 | all the way to assembler language output. The free the storage | |
11970 | for the function definition. | |
11971 | ||
11972 | This is called after parsing the body of the function definition. | |
11973 | LINENO is the current line number. | |
11974 | ||
11975 | C++: CALL_POPLEVEL is non-zero if an extra call to poplevel | |
11976 | (and expand_end_bindings) must be made to take care of the binding | |
11977 | contour for the base initializers. This is only relevant for | |
e92cc029 MS |
11978 | constructors. |
11979 | ||
11980 | NESTED is nonzero if we were in the middle of compiling another function | |
11981 | when we started on this one. */ | |
8d08fdba MS |
11982 | |
11983 | void | |
db5ae43f | 11984 | finish_function (lineno, call_poplevel, nested) |
8d08fdba MS |
11985 | int lineno; |
11986 | int call_poplevel; | |
db5ae43f | 11987 | int nested; |
8d08fdba MS |
11988 | { |
11989 | register tree fndecl = current_function_decl; | |
11990 | tree fntype, ctype = NULL_TREE; | |
f30432d7 | 11991 | rtx last_parm_insn, insns; |
8d08fdba MS |
11992 | /* Label to use if this function is supposed to return a value. */ |
11993 | tree no_return_label = NULL_TREE; | |
11994 | tree decls = NULL_TREE; | |
11995 | ||
11996 | /* When we get some parse errors, we can end up without a | |
11997 | current_function_decl, so cope. */ | |
11998 | if (fndecl == NULL_TREE) | |
11999 | return; | |
12000 | ||
e92cc029 MS |
12001 | if (! nested && function_depth > 1) |
12002 | nested = 1; | |
12003 | ||
8d08fdba MS |
12004 | fntype = TREE_TYPE (fndecl); |
12005 | ||
12006 | /* TREE_READONLY (fndecl) = 1; | |
12007 | This caused &foo to be of type ptr-to-const-function | |
12008 | which then got a warning when stored in a ptr-to-function variable. */ | |
12009 | ||
12010 | /* This happens on strange parse errors. */ | |
12011 | if (! current_function_parms_stored) | |
12012 | { | |
12013 | call_poplevel = 0; | |
12014 | store_parm_decls (); | |
12015 | } | |
12016 | ||
5156628f | 12017 | if (processing_template_decl) |
8d08fdba | 12018 | { |
5566b478 MS |
12019 | if (DECL_CONSTRUCTOR_P (fndecl) && call_poplevel) |
12020 | { | |
12021 | decls = getdecls (); | |
12022 | expand_end_bindings (decls, decls != NULL_TREE, 0); | |
12023 | poplevel (decls != NULL_TREE, 0, 0); | |
12024 | } | |
12025 | } | |
12026 | else | |
12027 | { | |
12028 | if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/) | |
8d08fdba | 12029 | { |
5566b478 MS |
12030 | tree ttype = target_type (fntype); |
12031 | tree parmdecl; | |
12032 | ||
8d08fdba MS |
12033 | if (IS_AGGR_TYPE (ttype)) |
12034 | /* Let debugger know it should output info for this type. */ | |
12035 | note_debug_info_needed (ttype); | |
5566b478 MS |
12036 | |
12037 | for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) | |
12038 | { | |
12039 | ttype = target_type (TREE_TYPE (parmdecl)); | |
12040 | if (IS_AGGR_TYPE (ttype)) | |
12041 | /* Let debugger know it should output info for this type. */ | |
12042 | note_debug_info_needed (ttype); | |
12043 | } | |
8d08fdba | 12044 | } |
8d08fdba | 12045 | |
5566b478 MS |
12046 | /* Clean house because we will need to reorder insns here. */ |
12047 | do_pending_stack_adjust (); | |
8d08fdba | 12048 | |
5566b478 | 12049 | if (dtor_label) |
8d08fdba | 12050 | { |
5566b478 MS |
12051 | tree binfo = TYPE_BINFO (current_class_type); |
12052 | tree cond = integer_one_node; | |
12053 | tree exprstmt; | |
12054 | tree in_charge_node = lookup_name (in_charge_identifier, 0); | |
12055 | tree virtual_size; | |
12056 | int ok_to_optimize_dtor = 0; | |
12057 | int empty_dtor = get_last_insn () == last_dtor_insn; | |
8d08fdba | 12058 | |
5566b478 MS |
12059 | if (current_function_assigns_this) |
12060 | cond = build (NE_EXPR, boolean_type_node, | |
4ac14744 | 12061 | current_class_ptr, integer_zero_node); |
5566b478 MS |
12062 | else |
12063 | { | |
12064 | int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); | |
12065 | ||
12066 | /* If this destructor is empty, then we don't need to check | |
12067 | whether `this' is NULL in some cases. */ | |
12068 | if ((flag_this_is_variable & 1) == 0) | |
12069 | ok_to_optimize_dtor = 1; | |
12070 | else if (empty_dtor) | |
12071 | ok_to_optimize_dtor | |
12072 | = (n_baseclasses == 0 | |
12073 | || (n_baseclasses == 1 | |
12074 | && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); | |
12075 | } | |
8d08fdba | 12076 | |
5566b478 MS |
12077 | /* These initializations might go inline. Protect |
12078 | the binding level of the parms. */ | |
12079 | pushlevel (0); | |
12080 | expand_start_bindings (0); | |
8d08fdba | 12081 | |
5566b478 MS |
12082 | if (current_function_assigns_this) |
12083 | { | |
12084 | current_function_assigns_this = 0; | |
12085 | current_function_just_assigned_this = 0; | |
12086 | } | |
8d08fdba | 12087 | |
5566b478 MS |
12088 | /* Generate the code to call destructor on base class. |
12089 | If this destructor belongs to a class with virtual | |
12090 | functions, then set the virtual function table | |
12091 | pointer to represent the type of our base class. */ | |
8d08fdba | 12092 | |
5566b478 MS |
12093 | /* This side-effect makes call to `build_delete' generate the |
12094 | code we have to have at the end of this destructor. */ | |
12095 | TYPE_HAS_DESTRUCTOR (current_class_type) = 0; | |
8d08fdba | 12096 | |
5566b478 MS |
12097 | /* These are two cases where we cannot delegate deletion. */ |
12098 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) | |
12099 | || TYPE_GETS_REG_DELETE (current_class_type)) | |
4ac14744 | 12100 | exprstmt = build_delete (current_class_type, current_class_ref, integer_zero_node, |
e92cc029 | 12101 | LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); |
5566b478 | 12102 | else |
4ac14744 | 12103 | exprstmt = build_delete (current_class_type, current_class_ref, in_charge_node, |
e92cc029 | 12104 | LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); |
5566b478 MS |
12105 | |
12106 | /* If we did not assign to this, then `this' is non-zero at | |
12107 | the end of a destructor. As a special optimization, don't | |
12108 | emit test if this is an empty destructor. If it does nothing, | |
12109 | it does nothing. If it calls a base destructor, the base | |
12110 | destructor will perform the test. */ | |
12111 | ||
12112 | if (exprstmt != error_mark_node | |
12113 | && (TREE_CODE (exprstmt) != NOP_EXPR | |
12114 | || TREE_OPERAND (exprstmt, 0) != integer_zero_node | |
12115 | || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) | |
8d08fdba | 12116 | { |
5566b478 MS |
12117 | expand_label (dtor_label); |
12118 | if (cond != integer_one_node) | |
12119 | expand_start_cond (cond, 0); | |
12120 | if (exprstmt != void_zero_node) | |
12121 | /* Don't call `expand_expr_stmt' if we're not going to do | |
12122 | anything, since -Wall will give a diagnostic. */ | |
12123 | expand_expr_stmt (exprstmt); | |
12124 | ||
12125 | /* Run destructor on all virtual baseclasses. */ | |
12126 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) | |
8d08fdba | 12127 | { |
5566b478 MS |
12128 | tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); |
12129 | expand_start_cond (build (BIT_AND_EXPR, integer_type_node, | |
12130 | in_charge_node, integer_two_node), 0); | |
12131 | while (vbases) | |
8d08fdba | 12132 | { |
5566b478 MS |
12133 | if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) |
12134 | { | |
bd6dd845 MS |
12135 | tree vb = get_vbase |
12136 | (BINFO_TYPE (vbases), | |
12137 | TYPE_BINFO (current_class_type)); | |
e92cc029 | 12138 | expand_expr_stmt |
bd6dd845 MS |
12139 | (build_scoped_method_call |
12140 | (current_class_ref, vb, dtor_identifier, | |
e66d884e | 12141 | build_expr_list (NULL_TREE, integer_zero_node))); |
5566b478 MS |
12142 | } |
12143 | vbases = TREE_CHAIN (vbases); | |
8d08fdba | 12144 | } |
5566b478 | 12145 | expand_end_cond (); |
8d08fdba | 12146 | } |
5566b478 MS |
12147 | |
12148 | do_pending_stack_adjust (); | |
12149 | if (cond != integer_one_node) | |
12150 | expand_end_cond (); | |
8d08fdba MS |
12151 | } |
12152 | ||
5566b478 MS |
12153 | TYPE_HAS_DESTRUCTOR (current_class_type) = 1; |
12154 | ||
12155 | virtual_size = c_sizeof (current_class_type); | |
12156 | ||
12157 | /* At the end, call delete if that's what's requested. */ | |
12158 | if (TYPE_GETS_REG_DELETE (current_class_type)) | |
12159 | /* This NOP_EXPR means we are in a static call context. */ | |
beb53fb8 JM |
12160 | exprstmt |
12161 | = build_method_call (build_indirect_ref (build1 (NOP_EXPR, | |
12162 | build_pointer_type (current_class_type), | |
12163 | error_mark_node), | |
12164 | NULL_PTR), | |
12165 | ansi_opname[(int) DELETE_EXPR], | |
e66d884e JM |
12166 | expr_tree_cons (NULL_TREE, current_class_ptr, |
12167 | build_expr_list (NULL_TREE, virtual_size)), | |
beb53fb8 | 12168 | NULL_TREE, LOOKUP_NORMAL); |
5566b478 | 12169 | else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) |
4ac14744 | 12170 | exprstmt = build_x_delete (ptr_type_node, current_class_ptr, 0, |
5566b478 MS |
12171 | virtual_size); |
12172 | else | |
12173 | exprstmt = NULL_TREE; | |
8d08fdba | 12174 | |
5566b478 MS |
12175 | if (exprstmt) |
12176 | { | |
12177 | cond = build (BIT_AND_EXPR, integer_type_node, | |
12178 | in_charge_node, integer_one_node); | |
12179 | expand_start_cond (cond, 0); | |
12180 | expand_expr_stmt (exprstmt); | |
12181 | expand_end_cond (); | |
12182 | } | |
8d08fdba | 12183 | |
5566b478 | 12184 | /* End of destructor. */ |
fc378698 | 12185 | expand_end_bindings (NULL_TREE, getdecls () != NULL_TREE, 0); |
5566b478 MS |
12186 | poplevel (2, 0, 0); /* XXX change to 1 */ |
12187 | ||
12188 | /* Back to the top of destructor. */ | |
956d6950 | 12189 | /* Don't execute destructor code if `this' is NULL. */ |
5566b478 MS |
12190 | |
12191 | start_sequence (); | |
12192 | ||
12193 | /* If the dtor is empty, and we know there is not possible way we | |
12194 | could use any vtable entries, before they are possibly set by | |
12195 | a base class dtor, we don't have to setup the vtables, as we | |
12196 | know that any base class dtoring will set up any vtables it | |
12197 | needs. We avoid MI, because one base class dtor can do a | |
12198 | virtual dispatch to an overridden function that would need to | |
12199 | have a non-related vtable set up, we cannot avoid setting up | |
12200 | vtables in that case. We could change this to see if there is | |
12201 | just one vtable. */ | |
12202 | if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type)) | |
12203 | { | |
12204 | /* Make all virtual function table pointers in non-virtual base | |
12205 | classes point to CURRENT_CLASS_TYPE's virtual function | |
12206 | tables. */ | |
4ac14744 | 12207 | expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr); |
8d08fdba | 12208 | |
5566b478 | 12209 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) |
4ac14744 | 12210 | expand_indirect_vtbls_init (binfo, current_class_ref, current_class_ptr); |
5566b478 MS |
12211 | } |
12212 | ||
12213 | if (! ok_to_optimize_dtor) | |
12214 | { | |
12215 | cond = build_binary_op (NE_EXPR, | |
4ac14744 | 12216 | current_class_ptr, integer_zero_node, 1); |
5566b478 MS |
12217 | expand_start_cond (cond, 0); |
12218 | } | |
8d08fdba | 12219 | |
5566b478 MS |
12220 | insns = get_insns (); |
12221 | end_sequence (); | |
f30432d7 | 12222 | |
5566b478 MS |
12223 | last_parm_insn = get_first_nonparm_insn (); |
12224 | if (last_parm_insn == NULL_RTX) | |
12225 | last_parm_insn = get_last_insn (); | |
12226 | else | |
12227 | last_parm_insn = previous_insn (last_parm_insn); | |
8d08fdba | 12228 | |
5566b478 | 12229 | emit_insns_after (insns, last_parm_insn); |
72b7eeff | 12230 | |
5566b478 MS |
12231 | if (! ok_to_optimize_dtor) |
12232 | expand_end_cond (); | |
72b7eeff | 12233 | } |
5566b478 | 12234 | else if (current_function_assigns_this) |
8d08fdba | 12235 | { |
5566b478 MS |
12236 | /* Does not need to call emit_base_init, because |
12237 | that is done (if needed) just after assignment to this | |
12238 | is seen. */ | |
12239 | ||
12240 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
12241 | { | |
12242 | end_protect_partials (); | |
12243 | expand_label (ctor_label); | |
12244 | ctor_label = NULL_TREE; | |
12245 | ||
12246 | if (call_poplevel) | |
12247 | { | |
12248 | decls = getdecls (); | |
12249 | expand_end_bindings (decls, decls != NULL_TREE, 0); | |
12250 | poplevel (decls != NULL_TREE, 0, 0); | |
12251 | } | |
4ac14744 | 12252 | c_expand_return (current_class_ptr); |
5566b478 MS |
12253 | } |
12254 | else if (TYPE_MAIN_VARIANT (TREE_TYPE ( | |
12255 | DECL_RESULT (current_function_decl))) != void_type_node | |
12256 | && return_label != NULL_RTX) | |
12257 | no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
12258 | ||
12259 | current_function_assigns_this = 0; | |
12260 | current_function_just_assigned_this = 0; | |
12261 | base_init_expr = NULL_TREE; | |
8d08fdba | 12262 | } |
5566b478 MS |
12263 | else if (DECL_CONSTRUCTOR_P (fndecl)) |
12264 | { | |
a703fb38 | 12265 | tree cond = NULL_TREE, thenclause = NULL_TREE; |
5566b478 MS |
12266 | /* Allow constructor for a type to get a new instance of the object |
12267 | using `build_new'. */ | |
12268 | tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); | |
12269 | CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; | |
f30432d7 | 12270 | |
5566b478 | 12271 | DECL_RETURNS_FIRST_ARG (fndecl) = 1; |
f30432d7 | 12272 | |
5566b478 MS |
12273 | if (flag_this_is_variable > 0) |
12274 | { | |
12275 | cond = build_binary_op (EQ_EXPR, | |
4ac14744 MS |
12276 | current_class_ptr, integer_zero_node, 1); |
12277 | thenclause = build_modify_expr (current_class_ptr, NOP_EXPR, | |
5566b478 MS |
12278 | build_new (NULL_TREE, current_class_type, void_type_node, 0)); |
12279 | } | |
f30432d7 | 12280 | |
5566b478 | 12281 | CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; |
f30432d7 | 12282 | |
5566b478 MS |
12283 | start_sequence (); |
12284 | ||
12285 | if (flag_this_is_variable > 0) | |
12286 | { | |
12287 | expand_start_cond (cond, 0); | |
12288 | expand_expr_stmt (thenclause); | |
12289 | expand_end_cond (); | |
12290 | } | |
12291 | ||
12292 | /* Emit insns from `emit_base_init' which sets up virtual | |
12293 | function table pointer(s). */ | |
12294 | if (base_init_expr) | |
12295 | { | |
12296 | expand_expr_stmt (base_init_expr); | |
12297 | base_init_expr = NULL_TREE; | |
12298 | } | |
12299 | ||
12300 | insns = get_insns (); | |
12301 | end_sequence (); | |
12302 | ||
b87692e5 | 12303 | /* This is where the body of the constructor begins. */ |
5566b478 | 12304 | |
b87692e5 | 12305 | emit_insns_after (insns, last_parm_cleanup_insn); |
8d08fdba | 12306 | |
b7484fbe | 12307 | end_protect_partials (); |
5566b478 MS |
12308 | |
12309 | /* This is where the body of the constructor ends. */ | |
8d08fdba MS |
12310 | expand_label (ctor_label); |
12311 | ctor_label = NULL_TREE; | |
12312 | ||
12313 | if (call_poplevel) | |
12314 | { | |
12315 | decls = getdecls (); | |
8d08fdba | 12316 | expand_end_bindings (decls, decls != NULL_TREE, 0); |
5566b478 | 12317 | poplevel (decls != NULL_TREE, 1, 0); |
8d08fdba | 12318 | } |
8d08fdba | 12319 | |
4ac14744 | 12320 | c_expand_return (current_class_ptr); |
8d08fdba | 12321 | |
5566b478 MS |
12322 | current_function_assigns_this = 0; |
12323 | current_function_just_assigned_this = 0; | |
12324 | } | |
12325 | else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 | |
12326 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") | |
12327 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
8d08fdba | 12328 | { |
5566b478 MS |
12329 | /* Make it so that `main' always returns 0 by default. */ |
12330 | #ifdef VMS | |
12331 | c_expand_return (integer_one_node); | |
12332 | #else | |
12333 | c_expand_return (integer_zero_node); | |
12334 | #endif | |
8d08fdba | 12335 | } |
5566b478 MS |
12336 | else if (return_label != NULL_RTX |
12337 | && current_function_return_value == NULL_TREE | |
12338 | && ! DECL_NAME (DECL_RESULT (current_function_decl))) | |
12339 | no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
8d08fdba | 12340 | |
eb448459 MS |
12341 | if (flag_exceptions) |
12342 | expand_exception_blocks (); | |
12343 | ||
5566b478 MS |
12344 | /* If this function is supposed to return a value, ensure that |
12345 | we do not fall into the cleanups by mistake. The end of our | |
12346 | function will look like this: | |
12347 | ||
12348 | user code (may have return stmt somewhere) | |
12349 | goto no_return_label | |
12350 | cleanup_label: | |
12351 | cleanups | |
12352 | goto return_label | |
12353 | no_return_label: | |
12354 | NOTE_INSN_FUNCTION_END | |
12355 | return_label: | |
12356 | things for return | |
12357 | ||
12358 | If the user omits a return stmt in the USER CODE section, we | |
12359 | will have a control path which reaches NOTE_INSN_FUNCTION_END. | |
12360 | Otherwise, we won't. */ | |
12361 | if (no_return_label) | |
8d08fdba | 12362 | { |
5566b478 MS |
12363 | DECL_CONTEXT (no_return_label) = fndecl; |
12364 | DECL_INITIAL (no_return_label) = error_mark_node; | |
12365 | DECL_SOURCE_FILE (no_return_label) = input_filename; | |
12366 | DECL_SOURCE_LINE (no_return_label) = lineno; | |
12367 | expand_goto (no_return_label); | |
8d08fdba MS |
12368 | } |
12369 | ||
5566b478 | 12370 | if (cleanup_label) |
a9aedbc2 | 12371 | { |
5566b478 MS |
12372 | /* remove the binding contour which is used |
12373 | to catch cleanup-generated temporaries. */ | |
12374 | expand_end_bindings (0, 0, 0); | |
12375 | poplevel (0, 0, 0); | |
8d08fdba | 12376 | |
eb448459 MS |
12377 | /* Emit label at beginning of cleanup code for parameters. */ |
12378 | emit_label (cleanup_label); | |
12379 | } | |
b7484fbe | 12380 | |
5566b478 MS |
12381 | /* Get return value into register if that's where it's supposed to be. */ |
12382 | if (original_result_rtx) | |
12383 | fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); | |
8d08fdba | 12384 | |
5566b478 MS |
12385 | /* Finish building code that will trigger warnings if users forget |
12386 | to make their functions return values. */ | |
12387 | if (no_return_label || cleanup_label) | |
12388 | emit_jump (return_label); | |
12389 | if (no_return_label) | |
8d08fdba | 12390 | { |
5566b478 MS |
12391 | /* We don't need to call `expand_*_return' here because we |
12392 | don't need any cleanups here--this path of code is only | |
12393 | for error checking purposes. */ | |
12394 | expand_label (no_return_label); | |
8d08fdba MS |
12395 | } |
12396 | ||
5566b478 MS |
12397 | /* Generate rtl for function exit. */ |
12398 | expand_function_end (input_filename, lineno, 1); | |
8d08fdba | 12399 | } |
8d2733ca | 12400 | |
8d08fdba MS |
12401 | /* This must come after expand_function_end because cleanups might |
12402 | have declarations (from inline functions) that need to go into | |
12403 | this function's blocks. */ | |
12404 | if (current_binding_level->parm_flag != 1) | |
12405 | my_friendly_abort (122); | |
12406 | poplevel (1, 0, 1); | |
12407 | ||
db5ae43f MS |
12408 | /* reset scope for C++: if we were in the scope of a class, |
12409 | then when we finish this function, we are not longer so. | |
12410 | This cannot be done until we know for sure that no more | |
12411 | class members will ever be referenced in this function | |
12412 | (i.e., calls to destructors). */ | |
12413 | if (current_class_name) | |
12414 | { | |
12415 | ctype = current_class_type; | |
12416 | pop_nested_class (1); | |
12417 | } | |
12418 | else | |
12419 | pop_memoized_context (1); | |
12420 | ||
8d08fdba | 12421 | /* Must mark the RESULT_DECL as being in this function. */ |
c73964b2 | 12422 | DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; |
8d08fdba | 12423 | |
8d08fdba MS |
12424 | /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point |
12425 | to the FUNCTION_DECL node itself. */ | |
12426 | BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; | |
12427 | ||
5156628f | 12428 | if (! processing_template_decl) |
5566b478 | 12429 | { |
75650646 MM |
12430 | int saved_flag_keep_inline_functions = |
12431 | flag_keep_inline_functions; | |
12432 | ||
5566b478 MS |
12433 | /* So we can tell if jump_optimize sets it to 1. */ |
12434 | can_reach_end = 0; | |
8d08fdba | 12435 | |
75650646 | 12436 | if (DECL_CONTEXT (fndecl) != NULL_TREE |
e1467ff2 | 12437 | && hack_decl_function_context (fndecl)) |
75650646 MM |
12438 | /* Trick rest_of_compilation into not deferring output of this |
12439 | function, even if it is inline, since the rtl_obstack for | |
12440 | this function is the function_obstack of the enclosing | |
12441 | function and will be deallocated when the enclosing | |
12442 | function is gone. See save_tree_status. */ | |
12443 | flag_keep_inline_functions = 1; | |
12444 | ||
6633d636 MS |
12445 | /* Run the optimizers and output the assembler code for this |
12446 | function. */ | |
12447 | ||
12448 | if (DECL_ARTIFICIAL (fndecl)) | |
12449 | { | |
12450 | /* Do we really *want* to inline this synthesized method? */ | |
12451 | ||
12452 | int save_fif = flag_inline_functions; | |
12453 | flag_inline_functions = 1; | |
12454 | ||
12455 | /* Turn off DECL_INLINE for the moment so function_cannot_inline_p | |
12456 | will check our size. */ | |
12457 | DECL_INLINE (fndecl) = 0; | |
12458 | ||
12459 | rest_of_compilation (fndecl); | |
12460 | flag_inline_functions = save_fif; | |
12461 | } | |
12462 | else | |
12463 | rest_of_compilation (fndecl); | |
8d08fdba | 12464 | |
75650646 MM |
12465 | flag_keep_inline_functions = saved_flag_keep_inline_functions; |
12466 | ||
5566b478 MS |
12467 | if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl)) |
12468 | { | |
12469 | /* Set DECL_EXTERNAL so that assemble_external will be called as | |
12470 | necessary. We'll clear it again in finish_file. */ | |
12471 | if (! DECL_EXTERNAL (fndecl)) | |
12472 | DECL_NOT_REALLY_EXTERN (fndecl) = 1; | |
12473 | DECL_EXTERNAL (fndecl) = 1; | |
12474 | mark_inline_for_output (fndecl); | |
12475 | } | |
8926095f | 12476 | |
d2e5ee5c MS |
12477 | if (ctype && TREE_ASM_WRITTEN (fndecl)) |
12478 | note_debug_info_needed (ctype); | |
12479 | ||
5566b478 | 12480 | current_function_returns_null |= can_reach_end; |
8d08fdba | 12481 | |
5566b478 MS |
12482 | /* Since we don't normally go through c_expand_return for constructors, |
12483 | this normally gets the wrong value. | |
12484 | Also, named return values have their return codes emitted after | |
12485 | NOTE_INSN_FUNCTION_END, confusing jump.c. */ | |
12486 | if (DECL_CONSTRUCTOR_P (fndecl) | |
12487 | || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) | |
12488 | current_function_returns_null = 0; | |
8d08fdba | 12489 | |
5566b478 MS |
12490 | if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) |
12491 | cp_warning ("`noreturn' function `%D' does return", fndecl); | |
12492 | else if ((warn_return_type || pedantic) | |
12493 | && current_function_returns_null | |
12494 | && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node) | |
12495 | { | |
12496 | /* If this function returns non-void and control can drop through, | |
12497 | complain. */ | |
14e403d4 | 12498 | cp_warning ("control reaches end of non-void function `%D'", fndecl); |
5566b478 MS |
12499 | } |
12500 | /* With just -W, complain only if function returns both with | |
12501 | and without a value. */ | |
12502 | else if (extra_warnings | |
12503 | && current_function_returns_value && current_function_returns_null) | |
12504 | warning ("this function may return with or without a value"); | |
8d08fdba | 12505 | } |
5566b478 MS |
12506 | |
12507 | --function_depth; | |
8d08fdba MS |
12508 | |
12509 | /* Free all the tree nodes making up this function. */ | |
12510 | /* Switch back to allocating nodes permanently | |
12511 | until we start another function. */ | |
5156628f | 12512 | if (processing_template_decl) |
5566b478 MS |
12513 | { |
12514 | --minimal_parse_mode; | |
12515 | DECL_SAVED_TREE (fndecl) = TREE_CHAIN (DECL_SAVED_TREE (fndecl)); | |
12516 | } | |
12517 | ||
db5ae43f MS |
12518 | if (! nested) |
12519 | permanent_allocation (1); | |
8d08fdba | 12520 | |
8d08fdba MS |
12521 | if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) |
12522 | { | |
d2e5ee5c MS |
12523 | tree t; |
12524 | ||
8d08fdba MS |
12525 | /* Stop pointing to the local nodes about to be freed. */ |
12526 | /* But DECL_INITIAL must remain nonzero so we know this | |
12527 | was an actual function definition. */ | |
12528 | DECL_INITIAL (fndecl) = error_mark_node; | |
d2e5ee5c | 12529 | for (t = DECL_ARGUMENTS (fndecl); t; t = TREE_CHAIN (t)) |
de22184b | 12530 | DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX; |
8d08fdba MS |
12531 | } |
12532 | ||
e1cd6e56 MS |
12533 | if (DECL_STATIC_CONSTRUCTOR (fndecl)) |
12534 | static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors); | |
12535 | if (DECL_STATIC_DESTRUCTOR (fndecl)) | |
12536 | static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors); | |
12537 | ||
28cbf42c MS |
12538 | if (! nested) |
12539 | { | |
12540 | /* Let the error reporting routines know that we're outside a | |
12541 | function. For a nested function, this value is used in | |
12542 | pop_cp_function_context and then reset via pop_function_context. */ | |
12543 | current_function_decl = NULL_TREE; | |
12544 | } | |
12545 | ||
e349ee73 | 12546 | named_label_uses = NULL; |
4ac14744 MS |
12547 | current_class_ptr = NULL_TREE; |
12548 | current_class_ref = NULL_TREE; | |
8d08fdba MS |
12549 | } |
12550 | \f | |
12551 | /* Create the FUNCTION_DECL for a function definition. | |
12552 | LINE1 is the line number that the definition absolutely begins on. | |
12553 | LINE2 is the line number that the name of the function appears on. | |
12554 | DECLSPECS and DECLARATOR are the parts of the declaration; | |
12555 | they describe the return type and the name of the function, | |
12556 | but twisted together in a fashion that parallels the syntax of C. | |
12557 | ||
12558 | This function creates a binding context for the function body | |
12559 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
12560 | ||
12561 | Returns a FUNCTION_DECL on success. | |
12562 | ||
12563 | If the DECLARATOR is not suitable for a function (it defines a datum | |
12564 | instead), we return 0, which tells yyparse to report a parse error. | |
12565 | ||
12566 | May return void_type_node indicating that this method is actually | |
12567 | a friend. See grokfield for more details. | |
12568 | ||
12569 | Came here with a `.pushlevel' . | |
12570 | ||
12571 | DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING | |
12572 | CHANGES TO CODE IN `grokfield'. */ | |
e92cc029 | 12573 | |
8d08fdba | 12574 | tree |
c11b6f21 MS |
12575 | start_method (declspecs, declarator) |
12576 | tree declarator, declspecs; | |
8d08fdba | 12577 | { |
c11b6f21 | 12578 | tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, |
f30432d7 | 12579 | NULL_TREE); |
8d08fdba MS |
12580 | |
12581 | /* Something too ugly to handle. */ | |
12582 | if (fndecl == NULL_TREE) | |
12583 | return NULL_TREE; | |
12584 | ||
12585 | /* Pass friends other than inline friend functions back. */ | |
12586 | if (TYPE_MAIN_VARIANT (fndecl) == void_type_node) | |
12587 | return fndecl; | |
12588 | ||
12589 | if (TREE_CODE (fndecl) != FUNCTION_DECL) | |
12590 | /* Not a function, tell parser to report parse error. */ | |
12591 | return NULL_TREE; | |
12592 | ||
12593 | if (IS_SIGNATURE (current_class_type)) | |
824b9a4c | 12594 | IS_DEFAULT_IMPLEMENTATION (fndecl) = 1; |
8d08fdba MS |
12595 | |
12596 | if (DECL_IN_AGGR_P (fndecl)) | |
12597 | { | |
12598 | if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) | |
12599 | { | |
12600 | if (DECL_CONTEXT (fndecl)) | |
12601 | cp_error ("`%D' is already defined in class %s", fndecl, | |
12602 | TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); | |
12603 | } | |
12604 | return void_type_node; | |
12605 | } | |
12606 | ||
faae18ab MS |
12607 | DECL_THIS_INLINE (fndecl) = 1; |
12608 | ||
8926095f | 12609 | if (flag_default_inline) |
8d08fdba MS |
12610 | DECL_INLINE (fndecl) = 1; |
12611 | ||
75650646 | 12612 | if (processing_template_decl) |
3ac3d9ea | 12613 | fndecl = push_template_decl (fndecl); |
a0a33927 | 12614 | |
8d08fdba MS |
12615 | /* We read in the parameters on the maybepermanent_obstack, |
12616 | but we won't be getting back to them until after we | |
12617 | may have clobbered them. So the call to preserve_data | |
12618 | will keep them safe. */ | |
12619 | preserve_data (); | |
12620 | ||
12621 | if (! DECL_FRIEND_P (fndecl)) | |
12622 | { | |
12623 | if (DECL_CHAIN (fndecl) != NULL_TREE) | |
12624 | { | |
12625 | /* Need a fresh node here so that we don't get circularity | |
12626 | when we link these together. If FNDECL was a friend, then | |
12627 | `pushdecl' does the right thing, which is nothing wrt its | |
12628 | current value of DECL_CHAIN. */ | |
12629 | fndecl = copy_node (fndecl); | |
12630 | } | |
12631 | if (TREE_CHAIN (fndecl)) | |
12632 | { | |
12633 | fndecl = copy_node (fndecl); | |
12634 | TREE_CHAIN (fndecl) = NULL_TREE; | |
12635 | } | |
12636 | ||
12637 | if (DECL_CONSTRUCTOR_P (fndecl)) | |
a0a33927 MS |
12638 | { |
12639 | if (! grok_ctor_properties (current_class_type, fndecl)) | |
12640 | return void_type_node; | |
12641 | } | |
8d08fdba MS |
12642 | else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) |
12643 | grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0); | |
12644 | } | |
12645 | ||
82580166 | 12646 | cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0); |
8d08fdba MS |
12647 | |
12648 | /* Make a place for the parms */ | |
12649 | pushlevel (0); | |
12650 | current_binding_level->parm_flag = 1; | |
12651 | ||
12652 | DECL_IN_AGGR_P (fndecl) = 1; | |
12653 | return fndecl; | |
12654 | } | |
12655 | ||
12656 | /* Go through the motions of finishing a function definition. | |
12657 | We don't compile this method until after the whole class has | |
12658 | been processed. | |
12659 | ||
12660 | FINISH_METHOD must return something that looks as though it | |
12661 | came from GROKFIELD (since we are defining a method, after all). | |
12662 | ||
12663 | This is called after parsing the body of the function definition. | |
12664 | STMTS is the chain of statements that makes up the function body. | |
12665 | ||
12666 | DECL is the ..._DECL that `start_method' provided. */ | |
12667 | ||
12668 | tree | |
12669 | finish_method (decl) | |
12670 | tree decl; | |
12671 | { | |
12672 | register tree fndecl = decl; | |
12673 | tree old_initial; | |
8d08fdba MS |
12674 | |
12675 | register tree link; | |
12676 | ||
12677 | if (TYPE_MAIN_VARIANT (decl) == void_type_node) | |
12678 | return decl; | |
12679 | ||
12680 | old_initial = DECL_INITIAL (fndecl); | |
12681 | ||
12682 | /* Undo the level for the parms (from start_method). | |
12683 | This is like poplevel, but it causes nothing to be | |
12684 | saved. Saving information here confuses symbol-table | |
12685 | output routines. Besides, this information will | |
12686 | be correctly output when this method is actually | |
12687 | compiled. */ | |
12688 | ||
12689 | /* Clear out the meanings of the local variables of this level; | |
12690 | also record in each decl which block it belongs to. */ | |
12691 | ||
12692 | for (link = current_binding_level->names; link; link = TREE_CHAIN (link)) | |
12693 | { | |
12694 | if (DECL_NAME (link) != NULL_TREE) | |
12695 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; | |
12696 | my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163); | |
12697 | DECL_CONTEXT (link) = NULL_TREE; | |
12698 | } | |
12699 | ||
12700 | /* Restore all name-meanings of the outer levels | |
12701 | that were shadowed by this level. */ | |
12702 | ||
12703 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
12704 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
12705 | for (link = current_binding_level->class_shadowed; | |
12706 | link; link = TREE_CHAIN (link)) | |
12707 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
12708 | for (link = current_binding_level->type_shadowed; | |
12709 | link; link = TREE_CHAIN (link)) | |
12710 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
12711 | ||
12712 | GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, | |
12713 | (HOST_WIDE_INT) current_binding_level->level_chain, | |
12714 | current_binding_level->parm_flag, | |
5566b478 | 12715 | current_binding_level->keep); |
8d08fdba MS |
12716 | |
12717 | poplevel (0, 0, 0); | |
12718 | ||
12719 | DECL_INITIAL (fndecl) = old_initial; | |
12720 | ||
12721 | /* We used to check if the context of FNDECL was different from | |
12722 | current_class_type as another way to get inside here. This didn't work | |
12723 | for String.cc in libg++. */ | |
12724 | if (DECL_FRIEND_P (fndecl)) | |
12725 | { | |
12726 | CLASSTYPE_INLINE_FRIENDS (current_class_type) | |
12727 | = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type)); | |
12728 | decl = void_type_node; | |
12729 | } | |
12730 | ||
12731 | return decl; | |
12732 | } | |
12733 | \f | |
12734 | /* Called when a new struct TYPE is defined. | |
12735 | If this structure or union completes the type of any previous | |
12736 | variable declaration, lay it out and output its rtl. */ | |
12737 | ||
12738 | void | |
12739 | hack_incomplete_structures (type) | |
12740 | tree type; | |
12741 | { | |
f30432d7 | 12742 | tree *list; |
8d08fdba | 12743 | |
f30432d7 | 12744 | if (current_binding_level->incomplete == NULL_TREE) |
8d08fdba MS |
12745 | return; |
12746 | ||
12747 | if (!type) /* Don't do this for class templates. */ | |
12748 | return; | |
12749 | ||
f30432d7 MS |
12750 | for (list = ¤t_binding_level->incomplete; *list; ) |
12751 | { | |
12752 | tree decl = TREE_VALUE (*list); | |
a703fb38 | 12753 | if ((decl && TREE_TYPE (decl) == type) |
f30432d7 MS |
12754 | || (TREE_TYPE (decl) |
12755 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
12756 | && TREE_TYPE (TREE_TYPE (decl)) == type)) | |
12757 | { | |
12758 | int toplevel = toplevel_bindings_p (); | |
12759 | if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
12760 | && TREE_TYPE (TREE_TYPE (decl)) == type) | |
12761 | layout_type (TREE_TYPE (decl)); | |
12762 | layout_decl (decl, 0); | |
12763 | rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); | |
12764 | if (! toplevel) | |
12765 | { | |
12766 | tree cleanup; | |
12767 | expand_decl (decl); | |
12768 | cleanup = maybe_build_cleanup (decl); | |
12769 | expand_decl_init (decl); | |
e349ee73 | 12770 | if (! expand_decl_cleanup (decl, cleanup)) |
f30432d7 MS |
12771 | cp_error ("parser lost in parsing declaration of `%D'", |
12772 | decl); | |
12773 | } | |
12774 | *list = TREE_CHAIN (*list); | |
12775 | } | |
12776 | else | |
12777 | list = &TREE_CHAIN (*list); | |
12778 | } | |
8d08fdba MS |
12779 | } |
12780 | ||
8d08fdba | 12781 | /* If DECL is of a type which needs a cleanup, build that cleanup here. |
c73964b2 | 12782 | See build_delete for information about AUTO_DELETE. |
8d08fdba MS |
12783 | |
12784 | Don't build these on the momentary obstack; they must live | |
12785 | the life of the binding contour. */ | |
e92cc029 | 12786 | |
c73964b2 MS |
12787 | static tree |
12788 | maybe_build_cleanup_1 (decl, auto_delete) | |
12789 | tree decl, auto_delete; | |
8d08fdba MS |
12790 | { |
12791 | tree type = TREE_TYPE (decl); | |
12792 | if (TYPE_NEEDS_DESTRUCTOR (type)) | |
12793 | { | |
12794 | int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; | |
12795 | tree rval; | |
8d08fdba MS |
12796 | |
12797 | if (TREE_CODE (decl) != PARM_DECL) | |
12798 | temp = suspend_momentary (); | |
12799 | ||
12800 | if (TREE_CODE (type) == ARRAY_TYPE) | |
12801 | rval = decl; | |
12802 | else | |
12803 | { | |
12804 | mark_addressable (decl); | |
12805 | rval = build_unary_op (ADDR_EXPR, decl, 0); | |
12806 | } | |
12807 | ||
12808 | /* Optimize for space over speed here. */ | |
12809 | if (! TYPE_USES_VIRTUAL_BASECLASSES (type) | |
12810 | || flag_expensive_optimizations) | |
12811 | flags |= LOOKUP_NONVIRTUAL; | |
12812 | ||
c73964b2 | 12813 | rval = build_delete (TREE_TYPE (rval), rval, auto_delete, flags, 0); |
8d08fdba MS |
12814 | |
12815 | if (TYPE_USES_VIRTUAL_BASECLASSES (type) | |
12816 | && ! TYPE_HAS_DESTRUCTOR (type)) | |
e66d884e JM |
12817 | rval = build_compound_expr (expr_tree_cons (NULL_TREE, rval, |
12818 | build_expr_list (NULL_TREE, build_vbase_delete (type, decl)))); | |
8d08fdba | 12819 | |
8d08fdba MS |
12820 | if (TREE_CODE (decl) != PARM_DECL) |
12821 | resume_momentary (temp); | |
12822 | ||
8d08fdba MS |
12823 | return rval; |
12824 | } | |
12825 | return 0; | |
12826 | } | |
c73964b2 MS |
12827 | |
12828 | /* If DECL is of a type which needs a cleanup, build that cleanup | |
12829 | here. The cleanup does free the storage with a call to delete. */ | |
12830 | ||
12831 | tree | |
12832 | maybe_build_cleanup_and_delete (decl) | |
12833 | tree decl; | |
12834 | { | |
12835 | return maybe_build_cleanup_1 (decl, integer_three_node); | |
12836 | } | |
12837 | ||
12838 | /* If DECL is of a type which needs a cleanup, build that cleanup | |
12839 | here. The cleanup does not free the storage with a call a delete. */ | |
12840 | ||
12841 | tree | |
12842 | maybe_build_cleanup (decl) | |
12843 | tree decl; | |
12844 | { | |
12845 | return maybe_build_cleanup_1 (decl, integer_two_node); | |
12846 | } | |
8d08fdba MS |
12847 | \f |
12848 | /* Expand a C++ expression at the statement level. | |
12849 | This is needed to ferret out nodes which have UNKNOWN_TYPE. | |
12850 | The C++ type checker should get all of these out when | |
12851 | expressions are combined with other, type-providing, expressions, | |
12852 | leaving only orphan expressions, such as: | |
12853 | ||
e92cc029 | 12854 | &class::bar; / / takes its address, but does nothing with it. */ |
8d08fdba | 12855 | |
8d08fdba MS |
12856 | void |
12857 | cplus_expand_expr_stmt (exp) | |
12858 | tree exp; | |
12859 | { | |
5156628f | 12860 | if (processing_template_decl) |
5566b478 MS |
12861 | { |
12862 | add_tree (build_min_nt (EXPR_STMT, exp)); | |
12863 | return; | |
12864 | } | |
12865 | ||
eb66be0e MS |
12866 | /* Arrange for all temps to disappear. */ |
12867 | expand_start_target_temps (); | |
12868 | ||
8d08fdba MS |
12869 | if (TREE_TYPE (exp) == unknown_type_node) |
12870 | { | |
12871 | if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST) | |
12872 | error ("address of overloaded function with no contextual type information"); | |
12873 | else if (TREE_CODE (exp) == COMPONENT_REF) | |
12874 | warning ("useless reference to a member function name, did you forget the ()?"); | |
12875 | } | |
12876 | else | |
12877 | { | |
8d08fdba MS |
12878 | if (TREE_CODE (exp) == FUNCTION_DECL) |
12879 | { | |
12880 | cp_warning ("reference, not call, to function `%D'", exp); | |
12881 | warning ("at this point in file"); | |
12882 | } | |
8d08fdba | 12883 | |
63c68bb7 MS |
12884 | #if 0 |
12885 | /* We should do this eventually, but right now this causes regex.o from | |
12886 | libg++ to miscompile, and tString to core dump. */ | |
5b605f68 | 12887 | exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp); |
63c68bb7 | 12888 | #endif |
d2e5ee5c MS |
12889 | /* If we don't do this, we end up down inside expand_expr |
12890 | trying to do TYPE_MODE on the ERROR_MARK, and really | |
12891 | go outside the bounds of the type. */ | |
12892 | if (exp != error_mark_node) | |
12893 | expand_expr_stmt (break_out_cleanups (exp)); | |
8d08fdba MS |
12894 | } |
12895 | ||
12896 | /* Clean up any pending cleanups. This happens when a function call | |
12897 | returns a cleanup-needing value that nobody uses. */ | |
eb66be0e | 12898 | expand_end_target_temps (); |
8d08fdba MS |
12899 | } |
12900 | ||
12901 | /* When a stmt has been parsed, this function is called. | |
12902 | ||
12903 | Currently, this function only does something within a | |
12904 | constructor's scope: if a stmt has just assigned to this, | |
12905 | and we are in a derived class, we call `emit_base_init'. */ | |
12906 | ||
12907 | void | |
12908 | finish_stmt () | |
12909 | { | |
12910 | extern struct nesting *cond_stack, *loop_stack, *case_stack; | |
12911 | ||
12912 | ||
12913 | if (current_function_assigns_this | |
12914 | || ! current_function_just_assigned_this) | |
12915 | return; | |
12916 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
12917 | { | |
12918 | /* Constructors must wait until we are out of control | |
12919 | zones before calling base constructors. */ | |
12920 | if (cond_stack || loop_stack || case_stack) | |
12921 | return; | |
a9aedbc2 | 12922 | expand_expr_stmt (base_init_expr); |
8d08fdba MS |
12923 | check_base_init (current_class_type); |
12924 | } | |
12925 | current_function_assigns_this = 1; | |
8d08fdba MS |
12926 | } |
12927 | ||
8d08fdba | 12928 | /* Change a static member function definition into a FUNCTION_TYPE, instead |
700f8a87 MS |
12929 | of the METHOD_TYPE that we create when it's originally parsed. |
12930 | ||
12931 | WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES | |
12932 | (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of | |
12933 | other decls. Either pass the addresses of local variables or NULL. */ | |
12934 | ||
8857f91e | 12935 | void |
700f8a87 MS |
12936 | revert_static_member_fn (decl, fn, argtypes) |
12937 | tree *decl, *fn, *argtypes; | |
8d08fdba | 12938 | { |
700f8a87 MS |
12939 | tree tmp; |
12940 | tree function = fn ? *fn : TREE_TYPE (*decl); | |
12941 | tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function); | |
8d08fdba | 12942 | |
f30432d7 MS |
12943 | if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args)))) |
12944 | cp_error ("static member function `%#D' declared const", *decl); | |
12945 | if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args)))) | |
12946 | cp_error ("static member function `%#D' declared volatile", *decl); | |
12947 | ||
700f8a87 MS |
12948 | args = TREE_CHAIN (args); |
12949 | tmp = build_function_type (TREE_TYPE (function), args); | |
8d08fdba MS |
12950 | tmp = build_type_variant (tmp, TYPE_READONLY (function), |
12951 | TYPE_VOLATILE (function)); | |
f30432d7 | 12952 | tmp = build_exception_variant (tmp, |
8d08fdba MS |
12953 | TYPE_RAISES_EXCEPTIONS (function)); |
12954 | TREE_TYPE (*decl) = tmp; | |
f30432d7 MS |
12955 | if (DECL_ARGUMENTS (*decl)) |
12956 | DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl)); | |
8d08fdba | 12957 | DECL_STATIC_FUNCTION_P (*decl) = 1; |
700f8a87 MS |
12958 | if (fn) |
12959 | *fn = tmp; | |
12960 | if (argtypes) | |
12961 | *argtypes = args; | |
8d08fdba | 12962 | } |
a4443a08 MS |
12963 | |
12964 | int | |
12965 | id_in_current_class (id) | |
12966 | tree id; | |
12967 | { | |
12968 | return !!purpose_member (id, class_binding_level->class_shadowed); | |
12969 | } | |
db5ae43f MS |
12970 | |
12971 | struct cp_function | |
12972 | { | |
12973 | int returns_value; | |
12974 | int returns_null; | |
12975 | int warn_about_return_type; | |
db5ae43f MS |
12976 | int assigns_this; |
12977 | int just_assigned_this; | |
12978 | int parms_stored; | |
7215f9a0 | 12979 | int temp_name_counter; |
db5ae43f MS |
12980 | tree named_labels; |
12981 | tree shadowed_labels; | |
12982 | tree ctor_label; | |
12983 | tree dtor_label; | |
72b7eeff | 12984 | rtx last_dtor_insn; |
b87692e5 | 12985 | rtx last_parm_cleanup_insn; |
79ff2c6c MS |
12986 | tree base_init_list; |
12987 | tree member_init_list; | |
a9aedbc2 | 12988 | tree base_init_expr; |
4ac14744 MS |
12989 | tree current_class_ptr; |
12990 | tree current_class_ref; | |
db5ae43f MS |
12991 | rtx result_rtx; |
12992 | struct cp_function *next; | |
12993 | struct binding_level *binding_level; | |
42976354 | 12994 | int static_labelno; |
db5ae43f MS |
12995 | }; |
12996 | ||
bd6dd845 | 12997 | static struct cp_function *cp_function_chain; |
db5ae43f | 12998 | |
7215f9a0 MS |
12999 | extern int temp_name_counter; |
13000 | ||
db5ae43f MS |
13001 | /* Save and reinitialize the variables |
13002 | used during compilation of a C++ function. */ | |
13003 | ||
13004 | void | |
28cbf42c MS |
13005 | push_cp_function_context (context) |
13006 | tree context; | |
db5ae43f MS |
13007 | { |
13008 | struct cp_function *p | |
13009 | = (struct cp_function *) xmalloc (sizeof (struct cp_function)); | |
13010 | ||
28cbf42c | 13011 | push_function_context_to (context); |
db5ae43f MS |
13012 | |
13013 | p->next = cp_function_chain; | |
13014 | cp_function_chain = p; | |
13015 | ||
13016 | p->named_labels = named_labels; | |
13017 | p->shadowed_labels = shadowed_labels; | |
13018 | p->returns_value = current_function_returns_value; | |
13019 | p->returns_null = current_function_returns_null; | |
13020 | p->warn_about_return_type = warn_about_return_type; | |
db5ae43f MS |
13021 | p->binding_level = current_binding_level; |
13022 | p->ctor_label = ctor_label; | |
13023 | p->dtor_label = dtor_label; | |
72b7eeff | 13024 | p->last_dtor_insn = last_dtor_insn; |
b87692e5 | 13025 | p->last_parm_cleanup_insn = last_parm_cleanup_insn; |
db5ae43f MS |
13026 | p->assigns_this = current_function_assigns_this; |
13027 | p->just_assigned_this = current_function_just_assigned_this; | |
13028 | p->parms_stored = current_function_parms_stored; | |
13029 | p->result_rtx = original_result_rtx; | |
a9aedbc2 | 13030 | p->base_init_expr = base_init_expr; |
7215f9a0 | 13031 | p->temp_name_counter = temp_name_counter; |
79ff2c6c MS |
13032 | p->base_init_list = current_base_init_list; |
13033 | p->member_init_list = current_member_init_list; | |
4ac14744 MS |
13034 | p->current_class_ptr = current_class_ptr; |
13035 | p->current_class_ref = current_class_ref; | |
42976354 | 13036 | p->static_labelno = static_labelno; |
db5ae43f MS |
13037 | } |
13038 | ||
13039 | /* Restore the variables used during compilation of a C++ function. */ | |
13040 | ||
13041 | void | |
28cbf42c MS |
13042 | pop_cp_function_context (context) |
13043 | tree context; | |
db5ae43f MS |
13044 | { |
13045 | struct cp_function *p = cp_function_chain; | |
13046 | tree link; | |
13047 | ||
13048 | /* Bring back all the labels that were shadowed. */ | |
13049 | for (link = shadowed_labels; link; link = TREE_CHAIN (link)) | |
13050 | if (DECL_NAME (TREE_VALUE (link)) != 0) | |
13051 | SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), | |
13052 | TREE_VALUE (link)); | |
13053 | ||
28cbf42c | 13054 | pop_function_context_from (context); |
db5ae43f MS |
13055 | |
13056 | cp_function_chain = p->next; | |
13057 | ||
13058 | named_labels = p->named_labels; | |
13059 | shadowed_labels = p->shadowed_labels; | |
13060 | current_function_returns_value = p->returns_value; | |
13061 | current_function_returns_null = p->returns_null; | |
13062 | warn_about_return_type = p->warn_about_return_type; | |
db5ae43f MS |
13063 | current_binding_level = p->binding_level; |
13064 | ctor_label = p->ctor_label; | |
13065 | dtor_label = p->dtor_label; | |
72b7eeff | 13066 | last_dtor_insn = p->last_dtor_insn; |
b87692e5 | 13067 | last_parm_cleanup_insn = p->last_parm_cleanup_insn; |
db5ae43f MS |
13068 | current_function_assigns_this = p->assigns_this; |
13069 | current_function_just_assigned_this = p->just_assigned_this; | |
13070 | current_function_parms_stored = p->parms_stored; | |
13071 | original_result_rtx = p->result_rtx; | |
a9aedbc2 | 13072 | base_init_expr = p->base_init_expr; |
7215f9a0 | 13073 | temp_name_counter = p->temp_name_counter; |
79ff2c6c MS |
13074 | current_base_init_list = p->base_init_list; |
13075 | current_member_init_list = p->member_init_list; | |
4ac14744 MS |
13076 | current_class_ptr = p->current_class_ptr; |
13077 | current_class_ref = p->current_class_ref; | |
42976354 | 13078 | static_labelno = p->static_labelno; |
db5ae43f MS |
13079 | |
13080 | free (p); | |
13081 | } | |
ebfc180f | 13082 | |
5566b478 MS |
13083 | int |
13084 | in_function_p () | |
13085 | { | |
13086 | return function_depth != 0; | |
13087 | } |