]>
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" |
da20811c | 31 | #include <stdio.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" | |
38 | #include <sys/types.h> | |
39 | #include <signal.h> | |
40 | #include "obstack.h" | |
72b7eeff | 41 | #include "defaults.h" |
49c249e1 JM |
42 | #include "output.h" |
43 | #include "except.h" | |
8d08fdba | 44 | |
9f617717 L |
45 | #ifdef HAVE_STDLIB_H |
46 | #include <stdlib.h> | |
47 | #endif | |
48 | ||
49 | #ifdef NEED_DECLARATION_FREE | |
50 | extern void free PROTO((void *)); | |
51 | #endif | |
52 | ||
8d08fdba MS |
53 | #define obstack_chunk_alloc xmalloc |
54 | #define obstack_chunk_free free | |
55 | ||
8d2733ca MS |
56 | extern tree builtin_return_address_fndecl; |
57 | ||
8d08fdba MS |
58 | extern struct obstack permanent_obstack; |
59 | ||
60 | extern int current_class_depth; | |
61 | ||
e1cd6e56 MS |
62 | extern tree static_ctors, static_dtors; |
63 | ||
42976354 BK |
64 | extern int static_labelno; |
65 | ||
30394414 JM |
66 | extern tree current_namespace; |
67 | extern tree global_namespace; | |
68 | ||
8d08fdba MS |
69 | /* Stack of places to restore the search obstack back to. */ |
70 | ||
71 | /* Obstack used for remembering local class declarations (like | |
72 | enums and static (const) members. */ | |
73 | #include "stack.h" | |
5566b478 | 74 | struct obstack decl_obstack; |
8d08fdba MS |
75 | static struct stack_level *decl_stack; |
76 | ||
77 | #ifndef CHAR_TYPE_SIZE | |
78 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
79 | #endif | |
80 | ||
81 | #ifndef SHORT_TYPE_SIZE | |
82 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) | |
83 | #endif | |
84 | ||
85 | #ifndef INT_TYPE_SIZE | |
86 | #define INT_TYPE_SIZE BITS_PER_WORD | |
87 | #endif | |
88 | ||
89 | #ifndef LONG_TYPE_SIZE | |
90 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
91 | #endif | |
92 | ||
93 | #ifndef LONG_LONG_TYPE_SIZE | |
94 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
95 | #endif | |
96 | ||
97 | #ifndef WCHAR_UNSIGNED | |
98 | #define WCHAR_UNSIGNED 0 | |
99 | #endif | |
100 | ||
101 | #ifndef FLOAT_TYPE_SIZE | |
102 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
103 | #endif | |
104 | ||
105 | #ifndef DOUBLE_TYPE_SIZE | |
106 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
107 | #endif | |
108 | ||
109 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
110 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
111 | #endif | |
112 | ||
255512c1 | 113 | #ifndef BOOL_TYPE_SIZE |
e1cd6e56 | 114 | #ifdef SLOW_BYTE_ACCESS |
d2e5ee5c | 115 | #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (POINTER_SIZE) : (CHAR_TYPE_SIZE)) |
e1cd6e56 | 116 | #else |
d2e5ee5c | 117 | #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE |
e1cd6e56 | 118 | #endif |
255512c1 JM |
119 | #endif |
120 | ||
8d08fdba MS |
121 | /* We let tm.h override the types used here, to handle trivial differences |
122 | such as the choice of unsigned int or long unsigned int for size_t. | |
123 | When machines start needing nontrivial differences in the size type, | |
124 | it would be best to do something here to figure out automatically | |
125 | from other information what type to use. */ | |
126 | ||
127 | #ifndef SIZE_TYPE | |
128 | #define SIZE_TYPE "long unsigned int" | |
129 | #endif | |
130 | ||
131 | #ifndef PTRDIFF_TYPE | |
132 | #define PTRDIFF_TYPE "long int" | |
133 | #endif | |
134 | ||
135 | #ifndef WCHAR_TYPE | |
136 | #define WCHAR_TYPE "int" | |
137 | #endif | |
138 | ||
8d08fdba MS |
139 | static tree grokparms PROTO((tree, int)); |
140 | static tree lookup_nested_type PROTO((tree, tree)); | |
141 | static char *redeclaration_error_message PROTO((tree, tree)); | |
bd6dd845 MS |
142 | static tree push_overloaded_decl PROTO((tree, int)); |
143 | static void push_overloaded_decl_top_level PROTO((tree, int)); | |
8d08fdba | 144 | |
49c249e1 JM |
145 | static struct stack_level *push_decl_level PROTO((struct stack_level *, |
146 | struct obstack *)); | |
147 | static void push_binding_level PROTO((struct binding_level *, int, | |
148 | int)); | |
149 | static void pop_binding_level PROTO((void)); | |
150 | static void suspend_binding_level PROTO((void)); | |
151 | static void resume_binding_level PROTO((struct binding_level *)); | |
152 | static struct binding_level *make_binding_level PROTO((void)); | |
153 | static int namespace_bindings_p PROTO((void)); | |
154 | static void declare_namespace_level PROTO((void)); | |
155 | static tree get_unique_name PROTO((void)); | |
156 | static void signal_catch PROTO((int)); | |
157 | static void storedecls PROTO((tree)); | |
158 | static void storetags PROTO((tree)); | |
159 | static void require_complete_types_for_parms PROTO((tree)); | |
160 | static void push_overloaded_decl_1 PROTO((tree)); | |
161 | static int ambi_op_p PROTO((tree)); | |
162 | static int unary_op_p PROTO((tree)); | |
163 | static tree store_bindings PROTO((tree, tree)); | |
164 | static tree lookup_tag_reverse PROTO((tree, tree)); | |
165 | static tree obscure_complex_init PROTO((tree, tree)); | |
166 | static tree maybe_build_cleanup_1 PROTO((tree, tree)); | |
167 | static tree lookup_name_real PROTO((tree, int, int)); | |
168 | static void warn_extern_redeclared_static PROTO((tree, tree)); | |
a703fb38 | 169 | static void grok_reference_init PROTO((tree, tree, tree)); |
386b8a85 | 170 | static tree grokfndecl PROTO((tree, tree, tree, tree, int, |
49c249e1 | 171 | enum overload_flags, |
386b8a85 | 172 | tree, tree, tree, int, int, int, int, int, int)); |
49c249e1 JM |
173 | static tree grokvardecl PROTO((tree, tree, RID_BIT_TYPE *, int, int)); |
174 | static tree lookup_tag PROTO((enum tree_code, tree, | |
175 | struct binding_level *, int)); | |
176 | static void set_identifier_type_value_with_scope | |
177 | PROTO((tree, tree, struct binding_level *)); | |
178 | static void record_builtin_type PROTO((enum rid, char *, tree)); | |
179 | static int member_function_or_else PROTO((tree, tree, char *)); | |
180 | static void bad_specifiers PROTO((tree, char *, int, int, int, int, | |
181 | int)); | |
8d08fdba MS |
182 | |
183 | /* a node which has tree code ERROR_MARK, and whose type is itself. | |
184 | All erroneous expressions are replaced with this node. All functions | |
185 | that accept nodes as arguments should avoid generating error messages | |
186 | if this node is one of the arguments, since it is undesirable to get | |
187 | multiple error messages from one error in the input. */ | |
188 | ||
189 | tree error_mark_node; | |
190 | ||
191 | /* Erroneous argument lists can use this *IFF* they do not modify it. */ | |
192 | tree error_mark_list; | |
193 | ||
194 | /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ | |
195 | ||
196 | tree short_integer_type_node; | |
197 | tree integer_type_node; | |
198 | tree long_integer_type_node; | |
199 | tree long_long_integer_type_node; | |
200 | ||
201 | tree short_unsigned_type_node; | |
202 | tree unsigned_type_node; | |
203 | tree long_unsigned_type_node; | |
204 | tree long_long_unsigned_type_node; | |
205 | ||
206 | tree ptrdiff_type_node; | |
207 | ||
208 | tree unsigned_char_type_node; | |
209 | tree signed_char_type_node; | |
210 | tree char_type_node; | |
211 | tree wchar_type_node; | |
212 | tree signed_wchar_type_node; | |
213 | tree unsigned_wchar_type_node; | |
214 | ||
f376e137 MS |
215 | tree wchar_decl_node; |
216 | ||
8d08fdba MS |
217 | tree float_type_node; |
218 | tree double_type_node; | |
219 | tree long_double_type_node; | |
220 | ||
37c46b43 MS |
221 | tree complex_integer_type_node; |
222 | tree complex_float_type_node; | |
223 | tree complex_double_type_node; | |
224 | tree complex_long_double_type_node; | |
225 | ||
8d08fdba MS |
226 | tree intQI_type_node; |
227 | tree intHI_type_node; | |
228 | tree intSI_type_node; | |
229 | tree intDI_type_node; | |
230 | ||
231 | tree unsigned_intQI_type_node; | |
232 | tree unsigned_intHI_type_node; | |
233 | tree unsigned_intSI_type_node; | |
234 | tree unsigned_intDI_type_node; | |
235 | ||
236 | /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */ | |
237 | ||
238 | tree void_type_node, void_list_node; | |
239 | tree void_zero_node; | |
240 | ||
241 | /* Nodes for types `void *' and `const void *'. */ | |
242 | ||
bd6dd845 | 243 | tree ptr_type_node; |
6c20b7e9 | 244 | tree const_ptr_type_node; |
8d08fdba MS |
245 | |
246 | /* Nodes for types `char *' and `const char *'. */ | |
247 | ||
248 | tree string_type_node, const_string_type_node; | |
249 | ||
250 | /* Type `char[256]' or something like it. | |
251 | Used when an array of char is needed and the size is irrelevant. */ | |
252 | ||
253 | tree char_array_type_node; | |
254 | ||
255 | /* Type `int[256]' or something like it. | |
256 | Used when an array of int needed and the size is irrelevant. */ | |
257 | ||
258 | tree int_array_type_node; | |
259 | ||
260 | /* Type `wchar_t[256]' or something like it. | |
261 | Used when a wide string literal is created. */ | |
262 | ||
263 | tree wchar_array_type_node; | |
264 | ||
2986ae00 | 265 | /* The bool data type, and constants */ |
255512c1 | 266 | tree boolean_type_node, boolean_true_node, boolean_false_node; |
2986ae00 | 267 | |
8d08fdba MS |
268 | /* type `int ()' -- used for implicit declaration of functions. */ |
269 | ||
270 | tree default_function_type; | |
271 | ||
272 | /* function types `double (double)' and `double (double, double)', etc. */ | |
273 | ||
bd6dd845 MS |
274 | static tree double_ftype_double, double_ftype_double_double; |
275 | static tree int_ftype_int, long_ftype_long; | |
276 | static tree float_ftype_float; | |
277 | static tree ldouble_ftype_ldouble; | |
8d08fdba | 278 | |
8d08fdba | 279 | /* Function type `int (const void *, const void *, size_t)' */ |
5566b478 | 280 | static tree int_ftype_cptr_cptr_sizet; |
8d08fdba MS |
281 | |
282 | /* C++ extensions */ | |
700f8a87 | 283 | tree vtable_entry_type; |
8d08fdba | 284 | tree delta_type_node; |
db5ae43f | 285 | #if 0 |
e92cc029 | 286 | /* Old rtti stuff. */ |
db5ae43f MS |
287 | tree __baselist_desc_type_node; |
288 | tree __i_desc_type_node, __m_desc_type_node; | |
8d08fdba | 289 | tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; |
db5ae43f | 290 | #endif |
5566b478 MS |
291 | tree __t_desc_type_node; |
292 | #if 0 | |
293 | tree __tp_desc_type_node; | |
294 | #endif | |
db5ae43f MS |
295 | tree __access_mode_type_node; |
296 | tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node; | |
297 | tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node; | |
298 | tree __ptmf_desc_type_node, __ptmd_desc_type_node; | |
299 | #if 0 | |
300 | /* Not needed yet? May be needed one day? */ | |
301 | tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type; | |
302 | tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type; | |
303 | tree __ptmf_desc_array_type, __ptmd_desc_array_type; | |
304 | #endif | |
305 | ||
8d08fdba MS |
306 | tree class_star_type_node; |
307 | tree class_type_node, record_type_node, union_type_node, enum_type_node; | |
db5ae43f | 308 | tree unknown_type_node; |
8d08fdba MS |
309 | tree opaque_type_node, signature_type_node; |
310 | tree sigtable_entry_type; | |
8d08fdba | 311 | |
8d08fdba MS |
312 | /* Array type `vtable_entry_type[]' */ |
313 | tree vtbl_type_node; | |
314 | ||
6633d636 MS |
315 | /* namespace std */ |
316 | tree std_node; | |
317 | ||
8d08fdba MS |
318 | /* In a destructor, the point at which all derived class destroying |
319 | has been done, just before any base class destroying will be done. */ | |
320 | ||
321 | tree dtor_label; | |
322 | ||
72b7eeff MS |
323 | /* In a destructor, the last insn emitted after the start of the |
324 | function and the parms. */ | |
325 | ||
bd6dd845 | 326 | static rtx last_dtor_insn; |
72b7eeff | 327 | |
b87692e5 | 328 | /* In a constructor, the last insn emitted after the start of the |
9664b89e JM |
329 | function and the parms, the exception specification and any |
330 | function-try-block. The constructor initializers are emitted after | |
331 | this insn. */ | |
b87692e5 MS |
332 | |
333 | static rtx last_parm_cleanup_insn; | |
334 | ||
8d08fdba MS |
335 | /* In a constructor, the point at which we are ready to return |
336 | the pointer to the initialized object. */ | |
337 | ||
338 | tree ctor_label; | |
339 | ||
8d08fdba MS |
340 | /* A FUNCTION_DECL which can call `abort'. Not necessarily the |
341 | one that the user will declare, but sufficient to be called | |
342 | by routines that want to abort the program. */ | |
343 | ||
344 | tree abort_fndecl; | |
345 | ||
346 | extern rtx cleanup_label, return_label; | |
347 | ||
348 | /* If original DECL_RESULT of current function was a register, | |
349 | but due to being an addressable named return value, would up | |
350 | on the stack, this variable holds the named return value's | |
351 | original location. */ | |
bd6dd845 | 352 | static rtx original_result_rtx; |
8d08fdba MS |
353 | |
354 | /* Sequence of insns which represents base initialization. */ | |
a9aedbc2 | 355 | tree base_init_expr; |
8d08fdba MS |
356 | |
357 | /* C++: Keep these around to reduce calls to `get_identifier'. | |
358 | Identifiers for `this' in member functions and the auto-delete | |
359 | parameter for destructors. */ | |
360 | tree this_identifier, in_charge_identifier; | |
fc378698 | 361 | tree ctor_identifier, dtor_identifier; |
e92cc029 | 362 | /* Used in pointer to member functions, in vtables, and in sigtables. */ |
8d08fdba | 363 | tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; |
9dd70aa4 | 364 | tree pfn_or_delta2_identifier, tag_identifier; |
5566b478 | 365 | tree vt_off_identifier; |
8d08fdba | 366 | |
e349ee73 MS |
367 | struct named_label_list |
368 | { | |
369 | struct binding_level *binding_level; | |
370 | tree names_in_scope; | |
371 | tree label_decl; | |
372 | char *filename_o_goto; | |
373 | int lineno_o_goto; | |
374 | struct named_label_list *next; | |
375 | }; | |
376 | ||
8d08fdba MS |
377 | /* A list (chain of TREE_LIST nodes) of named label uses. |
378 | The TREE_PURPOSE field is the list of variables defined | |
379 | the the label's scope defined at the point of use. | |
380 | The TREE_VALUE field is the LABEL_DECL used. | |
381 | The TREE_TYPE field holds `current_binding_level' at the | |
382 | point of the label's use. | |
383 | ||
e349ee73 MS |
384 | BWAHAHAAHAHahhahahahaah. No, no, no, said the little chicken. |
385 | ||
386 | Look at the pretty struct named_label_list. See the pretty struct | |
387 | with the pretty named fields that describe what they do. See the | |
388 | pretty lack of gratuitous casts. Notice the code got a lot cleaner. | |
389 | ||
8d08fdba MS |
390 | Used only for jumps to as-yet undefined labels, since |
391 | jumps to defined labels can have their validity checked | |
392 | by stmt.c. */ | |
393 | ||
e349ee73 | 394 | static struct named_label_list *named_label_uses = NULL; |
8d08fdba MS |
395 | |
396 | /* A list of objects which have constructors or destructors | |
397 | which reside in the global scope. The decl is stored in | |
398 | the TREE_VALUE slot and the initializer is stored | |
399 | in the TREE_PURPOSE slot. */ | |
400 | tree static_aggregates; | |
401 | ||
8d08fdba MS |
402 | /* -- end of C++ */ |
403 | ||
404 | /* Two expressions that are constants with value zero. | |
405 | The first is of type `int', the second of type `void *'. */ | |
406 | ||
407 | tree integer_zero_node; | |
408 | tree null_pointer_node; | |
409 | ||
d11ad92e MS |
410 | /* The value for __null (NULL), either of type `void *' or, with -ansi, |
411 | an integer type of the same size. */ | |
412 | ||
413 | tree null_node; | |
414 | ||
8d08fdba MS |
415 | /* A node for the integer constants 1, 2, and 3. */ |
416 | ||
417 | tree integer_one_node, integer_two_node, integer_three_node; | |
418 | ||
8d08fdba MS |
419 | /* While defining an enum type, this is 1 plus the last enumerator |
420 | constant value. */ | |
421 | ||
422 | static tree enum_next_value; | |
423 | ||
7177d104 MS |
424 | /* Nonzero means that there was overflow computing enum_next_value. */ |
425 | ||
426 | static int enum_overflow; | |
427 | ||
8d08fdba MS |
428 | /* Parsing a function declarator leaves a list of parameter names |
429 | or a chain or parameter decls here. */ | |
430 | ||
431 | tree last_function_parms; | |
432 | ||
433 | /* Parsing a function declarator leaves here a chain of structure | |
434 | and enum types declared in the parmlist. */ | |
435 | ||
436 | static tree last_function_parm_tags; | |
437 | ||
438 | /* After parsing the declarator that starts a function definition, | |
439 | `start_function' puts here the list of parameter names or chain of decls. | |
440 | `store_parm_decls' finds it here. */ | |
441 | ||
442 | static tree current_function_parms; | |
443 | ||
444 | /* Similar, for last_function_parm_tags. */ | |
445 | static tree current_function_parm_tags; | |
446 | ||
447 | /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function | |
448 | that have names. Here so we can clear out their names' definitions | |
449 | at the end of the function. */ | |
450 | ||
451 | static tree named_labels; | |
452 | ||
453 | /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ | |
454 | ||
455 | static tree shadowed_labels; | |
456 | ||
8d08fdba MS |
457 | /* The FUNCTION_DECL for the function currently being compiled, |
458 | or 0 if between functions. */ | |
459 | tree current_function_decl; | |
460 | ||
461 | /* Set to 0 at beginning of a function definition, set to 1 if | |
462 | a return statement that specifies a return value is seen. */ | |
463 | ||
464 | int current_function_returns_value; | |
465 | ||
466 | /* Set to 0 at beginning of a function definition, set to 1 if | |
467 | a return statement with no argument is seen. */ | |
468 | ||
469 | int current_function_returns_null; | |
470 | ||
471 | /* Set to 0 at beginning of a function definition, and whenever | |
472 | a label (case or named) is defined. Set to value of expression | |
473 | returned from function when that value can be transformed into | |
474 | a named return value. */ | |
475 | ||
476 | tree current_function_return_value; | |
477 | ||
478 | /* Set to nonzero by `grokdeclarator' for a function | |
479 | whose return type is defaulted, if warnings for this are desired. */ | |
480 | ||
481 | static int warn_about_return_type; | |
482 | ||
8d08fdba MS |
483 | /* Nonzero means give `double' the same size as `float'. */ |
484 | ||
485 | extern int flag_short_double; | |
486 | ||
487 | /* Nonzero means don't recognize any builtin functions. */ | |
488 | ||
489 | extern int flag_no_builtin; | |
490 | ||
00595019 MS |
491 | /* Nonzero means don't recognize the non-ANSI builtin functions. |
492 | -ansi sets this. */ | |
493 | ||
494 | extern int flag_no_nonansi_builtin; | |
495 | ||
e1cd6e56 MS |
496 | /* Nonzero means enable obscure ANSI features and disable GNU extensions |
497 | that might cause ANSI-compliant code to be miscompiled. */ | |
8d08fdba MS |
498 | |
499 | extern int flag_ansi; | |
500 | ||
501 | /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) | |
e92cc029 | 502 | objects. */ |
8d08fdba MS |
503 | extern int flag_huge_objects; |
504 | ||
505 | /* Nonzero if we want to conserve space in the .o files. We do this | |
506 | by putting uninitialized data and runtime initialized data into | |
ddd5a7c1 | 507 | .common instead of .data at the expense of not flagging multiple |
8d08fdba MS |
508 | definitions. */ |
509 | extern int flag_conserve_space; | |
510 | ||
511 | /* Pointers to the base and current top of the language name stack. */ | |
512 | ||
513 | extern tree *current_lang_base, *current_lang_stack; | |
514 | \f | |
51c184be | 515 | /* C and C++ flags are in decl2.c. */ |
8d08fdba MS |
516 | |
517 | /* Set to 0 at beginning of a constructor, set to 1 | |
518 | if that function does an allocation before referencing its | |
519 | instance variable. */ | |
5566b478 | 520 | static int current_function_assigns_this; |
8d08fdba MS |
521 | int current_function_just_assigned_this; |
522 | ||
523 | /* Set to 0 at beginning of a function. Set non-zero when | |
524 | store_parm_decls is called. Don't call store_parm_decls | |
525 | if this flag is non-zero! */ | |
526 | int current_function_parms_stored; | |
527 | ||
51c184be | 528 | /* Flag used when debugging spew.c */ |
8d08fdba MS |
529 | |
530 | extern int spew_debug; | |
531 | ||
532 | /* This is a copy of the class_shadowed list of the previous class binding | |
533 | contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs | |
534 | when entering another class scope (i.e. a cache miss). */ | |
535 | extern tree previous_class_values; | |
536 | ||
e92cc029 MS |
537 | /* A expression of value 0 with the same precision as a sizetype |
538 | node, but signed. */ | |
539 | tree signed_size_zero_node; | |
540 | ||
8d08fdba MS |
541 | \f |
542 | /* Allocate a level of searching. */ | |
e92cc029 | 543 | |
824b9a4c | 544 | static |
8d08fdba MS |
545 | struct stack_level * |
546 | push_decl_level (stack, obstack) | |
547 | struct stack_level *stack; | |
548 | struct obstack *obstack; | |
549 | { | |
550 | struct stack_level tem; | |
551 | tem.prev = stack; | |
552 | ||
553 | return push_stack_level (obstack, (char *)&tem, sizeof (tem)); | |
554 | } | |
555 | \f | |
556 | /* For each binding contour we allocate a binding_level structure | |
e92cc029 MS |
557 | which records the names defined in that contour. |
558 | Contours include: | |
559 | 0) the global one | |
560 | 1) one for each function definition, | |
561 | where internal declarations of the parameters appear. | |
562 | 2) one for each compound statement, | |
563 | to record its declarations. | |
564 | ||
565 | The current meaning of a name can be found by searching the levels | |
566 | from the current one out to the global one. | |
567 | ||
568 | Off to the side, may be the class_binding_level. This exists only | |
569 | to catch class-local declarations. It is otherwise nonexistent. | |
570 | ||
571 | Also there may be binding levels that catch cleanups that must be | |
572 | run when exceptions occur. */ | |
8d08fdba MS |
573 | |
574 | /* Note that the information in the `names' component of the global contour | |
575 | is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ | |
576 | ||
577 | struct binding_level | |
578 | { | |
579 | /* A chain of _DECL nodes for all variables, constants, functions, | |
e92cc029 MS |
580 | and typedef types. These are in the reverse of the order |
581 | supplied. */ | |
8d08fdba MS |
582 | tree names; |
583 | ||
e92cc029 MS |
584 | /* A list of structure, union and enum definitions, for looking up |
585 | tag names. | |
586 | It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, | |
587 | or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, | |
588 | or ENUMERAL_TYPE node. | |
589 | ||
590 | C++: the TREE_VALUE nodes can be simple types for | |
591 | component_bindings. */ | |
8d08fdba MS |
592 | tree tags; |
593 | ||
594 | /* For each level, a list of shadowed outer-level local definitions | |
595 | to be restored when this level is popped. | |
596 | Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and | |
597 | whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ | |
598 | tree shadowed; | |
599 | ||
600 | /* Same, for IDENTIFIER_CLASS_VALUE. */ | |
601 | tree class_shadowed; | |
602 | ||
603 | /* Same, for IDENTIFIER_TYPE_VALUE. */ | |
604 | tree type_shadowed; | |
605 | ||
606 | /* For each level (except not the global one), | |
607 | a chain of BLOCK nodes for all the levels | |
608 | that were entered and exited one level down. */ | |
609 | tree blocks; | |
610 | ||
611 | /* The BLOCK node for this level, if one has been preallocated. | |
612 | If 0, the BLOCK is allocated (if needed) when the level is popped. */ | |
613 | tree this_block; | |
614 | ||
615 | /* The binding level which this one is contained in (inherits from). */ | |
616 | struct binding_level *level_chain; | |
617 | ||
f30432d7 | 618 | /* List of decls in `names' that have incomplete |
8d08fdba | 619 | structure or union types. */ |
f30432d7 | 620 | tree incomplete; |
8d08fdba | 621 | |
8d6e462b | 622 | /* List of VAR_DECLS saved from a previous for statement. |
abc95ed3 | 623 | These would be dead in ANSI-conforming code, but might |
d22c8596 | 624 | be referenced in ARM-era code. */ |
8d6e462b PB |
625 | tree dead_vars_from_for; |
626 | ||
8d08fdba MS |
627 | /* 1 for the level that holds the parameters of a function. |
628 | 2 for the level that holds a class declaration. | |
629 | 3 for levels that hold parameter declarations. */ | |
630 | unsigned parm_flag : 4; | |
631 | ||
632 | /* 1 means make a BLOCK for this level regardless of all else. | |
633 | 2 for temporary binding contours created by the compiler. */ | |
634 | unsigned keep : 3; | |
635 | ||
636 | /* Nonzero if this level "doesn't exist" for tags. */ | |
637 | unsigned tag_transparent : 1; | |
638 | ||
639 | /* Nonzero if this level can safely have additional | |
640 | cleanup-needing variables added to it. */ | |
641 | unsigned more_cleanups_ok : 1; | |
642 | unsigned have_cleanups : 1; | |
643 | ||
5566b478 MS |
644 | /* Nonzero if this level is for storing the decls for template |
645 | parameters and generic decls; these decls will be discarded and | |
646 | replaced with a TEMPLATE_DECL. */ | |
8d08fdba MS |
647 | unsigned pseudo_global : 1; |
648 | ||
a9aedbc2 MS |
649 | /* This is set for a namespace binding level. */ |
650 | unsigned namespace_p : 1; | |
651 | ||
2ee887f2 | 652 | /* True if this level is that of a for-statement where we need to |
d22c8596 | 653 | worry about ambiguous (ARM or ANSI) scope rules. */ |
8d6e462b PB |
654 | unsigned is_for_scope : 1; |
655 | ||
5566b478 | 656 | /* Two bits left for this word. */ |
8d08fdba MS |
657 | |
658 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
659 | /* Binding depth at which this level began. */ | |
660 | unsigned binding_depth; | |
661 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
662 | }; | |
663 | ||
664 | #define NULL_BINDING_LEVEL ((struct binding_level *) NULL) | |
665 | ||
666 | /* The (non-class) binding level currently in effect. */ | |
667 | ||
668 | static struct binding_level *current_binding_level; | |
669 | ||
670 | /* The binding level of the current class, if any. */ | |
671 | ||
672 | static struct binding_level *class_binding_level; | |
673 | ||
674 | /* The current (class or non-class) binding level currently in effect. */ | |
675 | ||
676 | #define inner_binding_level \ | |
677 | (class_binding_level ? class_binding_level : current_binding_level) | |
678 | ||
679 | /* A chain of binding_level structures awaiting reuse. */ | |
680 | ||
681 | static struct binding_level *free_binding_level; | |
682 | ||
683 | /* The outermost binding level, for names of file scope. | |
684 | This is created when the compiler is started and exists | |
685 | through the entire run. */ | |
686 | ||
687 | static struct binding_level *global_binding_level; | |
688 | ||
689 | /* Binding level structures are initialized by copying this one. */ | |
690 | ||
691 | static struct binding_level clear_binding_level; | |
692 | ||
693 | /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ | |
694 | ||
695 | static int keep_next_level_flag; | |
696 | ||
697 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
698 | static int binding_depth = 0; | |
699 | static int is_class_level = 0; | |
700 | ||
701 | static void | |
702 | indent () | |
703 | { | |
704 | register unsigned i; | |
705 | ||
706 | for (i = 0; i < binding_depth*2; i++) | |
707 | putc (' ', stderr); | |
708 | } | |
709 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
710 | ||
711 | static tree pushdecl_with_scope PROTO((tree, struct binding_level *)); | |
712 | ||
713 | static void | |
714 | push_binding_level (newlevel, tag_transparent, keep) | |
715 | struct binding_level *newlevel; | |
716 | int tag_transparent, keep; | |
717 | { | |
718 | /* Add this level to the front of the chain (stack) of levels that | |
719 | are active. */ | |
720 | *newlevel = clear_binding_level; | |
721 | if (class_binding_level) | |
722 | { | |
723 | newlevel->level_chain = class_binding_level; | |
724 | class_binding_level = (struct binding_level *)0; | |
725 | } | |
726 | else | |
727 | { | |
728 | newlevel->level_chain = current_binding_level; | |
729 | } | |
730 | current_binding_level = newlevel; | |
731 | newlevel->tag_transparent = tag_transparent; | |
732 | newlevel->more_cleanups_ok = 1; | |
8d08fdba MS |
733 | newlevel->keep = keep; |
734 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
735 | newlevel->binding_depth = binding_depth; | |
736 | indent (); | |
737 | fprintf (stderr, "push %s level 0x%08x line %d\n", | |
738 | (is_class_level) ? "class" : "block", newlevel, lineno); | |
739 | is_class_level = 0; | |
740 | binding_depth++; | |
741 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
742 | } | |
743 | ||
744 | static void | |
745 | pop_binding_level () | |
746 | { | |
747 | if (class_binding_level) | |
748 | current_binding_level = class_binding_level; | |
749 | ||
750 | if (global_binding_level) | |
751 | { | |
e92cc029 | 752 | /* cannot pop a level, if there are none left to pop. */ |
8d08fdba MS |
753 | if (current_binding_level == global_binding_level) |
754 | my_friendly_abort (123); | |
755 | } | |
756 | /* Pop the current level, and free the structure for reuse. */ | |
757 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
758 | binding_depth--; | |
759 | indent (); | |
760 | fprintf (stderr, "pop %s level 0x%08x line %d\n", | |
761 | (is_class_level) ? "class" : "block", | |
762 | current_binding_level, lineno); | |
763 | if (is_class_level != (current_binding_level == class_binding_level)) | |
9e9ff709 MS |
764 | { |
765 | indent (); | |
766 | fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); | |
767 | } | |
8d08fdba MS |
768 | is_class_level = 0; |
769 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
770 | { | |
771 | register struct binding_level *level = current_binding_level; | |
772 | current_binding_level = current_binding_level->level_chain; | |
773 | level->level_chain = free_binding_level; | |
774 | #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
775 | if (level->binding_depth != binding_depth) | |
776 | abort (); | |
777 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
778 | free_binding_level = level; | |
779 | ||
780 | class_binding_level = current_binding_level; | |
781 | if (class_binding_level->parm_flag != 2) | |
782 | class_binding_level = 0; | |
783 | while (current_binding_level->parm_flag == 2) | |
784 | current_binding_level = current_binding_level->level_chain; | |
785 | } | |
786 | } | |
a9aedbc2 MS |
787 | |
788 | static void | |
789 | suspend_binding_level () | |
790 | { | |
791 | if (class_binding_level) | |
792 | current_binding_level = class_binding_level; | |
793 | ||
794 | if (global_binding_level) | |
795 | { | |
e92cc029 | 796 | /* cannot suspend a level, if there are none left to suspend. */ |
a9aedbc2 MS |
797 | if (current_binding_level == global_binding_level) |
798 | my_friendly_abort (123); | |
799 | } | |
800 | /* Suspend the current level. */ | |
801 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
802 | binding_depth--; | |
803 | indent (); | |
804 | fprintf (stderr, "suspend %s level 0x%08x line %d\n", | |
805 | (is_class_level) ? "class" : "block", | |
806 | current_binding_level, lineno); | |
807 | if (is_class_level != (current_binding_level == class_binding_level)) | |
9e9ff709 MS |
808 | { |
809 | indent (); | |
810 | fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); | |
811 | } | |
a9aedbc2 MS |
812 | is_class_level = 0; |
813 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
814 | { | |
a9aedbc2 | 815 | current_binding_level = current_binding_level->level_chain; |
a9aedbc2 MS |
816 | class_binding_level = current_binding_level; |
817 | if (class_binding_level->parm_flag != 2) | |
818 | class_binding_level = 0; | |
819 | while (current_binding_level->parm_flag == 2) | |
820 | current_binding_level = current_binding_level->level_chain; | |
821 | } | |
822 | } | |
823 | ||
824b9a4c | 824 | static void |
a9aedbc2 MS |
825 | resume_binding_level (b) |
826 | struct binding_level *b; | |
827 | { | |
828 | if (class_binding_level) | |
829 | { | |
830 | #if 1 | |
e92cc029 | 831 | /* These are here because we cannot deal with shadows yet. */ |
a9aedbc2 MS |
832 | sorry ("cannot resume a namespace inside class"); |
833 | return; | |
834 | #else | |
835 | b->level_chain = class_binding_level; | |
836 | class_binding_level = (struct binding_level *)0; | |
837 | #endif | |
838 | } | |
839 | else | |
840 | { | |
841 | #if 1 | |
e92cc029 | 842 | /* These are here because we cannot deal with shadows yet. */ |
a9aedbc2 MS |
843 | if (b->level_chain != current_binding_level) |
844 | { | |
845 | sorry ("cannot resume a namespace inside a different namespace"); | |
846 | return; | |
847 | } | |
848 | #endif | |
849 | b->level_chain = current_binding_level; | |
850 | } | |
851 | current_binding_level = b; | |
852 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
853 | b->binding_depth = binding_depth; | |
854 | indent (); | |
855 | fprintf (stderr, "resume %s level 0x%08x line %d\n", | |
856 | (is_class_level) ? "class" : "block", b, lineno); | |
857 | is_class_level = 0; | |
858 | binding_depth++; | |
859 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
860 | } | |
8d08fdba | 861 | \f |
cffa8729 MS |
862 | /* Create a new `struct binding_level'. */ |
863 | ||
864 | static | |
865 | struct binding_level * | |
866 | make_binding_level () | |
867 | { | |
868 | /* NOSTRICT */ | |
869 | return (struct binding_level *) xmalloc (sizeof (struct binding_level)); | |
870 | } | |
871 | ||
8d08fdba MS |
872 | /* Nonzero if we are currently in the global binding level. */ |
873 | ||
874 | int | |
875 | global_bindings_p () | |
876 | { | |
877 | return current_binding_level == global_binding_level; | |
878 | } | |
879 | ||
a9aedbc2 MS |
880 | /* Nonzero if we are currently in a toplevel binding level. This |
881 | means either the global binding level or a namespace in a toplevel | |
882 | binding level. */ | |
883 | ||
884 | int | |
885 | toplevel_bindings_p () | |
886 | { | |
887 | struct binding_level *b = current_binding_level; | |
888 | ||
889 | while (1) | |
890 | { | |
891 | if (b == global_binding_level) | |
892 | return 1; | |
5566b478 MS |
893 | if (b->pseudo_global) |
894 | return 1; | |
a9aedbc2 MS |
895 | if (! b->namespace_p) |
896 | return 0; | |
897 | b=b->level_chain; | |
898 | } | |
899 | } | |
900 | ||
901 | /* Nonzero if this is a namespace scope. */ | |
902 | ||
824b9a4c | 903 | static int |
a9aedbc2 MS |
904 | namespace_bindings_p () |
905 | { | |
906 | return current_binding_level->namespace_p; | |
907 | } | |
908 | ||
8d08fdba MS |
909 | void |
910 | keep_next_level () | |
911 | { | |
912 | keep_next_level_flag = 1; | |
913 | } | |
914 | ||
915 | /* Nonzero if the current level needs to have a BLOCK made. */ | |
916 | ||
917 | int | |
918 | kept_level_p () | |
919 | { | |
920 | return (current_binding_level->blocks != NULL_TREE | |
921 | || current_binding_level->keep | |
922 | || current_binding_level->names != NULL_TREE | |
923 | || (current_binding_level->tags != NULL_TREE | |
924 | && !current_binding_level->tag_transparent)); | |
925 | } | |
926 | ||
927 | /* Identify this binding level as a level of parameters. */ | |
928 | ||
929 | void | |
930 | declare_parm_level () | |
931 | { | |
932 | current_binding_level->parm_flag = 1; | |
933 | } | |
934 | ||
8d08fdba MS |
935 | void |
936 | declare_pseudo_global_level () | |
937 | { | |
938 | current_binding_level->pseudo_global = 1; | |
939 | } | |
940 | ||
824b9a4c | 941 | static void |
a9aedbc2 MS |
942 | declare_namespace_level () |
943 | { | |
944 | current_binding_level->namespace_p = 1; | |
945 | } | |
946 | ||
8d08fdba MS |
947 | int |
948 | pseudo_global_level_p () | |
949 | { | |
950 | return current_binding_level->pseudo_global; | |
951 | } | |
952 | ||
953 | void | |
954 | set_class_shadows (shadows) | |
955 | tree shadows; | |
956 | { | |
957 | class_binding_level->class_shadowed = shadows; | |
958 | } | |
959 | ||
960 | /* Enter a new binding level. | |
961 | If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, | |
962 | not for that of tags. */ | |
963 | ||
964 | void | |
965 | pushlevel (tag_transparent) | |
966 | int tag_transparent; | |
967 | { | |
968 | register struct binding_level *newlevel = NULL_BINDING_LEVEL; | |
969 | ||
970 | /* If this is the top level of a function, | |
971 | just make sure that NAMED_LABELS is 0. | |
972 | They should have been set to 0 at the end of the previous function. */ | |
973 | ||
974 | if (current_binding_level == global_binding_level) | |
975 | my_friendly_assert (named_labels == NULL_TREE, 134); | |
976 | ||
977 | /* Reuse or create a struct for this binding level. */ | |
978 | ||
979 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
980 | if (0) | |
981 | #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
982 | if (free_binding_level) | |
983 | #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
984 | { | |
985 | newlevel = free_binding_level; | |
986 | free_binding_level = free_binding_level->level_chain; | |
987 | } | |
988 | else | |
989 | { | |
cffa8729 | 990 | newlevel = make_binding_level (); |
8d08fdba | 991 | } |
cffa8729 | 992 | |
8d08fdba MS |
993 | push_binding_level (newlevel, tag_transparent, keep_next_level_flag); |
994 | GNU_xref_start_scope ((HOST_WIDE_INT) newlevel); | |
995 | keep_next_level_flag = 0; | |
996 | } | |
997 | ||
5566b478 | 998 | void |
8d6e462b PB |
999 | note_level_for_for () |
1000 | { | |
1001 | current_binding_level->is_for_scope = 1; | |
1002 | } | |
1003 | ||
8d08fdba MS |
1004 | void |
1005 | pushlevel_temporary (tag_transparent) | |
1006 | int tag_transparent; | |
1007 | { | |
1008 | pushlevel (tag_transparent); | |
1009 | current_binding_level->keep = 2; | |
1010 | clear_last_expr (); | |
1011 | ||
1012 | /* Note we don't call push_momentary() here. Otherwise, it would cause | |
1013 | cleanups to be allocated on the momentary obstack, and they will be | |
1014 | overwritten by the next statement. */ | |
1015 | ||
1016 | expand_start_bindings (0); | |
1017 | } | |
1018 | ||
1019 | /* Exit a binding level. | |
1020 | Pop the level off, and restore the state of the identifier-decl mappings | |
1021 | that were in effect when this level was entered. | |
1022 | ||
1023 | If KEEP == 1, this level had explicit declarations, so | |
1024 | and create a "block" (a BLOCK node) for the level | |
1025 | to record its declarations and subblocks for symbol table output. | |
1026 | ||
1027 | If KEEP == 2, this level's subblocks go to the front, | |
1028 | not the back of the current binding level. This happens, | |
1029 | for instance, when code for constructors and destructors | |
1030 | need to generate code at the end of a function which must | |
1031 | be moved up to the front of the function. | |
1032 | ||
1033 | If FUNCTIONBODY is nonzero, this level is the body of a function, | |
1034 | so create a block as if KEEP were set and also clear out all | |
1035 | label names. | |
1036 | ||
1037 | If REVERSE is nonzero, reverse the order of decls before putting | |
1038 | them into the BLOCK. */ | |
1039 | ||
1040 | tree | |
1041 | poplevel (keep, reverse, functionbody) | |
1042 | int keep; | |
1043 | int reverse; | |
1044 | int functionbody; | |
1045 | { | |
1046 | register tree link; | |
1047 | /* The chain of decls was accumulated in reverse order. | |
1048 | Put it into forward order, just for cleanliness. */ | |
1049 | tree decls; | |
1050 | int tmp = functionbody; | |
8d08fdba MS |
1051 | int real_functionbody = current_binding_level->keep == 2 |
1052 | ? ((functionbody = 0), tmp) : functionbody; | |
1053 | tree tags = functionbody >= 0 ? current_binding_level->tags : 0; | |
1054 | tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; | |
1055 | tree block = NULL_TREE; | |
1056 | tree decl; | |
1057 | int block_previously_created; | |
1058 | ||
1059 | GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, | |
1060 | (HOST_WIDE_INT) current_binding_level->level_chain, | |
1061 | current_binding_level->parm_flag, | |
5566b478 | 1062 | current_binding_level->keep); |
8d08fdba MS |
1063 | |
1064 | if (current_binding_level->keep == 1) | |
1065 | keep = 1; | |
1066 | ||
8d08fdba MS |
1067 | /* Get the decls in the order they were written. |
1068 | Usually current_binding_level->names is in reverse order. | |
1069 | But parameter decls were previously put in forward order. */ | |
1070 | ||
1071 | if (reverse) | |
1072 | current_binding_level->names | |
1073 | = decls = nreverse (current_binding_level->names); | |
1074 | else | |
1075 | decls = current_binding_level->names; | |
1076 | ||
1077 | /* Output any nested inline functions within this block | |
1078 | if they weren't already output. */ | |
1079 | ||
1080 | for (decl = decls; decl; decl = TREE_CHAIN (decl)) | |
1081 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1082 | && ! TREE_ASM_WRITTEN (decl) | |
1083 | && DECL_INITIAL (decl) != NULL_TREE | |
6060a796 MS |
1084 | && TREE_ADDRESSABLE (decl) |
1085 | && decl_function_context (decl) == current_function_decl) | |
8d08fdba MS |
1086 | { |
1087 | /* If this decl was copied from a file-scope decl | |
1088 | on account of a block-scope extern decl, | |
1089 | propagate TREE_ADDRESSABLE to the file-scope decl. */ | |
1090 | if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) | |
1091 | TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; | |
1092 | else | |
1093 | { | |
1094 | push_function_context (); | |
1095 | output_inline_function (decl); | |
1096 | pop_function_context (); | |
1097 | } | |
1098 | } | |
1099 | ||
1100 | /* If there were any declarations or structure tags in that level, | |
1101 | or if this level is a function body, | |
1102 | create a BLOCK to record them for the life of this function. */ | |
1103 | ||
1104 | block = NULL_TREE; | |
1105 | block_previously_created = (current_binding_level->this_block != NULL_TREE); | |
1106 | if (block_previously_created) | |
1107 | block = current_binding_level->this_block; | |
1108 | else if (keep == 1 || functionbody) | |
1109 | block = make_node (BLOCK); | |
1110 | if (block != NULL_TREE) | |
1111 | { | |
72b7eeff MS |
1112 | if (block_previously_created) |
1113 | { | |
1114 | if (decls || tags || subblocks) | |
1115 | { | |
be99da77 | 1116 | if (BLOCK_VARS (block) || BLOCK_TYPE_TAGS (block)) |
72b7eeff MS |
1117 | { |
1118 | warning ("internal compiler error: debugging info corrupted"); | |
1119 | } | |
1120 | BLOCK_VARS (block) = decls; | |
1121 | BLOCK_TYPE_TAGS (block) = tags; | |
be99da77 MS |
1122 | |
1123 | /* We can have previous subblocks and new subblocks when | |
1124 | doing fixup_gotos with complex cleanups. We chain the new | |
1125 | subblocks onto the end of any pre-existing subblocks. */ | |
1126 | BLOCK_SUBBLOCKS (block) = chainon (BLOCK_SUBBLOCKS (block), | |
1127 | subblocks); | |
72b7eeff | 1128 | } |
be99da77 MS |
1129 | /* If we created the block earlier on, and we are just |
1130 | diddling it now, then it already should have a proper | |
1131 | BLOCK_END_NOTE value associated with it. */ | |
72b7eeff MS |
1132 | } |
1133 | else | |
1134 | { | |
1135 | BLOCK_VARS (block) = decls; | |
1136 | BLOCK_TYPE_TAGS (block) = tags; | |
1137 | BLOCK_SUBBLOCKS (block) = subblocks; | |
1138 | /* Otherwise, for a new block, install a new BLOCK_END_NOTE value. */ | |
1139 | remember_end_note (block); | |
1140 | } | |
8d08fdba MS |
1141 | } |
1142 | ||
1143 | /* In each subblock, record that this is its superior. */ | |
1144 | ||
1145 | if (keep >= 0) | |
1146 | for (link = subblocks; link; link = TREE_CHAIN (link)) | |
1147 | BLOCK_SUPERCONTEXT (link) = block; | |
1148 | ||
1149 | /* Clear out the meanings of the local variables of this level. */ | |
1150 | ||
8d6e462b PB |
1151 | if (current_binding_level->is_for_scope && flag_new_for_scope == 1) |
1152 | { | |
2ee887f2 | 1153 | struct binding_level *outer = current_binding_level->level_chain; |
8d6e462b PB |
1154 | for (link = decls; link; link = TREE_CHAIN (link)) |
1155 | { | |
1156 | if (TREE_CODE (link) == VAR_DECL) | |
1157 | DECL_DEAD_FOR_LOCAL (link) = 1; | |
e76a2646 MS |
1158 | else |
1159 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
8d6e462b | 1160 | } |
2ee887f2 MS |
1161 | |
1162 | /* Save declarations made in a 'for' statement so we can support pre-ANSI | |
e92cc029 | 1163 | 'for' scoping semantics. */ |
2ee887f2 MS |
1164 | |
1165 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1166 | { | |
1167 | tree id = TREE_PURPOSE (link); | |
1168 | tree decl = IDENTIFIER_LOCAL_VALUE (id); | |
1169 | ||
e76a2646 MS |
1170 | if (decl && DECL_DEAD_FOR_LOCAL (decl)) |
1171 | { | |
1172 | /* In this case keep the dead for-decl visible, | |
e92cc029 | 1173 | but remember what (if anything) it shadowed. */ |
e76a2646 MS |
1174 | DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link); |
1175 | TREE_CHAIN (decl) = outer->dead_vars_from_for; | |
1176 | outer->dead_vars_from_for = decl; | |
1177 | } | |
1178 | else | |
1179 | IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link); | |
2ee887f2 | 1180 | } |
8d6e462b | 1181 | } |
e92cc029 | 1182 | else /* Not special for scope. */ |
8d6e462b PB |
1183 | { |
1184 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1185 | { | |
1186 | if (DECL_NAME (link) != NULL_TREE) | |
8d08fdba | 1187 | { |
8d6e462b PB |
1188 | /* If the ident. was used or addressed via a local extern decl, |
1189 | don't forget that fact. */ | |
1190 | if (DECL_EXTERNAL (link)) | |
1191 | { | |
1192 | if (TREE_USED (link)) | |
1193 | TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; | |
1194 | if (TREE_ADDRESSABLE (link)) | |
1195 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1196 | } | |
1197 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
8d08fdba | 1198 | } |
8d08fdba | 1199 | } |
8d08fdba | 1200 | |
2ee887f2 MS |
1201 | /* Restore all name-meanings of the outer levels |
1202 | that were shadowed by this level. */ | |
8d08fdba | 1203 | |
2ee887f2 MS |
1204 | for (link = current_binding_level->shadowed; |
1205 | link; link = TREE_CHAIN (link)) | |
1206 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1207 | ||
1208 | /* We first restore the regular decls and *then* the dead_vars_from_for | |
1209 | to handle this case: | |
1210 | ||
1211 | int i; // i#1 | |
1212 | { | |
1213 | for (int i; ; ) { ...} // i#2 | |
1214 | int i; // i#3 | |
1215 | } // we are here | |
1216 | ||
1217 | In this case, we want remove the binding for i#3, restoring | |
1218 | that of i#2. Then we want to remove the binding for i#2, | |
e92cc029 | 1219 | and restore that of i#1. */ |
2ee887f2 MS |
1220 | |
1221 | link = current_binding_level->dead_vars_from_for; | |
1222 | for (; link != NULL_TREE; link = TREE_CHAIN (link)) | |
8d6e462b | 1223 | { |
2ee887f2 MS |
1224 | tree id = DECL_NAME (link); |
1225 | if (IDENTIFIER_LOCAL_VALUE (id) == link) | |
1226 | IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link); | |
8d6e462b PB |
1227 | } |
1228 | ||
2ee887f2 MS |
1229 | for (link = current_binding_level->class_shadowed; |
1230 | link; link = TREE_CHAIN (link)) | |
1231 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1232 | for (link = current_binding_level->type_shadowed; | |
1233 | link; link = TREE_CHAIN (link)) | |
1234 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
8d6e462b | 1235 | } |
8d08fdba MS |
1236 | |
1237 | /* If the level being exited is the top level of a function, | |
1238 | check over all the labels. */ | |
1239 | ||
1240 | if (functionbody) | |
1241 | { | |
1242 | /* If this is the top level block of a function, | |
1243 | the vars are the function's parameters. | |
1244 | Don't leave them in the BLOCK because they are | |
1245 | found in the FUNCTION_DECL instead. */ | |
1246 | ||
1247 | BLOCK_VARS (block) = 0; | |
1248 | ||
1249 | /* Clear out the definitions of all label names, | |
1250 | since their scopes end here. */ | |
1251 | ||
1252 | for (link = named_labels; link; link = TREE_CHAIN (link)) | |
1253 | { | |
1254 | register tree label = TREE_VALUE (link); | |
1255 | ||
1256 | if (DECL_INITIAL (label) == NULL_TREE) | |
1257 | { | |
1258 | cp_error_at ("label `%D' used but not defined", label); | |
1259 | /* Avoid crashing later. */ | |
1260 | define_label (input_filename, 1, DECL_NAME (label)); | |
1261 | } | |
1262 | else if (warn_unused && !TREE_USED (label)) | |
1263 | cp_warning_at ("label `%D' defined but not used", label); | |
1264 | SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE); | |
1265 | ||
1266 | /* Put the labels into the "variables" of the | |
1267 | top-level block, so debugger can see them. */ | |
1268 | TREE_CHAIN (label) = BLOCK_VARS (block); | |
1269 | BLOCK_VARS (block) = label; | |
1270 | } | |
1271 | ||
1272 | named_labels = NULL_TREE; | |
1273 | } | |
1274 | ||
1275 | /* Any uses of undefined labels now operate under constraints | |
1276 | of next binding contour. */ | |
1277 | { | |
1278 | struct binding_level *level_chain; | |
1279 | level_chain = current_binding_level->level_chain; | |
1280 | if (level_chain) | |
1281 | { | |
e349ee73 MS |
1282 | struct named_label_list *labels; |
1283 | for (labels = named_label_uses; labels; labels = labels->next) | |
1284 | if (labels->binding_level == current_binding_level) | |
8d08fdba | 1285 | { |
e349ee73 MS |
1286 | labels->binding_level = level_chain; |
1287 | labels->names_in_scope = level_chain->names; | |
8d08fdba MS |
1288 | } |
1289 | } | |
1290 | } | |
1291 | ||
1292 | tmp = current_binding_level->keep; | |
1293 | ||
1294 | pop_binding_level (); | |
1295 | if (functionbody) | |
1296 | DECL_INITIAL (current_function_decl) = block; | |
1297 | else if (block) | |
1298 | { | |
1299 | if (!block_previously_created) | |
1300 | current_binding_level->blocks | |
1301 | = chainon (current_binding_level->blocks, block); | |
1302 | } | |
1303 | /* If we did not make a block for the level just exited, | |
1304 | any blocks made for inner levels | |
1305 | (since they cannot be recorded as subblocks in that level) | |
1306 | must be carried forward so they will later become subblocks | |
1307 | of something else. */ | |
1308 | else if (subblocks) | |
1309 | { | |
1310 | if (keep == 2) | |
1311 | current_binding_level->blocks | |
1312 | = chainon (subblocks, current_binding_level->blocks); | |
1313 | else | |
1314 | current_binding_level->blocks | |
1315 | = chainon (current_binding_level->blocks, subblocks); | |
1316 | } | |
1317 | ||
1318 | /* Take care of compiler's internal binding structures. */ | |
a4443a08 | 1319 | if (tmp == 2) |
8d08fdba | 1320 | { |
8d08fdba MS |
1321 | expand_end_bindings (getdecls (), keep, 1); |
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 | block = poplevel (keep, reverse, real_functionbody); | |
1328 | } | |
1329 | ||
1330 | /* Each and every BLOCK node created here in `poplevel' is important | |
1331 | (e.g. for proper debugging information) so if we created one | |
1332 | earlier, mark it as "used". */ | |
1333 | if (block) | |
1334 | TREE_USED (block) = 1; | |
1335 | return block; | |
1336 | } | |
1337 | ||
a9aedbc2 | 1338 | /* Resume a binding level for a namespace. */ |
e92cc029 | 1339 | |
a9aedbc2 MS |
1340 | void |
1341 | resume_level (b) | |
1342 | struct binding_level *b; | |
1343 | { | |
1344 | tree decls, link; | |
1345 | ||
1346 | resume_binding_level (b); | |
1347 | ||
1348 | /* Resume the variable caches. */ | |
1349 | decls = current_binding_level->names; | |
1350 | ||
1351 | /* Restore the meanings of the local variables of this level. */ | |
1352 | ||
1353 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1354 | { | |
cffa8729 MS |
1355 | /* If it doesn't have a name, there is nothing left to do with it. */ |
1356 | if (DECL_NAME (link) == NULL_TREE) | |
1357 | continue; | |
1358 | ||
1359 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link; | |
a9aedbc2 MS |
1360 | |
1361 | /* If this is a TYPE_DECL, push it into the type value slot. */ | |
1362 | if (TREE_CODE (link) == TYPE_DECL) | |
1363 | SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link)); | |
1364 | } | |
1365 | } | |
1366 | ||
8d08fdba MS |
1367 | /* Delete the node BLOCK from the current binding level. |
1368 | This is used for the block inside a stmt expr ({...}) | |
1369 | so that the block can be reinserted where appropriate. */ | |
1370 | ||
1371 | void | |
1372 | delete_block (block) | |
1373 | tree block; | |
1374 | { | |
1375 | tree t; | |
1376 | if (current_binding_level->blocks == block) | |
1377 | current_binding_level->blocks = TREE_CHAIN (block); | |
1378 | for (t = current_binding_level->blocks; t;) | |
1379 | { | |
1380 | if (TREE_CHAIN (t) == block) | |
1381 | TREE_CHAIN (t) = TREE_CHAIN (block); | |
1382 | else | |
1383 | t = TREE_CHAIN (t); | |
1384 | } | |
1385 | TREE_CHAIN (block) = NULL_TREE; | |
1386 | /* Clear TREE_USED which is always set by poplevel. | |
1387 | The flag is set again if insert_block is called. */ | |
1388 | TREE_USED (block) = 0; | |
1389 | } | |
1390 | ||
1391 | /* Insert BLOCK at the end of the list of subblocks of the | |
1392 | current binding level. This is used when a BIND_EXPR is expanded, | |
1393 | to handle the BLOCK node inside the BIND_EXPR. */ | |
1394 | ||
1395 | void | |
1396 | insert_block (block) | |
1397 | tree block; | |
1398 | { | |
1399 | TREE_USED (block) = 1; | |
1400 | current_binding_level->blocks | |
1401 | = chainon (current_binding_level->blocks, block); | |
1402 | } | |
1403 | ||
8d08fdba MS |
1404 | /* Set the BLOCK node for the innermost scope |
1405 | (the one we are currently in). */ | |
1406 | ||
1407 | void | |
1408 | set_block (block) | |
1409 | register tree block; | |
1410 | { | |
1411 | current_binding_level->this_block = block; | |
1412 | } | |
1413 | ||
1414 | /* Do a pushlevel for class declarations. */ | |
e92cc029 | 1415 | |
8d08fdba MS |
1416 | void |
1417 | pushlevel_class () | |
1418 | { | |
1419 | register struct binding_level *newlevel; | |
1420 | ||
1421 | /* Reuse or create a struct for this binding level. */ | |
1422 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
1423 | if (0) | |
1424 | #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
1425 | if (free_binding_level) | |
1426 | #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
1427 | { | |
1428 | newlevel = free_binding_level; | |
1429 | free_binding_level = free_binding_level->level_chain; | |
1430 | } | |
1431 | else | |
1432 | { | |
cffa8729 | 1433 | newlevel = make_binding_level (); |
8d08fdba MS |
1434 | } |
1435 | ||
1436 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
1437 | is_class_level = 1; | |
1438 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
1439 | ||
1440 | push_binding_level (newlevel, 0, 0); | |
1441 | ||
1442 | decl_stack = push_decl_level (decl_stack, &decl_obstack); | |
1443 | class_binding_level = current_binding_level; | |
1444 | class_binding_level->parm_flag = 2; | |
1445 | /* We have just pushed into a new binding level. Now, fake out the rest | |
1446 | of the compiler. Set the `current_binding_level' back to point to | |
1447 | the most closely containing non-class binding level. */ | |
1448 | do | |
1449 | { | |
1450 | current_binding_level = current_binding_level->level_chain; | |
1451 | } | |
1452 | while (current_binding_level->parm_flag == 2); | |
1453 | } | |
1454 | ||
700f8a87 MS |
1455 | /* ...and a poplevel for class declarations. FORCE is used to force |
1456 | clearing out of CLASS_VALUEs after a class definition. */ | |
e92cc029 | 1457 | |
8d08fdba | 1458 | tree |
700f8a87 MS |
1459 | poplevel_class (force) |
1460 | int force; | |
8d08fdba MS |
1461 | { |
1462 | register struct binding_level *level = class_binding_level; | |
1463 | tree block = NULL_TREE; | |
1464 | tree shadowed; | |
1465 | ||
1466 | my_friendly_assert (level != 0, 354); | |
1467 | ||
1468 | decl_stack = pop_stack_level (decl_stack); | |
1469 | for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
1470 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1471 | /* If we're leaving a toplevel class, don't bother to do the setting | |
ddd5a7c1 | 1472 | of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot |
8d08fdba | 1473 | shouldn't even be used when current_class_type isn't set, and second, |
ddd5a7c1 | 1474 | if we don't touch it here, we're able to use the cache effect if the |
8d08fdba | 1475 | next time we're entering a class scope, it is the same class. */ |
700f8a87 | 1476 | if (current_class_depth != 1 || force) |
8d08fdba MS |
1477 | for (shadowed = level->class_shadowed; |
1478 | shadowed; | |
1479 | shadowed = TREE_CHAIN (shadowed)) | |
1480 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1481 | else | |
1482 | /* Remember to save what IDENTIFIER's were bound in this scope so we | |
1483 | can recover from cache misses. */ | |
e76a2646 MS |
1484 | { |
1485 | previous_class_type = current_class_type; | |
1486 | previous_class_values = class_binding_level->class_shadowed; | |
1487 | } | |
8d08fdba MS |
1488 | for (shadowed = level->type_shadowed; |
1489 | shadowed; | |
1490 | shadowed = TREE_CHAIN (shadowed)) | |
1491 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1492 | ||
1493 | GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, | |
1494 | (HOST_WIDE_INT) class_binding_level->level_chain, | |
1495 | class_binding_level->parm_flag, | |
5566b478 | 1496 | class_binding_level->keep); |
8d08fdba MS |
1497 | |
1498 | if (class_binding_level->parm_flag != 2) | |
1499 | class_binding_level = (struct binding_level *)0; | |
1500 | ||
1501 | /* Now, pop out of the the binding level which we created up in the | |
1502 | `pushlevel_class' routine. */ | |
1503 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
1504 | is_class_level = 1; | |
1505 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
1506 | ||
1507 | pop_binding_level (); | |
1508 | ||
1509 | return block; | |
1510 | } | |
1511 | \f | |
1512 | /* For debugging. */ | |
5566b478 MS |
1513 | static int no_print_functions = 0; |
1514 | static int no_print_builtins = 0; | |
8d08fdba MS |
1515 | |
1516 | void | |
1517 | print_binding_level (lvl) | |
1518 | struct binding_level *lvl; | |
1519 | { | |
1520 | tree t; | |
1521 | int i = 0, len; | |
1522 | fprintf (stderr, " blocks="); | |
1523 | fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks); | |
1524 | fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d", | |
f30432d7 | 1525 | list_length (lvl->incomplete), lvl->parm_flag, lvl->keep); |
8d08fdba MS |
1526 | if (lvl->tag_transparent) |
1527 | fprintf (stderr, " tag-transparent"); | |
1528 | if (lvl->more_cleanups_ok) | |
1529 | fprintf (stderr, " more-cleanups-ok"); | |
1530 | if (lvl->have_cleanups) | |
1531 | fprintf (stderr, " have-cleanups"); | |
8d08fdba MS |
1532 | fprintf (stderr, "\n"); |
1533 | if (lvl->names) | |
1534 | { | |
1535 | fprintf (stderr, " names:\t"); | |
1536 | /* We can probably fit 3 names to a line? */ | |
1537 | for (t = lvl->names; t; t = TREE_CHAIN (t)) | |
1538 | { | |
fc378698 | 1539 | if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL)) |
8d08fdba MS |
1540 | continue; |
1541 | if (no_print_builtins | |
fc378698 MS |
1542 | && (TREE_CODE (t) == TYPE_DECL) |
1543 | && (!strcmp (DECL_SOURCE_FILE (t),"<built-in>"))) | |
8d08fdba MS |
1544 | continue; |
1545 | ||
1546 | /* Function decls tend to have longer names. */ | |
1547 | if (TREE_CODE (t) == FUNCTION_DECL) | |
1548 | len = 3; | |
1549 | else | |
1550 | len = 2; | |
1551 | i += len; | |
1552 | if (i > 6) | |
1553 | { | |
1554 | fprintf (stderr, "\n\t"); | |
1555 | i = len; | |
1556 | } | |
1557 | print_node_brief (stderr, "", t, 0); | |
bd6dd845 | 1558 | if (t == error_mark_node) |
8d08fdba MS |
1559 | break; |
1560 | } | |
1561 | if (i) | |
1562 | fprintf (stderr, "\n"); | |
1563 | } | |
1564 | if (lvl->tags) | |
1565 | { | |
1566 | fprintf (stderr, " tags:\t"); | |
1567 | i = 0; | |
1568 | for (t = lvl->tags; t; t = TREE_CHAIN (t)) | |
1569 | { | |
1570 | if (TREE_PURPOSE (t) == NULL_TREE) | |
1571 | len = 3; | |
1572 | else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) | |
1573 | len = 2; | |
1574 | else | |
1575 | len = 4; | |
1576 | i += len; | |
1577 | if (i > 5) | |
1578 | { | |
1579 | fprintf (stderr, "\n\t"); | |
1580 | i = len; | |
1581 | } | |
1582 | if (TREE_PURPOSE (t) == NULL_TREE) | |
1583 | { | |
1584 | print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0); | |
1585 | fprintf (stderr, ">"); | |
1586 | } | |
1587 | else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) | |
1588 | print_node_brief (stderr, "", TREE_VALUE (t), 0); | |
1589 | else | |
1590 | { | |
1591 | print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0); | |
1592 | print_node_brief (stderr, "", TREE_VALUE (t), 0); | |
1593 | fprintf (stderr, ">"); | |
1594 | } | |
1595 | } | |
1596 | if (i) | |
1597 | fprintf (stderr, "\n"); | |
1598 | } | |
1599 | if (lvl->shadowed) | |
1600 | { | |
1601 | fprintf (stderr, " shadowed:"); | |
1602 | for (t = lvl->shadowed; t; t = TREE_CHAIN (t)) | |
1603 | { | |
1604 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
1605 | } | |
1606 | fprintf (stderr, "\n"); | |
1607 | } | |
1608 | if (lvl->class_shadowed) | |
1609 | { | |
1610 | fprintf (stderr, " class-shadowed:"); | |
1611 | for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t)) | |
1612 | { | |
1613 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
1614 | } | |
1615 | fprintf (stderr, "\n"); | |
1616 | } | |
1617 | if (lvl->type_shadowed) | |
1618 | { | |
1619 | fprintf (stderr, " type-shadowed:"); | |
1620 | for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t)) | |
1621 | { | |
8d08fdba | 1622 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); |
8d08fdba MS |
1623 | } |
1624 | fprintf (stderr, "\n"); | |
1625 | } | |
1626 | } | |
1627 | ||
1628 | void | |
1629 | print_other_binding_stack (stack) | |
1630 | struct binding_level *stack; | |
1631 | { | |
1632 | struct binding_level *level; | |
1633 | for (level = stack; level != global_binding_level; level = level->level_chain) | |
1634 | { | |
1635 | fprintf (stderr, "binding level "); | |
1636 | fprintf (stderr, HOST_PTR_PRINTF, level); | |
1637 | fprintf (stderr, "\n"); | |
1638 | print_binding_level (level); | |
1639 | } | |
1640 | } | |
1641 | ||
1642 | void | |
1643 | print_binding_stack () | |
1644 | { | |
1645 | struct binding_level *b; | |
1646 | fprintf (stderr, "current_binding_level="); | |
1647 | fprintf (stderr, HOST_PTR_PRINTF, current_binding_level); | |
1648 | fprintf (stderr, "\nclass_binding_level="); | |
1649 | fprintf (stderr, HOST_PTR_PRINTF, class_binding_level); | |
1650 | fprintf (stderr, "\nglobal_binding_level="); | |
1651 | fprintf (stderr, HOST_PTR_PRINTF, global_binding_level); | |
1652 | fprintf (stderr, "\n"); | |
1653 | if (class_binding_level) | |
1654 | { | |
1655 | for (b = class_binding_level; b; b = b->level_chain) | |
1656 | if (b == current_binding_level) | |
1657 | break; | |
1658 | if (b) | |
1659 | b = class_binding_level; | |
1660 | else | |
1661 | b = current_binding_level; | |
1662 | } | |
1663 | else | |
1664 | b = current_binding_level; | |
1665 | print_other_binding_stack (b); | |
1666 | fprintf (stderr, "global:\n"); | |
1667 | print_binding_level (global_binding_level); | |
1668 | } | |
a9aedbc2 | 1669 | |
30394414 JM |
1670 | /* Return the tree_binding for the name in the given scope |
1671 | If there are no bindings for the name in the scope, make a new | |
1672 | bindings node. This bindings list of this node will be empty, though. */ | |
1673 | ||
1674 | tree | |
1675 | binding_for_name (name, scope) | |
1676 | tree name; | |
1677 | tree scope; | |
1678 | { | |
1679 | tree iter; | |
1680 | for (iter = IDENTIFIER_NAMESPACE_BINDINGS (name); iter; | |
1681 | iter = TREE_CHAIN (iter)) | |
1682 | { | |
1683 | my_friendly_assert (TREE_CODE (iter) == CPLUS_BINDING, 374); | |
1684 | if (BINDING_SCOPE (iter) == scope) | |
1685 | return iter; | |
1686 | } | |
1687 | /* not found, make a new permanent one */ | |
1688 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
1689 | iter = make_node (CPLUS_BINDING); | |
1690 | TREE_CHAIN (iter) = IDENTIFIER_NAMESPACE_BINDINGS (name); | |
1691 | IDENTIFIER_NAMESPACE_BINDINGS (name) = iter; | |
1692 | BINDING_SCOPE (iter) = scope; | |
1693 | BINDING_VALUE (iter) = NULL_TREE; | |
1694 | pop_obstacks (); | |
1695 | return iter; | |
1696 | } | |
1697 | ||
dff6b454 RK |
1698 | extern char * first_global_object_name; |
1699 | ||
1700 | /* Get a unique name for each call to this routine for unnamed namespaces. | |
1701 | Mostly copied from get_file_function_name. */ | |
e92cc029 | 1702 | |
dff6b454 RK |
1703 | static tree |
1704 | get_unique_name () | |
1705 | { | |
1706 | static int temp_name_counter = 0; | |
1707 | char *buf; | |
1708 | register char *p; | |
1709 | ||
1710 | if (first_global_object_name) | |
1711 | p = first_global_object_name; | |
1712 | else if (main_input_filename) | |
1713 | p = main_input_filename; | |
1714 | else | |
1715 | p = input_filename; | |
1716 | ||
1717 | #define UNNAMED_NAMESPACE_FORMAT "__%s_%d" | |
1718 | ||
1719 | buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p)); | |
1720 | ||
1721 | sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++); | |
1722 | ||
1723 | /* Don't need to pull weird characters out of global names. */ | |
1724 | if (p != first_global_object_name) | |
1725 | { | |
30394414 | 1726 | for (p = buf+2; *p; p++) |
dff6b454 | 1727 | if (! ((*p >= '0' && *p <= '9') |
dff6b454 RK |
1728 | #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */ |
1729 | || *p == '$' | |
1730 | #endif | |
e92cc029 | 1731 | #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */ |
dff6b454 RK |
1732 | || *p == '.' |
1733 | #endif | |
1734 | || (*p >= 'A' && *p <= 'Z') | |
1735 | || (*p >= 'a' && *p <= 'z'))) | |
1736 | *p = '_'; | |
1737 | } | |
1738 | ||
1739 | return get_identifier (buf); | |
1740 | } | |
1741 | ||
1742 | /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we | |
1743 | select a name that is unique to this compilation unit. */ | |
e92cc029 | 1744 | |
a9aedbc2 MS |
1745 | void |
1746 | push_namespace (name) | |
1747 | tree name; | |
1748 | { | |
6633d636 | 1749 | #if 1 |
30394414 JM |
1750 | tree d; |
1751 | int need_new = 1; | |
1752 | int implicit_use = 0; | |
1753 | int nodecl = 0; | |
1754 | if (!global_namespace) | |
1755 | { | |
1756 | /* this must be :: */ | |
1757 | my_friendly_assert (name == get_identifier ("::"), 377); | |
1758 | nodecl = 1; | |
1759 | } | |
1760 | else if (!name) | |
1761 | { | |
1762 | name = get_unique_name (); | |
1763 | implicit_use = 1; | |
1764 | } | |
1765 | else | |
1766 | { | |
1767 | /* check whether this is an extended namespace definition */ | |
1768 | d = IDENTIFIER_NAMESPACE_VALUE (name); | |
1769 | if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL) | |
1770 | need_new = 0; | |
1771 | } | |
6633d636 | 1772 | |
30394414 JM |
1773 | if (need_new) |
1774 | { | |
1775 | /* make a new namespace, binding the name to it */ | |
1776 | d = build_lang_decl (NAMESPACE_DECL, name, void_type_node); | |
1777 | if (!nodecl) | |
1778 | d = pushdecl (d); | |
1779 | } | |
1780 | if (implicit_use) | |
1781 | do_using_directive (d); | |
1782 | /* enter the name space */ | |
1783 | current_namespace = d; | |
1784 | ||
6633d636 | 1785 | #else |
a9aedbc2 MS |
1786 | tree old_id = get_namespace_id (); |
1787 | char *buf; | |
72b7eeff | 1788 | tree d; |
a9aedbc2 | 1789 | |
dff6b454 RK |
1790 | if (! name) |
1791 | { | |
abc95ed3 | 1792 | /* Create a truly ugly name! */ |
dff6b454 RK |
1793 | name = get_unique_name (); |
1794 | } | |
1795 | ||
72b7eeff MS |
1796 | d = build_lang_decl (NAMESPACE_DECL, name, void_type_node); |
1797 | ||
a9aedbc2 | 1798 | /* Mark them as external, so redeclaration_error_message doesn't think |
e92cc029 | 1799 | they are duplicates. */ |
72b7eeff | 1800 | |
a9aedbc2 MS |
1801 | DECL_EXTERNAL (d) = 1; |
1802 | d = pushdecl (d); | |
1803 | ||
1804 | if (NAMESPACE_LEVEL (d) == 0) | |
1805 | { | |
1806 | /* This is new for this compilation unit. */ | |
1807 | pushlevel (0); | |
1808 | declare_namespace_level (); | |
72b7eeff | 1809 | NAMESPACE_LEVEL (d) = current_binding_level; |
a9aedbc2 MS |
1810 | } |
1811 | else | |
72b7eeff | 1812 | resume_level (NAMESPACE_LEVEL (d)); |
a9aedbc2 | 1813 | |
e92cc029 | 1814 | /* This code is just is bit old now... */ |
a9aedbc2 MS |
1815 | current_namespace = tree_cons (NULL_TREE, name, current_namespace); |
1816 | buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0) | |
1817 | + IDENTIFIER_LENGTH (name)); | |
1818 | sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "", | |
1819 | IDENTIFIER_POINTER (name)); | |
1820 | TREE_PURPOSE (current_namespace) = get_identifier (buf); | |
6633d636 | 1821 | #endif |
a9aedbc2 MS |
1822 | } |
1823 | ||
1824 | /* Pop from the scope of the current namespace. */ | |
e92cc029 | 1825 | |
a9aedbc2 MS |
1826 | void |
1827 | pop_namespace () | |
1828 | { | |
30394414 JM |
1829 | #if 1 |
1830 | current_namespace = DECL_NAMESPACE (current_namespace); | |
1831 | #else | |
a9aedbc2 MS |
1832 | tree decls, link; |
1833 | current_namespace = TREE_CHAIN (current_namespace); | |
1834 | ||
e92cc029 | 1835 | /* Just in case we get out of sync. */ |
a9aedbc2 MS |
1836 | if (! namespace_bindings_p ()) |
1837 | poplevel (0, 0, 0); | |
1838 | ||
1839 | decls = current_binding_level->names; | |
1840 | ||
1841 | /* Clear out the meanings of the local variables of this level. */ | |
1842 | ||
1843 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1844 | { | |
1845 | if (DECL_NAME (link) != NULL_TREE) | |
1846 | { | |
1847 | /* If the ident. was used or addressed via a local extern decl, | |
1848 | don't forget that fact. */ | |
1849 | if (DECL_EXTERNAL (link)) | |
1850 | { | |
1851 | if (TREE_USED (link)) | |
1852 | TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; | |
1853 | if (TREE_ADDRESSABLE (link)) | |
1854 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1855 | } | |
1856 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
1857 | } | |
1858 | } | |
1859 | ||
1860 | /* Restore all name-meanings of the outer levels | |
1861 | that were shadowed by this level. */ | |
1862 | ||
1863 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1864 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1865 | for (link = current_binding_level->class_shadowed; | |
1866 | link; link = TREE_CHAIN (link)) | |
1867 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1868 | for (link = current_binding_level->type_shadowed; | |
1869 | link; link = TREE_CHAIN (link)) | |
1870 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1871 | ||
1872 | /* suspend a level. */ | |
1873 | suspend_binding_level (); | |
6633d636 | 1874 | #endif |
a9aedbc2 | 1875 | } |
8d08fdba MS |
1876 | \f |
1877 | /* Subroutines for reverting temporarily to top-level for instantiation | |
1878 | of templates and such. We actually need to clear out the class- and | |
1879 | local-value slots of all identifiers, so that only the global values | |
1880 | are at all visible. Simply setting current_binding_level to the global | |
1881 | scope isn't enough, because more binding levels may be pushed. */ | |
1882 | struct saved_scope { | |
1883 | struct binding_level *old_binding_level; | |
1884 | tree old_bindings; | |
1885 | struct saved_scope *prev; | |
5f34005f | 1886 | tree class_name, class_type, function_decl; |
8d08fdba | 1887 | struct binding_level *class_bindings; |
51c184be MS |
1888 | tree *lang_base, *lang_stack, lang_name; |
1889 | int lang_stacksize; | |
5566b478 MS |
1890 | int minimal_parse_mode; |
1891 | tree last_function_parms; | |
e76a2646 | 1892 | tree template_parms; |
5156628f | 1893 | HOST_WIDE_INT processing_template_decl; |
a50f0918 | 1894 | tree previous_class_type, previous_class_values; |
e1467ff2 MM |
1895 | int processing_specialization; |
1896 | int processing_explicit_instantiation; | |
8d08fdba MS |
1897 | }; |
1898 | static struct saved_scope *current_saved_scope; | |
8d08fdba | 1899 | |
e92cc029 | 1900 | static tree |
45537677 MS |
1901 | store_bindings (names, old_bindings) |
1902 | tree names, old_bindings; | |
1903 | { | |
1904 | tree t; | |
1905 | for (t = names; t; t = TREE_CHAIN (t)) | |
1906 | { | |
1907 | tree binding, t1, id; | |
1908 | ||
1909 | if (TREE_CODE (t) == TREE_LIST) | |
1910 | id = TREE_PURPOSE (t); | |
1911 | else | |
1912 | id = DECL_NAME (t); | |
1913 | ||
1914 | if (!id | |
1915 | || (!IDENTIFIER_LOCAL_VALUE (id) | |
1916 | && !IDENTIFIER_CLASS_VALUE (id))) | |
1917 | continue; | |
1918 | ||
1919 | for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) | |
1920 | if (TREE_VEC_ELT (t1, 0) == id) | |
1921 | goto skip_it; | |
1922 | ||
1923 | binding = make_tree_vec (4); | |
1924 | if (id) | |
1925 | { | |
1926 | my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); | |
1927 | TREE_VEC_ELT (binding, 0) = id; | |
1928 | TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id); | |
1929 | TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id); | |
1930 | TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); | |
1931 | IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE; | |
1932 | IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; | |
1933 | } | |
1934 | TREE_CHAIN (binding) = old_bindings; | |
1935 | old_bindings = binding; | |
1936 | skip_it: | |
1937 | ; | |
1938 | } | |
1939 | return old_bindings; | |
1940 | } | |
1941 | ||
8d08fdba | 1942 | void |
5566b478 MS |
1943 | maybe_push_to_top_level (pseudo) |
1944 | int pseudo; | |
8d08fdba | 1945 | { |
51c184be | 1946 | extern int current_lang_stacksize; |
beb53fb8 JM |
1947 | struct saved_scope *s |
1948 | = (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); | |
5566b478 | 1949 | struct binding_level *b = inner_binding_level; |
8d08fdba MS |
1950 | tree old_bindings = NULL_TREE; |
1951 | ||
e349ee73 MS |
1952 | if (current_function_decl) |
1953 | push_cp_function_context (NULL_TREE); | |
1954 | ||
a50f0918 MS |
1955 | if (previous_class_type) |
1956 | old_bindings = store_bindings (previous_class_values, old_bindings); | |
1957 | ||
8d08fdba MS |
1958 | /* Have to include global_binding_level, because class-level decls |
1959 | aren't listed anywhere useful. */ | |
1960 | for (; b; b = b->level_chain) | |
1961 | { | |
1962 | tree t; | |
1963 | ||
5566b478 MS |
1964 | if (b == global_binding_level || (pseudo && b->pseudo_global)) |
1965 | break; | |
8d08fdba | 1966 | |
45537677 | 1967 | old_bindings = store_bindings (b->names, old_bindings); |
cffa8729 | 1968 | /* We also need to check class_shadowed to save class-level type |
45537677 MS |
1969 | bindings, since pushclass doesn't fill in b->names. */ |
1970 | if (b->parm_flag == 2) | |
cffa8729 | 1971 | old_bindings = store_bindings (b->class_shadowed, old_bindings); |
8d08fdba | 1972 | |
8d08fdba MS |
1973 | /* Unwind type-value slots back to top level. */ |
1974 | for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) | |
1975 | SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); | |
1976 | } | |
8d08fdba MS |
1977 | |
1978 | s->old_binding_level = current_binding_level; | |
5566b478 | 1979 | current_binding_level = b; |
8d08fdba MS |
1980 | |
1981 | s->class_name = current_class_name; | |
1982 | s->class_type = current_class_type; | |
8d08fdba MS |
1983 | s->function_decl = current_function_decl; |
1984 | s->class_bindings = class_binding_level; | |
51c184be MS |
1985 | s->lang_stack = current_lang_stack; |
1986 | s->lang_base = current_lang_base; | |
1987 | s->lang_stacksize = current_lang_stacksize; | |
1988 | s->lang_name = current_lang_name; | |
5566b478 MS |
1989 | s->minimal_parse_mode = minimal_parse_mode; |
1990 | s->last_function_parms = last_function_parms; | |
e76a2646 | 1991 | s->template_parms = current_template_parms; |
5156628f | 1992 | s->processing_template_decl = processing_template_decl; |
a50f0918 MS |
1993 | s->previous_class_type = previous_class_type; |
1994 | s->previous_class_values = previous_class_values; | |
e1467ff2 MM |
1995 | s->processing_specialization = processing_specialization; |
1996 | s->processing_explicit_instantiation = processing_explicit_instantiation; | |
e349ee73 | 1997 | |
5f34005f | 1998 | current_class_name = current_class_type = NULL_TREE; |
8d08fdba MS |
1999 | current_function_decl = NULL_TREE; |
2000 | class_binding_level = (struct binding_level *)0; | |
51c184be MS |
2001 | current_lang_stacksize = 10; |
2002 | current_lang_stack = current_lang_base | |
2003 | = (tree *) xmalloc (current_lang_stacksize * sizeof (tree)); | |
2004 | current_lang_name = lang_name_cplusplus; | |
2005 | strict_prototype = strict_prototypes_lang_cplusplus; | |
2006 | named_labels = NULL_TREE; | |
5566b478 | 2007 | minimal_parse_mode = 0; |
a50f0918 | 2008 | previous_class_type = previous_class_values = NULL_TREE; |
e1467ff2 MM |
2009 | processing_specialization = 0; |
2010 | processing_explicit_instantiation = 0; | |
e76a2646 | 2011 | if (!pseudo) |
5156628f MS |
2012 | { |
2013 | current_template_parms = NULL_TREE; | |
2014 | processing_template_decl = 0; | |
2015 | } | |
8d08fdba MS |
2016 | |
2017 | s->prev = current_saved_scope; | |
2018 | s->old_bindings = old_bindings; | |
2019 | current_saved_scope = s; | |
5566b478 MS |
2020 | |
2021 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
2022 | } | |
2023 | ||
2024 | void | |
2025 | push_to_top_level () | |
2026 | { | |
2027 | maybe_push_to_top_level (0); | |
8d08fdba MS |
2028 | } |
2029 | ||
2030 | void | |
2031 | pop_from_top_level () | |
2032 | { | |
51c184be | 2033 | extern int current_lang_stacksize; |
8d08fdba MS |
2034 | struct saved_scope *s = current_saved_scope; |
2035 | tree t; | |
2036 | ||
e76a2646 | 2037 | /* Clear out class-level bindings cache. */ |
8d08fdba | 2038 | if (previous_class_type) |
e76a2646 MS |
2039 | { |
2040 | popclass (-1); | |
2041 | previous_class_type = NULL_TREE; | |
2042 | } | |
8d08fdba | 2043 | |
5566b478 MS |
2044 | pop_obstacks (); |
2045 | ||
8d08fdba MS |
2046 | current_binding_level = s->old_binding_level; |
2047 | current_saved_scope = s->prev; | |
2048 | for (t = s->old_bindings; t; t = TREE_CHAIN (t)) | |
2049 | { | |
2050 | tree id = TREE_VEC_ELT (t, 0); | |
2051 | if (id) | |
2052 | { | |
2053 | IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1); | |
2054 | IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2); | |
2055 | IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); | |
2056 | } | |
2057 | } | |
2058 | current_class_name = s->class_name; | |
2059 | current_class_type = s->class_type; | |
8d08fdba MS |
2060 | current_function_decl = s->function_decl; |
2061 | class_binding_level = s->class_bindings; | |
51c184be MS |
2062 | free (current_lang_base); |
2063 | current_lang_base = s->lang_base; | |
2064 | current_lang_stack = s->lang_stack; | |
2065 | current_lang_name = s->lang_name; | |
2066 | current_lang_stacksize = s->lang_stacksize; | |
2067 | if (current_lang_name == lang_name_cplusplus) | |
2068 | strict_prototype = strict_prototypes_lang_cplusplus; | |
2069 | else if (current_lang_name == lang_name_c) | |
2070 | strict_prototype = strict_prototypes_lang_c; | |
5566b478 MS |
2071 | minimal_parse_mode = s->minimal_parse_mode; |
2072 | last_function_parms = s->last_function_parms; | |
e76a2646 | 2073 | current_template_parms = s->template_parms; |
5156628f | 2074 | processing_template_decl = s->processing_template_decl; |
a50f0918 MS |
2075 | previous_class_type = s->previous_class_type; |
2076 | previous_class_values = s->previous_class_values; | |
e1467ff2 MM |
2077 | processing_specialization = s->processing_specialization; |
2078 | processing_explicit_instantiation = s->processing_explicit_instantiation; | |
51c184be | 2079 | |
8d08fdba | 2080 | free (s); |
e349ee73 MS |
2081 | |
2082 | if (current_function_decl) | |
2083 | pop_cp_function_context (NULL_TREE); | |
8d08fdba MS |
2084 | } |
2085 | \f | |
2086 | /* Push a definition of struct, union or enum tag "name". | |
2087 | into binding_level "b". "type" should be the type node, | |
2088 | We assume that the tag "name" is not already defined. | |
2089 | ||
2090 | Note that the definition may really be just a forward reference. | |
2091 | In that case, the TYPE_SIZE will be a NULL_TREE. | |
2092 | ||
e92cc029 | 2093 | C++ gratuitously puts all these tags in the name space. */ |
8d08fdba MS |
2094 | |
2095 | /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID, | |
2096 | record the shadowed value for this binding contour. TYPE is | |
2097 | the type that ID maps to. */ | |
2098 | ||
2099 | static void | |
2100 | set_identifier_type_value_with_scope (id, type, b) | |
2101 | tree id; | |
2102 | tree type; | |
2103 | struct binding_level *b; | |
2104 | { | |
2105 | if (b != global_binding_level) | |
2106 | { | |
2107 | tree old_type_value = IDENTIFIER_TYPE_VALUE (id); | |
2108 | b->type_shadowed | |
2109 | = tree_cons (id, old_type_value, b->type_shadowed); | |
2110 | } | |
2111 | SET_IDENTIFIER_TYPE_VALUE (id, type); | |
2112 | } | |
2113 | ||
e92cc029 | 2114 | /* As set_identifier_type_value_with_scope, but using inner_binding_level. */ |
8d08fdba MS |
2115 | |
2116 | void | |
2117 | set_identifier_type_value (id, type) | |
2118 | tree id; | |
2119 | tree type; | |
2120 | { | |
2121 | set_identifier_type_value_with_scope (id, type, inner_binding_level); | |
2122 | } | |
2123 | ||
a9aedbc2 MS |
2124 | /* Pop off extraneous binding levels left over due to syntax errors. |
2125 | ||
2126 | We don't pop past namespaces, as they might be valid. */ | |
e92cc029 | 2127 | |
8926095f MS |
2128 | void |
2129 | pop_everything () | |
2130 | { | |
2131 | #ifdef DEBUG_CP_BINDING_LEVELS | |
2132 | fprintf (stderr, "XXX entering pop_everything ()\n"); | |
2133 | #endif | |
a9aedbc2 | 2134 | while (! toplevel_bindings_p () && ! pseudo_global_level_p ()) |
8926095f MS |
2135 | { |
2136 | if (class_binding_level) | |
2137 | pop_nested_class (1); | |
2138 | else | |
2139 | poplevel (0, 0, 0); | |
2140 | } | |
2141 | #ifdef DEBUG_CP_BINDING_LEVELS | |
2142 | fprintf (stderr, "XXX leaving pop_everything ()\n"); | |
2143 | #endif | |
2144 | } | |
2145 | ||
8d08fdba | 2146 | /* Push a tag name NAME for struct/class/union/enum type TYPE. |
ddd5a7c1 | 2147 | Normally put into into the inner-most non-tag-transparent scope, |
8d08fdba | 2148 | but if GLOBALIZE is true, put it in the inner-most non-class scope. |
e92cc029 | 2149 | The latter is needed for implicit declarations. */ |
8d08fdba MS |
2150 | |
2151 | void | |
2152 | pushtag (name, type, globalize) | |
2153 | tree name, type; | |
2154 | int globalize; | |
2155 | { | |
2156 | register struct binding_level *b; | |
7177d104 | 2157 | tree context = 0; |
2986ae00 | 2158 | tree c_decl = 0; |
8d08fdba MS |
2159 | |
2160 | b = inner_binding_level; | |
2161 | while (b->tag_transparent | |
2162 | || (globalize && b->parm_flag == 2)) | |
2163 | b = b->level_chain; | |
2164 | ||
a9aedbc2 | 2165 | if (toplevel_bindings_p ()) |
8d08fdba MS |
2166 | b->tags = perm_tree_cons (name, type, b->tags); |
2167 | else | |
2168 | b->tags = saveable_tree_cons (name, type, b->tags); | |
2169 | ||
2170 | if (name) | |
2171 | { | |
7177d104 MS |
2172 | context = type ? TYPE_CONTEXT (type) : NULL_TREE; |
2173 | if (! context && ! globalize) | |
2174 | context = current_scope (); | |
2175 | if (context) | |
2986ae00 | 2176 | c_decl = TREE_CODE (context) == FUNCTION_DECL |
e1cd6e56 | 2177 | ? context : TYPE_MAIN_DECL (context); |
8d08fdba | 2178 | |
8d08fdba | 2179 | /* Do C++ gratuitous typedefing. */ |
db5ae43f | 2180 | if (IDENTIFIER_TYPE_VALUE (name) != type) |
8d08fdba MS |
2181 | { |
2182 | register tree d; | |
2183 | int newdecl = 0; | |
2184 | ||
2185 | if (b->parm_flag != 2 | |
2186 | || TYPE_SIZE (current_class_type) != NULL_TREE) | |
2187 | { | |
2986ae00 | 2188 | d = lookup_nested_type (type, c_decl); |
8d08fdba MS |
2189 | |
2190 | if (d == NULL_TREE) | |
2191 | { | |
2192 | newdecl = 1; | |
8d08fdba | 2193 | d = build_decl (TYPE_DECL, name, type); |
00595019 | 2194 | SET_DECL_ARTIFICIAL (d); |
8d08fdba MS |
2195 | set_identifier_type_value_with_scope (name, type, b); |
2196 | } | |
2197 | else | |
d2e5ee5c | 2198 | d = TYPE_MAIN_DECL (d); |
8d08fdba | 2199 | |
e1cd6e56 | 2200 | TYPE_NAME (type) = d; |
5566b478 | 2201 | DECL_CONTEXT (d) = context; |
5156628f | 2202 | if (! globalize && processing_template_decl && IS_AGGR_TYPE (type)) |
3ac3d9ea | 2203 | d = push_template_decl (d); |
e1cd6e56 | 2204 | |
faf5394a MS |
2205 | if (b->parm_flag == 2) |
2206 | d = pushdecl_class_level (d); | |
2207 | else | |
2208 | d = pushdecl_with_scope (d, b); | |
8d08fdba MS |
2209 | } |
2210 | else | |
2211 | { | |
2212 | /* Make nested declarations go into class-level scope. */ | |
2213 | newdecl = 1; | |
a0a33927 | 2214 | d = build_decl (TYPE_DECL, name, type); |
00595019 | 2215 | SET_DECL_ARTIFICIAL (d); |
d2e5ee5c | 2216 | TYPE_NAME (type) = d; |
5566b478 | 2217 | DECL_CONTEXT (d) = context; |
5156628f | 2218 | if (! globalize && processing_template_decl && IS_AGGR_TYPE (type)) |
3ac3d9ea | 2219 | d = push_template_decl (d); |
e1cd6e56 | 2220 | |
8d08fdba | 2221 | d = pushdecl_class_level (d); |
8d08fdba | 2222 | } |
8ccc31eb | 2223 | if (newdecl) |
8d08fdba | 2224 | { |
d2e5ee5c MS |
2225 | if (ANON_AGGRNAME_P (name)) |
2226 | DECL_IGNORED_P (d) = 1; | |
8ccc31eb | 2227 | |
5566b478 | 2228 | TYPE_CONTEXT (type) = DECL_CONTEXT (d); |
1f06b267 | 2229 | DECL_ASSEMBLER_NAME (d) = DECL_NAME (d); |
8ccc31eb MS |
2230 | DECL_ASSEMBLER_NAME (d) |
2231 | = get_identifier (build_overload_name (type, 1, 1)); | |
8d08fdba | 2232 | } |
8d08fdba MS |
2233 | } |
2234 | if (b->parm_flag == 2) | |
2235 | { | |
2236 | TREE_NONLOCAL_FLAG (type) = 1; | |
2237 | if (TYPE_SIZE (current_class_type) == NULL_TREE) | |
2238 | CLASSTYPE_TAGS (current_class_type) = b->tags; | |
2239 | } | |
2240 | } | |
2241 | ||
2242 | if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) | |
2243 | /* Use the canonical TYPE_DECL for this node. */ | |
2244 | TYPE_STUB_DECL (type) = TYPE_NAME (type); | |
2245 | else | |
2246 | { | |
2247 | /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE | |
2248 | will be the tagged type we just added to the current | |
2249 | binding level. This fake NULL-named TYPE_DECL node helps | |
2250 | dwarfout.c to know when it needs to output a | |
2251 | representation of a tagged type, and it also gives us a | |
2252 | convenient place to record the "scope start" address for | |
2253 | the tagged type. */ | |
2254 | ||
8d08fdba | 2255 | tree d = build_decl (TYPE_DECL, NULL_TREE, type); |
8d08fdba MS |
2256 | TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b); |
2257 | } | |
2258 | } | |
2259 | ||
2260 | /* Counter used to create anonymous type names. */ | |
e92cc029 | 2261 | |
8d08fdba MS |
2262 | static int anon_cnt = 0; |
2263 | ||
2264 | /* Return an IDENTIFIER which can be used as a name for | |
2265 | anonymous structs and unions. */ | |
e92cc029 | 2266 | |
8d08fdba MS |
2267 | tree |
2268 | make_anon_name () | |
2269 | { | |
2270 | char buf[32]; | |
2271 | ||
2272 | sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++); | |
2273 | return get_identifier (buf); | |
2274 | } | |
2275 | ||
2276 | /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames. | |
2277 | This keeps dbxout from getting confused. */ | |
e92cc029 | 2278 | |
8d08fdba MS |
2279 | void |
2280 | clear_anon_tags () | |
2281 | { | |
2282 | register struct binding_level *b; | |
2283 | register tree tags; | |
2284 | static int last_cnt = 0; | |
2285 | ||
2286 | /* Fast out if no new anon names were declared. */ | |
2287 | if (last_cnt == anon_cnt) | |
2288 | return; | |
2289 | ||
2290 | b = current_binding_level; | |
2291 | while (b->tag_transparent) | |
2292 | b = b->level_chain; | |
2293 | tags = b->tags; | |
2294 | while (tags) | |
2295 | { | |
2296 | /* A NULL purpose means we have already processed all tags | |
2297 | from here to the end of the list. */ | |
2298 | if (TREE_PURPOSE (tags) == NULL_TREE) | |
2299 | break; | |
2300 | if (ANON_AGGRNAME_P (TREE_PURPOSE (tags))) | |
2301 | TREE_PURPOSE (tags) = NULL_TREE; | |
2302 | tags = TREE_CHAIN (tags); | |
2303 | } | |
2304 | last_cnt = anon_cnt; | |
2305 | } | |
2306 | \f | |
2307 | /* Subroutine of duplicate_decls: return truthvalue of whether | |
2308 | or not types of these decls match. | |
2309 | ||
2310 | For C++, we must compare the parameter list so that `int' can match | |
2311 | `int&' in a parameter position, but `int&' is not confused with | |
2312 | `const int&'. */ | |
e92cc029 | 2313 | |
6060a796 | 2314 | int |
8d08fdba MS |
2315 | decls_match (newdecl, olddecl) |
2316 | tree newdecl, olddecl; | |
2317 | { | |
2318 | int types_match; | |
2319 | ||
a28e3c7f MS |
2320 | if (TREE_CODE (newdecl) == FUNCTION_DECL |
2321 | && TREE_CODE (olddecl) == FUNCTION_DECL) | |
8d08fdba MS |
2322 | { |
2323 | tree f1 = TREE_TYPE (newdecl); | |
2324 | tree f2 = TREE_TYPE (olddecl); | |
2325 | tree p1 = TYPE_ARG_TYPES (f1); | |
2326 | tree p2 = TYPE_ARG_TYPES (f2); | |
2327 | ||
2328 | /* When we parse a static member function definition, | |
2329 | we put together a FUNCTION_DECL which thinks its type | |
2330 | is METHOD_TYPE. Change that to FUNCTION_TYPE, and | |
2331 | proceed. */ | |
2332 | if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl)) | |
700f8a87 | 2333 | revert_static_member_fn (&newdecl, &f1, &p1); |
8d08fdba MS |
2334 | else if (TREE_CODE (f2) == METHOD_TYPE |
2335 | && DECL_STATIC_FUNCTION_P (newdecl)) | |
700f8a87 | 2336 | revert_static_member_fn (&olddecl, &f2, &p2); |
8d08fdba MS |
2337 | |
2338 | /* Here we must take care of the case where new default | |
2339 | parameters are specified. Also, warn if an old | |
2340 | declaration becomes ambiguous because default | |
2341 | parameters may cause the two to be ambiguous. */ | |
2342 | if (TREE_CODE (f1) != TREE_CODE (f2)) | |
2343 | { | |
2344 | if (TREE_CODE (f1) == OFFSET_TYPE) | |
2345 | cp_compiler_error ("`%D' redeclared as member function", newdecl); | |
2346 | else | |
2347 | cp_compiler_error ("`%D' redeclared as non-member function", newdecl); | |
2348 | return 0; | |
2349 | } | |
2350 | ||
39211cd5 | 2351 | if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1)) |
8926095f | 2352 | { |
a28e3c7f | 2353 | if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c |
8926095f | 2354 | && p2 == NULL_TREE) |
a28e3c7f MS |
2355 | { |
2356 | types_match = self_promoting_args_p (p1); | |
2357 | if (p1 == void_list_node) | |
2358 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl); | |
2359 | } | |
2360 | else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c | |
2361 | && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE) | |
2362 | { | |
2363 | types_match = self_promoting_args_p (p2); | |
2364 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl); | |
2365 | } | |
8926095f | 2366 | else |
a4443a08 | 2367 | types_match = compparms (p1, p2, 3); |
8926095f | 2368 | } |
8d08fdba MS |
2369 | else |
2370 | types_match = 0; | |
2371 | } | |
51c184be MS |
2372 | else if (TREE_CODE (newdecl) == TEMPLATE_DECL |
2373 | && TREE_CODE (olddecl) == TEMPLATE_DECL) | |
2374 | { | |
f84b4be9 JM |
2375 | if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), |
2376 | DECL_TEMPLATE_PARMS (olddecl))) | |
2377 | return 0; | |
2378 | ||
2379 | if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) | |
2380 | types_match = 1; | |
2381 | else | |
2382 | types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl), | |
2383 | DECL_TEMPLATE_RESULT (newdecl)); | |
51c184be | 2384 | } |
8d08fdba MS |
2385 | else |
2386 | { | |
2387 | if (TREE_TYPE (newdecl) == error_mark_node) | |
2388 | types_match = TREE_TYPE (olddecl) == error_mark_node; | |
2389 | else if (TREE_TYPE (olddecl) == NULL_TREE) | |
2390 | types_match = TREE_TYPE (newdecl) == NULL_TREE; | |
a0a33927 MS |
2391 | else if (TREE_TYPE (newdecl) == NULL_TREE) |
2392 | types_match = 0; | |
72b7eeff MS |
2393 | /* Qualifiers must match, and they may be present on either, the type |
2394 | or the decl. */ | |
2395 | else if ((TREE_READONLY (newdecl) | |
2396 | || TYPE_READONLY (TREE_TYPE (newdecl))) | |
2397 | == (TREE_READONLY (olddecl) | |
2398 | || TYPE_READONLY (TREE_TYPE (olddecl))) | |
2399 | && (TREE_THIS_VOLATILE (newdecl) | |
2400 | || TYPE_VOLATILE (TREE_TYPE (newdecl))) | |
2401 | == (TREE_THIS_VOLATILE (olddecl) | |
2402 | || TYPE_VOLATILE (TREE_TYPE (olddecl)))) | |
2403 | types_match = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (newdecl)), | |
2404 | TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)), 1); | |
8d08fdba | 2405 | else |
72b7eeff | 2406 | types_match = 0; |
8d08fdba MS |
2407 | } |
2408 | ||
2409 | return types_match; | |
2410 | } | |
2411 | ||
2412 | /* If NEWDECL is `static' and an `extern' was seen previously, | |
2413 | warn about it. (OLDDECL may be NULL_TREE; NAME contains | |
2414 | information about previous usage as an `extern'.) | |
2415 | ||
2416 | Note that this does not apply to the C++ case of declaring | |
2417 | a variable `extern const' and then later `const'. | |
2418 | ||
8d08fdba MS |
2419 | Don't complain about built-in functions, since they are beyond |
2420 | the user's control. */ | |
2421 | ||
2422 | static void | |
2423 | warn_extern_redeclared_static (newdecl, olddecl) | |
2424 | tree newdecl, olddecl; | |
2425 | { | |
2426 | tree name; | |
2427 | ||
2428 | static char *explicit_extern_static_warning | |
2429 | = "`%D' was declared `extern' and later `static'"; | |
2430 | static char *implicit_extern_static_warning | |
2431 | = "`%D' was declared implicitly `extern' and later `static'"; | |
2432 | ||
d22c8596 | 2433 | if (TREE_CODE (newdecl) == TYPE_DECL) |
8d08fdba MS |
2434 | return; |
2435 | ||
2436 | name = DECL_ASSEMBLER_NAME (newdecl); | |
faae18ab | 2437 | if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl)) |
8d08fdba MS |
2438 | { |
2439 | /* It's okay to redeclare an ANSI built-in function as static, | |
2440 | or to declare a non-ANSI built-in function as anything. */ | |
2441 | if (! (TREE_CODE (newdecl) == FUNCTION_DECL | |
2442 | && olddecl != NULL_TREE | |
2443 | && TREE_CODE (olddecl) == FUNCTION_DECL | |
2444 | && (DECL_BUILT_IN (olddecl) | |
2445 | || DECL_BUILT_IN_NONANSI (olddecl)))) | |
2446 | { | |
a9aedbc2 | 2447 | cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name) |
8d08fdba MS |
2448 | ? implicit_extern_static_warning |
2449 | : explicit_extern_static_warning, newdecl); | |
2450 | if (olddecl != NULL_TREE) | |
a9aedbc2 | 2451 | cp_pedwarn_at ("previous declaration of `%D'", olddecl); |
8d08fdba MS |
2452 | } |
2453 | } | |
2454 | } | |
2455 | ||
2456 | /* Handle when a new declaration NEWDECL has the same name as an old | |
2457 | one OLDDECL in the same binding contour. Prints an error message | |
2458 | if appropriate. | |
2459 | ||
2460 | If safely possible, alter OLDDECL to look like NEWDECL, and return 1. | |
2461 | Otherwise, return 0. */ | |
2462 | ||
51c184be | 2463 | int |
8d08fdba | 2464 | duplicate_decls (newdecl, olddecl) |
824b9a4c | 2465 | tree newdecl, olddecl; |
8d08fdba MS |
2466 | { |
2467 | extern struct obstack permanent_obstack; | |
2468 | unsigned olddecl_uid = DECL_UID (olddecl); | |
2469 | int olddecl_friend = 0, types_match = 0; | |
2470 | int new_defines_function; | |
5566b478 MS |
2471 | |
2472 | if (newdecl == olddecl) | |
2473 | return 1; | |
8d08fdba | 2474 | |
f6abb50a | 2475 | if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd') |
d9525bec BK |
2476 | DECL_MACHINE_ATTRIBUTES (newdecl) |
2477 | = merge_machine_decl_attributes (olddecl, newdecl); | |
f6abb50a | 2478 | |
8926095f | 2479 | types_match = decls_match (newdecl, olddecl); |
8d08fdba MS |
2480 | |
2481 | if (TREE_CODE (olddecl) != TREE_LIST) | |
2482 | olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl); | |
2483 | ||
2484 | /* If either the type of the new decl or the type of the old decl is an | |
2485 | error_mark_node, then that implies that we have already issued an | |
2486 | error (earlier) for some bogus type specification, and in that case, | |
2487 | it is rather pointless to harass the user with yet more error message | |
2488 | about the same declaration, so well just pretent the types match here. */ | |
bd6dd845 MS |
2489 | if (TREE_TYPE (newdecl) == error_mark_node |
2490 | || TREE_TYPE (olddecl) == error_mark_node) | |
8d08fdba MS |
2491 | types_match = 1; |
2492 | ||
d22c8596 MS |
2493 | if (TREE_CODE (olddecl) == FUNCTION_DECL |
2494 | && DECL_ARTIFICIAL (olddecl) | |
2495 | && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl))) | |
8d08fdba MS |
2496 | { |
2497 | /* If you declare a built-in or predefined function name as static, | |
a4443a08 MS |
2498 | the old definition is overridden, but optionally warn this was a |
2499 | bad choice of name. Ditto for overloads. */ | |
893de33c | 2500 | if (! TREE_PUBLIC (newdecl) |
a4443a08 MS |
2501 | || (TREE_CODE (newdecl) == FUNCTION_DECL |
2502 | && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))) | |
2503 | { | |
2504 | if (warn_shadow) | |
2505 | cp_warning ("shadowing %s function `%#D'", | |
2506 | DECL_BUILT_IN (olddecl) ? "built-in" : "library", | |
2507 | olddecl); | |
2508 | /* Discard the old built-in function. */ | |
2509 | return 0; | |
2510 | } | |
2511 | else if (! types_match) | |
8d08fdba | 2512 | { |
a4443a08 MS |
2513 | if (TREE_CODE (newdecl) != FUNCTION_DECL) |
2514 | { | |
2515 | /* If the built-in is not ansi, then programs can override | |
2516 | it even globally without an error. */ | |
2517 | if (! DECL_BUILT_IN (olddecl)) | |
2518 | cp_warning ("library function `%#D' redeclared as non-function `%#D'", | |
2519 | olddecl, newdecl); | |
2520 | else | |
2521 | { | |
2522 | cp_error ("declaration of `%#D'", newdecl); | |
2523 | cp_error ("conflicts with built-in declaration `%#D'", | |
2524 | olddecl); | |
2525 | } | |
2526 | return 0; | |
2527 | } | |
2528 | ||
8d08fdba MS |
2529 | cp_warning ("declaration of `%#D'", newdecl); |
2530 | cp_warning ("conflicts with built-in declaration `%#D'", | |
2531 | olddecl); | |
8d08fdba | 2532 | } |
39211cd5 MS |
2533 | } |
2534 | else if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) | |
2535 | { | |
2536 | if ((TREE_CODE (newdecl) == FUNCTION_DECL | |
5566b478 | 2537 | && DECL_FUNCTION_TEMPLATE_P (olddecl)) |
39211cd5 | 2538 | || (TREE_CODE (olddecl) == FUNCTION_DECL |
5566b478 | 2539 | && DECL_FUNCTION_TEMPLATE_P (newdecl))) |
39211cd5 MS |
2540 | return 0; |
2541 | ||
2542 | cp_error ("`%#D' redeclared as different kind of symbol", newdecl); | |
2543 | if (TREE_CODE (olddecl) == TREE_LIST) | |
2544 | olddecl = TREE_VALUE (olddecl); | |
2545 | cp_error_at ("previous declaration of `%#D'", olddecl); | |
2546 | ||
2547 | /* New decl is completely inconsistent with the old one => | |
2548 | tell caller to replace the old one. */ | |
2549 | ||
2550 | return 0; | |
8d08fdba | 2551 | } |
8d08fdba MS |
2552 | else if (!types_match) |
2553 | { | |
8926095f | 2554 | if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
f0e01782 MS |
2555 | { |
2556 | /* The name of a class template may not be declared to refer to | |
2557 | any other template, class, function, object, namespace, value, | |
e92cc029 | 2558 | or type in the same scope. */ |
5566b478 MS |
2559 | if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL |
2560 | || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) | |
f0e01782 MS |
2561 | { |
2562 | cp_error ("declaration of template `%#D'", newdecl); | |
2563 | cp_error_at ("conflicts with previous declaration `%#D'", | |
2564 | olddecl); | |
2565 | } | |
ec255269 MS |
2566 | else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL |
2567 | && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL | |
2568 | && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))), | |
75650646 MM |
2569 | TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))), 3) |
2570 | && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), | |
2571 | DECL_TEMPLATE_PARMS (olddecl))) | |
ec255269 MS |
2572 | { |
2573 | cp_error ("new declaration `%#D'", newdecl); | |
2574 | cp_error_at ("ambiguates old declaration `%#D'", olddecl); | |
2575 | } | |
f0e01782 MS |
2576 | return 0; |
2577 | } | |
8926095f MS |
2578 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
2579 | { | |
2580 | if (DECL_LANGUAGE (newdecl) == lang_c | |
2581 | && DECL_LANGUAGE (olddecl) == lang_c) | |
2582 | { | |
2583 | cp_error ("declaration of C function `%#D' conflicts with", | |
2584 | newdecl); | |
2585 | cp_error_at ("previous declaration `%#D' here", olddecl); | |
2586 | } | |
00595019 | 2587 | else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)), |
28cbf42c | 2588 | TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3)) |
700f8a87 MS |
2589 | { |
2590 | cp_error ("new declaration `%#D'", newdecl); | |
2591 | cp_error_at ("ambiguates old declaration `%#D'", olddecl); | |
2592 | } | |
2593 | else | |
2594 | return 0; | |
8926095f | 2595 | } |
8d08fdba MS |
2596 | |
2597 | /* Already complained about this, so don't do so again. */ | |
a4443a08 | 2598 | else if (current_class_type == NULL_TREE |
8d08fdba MS |
2599 | || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) |
2600 | { | |
f376e137 | 2601 | cp_error ("conflicting types for `%#D'", newdecl); |
8926095f | 2602 | cp_error_at ("previous declaration as `%#D'", olddecl); |
8d08fdba MS |
2603 | } |
2604 | } | |
75650646 MM |
2605 | else if (TREE_CODE (newdecl) == FUNCTION_DECL |
2606 | && ((DECL_TEMPLATE_SPECIALIZATION (olddecl) | |
2607 | && (!DECL_TEMPLATE_INFO (newdecl) | |
2608 | || (DECL_TI_TEMPLATE (newdecl) | |
2609 | != DECL_TI_TEMPLATE (olddecl)))) | |
2610 | || (DECL_TEMPLATE_SPECIALIZATION (newdecl) | |
2611 | && (!DECL_TEMPLATE_INFO (olddecl) | |
2612 | || (DECL_TI_TEMPLATE (olddecl) | |
2613 | != DECL_TI_TEMPLATE (newdecl)))))) | |
386b8a85 JM |
2614 | /* It's OK to have a template specialization and a non-template |
2615 | with the same type, or to have specializations of two | |
75650646 MM |
2616 | different templates with the same type. Note that if one is a |
2617 | specialization, and the other is an instantiation of the same | |
2618 | template, that we do not exit at this point. That situation | |
2619 | can occur if we instantiate a template class, and then | |
2620 | specialize one of its methods. This situation is legal, but | |
2621 | the declarations must be merged in the usual way. */ | |
2622 | return 0; | |
2623 | else if (TREE_CODE (newdecl) == FUNCTION_DECL | |
2624 | && ((DECL_TEMPLATE_INSTANTIATION (olddecl) | |
2625 | && !DECL_USE_TEMPLATE (newdecl)) | |
2626 | || (DECL_TEMPLATE_INSTANTIATION (newdecl) | |
2627 | && !DECL_USE_TEMPLATE (olddecl)))) | |
2628 | /* One of the declarations is a template instantiation, and the | |
2629 | other is not a template at all. That's OK. */ | |
386b8a85 | 2630 | return 0; |
8d08fdba MS |
2631 | else |
2632 | { | |
2633 | char *errmsg = redeclaration_error_message (newdecl, olddecl); | |
2634 | if (errmsg) | |
2635 | { | |
51c184be | 2636 | cp_error (errmsg, newdecl); |
8d08fdba MS |
2637 | if (DECL_NAME (olddecl) != NULL_TREE) |
2638 | cp_error_at ((DECL_INITIAL (olddecl) | |
2639 | && current_binding_level == global_binding_level) | |
2640 | ? "`%#D' previously defined here" | |
2641 | : "`%#D' previously declared here", olddecl); | |
2642 | } | |
2643 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
2644 | && DECL_INITIAL (olddecl) != NULL_TREE | |
2645 | && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE | |
2646 | && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE) | |
2647 | { | |
2648 | /* Prototype decl follows defn w/o prototype. */ | |
2649 | cp_warning_at ("prototype for `%#D'", newdecl); | |
2650 | cp_warning_at ("follows non-prototype definition here", olddecl); | |
2651 | } | |
2652 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
2653 | && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)) | |
8926095f MS |
2654 | { |
2655 | /* extern "C" int foo (); | |
2656 | int foo () { bar (); } | |
2657 | is OK. */ | |
2658 | if (current_lang_stack == current_lang_base) | |
a28e3c7f | 2659 | DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); |
8926095f MS |
2660 | else |
2661 | { | |
2662 | cp_error_at ("previous declaration of `%#D' with %L linkage", | |
2663 | olddecl, DECL_LANGUAGE (olddecl)); | |
2664 | cp_error ("conflicts with new declaration with %L linkage", | |
2665 | DECL_LANGUAGE (newdecl)); | |
2666 | } | |
2667 | } | |
e1cd6e56 | 2668 | |
a6f02587 | 2669 | if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl)) |
c32381b1 JM |
2670 | ; |
2671 | else if (TREE_CODE (olddecl) == FUNCTION_DECL) | |
e1cd6e56 MS |
2672 | { |
2673 | tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl)); | |
2674 | tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)); | |
2675 | int i = 1; | |
2676 | ||
2677 | if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) | |
2678 | t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); | |
2679 | ||
2680 | for (; t1 && t1 != void_list_node; | |
2681 | t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) | |
2682 | if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) | |
2683 | { | |
2507f3b5 RK |
2684 | if (1 == simple_cst_equal (TREE_PURPOSE (t1), |
2685 | TREE_PURPOSE (t2))) | |
e1cd6e56 MS |
2686 | { |
2687 | if (pedantic) | |
2688 | { | |
2689 | cp_pedwarn ("default argument given for parameter %d of `%#D'", | |
2690 | i, newdecl); | |
2691 | cp_pedwarn_at ("after previous specification in `%#D'", | |
2692 | olddecl); | |
2693 | } | |
2694 | } | |
2695 | else | |
2696 | { | |
2697 | cp_error ("default argument given for parameter %d of `%#D'", | |
2698 | i, newdecl); | |
da20811c | 2699 | cp_error_at ("after previous specification in `%#D'", |
e1cd6e56 MS |
2700 | olddecl); |
2701 | } | |
2702 | } | |
a5894242 | 2703 | |
7fcdf4c2 MS |
2704 | if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl) |
2705 | && TREE_ADDRESSABLE (olddecl) && warn_inline) | |
dff6b454 | 2706 | { |
7fcdf4c2 MS |
2707 | cp_warning ("`%#D' was used before it was declared inline", |
2708 | newdecl); | |
2709 | cp_warning_at ("previous non-inline declaration here", | |
2710 | olddecl); | |
dff6b454 | 2711 | } |
e1cd6e56 | 2712 | } |
8ccc31eb MS |
2713 | /* These bits are logically part of the type for non-functions. */ |
2714 | else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) | |
2715 | || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)) | |
2716 | { | |
2717 | cp_pedwarn ("type qualifiers for `%#D'", newdecl); | |
2718 | cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl); | |
2719 | } | |
8d08fdba MS |
2720 | } |
2721 | ||
2722 | /* If new decl is `static' and an `extern' was seen previously, | |
2723 | warn about it. */ | |
2724 | warn_extern_redeclared_static (newdecl, olddecl); | |
2725 | ||
e92cc029 | 2726 | /* We have committed to returning 1 at this point. */ |
8d08fdba MS |
2727 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
2728 | { | |
2729 | /* Now that functions must hold information normally held | |
2730 | by field decls, there is extra work to do so that | |
2731 | declaration information does not get destroyed during | |
2732 | definition. */ | |
2733 | if (DECL_VINDEX (olddecl)) | |
2734 | DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl); | |
2735 | if (DECL_CONTEXT (olddecl)) | |
2736 | DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); | |
2737 | if (DECL_CLASS_CONTEXT (olddecl)) | |
2738 | DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); | |
2739 | if (DECL_CHAIN (newdecl) == NULL_TREE) | |
2740 | DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); | |
2741 | if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) | |
2742 | DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); | |
e1cd6e56 MS |
2743 | DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl); |
2744 | DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); | |
7215f9a0 | 2745 | DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl); |
864b83b9 | 2746 | DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl); |
8d08fdba MS |
2747 | } |
2748 | ||
2749 | /* Deal with C++: must preserve virtual function table size. */ | |
2750 | if (TREE_CODE (olddecl) == TYPE_DECL) | |
2751 | { | |
2752 | register tree newtype = TREE_TYPE (newdecl); | |
2753 | register tree oldtype = TREE_TYPE (olddecl); | |
2754 | ||
2755 | if (newtype != error_mark_node && oldtype != error_mark_node | |
2756 | && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype)) | |
2757 | { | |
2758 | CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype); | |
2759 | CLASSTYPE_FRIEND_CLASSES (newtype) | |
2760 | = CLASSTYPE_FRIEND_CLASSES (oldtype); | |
2761 | } | |
8d08fdba MS |
2762 | } |
2763 | ||
2764 | /* Special handling ensues if new decl is a function definition. */ | |
2765 | new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL | |
2766 | && DECL_INITIAL (newdecl) != NULL_TREE); | |
2767 | ||
2768 | /* Optionally warn about more than one declaration for the same name, | |
2769 | but don't warn about a function declaration followed by a definition. */ | |
2770 | if (warn_redundant_decls | |
700f8a87 | 2771 | && ! DECL_ARTIFICIAL (olddecl) |
8d08fdba MS |
2772 | && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE) |
2773 | /* Don't warn about extern decl followed by (tentative) definition. */ | |
2774 | && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) | |
2775 | { | |
2776 | cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); | |
44a8d0b3 | 2777 | cp_warning_at ("previous declaration of `%D'", olddecl); |
8d08fdba MS |
2778 | } |
2779 | ||
2780 | /* Copy all the DECL_... slots specified in the new decl | |
2781 | except for any that we copy here from the old type. */ | |
2782 | ||
5566b478 MS |
2783 | if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
2784 | { | |
37dac039 JM |
2785 | if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE) |
2786 | { | |
3ac3d9ea MM |
2787 | if (! duplicate_decls (DECL_TEMPLATE_RESULT (newdecl), |
2788 | DECL_TEMPLATE_RESULT (olddecl))) | |
2789 | cp_error ("invalid redeclaration of %D", newdecl); | |
2790 | TREE_TYPE (olddecl) = TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)); | |
37dac039 | 2791 | DECL_TEMPLATE_PARMS (olddecl) = DECL_TEMPLATE_PARMS (newdecl); |
f84b4be9 | 2792 | DECL_TEMPLATE_INFO (olddecl) = DECL_TEMPLATE_INFO (newdecl); |
37dac039 | 2793 | } |
5566b478 MS |
2794 | return 1; |
2795 | } | |
2796 | ||
8d08fdba MS |
2797 | if (types_match) |
2798 | { | |
2799 | /* Automatically handles default parameters. */ | |
2800 | tree oldtype = TREE_TYPE (olddecl); | |
e1cd6e56 | 2801 | tree newtype; |
8d08fdba | 2802 | |
e1cd6e56 MS |
2803 | /* Make sure we put the new type in the same obstack as the old one. */ |
2804 | if (oldtype) | |
39211cd5 MS |
2805 | push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); |
2806 | else | |
2807 | { | |
2808 | push_obstacks_nochange (); | |
2809 | end_temporary_allocation (); | |
2810 | } | |
2811 | ||
e1cd6e56 MS |
2812 | /* Merge the data types specified in the two decls. */ |
2813 | newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); | |
2814 | ||
8d08fdba MS |
2815 | if (TREE_CODE (newdecl) == VAR_DECL) |
2816 | DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl); | |
2817 | /* Do this after calling `common_type' so that default | |
2818 | parameters don't confuse us. */ | |
2819 | else if (TREE_CODE (newdecl) == FUNCTION_DECL | |
2820 | && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)) | |
2821 | != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)))) | |
2822 | { | |
f30432d7 | 2823 | TREE_TYPE (newdecl) = build_exception_variant (newtype, |
8d08fdba | 2824 | TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); |
f30432d7 | 2825 | TREE_TYPE (olddecl) = build_exception_variant (newtype, |
8d08fdba MS |
2826 | TYPE_RAISES_EXCEPTIONS (oldtype)); |
2827 | ||
047f64a3 JM |
2828 | if ((pedantic || (! DECL_IN_SYSTEM_HEADER (olddecl) |
2829 | && DECL_SOURCE_LINE (olddecl) != 0)) | |
da20811c | 2830 | && flag_exceptions |
824b9a4c | 2831 | && ! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl))) |
8d08fdba | 2832 | { |
824b9a4c | 2833 | cp_pedwarn ("declaration of `%D' throws different exceptions", |
a28e3c7f | 2834 | newdecl); |
824b9a4c | 2835 | cp_pedwarn_at ("previous declaration here", olddecl); |
8d08fdba MS |
2836 | } |
2837 | } | |
2838 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; | |
2839 | ||
2840 | /* Lay the type out, unless already done. */ | |
b7484fbe | 2841 | if (oldtype != TREE_TYPE (newdecl) |
5566b478 | 2842 | && TREE_TYPE (newdecl) != error_mark_node |
5156628f | 2843 | && !(processing_template_decl && uses_template_parms (newdecl))) |
b7484fbe MS |
2844 | layout_type (TREE_TYPE (newdecl)); |
2845 | ||
5566b478 MS |
2846 | if ((TREE_CODE (newdecl) == VAR_DECL |
2847 | || TREE_CODE (newdecl) == PARM_DECL | |
2848 | || TREE_CODE (newdecl) == RESULT_DECL | |
2849 | || TREE_CODE (newdecl) == FIELD_DECL | |
2850 | || TREE_CODE (newdecl) == TYPE_DECL) | |
5156628f | 2851 | && !(processing_template_decl && uses_template_parms (newdecl))) |
b7484fbe | 2852 | layout_decl (newdecl, 0); |
8d08fdba MS |
2853 | |
2854 | /* Merge the type qualifiers. */ | |
2855 | if (TREE_READONLY (newdecl)) | |
2856 | TREE_READONLY (olddecl) = 1; | |
2857 | if (TREE_THIS_VOLATILE (newdecl)) | |
2858 | TREE_THIS_VOLATILE (olddecl) = 1; | |
2859 | ||
2860 | /* Merge the initialization information. */ | |
8926095f MS |
2861 | if (DECL_INITIAL (newdecl) == NULL_TREE |
2862 | && DECL_INITIAL (olddecl) != NULL_TREE) | |
2863 | { | |
2864 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
2865 | DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); | |
2866 | DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); | |
2867 | } | |
39211cd5 MS |
2868 | |
2869 | /* Merge the section attribute. | |
2870 | We want to issue an error if the sections conflict but that must be | |
2871 | done later in decl_attributes since we are called before attributes | |
2872 | are assigned. */ | |
2873 | if (DECL_SECTION_NAME (newdecl) == NULL_TREE) | |
2874 | DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); | |
2875 | ||
8d08fdba MS |
2876 | /* Keep the old rtl since we can safely use it, unless it's the |
2877 | call to abort() used for abstract virtuals. */ | |
2878 | if ((DECL_LANG_SPECIFIC (olddecl) | |
2879 | && !DECL_ABSTRACT_VIRTUAL_P (olddecl)) | |
2880 | || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl)) | |
2881 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
39211cd5 MS |
2882 | |
2883 | pop_obstacks (); | |
8d08fdba MS |
2884 | } |
2885 | /* If cannot merge, then use the new type and qualifiers, | |
2886 | and don't preserve the old rtl. */ | |
2887 | else | |
2888 | { | |
2889 | /* Clean out any memory we had of the old declaration. */ | |
2890 | tree oldstatic = value_member (olddecl, static_aggregates); | |
2891 | if (oldstatic) | |
2892 | TREE_VALUE (oldstatic) = error_mark_node; | |
2893 | ||
2894 | TREE_TYPE (olddecl) = TREE_TYPE (newdecl); | |
2895 | TREE_READONLY (olddecl) = TREE_READONLY (newdecl); | |
2896 | TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); | |
2897 | TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); | |
2898 | } | |
2899 | ||
2900 | /* Merge the storage class information. */ | |
a9aedbc2 | 2901 | DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); |
e92cc029 | 2902 | DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl); |
a9aedbc2 MS |
2903 | TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); |
2904 | TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl); | |
2905 | if (! DECL_EXTERNAL (olddecl)) | |
2906 | DECL_EXTERNAL (newdecl) = 0; | |
8d08fdba | 2907 | |
5566b478 | 2908 | if (DECL_LANG_SPECIFIC (newdecl)) |
8d08fdba | 2909 | { |
a9aedbc2 MS |
2910 | DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl); |
2911 | DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl); | |
77be6f82 | 2912 | DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl); |
8d08fdba MS |
2913 | } |
2914 | ||
8d08fdba MS |
2915 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
2916 | { | |
75650646 MM |
2917 | if (DECL_TEMPLATE_INSTANTIATION (olddecl) |
2918 | && !DECL_TEMPLATE_INSTANTIATION (newdecl)) | |
2919 | { | |
2920 | /* If newdecl is not a specialization, then it is not a | |
2921 | template-related function at all. And that means that we | |
2922 | shoud have exited above, returning 0. */ | |
2923 | my_friendly_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl), | |
2924 | 0); | |
2925 | ||
2926 | if (TREE_USED (olddecl)) | |
2927 | /* From [temp.expl.spec]: | |
2928 | ||
2929 | If a template, a member template or the member of a class | |
2930 | template is explicitly specialized then that | |
2931 | specialization shall be declared before the first use of | |
2932 | that specialization that would cause an implicit | |
2933 | instantiation to take place, in every translation unit in | |
2934 | which such a use occurs. */ | |
2935 | cp_error ("explicit specialization of %D after first use", | |
2936 | olddecl); | |
2937 | ||
2938 | SET_DECL_TEMPLATE_SPECIALIZATION (olddecl); | |
2939 | } | |
faae18ab MS |
2940 | DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl); |
2941 | ||
2942 | /* If either decl says `inline', this fn is inline, unless its | |
2943 | definition was passed already. */ | |
2944 | if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE) | |
2945 | DECL_INLINE (olddecl) = 1; | |
2946 | DECL_INLINE (newdecl) = DECL_INLINE (olddecl); | |
2947 | ||
700f8a87 MS |
2948 | if (! types_match) |
2949 | { | |
2950 | DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl); | |
2951 | DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl); | |
5566b478 MS |
2952 | DECL_RTL (olddecl) = DECL_RTL (newdecl); |
2953 | } | |
2954 | if (! types_match || new_defines_function) | |
2955 | { | |
2956 | /* These need to be copied so that the names are available. */ | |
700f8a87 MS |
2957 | DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl); |
2958 | DECL_RESULT (olddecl) = DECL_RESULT (newdecl); | |
700f8a87 | 2959 | } |
8d08fdba MS |
2960 | if (new_defines_function) |
2961 | /* If defining a function declared with other language | |
2962 | linkage, use the previously declared language linkage. */ | |
2963 | DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); | |
2964 | else | |
2965 | { | |
2966 | /* If redeclaring a builtin function, and not a definition, | |
2967 | it stays built in. */ | |
2968 | if (DECL_BUILT_IN (olddecl)) | |
2969 | { | |
2970 | DECL_BUILT_IN (newdecl) = 1; | |
39211cd5 | 2971 | DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); |
8d08fdba MS |
2972 | /* If we're keeping the built-in definition, keep the rtl, |
2973 | regardless of declaration matches. */ | |
2974 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
2975 | } | |
2976 | else | |
2977 | DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); | |
2978 | ||
2979 | DECL_RESULT (newdecl) = DECL_RESULT (olddecl); | |
8926095f | 2980 | if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))) |
8d08fdba MS |
2981 | /* Previously saved insns go together with |
2982 | the function's previous definition. */ | |
2983 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
2984 | /* Don't clear out the arguments if we're redefining a function. */ | |
2985 | if (DECL_ARGUMENTS (olddecl)) | |
2986 | DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); | |
2987 | } | |
6060a796 MS |
2988 | if (DECL_LANG_SPECIFIC (olddecl)) |
2989 | DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl); | |
8d08fdba MS |
2990 | } |
2991 | ||
a9aedbc2 MS |
2992 | if (TREE_CODE (newdecl) == NAMESPACE_DECL) |
2993 | { | |
2994 | NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl); | |
2995 | } | |
2996 | ||
8926095f MS |
2997 | if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
2998 | { | |
75650646 MM |
2999 | DECL_TEMPLATE_SPECIALIZATIONS (newdecl) |
3000 | = DECL_TEMPLATE_SPECIALIZATIONS (olddecl); | |
f376e137 MS |
3001 | if (DECL_CHAIN (newdecl) == NULL_TREE) |
3002 | DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); | |
8926095f | 3003 | } |
5566b478 | 3004 | |
8d08fdba MS |
3005 | /* Now preserve various other info from the definition. */ |
3006 | TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); | |
3007 | TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); | |
3008 | DECL_COMMON (newdecl) = DECL_COMMON (olddecl); | |
f376e137 | 3009 | DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl); |
8d08fdba MS |
3010 | |
3011 | /* Don't really know how much of the language-specific | |
3012 | values we should copy from old to new. */ | |
3013 | if (DECL_LANG_SPECIFIC (olddecl)) | |
3014 | { | |
3015 | DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); | |
3016 | DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); | |
db5ae43f | 3017 | DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); |
5566b478 MS |
3018 | if (DECL_TEMPLATE_INFO (newdecl) == NULL_TREE) |
3019 | { | |
3020 | DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); | |
3021 | DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl); | |
3022 | } | |
8d08fdba MS |
3023 | } |
3024 | ||
3025 | if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
3026 | { | |
3027 | int function_size; | |
3028 | struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl); | |
3029 | struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl); | |
3030 | ||
3031 | function_size = sizeof (struct tree_decl); | |
3032 | ||
3033 | bcopy ((char *) newdecl + sizeof (struct tree_common), | |
3034 | (char *) olddecl + sizeof (struct tree_common), | |
3035 | function_size - sizeof (struct tree_common)); | |
3036 | ||
3037 | /* Can we safely free the storage used by newdecl? */ | |
3038 | ||
3039 | #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \ | |
3040 | & ~ obstack_alignment_mask (&permanent_obstack)) | |
3041 | ||
75650646 MM |
3042 | if (DECL_TEMPLATE_INSTANTIATION (newdecl)) |
3043 | { | |
3044 | /* If newdecl is a template instantiation, it is possible that | |
3045 | the following sequence of events has occurred: | |
3046 | ||
3047 | o A friend function was declared in a class template. The | |
3048 | class template was instantiated. | |
3049 | ||
3050 | o The instantiation of the friend declaration was | |
3051 | recorded on the instantiation list, and is newdecl. | |
3052 | ||
3053 | o Later, however, instantiate_class_template called pushdecl | |
3054 | on the newdecl to perform name injection. But, pushdecl in | |
3055 | turn called duplicate_decls when it discovered that another | |
3056 | declaration of a global function with the same name already | |
3057 | existed. | |
3058 | ||
3059 | o Here, in duplicate_decls, we decided to clobber newdecl. | |
3060 | ||
3061 | If we're going to do that, we'd better make sure that | |
3062 | olddecl, and not newdecl, is on the list of | |
3063 | instantiations so that if we try to do the instantiation | |
3064 | again we won't get the clobbered declaration. */ | |
3065 | ||
3066 | tree tmpl = DECL_TI_TEMPLATE (newdecl); | |
3067 | tree decls = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); | |
3068 | ||
3069 | for (; decls; decls = TREE_CHAIN (decls)) | |
3070 | if (TREE_VALUE (decls) == newdecl) | |
3071 | TREE_VALUE (decls) = olddecl; | |
3072 | } | |
3073 | ||
8d08fdba MS |
3074 | if ((char *)newdecl + ROUND (function_size) |
3075 | + ROUND (sizeof (struct lang_decl)) | |
3076 | == obstack_next_free (&permanent_obstack)) | |
3077 | { | |
3078 | DECL_MAIN_VARIANT (newdecl) = olddecl; | |
3079 | DECL_LANG_SPECIFIC (olddecl) = ol; | |
3080 | bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl)); | |
3081 | ||
3082 | obstack_free (&permanent_obstack, newdecl); | |
3083 | } | |
d22c8596 | 3084 | else if (LANG_DECL_PERMANENT (ol) && ol != nl) |
8d08fdba MS |
3085 | { |
3086 | if (DECL_MAIN_VARIANT (olddecl) == olddecl) | |
3087 | { | |
3088 | /* Save these lang_decls that would otherwise be lost. */ | |
3089 | extern tree free_lang_decl_chain; | |
3090 | tree free_lang_decl = (tree) ol; | |
d22c8596 MS |
3091 | |
3092 | if (DECL_LANG_SPECIFIC (olddecl) == ol) | |
3093 | abort (); | |
3094 | ||
8d08fdba MS |
3095 | TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; |
3096 | free_lang_decl_chain = free_lang_decl; | |
3097 | } | |
3098 | else | |
3099 | { | |
bd6dd845 | 3100 | /* Storage leak. */; |
8d08fdba MS |
3101 | } |
3102 | } | |
3103 | } | |
3104 | else | |
3105 | { | |
3106 | bcopy ((char *) newdecl + sizeof (struct tree_common), | |
3107 | (char *) olddecl + sizeof (struct tree_common), | |
3108 | sizeof (struct tree_decl) - sizeof (struct tree_common) | |
3109 | + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); | |
3110 | } | |
3111 | ||
3112 | DECL_UID (olddecl) = olddecl_uid; | |
3113 | if (olddecl_friend) | |
3114 | DECL_FRIEND_P (olddecl) = 1; | |
3115 | ||
d9525bec BK |
3116 | /* NEWDECL contains the merged attribute lists. |
3117 | Update OLDDECL to be the same. */ | |
3118 | DECL_MACHINE_ATTRIBUTES (olddecl) = DECL_MACHINE_ATTRIBUTES (newdecl); | |
3119 | ||
8d08fdba MS |
3120 | return 1; |
3121 | } | |
3122 | ||
3123 | /* Record a decl-node X as belonging to the current lexical scope. | |
3124 | Check for errors (such as an incompatible declaration for the same | |
3125 | name already seen in the same scope). | |
3126 | ||
3127 | Returns either X or an old decl for the same name. | |
3128 | If an old decl is returned, it may have been smashed | |
3129 | to agree with what X says. */ | |
3130 | ||
3131 | tree | |
3132 | pushdecl (x) | |
3133 | tree x; | |
3134 | { | |
3135 | register tree t; | |
8d08fdba | 3136 | register tree name = DECL_ASSEMBLER_NAME (x); |
8d08fdba MS |
3137 | register struct binding_level *b = current_binding_level; |
3138 | ||
8d08fdba | 3139 | if (x != current_function_decl |
700f8a87 MS |
3140 | /* Don't change DECL_CONTEXT of virtual methods. */ |
3141 | && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x)) | |
8d08fdba MS |
3142 | && ! DECL_CONTEXT (x)) |
3143 | DECL_CONTEXT (x) = current_function_decl; | |
3144 | /* A local declaration for a function doesn't constitute nesting. */ | |
3145 | if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0) | |
3146 | DECL_CONTEXT (x) = 0; | |
3147 | ||
8d08fdba | 3148 | /* Type are looked up using the DECL_NAME, as that is what the rest of the |
e92cc029 | 3149 | compiler wants to use. */ |
a9aedbc2 | 3150 | if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL |
73b0fce8 KL |
3151 | || TREE_CODE (x) == NAMESPACE_DECL || TREE_CODE (x) == TEMPLATE_TYPE_PARM |
3152 | || TREE_CODE (x) == TEMPLATE_TEMPLATE_PARM) | |
8d08fdba | 3153 | name = DECL_NAME (x); |
8d08fdba MS |
3154 | |
3155 | if (name) | |
3156 | { | |
5566b478 MS |
3157 | #if 0 |
3158 | /* Not needed...see below. */ | |
8d08fdba MS |
3159 | char *file; |
3160 | int line; | |
5566b478 | 3161 | #endif |
386b8a85 JM |
3162 | if (TREE_CODE (name) == TEMPLATE_ID_EXPR) |
3163 | name = TREE_OPERAND (name, 0); | |
3164 | ||
700f8a87 | 3165 | t = lookup_name_current_level (name); |
8d08fdba MS |
3166 | if (t == error_mark_node) |
3167 | { | |
3168 | /* error_mark_node is 0 for a while during initialization! */ | |
3169 | t = NULL_TREE; | |
3170 | cp_error_at ("`%#D' used prior to declaration", x); | |
3171 | } | |
3172 | ||
51c184be | 3173 | else if (t != NULL_TREE) |
8d08fdba | 3174 | { |
5566b478 MS |
3175 | #if 0 |
3176 | /* This is turned off until I have time to do it right (bpk). */ | |
e92cc029 | 3177 | /* With the code below that uses it... */ |
8d6e462b PB |
3178 | file = DECL_SOURCE_FILE (t); |
3179 | line = DECL_SOURCE_LINE (t); | |
5566b478 | 3180 | #endif |
2ee887f2 | 3181 | if (TREE_CODE (t) == PARM_DECL) |
8d08fdba MS |
3182 | { |
3183 | if (DECL_CONTEXT (t) == NULL_TREE) | |
3184 | fatal ("parse errors have confused me too much"); | |
be99da77 | 3185 | |
e92cc029 | 3186 | /* Check for duplicate params. */ |
be99da77 MS |
3187 | if (duplicate_decls (x, t)) |
3188 | return t; | |
8d08fdba | 3189 | } |
8d6e462b | 3190 | else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c) |
5566b478 MS |
3191 | || DECL_FUNCTION_TEMPLATE_P (x)) |
3192 | && is_overloaded_fn (t)) | |
8926095f | 3193 | /* don't do anything just yet */; |
e1cd6e56 MS |
3194 | else if (t == wchar_decl_node) |
3195 | { | |
3196 | if (pedantic && ! DECL_IN_SYSTEM_HEADER (x)) | |
3197 | cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x)); | |
3198 | ||
3199 | /* Throw away the redeclaration. */ | |
3200 | return t; | |
3201 | } | |
8926095f | 3202 | else if (TREE_CODE (t) != TREE_CODE (x)) |
8d08fdba | 3203 | { |
ec255269 MS |
3204 | if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t) |
3205 | && TREE_CODE (x) != TYPE_DECL | |
3206 | && ! (TREE_CODE (x) == TEMPLATE_DECL | |
3207 | && TREE_CODE (DECL_TEMPLATE_RESULT (x)) == TYPE_DECL)) | |
3208 | || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) | |
3209 | && TREE_CODE (t) != TYPE_DECL | |
3210 | && ! (TREE_CODE (t) == TEMPLATE_DECL | |
3211 | && (TREE_CODE (DECL_TEMPLATE_RESULT (t)) | |
3212 | == TYPE_DECL)))) | |
51c184be MS |
3213 | { |
3214 | /* We do nothing special here, because C++ does such nasty | |
3215 | things with TYPE_DECLs. Instead, just let the TYPE_DECL | |
3216 | get shadowed, and know that if we need to find a TYPE_DECL | |
3217 | for a given name, we can look in the IDENTIFIER_TYPE_VALUE | |
3218 | slot of the identifier. */ | |
3219 | ; | |
3220 | } | |
3221 | else if (duplicate_decls (x, t)) | |
3222 | return t; | |
8d08fdba MS |
3223 | } |
3224 | else if (duplicate_decls (x, t)) | |
51c184be | 3225 | { |
8d08fdba | 3226 | #if 0 |
8926095f | 3227 | /* This is turned off until I have time to do it right (bpk). */ |
8d08fdba | 3228 | |
8926095f MS |
3229 | /* Also warn if they did a prototype with `static' on it, but |
3230 | then later left the `static' off. */ | |
3231 | if (! TREE_PUBLIC (name) && TREE_PUBLIC (x)) | |
8d08fdba | 3232 | { |
8926095f MS |
3233 | if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t)) |
3234 | return t; | |
8d08fdba | 3235 | |
8926095f MS |
3236 | if (extra_warnings) |
3237 | { | |
a28e3c7f MS |
3238 | cp_warning ("`static' missing from declaration of `%D'", |
3239 | t); | |
8926095f MS |
3240 | warning_with_file_and_line (file, line, |
3241 | "previous declaration of `%s'", | |
3242 | decl_as_string (t, 0)); | |
3243 | } | |
8d08fdba | 3244 | |
8926095f MS |
3245 | /* Now fix things so it'll do what they expect. */ |
3246 | if (current_function_decl) | |
3247 | TREE_PUBLIC (current_function_decl) = 0; | |
3248 | } | |
51c184be MS |
3249 | /* Due to interference in memory reclamation (X may be |
3250 | obstack-deallocated at this point), we must guard against | |
8926095f MS |
3251 | one really special case. [jason: This should be handled |
3252 | by start_function] */ | |
51c184be MS |
3253 | if (current_function_decl == x) |
3254 | current_function_decl = t; | |
8926095f | 3255 | #endif |
7177d104 MS |
3256 | if (TREE_CODE (t) == TYPE_DECL) |
3257 | SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t)); | |
f30432d7 MS |
3258 | else if (TREE_CODE (t) == FUNCTION_DECL) |
3259 | check_default_args (t); | |
7177d104 | 3260 | |
51c184be MS |
3261 | return t; |
3262 | } | |
8d08fdba | 3263 | } |
8926095f MS |
3264 | |
3265 | if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x)) | |
3266 | { | |
3267 | t = push_overloaded_decl (x, 1); | |
3268 | if (t != x || DECL_LANGUAGE (x) == lang_c) | |
3269 | return t; | |
3270 | } | |
5566b478 | 3271 | else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_CONTEXT (x) == NULL_TREE) |
8926095f | 3272 | return push_overloaded_decl (x, 0); |
8d08fdba MS |
3273 | |
3274 | /* If declaring a type as a typedef, and the type has no known | |
3275 | typedef name, install this TYPE_DECL as its typedef name. */ | |
3276 | if (TREE_CODE (x) == TYPE_DECL) | |
3277 | { | |
3278 | tree type = TREE_TYPE (x); | |
3279 | tree name = (type != error_mark_node) ? TYPE_NAME (type) : x; | |
3280 | ||
3281 | if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL) | |
3282 | { | |
3283 | /* If these are different names, and we're at the global | |
3284 | binding level, make two equivalent definitions. */ | |
3285 | name = x; | |
3286 | if (global_bindings_p ()) | |
3287 | TYPE_NAME (type) = x; | |
3288 | } | |
8d08fdba MS |
3289 | my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140); |
3290 | ||
8d08fdba MS |
3291 | if (type != error_mark_node |
3292 | && TYPE_NAME (type) | |
3293 | && TYPE_IDENTIFIER (type)) | |
3294 | set_identifier_type_value_with_scope (DECL_NAME (x), type, b); | |
3295 | } | |
3296 | ||
3297 | /* Multiple external decls of the same identifier ought to match. | |
3298 | ||
3299 | We get warnings about inline functions where they are defined. | |
39211cd5 MS |
3300 | We get warnings about other functions from push_overloaded_decl. |
3301 | ||
8d08fdba | 3302 | Avoid duplicate warnings where they are used. */ |
39211cd5 | 3303 | if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL) |
8d08fdba MS |
3304 | { |
3305 | tree decl; | |
30394414 | 3306 | tree bindings = binding_for_name (name, current_namespace); |
8d08fdba | 3307 | |
30394414 JM |
3308 | if (BINDING_VALUE (bindings) != NULL_TREE |
3309 | && (DECL_EXTERNAL (BINDING_VALUE (bindings)) | |
3310 | || TREE_PUBLIC (BINDING_VALUE (bindings)))) | |
3311 | decl = BINDING_VALUE (bindings); | |
8d08fdba MS |
3312 | else |
3313 | decl = NULL_TREE; | |
3314 | ||
39211cd5 | 3315 | if (decl |
8d08fdba MS |
3316 | /* If different sort of thing, we already gave an error. */ |
3317 | && TREE_CODE (decl) == TREE_CODE (x) | |
39211cd5 | 3318 | && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1)) |
8d08fdba MS |
3319 | { |
3320 | cp_pedwarn ("type mismatch with previous external decl", x); | |
8926095f | 3321 | cp_pedwarn_at ("previous external decl of `%#D'", decl); |
8d08fdba MS |
3322 | } |
3323 | } | |
3324 | ||
8d08fdba MS |
3325 | /* This name is new in its binding level. |
3326 | Install the new declaration and return it. */ | |
3327 | if (b == global_binding_level) | |
3328 | { | |
3329 | /* Install a global value. */ | |
30394414 | 3330 | tree bindings = binding_for_name (name, current_namespace); |
8d08fdba | 3331 | |
8d08fdba MS |
3332 | /* If the first global decl has external linkage, |
3333 | warn if we later see static one. */ | |
30394414 | 3334 | if (BINDING_VALUE (bindings) == NULL_TREE && TREE_PUBLIC (x)) |
8d08fdba MS |
3335 | TREE_PUBLIC (name) = 1; |
3336 | ||
e1cd6e56 MS |
3337 | /* Don't install an artificial TYPE_DECL if we already have |
3338 | another _DECL with that name. */ | |
8d08fdba MS |
3339 | if (TREE_CODE (x) != TYPE_DECL |
3340 | || t == NULL_TREE | |
e1cd6e56 | 3341 | || ! DECL_ARTIFICIAL (x)) |
30394414 JM |
3342 | { |
3343 | if (TREE_CODE (x) == FUNCTION_DECL) | |
3344 | my_friendly_assert ((BINDING_VALUE (bindings) == NULL_TREE) | |
3345 | || BINDING_VALUE (bindings) == x, 378); | |
3346 | BINDING_VALUE (bindings) = x; | |
3347 | } | |
8d08fdba MS |
3348 | |
3349 | /* Don't forget if the function was used via an implicit decl. */ | |
3350 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
3351 | && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) | |
3352 | TREE_USED (x) = 1; | |
3353 | ||
3354 | /* Don't forget if its address was taken in that way. */ | |
3355 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
3356 | && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) | |
3357 | TREE_ADDRESSABLE (x) = 1; | |
3358 | ||
3359 | /* Warn about mismatches against previous implicit decl. */ | |
3360 | if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE | |
3361 | /* If this real decl matches the implicit, don't complain. */ | |
3362 | && ! (TREE_CODE (x) == FUNCTION_DECL | |
3363 | && TREE_TYPE (TREE_TYPE (x)) == integer_type_node)) | |
3364 | cp_warning | |
3365 | ("`%D' was previously implicitly declared to return `int'", x); | |
3366 | ||
3367 | /* If new decl is `static' and an `extern' was seen previously, | |
3368 | warn about it. */ | |
a0a33927 MS |
3369 | if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t)) |
3370 | warn_extern_redeclared_static (x, t); | |
8d08fdba MS |
3371 | } |
3372 | else | |
3373 | { | |
3374 | /* Here to install a non-global value. */ | |
3375 | tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); | |
30394414 | 3376 | tree oldglobal = binding_for_name (name, current_namespace); |
8d08fdba | 3377 | |
e1cd6e56 MS |
3378 | /* Don't install an artificial TYPE_DECL if we already have |
3379 | another _DECL with that name. */ | |
3380 | if (TREE_CODE (x) != TYPE_DECL | |
3381 | || t == NULL_TREE | |
3382 | || ! DECL_ARTIFICIAL (x)) | |
3383 | { | |
3384 | b->shadowed = tree_cons (name, oldlocal, b->shadowed); | |
3385 | IDENTIFIER_LOCAL_VALUE (name) = x; | |
3386 | } | |
8d08fdba MS |
3387 | |
3388 | /* If this is a TYPE_DECL, push it into the type value slot. */ | |
3389 | if (TREE_CODE (x) == TYPE_DECL) | |
3390 | set_identifier_type_value_with_scope (name, TREE_TYPE (x), b); | |
3391 | ||
a9aedbc2 MS |
3392 | /* Clear out any TYPE_DECL shadowed by a namespace so that |
3393 | we won't think this is a type. The C struct hack doesn't | |
3394 | go through namespaces. */ | |
3395 | if (TREE_CODE (x) == NAMESPACE_DECL) | |
3396 | set_identifier_type_value_with_scope (name, NULL_TREE, b); | |
3397 | ||
8d08fdba MS |
3398 | /* If this is an extern function declaration, see if we |
3399 | have a global definition or declaration for the function. */ | |
3400 | if (oldlocal == NULL_TREE | |
faae18ab | 3401 | && DECL_EXTERNAL (x) |
30394414 | 3402 | && BINDING_VALUE (oldglobal) != NULL_TREE |
8d08fdba | 3403 | && TREE_CODE (x) == FUNCTION_DECL |
30394414 | 3404 | && TREE_CODE (BINDING_VALUE (oldglobal)) == FUNCTION_DECL) |
8d08fdba MS |
3405 | { |
3406 | /* We have one. Their types must agree. */ | |
30394414 | 3407 | if (decls_match (x, BINDING_VALUE (oldglobal))) |
6060a796 MS |
3408 | /* OK */; |
3409 | else | |
8d08fdba MS |
3410 | { |
3411 | cp_warning ("extern declaration of `%#D' doesn't match", x); | |
30394414 | 3412 | cp_warning_at ("global declaration `%#D'", BINDING_VALUE (oldglobal)); |
8d08fdba | 3413 | } |
8d08fdba MS |
3414 | } |
3415 | /* If we have a local external declaration, | |
3416 | and no file-scope declaration has yet been seen, | |
3417 | then if we later have a file-scope decl it must not be static. */ | |
3418 | if (oldlocal == NULL_TREE | |
30394414 | 3419 | && BINDING_VALUE (oldglobal) == NULL_TREE |
8d08fdba MS |
3420 | && DECL_EXTERNAL (x) |
3421 | && TREE_PUBLIC (x)) | |
3422 | { | |
3423 | TREE_PUBLIC (name) = 1; | |
3424 | } | |
3425 | ||
3426 | if (DECL_FROM_INLINE (x)) | |
3427 | /* Inline decls shadow nothing. */; | |
3428 | ||
3429 | /* Warn if shadowing an argument at the top level of the body. */ | |
3430 | else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) | |
3431 | && TREE_CODE (oldlocal) == PARM_DECL | |
3432 | && TREE_CODE (x) != PARM_DECL) | |
3433 | { | |
3434 | /* Go to where the parms should be and see if we | |
3435 | find them there. */ | |
3436 | struct binding_level *b = current_binding_level->level_chain; | |
3437 | ||
3438 | if (cleanup_label) | |
3439 | b = b->level_chain; | |
3440 | ||
3441 | /* ARM $8.3 */ | |
3442 | if (b->parm_flag == 1) | |
3443 | cp_error ("declaration of `%#D' shadows a parameter", name); | |
3444 | } | |
72b7eeff | 3445 | else if (warn_shadow && oldlocal != NULL_TREE && b->is_for_scope |
8d6e462b PB |
3446 | && !DECL_DEAD_FOR_LOCAL (oldlocal)) |
3447 | { | |
3448 | warning ("variable `%s' shadows local", | |
3449 | IDENTIFIER_POINTER (name)); | |
3450 | cp_warning_at (" this is the shadowed declaration", oldlocal); | |
3451 | } | |
8d08fdba MS |
3452 | /* Maybe warn if shadowing something else. */ |
3453 | else if (warn_shadow && !DECL_EXTERNAL (x) | |
3454 | /* No shadow warnings for internally generated vars. */ | |
700f8a87 | 3455 | && ! DECL_ARTIFICIAL (x) |
8d08fdba MS |
3456 | /* No shadow warnings for vars made for inlining. */ |
3457 | && ! DECL_FROM_INLINE (x)) | |
3458 | { | |
3459 | char *warnstring = NULL; | |
3460 | ||
3461 | if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) | |
3462 | warnstring = "declaration of `%s' shadows a parameter"; | |
3463 | else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE | |
4ac14744 | 3464 | && current_class_ptr |
8d08fdba MS |
3465 | && !TREE_STATIC (name)) |
3466 | warnstring = "declaration of `%s' shadows a member of `this'"; | |
3467 | else if (oldlocal != NULL_TREE) | |
3468 | warnstring = "declaration of `%s' shadows previous local"; | |
30394414 JM |
3469 | else if (BINDING_VALUE (oldglobal) != NULL_TREE) |
3470 | /* XXX shadow warnings in outer-more namespaces */ | |
8d08fdba MS |
3471 | warnstring = "declaration of `%s' shadows global declaration"; |
3472 | ||
3473 | if (warnstring) | |
3474 | warning (warnstring, IDENTIFIER_POINTER (name)); | |
3475 | } | |
e1cd6e56 | 3476 | } |
8d08fdba | 3477 | |
e1cd6e56 | 3478 | if (TREE_CODE (x) == FUNCTION_DECL) |
f30432d7 | 3479 | check_default_args (x); |
8145f082 MS |
3480 | |
3481 | /* Keep count of variables in this level with incomplete type. */ | |
8145f082 | 3482 | if (TREE_CODE (x) == VAR_DECL |
28cbf42c | 3483 | && TREE_TYPE (x) != error_mark_node |
f30432d7 MS |
3484 | && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE |
3485 | && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) | |
3486 | /* RTTI TD entries are created while defining the type_info. */ | |
3487 | || (TYPE_LANG_SPECIFIC (TREE_TYPE (x)) | |
3488 | && TYPE_BEING_DEFINED (TREE_TYPE (x))))) | |
3489 | b->incomplete = tree_cons (NULL_TREE, x, b->incomplete); | |
8d08fdba MS |
3490 | } |
3491 | ||
8d08fdba MS |
3492 | /* Put decls on list in reverse order. |
3493 | We will reverse them later if necessary. */ | |
3494 | TREE_CHAIN (x) = b->names; | |
3495 | b->names = x; | |
3496 | if (! (b != global_binding_level || TREE_PERMANENT (x))) | |
3497 | my_friendly_abort (124); | |
3498 | ||
3499 | return x; | |
3500 | } | |
3501 | ||
5566b478 MS |
3502 | /* Same as pushdecl, but define X in binding-level LEVEL. We rely on the |
3503 | caller to set DECL_CONTEXT properly. */ | |
8d08fdba MS |
3504 | |
3505 | static tree | |
3506 | pushdecl_with_scope (x, level) | |
3507 | tree x; | |
3508 | struct binding_level *level; | |
3509 | { | |
3510 | register struct binding_level *b = current_binding_level; | |
5566b478 | 3511 | tree function_decl = current_function_decl; |
8d08fdba | 3512 | |
5566b478 | 3513 | current_function_decl = NULL_TREE; |
8d08fdba MS |
3514 | current_binding_level = level; |
3515 | x = pushdecl (x); | |
3516 | current_binding_level = b; | |
5566b478 | 3517 | current_function_decl = function_decl; |
8d08fdba MS |
3518 | return x; |
3519 | } | |
3520 | ||
3521 | /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, | |
3522 | if appropriate. */ | |
e92cc029 | 3523 | |
8d08fdba MS |
3524 | tree |
3525 | pushdecl_top_level (x) | |
3526 | tree x; | |
3527 | { | |
3528 | register struct binding_level *b = inner_binding_level; | |
3529 | register tree t = pushdecl_with_scope (x, global_binding_level); | |
3530 | ||
3531 | /* Now, the type_shadowed stack may screw us. Munge it so it does | |
3532 | what we want. */ | |
3533 | if (TREE_CODE (x) == TYPE_DECL) | |
3534 | { | |
3535 | tree name = DECL_NAME (x); | |
3536 | tree newval; | |
3537 | tree *ptr = (tree *)0; | |
3538 | for (; b != global_binding_level; b = b->level_chain) | |
3539 | { | |
3540 | tree shadowed = b->type_shadowed; | |
3541 | for (; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
3542 | if (TREE_PURPOSE (shadowed) == name) | |
3543 | { | |
3544 | ptr = &TREE_VALUE (shadowed); | |
3545 | /* Can't break out of the loop here because sometimes | |
3546 | a binding level will have duplicate bindings for | |
3547 | PT names. It's gross, but I haven't time to fix it. */ | |
3548 | } | |
3549 | } | |
3550 | newval = TREE_TYPE (x); | |
3551 | if (ptr == (tree *)0) | |
3552 | { | |
3553 | /* @@ This shouldn't be needed. My test case "zstring.cc" trips | |
3554 | up here if this is changed to an assertion. --KR */ | |
3555 | SET_IDENTIFIER_TYPE_VALUE (name, newval); | |
3556 | } | |
3557 | else | |
3558 | { | |
8d08fdba MS |
3559 | *ptr = newval; |
3560 | } | |
3561 | } | |
3562 | return t; | |
3563 | } | |
3564 | ||
3565 | /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL, | |
3566 | if appropriate. */ | |
e92cc029 | 3567 | |
bd6dd845 | 3568 | static void |
8d08fdba MS |
3569 | push_overloaded_decl_top_level (x, forget) |
3570 | tree x; | |
3571 | int forget; | |
3572 | { | |
3573 | struct binding_level *b = current_binding_level; | |
3574 | ||
3575 | current_binding_level = global_binding_level; | |
3576 | push_overloaded_decl (x, forget); | |
3577 | current_binding_level = b; | |
3578 | } | |
3579 | ||
3580 | /* Make the declaration of X appear in CLASS scope. */ | |
e92cc029 | 3581 | |
8d08fdba MS |
3582 | tree |
3583 | pushdecl_class_level (x) | |
3584 | tree x; | |
3585 | { | |
3586 | /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class | |
3587 | scope looks for the pre-mangled name. */ | |
3588 | register tree name = DECL_NAME (x); | |
3589 | ||
3590 | if (name) | |
3591 | { | |
8d2733ca MS |
3592 | if (TYPE_BEING_DEFINED (current_class_type)) |
3593 | { | |
3594 | /* Check for inconsistent use of this name in the class body. | |
3595 | Types, enums, and static vars are checked here; other | |
3596 | members are checked in finish_struct. */ | |
3597 | tree icv = IDENTIFIER_CLASS_VALUE (name); | |
3598 | ||
5566b478 | 3599 | if (icv && icv != x |
a4443a08 MS |
3600 | /* Don't complain about inherited names. */ |
3601 | && id_in_current_class (name) | |
3602 | /* Or shadowed tags. */ | |
3603 | && !(TREE_CODE (icv) == TYPE_DECL | |
3604 | && DECL_CONTEXT (icv) == current_class_type)) | |
8d2733ca MS |
3605 | { |
3606 | cp_error ("declaration of identifier `%D' as `%#D'", name, x); | |
3607 | cp_error_at ("conflicts with previous use in class as `%#D'", | |
3608 | icv); | |
3609 | } | |
3610 | } | |
3611 | ||
8d08fdba MS |
3612 | push_class_level_binding (name, x); |
3613 | if (TREE_CODE (x) == TYPE_DECL) | |
3614 | { | |
3615 | set_identifier_type_value (name, TREE_TYPE (x)); | |
8d08fdba MS |
3616 | } |
3617 | } | |
3618 | return x; | |
3619 | } | |
3620 | ||
bd6dd845 | 3621 | #if 0 |
7177d104 MS |
3622 | /* This function is used to push the mangled decls for nested types into |
3623 | the appropriate scope. Previously pushdecl_top_level was used, but that | |
3624 | is incorrect for members of local classes. */ | |
e92cc029 | 3625 | |
5566b478 | 3626 | void |
7177d104 MS |
3627 | pushdecl_nonclass_level (x) |
3628 | tree x; | |
3629 | { | |
3630 | struct binding_level *b = current_binding_level; | |
3631 | ||
7177d104 | 3632 | my_friendly_assert (b->parm_flag != 2, 180); |
7177d104 | 3633 | |
5566b478 | 3634 | #if 0 |
7177d104 MS |
3635 | /* Get out of template binding levels */ |
3636 | while (b->pseudo_global) | |
3637 | b = b->level_chain; | |
5566b478 | 3638 | #endif |
7177d104 MS |
3639 | |
3640 | pushdecl_with_scope (x, b); | |
3641 | } | |
bd6dd845 | 3642 | #endif |
7177d104 | 3643 | |
8d08fdba MS |
3644 | /* Make the declaration(s) of X appear in CLASS scope |
3645 | under the name NAME. */ | |
e92cc029 | 3646 | |
8d08fdba MS |
3647 | void |
3648 | push_class_level_binding (name, x) | |
3649 | tree name; | |
3650 | tree x; | |
3651 | { | |
98c1c668 JM |
3652 | /* The class_binding_level will be NULL if x is a template |
3653 | parameter name in a member template. */ | |
3654 | if (!class_binding_level) | |
3655 | return; | |
3656 | ||
e1cd6e56 MS |
3657 | if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) |
3658 | && purpose_member (name, class_binding_level->class_shadowed)) | |
3659 | return; | |
3660 | ||
8d08fdba MS |
3661 | maybe_push_cache_obstack (); |
3662 | class_binding_level->class_shadowed | |
3663 | = tree_cons (name, IDENTIFIER_CLASS_VALUE (name), | |
3664 | class_binding_level->class_shadowed); | |
3665 | pop_obstacks (); | |
3666 | IDENTIFIER_CLASS_VALUE (name) = x; | |
3667 | obstack_ptr_grow (&decl_obstack, x); | |
3668 | } | |
3669 | ||
3670 | /* Tell caller how to interpret a TREE_LIST which contains | |
3671 | chains of FUNCTION_DECLS. */ | |
e92cc029 | 3672 | |
8d08fdba MS |
3673 | int |
3674 | overloaded_globals_p (list) | |
3675 | tree list; | |
3676 | { | |
3677 | my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142); | |
3678 | ||
3679 | /* Don't commit caller to seeing them as globals. */ | |
3680 | if (TREE_NONLOCAL_FLAG (list)) | |
3681 | return -1; | |
8d08fdba | 3682 | /* Do commit caller to not seeing them as globals. */ |
5566b478 MS |
3683 | if (TREE_CODE (TREE_VALUE (list)) == TREE_LIST) |
3684 | return 0; | |
3685 | /* Do commit caller to seeing them as globals. */ | |
3686 | return 1; | |
8d08fdba MS |
3687 | } |
3688 | ||
700f8a87 MS |
3689 | /* DECL is a FUNCTION_DECL which may have other definitions already in |
3690 | place. We get around this by making the value of the identifier point | |
3691 | to a list of all the things that want to be referenced by that name. It | |
3692 | is then up to the users of that name to decide what to do with that | |
8d08fdba MS |
3693 | list. |
3694 | ||
3695 | DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT | |
3696 | slot. It is dealt with the same way. | |
3697 | ||
3698 | The value returned may be a previous declaration if we guessed wrong | |
3699 | about what language DECL should belong to (C or C++). Otherwise, | |
3700 | it's always DECL (and never something that's not a _DECL). */ | |
e92cc029 | 3701 | |
bd6dd845 | 3702 | static tree |
8d08fdba MS |
3703 | push_overloaded_decl (decl, forgettable) |
3704 | tree decl; | |
3705 | int forgettable; | |
3706 | { | |
3707 | tree orig_name = DECL_NAME (decl); | |
700f8a87 | 3708 | tree old; |
5566b478 | 3709 | int doing_global = (global_bindings_p () || ! forgettable); |
700f8a87 MS |
3710 | |
3711 | if (doing_global) | |
3712 | { | |
30394414 | 3713 | old = IDENTIFIER_NAMESPACE_VALUE (orig_name); |
700f8a87 | 3714 | if (old && TREE_CODE (old) == FUNCTION_DECL |
a4443a08 | 3715 | && DECL_ARTIFICIAL (old) |
700f8a87 MS |
3716 | && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old))) |
3717 | { | |
a4443a08 MS |
3718 | if (duplicate_decls (decl, old)) |
3719 | return old; | |
700f8a87 MS |
3720 | old = NULL_TREE; |
3721 | } | |
3722 | } | |
3723 | else | |
3724 | { | |
3725 | old = IDENTIFIER_LOCAL_VALUE (orig_name); | |
a4443a08 | 3726 | |
700f8a87 MS |
3727 | if (! purpose_member (orig_name, current_binding_level->shadowed)) |
3728 | { | |
3729 | current_binding_level->shadowed | |
3730 | = tree_cons (orig_name, old, current_binding_level->shadowed); | |
3731 | old = NULL_TREE; | |
3732 | } | |
3733 | } | |
8d08fdba | 3734 | |
700f8a87 | 3735 | if (old) |
8d08fdba | 3736 | { |
e1cd6e56 | 3737 | if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) |
8926095f | 3738 | { |
700f8a87 | 3739 | tree t = TREE_TYPE (old); |
cdf5b885 MS |
3740 | if (IS_AGGR_TYPE (t) && warn_shadow |
3741 | && (! DECL_IN_SYSTEM_HEADER (decl) | |
3742 | || ! DECL_IN_SYSTEM_HEADER (old))) | |
8926095f | 3743 | cp_warning ("`%#D' hides constructor for `%#T'", decl, t); |
5b605f68 | 3744 | old = NULL_TREE; |
8926095f | 3745 | } |
700f8a87 | 3746 | else if (is_overloaded_fn (old)) |
8d08fdba | 3747 | { |
8d08fdba MS |
3748 | tree tmp; |
3749 | ||
700f8a87 MS |
3750 | for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp)) |
3751 | if (decl == tmp || duplicate_decls (decl, tmp)) | |
3752 | return tmp; | |
8d08fdba | 3753 | } |
e1cd6e56 MS |
3754 | else |
3755 | { | |
3756 | cp_error_at ("previous non-function declaration `%#D'", old); | |
3757 | cp_error ("conflicts with function declaration `%#D'", decl); | |
a9aedbc2 | 3758 | return decl; |
e1cd6e56 | 3759 | } |
8d08fdba | 3760 | } |
7177d104 | 3761 | |
700f8a87 | 3762 | if (old || TREE_CODE (decl) == TEMPLATE_DECL) |
8d08fdba | 3763 | { |
700f8a87 MS |
3764 | if (old && is_overloaded_fn (old)) |
3765 | DECL_CHAIN (decl) = get_first_fn (old); | |
8d08fdba MS |
3766 | else |
3767 | DECL_CHAIN (decl) = NULL_TREE; | |
700f8a87 MS |
3768 | old = tree_cons (orig_name, decl, NULL_TREE); |
3769 | TREE_TYPE (old) = unknown_type_node; | |
8d08fdba MS |
3770 | } |
3771 | else | |
3772 | /* orig_name is not ambiguous. */ | |
700f8a87 MS |
3773 | old = decl; |
3774 | ||
3775 | if (doing_global) | |
30394414 | 3776 | IDENTIFIER_NAMESPACE_VALUE (orig_name) = old; |
700f8a87 MS |
3777 | else |
3778 | IDENTIFIER_LOCAL_VALUE (orig_name) = old; | |
3779 | ||
8d08fdba MS |
3780 | return decl; |
3781 | } | |
3782 | \f | |
3783 | /* Generate an implicit declaration for identifier FUNCTIONID | |
3784 | as a function of type int (). Print a warning if appropriate. */ | |
3785 | ||
3786 | tree | |
3787 | implicitly_declare (functionid) | |
3788 | tree functionid; | |
3789 | { | |
3790 | register tree decl; | |
3791 | int temp = allocation_temporary_p (); | |
3792 | ||
3793 | push_obstacks_nochange (); | |
3794 | ||
3795 | /* Save the decl permanently so we can warn if definition follows. | |
3796 | In ANSI C, warn_implicit is usually false, so the saves little space. | |
3797 | But in C++, it's usually true, hence the extra code. */ | |
d22c8596 | 3798 | if (temp && (! warn_implicit || toplevel_bindings_p ())) |
8d08fdba MS |
3799 | end_temporary_allocation (); |
3800 | ||
3801 | /* We used to reuse an old implicit decl here, | |
3802 | but this loses with inline functions because it can clobber | |
3803 | the saved decl chains. */ | |
3804 | decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type); | |
3805 | ||
3806 | DECL_EXTERNAL (decl) = 1; | |
3807 | TREE_PUBLIC (decl) = 1; | |
3808 | ||
3809 | /* ANSI standard says implicit declarations are in the innermost block. | |
d22c8596 | 3810 | So we record the decl in the standard fashion. */ |
8d08fdba MS |
3811 | pushdecl (decl); |
3812 | rest_of_decl_compilation (decl, NULL_PTR, 0, 0); | |
3813 | ||
3814 | if (warn_implicit | |
3815 | /* Only one warning per identifier. */ | |
3816 | && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE) | |
3817 | { | |
3818 | cp_pedwarn ("implicit declaration of function `%#D'", decl); | |
3819 | } | |
3820 | ||
3821 | SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl); | |
3822 | ||
3823 | pop_obstacks (); | |
3824 | ||
3825 | return decl; | |
3826 | } | |
3827 | ||
3828 | /* Return zero if the declaration NEWDECL is valid | |
3829 | when the declaration OLDDECL (assumed to be for the same name) | |
3830 | has already been seen. | |
3831 | Otherwise return an error message format string with a %s | |
3832 | where the identifier should go. */ | |
3833 | ||
3834 | static char * | |
3835 | redeclaration_error_message (newdecl, olddecl) | |
3836 | tree newdecl, olddecl; | |
3837 | { | |
3838 | if (TREE_CODE (newdecl) == TYPE_DECL) | |
3839 | { | |
3840 | /* Because C++ can put things into name space for free, | |
3841 | constructs like "typedef struct foo { ... } foo" | |
3842 | would look like an erroneous redeclaration. */ | |
8926095f | 3843 | if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0)) |
8d08fdba MS |
3844 | return 0; |
3845 | else | |
51c184be | 3846 | return "redefinition of `%#D'"; |
8d08fdba MS |
3847 | } |
3848 | else if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
3849 | { | |
3850 | /* If this is a pure function, its olddecl will actually be | |
3851 | the original initialization to `0' (which we force to call | |
3852 | abort()). Don't complain about redefinition in this case. */ | |
3853 | if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) | |
3854 | return 0; | |
3855 | ||
db5ae43f MS |
3856 | /* We'll complain about linkage mismatches in |
3857 | warn_extern_redeclared_static. */ | |
3858 | ||
3859 | /* defining the same name twice is no good. */ | |
8d08fdba | 3860 | if (DECL_INITIAL (olddecl) != NULL_TREE |
faae18ab | 3861 | && DECL_INITIAL (newdecl) != NULL_TREE) |
8d08fdba MS |
3862 | { |
3863 | if (DECL_NAME (olddecl) == NULL_TREE) | |
51c184be | 3864 | return "`%#D' not declared in class"; |
8d08fdba | 3865 | else |
51c184be | 3866 | return "redefinition of `%#D'"; |
8d08fdba MS |
3867 | } |
3868 | return 0; | |
3869 | } | |
51c184be MS |
3870 | else if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
3871 | { | |
ec255269 MS |
3872 | if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL |
3873 | && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) | |
3874 | && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl))) | |
3875 | || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL | |
3876 | && TYPE_SIZE (TREE_TYPE (newdecl)) | |
3877 | && TYPE_SIZE (TREE_TYPE (olddecl)))) | |
51c184be MS |
3878 | return "redefinition of `%#D'"; |
3879 | return 0; | |
3880 | } | |
5566b478 | 3881 | else if (toplevel_bindings_p ()) |
8d08fdba MS |
3882 | { |
3883 | /* Objects declared at top level: */ | |
3884 | /* If at least one is a reference, it's ok. */ | |
3885 | if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) | |
3886 | return 0; | |
8926095f MS |
3887 | /* Reject two definitions. */ |
3888 | return "redefinition of `%#D'"; | |
8d08fdba MS |
3889 | } |
3890 | else | |
3891 | { | |
3892 | /* Objects declared with block scope: */ | |
3893 | /* Reject two definitions, and reject a definition | |
3894 | together with an external reference. */ | |
3895 | if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))) | |
51c184be | 3896 | return "redeclaration of `%#D'"; |
8d08fdba MS |
3897 | return 0; |
3898 | } | |
3899 | } | |
3900 | \f | |
3901 | /* Get the LABEL_DECL corresponding to identifier ID as a label. | |
3902 | Create one if none exists so far for the current function. | |
3903 | This function is called for both label definitions and label references. */ | |
3904 | ||
3905 | tree | |
3906 | lookup_label (id) | |
3907 | tree id; | |
3908 | { | |
3909 | register tree decl = IDENTIFIER_LABEL_VALUE (id); | |
3910 | ||
3911 | if (current_function_decl == NULL_TREE) | |
3912 | { | |
3913 | error ("label `%s' referenced outside of any function", | |
3914 | IDENTIFIER_POINTER (id)); | |
3915 | return NULL_TREE; | |
3916 | } | |
3917 | ||
3918 | if ((decl == NULL_TREE | |
3919 | || DECL_SOURCE_LINE (decl) == 0) | |
e349ee73 MS |
3920 | && (named_label_uses == NULL |
3921 | || named_label_uses->names_in_scope != current_binding_level->names | |
3922 | || named_label_uses->label_decl != decl)) | |
3923 | { | |
3924 | struct named_label_list *new_ent; | |
3925 | new_ent | |
3926 | = (struct named_label_list*)oballoc (sizeof (struct named_label_list)); | |
3927 | new_ent->label_decl = decl; | |
3928 | new_ent->names_in_scope = current_binding_level->names; | |
3929 | new_ent->binding_level = current_binding_level; | |
3930 | new_ent->lineno_o_goto = lineno; | |
3931 | new_ent->filename_o_goto = input_filename; | |
3932 | new_ent->next = named_label_uses; | |
3933 | named_label_uses = new_ent; | |
8d08fdba MS |
3934 | } |
3935 | ||
3936 | /* Use a label already defined or ref'd with this name. */ | |
3937 | if (decl != NULL_TREE) | |
3938 | { | |
3939 | /* But not if it is inherited and wasn't declared to be inheritable. */ | |
3940 | if (DECL_CONTEXT (decl) != current_function_decl | |
3941 | && ! C_DECLARED_LABEL_FLAG (decl)) | |
3942 | return shadow_label (id); | |
3943 | return decl; | |
3944 | } | |
3945 | ||
3946 | decl = build_decl (LABEL_DECL, id, void_type_node); | |
3947 | ||
cffa8729 MS |
3948 | /* Make sure every label has an rtx. */ |
3949 | label_rtx (decl); | |
3950 | ||
8d08fdba MS |
3951 | /* A label not explicitly declared must be local to where it's ref'd. */ |
3952 | DECL_CONTEXT (decl) = current_function_decl; | |
3953 | ||
3954 | DECL_MODE (decl) = VOIDmode; | |
3955 | ||
3956 | /* Say where one reference is to the label, | |
3957 | for the sake of the error if it is not defined. */ | |
3958 | DECL_SOURCE_LINE (decl) = lineno; | |
3959 | DECL_SOURCE_FILE (decl) = input_filename; | |
3960 | ||
3961 | SET_IDENTIFIER_LABEL_VALUE (id, decl); | |
3962 | ||
3963 | named_labels = tree_cons (NULL_TREE, decl, named_labels); | |
e349ee73 | 3964 | named_label_uses->label_decl = decl; |
8d08fdba MS |
3965 | |
3966 | return decl; | |
3967 | } | |
3968 | ||
3969 | /* Make a label named NAME in the current function, | |
3970 | shadowing silently any that may be inherited from containing functions | |
3971 | or containing scopes. | |
3972 | ||
3973 | Note that valid use, if the label being shadowed | |
3974 | comes from another scope in the same function, | |
3975 | requires calling declare_nonlocal_label right away. */ | |
3976 | ||
3977 | tree | |
3978 | shadow_label (name) | |
3979 | tree name; | |
3980 | { | |
3981 | register tree decl = IDENTIFIER_LABEL_VALUE (name); | |
3982 | ||
3983 | if (decl != NULL_TREE) | |
3984 | { | |
3985 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
3986 | SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); | |
3987 | SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE); | |
3988 | } | |
3989 | ||
3990 | return lookup_label (name); | |
3991 | } | |
3992 | ||
3993 | /* Define a label, specifying the location in the source file. | |
3994 | Return the LABEL_DECL node for the label, if the definition is valid. | |
3995 | Otherwise return 0. */ | |
3996 | ||
3997 | tree | |
3998 | define_label (filename, line, name) | |
3999 | char *filename; | |
4000 | int line; | |
4001 | tree name; | |
4002 | { | |
5566b478 MS |
4003 | tree decl; |
4004 | ||
4005 | if (minimal_parse_mode) | |
4006 | { | |
4007 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
4008 | decl = build_decl (LABEL_DECL, name, void_type_node); | |
4009 | pop_obstacks (); | |
4010 | DECL_SOURCE_LINE (decl) = line; | |
4011 | DECL_SOURCE_FILE (decl) = filename; | |
4012 | add_tree (decl); | |
4013 | return decl; | |
4014 | } | |
4015 | ||
4016 | decl = lookup_label (name); | |
8d08fdba MS |
4017 | |
4018 | /* After labels, make any new cleanups go into their | |
4019 | own new (temporary) binding contour. */ | |
4020 | current_binding_level->more_cleanups_ok = 0; | |
4021 | ||
4022 | /* If label with this name is known from an outer context, shadow it. */ | |
4023 | if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl) | |
4024 | { | |
4025 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
4026 | SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); | |
4027 | decl = lookup_label (name); | |
4028 | } | |
4029 | ||
e1cd6e56 MS |
4030 | if (name == get_identifier ("wchar_t")) |
4031 | cp_pedwarn ("label named wchar_t"); | |
4032 | ||
8d08fdba MS |
4033 | if (DECL_INITIAL (decl) != NULL_TREE) |
4034 | { | |
4035 | cp_error ("duplicate label `%D'", decl); | |
4036 | return 0; | |
4037 | } | |
4038 | else | |
4039 | { | |
e349ee73 | 4040 | struct named_label_list *uses, *prev; |
28cbf42c | 4041 | int identified = 0; |
8d08fdba MS |
4042 | |
4043 | /* Mark label as having been defined. */ | |
4044 | DECL_INITIAL (decl) = error_mark_node; | |
4045 | /* Say where in the source. */ | |
4046 | DECL_SOURCE_FILE (decl) = filename; | |
4047 | DECL_SOURCE_LINE (decl) = line; | |
4048 | ||
e349ee73 MS |
4049 | prev = NULL; |
4050 | uses = named_label_uses; | |
4051 | while (uses != NULL) | |
4052 | if (uses->label_decl == decl) | |
8d08fdba MS |
4053 | { |
4054 | struct binding_level *b = current_binding_level; | |
4055 | while (b) | |
4056 | { | |
4057 | tree new_decls = b->names; | |
e349ee73 MS |
4058 | tree old_decls = (b == uses->binding_level) |
4059 | ? uses->names_in_scope : NULL_TREE; | |
8d08fdba MS |
4060 | while (new_decls != old_decls) |
4061 | { | |
4062 | if (TREE_CODE (new_decls) == VAR_DECL | |
4063 | /* Don't complain about crossing initialization | |
4064 | of internal entities. They can't be accessed, | |
4065 | and they should be cleaned up | |
4066 | by the time we get to the label. */ | |
700f8a87 | 4067 | && ! DECL_ARTIFICIAL (new_decls) |
8d08fdba MS |
4068 | && ((DECL_INITIAL (new_decls) != NULL_TREE |
4069 | && DECL_INITIAL (new_decls) != error_mark_node) | |
4070 | || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) | |
4071 | { | |
e349ee73 MS |
4072 | if (! identified) |
4073 | { | |
4074 | cp_error ("jump to label `%D'", decl); | |
4075 | error_with_file_and_line (uses->filename_o_goto, | |
4076 | uses->lineno_o_goto, | |
4077 | " from here"); | |
4078 | identified = 1; | |
4079 | } | |
28cbf42c MS |
4080 | cp_error_at (" crosses initialization of `%#D'", |
4081 | new_decls); | |
8d08fdba MS |
4082 | } |
4083 | new_decls = TREE_CHAIN (new_decls); | |
4084 | } | |
e349ee73 | 4085 | if (b == uses->binding_level) |
8d08fdba MS |
4086 | break; |
4087 | b = b->level_chain; | |
4088 | } | |
4089 | ||
e349ee73 MS |
4090 | if (prev != NULL) |
4091 | prev->next = uses->next; | |
8d08fdba | 4092 | else |
e349ee73 MS |
4093 | named_label_uses = uses->next; |
4094 | ||
4095 | uses = uses->next; | |
4096 | } | |
4097 | else | |
4098 | { | |
4099 | prev = uses; | |
4100 | uses = uses->next; | |
8d08fdba MS |
4101 | } |
4102 | current_function_return_value = NULL_TREE; | |
4103 | return decl; | |
4104 | } | |
4105 | } | |
4106 | ||
a5894242 MS |
4107 | struct cp_switch |
4108 | { | |
4109 | struct binding_level *level; | |
4110 | struct cp_switch *next; | |
4111 | }; | |
4112 | ||
4113 | static struct cp_switch *switch_stack; | |
4114 | ||
4115 | void | |
4116 | push_switch () | |
4117 | { | |
4118 | struct cp_switch *p | |
4119 | = (struct cp_switch *) oballoc (sizeof (struct cp_switch)); | |
4120 | p->level = current_binding_level; | |
4121 | p->next = switch_stack; | |
4122 | switch_stack = p; | |
4123 | } | |
4124 | ||
4125 | void | |
4126 | pop_switch () | |
4127 | { | |
4128 | switch_stack = switch_stack->next; | |
4129 | } | |
4130 | ||
8d08fdba MS |
4131 | /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ |
4132 | /* XXX Note decl is never actually used. (bpk) */ | |
e92cc029 | 4133 | |
8d08fdba MS |
4134 | void |
4135 | define_case_label (decl) | |
4136 | tree decl; | |
4137 | { | |
4138 | tree cleanup = last_cleanup_this_contour (); | |
a5894242 MS |
4139 | struct binding_level *b = current_binding_level; |
4140 | int identified = 0; | |
4141 | ||
8d08fdba MS |
4142 | if (cleanup) |
4143 | { | |
4144 | static int explained = 0; | |
a5894242 MS |
4145 | cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup)); |
4146 | warning ("where case label appears here"); | |
8d08fdba MS |
4147 | if (!explained) |
4148 | { | |
a5894242 MS |
4149 | warning ("(enclose actions of previous case statements requiring"); |
4150 | warning ("destructors in their own binding contours.)"); | |
8d08fdba MS |
4151 | explained = 1; |
4152 | } | |
4153 | } | |
4154 | ||
a5894242 MS |
4155 | for (; b && b != switch_stack->level; b = b->level_chain) |
4156 | { | |
4157 | tree new_decls = b->names; | |
4158 | for (; new_decls; new_decls = TREE_CHAIN (new_decls)) | |
4159 | { | |
4160 | if (TREE_CODE (new_decls) == VAR_DECL | |
4161 | /* Don't complain about crossing initialization | |
4162 | of internal entities. They can't be accessed, | |
4163 | and they should be cleaned up | |
4164 | by the time we get to the label. */ | |
4165 | && ! DECL_ARTIFICIAL (new_decls) | |
4166 | && ((DECL_INITIAL (new_decls) != NULL_TREE | |
4167 | && DECL_INITIAL (new_decls) != error_mark_node) | |
4168 | || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) | |
4169 | { | |
4170 | if (! identified) | |
4171 | error ("jump to case label"); | |
4172 | identified = 1; | |
4173 | cp_error_at (" crosses initialization of `%#D'", | |
4174 | new_decls); | |
4175 | } | |
4176 | } | |
4177 | } | |
4178 | ||
8d08fdba MS |
4179 | /* After labels, make any new cleanups go into their |
4180 | own new (temporary) binding contour. */ | |
4181 | ||
4182 | current_binding_level->more_cleanups_ok = 0; | |
4183 | current_function_return_value = NULL_TREE; | |
4184 | } | |
4185 | \f | |
4186 | /* Return the list of declarations of the current level. | |
4187 | Note that this list is in reverse order unless/until | |
4188 | you nreverse it; and when you do nreverse it, you must | |
4189 | store the result back using `storedecls' or you will lose. */ | |
4190 | ||
4191 | tree | |
4192 | getdecls () | |
4193 | { | |
4194 | return current_binding_level->names; | |
4195 | } | |
4196 | ||
4197 | /* Return the list of type-tags (for structs, etc) of the current level. */ | |
4198 | ||
4199 | tree | |
4200 | gettags () | |
4201 | { | |
4202 | return current_binding_level->tags; | |
4203 | } | |
4204 | ||
4205 | /* Store the list of declarations of the current level. | |
4206 | This is done for the parameter declarations of a function being defined, | |
4207 | after they are modified in the light of any missing parameters. */ | |
4208 | ||
4209 | static void | |
4210 | storedecls (decls) | |
4211 | tree decls; | |
4212 | { | |
4213 | current_binding_level->names = decls; | |
4214 | } | |
4215 | ||
4216 | /* Similarly, store the list of tags of the current level. */ | |
4217 | ||
4218 | static void | |
4219 | storetags (tags) | |
4220 | tree tags; | |
4221 | { | |
4222 | current_binding_level->tags = tags; | |
4223 | } | |
4224 | \f | |
4225 | /* Given NAME, an IDENTIFIER_NODE, | |
4226 | return the structure (or union or enum) definition for that name. | |
4227 | Searches binding levels from BINDING_LEVEL up to the global level. | |
4228 | If THISLEVEL_ONLY is nonzero, searches only the specified context | |
4229 | (but skips any tag-transparent contexts to find one that is | |
4230 | meaningful for tags). | |
4231 | FORM says which kind of type the caller wants; | |
4232 | it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. | |
4233 | If the wrong kind of type is found, and it's not a template, an error is | |
4234 | reported. */ | |
4235 | ||
4236 | static tree | |
4237 | lookup_tag (form, name, binding_level, thislevel_only) | |
4238 | enum tree_code form; | |
8d08fdba | 4239 | tree name; |
cffa8729 | 4240 | struct binding_level *binding_level; |
8d08fdba MS |
4241 | int thislevel_only; |
4242 | { | |
4243 | register struct binding_level *level; | |
4244 | ||
4245 | for (level = binding_level; level; level = level->level_chain) | |
4246 | { | |
4247 | register tree tail; | |
4248 | if (ANON_AGGRNAME_P (name)) | |
4249 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
4250 | { | |
4251 | /* There's no need for error checking here, because | |
4252 | anon names are unique throughout the compilation. */ | |
4253 | if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name) | |
4254 | return TREE_VALUE (tail); | |
4255 | } | |
4256 | else | |
4257 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
4258 | { | |
a80e4195 | 4259 | if (TREE_PURPOSE (tail) == name) |
8d08fdba MS |
4260 | { |
4261 | enum tree_code code = TREE_CODE (TREE_VALUE (tail)); | |
4262 | /* Should tighten this up; it'll probably permit | |
4263 | UNION_TYPE and a struct template, for example. */ | |
4264 | if (code != form | |
5566b478 | 4265 | && !(form != ENUMERAL_TYPE && code == TEMPLATE_DECL)) |
8d08fdba MS |
4266 | { |
4267 | /* Definition isn't the kind we were looking for. */ | |
4268 | cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail), | |
4269 | form); | |
72b7eeff | 4270 | return NULL_TREE; |
8d08fdba MS |
4271 | } |
4272 | return TREE_VALUE (tail); | |
4273 | } | |
4274 | } | |
4275 | if (thislevel_only && ! level->tag_transparent) | |
5566b478 MS |
4276 | { |
4277 | if (level->pseudo_global) | |
4278 | { | |
30394414 JM |
4279 | /* XXX MvL */ |
4280 | tree t = IDENTIFIER_NAMESPACE_VALUE (name); | |
5566b478 MS |
4281 | if (t && TREE_CODE (t) == TEMPLATE_DECL |
4282 | && TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL) | |
4283 | return TREE_TYPE (t); | |
4284 | } | |
4285 | return NULL_TREE; | |
4286 | } | |
8d08fdba MS |
4287 | if (current_class_type && level->level_chain == global_binding_level) |
4288 | { | |
4289 | /* Try looking in this class's tags before heading into | |
4290 | global binding level. */ | |
4291 | tree context = current_class_type; | |
4292 | while (context) | |
4293 | { | |
4294 | switch (TREE_CODE_CLASS (TREE_CODE (context))) | |
4295 | { | |
4296 | tree these_tags; | |
4297 | case 't': | |
4298 | these_tags = CLASSTYPE_TAGS (context); | |
4299 | if (ANON_AGGRNAME_P (name)) | |
4300 | while (these_tags) | |
4301 | { | |
4302 | if (TYPE_IDENTIFIER (TREE_VALUE (these_tags)) | |
4303 | == name) | |
4304 | return TREE_VALUE (tail); | |
4305 | these_tags = TREE_CHAIN (these_tags); | |
4306 | } | |
4307 | else | |
4308 | while (these_tags) | |
4309 | { | |
4310 | if (TREE_PURPOSE (these_tags) == name) | |
4311 | { | |
4312 | if (TREE_CODE (TREE_VALUE (these_tags)) != form) | |
4313 | { | |
4314 | cp_error ("`%#D' redeclared as %C in class scope", | |
4315 | TREE_VALUE (tail), form); | |
72b7eeff | 4316 | return NULL_TREE; |
8d08fdba MS |
4317 | } |
4318 | return TREE_VALUE (tail); | |
4319 | } | |
4320 | these_tags = TREE_CHAIN (these_tags); | |
4321 | } | |
4322 | /* If this type is not yet complete, then don't | |
4323 | look at its context. */ | |
4324 | if (TYPE_SIZE (context) == NULL_TREE) | |
4325 | goto no_context; | |
4326 | /* Go to next enclosing type, if any. */ | |
d2e5ee5c | 4327 | context = DECL_CONTEXT (TYPE_MAIN_DECL (context)); |
8d08fdba MS |
4328 | break; |
4329 | case 'd': | |
4330 | context = DECL_CONTEXT (context); | |
4331 | break; | |
4332 | default: | |
4333 | my_friendly_abort (10); | |
4334 | } | |
4335 | continue; | |
4336 | no_context: | |
4337 | break; | |
4338 | } | |
4339 | } | |
4340 | } | |
4341 | return NULL_TREE; | |
4342 | } | |
4343 | ||
bd6dd845 | 4344 | #if 0 |
8d08fdba MS |
4345 | void |
4346 | set_current_level_tags_transparency (tags_transparent) | |
4347 | int tags_transparent; | |
4348 | { | |
4349 | current_binding_level->tag_transparent = tags_transparent; | |
4350 | } | |
bd6dd845 | 4351 | #endif |
8d08fdba MS |
4352 | |
4353 | /* Given a type, find the tag that was defined for it and return the tag name. | |
4354 | Otherwise return 0. However, the value can never be 0 | |
4355 | in the cases in which this is used. | |
4356 | ||
4357 | C++: If NAME is non-zero, this is the new name to install. This is | |
4358 | done when replacing anonymous tags with real tag names. */ | |
4359 | ||
4360 | static tree | |
4361 | lookup_tag_reverse (type, name) | |
4362 | tree type; | |
4363 | tree name; | |
4364 | { | |
4365 | register struct binding_level *level; | |
4366 | ||
4367 | for (level = current_binding_level; level; level = level->level_chain) | |
4368 | { | |
4369 | register tree tail; | |
4370 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
4371 | { | |
4372 | if (TREE_VALUE (tail) == type) | |
4373 | { | |
4374 | if (name) | |
4375 | TREE_PURPOSE (tail) = name; | |
4376 | return TREE_PURPOSE (tail); | |
4377 | } | |
4378 | } | |
4379 | } | |
4380 | return NULL_TREE; | |
4381 | } | |
8d08fdba MS |
4382 | \f |
4383 | /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). | |
4384 | Return the type value, or NULL_TREE if not found. */ | |
e92cc029 | 4385 | |
8d08fdba MS |
4386 | static tree |
4387 | lookup_nested_type (type, context) | |
4388 | tree type; | |
4389 | tree context; | |
4390 | { | |
4391 | if (context == NULL_TREE) | |
4392 | return NULL_TREE; | |
4393 | while (context) | |
4394 | { | |
4395 | switch (TREE_CODE (context)) | |
4396 | { | |
4397 | case TYPE_DECL: | |
4398 | { | |
4399 | tree ctype = TREE_TYPE (context); | |
4400 | tree match = value_member (type, CLASSTYPE_TAGS (ctype)); | |
4401 | if (match) | |
4402 | return TREE_VALUE (match); | |
4403 | context = DECL_CONTEXT (context); | |
4404 | ||
4405 | /* When we have a nested class whose member functions have | |
4406 | local types (e.g., a set of enums), we'll arrive here | |
4407 | with the DECL_CONTEXT as the actual RECORD_TYPE node for | |
4408 | the enclosing class. Instead, we want to make sure we | |
4409 | come back in here with the TYPE_DECL, not the RECORD_TYPE. */ | |
4410 | if (context && TREE_CODE (context) == RECORD_TYPE) | |
4411 | context = TREE_CHAIN (context); | |
4412 | } | |
4413 | break; | |
4414 | case FUNCTION_DECL: | |
e1cd6e56 MS |
4415 | if (TYPE_NAME (type) && TYPE_IDENTIFIER (type)) |
4416 | return lookup_name (TYPE_IDENTIFIER (type), 1); | |
4417 | return NULL_TREE; | |
8d08fdba MS |
4418 | default: |
4419 | my_friendly_abort (12); | |
4420 | } | |
4421 | } | |
4422 | return NULL_TREE; | |
4423 | } | |
4424 | ||
a9aedbc2 | 4425 | /* Look up NAME in the NAMESPACE. */ |
e92cc029 | 4426 | |
a9aedbc2 MS |
4427 | tree |
4428 | lookup_namespace_name (namespace, name) | |
4429 | tree namespace, name; | |
4430 | { | |
30394414 JM |
4431 | #if 1 |
4432 | tree val; | |
4433 | my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 370); | |
4434 | my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 373); | |
4435 | ||
4436 | val = qualified_lookup_using_namespace (name, namespace); | |
4437 | if (val) | |
4438 | return val; | |
4439 | cp_error ("`%D' undeclared in namespace `%D'", name, namespace); | |
4440 | return error_mark_node; | |
4441 | #else | |
a9aedbc2 | 4442 | struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace); |
fc378698 | 4443 | tree x = NULL_TREE; |
fc378698 MS |
4444 | #if 1 |
4445 | /* This searches just one level. */ | |
4446 | if (b) | |
a9aedbc2 MS |
4447 | { |
4448 | for (x = b->names; x; x = TREE_CHAIN (x)) | |
4449 | if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name) | |
4450 | break; | |
a9aedbc2 | 4451 | } |
fc378698 MS |
4452 | #else |
4453 | /* This searches all levels. */ | |
4454 | for (; b && !x; b = b->level_chain) | |
4455 | { | |
4456 | for (x = b->names; x; x = TREE_CHAIN (x)) | |
4457 | if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name) | |
4458 | break; | |
4459 | } | |
4460 | #endif | |
a9aedbc2 | 4461 | return x; |
30394414 | 4462 | #endif |
a9aedbc2 MS |
4463 | } |
4464 | ||
5566b478 MS |
4465 | tree |
4466 | make_typename_type (context, name) | |
4467 | tree context, name; | |
4468 | { | |
a80e4195 MS |
4469 | tree t, d; |
4470 | ||
653cc74a JM |
4471 | if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') |
4472 | name = TYPE_IDENTIFIER (name); | |
4473 | else if (TREE_CODE (name) == TYPE_DECL) | |
a80e4195 MS |
4474 | name = DECL_NAME (name); |
4475 | else if (TREE_CODE (name) != IDENTIFIER_NODE) | |
4476 | my_friendly_abort (2000); | |
5566b478 | 4477 | |
85b71cf2 | 4478 | if (! uses_template_parms (context) |
7fcdf4c2 | 4479 | || context == current_class_type) |
5566b478 | 4480 | { |
ffb690bd JM |
4481 | if (IS_AGGR_TYPE (context)) |
4482 | t = lookup_field (context, name, 0, 1); | |
4483 | else | |
4484 | t = NULL_TREE; | |
4485 | ||
5566b478 MS |
4486 | if (t == NULL_TREE) |
4487 | { | |
e76a2646 | 4488 | cp_error ("no type named `%#T' in `%#T'", name, context); |
5566b478 MS |
4489 | return error_mark_node; |
4490 | } | |
4491 | return TREE_TYPE (t); | |
4492 | } | |
4493 | ||
5156628f | 4494 | if (processing_template_decl) |
5566b478 MS |
4495 | push_obstacks (&permanent_obstack, &permanent_obstack); |
4496 | t = make_lang_type (TYPENAME_TYPE); | |
4497 | d = build_decl (TYPE_DECL, name, t); | |
5156628f | 4498 | if (processing_template_decl) |
5566b478 MS |
4499 | pop_obstacks (); |
4500 | ||
4501 | TYPE_CONTEXT (t) = context; | |
d2e5ee5c MS |
4502 | TYPE_NAME (TREE_TYPE (d)) = d; |
4503 | TYPE_STUB_DECL (TREE_TYPE (d)) = d; | |
5566b478 | 4504 | DECL_CONTEXT (d) = context; |
7fcdf4c2 | 4505 | CLASSTYPE_GOT_SEMICOLON (t) = 1; |
5566b478 MS |
4506 | |
4507 | return t; | |
4508 | } | |
4509 | ||
bd2a82a6 JM |
4510 | /* Given a TYPE_DECL T looked up in CONTEXT, return a TYPENAME_TYPE |
4511 | where the scope is either CONTEXT or the first base of CONTEXT along the | |
4512 | inheritance chain to T that depends on template parameters. | |
4513 | ||
4514 | Called from lookup_name_real to implement the implicit typename | |
4515 | extension. */ | |
4516 | ||
4517 | static tree | |
4518 | make_implicit_typename (context, t) | |
4519 | tree context, t; | |
4520 | { | |
4521 | tree retval; | |
4522 | ||
3ac3d9ea MM |
4523 | if (TREE_CODE (context) != TYPENAME_TYPE |
4524 | && uses_template_parms (DECL_CONTEXT (t)) | |
bd2a82a6 JM |
4525 | && DECL_CONTEXT (t) != context) |
4526 | { | |
4527 | tree binfo = get_binfo (DECL_CONTEXT (t), context, 0); | |
5951f637 | 4528 | while (binfo) |
bd2a82a6 JM |
4529 | { |
4530 | tree next = BINFO_INHERITANCE_CHAIN (binfo); | |
4531 | if (! uses_template_parms (BINFO_TYPE (next)) | |
4532 | || BINFO_TYPE (next) == context) | |
4533 | break; | |
4534 | binfo = next; | |
4535 | } | |
5951f637 JM |
4536 | if (binfo) |
4537 | retval = make_typename_type (BINFO_TYPE (binfo), DECL_NAME (t)); | |
4538 | else | |
4539 | /* FIXME: find the enclosing class whose base t comes from. */ | |
4540 | retval = make_typename_type (DECL_CONTEXT (t), DECL_NAME (t)); | |
bd2a82a6 JM |
4541 | } |
4542 | else | |
4543 | retval = make_typename_type (context, DECL_NAME (t)); | |
4544 | ||
4545 | TREE_TYPE (retval) = TREE_TYPE (t); | |
4546 | return retval; | |
4547 | } | |
4548 | ||
8d08fdba MS |
4549 | /* Look up NAME in the current binding level and its superiors in the |
4550 | namespace of variables, functions and typedefs. Return a ..._DECL | |
4551 | node of some kind representing its definition if there is only one | |
4552 | such declaration, or return a TREE_LIST with all the overloaded | |
4553 | definitions if there are many, or return 0 if it is undefined. | |
4554 | ||
4555 | If PREFER_TYPE is > 0, we prefer TYPE_DECLs. | |
a28e3c7f | 4556 | If PREFER_TYPE is -2, we're being called from yylex(). (UGLY) |
f84b4be9 JM |
4557 | Otherwise we prefer non-TYPE_DECLs. |
4558 | ||
4559 | If NONCLASS is non-zero, we don't look for the NAME in class scope, | |
4560 | using IDENTIFIER_CLASS_VALUE. */ | |
8d08fdba | 4561 | |
824b9a4c | 4562 | static tree |
700f8a87 | 4563 | lookup_name_real (name, prefer_type, nonclass) |
8d08fdba | 4564 | tree name; |
700f8a87 | 4565 | int prefer_type, nonclass; |
8d08fdba MS |
4566 | { |
4567 | register tree val; | |
a28e3c7f | 4568 | int yylex = 0; |
e1cd6e56 | 4569 | tree from_obj = NULL_TREE; |
e76a2646 | 4570 | tree locval, classval; |
8d08fdba | 4571 | |
a28e3c7f MS |
4572 | if (prefer_type == -2) |
4573 | { | |
4574 | extern int looking_for_typename; | |
fc378698 | 4575 | tree type = NULL_TREE; |
a28e3c7f MS |
4576 | |
4577 | yylex = 1; | |
4578 | prefer_type = looking_for_typename; | |
e1cd6e56 | 4579 | |
653cc74a JM |
4580 | /* std:: becomes :: for now. */ |
4581 | if (got_scope == std_node) | |
4582 | got_scope = void_type_node; | |
4583 | ||
e1cd6e56 MS |
4584 | if (got_scope) |
4585 | type = got_scope; | |
dff6b454 | 4586 | else if (got_object != error_mark_node) |
e1cd6e56 | 4587 | type = got_object; |
a28e3c7f | 4588 | |
e1cd6e56 | 4589 | if (type) |
a28e3c7f | 4590 | { |
e1cd6e56 | 4591 | if (type == error_mark_node) |
f376e137 | 4592 | return error_mark_node; |
a80e4195 MS |
4593 | if (TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type)) |
4594 | type = TREE_TYPE (type); | |
5566b478 MS |
4595 | |
4596 | type = complete_type (type); | |
4597 | ||
4598 | if (type == void_type_node) | |
a28e3c7f | 4599 | val = IDENTIFIER_GLOBAL_VALUE (name); |
a9aedbc2 MS |
4600 | else if (TREE_CODE (type) == NAMESPACE_DECL) |
4601 | { | |
30394414 | 4602 | val = NAMESPACE_BINDING (name, type); |
a9aedbc2 | 4603 | } |
5566b478 | 4604 | else if (! IS_AGGR_TYPE (type) |
5156628f | 4605 | || TREE_CODE (type) == TEMPLATE_TYPE_PARM |
73b0fce8 | 4606 | || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM |
5156628f | 4607 | || TREE_CODE (type) == TYPENAME_TYPE) |
e92cc029 | 4608 | /* Someone else will give an error about this if needed. */ |
a28e3c7f | 4609 | val = NULL_TREE; |
e1cd6e56 | 4610 | else if (TYPE_BEING_DEFINED (type)) |
700f8a87 MS |
4611 | { |
4612 | val = IDENTIFIER_CLASS_VALUE (name); | |
e1cd6e56 | 4613 | if (val && DECL_CONTEXT (val) != type) |
700f8a87 MS |
4614 | { |
4615 | struct binding_level *b = class_binding_level; | |
4616 | for (val = NULL_TREE; b; b = b->level_chain) | |
4617 | { | |
4618 | tree t = purpose_member (name, b->class_shadowed); | |
4619 | if (t && TREE_VALUE (t) | |
e1cd6e56 | 4620 | && DECL_CONTEXT (TREE_VALUE (t)) == type) |
700f8a87 MS |
4621 | { |
4622 | val = TREE_VALUE (t); | |
4623 | break; | |
4624 | } | |
4625 | } | |
4626 | } | |
5566b478 | 4627 | if (val == NULL_TREE) |
e1cd6e56 | 4628 | val = lookup_field (type, name, 0, 1); |
700f8a87 | 4629 | } |
e1cd6e56 | 4630 | else if (type == current_class_type) |
a28e3c7f | 4631 | val = IDENTIFIER_CLASS_VALUE (name); |
a28e3c7f | 4632 | else |
e1cd6e56 | 4633 | val = lookup_field (type, name, 0, prefer_type); |
a28e3c7f | 4634 | } |
e1cd6e56 MS |
4635 | else |
4636 | val = NULL_TREE; | |
4637 | ||
85b71cf2 | 4638 | /* Add implicit 'typename' to scoped types from other classes. */ |
5156628f | 4639 | if (got_scope && processing_template_decl |
7fcdf4c2 | 4640 | && got_scope != current_class_type |
a80e4195 MS |
4641 | && uses_template_parms (got_scope) |
4642 | && val && TREE_CODE (val) == TYPE_DECL | |
4643 | && ! DECL_ARTIFICIAL (val)) | |
4644 | { | |
bd2a82a6 | 4645 | tree t = make_implicit_typename (got_scope, val); |
a80e4195 MS |
4646 | val = TYPE_MAIN_DECL (t); |
4647 | } | |
a80e4195 | 4648 | |
594740f3 | 4649 | if (got_scope) |
e1cd6e56 | 4650 | goto done; |
594740f3 | 4651 | else if (got_object && val) |
e1cd6e56 | 4652 | from_obj = val; |
a28e3c7f | 4653 | } |
e76a2646 MS |
4654 | |
4655 | locval = classval = NULL_TREE; | |
4656 | ||
8d08fdba MS |
4657 | if (current_binding_level != global_binding_level |
4658 | && IDENTIFIER_LOCAL_VALUE (name)) | |
e76a2646 MS |
4659 | locval = IDENTIFIER_LOCAL_VALUE (name); |
4660 | ||
8d08fdba MS |
4661 | /* In C++ class fields are between local and global scope, |
4662 | just before the global scope. */ | |
e76a2646 | 4663 | if (current_class_type && ! nonclass) |
8d08fdba | 4664 | { |
e76a2646 MS |
4665 | classval = IDENTIFIER_CLASS_VALUE (name); |
4666 | if (classval == NULL_TREE && TYPE_BEING_DEFINED (current_class_type)) | |
700f8a87 MS |
4667 | /* Try to find values from base classes if we are presently |
4668 | defining a type. We are presently only interested in | |
4669 | TYPE_DECLs. */ | |
e76a2646 | 4670 | classval = lookup_field (current_class_type, name, 0, 1); |
8d08fdba MS |
4671 | |
4672 | /* yylex() calls this with -2, since we should never start digging for | |
4673 | the nested name at the point where we haven't even, for example, | |
4674 | created the COMPONENT_REF or anything like that. */ | |
e76a2646 MS |
4675 | if (classval == NULL_TREE) |
4676 | classval = lookup_nested_field (name, ! yylex); | |
85b71cf2 JM |
4677 | |
4678 | /* Add implicit 'typename' to types from base classes. */ | |
4679 | if (processing_template_decl | |
4680 | && classval && TREE_CODE (classval) == TYPE_DECL | |
4681 | && DECL_CONTEXT (classval) != current_class_type | |
4682 | && uses_template_parms (DECL_CONTEXT (classval)) | |
4683 | && ! DECL_ARTIFICIAL (classval)) | |
4684 | { | |
bd2a82a6 | 4685 | tree t = make_implicit_typename (current_class_type, classval); |
85b71cf2 JM |
4686 | classval = TYPE_MAIN_DECL (t); |
4687 | } | |
e76a2646 | 4688 | } |
8d08fdba | 4689 | |
e76a2646 MS |
4690 | if (locval && classval) |
4691 | { | |
4692 | if (current_scope () == current_function_decl | |
4693 | && ! hack_decl_function_context (current_function_decl)) | |
4694 | /* Not in a nested function. */ | |
4695 | val = locval; | |
4696 | else | |
4697 | { | |
4698 | /* This is incredibly horrible. The whole concept of | |
4699 | IDENTIFIER_LOCAL_VALUE / IDENTIFIER_CLASS_VALUE / | |
4700 | IDENTIFIER_GLOBAL_VALUE needs to be scrapped for local | |
4701 | classes. */ | |
4702 | tree lctx = hack_decl_function_context (locval); | |
4703 | tree cctx = hack_decl_function_context (classval); | |
4704 | ||
4705 | if (lctx == current_scope ()) | |
4706 | val = locval; | |
4707 | else if (lctx == cctx) | |
4708 | val = classval; | |
4709 | else | |
4710 | /* I don't know which is right; let's just guess for now. */ | |
4711 | val = locval; | |
4712 | } | |
8d08fdba | 4713 | } |
e76a2646 MS |
4714 | else if (locval) |
4715 | val = locval; | |
4716 | else if (classval) | |
4717 | val = classval; | |
8d08fdba | 4718 | else |
30394414 JM |
4719 | { |
4720 | /* unscoped lookup of a global, iterate over namespaces, | |
4721 | considering using namespace statements */ | |
4722 | tree binding; | |
4723 | tree scope = current_namespace; | |
4724 | do | |
4725 | { | |
4726 | binding = binding_for_name (name, scope); | |
4727 | val = BINDING_VALUE (binding); | |
4728 | val = lookup_using_namespace (name, val, current_namespace, scope); | |
4729 | if (scope == global_namespace) | |
4730 | break; | |
4731 | scope = DECL_NAMESPACE (scope); | |
4732 | } | |
4733 | while (!val); | |
4734 | } | |
8d08fdba | 4735 | |
a28e3c7f | 4736 | done: |
8d08fdba MS |
4737 | if (val) |
4738 | { | |
c91a56d2 | 4739 | /* This should only warn about types used in qualified-ids. */ |
e1cd6e56 | 4740 | if (from_obj && from_obj != val) |
5566b478 | 4741 | { |
c91a56d2 MS |
4742 | if (looking_for_typename && TREE_CODE (from_obj) == TYPE_DECL |
4743 | && TREE_CODE (val) == TYPE_DECL | |
4744 | && TREE_TYPE (from_obj) != TREE_TYPE (val)) | |
4745 | { | |
4746 | cp_pedwarn ("lookup of `%D' in the scope of `%#T' (`%#T')", | |
4747 | name, got_object, TREE_TYPE (from_obj)); | |
4748 | cp_pedwarn (" does not match lookup in the current scope (`%#T')", | |
4749 | TREE_TYPE (val)); | |
4750 | } | |
594740f3 MS |
4751 | |
4752 | val = from_obj; | |
5566b478 | 4753 | } |
e1cd6e56 | 4754 | |
cf776105 | 4755 | if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template) |
a0a33927 | 4756 | || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0) |
e1cd6e56 MS |
4757 | ; |
4758 | else if (IDENTIFIER_HAS_TYPE_VALUE (name)) | |
d2e5ee5c | 4759 | val = TYPE_MAIN_DECL (IDENTIFIER_TYPE_VALUE (name)); |
e1cd6e56 MS |
4760 | else if (TREE_TYPE (val) == error_mark_node) |
4761 | val = error_mark_node; | |
8d08fdba | 4762 | } |
e1cd6e56 MS |
4763 | else if (from_obj) |
4764 | val = from_obj; | |
8d08fdba MS |
4765 | |
4766 | return val; | |
4767 | } | |
4768 | ||
700f8a87 MS |
4769 | tree |
4770 | lookup_name_nonclass (name) | |
4771 | tree name; | |
4772 | { | |
4773 | return lookup_name_real (name, 0, 1); | |
4774 | } | |
4775 | ||
4776 | tree | |
4777 | lookup_name (name, prefer_type) | |
4778 | tree name; | |
4779 | int prefer_type; | |
4780 | { | |
4781 | return lookup_name_real (name, prefer_type, 0); | |
4782 | } | |
4783 | ||
8d08fdba MS |
4784 | /* Similar to `lookup_name' but look only at current binding level. */ |
4785 | ||
4786 | tree | |
4787 | lookup_name_current_level (name) | |
4788 | tree name; | |
4789 | { | |
4790 | register tree t = NULL_TREE; | |
4791 | ||
4792 | if (current_binding_level == global_binding_level) | |
4793 | { | |
30394414 | 4794 | t = IDENTIFIER_NAMESPACE_VALUE (name); |
8d08fdba MS |
4795 | |
4796 | /* extern "C" function() */ | |
4797 | if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST) | |
4798 | t = TREE_VALUE (t); | |
4799 | } | |
4800 | else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE) | |
4801 | { | |
a4443a08 MS |
4802 | struct binding_level *b = current_binding_level; |
4803 | while (1) | |
4804 | { | |
4805 | for (t = b->names; t; t = TREE_CHAIN (t)) | |
e1cd6e56 | 4806 | if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name) |
a4443a08 MS |
4807 | goto out; |
4808 | if (b->keep == 2) | |
4809 | b = b->level_chain; | |
4810 | else | |
4811 | break; | |
4812 | } | |
4813 | out: | |
4814 | ; | |
8d08fdba MS |
4815 | } |
4816 | ||
4817 | return t; | |
4818 | } | |
4819 | \f | |
4820 | /* Arrange for the user to get a source line number, even when the | |
4821 | compiler is going down in flames, so that she at least has a | |
4822 | chance of working around problems in the compiler. We used to | |
4823 | call error(), but that let the segmentation fault continue | |
4824 | through; now, it's much more passive by asking them to send the | |
4825 | maintainers mail about the problem. */ | |
4826 | ||
4827 | static void | |
4828 | signal_catch (sig) | |
4829 | int sig; | |
4830 | { | |
4831 | signal (SIGSEGV, SIG_DFL); | |
4832 | #ifdef SIGIOT | |
4833 | signal (SIGIOT, SIG_DFL); | |
4834 | #endif | |
4835 | #ifdef SIGILL | |
4836 | signal (SIGILL, SIG_DFL); | |
4837 | #endif | |
4838 | #ifdef SIGABRT | |
4839 | signal (SIGABRT, SIG_DFL); | |
4840 | #endif | |
4841 | #ifdef SIGBUS | |
4842 | signal (SIGBUS, SIG_DFL); | |
4843 | #endif | |
4844 | my_friendly_abort (0); | |
4845 | } | |
4846 | ||
de22184b MS |
4847 | #if 0 |
4848 | /* Unused -- brendan 970107 */ | |
8d08fdba MS |
4849 | /* Array for holding types considered "built-in". These types |
4850 | are output in the module in which `main' is defined. */ | |
4851 | static tree *builtin_type_tdescs_arr; | |
4852 | static int builtin_type_tdescs_len, builtin_type_tdescs_max; | |
de22184b | 4853 | #endif |
8d08fdba MS |
4854 | |
4855 | /* Push the declarations of builtin types into the namespace. | |
4856 | RID_INDEX, if < RID_MAX is the index of the builtin type | |
4857 | in the array RID_POINTERS. NAME is the name used when looking | |
4858 | up the builtin type. TYPE is the _TYPE node for the builtin type. */ | |
4859 | ||
4860 | static void | |
4861 | record_builtin_type (rid_index, name, type) | |
4862 | enum rid rid_index; | |
4863 | char *name; | |
4864 | tree type; | |
4865 | { | |
4866 | tree rname = NULL_TREE, tname = NULL_TREE; | |
a703fb38 | 4867 | tree tdecl = NULL_TREE; |
8d08fdba MS |
4868 | |
4869 | if ((int) rid_index < (int) RID_MAX) | |
4870 | rname = ridpointers[(int) rid_index]; | |
4871 | if (name) | |
4872 | tname = get_identifier (name); | |
4873 | ||
4874 | TYPE_BUILT_IN (type) = 1; | |
4875 | ||
4876 | if (tname) | |
4877 | { | |
8d08fdba | 4878 | tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); |
8d08fdba MS |
4879 | set_identifier_type_value (tname, NULL_TREE); |
4880 | if ((int) rid_index < (int) RID_MAX) | |
30394414 | 4881 | /* builtin types live in the global namespace */ |
8d08fdba MS |
4882 | IDENTIFIER_GLOBAL_VALUE (tname) = tdecl; |
4883 | } | |
4884 | if (rname != NULL_TREE) | |
4885 | { | |
4886 | if (tname != NULL_TREE) | |
4887 | { | |
4888 | set_identifier_type_value (rname, NULL_TREE); | |
4889 | IDENTIFIER_GLOBAL_VALUE (rname) = tdecl; | |
4890 | } | |
4891 | else | |
4892 | { | |
8d08fdba | 4893 | tdecl = pushdecl (build_decl (TYPE_DECL, rname, type)); |
8d08fdba MS |
4894 | set_identifier_type_value (rname, NULL_TREE); |
4895 | } | |
4896 | } | |
8d08fdba MS |
4897 | } |
4898 | ||
8d08fdba MS |
4899 | /* Push overloaded decl, in global scope, with one argument so it |
4900 | can be used as a callback from define_function. */ | |
e92cc029 | 4901 | |
8d08fdba MS |
4902 | static void |
4903 | push_overloaded_decl_1 (x) | |
4904 | tree x; | |
4905 | { | |
4906 | push_overloaded_decl (x, 0); | |
4907 | } | |
4908 | ||
8ccc31eb MS |
4909 | #ifdef __GNUC__ |
4910 | __inline | |
4911 | #endif | |
6b5fbb55 MS |
4912 | tree |
4913 | auto_function (name, type, code) | |
8ccc31eb MS |
4914 | tree name, type; |
4915 | enum built_in_function code; | |
4916 | { | |
4917 | return define_function | |
49c249e1 | 4918 | (IDENTIFIER_POINTER (name), type, code, push_overloaded_decl_1, |
8ccc31eb MS |
4919 | IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type), |
4920 | 0))); | |
4921 | } | |
4922 | ||
8d08fdba MS |
4923 | /* Create the predefined scalar types of C, |
4924 | and some nodes representing standard constants (0, 1, (void *)0). | |
4925 | Initialize the global binding level. | |
4926 | Make definitions for built-in primitive functions. */ | |
4927 | ||
4928 | void | |
4929 | init_decl_processing () | |
4930 | { | |
4931 | tree decl; | |
de22184b | 4932 | register tree endlink, int_endlink, double_endlink, unsigned_endlink; |
8d08fdba | 4933 | tree fields[20]; |
8d08fdba | 4934 | /* Data type of memcpy. */ |
cffa8729 | 4935 | tree memcpy_ftype, strlen_ftype; |
8d08fdba MS |
4936 | int wchar_type_size; |
4937 | tree temp; | |
4938 | tree array_domain_type; | |
e1cd6e56 | 4939 | extern int flag_strict_prototype; |
a703fb38 | 4940 | tree vb_off_identifier = NULL_TREE; |
5566b478 MS |
4941 | /* Function type `char *(char *, char *)' and similar ones */ |
4942 | tree string_ftype_ptr_ptr, int_ftype_string_string; | |
de22184b MS |
4943 | tree sizetype_endlink; |
4944 | tree ptr_ftype, ptr_ftype_unsigned, ptr_ftype_sizetype; | |
ca55abae | 4945 | tree void_ftype, void_ftype_int, void_ftype_ptr, ptr_ftype_void; |
8d08fdba MS |
4946 | |
4947 | /* Have to make these distinct before we try using them. */ | |
4948 | lang_name_cplusplus = get_identifier ("C++"); | |
4949 | lang_name_c = get_identifier ("C"); | |
4950 | ||
30394414 JM |
4951 | /* enter the global namespace */ |
4952 | my_friendly_assert (global_namespace == NULL_TREE, 375); | |
4953 | my_friendly_assert (current_lang_name == NULL_TREE, 375); | |
4954 | current_lang_name = lang_name_cplusplus; | |
4955 | push_namespace (get_identifier ("::")); | |
4956 | global_namespace = current_namespace; | |
4957 | current_lang_name = NULL_TREE; | |
4958 | ||
e1cd6e56 MS |
4959 | if (flag_strict_prototype == 2) |
4960 | { | |
4961 | if (pedantic) | |
4962 | strict_prototypes_lang_c = strict_prototypes_lang_cplusplus; | |
4963 | } | |
4964 | else | |
4965 | strict_prototypes_lang_c = flag_strict_prototype; | |
8926095f | 4966 | |
8d08fdba MS |
4967 | /* Initially, C. */ |
4968 | current_lang_name = lang_name_c; | |
4969 | ||
4970 | current_function_decl = NULL_TREE; | |
4971 | named_labels = NULL_TREE; | |
e349ee73 | 4972 | named_label_uses = NULL; |
8d08fdba MS |
4973 | current_binding_level = NULL_BINDING_LEVEL; |
4974 | free_binding_level = NULL_BINDING_LEVEL; | |
4975 | ||
42976354 | 4976 | #ifndef __CYGWIN32__ |
8d08fdba MS |
4977 | /* Because most segmentation signals can be traced back into user |
4978 | code, catch them and at least give the user a chance of working | |
e92cc029 | 4979 | around compiler bugs. */ |
8d08fdba MS |
4980 | signal (SIGSEGV, signal_catch); |
4981 | ||
4982 | /* We will also catch aborts in the back-end through signal_catch and | |
4983 | give the user a chance to see where the error might be, and to defeat | |
4984 | aborts in the back-end when there have been errors previously in their | |
e92cc029 | 4985 | code. */ |
8d08fdba MS |
4986 | #ifdef SIGIOT |
4987 | signal (SIGIOT, signal_catch); | |
4988 | #endif | |
4989 | #ifdef SIGILL | |
4990 | signal (SIGILL, signal_catch); | |
4991 | #endif | |
4992 | #ifdef SIGABRT | |
4993 | signal (SIGABRT, signal_catch); | |
4994 | #endif | |
4995 | #ifdef SIGBUS | |
4996 | signal (SIGBUS, signal_catch); | |
4997 | #endif | |
7834ab39 MS |
4998 | #else /* ndef __CYGWIN32__ */ |
4999 | /* Cygwin32 cannot handle catching signals other than | |
5000 | SIGABRT yet. We hope this will cease to be the case soon. */ | |
5001 | #ifdef SIGABRT | |
5002 | signal (SIGABRT, signal_catch); | |
5003 | #endif | |
5004 | #endif /* ndef __CYGWIN32__ */ | |
8d08fdba MS |
5005 | |
5006 | gcc_obstack_init (&decl_obstack); | |
8d08fdba MS |
5007 | |
5008 | /* Must lay these out before anything else gets laid out. */ | |
5009 | error_mark_node = make_node (ERROR_MARK); | |
5010 | TREE_PERMANENT (error_mark_node) = 1; | |
5011 | TREE_TYPE (error_mark_node) = error_mark_node; | |
5012 | error_mark_list = build_tree_list (error_mark_node, error_mark_node); | |
5013 | TREE_TYPE (error_mark_list) = error_mark_node; | |
5014 | ||
a28e3c7f MS |
5015 | /* Make the binding_level structure for global names. */ |
5016 | pushlevel (0); | |
8d08fdba MS |
5017 | global_binding_level = current_binding_level; |
5018 | ||
5019 | this_identifier = get_identifier (THIS_NAME); | |
5020 | in_charge_identifier = get_identifier (IN_CHARGE_NAME); | |
fc378698 MS |
5021 | ctor_identifier = get_identifier (CTOR_NAME); |
5022 | dtor_identifier = get_identifier (DTOR_NAME); | |
8d08fdba MS |
5023 | pfn_identifier = get_identifier (VTABLE_PFN_NAME); |
5024 | index_identifier = get_identifier (VTABLE_INDEX_NAME); | |
5025 | delta_identifier = get_identifier (VTABLE_DELTA_NAME); | |
5026 | delta2_identifier = get_identifier (VTABLE_DELTA2_NAME); | |
5027 | pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2"); | |
dff6b454 RK |
5028 | if (flag_handle_signatures) |
5029 | { | |
5030 | tag_identifier = get_identifier (SIGTABLE_TAG_NAME); | |
9dd70aa4 GB |
5031 | vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME); |
5032 | vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME); | |
dff6b454 | 5033 | } |
8d08fdba MS |
5034 | |
5035 | /* Define `int' and `char' first so that dbx will output them first. */ | |
5036 | ||
5037 | integer_type_node = make_signed_type (INT_TYPE_SIZE); | |
5038 | record_builtin_type (RID_INT, NULL_PTR, integer_type_node); | |
5039 | ||
5040 | /* Define `char', which is like either `signed char' or `unsigned char' | |
5041 | but not the same as either. */ | |
5042 | ||
beb53fb8 JM |
5043 | char_type_node |
5044 | = (flag_signed_char | |
5045 | ? make_signed_type (CHAR_TYPE_SIZE) | |
5046 | : make_unsigned_type (CHAR_TYPE_SIZE)); | |
8d08fdba MS |
5047 | record_builtin_type (RID_CHAR, "char", char_type_node); |
5048 | ||
5049 | long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); | |
5050 | record_builtin_type (RID_LONG, "long int", long_integer_type_node); | |
5051 | ||
5052 | unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); | |
5053 | record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); | |
5054 | ||
5055 | long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); | |
5056 | record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node); | |
5057 | record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); | |
5058 | ||
5059 | long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); | |
5060 | record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node); | |
5061 | ||
5062 | long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); | |
5063 | record_builtin_type (RID_MAX, "long long unsigned int", | |
5064 | long_long_unsigned_type_node); | |
5065 | record_builtin_type (RID_MAX, "long long unsigned", | |
5066 | long_long_unsigned_type_node); | |
5067 | ||
5156628f MS |
5068 | short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); |
5069 | record_builtin_type (RID_SHORT, "short int", short_integer_type_node); | |
5070 | short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); | |
5071 | record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); | |
5072 | record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); | |
5073 | ||
8d08fdba | 5074 | /* `unsigned long' is the standard type for sizeof. |
8d08fdba | 5075 | Note that stddef.h uses `unsigned long', |
f5426d1e R |
5076 | and this must agree, even if long and int are the same size. */ |
5077 | set_sizetype | |
5078 | (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)))); | |
8d08fdba MS |
5079 | |
5080 | ptrdiff_type_node | |
5081 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); | |
5082 | ||
8d08fdba MS |
5083 | /* Define both `signed char' and `unsigned char'. */ |
5084 | signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); | |
5085 | record_builtin_type (RID_MAX, "signed char", signed_char_type_node); | |
5086 | unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); | |
5087 | record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); | |
5088 | ||
5089 | /* These are types that type_for_size and type_for_mode use. */ | |
5090 | intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); | |
5091 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); | |
5092 | intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); | |
5093 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); | |
5094 | intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); | |
5095 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); | |
5096 | intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); | |
5097 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); | |
5098 | unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); | |
5099 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); | |
5100 | unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); | |
5101 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); | |
5102 | unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); | |
5103 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); | |
5104 | unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); | |
5105 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); | |
5106 | ||
5107 | float_type_node = make_node (REAL_TYPE); | |
5108 | TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; | |
5109 | record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node); | |
5110 | layout_type (float_type_node); | |
5111 | ||
5112 | double_type_node = make_node (REAL_TYPE); | |
5113 | if (flag_short_double) | |
5114 | TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; | |
5115 | else | |
5116 | TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; | |
5117 | record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node); | |
5118 | layout_type (double_type_node); | |
5119 | ||
5120 | long_double_type_node = make_node (REAL_TYPE); | |
5121 | TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; | |
5122 | record_builtin_type (RID_MAX, "long double", long_double_type_node); | |
5123 | layout_type (long_double_type_node); | |
5124 | ||
37c46b43 MS |
5125 | complex_integer_type_node = make_node (COMPLEX_TYPE); |
5126 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"), | |
5127 | complex_integer_type_node)); | |
5128 | TREE_TYPE (complex_integer_type_node) = integer_type_node; | |
5129 | layout_type (complex_integer_type_node); | |
5130 | ||
5131 | complex_float_type_node = make_node (COMPLEX_TYPE); | |
5132 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"), | |
5133 | complex_float_type_node)); | |
5134 | TREE_TYPE (complex_float_type_node) = float_type_node; | |
5135 | layout_type (complex_float_type_node); | |
5136 | ||
5137 | complex_double_type_node = make_node (COMPLEX_TYPE); | |
5138 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"), | |
5139 | complex_double_type_node)); | |
5140 | TREE_TYPE (complex_double_type_node) = double_type_node; | |
5141 | layout_type (complex_double_type_node); | |
5142 | ||
5143 | complex_long_double_type_node = make_node (COMPLEX_TYPE); | |
5144 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"), | |
5145 | complex_long_double_type_node)); | |
5146 | TREE_TYPE (complex_long_double_type_node) = long_double_type_node; | |
5147 | layout_type (complex_long_double_type_node); | |
5148 | ||
8d08fdba MS |
5149 | integer_zero_node = build_int_2 (0, 0); |
5150 | TREE_TYPE (integer_zero_node) = integer_type_node; | |
5151 | integer_one_node = build_int_2 (1, 0); | |
5152 | TREE_TYPE (integer_one_node) = integer_type_node; | |
5153 | integer_two_node = build_int_2 (2, 0); | |
5154 | TREE_TYPE (integer_two_node) = integer_type_node; | |
5155 | integer_three_node = build_int_2 (3, 0); | |
5156 | TREE_TYPE (integer_three_node) = integer_type_node; | |
8d08fdba | 5157 | |
255512c1 JM |
5158 | boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); |
5159 | TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); | |
5160 | record_builtin_type (RID_BOOL, "bool", boolean_type_node); | |
5161 | boolean_false_node = build_int_2 (0, 0); | |
5162 | TREE_TYPE (boolean_false_node) = boolean_type_node; | |
5163 | boolean_true_node = build_int_2 (1, 0); | |
5164 | TREE_TYPE (boolean_true_node) = boolean_type_node; | |
2986ae00 | 5165 | |
8d08fdba MS |
5166 | /* These are needed by stor-layout.c. */ |
5167 | size_zero_node = size_int (0); | |
5168 | size_one_node = size_int (1); | |
5169 | ||
e92cc029 MS |
5170 | signed_size_zero_node = build_int_2 (0, 0); |
5171 | TREE_TYPE (signed_size_zero_node) = make_signed_type (TYPE_PRECISION (sizetype)); | |
5172 | ||
8d08fdba MS |
5173 | void_type_node = make_node (VOID_TYPE); |
5174 | record_builtin_type (RID_VOID, NULL_PTR, void_type_node); | |
5175 | layout_type (void_type_node); /* Uses integer_zero_node. */ | |
5176 | void_list_node = build_tree_list (NULL_TREE, void_type_node); | |
5177 | TREE_PARMLIST (void_list_node) = 1; | |
5178 | ||
d11ad92e | 5179 | null_pointer_node = build_int_2 (0, 0); |
8d08fdba | 5180 | TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); |
d11ad92e MS |
5181 | layout_type (TREE_TYPE (null_pointer_node)); |
5182 | ||
8d08fdba MS |
5183 | /* Used for expressions that do nothing, but are not errors. */ |
5184 | void_zero_node = build_int_2 (0, 0); | |
5185 | TREE_TYPE (void_zero_node) = void_type_node; | |
5186 | ||
5187 | string_type_node = build_pointer_type (char_type_node); | |
beb53fb8 JM |
5188 | const_string_type_node |
5189 | = build_pointer_type (build_type_variant (char_type_node, 1, 0)); | |
6b5fbb55 | 5190 | #if 0 |
8d08fdba | 5191 | record_builtin_type (RID_MAX, NULL_PTR, string_type_node); |
6b5fbb55 | 5192 | #endif |
8d08fdba MS |
5193 | |
5194 | /* Make a type to be the domain of a few array types | |
5195 | whose domains don't really matter. | |
5196 | 200 is small enough that it always fits in size_t | |
5197 | and large enough that it can hold most function names for the | |
5198 | initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ | |
5199 | array_domain_type = build_index_type (build_int_2 (200, 0)); | |
5200 | ||
5201 | /* make a type for arrays of characters. | |
5202 | With luck nothing will ever really depend on the length of this | |
5203 | array type. */ | |
5204 | char_array_type_node | |
5205 | = build_array_type (char_type_node, array_domain_type); | |
5206 | /* Likewise for arrays of ints. */ | |
5207 | int_array_type_node | |
5208 | = build_array_type (integer_type_node, array_domain_type); | |
5209 | ||
5210 | /* This is just some anonymous class type. Nobody should ever | |
5211 | need to look inside this envelope. */ | |
5212 | class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE)); | |
5213 | ||
5214 | default_function_type | |
5215 | = build_function_type (integer_type_node, NULL_TREE); | |
8d08fdba MS |
5216 | |
5217 | ptr_type_node = build_pointer_type (void_type_node); | |
beb53fb8 JM |
5218 | const_ptr_type_node |
5219 | = build_pointer_type (build_type_variant (void_type_node, 1, 0)); | |
6b5fbb55 | 5220 | #if 0 |
8d08fdba | 5221 | record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node); |
6b5fbb55 | 5222 | #endif |
8d08fdba MS |
5223 | endlink = void_list_node; |
5224 | int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); | |
5225 | double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); | |
de22184b MS |
5226 | unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink); |
5227 | ||
5228 | ptr_ftype = build_function_type (ptr_type_node, NULL_TREE); | |
5229 | ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink); | |
5230 | sizetype_endlink = tree_cons (NULL_TREE, sizetype, endlink); | |
5231 | /* We realloc here because sizetype could be int or unsigned. S'ok. */ | |
5232 | ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink); | |
5233 | ||
5234 | void_ftype = build_function_type (void_type_node, endlink); | |
5235 | void_ftype_int = build_function_type (void_type_node, int_endlink); | |
5236 | void_ftype_ptr | |
5237 | = build_function_type (void_type_node, | |
5238 | tree_cons (NULL_TREE, ptr_type_node, endlink)); | |
824b9a4c MS |
5239 | void_ftype_ptr |
5240 | = build_exception_variant (void_ftype_ptr, | |
5241 | tree_cons (NULL_TREE, NULL_TREE, NULL_TREE)); | |
8d08fdba | 5242 | |
cffa8729 MS |
5243 | float_ftype_float |
5244 | = build_function_type (float_type_node, | |
5245 | tree_cons (NULL_TREE, float_type_node, endlink)); | |
5246 | ||
8d08fdba MS |
5247 | double_ftype_double |
5248 | = build_function_type (double_type_node, double_endlink); | |
5249 | ||
cffa8729 MS |
5250 | ldouble_ftype_ldouble |
5251 | = build_function_type (long_double_type_node, | |
5252 | tree_cons (NULL_TREE, long_double_type_node, | |
5253 | endlink)); | |
5254 | ||
8d08fdba MS |
5255 | double_ftype_double_double |
5256 | = build_function_type (double_type_node, | |
a28e3c7f MS |
5257 | tree_cons (NULL_TREE, double_type_node, |
5258 | double_endlink)); | |
8d08fdba MS |
5259 | |
5260 | int_ftype_int | |
5261 | = build_function_type (integer_type_node, int_endlink); | |
5262 | ||
5263 | long_ftype_long | |
5264 | = build_function_type (long_integer_type_node, | |
a28e3c7f MS |
5265 | tree_cons (NULL_TREE, long_integer_type_node, |
5266 | endlink)); | |
8d08fdba | 5267 | |
8d08fdba MS |
5268 | int_ftype_cptr_cptr_sizet |
5269 | = build_function_type (integer_type_node, | |
5270 | tree_cons (NULL_TREE, const_ptr_type_node, | |
5271 | tree_cons (NULL_TREE, const_ptr_type_node, | |
5272 | tree_cons (NULL_TREE, | |
5273 | sizetype, | |
5274 | endlink)))); | |
5275 | ||
8d08fdba MS |
5276 | string_ftype_ptr_ptr /* strcpy prototype */ |
5277 | = build_function_type (string_type_node, | |
5278 | tree_cons (NULL_TREE, string_type_node, | |
5279 | tree_cons (NULL_TREE, | |
5280 | const_string_type_node, | |
5281 | endlink))); | |
5282 | ||
8d08fdba MS |
5283 | int_ftype_string_string /* strcmp prototype */ |
5284 | = build_function_type (integer_type_node, | |
5285 | tree_cons (NULL_TREE, const_string_type_node, | |
5286 | tree_cons (NULL_TREE, | |
5287 | const_string_type_node, | |
5288 | endlink))); | |
5289 | ||
cffa8729 | 5290 | strlen_ftype /* strlen prototype */ |
8d08fdba MS |
5291 | = build_function_type (sizetype, |
5292 | tree_cons (NULL_TREE, const_string_type_node, | |
5293 | endlink)); | |
5294 | ||
8d08fdba | 5295 | memcpy_ftype /* memcpy prototype */ |
d22c8596 | 5296 | = build_function_type (ptr_type_node, |
8d08fdba MS |
5297 | tree_cons (NULL_TREE, ptr_type_node, |
5298 | tree_cons (NULL_TREE, const_ptr_type_node, | |
de22184b | 5299 | sizetype_endlink))); |
8d08fdba MS |
5300 | |
5301 | if (flag_huge_objects) | |
5302 | delta_type_node = long_integer_type_node; | |
5303 | else | |
5304 | delta_type_node = short_integer_type_node; | |
5305 | ||
b9620d0e | 5306 | builtin_function ("__builtin_constant_p", default_function_type, |
8d08fdba MS |
5307 | BUILT_IN_CONSTANT_P, NULL_PTR); |
5308 | ||
beb53fb8 JM |
5309 | builtin_return_address_fndecl |
5310 | = builtin_function ("__builtin_return_address", ptr_ftype_unsigned, | |
5311 | BUILT_IN_RETURN_ADDRESS, NULL_PTR); | |
8926095f | 5312 | |
de22184b | 5313 | builtin_function ("__builtin_frame_address", ptr_ftype_unsigned, |
8926095f MS |
5314 | BUILT_IN_FRAME_ADDRESS, NULL_PTR); |
5315 | ||
ca55abae JM |
5316 | ptr_ftype_void = build_function_type (ptr_type_node, endlink); |
5317 | builtin_function ("__builtin_fp", ptr_ftype_void, BUILT_IN_FP, NULL_PTR); | |
5318 | builtin_function ("__builtin_sp", ptr_ftype_void, BUILT_IN_SP, NULL_PTR); | |
5319 | ||
de22184b | 5320 | builtin_function ("__builtin_alloca", ptr_ftype_sizetype, |
8d08fdba | 5321 | BUILT_IN_ALLOCA, "alloca"); |
cffa8729 | 5322 | builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); |
00595019 MS |
5323 | /* Define alloca, ffs as builtins. |
5324 | Declare _exit just to mark it as volatile. */ | |
5325 | if (! flag_no_builtin && !flag_no_nonansi_builtin) | |
5326 | { | |
de22184b | 5327 | temp = builtin_function ("alloca", ptr_ftype_sizetype, |
00595019 MS |
5328 | BUILT_IN_ALLOCA, NULL_PTR); |
5329 | /* Suppress error if redefined as a non-function. */ | |
5330 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
00595019 MS |
5331 | temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); |
5332 | /* Suppress error if redefined as a non-function. */ | |
5333 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
de22184b | 5334 | temp = builtin_function ("_exit", void_ftype_int, |
00595019 MS |
5335 | NOT_BUILT_IN, NULL_PTR); |
5336 | TREE_THIS_VOLATILE (temp) = 1; | |
5337 | TREE_SIDE_EFFECTS (temp) = 1; | |
5338 | /* Suppress error if redefined as a non-function. */ | |
5339 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
5340 | } | |
8d08fdba | 5341 | |
cffa8729 MS |
5342 | builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); |
5343 | builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS, | |
5344 | NULL_PTR); | |
5345 | builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, | |
5346 | NULL_PTR); | |
5347 | builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, | |
5348 | NULL_PTR); | |
8d08fdba MS |
5349 | builtin_function ("__builtin_labs", long_ftype_long, |
5350 | BUILT_IN_LABS, NULL_PTR); | |
de22184b | 5351 | builtin_function ("__builtin_saveregs", ptr_ftype, |
8d08fdba | 5352 | BUILT_IN_SAVEREGS, NULL_PTR); |
8d08fdba MS |
5353 | builtin_function ("__builtin_classify_type", default_function_type, |
5354 | BUILT_IN_CLASSIFY_TYPE, NULL_PTR); | |
de22184b | 5355 | builtin_function ("__builtin_next_arg", ptr_ftype, |
8d08fdba | 5356 | BUILT_IN_NEXT_ARG, NULL_PTR); |
de22184b | 5357 | builtin_function ("__builtin_args_info", int_ftype_int, |
8d08fdba | 5358 | BUILT_IN_ARGS_INFO, NULL_PTR); |
eb66be0e MS |
5359 | builtin_function ("__builtin_setjmp", |
5360 | build_function_type (integer_type_node, | |
5361 | tree_cons (NULL_TREE, ptr_type_node, | |
5362 | endlink)), | |
5363 | BUILT_IN_SETJMP, NULL_PTR); | |
5364 | builtin_function ("__builtin_longjmp", | |
5365 | build_function_type (integer_type_node, | |
5366 | tree_cons (NULL_TREE, ptr_type_node, | |
5367 | tree_cons (NULL_TREE, | |
5368 | integer_type_node, | |
5369 | endlink))), | |
5370 | BUILT_IN_LONGJMP, NULL_PTR); | |
8d08fdba MS |
5371 | |
5372 | /* Untyped call and return. */ | |
de22184b | 5373 | builtin_function ("__builtin_apply_args", ptr_ftype, |
8d08fdba MS |
5374 | BUILT_IN_APPLY_ARGS, NULL_PTR); |
5375 | ||
5376 | temp = tree_cons (NULL_TREE, | |
5377 | build_pointer_type (build_function_type (void_type_node, | |
5378 | NULL_TREE)), | |
de22184b | 5379 | ptr_ftype_sizetype); |
8d08fdba MS |
5380 | builtin_function ("__builtin_apply", |
5381 | build_function_type (ptr_type_node, temp), | |
5382 | BUILT_IN_APPLY, NULL_PTR); | |
de22184b | 5383 | builtin_function ("__builtin_return", void_ftype_ptr, |
8d08fdba MS |
5384 | BUILT_IN_RETURN, NULL_PTR); |
5385 | ||
5386 | /* Currently under experimentation. */ | |
5387 | builtin_function ("__builtin_memcpy", memcpy_ftype, | |
5388 | BUILT_IN_MEMCPY, "memcpy"); | |
5389 | builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, | |
5390 | BUILT_IN_MEMCMP, "memcmp"); | |
5391 | builtin_function ("__builtin_strcmp", int_ftype_string_string, | |
5392 | BUILT_IN_STRCMP, "strcmp"); | |
5393 | builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, | |
5394 | BUILT_IN_STRCPY, "strcpy"); | |
cffa8729 | 5395 | builtin_function ("__builtin_strlen", strlen_ftype, |
8d08fdba | 5396 | BUILT_IN_STRLEN, "strlen"); |
cffa8729 MS |
5397 | builtin_function ("__builtin_sqrtf", float_ftype_float, |
5398 | BUILT_IN_FSQRT, "sqrtf"); | |
5399 | builtin_function ("__builtin_fsqrt", double_ftype_double, | |
5400 | BUILT_IN_FSQRT, NULL_PTR); | |
5401 | builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble, | |
5402 | BUILT_IN_FSQRT, "sqrtl"); | |
5403 | builtin_function ("__builtin_sinf", float_ftype_float, | |
5404 | BUILT_IN_SIN, "sinf"); | |
5405 | builtin_function ("__builtin_sin", double_ftype_double, | |
5406 | BUILT_IN_SIN, "sin"); | |
5407 | builtin_function ("__builtin_sinl", ldouble_ftype_ldouble, | |
5408 | BUILT_IN_SIN, "sinl"); | |
5409 | builtin_function ("__builtin_cosf", float_ftype_float, | |
5410 | BUILT_IN_COS, "cosf"); | |
5411 | builtin_function ("__builtin_cos", double_ftype_double, | |
5412 | BUILT_IN_COS, "cos"); | |
5413 | builtin_function ("__builtin_cosl", ldouble_ftype_ldouble, | |
5414 | BUILT_IN_COS, "cosl"); | |
8d08fdba MS |
5415 | |
5416 | if (!flag_no_builtin) | |
5417 | { | |
8d08fdba MS |
5418 | builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); |
5419 | builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); | |
5420 | builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); | |
cffa8729 MS |
5421 | builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR); |
5422 | builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, | |
5423 | NULL_PTR); | |
8d08fdba MS |
5424 | builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); |
5425 | builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, | |
5426 | NULL_PTR); | |
cffa8729 MS |
5427 | builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, |
5428 | NULL_PTR); | |
a28e3c7f MS |
5429 | builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, |
5430 | NULL_PTR); | |
cffa8729 MS |
5431 | builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR); |
5432 | builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR); | |
5433 | builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR); | |
5434 | builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT, | |
5435 | NULL_PTR); | |
5436 | builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR); | |
8d08fdba | 5437 | builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); |
cffa8729 MS |
5438 | builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR); |
5439 | builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR); | |
8d08fdba | 5440 | builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); |
cffa8729 | 5441 | builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR); |
00595019 MS |
5442 | |
5443 | /* Declare these functions volatile | |
5444 | to avoid spurious "control drops through" warnings. */ | |
de22184b | 5445 | temp = builtin_function ("abort", void_ftype, |
00595019 MS |
5446 | NOT_BUILT_IN, NULL_PTR); |
5447 | TREE_THIS_VOLATILE (temp) = 1; | |
5448 | TREE_SIDE_EFFECTS (temp) = 1; | |
5449 | /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on | |
5450 | them... */ | |
5451 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
de22184b | 5452 | temp = builtin_function ("exit", void_ftype_int, |
00595019 MS |
5453 | NOT_BUILT_IN, NULL_PTR); |
5454 | TREE_THIS_VOLATILE (temp) = 1; | |
5455 | TREE_SIDE_EFFECTS (temp) = 1; | |
5456 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
8d08fdba MS |
5457 | } |
5458 | ||
5459 | #if 0 | |
5460 | /* Support for these has not been written in either expand_builtin | |
5461 | or build_function_call. */ | |
72b7eeff MS |
5462 | builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR); |
5463 | builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR); | |
a28e3c7f | 5464 | builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, |
72b7eeff | 5465 | NULL_PTR); |
cffa8729 MS |
5466 | builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, |
5467 | NULL_PTR); | |
a28e3c7f | 5468 | builtin_function ("__builtin_fmod", double_ftype_double_double, |
72b7eeff | 5469 | BUILT_IN_FMOD, NULL_PTR); |
a28e3c7f | 5470 | builtin_function ("__builtin_frem", double_ftype_double_double, |
72b7eeff | 5471 | BUILT_IN_FREM, NULL_PTR); |
cffa8729 MS |
5472 | builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, |
5473 | BUILT_IN_MEMSET, NULL_PTR); | |
a28e3c7f | 5474 | builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, |
72b7eeff | 5475 | NULL_PTR); |
a28e3c7f | 5476 | builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, |
72b7eeff | 5477 | NULL_PTR); |
8d08fdba MS |
5478 | #endif |
5479 | ||
5480 | /* C++ extensions */ | |
5481 | ||
5482 | unknown_type_node = make_node (UNKNOWN_TYPE); | |
8d08fdba MS |
5483 | decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"), |
5484 | unknown_type_node)); | |
5485 | /* Make sure the "unknown type" typedecl gets ignored for debug info. */ | |
5486 | DECL_IGNORED_P (decl) = 1; | |
39211cd5 | 5487 | TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; |
8d08fdba MS |
5488 | TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node); |
5489 | TYPE_ALIGN (unknown_type_node) = 1; | |
5490 | TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node); | |
5491 | /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ | |
5492 | TREE_TYPE (unknown_type_node) = unknown_type_node; | |
a6967cc0 JM |
5493 | |
5494 | if (flag_ansi) | |
5495 | TREE_TYPE (null_node) = type_for_size (POINTER_SIZE, 0); | |
5496 | else | |
5497 | TREE_TYPE (null_node) = build_pointer_type (unknown_type_node); | |
5498 | ||
5499 | /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same | |
5500 | result. */ | |
8d08fdba MS |
5501 | TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; |
5502 | TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; | |
5503 | ||
5504 | /* This is for handling opaque types in signatures. */ | |
5505 | opaque_type_node = copy_node (ptr_type_node); | |
5506 | TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node; | |
5507 | record_builtin_type (RID_MAX, 0, opaque_type_node); | |
5508 | ||
e92cc029 | 5509 | /* This is special for C++ so functions can be overloaded. */ |
8d08fdba MS |
5510 | wchar_type_node |
5511 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); | |
5512 | wchar_type_size = TYPE_PRECISION (wchar_type_node); | |
5513 | signed_wchar_type_node = make_signed_type (wchar_type_size); | |
5514 | unsigned_wchar_type_node = make_unsigned_type (wchar_type_size); | |
5515 | wchar_type_node | |
5516 | = TREE_UNSIGNED (wchar_type_node) | |
5517 | ? unsigned_wchar_type_node | |
5518 | : signed_wchar_type_node; | |
5519 | record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node); | |
5520 | ||
f376e137 MS |
5521 | /* Artificial declaration of wchar_t -- can be bashed */ |
5522 | wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"), | |
5523 | wchar_type_node); | |
5524 | pushdecl (wchar_decl_node); | |
5525 | ||
8d08fdba MS |
5526 | /* This is for wide string constants. */ |
5527 | wchar_array_type_node | |
5528 | = build_array_type (wchar_type_node, array_domain_type); | |
5529 | ||
8926095f | 5530 | if (flag_vtable_thunks) |
700f8a87 MS |
5531 | { |
5532 | /* Make sure we get a unique function type, so we can give | |
5533 | its pointer type a name. (This wins for gdb.) */ | |
5534 | tree vfunc_type = make_node (FUNCTION_TYPE); | |
5535 | TREE_TYPE (vfunc_type) = integer_type_node; | |
5536 | TYPE_ARG_TYPES (vfunc_type) = NULL_TREE; | |
5537 | layout_type (vfunc_type); | |
5538 | ||
5539 | vtable_entry_type = build_pointer_type (vfunc_type); | |
5540 | } | |
8926095f | 5541 | else |
700f8a87 MS |
5542 | { |
5543 | vtable_entry_type = make_lang_type (RECORD_TYPE); | |
5544 | fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, | |
5545 | delta_type_node); | |
5546 | fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, | |
5547 | delta_type_node); | |
5548 | fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, | |
5549 | ptr_type_node); | |
5550 | finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2, | |
5551 | double_type_node); | |
5552 | ||
5553 | /* Make this part of an invisible union. */ | |
5554 | fields[3] = copy_node (fields[2]); | |
5555 | TREE_TYPE (fields[3]) = delta_type_node; | |
5556 | DECL_NAME (fields[3]) = delta2_identifier; | |
5557 | DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node); | |
5558 | DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node); | |
5559 | TREE_UNSIGNED (fields[3]) = 0; | |
5560 | TREE_CHAIN (fields[2]) = fields[3]; | |
5561 | vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0); | |
5562 | } | |
5563 | record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type); | |
8d08fdba | 5564 | |
8d08fdba MS |
5565 | vtbl_type_node |
5566 | = build_array_type (vtable_entry_type, NULL_TREE); | |
5567 | layout_type (vtbl_type_node); | |
f376e137 | 5568 | vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0); |
8d08fdba MS |
5569 | record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node); |
5570 | ||
5571 | /* Simplify life by making a "sigtable_entry_type". Give its | |
5572 | fields names so that the debugger can use them. */ | |
5573 | ||
5574 | if (flag_handle_signatures) | |
5575 | { | |
5576 | sigtable_entry_type = make_lang_type (RECORD_TYPE); | |
dff6b454 RK |
5577 | fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier, |
5578 | delta_type_node); | |
9dd70aa4 | 5579 | fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier, |
dff6b454 | 5580 | delta_type_node); |
9dd70aa4 | 5581 | fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier, |
dff6b454 RK |
5582 | delta_type_node); |
5583 | fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier, | |
5584 | delta_type_node); | |
9dd70aa4 GB |
5585 | fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier, |
5586 | ptr_type_node); | |
5587 | ||
5588 | /* Set the alignment to the max of the alignment of ptr_type_node and | |
5589 | delta_type_node. Double alignment wastes a word on the Sparc. */ | |
5590 | finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4, | |
5591 | (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node)) | |
5592 | ? ptr_type_node | |
5593 | : delta_type_node); | |
dff6b454 RK |
5594 | |
5595 | /* Make this part of an invisible union. */ | |
9dd70aa4 GB |
5596 | fields[5] = copy_node (fields[4]); |
5597 | TREE_TYPE (fields[5]) = delta_type_node; | |
5598 | DECL_NAME (fields[5]) = vt_off_identifier; | |
5599 | DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node); | |
5600 | DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node); | |
5601 | TREE_UNSIGNED (fields[5]) = 0; | |
5602 | TREE_CHAIN (fields[4]) = fields[5]; | |
dff6b454 | 5603 | |
8d08fdba MS |
5604 | sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0); |
5605 | record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type); | |
5606 | } | |
5607 | ||
6633d636 MS |
5608 | std_node = build_decl (NAMESPACE_DECL, get_identifier ("std"), |
5609 | void_type_node); | |
5610 | pushdecl (std_node); | |
5611 | ||
db5ae43f MS |
5612 | #if 0 |
5613 | if (flag_rtti) | |
8d08fdba MS |
5614 | { |
5615 | /* Must build __t_desc type. Currently, type descriptors look like this: | |
5616 | ||
5617 | struct __t_desc | |
5618 | { | |
5619 | const char *name; | |
5620 | int size; | |
5621 | int bits; | |
5622 | struct __t_desc *points_to; | |
5623 | int ivars_count, meths_count; | |
5624 | struct __i_desc *ivars[]; | |
5625 | struct __m_desc *meths[]; | |
5626 | struct __t_desc *parents[]; | |
5627 | struct __t_desc *vbases[]; | |
5628 | int offsets[]; | |
5629 | }; | |
5630 | ||
5631 | ...as per Linton's paper. */ | |
5632 | ||
5633 | __t_desc_type_node = make_lang_type (RECORD_TYPE); | |
5634 | __i_desc_type_node = make_lang_type (RECORD_TYPE); | |
5635 | __m_desc_type_node = make_lang_type (RECORD_TYPE); | |
beb53fb8 JM |
5636 | __t_desc_array_type |
5637 | = build_array_type (build_pointer_type (__t_desc_type_node), | |
5638 | NULL_TREE); | |
5639 | __i_desc_array_type | |
5640 | = build_array_type (build_pointer_type (__i_desc_type_node), | |
5641 | NULL_TREE); | |
5642 | __m_desc_array_type | |
5643 | = build_array_type (build_pointer_type (__m_desc_type_node), | |
5644 | NULL_TREE); | |
8d08fdba MS |
5645 | |
5646 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), | |
5647 | string_type_node); | |
5648 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"), | |
5649 | unsigned_type_node); | |
5650 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"), | |
5651 | unsigned_type_node); | |
a28e3c7f MS |
5652 | fields[3] = build_lang_field_decl (FIELD_DECL, |
5653 | get_identifier ("points_to"), | |
f30432d7 | 5654 | build_pointer_type (__t_desc_type_node)); |
8d08fdba MS |
5655 | fields[4] = build_lang_field_decl (FIELD_DECL, |
5656 | get_identifier ("ivars_count"), | |
5657 | integer_type_node); | |
5658 | fields[5] = build_lang_field_decl (FIELD_DECL, | |
5659 | get_identifier ("meths_count"), | |
5660 | integer_type_node); | |
5661 | fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"), | |
5662 | build_pointer_type (__i_desc_array_type)); | |
5663 | fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"), | |
5664 | build_pointer_type (__m_desc_array_type)); | |
5665 | fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"), | |
5666 | build_pointer_type (__t_desc_array_type)); | |
5667 | fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"), | |
5668 | build_pointer_type (__t_desc_array_type)); | |
5669 | fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"), | |
5670 | build_pointer_type (integer_type_node)); | |
5671 | finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node); | |
5672 | ||
5673 | /* ivar descriptors look like this: | |
5674 | ||
5675 | struct __i_desc | |
5676 | { | |
5677 | const char *name; | |
5678 | int offset; | |
5679 | struct __t_desc *type; | |
5680 | }; | |
5681 | */ | |
5682 | ||
5683 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), | |
5684 | string_type_node); | |
5685 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"), | |
5686 | integer_type_node); | |
5687 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"), | |
f30432d7 | 5688 | build_pointer_type (__t_desc_type_node)); |
a28e3c7f MS |
5689 | finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, |
5690 | integer_type_node); | |
8d08fdba MS |
5691 | |
5692 | /* method descriptors look like this: | |
5693 | ||
5694 | struct __m_desc | |
5695 | { | |
5696 | const char *name; | |
5697 | int vindex; | |
5698 | struct __t_desc *vcontext; | |
5699 | struct __t_desc *return_type; | |
5700 | void (*address)(); | |
5701 | short parm_count; | |
5702 | short required_parms; | |
5703 | struct __t_desc *parm_types[]; | |
5704 | }; | |
5705 | */ | |
5706 | ||
5707 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), | |
5708 | string_type_node); | |
5709 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"), | |
5710 | integer_type_node); | |
5711 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"), | |
f30432d7 | 5712 | build_pointer_type (__t_desc_type_node)); |
8d08fdba | 5713 | fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"), |
f30432d7 | 5714 | build_pointer_type (__t_desc_type_node)); |
8d08fdba MS |
5715 | fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"), |
5716 | build_pointer_type (default_function_type)); | |
5717 | fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"), | |
5718 | short_integer_type_node); | |
5719 | fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"), | |
5720 | short_integer_type_node); | |
5721 | fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"), | |
f30432d7 | 5722 | build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE))); |
a28e3c7f MS |
5723 | finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, |
5724 | integer_type_node); | |
8d08fdba | 5725 | } |
db5ae43f MS |
5726 | #endif /*flag_rtti*/ |
5727 | ||
5728 | /* Now, C++. */ | |
5729 | current_lang_name = lang_name_cplusplus; | |
8d08fdba | 5730 | |
ced78d8b JM |
5731 | { |
5732 | tree bad_alloc_type_node = xref_tag | |
5733 | (class_type_node, get_identifier ("bad_alloc"), NULL_TREE, 1); | |
5734 | tree newtype = build_exception_variant | |
5735 | (ptr_ftype_sizetype, build_tree_list (NULL_TREE, bad_alloc_type_node)); | |
5736 | tree deltype = build_exception_variant | |
5737 | (void_ftype_ptr, build_tree_list (NULL_TREE, NULL_TREE)); | |
5738 | auto_function (ansi_opname[(int) NEW_EXPR], newtype, NOT_BUILT_IN); | |
5739 | auto_function (ansi_opname[(int) VEC_NEW_EXPR], newtype, NOT_BUILT_IN); | |
5740 | auto_function (ansi_opname[(int) DELETE_EXPR], deltype, NOT_BUILT_IN); | |
5741 | auto_function (ansi_opname[(int) VEC_DELETE_EXPR], deltype, NOT_BUILT_IN); | |
5742 | } | |
8d08fdba MS |
5743 | |
5744 | abort_fndecl | |
de22184b | 5745 | = define_function ("__pure_virtual", void_ftype, |
8d08fdba MS |
5746 | NOT_BUILT_IN, 0, 0); |
5747 | ||
8d08fdba MS |
5748 | /* Perform other language dependent initializations. */ |
5749 | init_class_processing (); | |
5750 | init_init_processing (); | |
5751 | init_search_processing (); | |
1737fe20 BK |
5752 | if (flag_rtti) |
5753 | init_rtti_processing (); | |
8d08fdba | 5754 | |
6467930b | 5755 | if (flag_exceptions) |
8d2733ca | 5756 | init_exception_processing (); |
8d08fdba MS |
5757 | if (flag_no_inline) |
5758 | { | |
5759 | flag_inline_functions = 0; | |
8d08fdba | 5760 | } |
9e9ff709 | 5761 | |
7fcdf4c2 | 5762 | if (! supports_one_only ()) |
72b7eeff | 5763 | flag_weak = 0; |
8d08fdba MS |
5764 | |
5765 | /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ | |
5766 | declare_function_name (); | |
5767 | ||
5768 | /* Prepare to check format strings against argument lists. */ | |
5769 | init_function_format_info (); | |
e9a25f70 JL |
5770 | |
5771 | /* Show we use EH for cleanups. */ | |
5772 | using_eh_for_cleanups (); | |
8d08fdba MS |
5773 | } |
5774 | ||
e92cc029 | 5775 | /* initialize type descriptor type node of various rtti type. */ |
db5ae43f MS |
5776 | |
5777 | int | |
5778 | init_type_desc() | |
5779 | { | |
5780 | tree tdecl; | |
5781 | ||
5782 | tdecl = lookup_name (get_identifier ("type_info"), 0); | |
5783 | if (tdecl == NULL_TREE) | |
5784 | return 0; | |
fc378698 | 5785 | __t_desc_type_node = TREE_TYPE (tdecl); |
5566b478 | 5786 | #if 0 |
db5ae43f | 5787 | __tp_desc_type_node = build_pointer_type (__t_desc_type_node); |
5566b478 | 5788 | #endif |
db5ae43f MS |
5789 | |
5790 | #if 0 | |
5791 | tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0); | |
5792 | if (tdecl == NULL_TREE) | |
5793 | return 0; | |
5794 | __baselist_desc_type_node = TREE_TYPE (tdecl); | |
5795 | #endif | |
5796 | ||
5797 | tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0); | |
5798 | if (tdecl == NULL_TREE) | |
5799 | return 0; | |
5800 | __bltn_desc_type_node = TREE_TYPE (tdecl); | |
5801 | ||
5802 | tdecl = lookup_name (get_identifier ("__user_type_info"), 0); | |
5803 | if (tdecl == NULL_TREE) | |
5804 | return 0; | |
5805 | __user_desc_type_node = TREE_TYPE (tdecl); | |
5806 | ||
5807 | tdecl = lookup_name (get_identifier ("__class_type_info"), 0); | |
5808 | if (tdecl == NULL_TREE) | |
5809 | return 0; | |
5810 | __class_desc_type_node = TREE_TYPE (tdecl); | |
5811 | ||
5812 | tdecl = lookup_field (__class_desc_type_node, | |
5813 | get_identifier ("access_mode"), 0, 0); | |
5814 | if (tdecl == NULL_TREE) | |
5815 | return 0; | |
5816 | __access_mode_type_node = TREE_TYPE (tdecl); | |
5817 | ||
5818 | tdecl = lookup_name (get_identifier ("__attr_type_info"), 0); | |
5819 | if (tdecl == NULL_TREE) | |
5820 | return 0; | |
5821 | __attr_desc_type_node = TREE_TYPE (tdecl); | |
5822 | ||
5823 | tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0); | |
5824 | if (tdecl == NULL_TREE) | |
5825 | return 0; | |
5826 | __ptr_desc_type_node = TREE_TYPE (tdecl); | |
5827 | ||
5828 | tdecl = lookup_name (get_identifier ("__func_type_info"), 0); | |
5829 | if (tdecl == NULL_TREE) | |
5830 | return 0; | |
5831 | __func_desc_type_node = TREE_TYPE (tdecl); | |
5832 | ||
5833 | tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0); | |
5834 | if (tdecl == NULL_TREE) | |
5835 | return 0; | |
5836 | __ptmf_desc_type_node = TREE_TYPE (tdecl); | |
5837 | ||
5838 | tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0); | |
5839 | if (tdecl == NULL_TREE) | |
5840 | return 0; | |
5841 | __ptmd_desc_type_node = TREE_TYPE (tdecl); | |
5842 | ||
5843 | return 1; | |
5844 | } | |
8d08fdba MS |
5845 | /* Make a definition for a builtin function named NAME and whose data type |
5846 | is TYPE. TYPE should be a function type with argument types. | |
5847 | FUNCTION_CODE tells later passes how to compile calls to this function. | |
5848 | See tree.h for its possible values. | |
5849 | ||
5850 | If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, | |
5851 | the name to be called if we can't opencode the function. */ | |
5852 | ||
5853 | tree | |
5854 | define_function (name, type, function_code, pfn, library_name) | |
5855 | char *name; | |
5856 | tree type; | |
5857 | enum built_in_function function_code; | |
49c249e1 | 5858 | void (*pfn) PROTO((tree)); |
8d08fdba MS |
5859 | char *library_name; |
5860 | { | |
5861 | tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); | |
5862 | DECL_EXTERNAL (decl) = 1; | |
5863 | TREE_PUBLIC (decl) = 1; | |
863adfc0 | 5864 | DECL_ARTIFICIAL (decl) = 1; |
8d08fdba MS |
5865 | |
5866 | /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, | |
5867 | we cannot change DECL_ASSEMBLER_NAME until we have installed this | |
5868 | function in the namespace. */ | |
5869 | if (pfn) (*pfn) (decl); | |
5870 | if (library_name) | |
5871 | DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); | |
5872 | make_function_rtl (decl); | |
5873 | if (function_code != NOT_BUILT_IN) | |
5874 | { | |
5875 | DECL_BUILT_IN (decl) = 1; | |
39211cd5 | 5876 | DECL_FUNCTION_CODE (decl) = function_code; |
8d08fdba MS |
5877 | } |
5878 | return decl; | |
5879 | } | |
5880 | \f | |
5881 | /* Called when a declaration is seen that contains no names to declare. | |
5882 | If its type is a reference to a structure, union or enum inherited | |
5883 | from a containing scope, shadow that tag name for the current scope | |
5884 | with a forward reference. | |
5885 | If its type defines a new named structure or union | |
5886 | or defines an enum, it is valid but we need not do anything here. | |
5887 | Otherwise, it is an error. | |
5888 | ||
5889 | C++: may have to grok the declspecs to learn about static, | |
5890 | complain for anonymous unions. */ | |
5891 | ||
5892 | void | |
5893 | shadow_tag (declspecs) | |
5894 | tree declspecs; | |
5895 | { | |
5896 | int found_tag = 0; | |
2986ae00 | 5897 | tree ob_modifier = NULL_TREE; |
8d08fdba MS |
5898 | register tree link; |
5899 | register enum tree_code code, ok_code = ERROR_MARK; | |
5900 | register tree t = NULL_TREE; | |
5901 | ||
5902 | for (link = declspecs; link; link = TREE_CHAIN (link)) | |
5903 | { | |
5904 | register tree value = TREE_VALUE (link); | |
5905 | ||
5906 | code = TREE_CODE (value); | |
5907 | if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE) | |
8d08fdba | 5908 | { |
d2e5ee5c | 5909 | my_friendly_assert (TYPE_MAIN_DECL (value) != NULL_TREE, 261); |
8d08fdba | 5910 | |
fc378698 | 5911 | if (IS_AGGR_TYPE (value) && CLASSTYPE_USE_TEMPLATE (value)) |
5566b478 MS |
5912 | { |
5913 | if (CLASSTYPE_IMPLICIT_INSTANTIATION (value) | |
5914 | && TYPE_SIZE (value) == NULL_TREE) | |
73aad9b9 JM |
5915 | { |
5916 | SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (value); | |
5156628f | 5917 | if (processing_template_decl) |
73aad9b9 JM |
5918 | push_template_decl (TYPE_MAIN_DECL (value)); |
5919 | } | |
5566b478 MS |
5920 | else if (CLASSTYPE_TEMPLATE_INSTANTIATION (value)) |
5921 | cp_error ("specialization after instantiation of `%T'", value); | |
5922 | } | |
5923 | ||
b8bca6f2 JM |
5924 | t = value; |
5925 | ok_code = code; | |
5926 | found_tag++; | |
8d08fdba MS |
5927 | } |
5928 | else if (value == ridpointers[(int) RID_STATIC] | |
2986ae00 MS |
5929 | || value == ridpointers[(int) RID_EXTERN] |
5930 | || value == ridpointers[(int) RID_AUTO] | |
28cbf42c MS |
5931 | || value == ridpointers[(int) RID_REGISTER] |
5932 | || value == ridpointers[(int) RID_INLINE] | |
5933 | || value == ridpointers[(int) RID_VIRTUAL] | |
5934 | || value == ridpointers[(int) RID_EXPLICIT]) | |
2986ae00 | 5935 | ob_modifier = value; |
8d08fdba MS |
5936 | } |
5937 | ||
5938 | /* This is where the variables in an anonymous union are | |
5939 | declared. An anonymous union declaration looks like: | |
5940 | union { ... } ; | |
5941 | because there is no declarator after the union, the parser | |
5942 | sends that declaration here. */ | |
5943 | if (ok_code == UNION_TYPE | |
5944 | && t != NULL_TREE | |
5945 | && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE | |
5946 | && ANON_AGGRNAME_P (TYPE_NAME (t))) | |
5947 | || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL | |
5948 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))) | |
5949 | { | |
d2e5ee5c | 5950 | /* See also grok_x_components. */ |
d2e5ee5c MS |
5951 | tree *q; |
5952 | ||
5953 | /* Wipe out memory of synthesized methods */ | |
5954 | TYPE_HAS_CONSTRUCTOR (t) = 0; | |
5955 | TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0; | |
5956 | TYPE_HAS_INIT_REF (t) = 0; | |
5957 | TYPE_HAS_CONST_INIT_REF (t) = 0; | |
5958 | TYPE_HAS_ASSIGN_REF (t) = 0; | |
5959 | TYPE_HAS_ASSIGNMENT (t) = 0; | |
5960 | TYPE_HAS_CONST_ASSIGN_REF (t) = 0; | |
5961 | ||
5962 | q = &TYPE_METHODS (t); | |
5963 | while (*q) | |
5964 | { | |
5965 | if (DECL_ARTIFICIAL (*q)) | |
5966 | *q = TREE_CHAIN (*q); | |
5967 | else | |
5968 | q = &TREE_CHAIN (*q); | |
5969 | } | |
f49422da | 5970 | |
8d08fdba MS |
5971 | /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have |
5972 | function members. */ | |
d2e5ee5c MS |
5973 | if (TYPE_METHODS (t)) |
5974 | error ("an anonymous union cannot have function members"); | |
c91a56d2 | 5975 | |
8d08fdba MS |
5976 | if (TYPE_FIELDS (t)) |
5977 | { | |
a28e3c7f | 5978 | tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, |
c11b6f21 | 5979 | NULL_TREE); |
8d08fdba MS |
5980 | finish_anon_union (decl); |
5981 | } | |
8d08fdba MS |
5982 | } |
5983 | else | |
5984 | { | |
5985 | /* Anonymous unions are objects, that's why we only check for | |
2986ae00 | 5986 | inappropriate specifiers in this branch. */ |
28cbf42c | 5987 | |
2986ae00 | 5988 | if (ob_modifier) |
28cbf42c MS |
5989 | { |
5990 | if (ob_modifier == ridpointers[(int) RID_INLINE] | |
5991 | || ob_modifier == ridpointers[(int) RID_VIRTUAL]) | |
5992 | cp_error ("`%D' can only be specified for functions", ob_modifier); | |
5993 | else if (ob_modifier == ridpointers[(int) RID_EXPLICIT]) | |
5994 | cp_error ("`%D' can only be specified for constructors", | |
5995 | ob_modifier); | |
5996 | else | |
5997 | cp_error ("`%D' can only be specified for objects and functions", | |
5998 | ob_modifier); | |
5999 | } | |
8d08fdba | 6000 | |
b8bca6f2 | 6001 | if (found_tag == 0) |
2df06032 | 6002 | cp_error ("abstract declarator used as declaration"); |
b8bca6f2 | 6003 | else if (found_tag > 1) |
2986ae00 | 6004 | pedwarn ("multiple types in one declaration"); |
8d08fdba MS |
6005 | } |
6006 | } | |
6007 | \f | |
6008 | /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ | |
6009 | ||
6010 | tree | |
6011 | groktypename (typename) | |
6012 | tree typename; | |
6013 | { | |
6014 | if (TREE_CODE (typename) != TREE_LIST) | |
6015 | return typename; | |
6016 | return grokdeclarator (TREE_VALUE (typename), | |
6017 | TREE_PURPOSE (typename), | |
c11b6f21 | 6018 | TYPENAME, 0, NULL_TREE); |
8d08fdba MS |
6019 | } |
6020 | ||
6021 | /* Decode a declarator in an ordinary declaration or data definition. | |
6022 | This is called as soon as the type information and variable name | |
6023 | have been parsed, before parsing the initializer if any. | |
6024 | Here we create the ..._DECL node, fill in its type, | |
6025 | and put it on the list of decls for the current context. | |
6026 | The ..._DECL node is returned as the value. | |
6027 | ||
6028 | Exception: for arrays where the length is not specified, | |
82580166 | 6029 | the type is left null, to be filled in by `cp_finish_decl'. |
8d08fdba MS |
6030 | |
6031 | Function definitions do not come here; they go to start_function | |
6032 | instead. However, external and forward declarations of functions | |
6033 | do go through here. Structure field declarations are done by | |
6034 | grokfield and not through here. */ | |
6035 | ||
6036 | /* Set this to zero to debug not using the temporary obstack | |
6037 | to parse initializers. */ | |
6038 | int debug_temp_inits = 1; | |
6039 | ||
6040 | tree | |
c11b6f21 | 6041 | start_decl (declarator, declspecs, initialized) |
8d08fdba MS |
6042 | tree declarator, declspecs; |
6043 | int initialized; | |
8d08fdba MS |
6044 | { |
6045 | register tree decl; | |
6046 | register tree type, tem; | |
6047 | tree context; | |
6048 | extern int have_extern_spec; | |
6049 | extern int used_extern_spec; | |
6050 | ||
5566b478 MS |
6051 | #if 0 |
6052 | /* See code below that used this. */ | |
8d08fdba | 6053 | int init_written = initialized; |
5566b478 | 6054 | #endif |
8d08fdba | 6055 | |
e92cc029 | 6056 | /* This should only be done once on the top most decl. */ |
8d08fdba MS |
6057 | if (have_extern_spec && !used_extern_spec) |
6058 | { | |
a28e3c7f MS |
6059 | declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), |
6060 | declspecs); | |
8d08fdba MS |
6061 | used_extern_spec = 1; |
6062 | } | |
6063 | ||
c11b6f21 | 6064 | decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, |
f30432d7 | 6065 | NULL_TREE); |
8d08fdba MS |
6066 | if (decl == NULL_TREE || decl == void_type_node) |
6067 | return NULL_TREE; | |
6068 | ||
6069 | type = TREE_TYPE (decl); | |
6070 | ||
6071 | /* Don't lose if destructors must be executed at file-level. */ | |
5156628f | 6072 | if (! processing_template_decl && TREE_STATIC (decl) |
ec255269 | 6073 | && TYPE_NEEDS_DESTRUCTOR (complete_type (type)) |
8d08fdba MS |
6074 | && !TREE_PERMANENT (decl)) |
6075 | { | |
6076 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
6077 | decl = copy_node (decl); | |
6078 | if (TREE_CODE (type) == ARRAY_TYPE) | |
6079 | { | |
6080 | tree itype = TYPE_DOMAIN (type); | |
6081 | if (itype && ! TREE_PERMANENT (itype)) | |
6082 | { | |
6083 | itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype))); | |
6084 | type = build_cplus_array_type (TREE_TYPE (type), itype); | |
6085 | TREE_TYPE (decl) = type; | |
6086 | } | |
6087 | } | |
6088 | pop_obstacks (); | |
6089 | } | |
6090 | ||
8d08fdba MS |
6091 | context |
6092 | = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) | |
6093 | ? DECL_CLASS_CONTEXT (decl) | |
6094 | : DECL_CONTEXT (decl); | |
6095 | ||
8d08fdba MS |
6096 | if (initialized) |
6097 | /* Is it valid for this decl to have an initializer at all? | |
6098 | If not, set INITIALIZED to zero, which will indirectly | |
82580166 | 6099 | tell `cp_finish_decl' to ignore the initializer once it is parsed. */ |
8d08fdba MS |
6100 | switch (TREE_CODE (decl)) |
6101 | { | |
6102 | case TYPE_DECL: | |
6103 | /* typedef foo = bar means give foo the same type as bar. | |
82580166 | 6104 | We haven't parsed bar yet, so `cp_finish_decl' will fix that up. |
8d08fdba MS |
6105 | Any other case of an initialization in a TYPE_DECL is an error. */ |
6106 | if (pedantic || list_length (declspecs) > 1) | |
6107 | { | |
6108 | cp_error ("typedef `%D' is initialized", decl); | |
6109 | initialized = 0; | |
6110 | } | |
6111 | break; | |
6112 | ||
6113 | case FUNCTION_DECL: | |
6114 | cp_error ("function `%#D' is initialized like a variable", decl); | |
6115 | initialized = 0; | |
6116 | break; | |
6117 | ||
6118 | default: | |
5156628f | 6119 | if (! processing_template_decl) |
8d08fdba | 6120 | { |
bd6dd845 | 6121 | if (type != error_mark_node) |
5156628f | 6122 | { |
bd6dd845 MS |
6123 | if (TYPE_SIZE (type) != NULL_TREE |
6124 | && ! TREE_CONSTANT (TYPE_SIZE (type))) | |
6125 | { | |
6126 | cp_error | |
6127 | ("variable-sized object `%D' may not be initialized", | |
6128 | decl); | |
6129 | initialized = 0; | |
6130 | } | |
5156628f | 6131 | |
bd6dd845 MS |
6132 | if (TREE_CODE (type) == ARRAY_TYPE |
6133 | && TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) | |
6134 | { | |
6135 | cp_error | |
6136 | ("elements of array `%#D' have incomplete type", decl); | |
6137 | initialized = 0; | |
6138 | } | |
5156628f | 6139 | } |
8d08fdba MS |
6140 | } |
6141 | } | |
6142 | ||
8d08fdba MS |
6143 | if (initialized) |
6144 | { | |
a9aedbc2 | 6145 | if (! toplevel_bindings_p () |
8d08fdba MS |
6146 | && DECL_EXTERNAL (decl)) |
6147 | cp_warning ("declaration of `%#D' has `extern' and is initialized", | |
6148 | decl); | |
6149 | DECL_EXTERNAL (decl) = 0; | |
5566b478 | 6150 | if (toplevel_bindings_p ()) |
8d08fdba MS |
6151 | TREE_STATIC (decl) = 1; |
6152 | ||
6153 | /* Tell `pushdecl' this is an initialized decl | |
6154 | even though we don't yet have the initializer expression. | |
82580166 | 6155 | Also tell `cp_finish_decl' it may store the real initializer. */ |
8d08fdba MS |
6156 | DECL_INITIAL (decl) = error_mark_node; |
6157 | } | |
6158 | ||
5566b478 | 6159 | if (context && TYPE_SIZE (complete_type (context)) != NULL_TREE) |
5b605f68 MS |
6160 | { |
6161 | if (TREE_CODE (decl) == VAR_DECL) | |
6162 | { | |
6163 | tree field = lookup_field (context, DECL_NAME (decl), 0, 0); | |
6164 | if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) | |
6165 | cp_error ("`%#D' is not a static member of `%#T'", decl, context); | |
e349ee73 MS |
6166 | else |
6167 | { | |
6168 | if (DECL_CONTEXT (field) != context) | |
f2d773a2 JM |
6169 | { |
6170 | cp_pedwarn ("ANSI C++ does not permit `%T::%D' to be defined as `%T::%D'", | |
6171 | DECL_CONTEXT (field), DECL_NAME (decl), | |
6172 | context, DECL_NAME (decl)); | |
6173 | DECL_CONTEXT (decl) = DECL_CONTEXT (field); | |
6174 | } | |
75650646 MM |
6175 | /* Static data member are tricky; an in-class initialization |
6176 | still doesn't provide a definition, so the in-class | |
6177 | declaration will have DECL_EXTERNAL set, but will have an | |
6178 | initialization. Thus, duplicate_decls won't warn | |
6179 | about this situation, and so we check here. */ | |
6180 | if (DECL_INITIAL (decl) && DECL_INITIAL (field)) | |
6181 | cp_error ("duplicate initialization of %D", decl); | |
e349ee73 MS |
6182 | if (duplicate_decls (decl, field)) |
6183 | decl = field; | |
6184 | } | |
5b605f68 | 6185 | } |
f30432d7 MS |
6186 | else |
6187 | { | |
5566b478 | 6188 | tree field = check_classfn (context, decl); |
f30432d7 MS |
6189 | if (field && duplicate_decls (decl, field)) |
6190 | decl = field; | |
6191 | } | |
6192 | ||
6193 | /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */ | |
5b605f68 MS |
6194 | if (DECL_LANG_SPECIFIC (decl)) |
6195 | DECL_IN_AGGR_P (decl) = 0; | |
f30432d7 MS |
6196 | if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context)) |
6197 | SET_DECL_TEMPLATE_SPECIALIZATION (decl); | |
6198 | ||
6199 | /* Stupid stupid stupid stupid (jason 7/21/95) */ | |
6200 | if (pedantic && DECL_EXTERNAL (decl) | |
6201 | && ! DECL_TEMPLATE_SPECIALIZATION (decl)) | |
6202 | cp_pedwarn ("declaration of `%#D' outside of class is not definition", | |
6203 | decl); | |
6204 | ||
5b605f68 MS |
6205 | pushclass (context, 2); |
6206 | } | |
6207 | ||
8d08fdba MS |
6208 | /* Add this decl to the current binding level, but not if it |
6209 | comes from another scope, e.g. a static member variable. | |
6210 | TEM may equal DECL or it may be a previous decl of the same name. */ | |
5b605f68 | 6211 | |
8d08fdba MS |
6212 | if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE) |
6213 | || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ()) | |
75650646 MM |
6214 | || TREE_CODE (type) == LANG_TYPE |
6215 | /* The declaration of template specializations does not affect | |
6216 | the functions available for overload resolution, so we do not | |
6217 | call pushdecl. */ | |
e1467ff2 | 6218 | || (TREE_CODE (decl) == FUNCTION_DECL |
75650646 | 6219 | && DECL_TEMPLATE_SPECIALIZATION (decl))) |
8d08fdba MS |
6220 | tem = decl; |
6221 | else | |
8926095f | 6222 | tem = pushdecl (decl); |
2ee887f2 | 6223 | |
5156628f | 6224 | if (processing_template_decl) |
5566b478 MS |
6225 | { |
6226 | if (! current_function_decl) | |
3ac3d9ea | 6227 | tem = push_template_decl (tem); |
5566b478 MS |
6228 | else if (minimal_parse_mode) |
6229 | DECL_VINDEX (decl) | |
6230 | = build_min_nt (DECL_STMT, copy_to_permanent (declarator), | |
6231 | copy_to_permanent (declspecs), | |
c11b6f21 | 6232 | NULL_TREE); |
5566b478 MS |
6233 | } |
6234 | ||
6235 | ||
2ee887f2 | 6236 | #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) |
a3203465 | 6237 | /* Tell the back-end to use or not use .common as appropriate. If we say |
a50f0918 MS |
6238 | -fconserve-space, we want this to save .data space, at the expense of |
6239 | wrong semantics. If we say -fno-conserve-space, we want this to | |
6240 | produce errors about redefs; to do this we force variables into the | |
6241 | data segment. */ | |
a3203465 | 6242 | DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem); |
2ee887f2 | 6243 | #endif |
8d08fdba | 6244 | |
5156628f | 6245 | if (! processing_template_decl) |
5566b478 | 6246 | start_decl_1 (tem); |
8d08fdba | 6247 | |
5566b478 MS |
6248 | /* Corresponding pop_obstacks is done in `cp_finish_decl'. */ |
6249 | push_obstacks_nochange (); | |
8d08fdba | 6250 | |
5566b478 MS |
6251 | #if 0 |
6252 | /* We have no way of knowing whether the initializer will need to be | |
6253 | evaluated at run-time or not until we've parsed it, so let's just put | |
6254 | it in the permanent obstack. (jason) */ | |
8d08fdba MS |
6255 | if (init_written |
6256 | && ! (TREE_CODE (tem) == PARM_DECL | |
6257 | || (TREE_READONLY (tem) | |
6258 | && (TREE_CODE (tem) == VAR_DECL | |
6259 | || TREE_CODE (tem) == FIELD_DECL)))) | |
6260 | { | |
6261 | /* When parsing and digesting the initializer, | |
6262 | use temporary storage. Do this even if we will ignore the value. */ | |
a9aedbc2 | 6263 | if (toplevel_bindings_p () && debug_temp_inits) |
8d08fdba | 6264 | { |
5156628f | 6265 | if (processing_template_decl |
5566b478 | 6266 | || TYPE_NEEDS_CONSTRUCTING (type) |
a28e3c7f | 6267 | || TREE_CODE (type) == REFERENCE_TYPE) |
8d08fdba MS |
6268 | /* In this case, the initializer must lay down in permanent |
6269 | storage, since it will be saved until `finish_file' is run. */ | |
6270 | ; | |
6271 | else | |
6272 | temporary_allocation (); | |
6273 | } | |
6274 | } | |
5566b478 | 6275 | #endif |
8d08fdba | 6276 | |
8d08fdba MS |
6277 | return tem; |
6278 | } | |
6279 | ||
5566b478 MS |
6280 | void |
6281 | start_decl_1 (decl) | |
6282 | tree decl; | |
8d08fdba | 6283 | { |
5566b478 MS |
6284 | tree type = TREE_TYPE (decl); |
6285 | int initialized = (DECL_INITIAL (decl) != NULL_TREE); | |
8d08fdba | 6286 | |
5566b478 MS |
6287 | /* If this type of object needs a cleanup, and control may |
6288 | jump past it, make a new binding level so that it is cleaned | |
6289 | up only when it is initialized first. */ | |
6290 | if (TYPE_NEEDS_DESTRUCTOR (type) | |
6291 | && current_binding_level->more_cleanups_ok == 0) | |
6292 | pushlevel_temporary (1); | |
6293 | ||
6294 | if (initialized) | |
6295 | /* Is it valid for this decl to have an initializer at all? | |
6296 | If not, set INITIALIZED to zero, which will indirectly | |
6297 | tell `cp_finish_decl' to ignore the initializer once it is parsed. */ | |
8d08fdba | 6298 | { |
5566b478 MS |
6299 | /* Don't allow initializations for incomplete types except for |
6300 | arrays which might be completed by the initialization. */ | |
6301 | if (type == error_mark_node) | |
6302 | ; /* Don't complain again. */ | |
6303 | else if (TYPE_SIZE (complete_type (type)) != NULL_TREE) | |
6304 | ; /* A complete type is ok. */ | |
6305 | else if (TREE_CODE (type) != ARRAY_TYPE) | |
8d08fdba | 6306 | { |
5566b478 MS |
6307 | cp_error ("variable `%#D' has initializer but incomplete type", |
6308 | decl); | |
6309 | initialized = 0; | |
6310 | } | |
6311 | else if (TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) | |
6312 | { | |
6313 | if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)) | |
6314 | cp_error ("elements of array `%#D' have incomplete type", decl); | |
6315 | /* else we already gave an error in start_decl. */ | |
6316 | initialized = 0; | |
8d08fdba | 6317 | } |
8d08fdba MS |
6318 | } |
6319 | ||
5566b478 MS |
6320 | if (!initialized |
6321 | && TREE_CODE (decl) != TYPE_DECL | |
6322 | && TREE_CODE (decl) != TEMPLATE_DECL | |
6323 | && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) | |
8d08fdba | 6324 | { |
5156628f | 6325 | if ((! processing_template_decl || ! uses_template_parms (type)) |
7fcdf4c2 | 6326 | && TYPE_SIZE (complete_type (type)) == NULL_TREE) |
5566b478 MS |
6327 | { |
6328 | cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", | |
6329 | decl); | |
6330 | /* Change the type so that assemble_variable will give | |
6331 | DECL an rtl we can live with: (mem (const_int 0)). */ | |
6332 | TREE_TYPE (decl) = error_mark_node; | |
6333 | type = error_mark_node; | |
6334 | } | |
6335 | else | |
6336 | { | |
6337 | /* If any base type in the hierarchy of TYPE needs a constructor, | |
6338 | then we set initialized to 1. This way any nodes which are | |
6339 | created for the purposes of initializing this aggregate | |
6340 | will live as long as it does. This is necessary for global | |
6341 | aggregates which do not have their initializers processed until | |
6342 | the end of the file. */ | |
6343 | initialized = TYPE_NEEDS_CONSTRUCTING (type); | |
6344 | } | |
6345 | } | |
6346 | ||
6347 | #if 0 | |
6348 | /* We don't do this yet for GNU C++. */ | |
6349 | /* For a local variable, define the RTL now. */ | |
6350 | if (! toplevel_bindings_p () | |
6351 | /* But not if this is a duplicate decl | |
6352 | and we preserved the rtl from the previous one | |
6353 | (which may or may not happen). */ | |
6354 | && DECL_RTL (tem) == NULL_RTX) | |
6355 | { | |
6356 | if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) | |
6357 | expand_decl (tem); | |
6358 | else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE | |
6359 | && DECL_INITIAL (tem) != NULL_TREE) | |
6360 | expand_decl (tem); | |
6361 | } | |
6362 | #endif | |
6363 | ||
6364 | if (! initialized) | |
6365 | DECL_INITIAL (decl) = NULL_TREE; | |
6366 | } | |
6367 | ||
6368 | /* Handle initialization of references. | |
6369 | These three arguments from from `cp_finish_decl', and have the | |
e92cc029 MS |
6370 | same meaning here that they do there. |
6371 | ||
6372 | Quotes on semantics can be found in ARM 8.4.3. */ | |
6373 | ||
5566b478 | 6374 | static void |
a703fb38 | 6375 | grok_reference_init (decl, type, init) |
5566b478 | 6376 | tree decl, type, init; |
5566b478 MS |
6377 | { |
6378 | tree tmp; | |
6379 | ||
6380 | if (init == NULL_TREE) | |
6381 | { | |
6382 | if ((DECL_LANG_SPECIFIC (decl) == 0 | |
6383 | || DECL_IN_AGGR_P (decl) == 0) | |
6384 | && ! DECL_THIS_EXTERN (decl)) | |
6385 | { | |
6386 | cp_error ("`%D' declared as reference but not initialized", decl); | |
6387 | if (TREE_CODE (decl) == VAR_DECL) | |
6388 | SET_DECL_REFERENCE_SLOT (decl, error_mark_node); | |
6389 | } | |
6390 | return; | |
6391 | } | |
6392 | ||
6393 | if (init == error_mark_node) | |
6394 | return; | |
6395 | ||
6396 | if (TREE_CODE (type) == REFERENCE_TYPE | |
6397 | && TREE_CODE (init) == CONSTRUCTOR) | |
6398 | { | |
6399 | cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl); | |
8d08fdba MS |
6400 | return; |
6401 | } | |
6402 | ||
ec255269 MS |
6403 | if (TREE_TYPE (init) && TREE_CODE (TREE_TYPE (init)) == UNKNOWN_TYPE) |
6404 | /* decay_conversion is probably wrong for references to functions. */ | |
6405 | init = decay_conversion (instantiate_type (TREE_TYPE (type), init, 1)); | |
6406 | ||
8d08fdba MS |
6407 | if (TREE_CODE (init) == TREE_LIST) |
6408 | init = build_compound_expr (init); | |
8d08fdba | 6409 | |
8ccc31eb MS |
6410 | if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE) |
6411 | init = convert_from_reference (init); | |
6412 | ||
8d08fdba MS |
6413 | if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE |
6414 | && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE) | |
6415 | { | |
a3203465 | 6416 | /* Note: default conversion is only called in very special cases. */ |
8d08fdba MS |
6417 | init = default_conversion (init); |
6418 | } | |
6419 | ||
a3203465 | 6420 | tmp = convert_to_reference |
9a3b49ac MS |
6421 | (type, init, CONV_IMPLICIT, |
6422 | LOOKUP_SPECULATIVELY|LOOKUP_NORMAL|DIRECT_BIND, decl); | |
8d08fdba | 6423 | |
a3203465 MS |
6424 | if (tmp == error_mark_node) |
6425 | goto fail; | |
6426 | else if (tmp != NULL_TREE) | |
8d08fdba | 6427 | { |
a3203465 | 6428 | init = tmp; |
4c7bdca6 | 6429 | DECL_INITIAL (decl) = save_expr (init); |
8d08fdba | 6430 | } |
a3203465 | 6431 | else |
8d08fdba | 6432 | { |
a3203465 MS |
6433 | cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init)); |
6434 | goto fail; | |
8d08fdba | 6435 | } |
8d08fdba | 6436 | |
8d08fdba MS |
6437 | /* ?? Can this be optimized in some cases to |
6438 | hand back the DECL_INITIAL slot?? */ | |
6439 | if (TYPE_SIZE (TREE_TYPE (type))) | |
6440 | { | |
6441 | init = convert_from_reference (decl); | |
6442 | if (TREE_PERMANENT (decl)) | |
6443 | init = copy_to_permanent (init); | |
6444 | SET_DECL_REFERENCE_SLOT (decl, init); | |
6445 | } | |
6446 | ||
6447 | if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl))) | |
6448 | { | |
6449 | expand_static_init (decl, DECL_INITIAL (decl)); | |
6450 | DECL_INITIAL (decl) = NULL_TREE; | |
6451 | } | |
6452 | return; | |
6453 | ||
6454 | fail: | |
6455 | if (TREE_CODE (decl) == VAR_DECL) | |
6456 | SET_DECL_REFERENCE_SLOT (decl, error_mark_node); | |
6457 | return; | |
6458 | } | |
6459 | ||
6060a796 MS |
6460 | /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from |
6461 | mucking with forces it does not comprehend (i.e. initialization with a | |
6462 | constructor). If we are at global scope and won't go into COMMON, fill | |
6463 | it in with a dummy CONSTRUCTOR to force the variable into .data; | |
6464 | otherwise we can use error_mark_node. */ | |
6465 | ||
28cbf42c MS |
6466 | static tree |
6467 | obscure_complex_init (decl, init) | |
6468 | tree decl, init; | |
6060a796 | 6469 | { |
28cbf42c MS |
6470 | if (! flag_no_inline && TREE_STATIC (decl)) |
6471 | { | |
6472 | if (extract_init (decl, init)) | |
6473 | return NULL_TREE; | |
6474 | } | |
6475 | ||
2ee887f2 | 6476 | #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) |
a9aedbc2 | 6477 | if (toplevel_bindings_p () && ! DECL_COMMON (decl)) |
6060a796 MS |
6478 | DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE, |
6479 | NULL_TREE); | |
6480 | else | |
2ee887f2 | 6481 | #endif |
6060a796 | 6482 | DECL_INITIAL (decl) = error_mark_node; |
28cbf42c MS |
6483 | |
6484 | return init; | |
6060a796 MS |
6485 | } |
6486 | ||
8d08fdba MS |
6487 | /* Finish processing of a declaration; |
6488 | install its line number and initial value. | |
6489 | If the length of an array type is not known before, | |
6490 | it must be determined now, from the initial value, or it is an error. | |
6491 | ||
6492 | Call `pop_obstacks' iff NEED_POP is nonzero. | |
6493 | ||
82580166 | 6494 | For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers |
8d08fdba MS |
6495 | for aggregates that have constructors alive on the permanent obstack, |
6496 | so that the global initializing functions can be written at the end. | |
6497 | ||
6498 | INIT0 holds the value of an initializer that should be allowed to escape | |
6499 | the normal rules. | |
6500 | ||
6060a796 MS |
6501 | FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0 |
6502 | if the (init) syntax was used. | |
6503 | ||
8d08fdba | 6504 | For functions that take default parameters, DECL points to its |
82580166 | 6505 | "maximal" instantiation. `cp_finish_decl' must then also declared its |
8d08fdba MS |
6506 | subsequently lower and lower forms of instantiation, checking for |
6507 | ambiguity as it goes. This can be sped up later. */ | |
6508 | ||
6509 | void | |
82580166 | 6510 | cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) |
8d08fdba MS |
6511 | tree decl, init; |
6512 | tree asmspec_tree; | |
6513 | int need_pop; | |
6060a796 | 6514 | int flags; |
8d08fdba MS |
6515 | { |
6516 | register tree type; | |
a703fb38 | 6517 | tree cleanup = NULL_TREE, ttype = NULL_TREE; |
8d08fdba MS |
6518 | int was_incomplete; |
6519 | int temporary = allocation_temporary_p (); | |
6520 | char *asmspec = NULL; | |
6521 | int was_readonly = 0; | |
0c4b14c4 | 6522 | int already_used = 0; |
8d08fdba MS |
6523 | |
6524 | /* If this is 0, then we did not change obstacks. */ | |
6525 | if (! decl) | |
6526 | { | |
6527 | if (init) | |
6528 | error ("assignment (not initialization) in declaration"); | |
6529 | return; | |
6530 | } | |
6531 | ||
a4443a08 | 6532 | /* If a name was specified, get the string. */ |
8d08fdba | 6533 | if (asmspec_tree) |
8d08fdba | 6534 | asmspec = TREE_STRING_POINTER (asmspec_tree); |
8d08fdba MS |
6535 | |
6536 | /* If the type of the thing we are declaring either has | |
6537 | a constructor, or has a virtual function table pointer, | |
6538 | AND its initialization was accepted by `start_decl', | |
6539 | then we stayed on the permanent obstack through the | |
6540 | declaration, otherwise, changed obstacks as GCC would. */ | |
6541 | ||
6542 | type = TREE_TYPE (decl); | |
6543 | ||
f376e137 | 6544 | if (type == error_mark_node) |
eac293a1 | 6545 | { |
a9aedbc2 | 6546 | if (toplevel_bindings_p () && temporary) |
eac293a1 MS |
6547 | end_temporary_allocation (); |
6548 | ||
6549 | return; | |
6550 | } | |
f376e137 | 6551 | |
5156628f | 6552 | if (processing_template_decl) |
5566b478 MS |
6553 | { |
6554 | if (init && DECL_INITIAL (decl)) | |
6555 | DECL_INITIAL (decl) = init; | |
faf5394a | 6556 | if (minimal_parse_mode && ! DECL_ARTIFICIAL (decl)) |
5566b478 MS |
6557 | { |
6558 | tree stmt = DECL_VINDEX (decl); | |
e1467ff2 | 6559 | /* If the decl is declaring a member of a local class (in a |
8857f91e MM |
6560 | template function), the DECL_VINDEX will either be NULL, |
6561 | or it will be an actual virtual function index, not a | |
6562 | DECL_STMT. */ | |
6563 | if (stmt != NULL_TREE && TREE_CODE (stmt) == DECL_STMT) | |
75650646 MM |
6564 | { |
6565 | DECL_VINDEX (decl) = NULL_TREE; | |
6566 | TREE_OPERAND (stmt, 2) = copy_to_permanent (init); | |
6567 | add_tree (stmt); | |
6568 | } | |
5566b478 | 6569 | } |
8d08fdba | 6570 | |
5566b478 MS |
6571 | goto finish_end0; |
6572 | } | |
8d08fdba MS |
6573 | /* Take care of TYPE_DECLs up front. */ |
6574 | if (TREE_CODE (decl) == TYPE_DECL) | |
6575 | { | |
6576 | if (init && DECL_INITIAL (decl)) | |
6577 | { | |
6578 | /* typedef foo = bar; store the type of bar as the type of foo. */ | |
6579 | TREE_TYPE (decl) = type = TREE_TYPE (init); | |
6580 | DECL_INITIAL (decl) = init = NULL_TREE; | |
6581 | } | |
a0a33927 MS |
6582 | if (type != error_mark_node |
6583 | && IS_AGGR_TYPE (type) && DECL_NAME (decl)) | |
8d08fdba MS |
6584 | { |
6585 | if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type) | |
6586 | cp_warning ("shadowing previous type declaration of `%#D'", decl); | |
6587 | set_identifier_type_value (DECL_NAME (decl), type); | |
6588 | CLASSTYPE_GOT_SEMICOLON (type) = 1; | |
6589 | } | |
6590 | GNU_xref_decl (current_function_decl, decl); | |
cffa8729 MS |
6591 | |
6592 | /* If we have installed this as the canonical typedef for this | |
6593 | type, and that type has not been defined yet, delay emitting | |
956d6950 | 6594 | the debug information for it, as we will emit it later. */ |
d2e5ee5c | 6595 | if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl |
cffa8729 MS |
6596 | && TYPE_SIZE (TREE_TYPE (decl)) == NULL_TREE) |
6597 | TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; | |
6598 | ||
8d08fdba | 6599 | rest_of_decl_compilation (decl, NULL_PTR, |
5566b478 | 6600 | DECL_CONTEXT (decl) == NULL_TREE, at_eof); |
8d08fdba MS |
6601 | goto finish_end; |
6602 | } | |
8d08fdba MS |
6603 | if (TREE_CODE (decl) != FUNCTION_DECL) |
6604 | { | |
6605 | ttype = target_type (type); | |
8d08fdba MS |
6606 | } |
6607 | ||
6608 | if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) | |
6609 | && TYPE_NEEDS_CONSTRUCTING (type)) | |
6610 | { | |
6611 | ||
6612 | /* Currently, GNU C++ puts constants in text space, making them | |
6613 | impossible to initialize. In the future, one would hope for | |
6614 | an operating system which understood the difference between | |
6615 | initialization and the running of a program. */ | |
6616 | was_readonly = 1; | |
6617 | TREE_READONLY (decl) = 0; | |
6618 | } | |
6619 | ||
6620 | if (TREE_CODE (decl) == FIELD_DECL) | |
6621 | { | |
6622 | if (init && init != error_mark_node) | |
6623 | my_friendly_assert (TREE_PERMANENT (init), 147); | |
6624 | ||
6625 | if (asmspec) | |
6626 | { | |
6627 | /* This must override the asm specifier which was placed | |
6060a796 | 6628 | by grokclassfn. Lay this out fresh. */ |
8d08fdba MS |
6629 | DECL_RTL (TREE_TYPE (decl)) = NULL_RTX; |
6630 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
6631 | make_decl_rtl (decl, asmspec, 0); | |
6632 | } | |
6633 | } | |
6634 | /* If `start_decl' didn't like having an initialization, ignore it now. */ | |
6635 | else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) | |
6636 | init = NULL_TREE; | |
6637 | else if (DECL_EXTERNAL (decl)) | |
6638 | ; | |
6639 | else if (TREE_CODE (type) == REFERENCE_TYPE | |
6640 | || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type))) | |
6641 | { | |
f376e137 MS |
6642 | if (TREE_STATIC (decl)) |
6643 | make_decl_rtl (decl, NULL_PTR, | |
a9aedbc2 | 6644 | toplevel_bindings_p () |
f376e137 | 6645 | || pseudo_global_level_p ()); |
a703fb38 | 6646 | grok_reference_init (decl, type, init); |
8d08fdba MS |
6647 | init = NULL_TREE; |
6648 | } | |
6649 | ||
6650 | GNU_xref_decl (current_function_decl, decl); | |
6651 | ||
a0a33927 | 6652 | if (TREE_CODE (decl) == FIELD_DECL) |
8d08fdba MS |
6653 | ; |
6654 | else if (TREE_CODE (decl) == CONST_DECL) | |
6655 | { | |
6656 | my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); | |
6657 | ||
6658 | DECL_INITIAL (decl) = init; | |
6659 | ||
6660 | /* This will keep us from needing to worry about our obstacks. */ | |
6661 | my_friendly_assert (init != NULL_TREE, 149); | |
6662 | init = NULL_TREE; | |
6663 | } | |
6664 | else if (init) | |
6665 | { | |
6666 | if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type)) | |
6667 | { | |
6668 | if (TREE_CODE (type) == ARRAY_TYPE) | |
6669 | init = digest_init (type, init, (tree *) 0); | |
a3203465 | 6670 | else if (TREE_CODE (init) == CONSTRUCTOR) |
8d08fdba | 6671 | { |
f30432d7 | 6672 | if (TYPE_NON_AGGREGATE_CLASS (type)) |
8d08fdba | 6673 | { |
a28e3c7f MS |
6674 | cp_error ("`%D' must be initialized by constructor, not by `{...}'", |
6675 | decl); | |
8d08fdba MS |
6676 | init = error_mark_node; |
6677 | } | |
6678 | else | |
6679 | goto dont_use_constructor; | |
6680 | } | |
8d08fdba MS |
6681 | } |
6682 | else | |
6683 | { | |
6684 | dont_use_constructor: | |
6685 | if (TREE_CODE (init) != TREE_VEC) | |
6686 | init = store_init_value (decl, init); | |
8d08fdba | 6687 | } |
28cbf42c MS |
6688 | |
6689 | if (init) | |
6690 | /* We must hide the initializer so that expand_decl | |
6691 | won't try to do something it does not understand. */ | |
6692 | init = obscure_complex_init (decl, init); | |
8d08fdba | 6693 | } |
a0a33927 MS |
6694 | else if (DECL_EXTERNAL (decl)) |
6695 | ; | |
8d08fdba MS |
6696 | else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't' |
6697 | && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))) | |
6698 | { | |
6699 | tree ctype = type; | |
6700 | while (TREE_CODE (ctype) == ARRAY_TYPE) | |
6701 | ctype = TREE_TYPE (ctype); | |
6702 | if (! TYPE_NEEDS_CONSTRUCTING (ctype)) | |
6703 | { | |
6704 | if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype)) | |
6705 | cp_error ("structure `%D' with uninitialized const members", decl); | |
6706 | if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype)) | |
a28e3c7f MS |
6707 | cp_error ("structure `%D' with uninitialized reference members", |
6708 | decl); | |
8d08fdba MS |
6709 | } |
6710 | ||
6711 | if (TREE_CODE (decl) == VAR_DECL | |
6712 | && !DECL_INITIAL (decl) | |
6713 | && !TYPE_NEEDS_CONSTRUCTING (type) | |
6714 | && (TYPE_READONLY (type) || TREE_READONLY (decl))) | |
6715 | cp_error ("uninitialized const `%D'", decl); | |
6716 | ||
6060a796 MS |
6717 | if (TYPE_SIZE (type) != NULL_TREE |
6718 | && TYPE_NEEDS_CONSTRUCTING (type)) | |
28cbf42c | 6719 | init = obscure_complex_init (decl, NULL_TREE); |
8d08fdba MS |
6720 | } |
6721 | else if (TREE_CODE (decl) == VAR_DECL | |
6722 | && TREE_CODE (type) != REFERENCE_TYPE | |
6723 | && (TYPE_READONLY (type) || TREE_READONLY (decl))) | |
6724 | { | |
6725 | /* ``Unless explicitly declared extern, a const object does not have | |
6726 | external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 | |
6727 | However, if it's `const int foo = 1; const int foo;', don't complain | |
6728 | about the second decl, since it does have an initializer before. | |
6729 | We deliberately don't complain about arrays, because they're | |
6730 | supposed to be initialized by a constructor. */ | |
6731 | if (! DECL_INITIAL (decl) | |
6732 | && TREE_CODE (type) != ARRAY_TYPE | |
6733 | && (!pedantic || !current_class_type)) | |
6734 | cp_error ("uninitialized const `%#D'", decl); | |
6735 | } | |
6736 | ||
6737 | /* For top-level declaration, the initial value was read in | |
6738 | the temporary obstack. MAXINDEX, rtl, etc. to be made below | |
6739 | must go in the permanent obstack; but don't discard the | |
6740 | temporary data yet. */ | |
6741 | ||
a9aedbc2 | 6742 | if (toplevel_bindings_p () && temporary) |
8d08fdba MS |
6743 | end_temporary_allocation (); |
6744 | ||
6745 | /* Deduce size of array from initialization, if not already known. */ | |
6746 | ||
6747 | if (TREE_CODE (type) == ARRAY_TYPE | |
6748 | && TYPE_DOMAIN (type) == NULL_TREE | |
6749 | && TREE_CODE (decl) != TYPE_DECL) | |
6750 | { | |
6751 | int do_default | |
6752 | = (TREE_STATIC (decl) | |
6753 | /* Even if pedantic, an external linkage array | |
6754 | may have incomplete type at first. */ | |
6755 | ? pedantic && ! DECL_EXTERNAL (decl) | |
6756 | : !DECL_EXTERNAL (decl)); | |
6757 | tree initializer = init ? init : DECL_INITIAL (decl); | |
6758 | int failure = complete_array_type (type, initializer, do_default); | |
6759 | ||
6760 | if (failure == 1) | |
6761 | cp_error ("initializer fails to determine size of `%D'", decl); | |
6762 | ||
6763 | if (failure == 2) | |
6764 | { | |
6765 | if (do_default) | |
6766 | cp_error ("array size missing in `%D'", decl); | |
6767 | /* If a `static' var's size isn't known, make it extern as | |
6768 | well as static, so it does not get allocated. If it's not | |
6769 | `static', then don't mark it extern; finish_incomplete_decl | |
6770 | will give it a default size and it will get allocated. */ | |
6771 | else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) | |
6772 | DECL_EXTERNAL (decl) = 1; | |
6773 | } | |
6774 | ||
6775 | if (pedantic && TYPE_DOMAIN (type) != NULL_TREE | |
6776 | && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), | |
6777 | integer_zero_node)) | |
6778 | cp_error ("zero-size array `%D'", decl); | |
6779 | ||
6780 | layout_decl (decl, 0); | |
6781 | } | |
6782 | ||
6783 | if (TREE_CODE (decl) == VAR_DECL) | |
6784 | { | |
6785 | if (DECL_SIZE (decl) == NULL_TREE | |
ec255269 | 6786 | && TYPE_SIZE (complete_type (TREE_TYPE (decl))) != NULL_TREE) |
8d08fdba MS |
6787 | layout_decl (decl, 0); |
6788 | ||
6789 | if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) | |
6790 | { | |
6791 | /* A static variable with an incomplete type: | |
6792 | that is an error if it is initialized. | |
6793 | Otherwise, let it through, but if it is not `extern' | |
6794 | then it may cause an error message later. */ | |
6795 | if (DECL_INITIAL (decl) != NULL_TREE) | |
6796 | cp_error ("storage size of `%D' isn't known", decl); | |
6797 | init = NULL_TREE; | |
6798 | } | |
6799 | else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) | |
6800 | { | |
6801 | /* An automatic variable with an incomplete type: that is an error. | |
6802 | Don't talk about array types here, since we took care of that | |
6803 | message in grokdeclarator. */ | |
6804 | cp_error ("storage size of `%D' isn't known", decl); | |
6805 | TREE_TYPE (decl) = error_mark_node; | |
6806 | } | |
6807 | else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) | |
6808 | /* Let debugger know it should output info for this type. */ | |
6809 | note_debug_info_needed (ttype); | |
6810 | ||
d2e5ee5c MS |
6811 | if (TREE_STATIC (decl) && DECL_CONTEXT (decl) |
6812 | && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't') | |
6813 | note_debug_info_needed (DECL_CONTEXT (decl)); | |
6814 | ||
8d08fdba MS |
6815 | if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) |
6816 | && DECL_SIZE (decl) != NULL_TREE | |
6817 | && ! TREE_CONSTANT (DECL_SIZE (decl))) | |
6818 | { | |
6819 | if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) | |
6820 | constant_expression_warning (DECL_SIZE (decl)); | |
6821 | else | |
6822 | cp_error ("storage size of `%D' isn't constant", decl); | |
6823 | } | |
6824 | ||
c91a56d2 MS |
6825 | if (! DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type) |
6826 | /* Cleanups for static variables are handled by `finish_file'. */ | |
6827 | && ! TREE_STATIC (decl)) | |
8d08fdba MS |
6828 | { |
6829 | int yes = suspend_momentary (); | |
2ee887f2 | 6830 | cleanup = maybe_build_cleanup (decl); |
8d08fdba MS |
6831 | resume_momentary (yes); |
6832 | } | |
6833 | } | |
6834 | /* PARM_DECLs get cleanups, too. */ | |
6835 | else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type)) | |
6836 | { | |
6837 | if (temporary) | |
6838 | end_temporary_allocation (); | |
6839 | cleanup = maybe_build_cleanup (decl); | |
6840 | if (temporary) | |
6841 | resume_temporary_allocation (); | |
6842 | } | |
6843 | ||
6844 | /* Output the assembler code and/or RTL code for variables and functions, | |
6845 | unless the type is an undefined structure or union. | |
6846 | If not, it will get done when the type is completed. */ | |
6847 | ||
5566b478 MS |
6848 | was_incomplete = (DECL_SIZE (decl) == NULL_TREE); |
6849 | ||
8d08fdba MS |
6850 | if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL |
6851 | || TREE_CODE (decl) == RESULT_DECL) | |
6852 | { | |
6853 | /* ??? FIXME: What about nested classes? */ | |
e1467ff2 | 6854 | int toplev = toplevel_bindings_p () || pseudo_global_level_p (); |
8d08fdba | 6855 | int was_temp |
d22c8596 | 6856 | = (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type) |
8d08fdba MS |
6857 | && allocation_temporary_p ()); |
6858 | ||
6859 | if (was_temp) | |
6860 | end_temporary_allocation (); | |
6861 | ||
42976354 BK |
6862 | /* Extern inline function static data has external linkage. */ |
6863 | if (TREE_CODE (decl) == VAR_DECL | |
6864 | && TREE_STATIC (decl) | |
6865 | && current_function_decl | |
6866 | && DECL_CONTEXT (decl) == current_function_decl | |
6867 | && DECL_THIS_INLINE (current_function_decl) | |
893de33c | 6868 | && TREE_PUBLIC (current_function_decl)) |
42976354 | 6869 | { |
818045b6 JM |
6870 | if (DECL_INTERFACE_KNOWN (current_function_decl)) |
6871 | { | |
6872 | TREE_PUBLIC (decl) = 1; | |
6873 | DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl); | |
6874 | } | |
42976354 BK |
6875 | /* We can only do this if we can use common or weak, and we |
6876 | can't if it has been initialized and we don't support weak. */ | |
818045b6 JM |
6877 | else if (DECL_INITIAL (decl) == NULL_TREE |
6878 | || DECL_INITIAL (decl) == error_mark_node) | |
42976354 BK |
6879 | { |
6880 | TREE_PUBLIC (decl) = 1; | |
6881 | DECL_COMMON (decl) = 1; | |
6882 | } | |
6883 | else if (flag_weak) | |
6884 | make_decl_one_only (decl); | |
6885 | ||
6886 | if (TREE_PUBLIC (decl)) | |
6887 | DECL_ASSEMBLER_NAME (decl) | |
6888 | = build_static_name (current_function_decl, DECL_NAME (decl)); | |
6889 | else if (! DECL_ARTIFICIAL (decl)) | |
6890 | cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl); | |
6891 | } | |
6892 | ||
77be6f82 JM |
6893 | else if (TREE_CODE (decl) == VAR_DECL |
6894 | && DECL_LANG_SPECIFIC (decl) | |
6895 | && DECL_COMDAT (decl)) | |
6896 | { | |
6897 | /* Dynamically initialized vars go into common. */ | |
6898 | if (DECL_INITIAL (decl) == NULL_TREE | |
6899 | || DECL_INITIAL (decl) == error_mark_node) | |
6900 | DECL_COMMON (decl) = 1; | |
6901 | else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) | |
6902 | { | |
6903 | DECL_COMMON (decl) = 1; | |
6904 | DECL_INITIAL (decl) = error_mark_node; | |
6905 | } | |
6906 | else | |
6907 | { | |
6908 | /* Statically initialized vars are weak or comdat, if | |
6909 | supported. */ | |
6910 | if (flag_weak) | |
6911 | make_decl_one_only (decl); | |
6912 | else | |
be343556 JM |
6913 | { |
6914 | /* we can't do anything useful; leave vars for explicit | |
6915 | instantiation. */ | |
6916 | DECL_EXTERNAL (decl) = 1; | |
6917 | DECL_NOT_REALLY_EXTERN (decl) = 0; | |
6918 | } | |
77be6f82 JM |
6919 | } |
6920 | } | |
6921 | ||
8d08fdba MS |
6922 | if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) |
6923 | make_decl_rtl (decl, NULL_PTR, toplev); | |
6924 | else if (TREE_CODE (decl) == VAR_DECL | |
6925 | && TREE_READONLY (decl) | |
6926 | && DECL_INITIAL (decl) != NULL_TREE | |
6927 | && DECL_INITIAL (decl) != error_mark_node | |
a3203465 | 6928 | && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) |
8d08fdba MS |
6929 | { |
6930 | DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); | |
6931 | ||
6932 | if (asmspec) | |
6933 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
6934 | ||
6935 | if (! toplev | |
6936 | && TREE_STATIC (decl) | |
6937 | && ! TREE_SIDE_EFFECTS (decl) | |
6938 | && ! TREE_PUBLIC (decl) | |
6939 | && ! DECL_EXTERNAL (decl) | |
6940 | && ! TYPE_NEEDS_DESTRUCTOR (type) | |
6941 | && DECL_MODE (decl) != BLKmode) | |
6942 | { | |
6943 | /* If this variable is really a constant, then fill its DECL_RTL | |
6944 | slot with something which won't take up storage. | |
6945 | If something later should take its address, we can always give | |
6946 | it legitimate RTL at that time. */ | |
6947 | DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); | |
6948 | store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0); | |
6949 | TREE_ASM_WRITTEN (decl) = 1; | |
6950 | } | |
a0a33927 | 6951 | else if (toplev && ! TREE_PUBLIC (decl)) |
8d08fdba | 6952 | { |
8d08fdba | 6953 | /* If this is a static const, change its apparent linkage |
db5ae43f | 6954 | if it belongs to a #pragma interface. */ |
a0a33927 | 6955 | if (!interface_unknown) |
8d08fdba MS |
6956 | { |
6957 | TREE_PUBLIC (decl) = 1; | |
6958 | DECL_EXTERNAL (decl) = interface_only; | |
6959 | } | |
6960 | make_decl_rtl (decl, asmspec, toplev); | |
6961 | } | |
6962 | else | |
5566b478 | 6963 | rest_of_decl_compilation (decl, asmspec, toplev, at_eof); |
8d08fdba MS |
6964 | } |
6965 | else if (TREE_CODE (decl) == VAR_DECL | |
6966 | && DECL_LANG_SPECIFIC (decl) | |
6967 | && DECL_IN_AGGR_P (decl)) | |
6968 | { | |
6969 | if (TREE_STATIC (decl)) | |
6970 | { | |
6971 | if (init == NULL_TREE | |
6972 | #ifdef DEFAULT_STATIC_DEFS | |
6973 | /* If this code is dead, then users must | |
6974 | explicitly declare static member variables | |
6975 | outside the class def'n as well. */ | |
6976 | && TYPE_NEEDS_CONSTRUCTING (type) | |
6977 | #endif | |
6978 | ) | |
6979 | { | |
6980 | DECL_EXTERNAL (decl) = 1; | |
6981 | make_decl_rtl (decl, asmspec, 1); | |
6982 | } | |
6983 | else | |
5566b478 | 6984 | rest_of_decl_compilation (decl, asmspec, toplev, at_eof); |
8d08fdba MS |
6985 | } |
6986 | else | |
6987 | /* Just a constant field. Should not need any rtl. */ | |
6988 | goto finish_end0; | |
6989 | } | |
6990 | else | |
5566b478 | 6991 | rest_of_decl_compilation (decl, asmspec, toplev, at_eof); |
8d08fdba MS |
6992 | |
6993 | if (was_temp) | |
6994 | resume_temporary_allocation (); | |
6995 | ||
6996 | if (type != error_mark_node | |
6997 | && TYPE_LANG_SPECIFIC (type) | |
6998 | && CLASSTYPE_ABSTRACT_VIRTUALS (type)) | |
6999 | abstract_virtuals_error (decl, type); | |
7000 | else if ((TREE_CODE (type) == FUNCTION_TYPE | |
7001 | || TREE_CODE (type) == METHOD_TYPE) | |
7002 | && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) | |
7003 | && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type))) | |
7004 | abstract_virtuals_error (decl, TREE_TYPE (type)); | |
7005 | ||
7006 | if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type)) | |
7007 | signature_error (decl, type); | |
7008 | else if ((TREE_CODE (type) == FUNCTION_TYPE | |
7009 | || TREE_CODE (type) == METHOD_TYPE) | |
7010 | && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) | |
7011 | && IS_SIGNATURE (TREE_TYPE (type))) | |
7012 | signature_error (decl, TREE_TYPE (type)); | |
7013 | ||
7014 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
faae18ab | 7015 | ; |
67d743fe MS |
7016 | else if (DECL_EXTERNAL (decl) |
7017 | && ! (DECL_LANG_SPECIFIC (decl) | |
7018 | && DECL_NOT_REALLY_EXTERN (decl))) | |
5566b478 MS |
7019 | { |
7020 | if (init) | |
7021 | DECL_INITIAL (decl) = init; | |
7022 | } | |
8d08fdba MS |
7023 | else if (TREE_STATIC (decl) && type != error_mark_node) |
7024 | { | |
7025 | /* Cleanups for static variables are handled by `finish_file'. */ | |
f30432d7 MS |
7026 | if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE |
7027 | || TYPE_NEEDS_DESTRUCTOR (type)) | |
8d08fdba | 7028 | expand_static_init (decl, init); |
8d08fdba MS |
7029 | } |
7030 | else if (! toplev) | |
7031 | { | |
7032 | /* This is a declared decl which must live until the | |
7033 | end of the binding contour. It may need a cleanup. */ | |
7034 | ||
7035 | /* Recompute the RTL of a local array now | |
7036 | if it used to be an incomplete type. */ | |
7037 | if (was_incomplete && ! TREE_STATIC (decl)) | |
7038 | { | |
7039 | /* If we used it already as memory, it must stay in memory. */ | |
7040 | TREE_ADDRESSABLE (decl) = TREE_USED (decl); | |
7041 | /* If it's still incomplete now, no init will save it. */ | |
7042 | if (DECL_SIZE (decl) == NULL_TREE) | |
7043 | DECL_INITIAL (decl) = NULL_TREE; | |
7044 | expand_decl (decl); | |
7045 | } | |
7046 | else if (! TREE_ASM_WRITTEN (decl) | |
7047 | && (TYPE_SIZE (type) != NULL_TREE | |
7048 | || TREE_CODE (type) == ARRAY_TYPE)) | |
7049 | { | |
7050 | /* Do this here, because we did not expand this decl's | |
7051 | rtl in start_decl. */ | |
7052 | if (DECL_RTL (decl) == NULL_RTX) | |
7053 | expand_decl (decl); | |
7054 | else if (cleanup) | |
7055 | { | |
8d2733ca MS |
7056 | /* XXX: Why don't we use decl here? */ |
7057 | /* Ans: Because it was already expanded? */ | |
e349ee73 | 7058 | if (! expand_decl_cleanup (NULL_TREE, cleanup)) |
8d2733ca MS |
7059 | cp_error ("parser lost in parsing declaration of `%D'", |
7060 | decl); | |
8d08fdba MS |
7061 | /* Cleanup used up here. */ |
7062 | cleanup = NULL_TREE; | |
7063 | } | |
7064 | } | |
7065 | ||
2ee887f2 MS |
7066 | if (current_binding_level->is_for_scope) |
7067 | { | |
7068 | struct binding_level *outer = current_binding_level->level_chain; | |
7069 | ||
7070 | /* Check to see if the same name is already bound at | |
7071 | the outer level, either because it was directly declared, | |
7072 | or because a dead for-decl got preserved. In either case, | |
d22c8596 | 7073 | the code would not have been valid under the ARM |
2ee887f2 MS |
7074 | scope rules, so clear is_for_scope for the |
7075 | current_binding_level. | |
7076 | ||
7077 | Otherwise, we need to preserve the temp slot for decl | |
e92cc029 | 7078 | to last into the outer binding level. */ |
2ee887f2 MS |
7079 | |
7080 | int handling_dead_for_vars = 0; | |
7081 | tree link = outer->names; | |
7082 | for (; ; link = TREE_CHAIN (link)) | |
7083 | { | |
7084 | if (link == NULL && handling_dead_for_vars == 0) | |
7085 | { | |
7086 | link = outer->dead_vars_from_for; | |
7087 | handling_dead_for_vars = 1; | |
7088 | } | |
7089 | if (link == NULL) | |
7090 | { | |
cffa8729 | 7091 | if (DECL_IN_MEMORY_P (decl)) |
2ee887f2 MS |
7092 | preserve_temp_slots (DECL_RTL (decl)); |
7093 | break; | |
7094 | } | |
7095 | if (DECL_NAME (link) == DECL_NAME (decl)) | |
7096 | { | |
7097 | if (handling_dead_for_vars) | |
7098 | { | |
7099 | tree shadowing | |
7100 | = purpose_member (DECL_NAME (decl), | |
7101 | current_binding_level->shadowed); | |
7102 | if (shadowing && TREE_VALUE (shadowing) == link) | |
7103 | TREE_VALUE (shadowing) | |
7104 | = DECL_SHADOWED_FOR_VAR (link); | |
7105 | } | |
7106 | current_binding_level->is_for_scope = 0; | |
7107 | break; | |
7108 | } | |
7109 | } | |
7110 | } | |
7111 | ||
eb66be0e | 7112 | expand_start_target_temps (); |
72b7eeff | 7113 | |
8d08fdba MS |
7114 | if (DECL_SIZE (decl) && type != error_mark_node) |
7115 | { | |
7116 | /* Compute and store the initial value. */ | |
7117 | expand_decl_init (decl); | |
0c4b14c4 | 7118 | already_used = TREE_USED (decl) || TREE_USED (type); |
8d08fdba MS |
7119 | |
7120 | if (init || TYPE_NEEDS_CONSTRUCTING (type)) | |
7121 | { | |
a28e3c7f MS |
7122 | emit_line_note (DECL_SOURCE_FILE (decl), |
7123 | DECL_SOURCE_LINE (decl)); | |
6060a796 | 7124 | expand_aggr_init (decl, init, 0, flags); |
8d08fdba MS |
7125 | } |
7126 | ||
00595019 MS |
7127 | /* Set this to 0 so we can tell whether an aggregate which |
7128 | was initialized was ever used. Don't do this if it has a | |
7129 | destructor, so we don't complain about the 'resource | |
7130 | allocation is initialization' idiom. */ | |
249555b0 BK |
7131 | /* Now set attribute((unused)) on types so decls of |
7132 | of that type will be marked used. (see TREE_USED, above.) | |
7133 | This avoids the warning problems this particular code | |
7134 | tried to work around. */ | |
0c4b14c4 | 7135 | |
be99da77 | 7136 | if (TYPE_NEEDS_CONSTRUCTING (type) |
0c4b14c4 | 7137 | && ! already_used |
be99da77 MS |
7138 | && cleanup == NULL_TREE |
7139 | && DECL_NAME (decl)) | |
8d08fdba | 7140 | TREE_USED (decl) = 0; |
0c4b14c4 JM |
7141 | |
7142 | if (already_used) | |
7143 | TREE_USED (decl) = 1; | |
934c6b13 | 7144 | } |
eb66be0e | 7145 | |
934c6b13 | 7146 | /* Cleanup any temporaries needed for the initial value. */ |
eb66be0e | 7147 | expand_end_target_temps (); |
8d08fdba | 7148 | |
934c6b13 MS |
7149 | if (DECL_SIZE (decl) && type != error_mark_node) |
7150 | { | |
8d08fdba MS |
7151 | /* Store the cleanup, if there was one. */ |
7152 | if (cleanup) | |
7153 | { | |
e349ee73 | 7154 | if (! expand_decl_cleanup (decl, cleanup)) |
a28e3c7f MS |
7155 | cp_error ("parser lost in parsing declaration of `%D'", |
7156 | decl); | |
8d08fdba MS |
7157 | } |
7158 | } | |
7159 | } | |
7160 | finish_end0: | |
7161 | ||
7162 | /* Undo call to `pushclass' that was done in `start_decl' | |
7163 | due to initialization of qualified member variable. | |
7164 | I.e., Foo::x = 10; */ | |
7165 | { | |
f30432d7 | 7166 | tree context = DECL_REAL_CONTEXT (decl); |
8d08fdba MS |
7167 | if (context |
7168 | && TREE_CODE_CLASS (TREE_CODE (context)) == 't' | |
7169 | && (TREE_CODE (decl) == VAR_DECL | |
7170 | /* We also have a pushclass done that we need to undo here | |
7171 | if we're at top level and declare a method. */ | |
5566b478 MS |
7172 | || TREE_CODE (decl) == FUNCTION_DECL) |
7173 | /* If size hasn't been set, we're still defining it, | |
7174 | and therefore inside the class body; don't pop | |
7175 | the binding level.. */ | |
7176 | && TYPE_SIZE (context) != NULL_TREE | |
7177 | && context == current_class_type) | |
8d08fdba MS |
7178 | popclass (1); |
7179 | } | |
7180 | } | |
7181 | ||
7182 | finish_end: | |
7183 | ||
39211cd5 MS |
7184 | /* If requested, warn about definitions of large data objects. */ |
7185 | ||
7186 | if (warn_larger_than | |
5156628f | 7187 | && ! processing_template_decl |
39211cd5 MS |
7188 | && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) |
7189 | && !DECL_EXTERNAL (decl)) | |
7190 | { | |
7191 | register tree decl_size = DECL_SIZE (decl); | |
7192 | ||
7193 | if (decl_size && TREE_CODE (decl_size) == INTEGER_CST) | |
7194 | { | |
7195 | unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT; | |
7196 | ||
7197 | if (units > larger_than_size) | |
7198 | warning_with_decl (decl, "size of `%s' is %u bytes", units); | |
7199 | } | |
7200 | } | |
7201 | ||
8d08fdba MS |
7202 | if (need_pop) |
7203 | { | |
7204 | /* Resume permanent allocation, if not within a function. */ | |
7205 | /* The corresponding push_obstacks_nochange is in start_decl, | |
7206 | start_method, groktypename, and in grokfield. */ | |
7207 | pop_obstacks (); | |
7208 | } | |
7209 | ||
7210 | if (was_readonly) | |
7211 | TREE_READONLY (decl) = 1; | |
8d08fdba MS |
7212 | } |
7213 | ||
82580166 | 7214 | /* This is here for a midend callback from c-common.c */ |
e92cc029 | 7215 | |
82580166 MS |
7216 | void |
7217 | finish_decl (decl, init, asmspec_tree) | |
7218 | tree decl, init; | |
7219 | tree asmspec_tree; | |
7220 | { | |
7221 | cp_finish_decl (decl, init, asmspec_tree, 1, 0); | |
7222 | } | |
7223 | ||
8d08fdba MS |
7224 | void |
7225 | expand_static_init (decl, init) | |
7226 | tree decl; | |
7227 | tree init; | |
7228 | { | |
7229 | tree oldstatic = value_member (decl, static_aggregates); | |
a4443a08 | 7230 | |
8d08fdba MS |
7231 | if (oldstatic) |
7232 | { | |
7233 | if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) | |
7234 | cp_error ("multiple initializations given for `%D'", decl); | |
7235 | } | |
a9aedbc2 | 7236 | else if (! toplevel_bindings_p () && ! pseudo_global_level_p ()) |
8d08fdba MS |
7237 | { |
7238 | /* Emit code to perform this initialization but once. */ | |
7239 | tree temp; | |
7240 | ||
e92cc029 | 7241 | /* Remember this information until end of file. */ |
8d08fdba MS |
7242 | push_obstacks (&permanent_obstack, &permanent_obstack); |
7243 | ||
7244 | /* Emit code to perform this initialization but once. */ | |
7245 | temp = get_temp_name (integer_type_node, 1); | |
7246 | rest_of_decl_compilation (temp, NULL_PTR, 0, 0); | |
7247 | expand_start_cond (build_binary_op (EQ_EXPR, temp, | |
7248 | integer_zero_node, 1), 0); | |
eb66be0e | 7249 | expand_start_target_temps (); |
72b7eeff | 7250 | |
8d08fdba | 7251 | expand_assignment (temp, integer_one_node, 0, 0); |
28cbf42c | 7252 | if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)) |
f30432d7 | 7253 | || (init && TREE_CODE (init) == TREE_LIST)) |
8d08fdba | 7254 | { |
6060a796 | 7255 | expand_aggr_init (decl, init, 0, 0); |
8d08fdba MS |
7256 | do_pending_stack_adjust (); |
7257 | } | |
f30432d7 | 7258 | else if (init) |
8d08fdba | 7259 | expand_assignment (decl, init, 0, 0); |
f30432d7 | 7260 | |
a4443a08 | 7261 | /* Cleanup any temporaries needed for the initial value. */ |
eb66be0e | 7262 | expand_end_target_temps (); |
72b7eeff MS |
7263 | |
7264 | if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) | |
7265 | { | |
7266 | tree cleanup, fcall; | |
7267 | static tree Atexit = 0; | |
7268 | if (Atexit == 0) | |
7269 | { | |
7270 | tree atexit_fndecl, PFV, pfvlist; | |
e92cc029 | 7271 | /* Remember this information until end of file. */ |
72b7eeff MS |
7272 | push_obstacks (&permanent_obstack, &permanent_obstack); |
7273 | PFV = build_pointer_type (build_function_type | |
7274 | (void_type_node, void_list_node)); | |
7275 | ||
7276 | pfvlist = tree_cons (NULL_TREE, PFV, void_list_node); | |
7277 | ||
7278 | push_lang_context (lang_name_c); | |
beb53fb8 JM |
7279 | atexit_fndecl |
7280 | = builtin_function ("atexit", | |
7281 | build_function_type (void_type_node, | |
7282 | pfvlist), | |
7283 | NOT_BUILT_IN, NULL_PTR); | |
be99da77 | 7284 | assemble_external (atexit_fndecl); |
72b7eeff MS |
7285 | Atexit = default_conversion (atexit_fndecl); |
7286 | pop_lang_context (); | |
7287 | pop_obstacks (); | |
7288 | } | |
7289 | ||
7290 | cleanup = start_anon_func (); | |
7291 | expand_expr_stmt (build_cleanup (decl)); | |
7292 | end_anon_func (); | |
7293 | mark_addressable (cleanup); | |
7294 | cleanup = build_unary_op (ADDR_EXPR, cleanup, 0); | |
e66d884e | 7295 | fcall = build_function_call (Atexit, expr_tree_cons (NULL_TREE, cleanup, NULL_TREE)); |
72b7eeff MS |
7296 | expand_expr_stmt (fcall); |
7297 | } | |
7298 | ||
8d08fdba MS |
7299 | expand_end_cond (); |
7300 | if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) | |
7301 | { | |
7302 | static_aggregates = perm_tree_cons (temp, decl, static_aggregates); | |
7303 | TREE_STATIC (static_aggregates) = 1; | |
7304 | } | |
7305 | ||
e92cc029 | 7306 | /* Resume old (possibly temporary) allocation. */ |
8d08fdba MS |
7307 | pop_obstacks (); |
7308 | } | |
7309 | else | |
7310 | { | |
7311 | /* This code takes into account memory allocation | |
7312 | policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING | |
7313 | does not hold for this object, then we must make permanent | |
7314 | the storage currently in the temporary obstack. */ | |
7315 | if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) | |
7316 | preserve_initializer (); | |
7317 | static_aggregates = perm_tree_cons (init, decl, static_aggregates); | |
7318 | } | |
7319 | } | |
7320 | \f | |
7321 | /* Make TYPE a complete type based on INITIAL_VALUE. | |
7322 | Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, | |
7323 | 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ | |
7324 | ||
7325 | int | |
7326 | complete_array_type (type, initial_value, do_default) | |
7327 | tree type, initial_value; | |
7328 | int do_default; | |
7329 | { | |
7330 | register tree maxindex = NULL_TREE; | |
7331 | int value = 0; | |
7332 | ||
7333 | if (initial_value) | |
7334 | { | |
7335 | /* Note MAXINDEX is really the maximum index, | |
7336 | one less than the size. */ | |
7337 | if (TREE_CODE (initial_value) == STRING_CST) | |
e1cd6e56 MS |
7338 | { |
7339 | int eltsize | |
7340 | = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); | |
7341 | maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) | |
7342 | / eltsize) - 1, 0); | |
7343 | } | |
8d08fdba MS |
7344 | else if (TREE_CODE (initial_value) == CONSTRUCTOR) |
7345 | { | |
e1cd6e56 MS |
7346 | tree elts = CONSTRUCTOR_ELTS (initial_value); |
7347 | maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node); | |
7348 | for (; elts; elts = TREE_CHAIN (elts)) | |
7349 | { | |
7350 | if (TREE_PURPOSE (elts)) | |
7351 | maxindex = TREE_PURPOSE (elts); | |
7352 | else | |
7353 | maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node); | |
7354 | } | |
7355 | maxindex = copy_node (maxindex); | |
8d08fdba MS |
7356 | } |
7357 | else | |
7358 | { | |
7359 | /* Make an error message unless that happened already. */ | |
7360 | if (initial_value != error_mark_node) | |
7361 | value = 1; | |
7362 | ||
7363 | /* Prevent further error messages. */ | |
7364 | maxindex = build_int_2 (0, 0); | |
7365 | } | |
7366 | } | |
7367 | ||
7368 | if (!maxindex) | |
7369 | { | |
7370 | if (do_default) | |
7371 | maxindex = build_int_2 (0, 0); | |
7372 | value = 2; | |
7373 | } | |
7374 | ||
7375 | if (maxindex) | |
7376 | { | |
51c184be MS |
7377 | tree itype; |
7378 | ||
8d08fdba | 7379 | TYPE_DOMAIN (type) = build_index_type (maxindex); |
dff6b454 | 7380 | if (! TREE_TYPE (maxindex)) |
8d08fdba | 7381 | TREE_TYPE (maxindex) = TYPE_DOMAIN (type); |
51c184be MS |
7382 | if (initial_value) |
7383 | itype = TREE_TYPE (initial_value); | |
7384 | else | |
7385 | itype = NULL; | |
7386 | if (itype && !TYPE_DOMAIN (itype)) | |
7387 | TYPE_DOMAIN (itype) = TYPE_DOMAIN (type); | |
dff6b454 RK |
7388 | /* The type of the main variant should never be used for arrays |
7389 | of different sizes. It should only ever be completed with the | |
7390 | size of the array. */ | |
7391 | if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type))) | |
7392 | TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type); | |
8d08fdba MS |
7393 | } |
7394 | ||
7395 | /* Lay out the type now that we can get the real answer. */ | |
7396 | ||
7397 | layout_type (type); | |
7398 | ||
7399 | return value; | |
7400 | } | |
7401 | \f | |
7402 | /* Return zero if something is declared to be a member of type | |
7403 | CTYPE when in the context of CUR_TYPE. STRING is the error | |
7404 | message to print in that case. Otherwise, quietly return 1. */ | |
e92cc029 | 7405 | |
8d08fdba MS |
7406 | static int |
7407 | member_function_or_else (ctype, cur_type, string) | |
7408 | tree ctype, cur_type; | |
7409 | char *string; | |
7410 | { | |
7411 | if (ctype && ctype != cur_type) | |
7412 | { | |
7413 | error (string, TYPE_NAME_STRING (ctype)); | |
7414 | return 0; | |
7415 | } | |
7416 | return 1; | |
7417 | } | |
7418 | \f | |
7419 | /* Subroutine of `grokdeclarator'. */ | |
7420 | ||
7421 | /* Generate errors possibly applicable for a given set of specifiers. | |
7422 | This is for ARM $7.1.2. */ | |
e92cc029 | 7423 | |
8d08fdba MS |
7424 | static void |
7425 | bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) | |
7426 | tree object; | |
7427 | char *type; | |
7428 | int virtualp, quals, friendp, raises, inlinep; | |
7429 | { | |
7430 | if (virtualp) | |
7431 | cp_error ("`%D' declared as a `virtual' %s", object, type); | |
7432 | if (inlinep) | |
7433 | cp_error ("`%D' declared as an `inline' %s", object, type); | |
7434 | if (quals) | |
a28e3c7f MS |
7435 | cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", |
7436 | object, type); | |
8d08fdba MS |
7437 | if (friendp) |
7438 | cp_error_at ("invalid friend declaration", object); | |
7439 | if (raises) | |
6060a796 | 7440 | cp_error_at ("invalid exception specifications", object); |
8d08fdba MS |
7441 | } |
7442 | ||
7443 | /* CTYPE is class type, or null if non-class. | |
7444 | TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE | |
7445 | or METHOD_TYPE. | |
7446 | DECLARATOR is the function's name. | |
7447 | VIRTUALP is truthvalue of whether the function is virtual or not. | |
7448 | FLAGS are to be passed through to `grokclassfn'. | |
7449 | QUALS are qualifiers indicating whether the function is `const' | |
7450 | or `volatile'. | |
7451 | RAISES is a list of exceptions that this function can raise. | |
7452 | CHECK is 1 if we must find this method in CTYPE, 0 if we should | |
7453 | not look, and -1 if we should not call `grokclassfn' at all. */ | |
e92cc029 | 7454 | |
8d08fdba | 7455 | static tree |
386b8a85 JM |
7456 | grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, |
7457 | raises, attrlist, check, friendp, publicp, inlinep, funcdef_flag, | |
7458 | template_count) | |
8d08fdba MS |
7459 | tree ctype, type; |
7460 | tree declarator; | |
386b8a85 | 7461 | tree orig_declarator; |
8d08fdba MS |
7462 | int virtualp; |
7463 | enum overload_flags flags; | |
f30432d7 | 7464 | tree quals, raises, attrlist; |
386b8a85 | 7465 | int check, friendp, publicp, inlinep, funcdef_flag, template_count; |
8d08fdba MS |
7466 | { |
7467 | tree cname, decl; | |
7468 | int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; | |
42976354 | 7469 | tree t; |
8d08fdba MS |
7470 | |
7471 | if (ctype) | |
7472 | cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL | |
7473 | ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype); | |
7474 | else | |
7475 | cname = NULL_TREE; | |
7476 | ||
7477 | if (raises) | |
7478 | { | |
f30432d7 | 7479 | type = build_exception_variant (type, raises); |
8d08fdba | 7480 | } |
c11b6f21 | 7481 | |
8d08fdba MS |
7482 | decl = build_lang_decl (FUNCTION_DECL, declarator, type); |
7483 | /* propagate volatile out from type to decl */ | |
7484 | if (TYPE_VOLATILE (type)) | |
893de33c | 7485 | TREE_THIS_VOLATILE (decl) = 1; |
8d08fdba MS |
7486 | |
7487 | /* Should probably propagate const out from type to decl I bet (mrs). */ | |
7488 | if (staticp) | |
7489 | { | |
7490 | DECL_STATIC_FUNCTION_P (decl) = 1; | |
7491 | DECL_CONTEXT (decl) = ctype; | |
8d08fdba MS |
7492 | } |
7493 | ||
e76a2646 MS |
7494 | if (ctype) |
7495 | DECL_CLASS_CONTEXT (decl) = ctype; | |
7496 | ||
faae18ab MS |
7497 | if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main")) |
7498 | { | |
7499 | if (inlinep) | |
7500 | error ("cannot declare `main' to be inline"); | |
7501 | else if (! publicp) | |
7502 | error ("cannot declare `main' to be static"); | |
7503 | inlinep = 0; | |
7504 | publicp = 1; | |
7505 | } | |
7506 | ||
893de33c | 7507 | TREE_PUBLIC (decl) = publicp; |
faae18ab | 7508 | if (! publicp) |
893de33c JM |
7509 | { |
7510 | DECL_INTERFACE_KNOWN (decl) = 1; | |
7511 | DECL_NOT_REALLY_EXTERN (decl) = 1; | |
7512 | } | |
faae18ab MS |
7513 | |
7514 | if (inlinep) | |
7515 | DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1; | |
8d08fdba MS |
7516 | |
7517 | DECL_EXTERNAL (decl) = 1; | |
7518 | if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) | |
7519 | { | |
7520 | cp_error ("%smember function `%D' cannot have `%T' method qualifier", | |
7521 | (ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); | |
7522 | quals = NULL_TREE; | |
7523 | } | |
7524 | ||
7525 | if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) | |
7526 | grok_op_properties (decl, virtualp, check < 0); | |
7527 | ||
e76a2646 | 7528 | if (ctype && hack_decl_function_context (decl)) |
893de33c | 7529 | DECL_NO_STATIC_CHAIN (decl) = 1; |
e76a2646 | 7530 | |
42976354 BK |
7531 | for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t)) |
7532 | if (TREE_PURPOSE (t) | |
7533 | && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) | |
7534 | { | |
7535 | add_defarg_fn (decl); | |
7536 | break; | |
7537 | } | |
7538 | ||
75650646 MM |
7539 | if (friendp && |
7540 | TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR) | |
f84b4be9 JM |
7541 | { |
7542 | /* A friend declaration of the form friend void f<>(). Record | |
7543 | the information in the TEMPLATE_ID_EXPR. */ | |
7544 | SET_DECL_IMPLICIT_INSTANTIATION (decl); | |
7545 | DECL_TEMPLATE_INFO (decl) | |
7546 | = perm_tree_cons (TREE_OPERAND (orig_declarator, 0), | |
7547 | TREE_OPERAND (orig_declarator, 1), | |
7548 | NULL_TREE); | |
7549 | } | |
386b8a85 | 7550 | |
75650646 | 7551 | /* Caller will do the rest of this. */ |
8d08fdba MS |
7552 | if (check < 0) |
7553 | return decl; | |
7554 | ||
5566b478 | 7555 | if (check && funcdef_flag) |
d2e5ee5c | 7556 | DECL_INITIAL (decl) = error_mark_node; |
5566b478 | 7557 | |
8d08fdba MS |
7558 | if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) |
7559 | { | |
7560 | tree tmp; | |
7561 | /* Just handle constructors here. We could do this | |
7562 | inside the following if stmt, but I think | |
7563 | that the code is more legible by breaking this | |
7564 | case out. See comments below for what each of | |
7565 | the following calls is supposed to do. */ | |
7566 | DECL_CONSTRUCTOR_P (decl) = 1; | |
7567 | ||
7568 | grokclassfn (ctype, declarator, decl, flags, quals); | |
386b8a85 | 7569 | |
e1467ff2 MM |
7570 | decl = check_explicit_specialization (orig_declarator, decl, |
7571 | template_count, | |
f84b4be9 JM |
7572 | 2 * (funcdef_flag != 0) + |
7573 | 4 * (friendp != 0)); | |
75650646 | 7574 | |
8d08fdba | 7575 | if (check) |
5566b478 MS |
7576 | { |
7577 | tmp = check_classfn (ctype, decl); | |
98c1c668 JM |
7578 | |
7579 | if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) | |
7580 | tmp = DECL_TEMPLATE_RESULT(tmp); | |
7581 | ||
e349ee73 MS |
7582 | if (tmp && DECL_ARTIFICIAL (tmp)) |
7583 | cp_error ("definition of implicitly-declared `%D'", tmp); | |
5566b478 MS |
7584 | if (tmp && duplicate_decls (decl, tmp)) |
7585 | return tmp; | |
7586 | } | |
a0a33927 MS |
7587 | if (! grok_ctor_properties (ctype, decl)) |
7588 | return NULL_TREE; | |
7589 | ||
7177d104 | 7590 | if (check == 0 && ! current_function_decl) |
8d08fdba | 7591 | { |
30394414 | 7592 | /* assembler names live in the global namespace */ |
37c46b43 | 7593 | tmp = IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)); |
8d08fdba MS |
7594 | if (tmp == NULL_TREE) |
7595 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; | |
7596 | else if (TREE_CODE (tmp) != TREE_CODE (decl)) | |
7597 | cp_error ("inconsistent declarations for `%D'", decl); | |
7598 | else | |
7599 | { | |
7600 | duplicate_decls (decl, tmp); | |
7601 | decl = tmp; | |
7602 | /* avoid creating circularities. */ | |
7603 | DECL_CHAIN (decl) = NULL_TREE; | |
7604 | } | |
7605 | make_decl_rtl (decl, NULL_PTR, 1); | |
7606 | } | |
7607 | } | |
7608 | else | |
7609 | { | |
7610 | tree tmp; | |
7611 | ||
7612 | /* Function gets the ugly name, field gets the nice one. | |
7613 | This call may change the type of the function (because | |
7614 | of default parameters)! */ | |
7615 | if (ctype != NULL_TREE) | |
7616 | grokclassfn (ctype, cname, decl, flags, quals); | |
7617 | ||
e1467ff2 MM |
7618 | decl = check_explicit_specialization (orig_declarator, decl, |
7619 | template_count, | |
f84b4be9 JM |
7620 | 2 * (funcdef_flag != 0) + |
7621 | 4 * (friendp != 0)); | |
75650646 | 7622 | |
8d08fdba | 7623 | if (ctype != NULL_TREE && check) |
5566b478 MS |
7624 | { |
7625 | tmp = check_classfn (ctype, decl); | |
98c1c668 JM |
7626 | |
7627 | if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) | |
75650646 | 7628 | tmp = DECL_TEMPLATE_RESULT (tmp); |
98c1c668 | 7629 | |
5566b478 MS |
7630 | if (tmp && DECL_STATIC_FUNCTION_P (tmp) |
7631 | && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) | |
7632 | { | |
7633 | /* Remove the `this' parm added by grokclassfn. | |
7634 | XXX Isn't this done in start_function, too? */ | |
7635 | revert_static_member_fn (&decl, NULL, NULL); | |
7636 | last_function_parms = TREE_CHAIN (last_function_parms); | |
7637 | } | |
e349ee73 MS |
7638 | if (tmp && DECL_ARTIFICIAL (tmp)) |
7639 | cp_error ("definition of implicitly-declared `%D'", tmp); | |
7834ab39 MS |
7640 | if (tmp) |
7641 | { | |
7642 | if (!duplicate_decls (decl, tmp)) | |
7643 | my_friendly_abort (892); | |
7644 | return tmp; | |
7645 | } | |
5566b478 | 7646 | } |
8d08fdba MS |
7647 | |
7648 | if (ctype == NULL_TREE || check) | |
7649 | return decl; | |
7650 | ||
7177d104 MS |
7651 | /* Now install the declaration of this function so that others may |
7652 | find it (esp. its DECL_FRIENDLIST). Don't do this for local class | |
7653 | methods, though. */ | |
7654 | if (! current_function_decl) | |
8d08fdba | 7655 | { |
75650646 | 7656 | if (!DECL_TEMPLATE_SPECIALIZATION (decl)) |
7177d104 | 7657 | { |
75650646 MM |
7658 | /* We don't do this for specializations since the |
7659 | equivalent checks will be done later. Also, at this | |
7660 | point the DECL_ASSEMBLER_NAME is not yet fully | |
7661 | accurate. */ | |
7662 | ||
7663 | /* FIXME: this should only need to look at | |
7664 | IDENTIFIER_GLOBAL_VALUE. */ | |
7665 | tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); | |
7666 | if (tmp == NULL_TREE) | |
7667 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; | |
7668 | else if (TREE_CODE (tmp) != TREE_CODE (decl)) | |
7669 | cp_error ("inconsistent declarations for `%D'", decl); | |
7670 | else | |
7671 | { | |
7672 | duplicate_decls (decl, tmp); | |
7673 | decl = tmp; | |
7674 | /* avoid creating circularities. */ | |
7675 | DECL_CHAIN (decl) = NULL_TREE; | |
7676 | } | |
7177d104 | 7677 | } |
f30432d7 MS |
7678 | |
7679 | if (attrlist) | |
7680 | cplus_decl_attributes (decl, TREE_PURPOSE (attrlist), | |
7681 | TREE_VALUE (attrlist)); | |
7177d104 | 7682 | make_decl_rtl (decl, NULL_PTR, 1); |
8d08fdba | 7683 | } |
8d08fdba MS |
7684 | if (virtualp) |
7685 | { | |
2ee887f2 | 7686 | DECL_VIRTUAL_P (decl) = 1; |
8d08fdba MS |
7687 | if (DECL_VINDEX (decl) == NULL_TREE) |
7688 | DECL_VINDEX (decl) = error_mark_node; | |
7689 | IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; | |
8d08fdba MS |
7690 | } |
7691 | } | |
7692 | return decl; | |
7693 | } | |
7694 | ||
7695 | static tree | |
d2e5ee5c | 7696 | grokvardecl (type, declarator, specbits_in, initialized, constp) |
8d08fdba MS |
7697 | tree type; |
7698 | tree declarator; | |
d2e5ee5c | 7699 | RID_BIT_TYPE *specbits_in; |
8d08fdba | 7700 | int initialized; |
a9aedbc2 | 7701 | int constp; |
8d08fdba MS |
7702 | { |
7703 | tree decl; | |
f7da6097 MS |
7704 | RID_BIT_TYPE specbits; |
7705 | ||
7706 | specbits = *specbits_in; | |
8d08fdba MS |
7707 | |
7708 | if (TREE_CODE (type) == OFFSET_TYPE) | |
7709 | { | |
7710 | /* If you declare a static member so that it | |
7711 | can be initialized, the code will reach here. */ | |
5b605f68 MS |
7712 | tree basetype = TYPE_OFFSET_BASETYPE (type); |
7713 | type = TREE_TYPE (type); | |
7714 | decl = build_lang_field_decl (VAR_DECL, declarator, type); | |
7715 | DECL_CONTEXT (decl) = basetype; | |
7716 | DECL_CLASS_CONTEXT (decl) = basetype; | |
f376e137 | 7717 | DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator); |
8d08fdba MS |
7718 | } |
7719 | else | |
30394414 JM |
7720 | { |
7721 | decl = build_decl (VAR_DECL, declarator, complete_type (type)); | |
7722 | if (current_namespace != global_namespace) | |
7723 | DECL_ASSEMBLER_NAME (decl) = build_static_name (current_namespace, | |
7724 | declarator); | |
7725 | } | |
6060a796 | 7726 | |
8d08fdba MS |
7727 | if (RIDBIT_SETP (RID_EXTERN, specbits)) |
7728 | { | |
7729 | DECL_THIS_EXTERN (decl) = 1; | |
7730 | DECL_EXTERNAL (decl) = !initialized; | |
7731 | } | |
7732 | ||
7733 | /* In class context, static means one per class, | |
7734 | public access, and static storage. */ | |
7735 | if (DECL_FIELD_CONTEXT (decl) != NULL_TREE | |
7736 | && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl))) | |
7737 | { | |
7738 | TREE_PUBLIC (decl) = 1; | |
7739 | TREE_STATIC (decl) = 1; | |
5b605f68 | 7740 | DECL_EXTERNAL (decl) = 0; |
8d08fdba MS |
7741 | } |
7742 | /* At top level, either `static' or no s.c. makes a definition | |
7743 | (perhaps tentative), and absence of `static' makes it public. */ | |
a9aedbc2 | 7744 | else if (toplevel_bindings_p ()) |
8d08fdba | 7745 | { |
a9aedbc2 | 7746 | TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits) |
9fffd093 | 7747 | && (DECL_THIS_EXTERN (decl) || ! constp)); |
8d08fdba MS |
7748 | TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); |
7749 | } | |
7750 | /* Not at top level, only `static' makes a static definition. */ | |
7751 | else | |
7752 | { | |
7753 | TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits); | |
7754 | TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); | |
7755 | } | |
7756 | return decl; | |
7757 | } | |
7758 | ||
e92cc029 | 7759 | /* Create a canonical pointer to member function type. */ |
8d08fdba MS |
7760 | |
7761 | tree | |
7762 | build_ptrmemfunc_type (type) | |
7763 | tree type; | |
7764 | { | |
7765 | tree fields[4]; | |
7766 | tree t; | |
7767 | tree u; | |
7768 | ||
7769 | /* If a canonical type already exists for this type, use it. We use | |
7770 | this method instead of type_hash_canon, because it only does a | |
7771 | simple equality check on the list of field members. */ | |
7772 | ||
7773 | if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type))) | |
7774 | return t; | |
7775 | ||
7776 | push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); | |
7777 | ||
7778 | u = make_lang_type (UNION_TYPE); | |
f30432d7 | 7779 | IS_AGGR_TYPE (u) = 0; |
8d08fdba | 7780 | fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type); |
a28e3c7f MS |
7781 | fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, |
7782 | delta_type_node); | |
8d08fdba MS |
7783 | finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node); |
7784 | TYPE_NAME (u) = NULL_TREE; | |
7785 | ||
7786 | t = make_lang_type (RECORD_TYPE); | |
7787 | ||
e92cc029 | 7788 | /* Let the front-end know this is a pointer to member function. */ |
db5ae43f | 7789 | TYPE_PTRMEMFUNC_FLAG (t) = 1; |
f376e137 MS |
7790 | /* and not really an aggregate. */ |
7791 | IS_AGGR_TYPE (t) = 0; | |
8d08fdba | 7792 | |
a28e3c7f MS |
7793 | fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, |
7794 | delta_type_node); | |
7795 | fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, | |
7796 | delta_type_node); | |
8d08fdba MS |
7797 | fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u); |
7798 | finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node); | |
7799 | ||
7800 | pop_obstacks (); | |
7801 | ||
7802 | /* Zap out the name so that the back-end will give us the debugging | |
7803 | information for this anonymous RECORD_TYPE. */ | |
7804 | TYPE_NAME (t) = NULL_TREE; | |
7805 | ||
7806 | TYPE_SET_PTRMEMFUNC_TYPE (type, t); | |
7807 | ||
e92cc029 | 7808 | /* Seems to be wanted. */ |
8d08fdba MS |
7809 | CLASSTYPE_GOT_SEMICOLON (t) = 1; |
7810 | return t; | |
7811 | } | |
7812 | ||
7813 | /* Given declspecs and a declarator, | |
7814 | determine the name and type of the object declared | |
7815 | and construct a ..._DECL node for it. | |
7816 | (In one case we can return a ..._TYPE node instead. | |
7817 | For invalid input we sometimes return 0.) | |
7818 | ||
7819 | DECLSPECS is a chain of tree_list nodes whose value fields | |
7820 | are the storage classes and type specifiers. | |
7821 | ||
7822 | DECL_CONTEXT says which syntactic context this declaration is in: | |
7823 | NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. | |
7824 | FUNCDEF for a function definition. Like NORMAL but a few different | |
7825 | error messages in each case. Return value may be zero meaning | |
7826 | this definition is too screwy to try to parse. | |
7827 | MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to | |
7828 | handle member functions (which have FIELD context). | |
7829 | Return value may be zero meaning this definition is too screwy to | |
7830 | try to parse. | |
7831 | PARM for a parameter declaration (either within a function prototype | |
7832 | or before a function body). Make a PARM_DECL, or return void_type_node. | |
db5ae43f | 7833 | CATCHPARM for a parameter declaration before a catch clause. |
8d08fdba MS |
7834 | TYPENAME if for a typename (in a cast or sizeof). |
7835 | Don't make a DECL node; just return the ..._TYPE node. | |
7836 | FIELD for a struct or union field; make a FIELD_DECL. | |
7837 | BITFIELD for a field with specified width. | |
7838 | INITIALIZED is 1 if the decl has an initializer. | |
7839 | ||
7840 | In the TYPENAME case, DECLARATOR is really an absolute declarator. | |
7841 | It may also be so in the PARM case, for a prototype where the | |
7842 | argument type is specified but not the name. | |
7843 | ||
7844 | This function is where the complicated C meanings of `static' | |
7845 | and `extern' are interpreted. | |
7846 | ||
7847 | For C++, if there is any monkey business to do, the function which | |
7848 | calls this one must do it, i.e., prepending instance variables, | |
7849 | renaming overloaded function names, etc. | |
7850 | ||
7851 | Note that for this C++, it is an error to define a method within a class | |
7852 | which does not belong to that class. | |
7853 | ||
7854 | Except in the case where SCOPE_REFs are implicitly known (such as | |
7855 | methods within a class being redundantly qualified), | |
7856 | declarations which involve SCOPE_REFs are returned as SCOPE_REFs | |
7857 | (class_name::decl_name). The caller must also deal with this. | |
7858 | ||
7859 | If a constructor or destructor is seen, and the context is FIELD, | |
7860 | then the type gains the attribute TREE_HAS_x. If such a declaration | |
7861 | is erroneous, NULL_TREE is returned. | |
7862 | ||
7863 | QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member | |
7864 | function, these are the qualifiers to give to the `this' pointer. | |
7865 | ||
7866 | May return void_type_node if the declarator turned out to be a friend. | |
7867 | See grokfield for details. */ | |
7868 | ||
7869 | enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; | |
7870 | ||
7871 | tree | |
c11b6f21 | 7872 | grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) |
8d08fdba MS |
7873 | tree declspecs; |
7874 | tree declarator; | |
7875 | enum decl_context decl_context; | |
7876 | int initialized; | |
c11b6f21 | 7877 | tree attrlist; |
8d08fdba MS |
7878 | { |
7879 | RID_BIT_TYPE specbits; | |
7880 | int nclasses = 0; | |
7881 | tree spec; | |
7882 | tree type = NULL_TREE; | |
7883 | int longlong = 0; | |
7884 | int constp; | |
7885 | int volatilep; | |
db5ae43f | 7886 | int virtualp, explicitp, friendp, inlinep, staticp; |
8d08fdba MS |
7887 | int explicit_int = 0; |
7888 | int explicit_char = 0; | |
37c46b43 | 7889 | int defaulted_int = 0; |
8d08fdba MS |
7890 | int opaque_typedef = 0; |
7891 | tree typedef_decl = NULL_TREE; | |
7892 | char *name; | |
7893 | tree typedef_type = NULL_TREE; | |
7894 | int funcdef_flag = 0; | |
7895 | enum tree_code innermost_code = ERROR_MARK; | |
7896 | int bitfield = 0; | |
6125f3be DE |
7897 | #if 0 |
7898 | /* See the code below that used this. */ | |
f6abb50a | 7899 | tree decl_machine_attr = NULL_TREE; |
6125f3be | 7900 | #endif |
8d08fdba MS |
7901 | /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. |
7902 | All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ | |
7903 | tree init = NULL_TREE; | |
7904 | ||
7905 | /* Keep track of what sort of function is being processed | |
7906 | so that we can warn about default return values, or explicit | |
7907 | return values which do not match prescribed defaults. */ | |
7908 | enum return_types return_type = return_normal; | |
7909 | ||
7910 | tree dname = NULL_TREE; | |
7911 | tree ctype = current_class_type; | |
7912 | tree ctor_return_type = NULL_TREE; | |
7913 | enum overload_flags flags = NO_SPECIAL; | |
8d08fdba | 7914 | tree quals = NULL_TREE; |
c11b6f21 | 7915 | tree raises = NULL_TREE; |
386b8a85 | 7916 | int template_count = 0; |
8d08fdba MS |
7917 | |
7918 | RIDBIT_RESET_ALL (specbits); | |
7919 | if (decl_context == FUNCDEF) | |
7920 | funcdef_flag = 1, decl_context = NORMAL; | |
7921 | else if (decl_context == MEMFUNCDEF) | |
7922 | funcdef_flag = -1, decl_context = FIELD; | |
7923 | else if (decl_context == BITFIELD) | |
7924 | bitfield = 1, decl_context = FIELD; | |
7925 | ||
8d08fdba MS |
7926 | /* Look inside a declarator for the name being declared |
7927 | and get it as a string, for an error message. */ | |
7928 | { | |
be99da77 MS |
7929 | tree *next = &declarator; |
7930 | register tree decl; | |
8d08fdba MS |
7931 | name = NULL; |
7932 | ||
be99da77 MS |
7933 | while (next && *next) |
7934 | { | |
7935 | decl = *next; | |
7936 | switch (TREE_CODE (decl)) | |
8d08fdba | 7937 | { |
be99da77 MS |
7938 | case COND_EXPR: |
7939 | ctype = NULL_TREE; | |
7940 | next = &TREE_OPERAND (decl, 0); | |
7941 | break; | |
8d08fdba | 7942 | |
be99da77 | 7943 | case BIT_NOT_EXPR: /* for C++ destructors! */ |
8d08fdba | 7944 | { |
be99da77 MS |
7945 | tree name = TREE_OPERAND (decl, 0); |
7946 | tree rename = NULL_TREE; | |
7947 | ||
7948 | my_friendly_assert (flags == NO_SPECIAL, 152); | |
7949 | flags = DTOR_FLAG; | |
7950 | return_type = return_dtor; | |
5566b478 MS |
7951 | if (TREE_CODE (name) == TYPE_DECL) |
7952 | TREE_OPERAND (decl, 0) = name = constructor_name (name); | |
be99da77 MS |
7953 | my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); |
7954 | if (ctype == NULL_TREE) | |
7955 | { | |
7956 | if (current_class_type == NULL_TREE) | |
7957 | { | |
7958 | error ("destructors must be member functions"); | |
7959 | flags = NO_SPECIAL; | |
7960 | } | |
7961 | else | |
7962 | { | |
7963 | tree t = constructor_name (current_class_name); | |
7964 | if (t != name) | |
7965 | rename = t; | |
7966 | } | |
7967 | } | |
8d08fdba | 7968 | else |
be99da77 MS |
7969 | { |
7970 | tree t = constructor_name (ctype); | |
7971 | if (t != name) | |
7972 | rename = t; | |
7973 | } | |
51c184be | 7974 | |
be99da77 | 7975 | if (rename) |
39211cd5 | 7976 | { |
5566b478 MS |
7977 | cp_error ("destructor `%T' must match class name `%T'", |
7978 | name, rename); | |
be99da77 | 7979 | TREE_OPERAND (decl, 0) = rename; |
39211cd5 | 7980 | } |
be99da77 | 7981 | next = &name; |
51c184be | 7982 | } |
be99da77 | 7983 | break; |
8d08fdba | 7984 | |
be99da77 MS |
7985 | case ADDR_EXPR: /* C++ reference declaration */ |
7986 | /* fall through */ | |
7987 | case ARRAY_REF: | |
7988 | case INDIRECT_REF: | |
7989 | ctype = NULL_TREE; | |
7990 | innermost_code = TREE_CODE (decl); | |
7991 | next = &TREE_OPERAND (decl, 0); | |
7992 | break; | |
8d08fdba | 7993 | |
be99da77 MS |
7994 | case CALL_EXPR: |
7995 | if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) | |
8d08fdba | 7996 | { |
be99da77 MS |
7997 | /* This is actually a variable declaration using constructor |
7998 | syntax. We need to call start_decl and cp_finish_decl so we | |
7999 | can get the variable initialized... */ | |
8000 | ||
8001 | *next = TREE_OPERAND (decl, 0); | |
8002 | init = TREE_OPERAND (decl, 1); | |
8003 | ||
c11b6f21 | 8004 | decl = start_decl (declarator, declspecs, 1); |
249555b0 BK |
8005 | /* Look for __unused__ attribute */ |
8006 | if (TREE_USED (TREE_TYPE (decl))) | |
8007 | TREE_USED (decl) = 1; | |
be99da77 MS |
8008 | finish_decl (decl, init, NULL_TREE); |
8009 | return 0; | |
8d08fdba | 8010 | } |
be99da77 MS |
8011 | innermost_code = TREE_CODE (decl); |
8012 | if (decl_context == FIELD && ctype == NULL_TREE) | |
8013 | ctype = current_class_type; | |
45537677 | 8014 | if (ctype |
c11b6f21 | 8015 | && TREE_OPERAND (decl, 0) |
45537677 MS |
8016 | && (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL |
8017 | && ((DECL_NAME (TREE_OPERAND (decl, 0)) | |
8018 | == constructor_name_full (ctype)) | |
8019 | || (DECL_NAME (TREE_OPERAND (decl, 0)) | |
8020 | == constructor_name (ctype))))) | |
be99da77 MS |
8021 | TREE_OPERAND (decl, 0) = constructor_name (ctype); |
8022 | next = &TREE_OPERAND (decl, 0); | |
8023 | decl = *next; | |
8024 | if (ctype != NULL_TREE | |
8025 | && decl != NULL_TREE && flags != DTOR_FLAG | |
8026 | && decl == constructor_name (ctype)) | |
8d08fdba | 8027 | { |
be99da77 MS |
8028 | return_type = return_ctor; |
8029 | ctor_return_type = ctype; | |
8d08fdba | 8030 | } |
be99da77 MS |
8031 | ctype = NULL_TREE; |
8032 | break; | |
386b8a85 JM |
8033 | |
8034 | case TEMPLATE_ID_EXPR: | |
8035 | { | |
8036 | tree fns = TREE_OPERAND (decl, 0); | |
8037 | ||
8038 | if (TREE_CODE (fns) == LOOKUP_EXPR) | |
8039 | fns = TREE_OPERAND (fns, 0); | |
8040 | ||
8041 | if (TREE_CODE (fns) == IDENTIFIER_NODE) | |
8042 | dname = fns; | |
f84b4be9 | 8043 | else if (is_overloaded_fn (fns)) |
386b8a85 JM |
8044 | dname = DECL_NAME (get_first_fn (fns)); |
8045 | else | |
f84b4be9 | 8046 | my_friendly_abort (0); |
386b8a85 JM |
8047 | } |
8048 | /* fall through */ | |
be99da77 MS |
8049 | |
8050 | case IDENTIFIER_NODE: | |
386b8a85 JM |
8051 | if (TREE_CODE (decl) == IDENTIFIER_NODE) |
8052 | dname = decl; | |
8053 | ||
be99da77 MS |
8054 | next = 0; |
8055 | ||
8056 | if (is_rid (dname)) | |
8d08fdba | 8057 | { |
be99da77 MS |
8058 | cp_error ("declarator-id missing; using reserved word `%D'", |
8059 | dname); | |
8060 | name = IDENTIFIER_POINTER (dname); | |
8d08fdba | 8061 | } |
be99da77 | 8062 | if (! IDENTIFIER_OPNAME_P (dname) |
956d6950 | 8063 | /* GNU/Linux headers use '__op'. Arrgh. */ |
a703fb38 | 8064 | || (IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))) |
be99da77 | 8065 | name = IDENTIFIER_POINTER (dname); |
8d08fdba MS |
8066 | else |
8067 | { | |
be99da77 | 8068 | if (IDENTIFIER_TYPENAME_P (dname)) |
8d08fdba | 8069 | { |
be99da77 MS |
8070 | my_friendly_assert (flags == NO_SPECIAL, 154); |
8071 | flags = TYPENAME_FLAG; | |
8072 | ctor_return_type = TREE_TYPE (dname); | |
8073 | return_type = return_conversion; | |
8d08fdba | 8074 | } |
be99da77 | 8075 | name = operator_name_string (dname); |
8d08fdba | 8076 | } |
be99da77 | 8077 | break; |
8d08fdba | 8078 | |
be99da77 MS |
8079 | /* C++ extension */ |
8080 | case SCOPE_REF: | |
8081 | { | |
8082 | /* Perform error checking, and decide on a ctype. */ | |
8083 | tree cname = TREE_OPERAND (decl, 0); | |
8084 | if (cname == NULL_TREE) | |
8085 | ctype = NULL_TREE; | |
8086 | else if (! is_aggr_type (cname, 1)) | |
8087 | TREE_OPERAND (decl, 0) = NULL_TREE; | |
8088 | /* Must test TREE_OPERAND (decl, 1), in case user gives | |
8089 | us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ | |
8090 | else if (TREE_OPERAND (decl, 1) | |
8091 | && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) | |
8092 | ctype = cname; | |
73b0fce8 KL |
8093 | else if (TREE_CODE (cname) == TEMPLATE_TYPE_PARM |
8094 | || TREE_CODE (cname) == TEMPLATE_TEMPLATE_PARM) | |
5566b478 MS |
8095 | { |
8096 | cp_error ("`%T::%D' is not a valid declarator", cname, | |
8097 | TREE_OPERAND (decl, 1)); | |
8098 | cp_error (" perhaps you want `typename %T::%D' to make it a type", | |
8099 | cname, TREE_OPERAND (decl, 1)); | |
8100 | return void_type_node; | |
8101 | } | |
be99da77 MS |
8102 | else if (ctype == NULL_TREE) |
8103 | ctype = cname; | |
8104 | else if (TREE_COMPLEXITY (decl) == current_class_depth) | |
8105 | TREE_OPERAND (decl, 0) = ctype; | |
8106 | else | |
8107 | { | |
8108 | if (! UNIQUELY_DERIVED_FROM_P (cname, ctype)) | |
8109 | { | |
8110 | cp_error ("type `%T' is not derived from type `%T'", | |
8111 | cname, ctype); | |
8112 | TREE_OPERAND (decl, 0) = NULL_TREE; | |
8113 | } | |
8114 | else | |
8115 | ctype = cname; | |
8116 | } | |
8117 | ||
c91a56d2 MS |
8118 | if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL |
8119 | && ((DECL_NAME (TREE_OPERAND (decl, 1)) | |
8120 | == constructor_name_full (ctype)) | |
8121 | || (DECL_NAME (TREE_OPERAND (decl, 1)) | |
8122 | == constructor_name (ctype)))) | |
be99da77 MS |
8123 | TREE_OPERAND (decl, 1) = constructor_name (ctype); |
8124 | next = &TREE_OPERAND (decl, 1); | |
8125 | decl = *next; | |
8126 | if (ctype) | |
8127 | { | |
8128 | if (TREE_CODE (decl) == IDENTIFIER_NODE | |
8129 | && constructor_name (ctype) == decl) | |
8130 | { | |
8131 | return_type = return_ctor; | |
8132 | ctor_return_type = ctype; | |
8133 | } | |
8134 | else if (TREE_CODE (decl) == BIT_NOT_EXPR | |
8135 | && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE | |
8136 | && (constructor_name (ctype) == TREE_OPERAND (decl, 0) | |
8137 | || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) | |
8138 | { | |
8139 | return_type = return_dtor; | |
8140 | ctor_return_type = ctype; | |
8141 | flags = DTOR_FLAG; | |
8142 | TREE_OPERAND (decl, 0) = constructor_name (ctype); | |
8143 | next = &TREE_OPERAND (decl, 0); | |
8144 | } | |
8145 | } | |
8146 | } | |
8147 | break; | |
8148 | ||
8149 | case ERROR_MARK: | |
8150 | next = 0; | |
8151 | break; | |
8152 | ||
45537677 MS |
8153 | case TYPE_DECL: |
8154 | /* Parse error puts this typespec where | |
8155 | a declarator should go. */ | |
8156 | cp_error ("`%T' specified as declarator-id", DECL_NAME (decl)); | |
8157 | if (TREE_TYPE (decl) == current_class_type) | |
8158 | cp_error (" perhaps you want `%T' for a constructor", | |
8159 | current_class_name); | |
8160 | dname = DECL_NAME (decl); | |
8161 | name = IDENTIFIER_POINTER (dname); | |
8162 | ||
e92cc029 | 8163 | /* Avoid giving two errors for this. */ |
45537677 MS |
8164 | IDENTIFIER_CLASS_VALUE (dname) = NULL_TREE; |
8165 | ||
8166 | declspecs = temp_tree_cons (NULL_TREE, integer_type_node, | |
8167 | declspecs); | |
8168 | *next = dname; | |
8169 | next = 0; | |
8170 | break; | |
8171 | ||
be99da77 | 8172 | default: |
be99da77 MS |
8173 | cp_compiler_error ("`%D' as declarator", decl); |
8174 | return 0; /* We used to do a 155 abort here. */ | |
8d08fdba | 8175 | } |
be99da77 | 8176 | } |
8d08fdba MS |
8177 | if (name == NULL) |
8178 | name = "type name"; | |
8179 | } | |
8180 | ||
8181 | /* A function definition's declarator must have the form of | |
8182 | a function declarator. */ | |
8183 | ||
8184 | if (funcdef_flag && innermost_code != CALL_EXPR) | |
8185 | return 0; | |
8186 | ||
e1cd6e56 MS |
8187 | if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG) |
8188 | && innermost_code != CALL_EXPR | |
8189 | && ! (ctype && declspecs == NULL_TREE)) | |
8190 | { | |
8191 | cp_error ("declaration of `%D' as non-function", dname); | |
8192 | return void_type_node; | |
8193 | } | |
8194 | ||
8d08fdba MS |
8195 | /* Anything declared one level down from the top level |
8196 | must be one of the parameters of a function | |
8197 | (because the body is at least two levels down). */ | |
8198 | ||
8199 | /* This heuristic cannot be applied to C++ nodes! Fixed, however, | |
8200 | by not allowing C++ class definitions to specify their parameters | |
8201 | with xdecls (must be spec.d in the parmlist). | |
8202 | ||
8203 | Since we now wait to push a class scope until we are sure that | |
8204 | we are in a legitimate method context, we must set oldcname | |
a9aedbc2 MS |
8205 | explicitly (since current_class_name is not yet alive). |
8206 | ||
8207 | We also want to avoid calling this a PARM if it is in a namespace. */ | |
8d08fdba | 8208 | |
5566b478 MS |
8209 | if (decl_context == NORMAL && ! namespace_bindings_p () |
8210 | && ! pseudo_global_level_p ()) | |
a9aedbc2 MS |
8211 | { |
8212 | struct binding_level *b = current_binding_level; | |
8213 | current_binding_level = b->level_chain; | |
8214 | if (current_binding_level != 0 && toplevel_bindings_p ()) | |
8215 | decl_context = PARM; | |
8216 | current_binding_level = b; | |
8217 | } | |
8d08fdba MS |
8218 | |
8219 | /* Look through the decl specs and record which ones appear. | |
8220 | Some typespecs are defined as built-in typenames. | |
8221 | Others, the ones that are modifiers of other types, | |
8222 | are represented by bits in SPECBITS: set the bits for | |
8223 | the modifiers that appear. Storage class keywords are also in SPECBITS. | |
8224 | ||
8225 | If there is a typedef name or a type, store the type in TYPE. | |
8226 | This includes builtin typedefs such as `int'. | |
8227 | ||
8228 | Set EXPLICIT_INT if the type is `int' or `char' and did not | |
8229 | come from a user typedef. | |
8230 | ||
8231 | Set LONGLONG if `long' is mentioned twice. | |
8232 | ||
8233 | For C++, constructors and destructors have their own fast treatment. */ | |
8234 | ||
8235 | for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) | |
8236 | { | |
8237 | register int i; | |
8238 | register tree id; | |
8239 | ||
8240 | /* Certain parse errors slip through. For example, | |
8241 | `int class;' is not caught by the parser. Try | |
8242 | weakly to recover here. */ | |
8243 | if (TREE_CODE (spec) != TREE_LIST) | |
8244 | return 0; | |
8245 | ||
8246 | id = TREE_VALUE (spec); | |
8247 | ||
8248 | if (TREE_CODE (id) == IDENTIFIER_NODE) | |
8249 | { | |
a3203465 MS |
8250 | if (id == ridpointers[(int) RID_INT] |
8251 | || id == ridpointers[(int) RID_CHAR] | |
8252 | || id == ridpointers[(int) RID_BOOL] | |
8253 | || id == ridpointers[(int) RID_WCHAR]) | |
8d08fdba MS |
8254 | { |
8255 | if (type) | |
8ccc31eb MS |
8256 | { |
8257 | if (id == ridpointers[(int) RID_BOOL]) | |
8258 | error ("`bool' is now a keyword"); | |
8259 | else | |
8260 | cp_error ("extraneous `%T' ignored", id); | |
8261 | } | |
8d08fdba MS |
8262 | else |
8263 | { | |
a3203465 MS |
8264 | if (id == ridpointers[(int) RID_INT]) |
8265 | explicit_int = 1; | |
8266 | else if (id == ridpointers[(int) RID_CHAR]) | |
8267 | explicit_char = 1; | |
8d08fdba MS |
8268 | type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); |
8269 | } | |
8270 | goto found; | |
8271 | } | |
e92cc029 | 8272 | /* C++ aggregate types. */ |
8d08fdba MS |
8273 | if (IDENTIFIER_HAS_TYPE_VALUE (id)) |
8274 | { | |
8275 | if (type) | |
8276 | cp_error ("multiple declarations `%T' and `%T'", type, id); | |
8277 | else | |
8278 | type = IDENTIFIER_TYPE_VALUE (id); | |
8279 | goto found; | |
8280 | } | |
8281 | ||
f376e137 | 8282 | for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++) |
8d08fdba MS |
8283 | { |
8284 | if (ridpointers[i] == id) | |
8285 | { | |
8286 | if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) | |
8287 | { | |
e1cd6e56 MS |
8288 | if (pedantic && ! in_system_header) |
8289 | pedwarn ("ANSI C++ does not support `long long'"); | |
9a3b49ac | 8290 | if (longlong) |
a0a33927 | 8291 | error ("`long long long' is too long for GCC"); |
8d08fdba MS |
8292 | else |
8293 | longlong = 1; | |
8294 | } | |
8295 | else if (RIDBIT_SETP (i, specbits)) | |
a0a33927 | 8296 | pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); |
8d08fdba MS |
8297 | RIDBIT_SET (i, specbits); |
8298 | goto found; | |
8299 | } | |
8300 | } | |
8301 | } | |
e92cc029 | 8302 | /* C++ aggregate types. */ |
73b0fce8 | 8303 | else if (TREE_CODE (id) == TYPE_DECL || TREE_CODE (id) == TEMPLATE_DECL) |
45537677 MS |
8304 | { |
8305 | if (type) | |
8306 | cp_error ("multiple declarations `%T' and `%T'", type, | |
8307 | TREE_TYPE (id)); | |
8308 | else | |
5566b478 MS |
8309 | { |
8310 | type = TREE_TYPE (id); | |
8311 | TREE_VALUE (spec) = type; | |
8312 | } | |
45537677 MS |
8313 | goto found; |
8314 | } | |
8d08fdba MS |
8315 | if (type) |
8316 | error ("two or more data types in declaration of `%s'", name); | |
8317 | else if (TREE_CODE (id) == IDENTIFIER_NODE) | |
8318 | { | |
8319 | register tree t = lookup_name (id, 1); | |
8320 | if (!t || TREE_CODE (t) != TYPE_DECL) | |
8321 | error ("`%s' fails to be a typedef or built in type", | |
8322 | IDENTIFIER_POINTER (id)); | |
8323 | else | |
8324 | { | |
8325 | type = TREE_TYPE (t); | |
6125f3be DE |
8326 | #if 0 |
8327 | /* See the code below that used this. */ | |
f6abb50a | 8328 | decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); |
6125f3be | 8329 | #endif |
8d08fdba MS |
8330 | typedef_decl = t; |
8331 | } | |
8332 | } | |
bd6dd845 | 8333 | else if (id != error_mark_node) |
8d08fdba MS |
8334 | /* Can't change CLASS nodes into RECORD nodes here! */ |
8335 | type = id; | |
8336 | ||
8337 | found: ; | |
8338 | } | |
8339 | ||
8340 | typedef_type = type; | |
8341 | ||
37c46b43 | 8342 | /* No type at all: default to `int', and set DEFAULTED_INT |
8d08fdba MS |
8343 | because it was not a user-defined typedef. |
8344 | Except when we have a `typedef' inside a signature, in | |
8345 | which case the type defaults to `unknown type' and is | |
8346 | instantiated when assigning to a signature pointer or ref. */ | |
8347 | ||
a3203465 MS |
8348 | if (type == NULL_TREE |
8349 | && (RIDBIT_SETP (RID_SIGNED, specbits) | |
8350 | || RIDBIT_SETP (RID_UNSIGNED, specbits) | |
8351 | || RIDBIT_SETP (RID_LONG, specbits) | |
8352 | || RIDBIT_SETP (RID_SHORT, specbits))) | |
8353 | { | |
8354 | /* These imply 'int'. */ | |
8355 | type = integer_type_node; | |
37c46b43 | 8356 | defaulted_int = 1; |
a3203465 MS |
8357 | } |
8358 | ||
8d08fdba MS |
8359 | if (type == NULL_TREE) |
8360 | { | |
8361 | explicit_int = -1; | |
8362 | if (return_type == return_dtor) | |
8363 | type = void_type_node; | |
8364 | else if (return_type == return_ctor) | |
f30432d7 | 8365 | type = build_pointer_type (ctor_return_type); |
51c184be MS |
8366 | else if (return_type == return_conversion) |
8367 | type = ctor_return_type; | |
8d08fdba MS |
8368 | else if (current_class_type |
8369 | && IS_SIGNATURE (current_class_type) | |
fc378698 | 8370 | && RIDBIT_SETP (RID_TYPEDEF, specbits) |
8d08fdba MS |
8371 | && (decl_context == FIELD || decl_context == NORMAL)) |
8372 | { | |
8373 | explicit_int = 0; | |
8374 | opaque_typedef = 1; | |
8375 | type = copy_node (opaque_type_node); | |
8376 | } | |
8377 | else | |
8378 | { | |
a28e3c7f MS |
8379 | if (funcdef_flag) |
8380 | { | |
8381 | if (warn_return_type | |
a3203465 | 8382 | && return_type == return_normal) |
a28e3c7f MS |
8383 | /* Save warning until we know what is really going on. */ |
8384 | warn_about_return_type = 1; | |
8385 | } | |
a3203465 MS |
8386 | else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) |
8387 | pedwarn ("ANSI C++ forbids typedef which does not specify a type"); | |
343fdf03 JM |
8388 | else if (innermost_code != CALL_EXPR || pedantic |
8389 | || (warn_return_type && return_type == return_normal)) | |
8390 | { | |
8391 | if (innermost_code == CALL_EXPR) | |
8392 | cp_pedwarn ("return-type of `%D' defaults to `int'", dname); | |
8393 | else | |
8394 | cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type", | |
8395 | dname); | |
8396 | } | |
8d08fdba MS |
8397 | type = integer_type_node; |
8398 | } | |
8399 | } | |
8400 | else if (return_type == return_dtor) | |
8401 | { | |
8402 | error ("return type specification for destructor invalid"); | |
8403 | type = void_type_node; | |
8404 | } | |
8405 | else if (return_type == return_ctor) | |
8406 | { | |
8407 | error ("return type specification for constructor invalid"); | |
f30432d7 | 8408 | type = build_pointer_type (ctor_return_type); |
8d08fdba | 8409 | } |
51c184be MS |
8410 | else if (return_type == return_conversion) |
8411 | { | |
e1cd6e56 | 8412 | if (comptypes (type, ctor_return_type, 1) == 0) |
51c184be MS |
8413 | cp_error ("operator `%T' declared to return `%T'", |
8414 | ctor_return_type, type); | |
8415 | else | |
8416 | cp_pedwarn ("return type specified for `operator %T'", | |
8417 | ctor_return_type); | |
8418 | ||
8419 | type = ctor_return_type; | |
8420 | } | |
8d08fdba MS |
8421 | |
8422 | ctype = NULL_TREE; | |
8423 | ||
8424 | /* Now process the modifiers that were specified | |
8425 | and check for invalid combinations. */ | |
8426 | ||
8427 | /* Long double is a special combination. */ | |
8428 | ||
8429 | if (RIDBIT_SETP (RID_LONG, specbits) | |
8430 | && TYPE_MAIN_VARIANT (type) == double_type_node) | |
8431 | { | |
8432 | RIDBIT_RESET (RID_LONG, specbits); | |
8433 | type = build_type_variant (long_double_type_node, TYPE_READONLY (type), | |
8434 | TYPE_VOLATILE (type)); | |
8435 | } | |
8436 | ||
8437 | /* Check all other uses of type modifiers. */ | |
8438 | ||
8439 | if (RIDBIT_SETP (RID_UNSIGNED, specbits) | |
8440 | || RIDBIT_SETP (RID_SIGNED, specbits) | |
8441 | || RIDBIT_SETP (RID_LONG, specbits) | |
8442 | || RIDBIT_SETP (RID_SHORT, specbits)) | |
8443 | { | |
8444 | int ok = 0; | |
8445 | ||
8446 | if (TREE_CODE (type) == REAL_TYPE) | |
8447 | error ("short, signed or unsigned invalid for `%s'", name); | |
b7484fbe | 8448 | else if (TREE_CODE (type) != INTEGER_TYPE) |
8d08fdba MS |
8449 | error ("long, short, signed or unsigned invalid for `%s'", name); |
8450 | else if (RIDBIT_SETP (RID_LONG, specbits) | |
8451 | && RIDBIT_SETP (RID_SHORT, specbits)) | |
8452 | error ("long and short specified together for `%s'", name); | |
8453 | else if ((RIDBIT_SETP (RID_LONG, specbits) | |
8454 | || RIDBIT_SETP (RID_SHORT, specbits)) | |
8455 | && explicit_char) | |
8456 | error ("long or short specified with char for `%s'", name); | |
8457 | else if ((RIDBIT_SETP (RID_LONG, specbits) | |
8458 | || RIDBIT_SETP (RID_SHORT, specbits)) | |
8459 | && TREE_CODE (type) == REAL_TYPE) | |
8460 | error ("long or short specified with floating type for `%s'", name); | |
8461 | else if (RIDBIT_SETP (RID_SIGNED, specbits) | |
8462 | && RIDBIT_SETP (RID_UNSIGNED, specbits)) | |
8463 | error ("signed and unsigned given together for `%s'", name); | |
8464 | else | |
8465 | { | |
8466 | ok = 1; | |
37c46b43 | 8467 | if (!explicit_int && !defaulted_int && !explicit_char && pedantic) |
8d08fdba MS |
8468 | { |
8469 | pedwarn ("long, short, signed or unsigned used invalidly for `%s'", | |
8470 | name); | |
8471 | if (flag_pedantic_errors) | |
8472 | ok = 0; | |
8473 | } | |
8474 | } | |
8475 | ||
8476 | /* Discard the type modifiers if they are invalid. */ | |
8477 | if (! ok) | |
8478 | { | |
8479 | RIDBIT_RESET (RID_UNSIGNED, specbits); | |
8480 | RIDBIT_RESET (RID_SIGNED, specbits); | |
8481 | RIDBIT_RESET (RID_LONG, specbits); | |
8482 | RIDBIT_RESET (RID_SHORT, specbits); | |
8483 | longlong = 0; | |
8484 | } | |
8485 | } | |
8486 | ||
37c46b43 MS |
8487 | if (RIDBIT_SETP (RID_COMPLEX, specbits) |
8488 | && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) | |
8489 | { | |
8490 | error ("complex invalid for `%s'", name); | |
8491 | RIDBIT_RESET (RID_COMPLEX, specbits); | |
8492 | } | |
8493 | ||
8d08fdba MS |
8494 | /* Decide whether an integer type is signed or not. |
8495 | Optionally treat bitfields as signed by default. */ | |
8496 | if (RIDBIT_SETP (RID_UNSIGNED, specbits) | |
8d08fdba | 8497 | || (bitfield && ! flag_signed_bitfields |
37c46b43 | 8498 | && (explicit_int || defaulted_int || explicit_char |
8d08fdba MS |
8499 | /* A typedef for plain `int' without `signed' |
8500 | can be controlled just like plain `int'. */ | |
8501 | || ! (typedef_decl != NULL_TREE | |
8502 | && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
8503 | && TREE_CODE (type) != ENUMERAL_TYPE | |
8504 | && RIDBIT_NOTSETP (RID_SIGNED, specbits))) | |
8505 | { | |
8506 | if (longlong) | |
8507 | type = long_long_unsigned_type_node; | |
8508 | else if (RIDBIT_SETP (RID_LONG, specbits)) | |
8509 | type = long_unsigned_type_node; | |
8510 | else if (RIDBIT_SETP (RID_SHORT, specbits)) | |
8511 | type = short_unsigned_type_node; | |
8512 | else if (type == char_type_node) | |
8513 | type = unsigned_char_type_node; | |
8514 | else if (typedef_decl) | |
8515 | type = unsigned_type (type); | |
8516 | else | |
8517 | type = unsigned_type_node; | |
8518 | } | |
8519 | else if (RIDBIT_SETP (RID_SIGNED, specbits) | |
8520 | && type == char_type_node) | |
8521 | type = signed_char_type_node; | |
8522 | else if (longlong) | |
8523 | type = long_long_integer_type_node; | |
8524 | else if (RIDBIT_SETP (RID_LONG, specbits)) | |
8525 | type = long_integer_type_node; | |
8526 | else if (RIDBIT_SETP (RID_SHORT, specbits)) | |
8527 | type = short_integer_type_node; | |
8528 | ||
37c46b43 MS |
8529 | if (RIDBIT_SETP (RID_COMPLEX, specbits)) |
8530 | { | |
8531 | /* If we just have "complex", it is equivalent to | |
8532 | "complex double", but if any modifiers at all are specified it is | |
8533 | the complex form of TYPE. E.g, "complex short" is | |
8534 | "complex short int". */ | |
8535 | ||
8536 | if (defaulted_int && ! longlong | |
8537 | && ! (RIDBIT_SETP (RID_LONG, specbits) | |
8538 | || RIDBIT_SETP (RID_SHORT, specbits) | |
8539 | || RIDBIT_SETP (RID_SIGNED, specbits) | |
8540 | || RIDBIT_SETP (RID_UNSIGNED, specbits))) | |
8541 | type = complex_double_type_node; | |
8542 | else if (type == integer_type_node) | |
8543 | type = complex_integer_type_node; | |
8544 | else if (type == float_type_node) | |
8545 | type = complex_float_type_node; | |
8546 | else if (type == double_type_node) | |
8547 | type = complex_double_type_node; | |
8548 | else if (type == long_double_type_node) | |
8549 | type = complex_long_double_type_node; | |
8550 | else | |
8551 | type = build_complex_type (type); | |
8552 | } | |
8553 | ||
3ac3d9ea MM |
8554 | if (return_type == return_conversion |
8555 | && (RIDBIT_SETP (RID_CONST, specbits) | |
8556 | || RIDBIT_SETP (RID_VOLATILE, specbits))) | |
8557 | cp_error ("`operator %T' cannot be cv-qualified", | |
8558 | ctor_return_type); | |
8559 | ||
8d08fdba MS |
8560 | /* Set CONSTP if this declaration is `const', whether by |
8561 | explicit specification or via a typedef. | |
8562 | Likewise for VOLATILEP. */ | |
8563 | ||
8564 | constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type); | |
8565 | volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type); | |
8566 | staticp = 0; | |
8567 | inlinep = !! RIDBIT_SETP (RID_INLINE, specbits); | |
8d08fdba | 8568 | virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits); |
db5ae43f MS |
8569 | RIDBIT_RESET (RID_VIRTUAL, specbits); |
8570 | explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0; | |
8571 | RIDBIT_RESET (RID_EXPLICIT, specbits); | |
8d08fdba | 8572 | |
8d08fdba MS |
8573 | if (RIDBIT_SETP (RID_STATIC, specbits)) |
8574 | staticp = 1 + (decl_context == FIELD); | |
8575 | ||
8576 | if (virtualp && staticp == 2) | |
8577 | { | |
8578 | cp_error ("member `%D' cannot be declared both virtual and static", | |
8579 | dname); | |
8580 | staticp = 0; | |
8581 | } | |
8582 | friendp = RIDBIT_SETP (RID_FRIEND, specbits); | |
8d08fdba MS |
8583 | RIDBIT_RESET (RID_FRIEND, specbits); |
8584 | ||
8585 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
8586 | { | |
8587 | if (decl_context == PARM) | |
8588 | { | |
db5ae43f | 8589 | error ("non-member `%s' cannot be declared `mutable'", name); |
8d08fdba MS |
8590 | RIDBIT_RESET (RID_MUTABLE, specbits); |
8591 | } | |
8592 | else if (friendp || decl_context == TYPENAME) | |
8593 | { | |
db5ae43f | 8594 | error ("non-object member `%s' cannot be declared `mutable'", name); |
8d08fdba MS |
8595 | RIDBIT_RESET (RID_MUTABLE, specbits); |
8596 | } | |
8d08fdba MS |
8597 | } |
8598 | ||
8599 | /* Warn if two storage classes are given. Default to `auto'. */ | |
8600 | ||
8601 | if (RIDBIT_ANY_SET (specbits)) | |
8602 | { | |
8603 | if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++; | |
8604 | if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++; | |
8605 | if (decl_context == PARM && nclasses > 0) | |
8606 | error ("storage class specifiers invalid in parameter declarations"); | |
8607 | if (RIDBIT_SETP (RID_TYPEDEF, specbits)) | |
8608 | { | |
8609 | if (decl_context == PARM) | |
8610 | error ("typedef declaration invalid in parameter declaration"); | |
8611 | nclasses++; | |
8612 | } | |
8613 | if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++; | |
8614 | if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++; | |
8615 | } | |
8616 | ||
8617 | /* Give error if `virtual' is used outside of class declaration. */ | |
b7484fbe MS |
8618 | if (virtualp |
8619 | && (current_class_name == NULL_TREE || decl_context != FIELD)) | |
8d08fdba MS |
8620 | { |
8621 | error ("virtual outside class declaration"); | |
8622 | virtualp = 0; | |
8623 | } | |
8624 | if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits)) | |
8625 | { | |
8626 | error ("only members can be declared mutable"); | |
8627 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
8628 | } | |
8629 | ||
8630 | /* Static anonymous unions are dealt with here. */ | |
8631 | if (staticp && decl_context == TYPENAME | |
8632 | && TREE_CODE (declspecs) == TREE_LIST | |
8633 | && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE | |
8634 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs)))) | |
8635 | decl_context = FIELD; | |
8636 | ||
8637 | /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual' | |
8638 | is used in a signature member function declaration. */ | |
8639 | if (decl_context == FIELD | |
8640 | && IS_SIGNATURE (current_class_type) | |
fc378698 | 8641 | && RIDBIT_NOTSETP (RID_TYPEDEF, specbits)) |
8d08fdba MS |
8642 | { |
8643 | if (constp) | |
8644 | { | |
8645 | error ("`const' specified for signature member function `%s'", name); | |
8646 | constp = 0; | |
8647 | } | |
8648 | if (volatilep) | |
8649 | { | |
a28e3c7f MS |
8650 | error ("`volatile' specified for signature member function `%s'", |
8651 | name); | |
8d08fdba MS |
8652 | volatilep = 0; |
8653 | } | |
8654 | if (inlinep) | |
8655 | { | |
8656 | error ("`inline' specified for signature member function `%s'", name); | |
8657 | /* Later, we'll make signature member functions inline. */ | |
8658 | inlinep = 0; | |
8659 | } | |
8660 | if (friendp) | |
8661 | { | |
8662 | error ("`friend' declaration in signature definition"); | |
8663 | friendp = 0; | |
8664 | } | |
8665 | if (virtualp) | |
8666 | { | |
a28e3c7f MS |
8667 | error ("`virtual' specified for signature member function `%s'", |
8668 | name); | |
8d08fdba MS |
8669 | /* Later, we'll make signature member functions virtual. */ |
8670 | virtualp = 0; | |
8671 | } | |
8672 | } | |
8673 | ||
8674 | /* Warn about storage classes that are invalid for certain | |
8675 | kinds of declarations (parameters, typenames, etc.). */ | |
8676 | ||
8677 | if (nclasses > 1) | |
8678 | error ("multiple storage classes in declaration of `%s'", name); | |
8679 | else if (decl_context != NORMAL && nclasses > 0) | |
8680 | { | |
db5ae43f | 8681 | if ((decl_context == PARM || decl_context == CATCHPARM) |
8d08fdba MS |
8682 | && (RIDBIT_SETP (RID_REGISTER, specbits) |
8683 | || RIDBIT_SETP (RID_AUTO, specbits))) | |
8684 | ; | |
fc378698 MS |
8685 | else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) |
8686 | ; | |
8d08fdba | 8687 | else if (decl_context == FIELD |
fc378698 | 8688 | && ! IS_SIGNATURE (current_class_type) |
8d08fdba MS |
8689 | /* C++ allows static class elements */ |
8690 | && RIDBIT_SETP (RID_STATIC, specbits)) | |
8691 | /* C++ also allows inlines and signed and unsigned elements, | |
8692 | but in those cases we don't come in here. */ | |
8693 | ; | |
8694 | else | |
8695 | { | |
8696 | if (decl_context == FIELD) | |
8697 | { | |
b7484fbe MS |
8698 | tree tmp = NULL_TREE; |
8699 | register int op = 0; | |
8700 | ||
8701 | if (declarator) | |
8702 | { | |
9e9ff709 MS |
8703 | /* Avoid trying to get an operand off an identifier node. */ |
8704 | if (TREE_CODE (declarator) == IDENTIFIER_NODE) | |
8705 | tmp = declarator; | |
8706 | else | |
8707 | tmp = TREE_OPERAND (declarator, 0); | |
b7484fbe MS |
8708 | op = IDENTIFIER_OPNAME_P (tmp); |
8709 | } | |
8d08fdba MS |
8710 | error ("storage class specified for %s `%s'", |
8711 | IS_SIGNATURE (current_class_type) | |
8712 | ? (op | |
8713 | ? "signature member operator" | |
8714 | : "signature member function") | |
b7484fbe | 8715 | : (op ? "member operator" : "field"), |
8d08fdba MS |
8716 | op ? operator_name_string (tmp) : name); |
8717 | } | |
8718 | else | |
db5ae43f | 8719 | error (((decl_context == PARM || decl_context == CATCHPARM) |
8d08fdba MS |
8720 | ? "storage class specified for parameter `%s'" |
8721 | : "storage class specified for typename"), name); | |
8722 | RIDBIT_RESET (RID_REGISTER, specbits); | |
8723 | RIDBIT_RESET (RID_AUTO, specbits); | |
8724 | RIDBIT_RESET (RID_EXTERN, specbits); | |
8725 | ||
8726 | if (decl_context == FIELD && IS_SIGNATURE (current_class_type)) | |
8727 | { | |
8728 | RIDBIT_RESET (RID_STATIC, specbits); | |
8729 | staticp = 0; | |
8730 | } | |
8731 | } | |
8732 | } | |
8733 | else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag) | |
8734 | { | |
a9aedbc2 | 8735 | if (toplevel_bindings_p ()) |
8d08fdba | 8736 | { |
59be0cdd | 8737 | /* It's common practice (and completely valid) to have a const |
8d08fdba MS |
8738 | be initialized and declared extern. */ |
8739 | if (! constp) | |
8740 | warning ("`%s' initialized and declared `extern'", name); | |
8741 | } | |
8742 | else | |
8743 | error ("`%s' has both `extern' and initializer", name); | |
8744 | } | |
8745 | else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag | |
a9aedbc2 | 8746 | && ! toplevel_bindings_p ()) |
8d08fdba | 8747 | error ("nested function `%s' declared `extern'", name); |
a9aedbc2 | 8748 | else if (toplevel_bindings_p ()) |
8d08fdba MS |
8749 | { |
8750 | if (RIDBIT_SETP (RID_AUTO, specbits)) | |
8751 | error ("top-level declaration of `%s' specifies `auto'", name); | |
8d08fdba MS |
8752 | } |
8753 | ||
909e536a MS |
8754 | if (nclasses > 0 && friendp) |
8755 | error ("storage class specifiers invalid in friend function declarations"); | |
8756 | ||
8d08fdba MS |
8757 | /* Now figure out the structure of the declarator proper. |
8758 | Descend through it, creating more complex types, until we reach | |
8759 | the declared identifier (or NULL_TREE, in an absolute declarator). */ | |
8760 | ||
386b8a85 JM |
8761 | while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE |
8762 | && TREE_CODE (declarator) != TEMPLATE_ID_EXPR) | |
8d08fdba MS |
8763 | { |
8764 | /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), | |
8765 | an INDIRECT_REF (for *...), | |
8766 | a CALL_EXPR (for ...(...)), | |
8767 | an identifier (for the name being declared) | |
8768 | or a null pointer (for the place in an absolute declarator | |
8769 | where the name was omitted). | |
8770 | For the last two cases, we have just exited the loop. | |
8771 | ||
8772 | For C++ it could also be | |
8773 | a SCOPE_REF (for class :: ...). In this case, we have converted | |
8774 | sensible names to types, and those are the values we use to | |
8775 | qualify the member name. | |
8776 | an ADDR_EXPR (for &...), | |
8777 | a BIT_NOT_EXPR (for destructors) | |
8d08fdba MS |
8778 | |
8779 | At this point, TYPE is the type of elements of an array, | |
8780 | or for a function to return, or for a pointer to point to. | |
8781 | After this sequence of ifs, TYPE is the type of the | |
8782 | array or function or pointer, and DECLARATOR has had its | |
8783 | outermost layer removed. */ | |
8784 | ||
bd6dd845 | 8785 | if (type == error_mark_node) |
8d08fdba MS |
8786 | { |
8787 | if (TREE_CODE (declarator) == SCOPE_REF) | |
8788 | declarator = TREE_OPERAND (declarator, 1); | |
8789 | else | |
8790 | declarator = TREE_OPERAND (declarator, 0); | |
8791 | continue; | |
8792 | } | |
8793 | if (quals != NULL_TREE | |
8794 | && (declarator == NULL_TREE | |
8795 | || TREE_CODE (declarator) != SCOPE_REF)) | |
8796 | { | |
8797 | if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE) | |
8798 | ctype = TYPE_METHOD_BASETYPE (type); | |
8799 | if (ctype != NULL_TREE) | |
8800 | { | |
8d08fdba | 8801 | tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); |
8d08fdba MS |
8802 | ctype = grok_method_quals (ctype, dummy, quals); |
8803 | type = TREE_TYPE (dummy); | |
8804 | quals = NULL_TREE; | |
8805 | } | |
8806 | } | |
8807 | switch (TREE_CODE (declarator)) | |
8808 | { | |
8809 | case ARRAY_REF: | |
8810 | { | |
8811 | register tree itype = NULL_TREE; | |
8812 | register tree size = TREE_OPERAND (declarator, 1); | |
b7484fbe MS |
8813 | /* The index is a signed object `sizetype' bits wide. */ |
8814 | tree index_type = signed_type (sizetype); | |
8d08fdba MS |
8815 | |
8816 | declarator = TREE_OPERAND (declarator, 0); | |
8817 | ||
8818 | /* Check for some types that there cannot be arrays of. */ | |
8819 | ||
8820 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
8821 | { | |
8822 | cp_error ("declaration of `%D' as array of voids", dname); | |
8823 | type = error_mark_node; | |
8824 | } | |
8825 | ||
8826 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
8827 | { | |
8828 | cp_error ("declaration of `%D' as array of functions", dname); | |
8829 | type = error_mark_node; | |
8830 | } | |
8831 | ||
8832 | /* ARM $8.4.3: Since you can't have a pointer to a reference, | |
8833 | you can't have arrays of references. If we allowed them, | |
59be0cdd | 8834 | then we'd be saying x[i] is valid for an array x, but |
8d08fdba MS |
8835 | then you'd have to ask: what does `*(x + i)' mean? */ |
8836 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
8837 | { | |
8838 | if (decl_context == TYPENAME) | |
8839 | cp_error ("cannot make arrays of references"); | |
8840 | else | |
8841 | cp_error ("declaration of `%D' as array of references", | |
8842 | dname); | |
8843 | type = error_mark_node; | |
8844 | } | |
8845 | ||
8846 | if (TREE_CODE (type) == OFFSET_TYPE) | |
8847 | { | |
8848 | cp_error ("declaration of `%D' as array of data members", | |
8849 | dname); | |
8850 | type = error_mark_node; | |
8851 | } | |
8852 | ||
8853 | if (TREE_CODE (type) == METHOD_TYPE) | |
8854 | { | |
8855 | cp_error ("declaration of `%D' as array of function members", | |
8856 | dname); | |
8857 | type = error_mark_node; | |
8858 | } | |
8859 | ||
8860 | if (size == error_mark_node) | |
8861 | type = error_mark_node; | |
8862 | ||
8863 | if (type == error_mark_node) | |
8864 | continue; | |
8865 | ||
8866 | if (size) | |
8867 | { | |
8868 | /* Must suspend_momentary here because the index | |
8869 | type may need to live until the end of the function. | |
8870 | For example, it is used in the declaration of a | |
8871 | variable which requires destructing at the end of | |
8872 | the function; then build_vec_delete will need this | |
8873 | value. */ | |
8874 | int yes = suspend_momentary (); | |
8875 | /* might be a cast */ | |
8876 | if (TREE_CODE (size) == NOP_EXPR | |
8877 | && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) | |
8878 | size = TREE_OPERAND (size, 0); | |
8879 | ||
5566b478 MS |
8880 | /* If this involves a template parameter, it'll be |
8881 | constant, but we don't know what the value is yet. */ | |
5156628f | 8882 | if (processing_template_decl) |
5566b478 MS |
8883 | { |
8884 | itype = make_node (INTEGER_TYPE); | |
8885 | TYPE_MIN_VALUE (itype) = size_zero_node; | |
8886 | TYPE_MAX_VALUE (itype) = build_min | |
8887 | (MINUS_EXPR, sizetype, size, integer_one_node); | |
8888 | goto dont_grok_size; | |
8889 | } | |
8d08fdba MS |
8890 | |
8891 | if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE | |
8892 | && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) | |
8893 | { | |
8894 | cp_error ("size of array `%D' has non-integer type", | |
8895 | dname); | |
8896 | size = integer_one_node; | |
8897 | } | |
8898 | if (TREE_READONLY_DECL_P (size)) | |
8899 | size = decl_constant_value (size); | |
e1cd6e56 | 8900 | if (pedantic && integer_zerop (size)) |
8d08fdba MS |
8901 | cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname); |
8902 | if (TREE_CONSTANT (size)) | |
8903 | { | |
dff6b454 RK |
8904 | int old_flag_pedantic_errors = flag_pedantic_errors; |
8905 | int old_pedantic = pedantic; | |
8906 | pedantic = flag_pedantic_errors = 1; | |
8907 | /* Always give overflow errors on array subscripts. */ | |
8d08fdba | 8908 | constant_expression_warning (size); |
dff6b454 RK |
8909 | pedantic = old_pedantic; |
8910 | flag_pedantic_errors = old_flag_pedantic_errors; | |
8d08fdba MS |
8911 | if (INT_CST_LT (size, integer_zero_node)) |
8912 | { | |
8913 | cp_error ("size of array `%D' is negative", dname); | |
8914 | size = integer_one_node; | |
8915 | } | |
8d08fdba MS |
8916 | } |
8917 | else | |
8918 | { | |
e1cd6e56 | 8919 | if (pedantic) |
a0a33927 MS |
8920 | { |
8921 | if (dname) | |
8922 | cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", | |
8923 | dname); | |
8924 | else | |
8925 | cp_pedwarn ("ANSI C++ forbids variable-size array"); | |
8926 | } | |
8d08fdba | 8927 | } |
b7484fbe | 8928 | |
beb53fb8 JM |
8929 | itype |
8930 | = fold (build_binary_op (MINUS_EXPR, | |
37c46b43 MS |
8931 | cp_convert (index_type, size), |
8932 | cp_convert (index_type, | |
8933 | integer_one_node), 1)); | |
b7484fbe MS |
8934 | if (! TREE_CONSTANT (itype)) |
8935 | itype = variable_size (itype); | |
594740f3 MS |
8936 | else if (TREE_OVERFLOW (itype)) |
8937 | { | |
8938 | error ("overflow in array dimension"); | |
8939 | TREE_OVERFLOW (itype) = 0; | |
8940 | } | |
fc378698 MS |
8941 | |
8942 | /* If we're a parm, we need to have a permanent type so | |
8943 | mangling checks for re-use will work right. If both the | |
8944 | element and index types are permanent, the array type | |
8945 | will be, too. */ | |
8946 | if (decl_context == PARM | |
8947 | && allocation_temporary_p () && TREE_PERMANENT (type)) | |
8948 | { | |
8949 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
8950 | itype = build_index_type (itype); | |
8951 | pop_obstacks (); | |
8952 | } | |
8953 | else | |
8954 | itype = build_index_type (itype); | |
8955 | ||
5566b478 | 8956 | dont_grok_size: |
8d08fdba MS |
8957 | resume_momentary (yes); |
8958 | } | |
8959 | ||
8960 | /* Build the array type itself, then merge any constancy or | |
8961 | volatility into the target type. We must do it in this order | |
8962 | to ensure that the TYPE_MAIN_VARIANT field of the array type | |
8963 | is set correctly. */ | |
8964 | ||
8965 | type = build_cplus_array_type (type, itype); | |
8966 | if (constp || volatilep) | |
f376e137 | 8967 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
8968 | |
8969 | ctype = NULL_TREE; | |
8970 | } | |
8971 | break; | |
8972 | ||
8973 | case CALL_EXPR: | |
8974 | { | |
8975 | tree arg_types; | |
f376e137 MS |
8976 | int funcdecl_p; |
8977 | tree inner_parms = TREE_OPERAND (declarator, 1); | |
8978 | tree inner_decl = TREE_OPERAND (declarator, 0); | |
8d08fdba MS |
8979 | |
8980 | /* Declaring a function type. | |
8981 | Make sure we have a valid type for the function to return. */ | |
8982 | #if 0 | |
8983 | /* Is this an error? Should they be merged into TYPE here? */ | |
8984 | if (pedantic && (constp || volatilep)) | |
8985 | pedwarn ("function declared to return const or volatile result"); | |
8986 | #else | |
21474714 MS |
8987 | /* Merge any constancy or volatility into the function return |
8988 | type. */ | |
8d08fdba MS |
8989 | |
8990 | if (constp || volatilep) | |
8991 | { | |
f376e137 | 8992 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
8993 | if (IS_AGGR_TYPE (type)) |
8994 | build_pointer_type (type); | |
8995 | constp = 0; | |
8996 | volatilep = 0; | |
8997 | } | |
8998 | #endif | |
8999 | ||
9000 | /* Warn about some types functions can't return. */ | |
9001 | ||
9002 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
9003 | { | |
9004 | error ("`%s' declared as function returning a function", name); | |
9005 | type = integer_type_node; | |
9006 | } | |
9007 | if (TREE_CODE (type) == ARRAY_TYPE) | |
9008 | { | |
9009 | error ("`%s' declared as function returning an array", name); | |
9010 | type = integer_type_node; | |
9011 | } | |
9012 | ||
f376e137 MS |
9013 | if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) |
9014 | inner_decl = TREE_OPERAND (inner_decl, 1); | |
9015 | ||
386b8a85 JM |
9016 | if (inner_decl && TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR) |
9017 | inner_decl = dname; | |
9018 | ||
b7484fbe MS |
9019 | /* Pick up type qualifiers which should be applied to `this'. */ |
9020 | quals = TREE_OPERAND (declarator, 2); | |
9021 | ||
c11b6f21 MS |
9022 | /* Pick up the exception specifications. */ |
9023 | raises = TREE_TYPE (declarator); | |
9024 | ||
f376e137 MS |
9025 | /* Say it's a definition only for the CALL_EXPR |
9026 | closest to the identifier. */ | |
beb53fb8 | 9027 | funcdecl_p |
386b8a85 JM |
9028 | = inner_decl |
9029 | && (TREE_CODE (inner_decl) == IDENTIFIER_NODE | |
9030 | || TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR | |
9031 | || TREE_CODE (inner_decl) == BIT_NOT_EXPR); | |
9032 | ||
8d08fdba MS |
9033 | if (ctype == NULL_TREE |
9034 | && decl_context == FIELD | |
f376e137 | 9035 | && funcdecl_p |
8d08fdba MS |
9036 | && (friendp == 0 || dname == current_class_name)) |
9037 | ctype = current_class_type; | |
9038 | ||
51c184be | 9039 | if (ctype && return_type == return_conversion) |
8d08fdba MS |
9040 | TYPE_HAS_CONVERSION (ctype) = 1; |
9041 | if (ctype && constructor_name (ctype) == dname) | |
9042 | { | |
9043 | /* We are within a class's scope. If our declarator name | |
9044 | is the same as the class name, and we are defining | |
9045 | a function, then it is a constructor/destructor, and | |
9046 | therefore returns a void type. */ | |
9047 | ||
9048 | if (flags == DTOR_FLAG) | |
9049 | { | |
9050 | /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may | |
9051 | not be declared const or volatile. A destructor | |
9052 | may not be static. */ | |
9053 | if (staticp == 2) | |
9054 | error ("destructor cannot be static member function"); | |
b7484fbe | 9055 | if (quals) |
8d08fdba | 9056 | { |
b7484fbe | 9057 | error ("destructors cannot be declared `const' or `volatile'"); |
8d08fdba MS |
9058 | return void_type_node; |
9059 | } | |
9060 | if (decl_context == FIELD) | |
9061 | { | |
9062 | if (! member_function_or_else (ctype, current_class_type, | |
9063 | "destructor for alien class `%s' cannot be a member")) | |
9064 | return void_type_node; | |
9065 | } | |
9066 | } | |
e92cc029 | 9067 | else /* it's a constructor. */ |
8d08fdba | 9068 | { |
db5ae43f MS |
9069 | if (explicitp == 1) |
9070 | explicitp = 2; | |
8d08fdba MS |
9071 | /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may |
9072 | not be declared const or volatile. A constructor may | |
9073 | not be virtual. A constructor may not be static. */ | |
9074 | if (staticp == 2) | |
9075 | error ("constructor cannot be static member function"); | |
9076 | if (virtualp) | |
9077 | { | |
9078 | pedwarn ("constructors cannot be declared virtual"); | |
9079 | virtualp = 0; | |
9080 | } | |
b7484fbe | 9081 | if (quals) |
8d08fdba | 9082 | { |
b7484fbe | 9083 | error ("constructors cannot be declared `const' or `volatile'"); |
8d08fdba MS |
9084 | return void_type_node; |
9085 | } | |
8d08fdba | 9086 | { |
51c184be | 9087 | RID_BIT_TYPE tmp_bits; |
fc378698 | 9088 | bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof (RID_BIT_TYPE)); |
51c184be MS |
9089 | RIDBIT_RESET (RID_INLINE, tmp_bits); |
9090 | RIDBIT_RESET (RID_STATIC, tmp_bits); | |
9091 | if (RIDBIT_ANY_SET (tmp_bits)) | |
8d08fdba | 9092 | error ("return value type specifier for constructor ignored"); |
8d08fdba | 9093 | } |
f30432d7 | 9094 | type = build_pointer_type (ctype); |
beb53fb8 JM |
9095 | if (decl_context == FIELD |
9096 | && IS_SIGNATURE (current_class_type)) | |
8d08fdba MS |
9097 | { |
9098 | error ("constructor not allowed in signature"); | |
9099 | return void_type_node; | |
9100 | } | |
9101 | else if (decl_context == FIELD) | |
9102 | { | |
9103 | if (! member_function_or_else (ctype, current_class_type, | |
9104 | "constructor for alien class `%s' cannot be member")) | |
9105 | return void_type_node; | |
9106 | TYPE_HAS_CONSTRUCTOR (ctype) = 1; | |
9107 | if (return_type != return_ctor) | |
9108 | return NULL_TREE; | |
9109 | } | |
9110 | } | |
9111 | if (decl_context == FIELD) | |
9112 | staticp = 0; | |
9113 | } | |
b7484fbe | 9114 | else if (friendp) |
8d08fdba | 9115 | { |
b7484fbe MS |
9116 | if (initialized) |
9117 | error ("can't initialize friend function `%s'", name); | |
9118 | if (virtualp) | |
9119 | { | |
9120 | /* Cannot be both friend and virtual. */ | |
9121 | error ("virtual functions cannot be friends"); | |
9122 | RIDBIT_RESET (RID_FRIEND, specbits); | |
9123 | friendp = 0; | |
9124 | } | |
28cbf42c MS |
9125 | if (decl_context == NORMAL) |
9126 | error ("friend declaration not in class definition"); | |
9127 | if (current_function_decl && funcdef_flag) | |
9128 | cp_error ("can't define friend function `%s' in a local class definition", | |
9129 | name); | |
8d08fdba MS |
9130 | } |
9131 | ||
8d08fdba MS |
9132 | /* Construct the function type and go to the next |
9133 | inner layer of declarator. */ | |
9134 | ||
f376e137 | 9135 | declarator = TREE_OPERAND (declarator, 0); |
8d08fdba | 9136 | |
f376e137 MS |
9137 | /* FIXME: This is where default args should be fully |
9138 | processed. */ | |
8d08fdba | 9139 | |
f376e137 | 9140 | arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0); |
8d08fdba MS |
9141 | |
9142 | if (declarator) | |
9143 | { | |
9144 | /* Get past destructors, etc. | |
9145 | We know we have one because FLAGS will be non-zero. | |
9146 | ||
9147 | Complain about improper parameter lists here. */ | |
9148 | if (TREE_CODE (declarator) == BIT_NOT_EXPR) | |
9149 | { | |
9150 | declarator = TREE_OPERAND (declarator, 0); | |
9151 | ||
9152 | if (strict_prototype == 0 && arg_types == NULL_TREE) | |
9153 | arg_types = void_list_node; | |
9154 | else if (arg_types == NULL_TREE | |
9155 | || arg_types != void_list_node) | |
9156 | { | |
9157 | error ("destructors cannot be specified with parameters"); | |
9158 | arg_types = void_list_node; | |
9159 | } | |
9160 | } | |
9161 | } | |
9162 | ||
d22c8596 | 9163 | /* ANSI says that `const int foo ();' |
8d08fdba | 9164 | does not make the function foo const. */ |
d22c8596 | 9165 | type = build_function_type (type, arg_types); |
42976354 BK |
9166 | |
9167 | { | |
9168 | tree t; | |
9169 | for (t = arg_types; t; t = TREE_CHAIN (t)) | |
9170 | if (TREE_PURPOSE (t) | |
9171 | && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) | |
9172 | { | |
9173 | add_defarg_fn (type); | |
9174 | break; | |
9175 | } | |
9176 | } | |
8d08fdba MS |
9177 | } |
9178 | break; | |
9179 | ||
9180 | case ADDR_EXPR: | |
9181 | case INDIRECT_REF: | |
9182 | /* Filter out pointers-to-references and references-to-references. | |
9183 | We can get these if a TYPE_DECL is used. */ | |
9184 | ||
9185 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
9186 | { | |
9187 | error ("cannot declare %s to references", | |
9188 | TREE_CODE (declarator) == ADDR_EXPR | |
9189 | ? "references" : "pointers"); | |
9190 | declarator = TREE_OPERAND (declarator, 0); | |
9191 | continue; | |
9192 | } | |
9193 | ||
a5894242 MS |
9194 | if (TREE_CODE (type) == OFFSET_TYPE |
9195 | && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE | |
9196 | || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE)) | |
9197 | { | |
9198 | cp_error ("cannot declare pointer to `%#T' member", | |
9199 | TREE_TYPE (type)); | |
9200 | type = TREE_TYPE (type); | |
9201 | } | |
9202 | ||
8d08fdba MS |
9203 | /* Merge any constancy or volatility into the target type |
9204 | for the pointer. */ | |
9205 | ||
9206 | if (constp || volatilep) | |
9207 | { | |
9208 | /* A const or volatile signature pointer/reference is | |
9209 | pointing to a const or volatile object, i.e., the | |
9210 | `optr' is const or volatile, respectively, not the | |
9211 | signature pointer/reference itself. */ | |
9212 | if (! IS_SIGNATURE (type)) | |
9213 | { | |
f376e137 | 9214 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
9215 | if (IS_AGGR_TYPE (type)) |
9216 | build_pointer_type (type); | |
9217 | constp = 0; | |
9218 | volatilep = 0; | |
9219 | } | |
9220 | } | |
9221 | ||
9222 | if (IS_SIGNATURE (type)) | |
9223 | { | |
9224 | if (TREE_CODE (declarator) == ADDR_EXPR) | |
9225 | { | |
63718c49 GB |
9226 | if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE |
9227 | && TYPE_SIZE (type)) | |
9228 | cp_warning ("empty signature `%T' used in signature reference declaration", | |
9229 | type); | |
8d08fdba MS |
9230 | #if 0 |
9231 | type = build_signature_reference_type (type, | |
9232 | constp, volatilep); | |
9233 | #else | |
9234 | sorry ("signature reference"); | |
9235 | return NULL_TREE; | |
9236 | #endif | |
9237 | } | |
9238 | else | |
9239 | { | |
63718c49 GB |
9240 | if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE |
9241 | && TYPE_SIZE (type)) | |
9242 | cp_warning ("empty signature `%T' used in signature pointer declaration", | |
9243 | type); | |
8d08fdba MS |
9244 | type = build_signature_pointer_type (type, |
9245 | constp, volatilep); | |
9246 | } | |
9247 | constp = 0; | |
9248 | volatilep = 0; | |
9249 | } | |
9250 | else if (TREE_CODE (declarator) == ADDR_EXPR) | |
9251 | { | |
9252 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
9253 | { | |
9254 | error ("cannot declare references to functions; use pointer to function instead"); | |
9255 | type = build_pointer_type (type); | |
9256 | } | |
9257 | else | |
9258 | { | |
9259 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
9260 | error ("invalid type: `void &'"); | |
9261 | else | |
9262 | type = build_reference_type (type); | |
9263 | } | |
9264 | } | |
9265 | else if (TREE_CODE (type) == METHOD_TYPE) | |
9266 | { | |
9267 | type = build_ptrmemfunc_type (build_pointer_type (type)); | |
9268 | } | |
9269 | else | |
9270 | type = build_pointer_type (type); | |
9271 | ||
9272 | /* Process a list of type modifier keywords (such as | |
9273 | const or volatile) that were given inside the `*' or `&'. */ | |
9274 | ||
9275 | if (TREE_TYPE (declarator)) | |
9276 | { | |
9277 | register tree typemodlist; | |
9278 | int erred = 0; | |
9279 | for (typemodlist = TREE_TYPE (declarator); typemodlist; | |
9280 | typemodlist = TREE_CHAIN (typemodlist)) | |
9281 | { | |
9282 | if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST]) | |
9283 | constp++; | |
9284 | else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE]) | |
9285 | volatilep++; | |
9286 | else if (!erred) | |
9287 | { | |
9288 | erred = 1; | |
9289 | error ("invalid type modifier within %s declarator", | |
9290 | TREE_CODE (declarator) == ADDR_EXPR | |
9291 | ? "reference" : "pointer"); | |
9292 | } | |
9293 | } | |
9294 | if (constp > 1) | |
a0a33927 | 9295 | pedwarn ("duplicate `const'"); |
8d08fdba | 9296 | if (volatilep > 1) |
a0a33927 MS |
9297 | pedwarn ("duplicate `volatile'"); |
9298 | if (TREE_CODE (declarator) == ADDR_EXPR | |
9299 | && (constp || volatilep)) | |
9300 | { | |
9301 | if (constp) | |
e1cd6e56 | 9302 | pedwarn ("discarding `const' applied to a reference"); |
a0a33927 | 9303 | if (volatilep) |
e1cd6e56 | 9304 | pedwarn ("discarding `volatile' applied to a reference"); |
a0a33927 MS |
9305 | constp = volatilep = 0; |
9306 | } | |
8d08fdba MS |
9307 | } |
9308 | declarator = TREE_OPERAND (declarator, 0); | |
9309 | ctype = NULL_TREE; | |
9310 | break; | |
9311 | ||
9312 | case SCOPE_REF: | |
9313 | { | |
9314 | /* We have converted type names to NULL_TREE if the | |
9315 | name was bogus, or to a _TYPE node, if not. | |
9316 | ||
9317 | The variable CTYPE holds the type we will ultimately | |
9318 | resolve to. The code here just needs to build | |
9319 | up appropriate member types. */ | |
9320 | tree sname = TREE_OPERAND (declarator, 1); | |
386b8a85 JM |
9321 | tree t; |
9322 | ||
8d08fdba MS |
9323 | /* Destructors can have their visibilities changed as well. */ |
9324 | if (TREE_CODE (sname) == BIT_NOT_EXPR) | |
9325 | sname = TREE_OPERAND (sname, 0); | |
9326 | ||
9327 | if (TREE_COMPLEXITY (declarator) == 0) | |
9328 | /* This needs to be here, in case we are called | |
9329 | multiple times. */ ; | |
9330 | else if (friendp && (TREE_COMPLEXITY (declarator) < 2)) | |
9331 | /* don't fall out into global scope. Hides real bug? --eichin */ ; | |
5566b478 MS |
9332 | else if (! IS_AGGR_TYPE_CODE |
9333 | (TREE_CODE (TREE_OPERAND (declarator, 0)))) | |
9334 | ; | |
8d08fdba MS |
9335 | else if (TREE_COMPLEXITY (declarator) == current_class_depth) |
9336 | { | |
9a3b49ac MS |
9337 | /* Resolve any TYPENAME_TYPEs from the decl-specifier-seq |
9338 | that refer to ctype. They couldn't be resolved earlier | |
9339 | because we hadn't pushed into the class yet. | |
9340 | Example: resolve 'B<T>::type' in | |
9341 | 'B<typename B<T>::type> B<T>::f () { }'. */ | |
9342 | if (current_template_parms | |
9343 | && uses_template_parms (type) | |
9344 | && uses_template_parms (current_class_type)) | |
9345 | { | |
9346 | tree args = current_template_args (); | |
f7d98d58 | 9347 | type = tsubst (type, args, NULL_TREE); |
9a3b49ac MS |
9348 | } |
9349 | ||
a28e3c7f MS |
9350 | /* This pop_nested_class corresponds to the |
9351 | push_nested_class used to push into class scope for | |
9352 | parsing the argument list of a function decl, in | |
9353 | qualified_id. */ | |
8d08fdba MS |
9354 | pop_nested_class (1); |
9355 | TREE_COMPLEXITY (declarator) = current_class_depth; | |
9356 | } | |
9357 | else | |
9358 | my_friendly_abort (16); | |
9359 | ||
9360 | if (TREE_OPERAND (declarator, 0) == NULL_TREE) | |
9361 | { | |
9362 | /* We had a reference to a global decl, or | |
9363 | perhaps we were given a non-aggregate typedef, | |
9364 | in which case we cleared this out, and should just | |
9365 | keep going as though it wasn't there. */ | |
9366 | declarator = sname; | |
9367 | continue; | |
9368 | } | |
9369 | ctype = TREE_OPERAND (declarator, 0); | |
9370 | ||
386b8a85 JM |
9371 | t = ctype; |
9372 | while (t != NULL_TREE) | |
9373 | { | |
75650646 MM |
9374 | if (CLASSTYPE_TEMPLATE_INFO (t) && |
9375 | !CLASSTYPE_TEMPLATE_SPECIALIZATION (t)) | |
386b8a85 JM |
9376 | template_count += 1; |
9377 | t = TYPE_MAIN_DECL (t); | |
9378 | if (DECL_LANG_SPECIFIC (t)) | |
9379 | t = DECL_CLASS_CONTEXT (t); | |
9380 | else | |
9381 | t = NULL_TREE; | |
9382 | } | |
9383 | ||
8d08fdba MS |
9384 | if (sname == NULL_TREE) |
9385 | goto done_scoping; | |
9386 | ||
9387 | if (TREE_CODE (sname) == IDENTIFIER_NODE) | |
9388 | { | |
9389 | /* This is the `standard' use of the scoping operator: | |
9390 | basetype :: member . */ | |
9391 | ||
db5ae43f | 9392 | if (ctype == current_class_type) |
28cbf42c MS |
9393 | { |
9394 | /* class A { | |
9395 | void A::f (); | |
9396 | }; | |
9397 | ||
9398 | Is this ill-formed? */ | |
9399 | ||
9400 | if (pedantic) | |
9401 | cp_pedwarn ("extra qualification `%T::' on member `%s' ignored", | |
9402 | ctype, name); | |
9403 | } | |
db5ae43f | 9404 | else if (TREE_CODE (type) == FUNCTION_TYPE) |
8d08fdba MS |
9405 | { |
9406 | if (current_class_type == NULL_TREE | |
8d08fdba MS |
9407 | || friendp) |
9408 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
9409 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9410 | else | |
9411 | { | |
5b605f68 | 9412 | cp_error ("cannot declare member function `%T::%s' within `%T'", |
a3203465 | 9413 | ctype, name, current_class_type); |
8d08fdba MS |
9414 | return void_type_node; |
9415 | } | |
9416 | } | |
5566b478 MS |
9417 | else if (RIDBIT_SETP (RID_TYPEDEF, specbits) |
9418 | || TYPE_SIZE (complete_type (ctype)) != NULL_TREE) | |
8d08fdba | 9419 | { |
8d08fdba | 9420 | /* have to move this code elsewhere in this function. |
db5ae43f MS |
9421 | this code is used for i.e., typedef int A::M; M *pm; |
9422 | ||
9423 | It is? How? jason 10/2/94 */ | |
8d08fdba | 9424 | |
8d08fdba MS |
9425 | if (current_class_type) |
9426 | { | |
db5ae43f MS |
9427 | cp_error ("cannot declare member `%T::%s' within `%T'", |
9428 | ctype, name, current_class_type); | |
9429 | return void_type_node; | |
8d08fdba MS |
9430 | } |
9431 | type = build_offset_type (ctype, type); | |
9432 | } | |
9433 | else if (uses_template_parms (ctype)) | |
9434 | { | |
8d08fdba | 9435 | if (TREE_CODE (type) == FUNCTION_TYPE) |
beb53fb8 JM |
9436 | type |
9437 | = build_cplus_method_type (build_type_variant (ctype, | |
9438 | constp, | |
9439 | volatilep), | |
9440 | TREE_TYPE (type), | |
9441 | TYPE_ARG_TYPES (type)); | |
8d08fdba MS |
9442 | } |
9443 | else | |
9444 | { | |
9445 | cp_error ("structure `%T' not yet defined", ctype); | |
9446 | return error_mark_node; | |
9447 | } | |
9448 | ||
9449 | declarator = sname; | |
9450 | } | |
8d08fdba MS |
9451 | else if (TREE_CODE (sname) == SCOPE_REF) |
9452 | my_friendly_abort (17); | |
9453 | else | |
9454 | { | |
9455 | done_scoping: | |
9456 | declarator = TREE_OPERAND (declarator, 1); | |
9457 | if (declarator && TREE_CODE (declarator) == CALL_EXPR) | |
9458 | /* In this case, we will deal with it later. */ | |
9459 | ; | |
9460 | else | |
9461 | { | |
9462 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
9463 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9464 | else | |
9465 | type = build_offset_type (ctype, type); | |
9466 | } | |
9467 | } | |
9468 | } | |
9469 | break; | |
9470 | ||
9471 | case BIT_NOT_EXPR: | |
9472 | declarator = TREE_OPERAND (declarator, 0); | |
9473 | break; | |
9474 | ||
8d08fdba MS |
9475 | case RECORD_TYPE: |
9476 | case UNION_TYPE: | |
9477 | case ENUMERAL_TYPE: | |
9478 | declarator = NULL_TREE; | |
9479 | break; | |
9480 | ||
9481 | case ERROR_MARK: | |
9482 | declarator = NULL_TREE; | |
9483 | break; | |
9484 | ||
9485 | default: | |
9486 | my_friendly_abort (158); | |
9487 | } | |
9488 | } | |
9489 | ||
db5ae43f MS |
9490 | if (explicitp == 1) |
9491 | { | |
9492 | error ("only constructors can be declared `explicit'"); | |
9493 | explicitp = 0; | |
9494 | } | |
9495 | ||
8d08fdba MS |
9496 | /* Now TYPE has the actual type. */ |
9497 | ||
9498 | /* If this is declaring a typedef name, return a TYPE_DECL. */ | |
9499 | ||
f30432d7 MS |
9500 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) |
9501 | { | |
9502 | if (constp) | |
9503 | { | |
9504 | error ("const `%s' cannot be declared `mutable'", name); | |
9505 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
9506 | } | |
9507 | else if (staticp) | |
9508 | { | |
9509 | error ("static `%s' cannot be declared `mutable'", name); | |
9510 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
9511 | } | |
9512 | } | |
9513 | ||
fc378698 | 9514 | if (RIDBIT_SETP (RID_TYPEDEF, specbits) && decl_context != TYPENAME) |
8d08fdba MS |
9515 | { |
9516 | tree decl; | |
9517 | ||
9518 | /* Note that the grammar rejects storage classes | |
9519 | in typenames, fields or parameters. */ | |
9520 | if (constp || volatilep) | |
f376e137 | 9521 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba | 9522 | |
d2e5ee5c MS |
9523 | if (decl_context == FIELD) |
9524 | { | |
9525 | if (declarator == current_class_name) | |
9526 | cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class", | |
9527 | declarator); | |
9528 | decl = build_lang_decl (TYPE_DECL, declarator, type); | |
9529 | if (IS_SIGNATURE (current_class_type) && opaque_typedef) | |
9530 | SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; | |
9531 | } | |
9532 | else | |
9533 | decl = build_decl (TYPE_DECL, declarator, type); | |
9534 | ||
8d08fdba MS |
9535 | /* If the user declares "struct {...} foo" then `foo' will have |
9536 | an anonymous name. Fill that name in now. Nothing can | |
9537 | refer to it, so nothing needs know about the name change. | |
9538 | The TYPE_NAME field was filled in by build_struct_xref. */ | |
9539 | if (type != error_mark_node | |
9540 | && TYPE_NAME (type) | |
9541 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
9542 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) | |
9543 | { | |
9544 | /* replace the anonymous name with the real name everywhere. */ | |
9545 | lookup_tag_reverse (type, declarator); | |
d2e5ee5c | 9546 | TYPE_NAME (type) = decl; |
8d08fdba MS |
9547 | |
9548 | if (TYPE_LANG_SPECIFIC (type)) | |
9549 | TYPE_WAS_ANONYMOUS (type) = 1; | |
9550 | ||
d2e5ee5c MS |
9551 | DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl); |
9552 | DECL_ASSEMBLER_NAME (decl) | |
9553 | = get_identifier (build_overload_name (type, 1, 1)); | |
fc378698 | 9554 | } |
fc378698 | 9555 | |
8d08fdba MS |
9556 | if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE) |
9557 | { | |
9558 | cp_error_at ("typedef name may not be class-qualified", decl); | |
a3203465 | 9559 | return NULL_TREE; |
8d08fdba MS |
9560 | } |
9561 | else if (quals) | |
9562 | { | |
9563 | if (ctype == NULL_TREE) | |
9564 | { | |
9565 | if (TREE_CODE (type) != METHOD_TYPE) | |
9566 | cp_error_at ("invalid type qualifier for non-method type", decl); | |
9567 | else | |
9568 | ctype = TYPE_METHOD_BASETYPE (type); | |
9569 | } | |
9570 | if (ctype != NULL_TREE) | |
9571 | grok_method_quals (ctype, decl, quals); | |
9572 | } | |
9573 | ||
9574 | if (RIDBIT_SETP (RID_SIGNED, specbits) | |
9575 | || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
9576 | C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; | |
9577 | ||
9578 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
9579 | { | |
9580 | error ("non-object member `%s' cannot be declared mutable", name); | |
9581 | } | |
9582 | ||
c91a56d2 MS |
9583 | bad_specifiers (decl, "type", virtualp, quals != NULL_TREE, |
9584 | inlinep, friendp, raises != NULL_TREE); | |
9585 | ||
9586 | if (initialized) | |
9587 | error ("typedef declaration includes an initializer"); | |
9588 | ||
8d08fdba MS |
9589 | return decl; |
9590 | } | |
9591 | ||
9592 | /* Detect the case of an array type of unspecified size | |
9593 | which came, as such, direct from a typedef name. | |
9594 | We must copy the type, so that each identifier gets | |
9595 | a distinct type, so that each identifier's size can be | |
9596 | controlled separately by its own initializer. */ | |
9597 | ||
9598 | if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE | |
9599 | && TYPE_DOMAIN (type) == NULL_TREE) | |
9600 | { | |
9601 | type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); | |
9602 | } | |
9603 | ||
9604 | /* If this is a type name (such as, in a cast or sizeof), | |
9605 | compute the type and return it now. */ | |
9606 | ||
9607 | if (decl_context == TYPENAME) | |
9608 | { | |
9609 | /* Note that the grammar rejects storage classes | |
9610 | in typenames, fields or parameters. */ | |
9611 | if (constp || volatilep) | |
a703fb38 KG |
9612 | { |
9613 | if (IS_SIGNATURE (type)) | |
9614 | error ("`const' or `volatile' specified with signature type"); | |
9615 | else | |
9616 | type = cp_build_type_variant (type, constp, volatilep); | |
9617 | } | |
8d08fdba MS |
9618 | |
9619 | /* Special case: "friend class foo" looks like a TYPENAME context. */ | |
9620 | if (friendp) | |
9621 | { | |
b7484fbe MS |
9622 | if (volatilep) |
9623 | { | |
9624 | cp_error ("`volatile' specified for friend class declaration"); | |
9625 | volatilep = 0; | |
9626 | } | |
9627 | if (inlinep) | |
9628 | { | |
9629 | cp_error ("`inline' specified for friend class declaration"); | |
9630 | inlinep = 0; | |
9631 | } | |
9632 | ||
9633 | /* Only try to do this stuff if we didn't already give up. */ | |
9634 | if (type != integer_type_node) | |
9635 | { | |
9636 | /* A friendly class? */ | |
9637 | if (current_class_type) | |
9638 | make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type)); | |
9639 | else | |
9640 | error ("trying to make class `%s' a friend of global scope", | |
9641 | TYPE_NAME_STRING (type)); | |
9642 | type = void_type_node; | |
9643 | } | |
8d08fdba MS |
9644 | } |
9645 | else if (quals) | |
9646 | { | |
8d08fdba | 9647 | tree dummy = build_decl (TYPE_DECL, declarator, type); |
8d08fdba MS |
9648 | if (ctype == NULL_TREE) |
9649 | { | |
9650 | my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); | |
9651 | ctype = TYPE_METHOD_BASETYPE (type); | |
9652 | } | |
9653 | grok_method_quals (ctype, dummy, quals); | |
9654 | type = TREE_TYPE (dummy); | |
9655 | } | |
9656 | ||
9657 | return type; | |
9658 | } | |
9659 | else if (declarator == NULL_TREE && decl_context != PARM | |
db5ae43f | 9660 | && decl_context != CATCHPARM |
8d08fdba MS |
9661 | && TREE_CODE (type) != UNION_TYPE |
9662 | && ! bitfield) | |
9663 | { | |
9664 | cp_error ("abstract declarator `%T' used as declaration", type); | |
9665 | declarator = make_anon_name (); | |
9666 | } | |
9667 | ||
9668 | /* `void' at top level (not within pointer) | |
9669 | is allowed only in typedefs or type names. | |
9670 | We don't complain about parms either, but that is because | |
9671 | a better error message can be made later. */ | |
9672 | ||
9673 | if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM) | |
9674 | { | |
b7484fbe MS |
9675 | if (! declarator) |
9676 | error ("unnamed variable or field declared void"); | |
9677 | else if (TREE_CODE (declarator) == IDENTIFIER_NODE) | |
8d08fdba MS |
9678 | { |
9679 | if (IDENTIFIER_OPNAME_P (declarator)) | |
8d08fdba | 9680 | my_friendly_abort (356); |
8d08fdba MS |
9681 | else |
9682 | error ("variable or field `%s' declared void", name); | |
9683 | } | |
9684 | else | |
9685 | error ("variable or field declared void"); | |
9686 | type = integer_type_node; | |
9687 | } | |
9688 | ||
9689 | /* Now create the decl, which may be a VAR_DECL, a PARM_DECL | |
9690 | or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ | |
9691 | ||
9692 | { | |
9693 | register tree decl; | |
9694 | ||
9695 | if (decl_context == PARM) | |
9696 | { | |
8d08fdba MS |
9697 | if (ctype) |
9698 | error ("cannot use `::' in parameter declaration"); | |
9699 | ||
9700 | /* A parameter declared as an array of T is really a pointer to T. | |
9701 | One declared as a function is really a pointer to a function. | |
39211cd5 | 9702 | One declared as a member is really a pointer to member. */ |
8d08fdba MS |
9703 | |
9704 | if (TREE_CODE (type) == ARRAY_TYPE) | |
9705 | { | |
e92cc029 | 9706 | /* Transfer const-ness of array into that of type pointed to. */ |
39211cd5 | 9707 | type = build_pointer_type |
f376e137 | 9708 | (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); |
39211cd5 | 9709 | volatilep = constp = 0; |
8d08fdba MS |
9710 | } |
9711 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
9712 | type = build_pointer_type (type); | |
9713 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
9714 | type = build_pointer_type (type); | |
b7484fbe MS |
9715 | else if (type == void_type_node && declarator) |
9716 | { | |
9717 | error ("declaration of `%s' as void", name); | |
9718 | return NULL_TREE; | |
9719 | } | |
8d08fdba | 9720 | |
e349ee73 | 9721 | decl = build_decl (PARM_DECL, declarator, complete_type (type)); |
8d08fdba MS |
9722 | |
9723 | bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, | |
9724 | inlinep, friendp, raises != NULL_TREE); | |
9725 | if (current_class_type | |
9726 | && IS_SIGNATURE (current_class_type)) | |
9727 | { | |
9728 | if (inlinep) | |
9729 | error ("parameter of signature member function declared `inline'"); | |
9730 | if (RIDBIT_SETP (RID_AUTO, specbits)) | |
9731 | error ("parameter of signature member function declared `auto'"); | |
9732 | if (RIDBIT_SETP (RID_REGISTER, specbits)) | |
9733 | error ("parameter of signature member function declared `register'"); | |
9734 | } | |
9735 | ||
9736 | /* Compute the type actually passed in the parmlist, | |
9737 | for the case where there is no prototype. | |
9738 | (For example, shorts and chars are passed as ints.) | |
9739 | When there is a prototype, this is overridden later. */ | |
9740 | ||
39211cd5 | 9741 | DECL_ARG_TYPE (decl) = type_promotes_to (type); |
8d08fdba MS |
9742 | } |
9743 | else if (decl_context == FIELD) | |
9744 | { | |
9745 | if (type == error_mark_node) | |
9746 | { | |
9747 | /* Happens when declaring arrays of sizes which | |
9748 | are error_mark_node, for example. */ | |
9749 | decl = NULL_TREE; | |
9750 | } | |
9751 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
9752 | { | |
9753 | int publicp = 0; | |
e1467ff2 | 9754 | tree function_context; |
8d08fdba | 9755 | |
72b7eeff MS |
9756 | /* We catch the others as conflicts with the builtin |
9757 | typedefs. */ | |
9758 | if (friendp && declarator == ridpointers[(int) RID_SIGNED]) | |
9759 | { | |
9760 | cp_error ("function `%D' cannot be declared friend", | |
9761 | declarator); | |
9762 | friendp = 0; | |
9763 | } | |
9764 | ||
8d08fdba MS |
9765 | if (friendp == 0) |
9766 | { | |
9767 | if (ctype == NULL_TREE) | |
9768 | ctype = current_class_type; | |
9769 | ||
9770 | if (ctype == NULL_TREE) | |
9771 | { | |
9772 | cp_error ("can't make `%D' into a method -- not in a class", | |
9773 | declarator); | |
9774 | return void_type_node; | |
9775 | } | |
9776 | ||
9777 | /* ``A union may [ ... ] not [ have ] virtual functions.'' | |
9778 | ARM 9.5 */ | |
9779 | if (virtualp && TREE_CODE (ctype) == UNION_TYPE) | |
9780 | { | |
9781 | cp_error ("function `%D' declared virtual inside a union", | |
9782 | declarator); | |
9783 | return void_type_node; | |
9784 | } | |
9785 | ||
9786 | if (declarator == ansi_opname[(int) NEW_EXPR] | |
a28e3c7f MS |
9787 | || declarator == ansi_opname[(int) VEC_NEW_EXPR] |
9788 | || declarator == ansi_opname[(int) DELETE_EXPR] | |
9789 | || declarator == ansi_opname[(int) VEC_DELETE_EXPR]) | |
8d08fdba MS |
9790 | { |
9791 | if (virtualp) | |
9792 | { | |
9793 | cp_error ("`%D' cannot be declared virtual, since it is always static", | |
9794 | declarator); | |
9795 | virtualp = 0; | |
9796 | } | |
9797 | } | |
9798 | else if (staticp < 2) | |
9799 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
9800 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9801 | } | |
9802 | ||
9803 | /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ | |
e1467ff2 MM |
9804 | function_context = (ctype != NULL_TREE) ? |
9805 | hack_decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE; | |
9806 | publicp = (! friendp || ! staticp) | |
9807 | && function_context == NULL_TREE; | |
386b8a85 JM |
9808 | decl = grokfndecl (ctype, type, |
9809 | TREE_CODE (declarator) != TEMPLATE_ID_EXPR | |
9810 | ? declarator : dname, | |
9811 | declarator, | |
f30432d7 | 9812 | virtualp, flags, quals, raises, attrlist, |
386b8a85 JM |
9813 | friendp ? -1 : 0, friendp, publicp, inlinep, |
9814 | funcdef_flag, template_count); | |
f0e01782 MS |
9815 | if (decl == NULL_TREE) |
9816 | return NULL_TREE; | |
6125f3be DE |
9817 | #if 0 |
9818 | /* This clobbers the attrs stored in `decl' from `attrlist'. */ | |
9819 | /* The decl and setting of decl_machine_attr is also turned off. */ | |
71851aaa | 9820 | decl = build_decl_attribute_variant (decl, decl_machine_attr); |
6125f3be | 9821 | #endif |
f0e01782 | 9822 | |
db5ae43f MS |
9823 | if (explicitp == 2) |
9824 | DECL_NONCONVERTING_P (decl) = 1; | |
8d08fdba MS |
9825 | } |
9826 | else if (TREE_CODE (type) == METHOD_TYPE) | |
9827 | { | |
faae18ab MS |
9828 | /* We only get here for friend declarations of |
9829 | members of other classes. */ | |
8d08fdba MS |
9830 | /* All method decls are public, so tell grokfndecl to set |
9831 | TREE_PUBLIC, also. */ | |
386b8a85 | 9832 | decl = grokfndecl (ctype, type, declarator, declarator, |
f30432d7 | 9833 | virtualp, flags, quals, raises, attrlist, |
386b8a85 JM |
9834 | friendp ? -1 : 0, friendp, 1, 0, funcdef_flag, |
9835 | template_count); | |
f0e01782 MS |
9836 | if (decl == NULL_TREE) |
9837 | return NULL_TREE; | |
8d08fdba | 9838 | } |
5566b478 MS |
9839 | else if (!staticp && ! processing_template_decl |
9840 | && TYPE_SIZE (complete_type (type)) == NULL_TREE | |
8d08fdba MS |
9841 | && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) |
9842 | { | |
b7484fbe MS |
9843 | if (declarator) |
9844 | cp_error ("field `%D' has incomplete type", declarator); | |
9845 | else | |
9846 | cp_error ("name `%T' has incomplete type", type); | |
8d08fdba MS |
9847 | |
9848 | /* If we're instantiating a template, tell them which | |
9849 | instantiation made the field's type be incomplete. */ | |
9850 | if (current_class_type | |
9851 | && TYPE_NAME (current_class_type) | |
d2e5ee5c | 9852 | && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type)) |
8d08fdba MS |
9853 | && declspecs && TREE_VALUE (declspecs) |
9854 | && TREE_TYPE (TREE_VALUE (declspecs)) == type) | |
db5ae43f MS |
9855 | cp_error (" in instantiation of template `%T'", |
9856 | current_class_type); | |
9857 | ||
8d08fdba MS |
9858 | type = error_mark_node; |
9859 | decl = NULL_TREE; | |
9860 | } | |
9861 | else | |
9862 | { | |
9863 | if (friendp) | |
9864 | { | |
9865 | error ("`%s' is neither function nor method; cannot be declared friend", | |
9866 | IDENTIFIER_POINTER (declarator)); | |
9867 | friendp = 0; | |
9868 | } | |
9869 | decl = NULL_TREE; | |
9870 | } | |
9871 | ||
9872 | if (friendp) | |
9873 | { | |
9874 | /* Friends are treated specially. */ | |
9875 | if (ctype == current_class_type) | |
9876 | warning ("member functions are implicitly friends of their class"); | |
9877 | else | |
9878 | { | |
9879 | tree t = NULL_TREE; | |
9880 | if (decl && DECL_NAME (decl)) | |
9881 | t = do_friend (ctype, declarator, decl, | |
5566b478 MS |
9882 | last_function_parms, flags, quals, |
9883 | funcdef_flag); | |
8d08fdba MS |
9884 | if (t && funcdef_flag) |
9885 | return t; | |
9886 | ||
9887 | return void_type_node; | |
9888 | } | |
9889 | } | |
9890 | ||
9891 | /* Structure field. It may not be a function, except for C++ */ | |
9892 | ||
9893 | if (decl == NULL_TREE) | |
9894 | { | |
8d08fdba MS |
9895 | if (initialized) |
9896 | { | |
3ac3d9ea MM |
9897 | if (!staticp) |
9898 | { | |
9899 | /* An attempt is being made to initialize a non-static | |
9900 | member. But, from [class.mem]: | |
9901 | ||
9902 | 4 A member-declarator can contain a | |
9903 | constant-initializer only if it declares a static | |
9904 | member (_class.static_) of integral or enumeration | |
9905 | type, see _class.static.data_. | |
9906 | ||
9907 | This used to be relatively common practice, but | |
9908 | the rest of the compiler does not correctly | |
9909 | handle the initialization unless the member is | |
9910 | static so we make it static below. */ | |
9911 | cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'", | |
9912 | constp ? "const member" : "member", | |
9913 | declarator); | |
9914 | cp_pedwarn ("making `%D' static", declarator); | |
9915 | staticp = 1; | |
9916 | } | |
9917 | ||
a0a33927 MS |
9918 | /* Motion 10 at San Diego: If a static const integral data |
9919 | member is initialized with an integral constant | |
9920 | expression, the initializer may appear either in the | |
9921 | declaration (within the class), or in the definition, | |
9922 | but not both. If it appears in the class, the member is | |
9923 | a member constant. The file-scope definition is always | |
9924 | required. */ | |
3ac3d9ea MM |
9925 | if (! constp) |
9926 | /* According to Mike Stump, we generate bad code for | |
9927 | this case, so we might as well always make it an | |
9928 | error. */ | |
9929 | cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'", | |
9930 | declarator); | |
9931 | ||
9932 | if (pedantic && ! INTEGRAL_TYPE_P (type)) | |
9933 | cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", declarator, type); | |
8d08fdba MS |
9934 | } |
9935 | ||
3ac3d9ea | 9936 | if (staticp) |
8d08fdba | 9937 | { |
f30432d7 | 9938 | /* ANSI C++ Apr '95 wp 9.2 */ |
3ac3d9ea | 9939 | if (declarator == current_class_name) |
f30432d7 MS |
9940 | cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class", |
9941 | declarator); | |
9942 | ||
8d08fdba MS |
9943 | /* C++ allows static class members. |
9944 | All other work for this is done by grokfield. | |
9945 | This VAR_DECL is built by build_lang_field_decl. | |
9946 | All other VAR_DECLs are built by build_decl. */ | |
9947 | decl = build_lang_field_decl (VAR_DECL, declarator, type); | |
5b605f68 MS |
9948 | TREE_STATIC (decl) = 1; |
9949 | /* In class context, 'static' means public access. */ | |
3ac3d9ea | 9950 | TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = 1; |
8d08fdba MS |
9951 | } |
9952 | else | |
9953 | { | |
9954 | decl = build_lang_field_decl (FIELD_DECL, declarator, type); | |
9955 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
9956 | { | |
9957 | DECL_MUTABLE_P (decl) = 1; | |
9958 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
9959 | } | |
9960 | } | |
9961 | ||
9962 | bad_specifiers (decl, "field", virtualp, quals != NULL_TREE, | |
9963 | inlinep, friendp, raises != NULL_TREE); | |
9964 | } | |
9965 | } | |
9966 | else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | |
9967 | { | |
386b8a85 | 9968 | tree original_name; |
8d08fdba MS |
9969 | int publicp = 0; |
9970 | ||
9971 | if (! declarator) | |
9972 | return NULL_TREE; | |
9973 | ||
386b8a85 JM |
9974 | if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) |
9975 | original_name = dname; | |
9976 | else | |
9977 | original_name = declarator; | |
9978 | ||
8926095f MS |
9979 | if (RIDBIT_SETP (RID_AUTO, specbits)) |
9980 | error ("storage class `auto' invalid for function `%s'", name); | |
9981 | else if (RIDBIT_SETP (RID_REGISTER, specbits)) | |
9982 | error ("storage class `register' invalid for function `%s'", name); | |
8d08fdba MS |
9983 | |
9984 | /* Function declaration not at top level. | |
9985 | Storage classes other than `extern' are not allowed | |
9986 | and `extern' makes no difference. */ | |
a9aedbc2 | 9987 | if (! toplevel_bindings_p () |
8926095f MS |
9988 | && (RIDBIT_SETP (RID_STATIC, specbits) |
9989 | || RIDBIT_SETP (RID_INLINE, specbits)) | |
8d08fdba | 9990 | && pedantic) |
8926095f MS |
9991 | { |
9992 | if (RIDBIT_SETP (RID_STATIC, specbits)) | |
9993 | pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name); | |
9994 | else | |
9995 | pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name); | |
9996 | } | |
9997 | ||
8d08fdba MS |
9998 | if (ctype == NULL_TREE) |
9999 | { | |
10000 | if (virtualp) | |
10001 | { | |
10002 | error ("virtual non-class function `%s'", name); | |
10003 | virtualp = 0; | |
10004 | } | |
10005 | ||
10006 | if (current_lang_name == lang_name_cplusplus | |
5156628f | 10007 | && ! processing_template_decl |
8d08fdba MS |
10008 | && ! (IDENTIFIER_LENGTH (original_name) == 4 |
10009 | && IDENTIFIER_POINTER (original_name)[0] == 'm' | |
10010 | && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0) | |
10011 | && ! (IDENTIFIER_LENGTH (original_name) > 10 | |
10012 | && IDENTIFIER_POINTER (original_name)[0] == '_' | |
10013 | && IDENTIFIER_POINTER (original_name)[1] == '_' | |
10014 | && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0)) | |
8926095f | 10015 | /* Plain overloading: will not be grok'd by grokclassfn. */ |
386b8a85 JM |
10016 | if (name_mangling_version < 1 |
10017 | || TREE_CODE (declarator) != TEMPLATE_ID_EXPR) | |
10018 | declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0); | |
8d08fdba MS |
10019 | } |
10020 | else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2) | |
10021 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
10022 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
10023 | ||
eb66be0e | 10024 | /* Record presence of `static'. */ |
faae18ab | 10025 | publicp = (ctype != NULL_TREE |
a9aedbc2 | 10026 | || RIDBIT_SETP (RID_EXTERN, specbits) |
eb66be0e | 10027 | || !RIDBIT_SETP (RID_STATIC, specbits)); |
8d08fdba | 10028 | |
386b8a85 | 10029 | decl = grokfndecl (ctype, type, original_name, declarator, |
f30432d7 | 10030 | virtualp, flags, quals, raises, attrlist, |
75650646 | 10031 | 1, friendp, |
386b8a85 JM |
10032 | publicp, inlinep, funcdef_flag, |
10033 | template_count); | |
f0e01782 MS |
10034 | if (decl == NULL_TREE) |
10035 | return NULL_TREE; | |
8d08fdba | 10036 | |
386b8a85 | 10037 | if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c |
71cc65bd | 10038 | && (! DECL_USE_TEMPLATE (decl) || |
386b8a85 | 10039 | name_mangling_version < 1)) |
30394414 JM |
10040 | #if 0 |
10041 | /* XXX is support for the old __ns_ mangling really needed? MvL */ | |
6060a796 | 10042 | DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator); |
30394414 JM |
10043 | #else |
10044 | DECL_ASSEMBLER_NAME (decl) = declarator; | |
10045 | #endif | |
386b8a85 | 10046 | |
8d08fdba MS |
10047 | if (staticp == 1) |
10048 | { | |
10049 | int illegal_static = 0; | |
10050 | ||
10051 | /* Don't allow a static member function in a class, and forbid | |
10052 | declaring main to be static. */ | |
10053 | if (TREE_CODE (type) == METHOD_TYPE) | |
10054 | { | |
00595019 | 10055 | cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl); |
8d08fdba MS |
10056 | illegal_static = 1; |
10057 | } | |
8d08fdba MS |
10058 | else if (current_function_decl) |
10059 | { | |
10060 | /* FIXME need arm citation */ | |
10061 | error ("cannot declare static function inside another function"); | |
10062 | illegal_static = 1; | |
10063 | } | |
10064 | ||
10065 | if (illegal_static) | |
10066 | { | |
10067 | staticp = 0; | |
10068 | RIDBIT_RESET (RID_STATIC, specbits); | |
10069 | } | |
10070 | } | |
8d08fdba MS |
10071 | } |
10072 | else | |
10073 | { | |
10074 | /* It's a variable. */ | |
10075 | ||
db5ae43f MS |
10076 | if (decl_context == CATCHPARM) |
10077 | { | |
10078 | if (ctype) | |
10079 | { | |
10080 | ctype = NULL_TREE; | |
10081 | error ("cannot use `::' in parameter declaration"); | |
10082 | } | |
10083 | ||
10084 | /* A parameter declared as an array of T is really a pointer to T. | |
10085 | One declared as a function is really a pointer to a function. | |
10086 | One declared as a member is really a pointer to member. */ | |
10087 | ||
10088 | if (TREE_CODE (type) == ARRAY_TYPE) | |
10089 | { | |
e92cc029 MS |
10090 | /* Transfer const-ness of array into that of type |
10091 | pointed to. */ | |
db5ae43f MS |
10092 | type = build_pointer_type |
10093 | (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); | |
10094 | volatilep = constp = 0; | |
10095 | } | |
10096 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
10097 | type = build_pointer_type (type); | |
10098 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
10099 | type = build_pointer_type (type); | |
10100 | } | |
10101 | ||
8d08fdba | 10102 | /* An uninitialized decl with `extern' is a reference. */ |
d2e5ee5c | 10103 | decl = grokvardecl (type, declarator, &specbits, initialized, constp); |
8d08fdba MS |
10104 | bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, |
10105 | inlinep, friendp, raises != NULL_TREE); | |
10106 | ||
10107 | if (ctype) | |
10108 | { | |
f0e01782 | 10109 | DECL_CONTEXT (decl) = ctype; |
8d08fdba MS |
10110 | if (staticp == 1) |
10111 | { | |
f30432d7 | 10112 | cp_pedwarn ("static member `%D' re-declared as static", decl); |
8d08fdba MS |
10113 | staticp = 0; |
10114 | RIDBIT_RESET (RID_STATIC, specbits); | |
10115 | } | |
b7484fbe MS |
10116 | if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl)) |
10117 | { | |
10118 | cp_error ("static member `%D' declared `register'", decl); | |
10119 | RIDBIT_RESET (RID_REGISTER, specbits); | |
10120 | } | |
f30432d7 | 10121 | if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic) |
8d08fdba | 10122 | { |
f30432d7 MS |
10123 | cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage", |
10124 | decl); | |
8d08fdba MS |
10125 | RIDBIT_RESET (RID_EXTERN, specbits); |
10126 | } | |
10127 | } | |
10128 | } | |
10129 | ||
10130 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
10131 | { | |
10132 | error ("`%s' cannot be declared mutable", name); | |
10133 | } | |
10134 | ||
10135 | /* Record `register' declaration for warnings on & | |
10136 | and in case doing stupid register allocation. */ | |
10137 | ||
10138 | if (RIDBIT_SETP (RID_REGISTER, specbits)) | |
10139 | DECL_REGISTER (decl) = 1; | |
10140 | ||
8926095f MS |
10141 | if (RIDBIT_SETP (RID_EXTERN, specbits)) |
10142 | DECL_THIS_EXTERN (decl) = 1; | |
10143 | ||
faae18ab MS |
10144 | if (RIDBIT_SETP (RID_STATIC, specbits)) |
10145 | DECL_THIS_STATIC (decl) = 1; | |
10146 | ||
8d08fdba MS |
10147 | /* Record constancy and volatility. */ |
10148 | ||
10149 | if (constp) | |
10150 | TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE; | |
10151 | if (volatilep) | |
10152 | { | |
10153 | TREE_SIDE_EFFECTS (decl) = 1; | |
10154 | TREE_THIS_VOLATILE (decl) = 1; | |
10155 | } | |
10156 | ||
10157 | return decl; | |
10158 | } | |
10159 | } | |
10160 | \f | |
10161 | /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist. | |
10162 | An empty exprlist is a parmlist. An exprlist which | |
10163 | contains only identifiers at the global level | |
10164 | is a parmlist. Otherwise, it is an exprlist. */ | |
e92cc029 | 10165 | |
8d08fdba MS |
10166 | int |
10167 | parmlist_is_exprlist (exprs) | |
10168 | tree exprs; | |
10169 | { | |
10170 | if (exprs == NULL_TREE || TREE_PARMLIST (exprs)) | |
10171 | return 0; | |
10172 | ||
a9aedbc2 | 10173 | if (toplevel_bindings_p ()) |
8d08fdba MS |
10174 | { |
10175 | /* At the global level, if these are all identifiers, | |
10176 | then it is a parmlist. */ | |
10177 | while (exprs) | |
10178 | { | |
10179 | if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE) | |
10180 | return 1; | |
10181 | exprs = TREE_CHAIN (exprs); | |
10182 | } | |
10183 | return 0; | |
10184 | } | |
10185 | return 1; | |
10186 | } | |
10187 | ||
10188 | /* Subroutine of `grokparms'. In a fcn definition, arg types must | |
10189 | be complete. | |
10190 | ||
10191 | C++: also subroutine of `start_function'. */ | |
e92cc029 | 10192 | |
8d08fdba MS |
10193 | static void |
10194 | require_complete_types_for_parms (parms) | |
10195 | tree parms; | |
10196 | { | |
5566b478 MS |
10197 | if (processing_template_decl) |
10198 | return; | |
10199 | ||
8d08fdba MS |
10200 | while (parms) |
10201 | { | |
10202 | tree type = TREE_TYPE (parms); | |
5566b478 | 10203 | if (TYPE_SIZE (complete_type (type)) == NULL_TREE) |
8d08fdba MS |
10204 | { |
10205 | if (DECL_NAME (parms)) | |
10206 | error ("parameter `%s' has incomplete type", | |
10207 | IDENTIFIER_POINTER (DECL_NAME (parms))); | |
10208 | else | |
10209 | error ("parameter has incomplete type"); | |
10210 | TREE_TYPE (parms) = error_mark_node; | |
10211 | } | |
10212 | #if 0 | |
10213 | /* If the arg types are incomplete in a declaration, | |
10214 | they must include undefined tags. | |
10215 | These tags can never be defined in the scope of the declaration, | |
10216 | so the types can never be completed, | |
10217 | and no call can be compiled successfully. */ | |
10218 | /* This is not the right behavior for C++, but not having | |
10219 | it is also probably wrong. */ | |
10220 | else | |
10221 | { | |
10222 | /* Now warn if is a pointer to an incomplete type. */ | |
10223 | while (TREE_CODE (type) == POINTER_TYPE | |
10224 | || TREE_CODE (type) == REFERENCE_TYPE) | |
10225 | type = TREE_TYPE (type); | |
10226 | type = TYPE_MAIN_VARIANT (type); | |
10227 | if (TYPE_SIZE (type) == NULL_TREE) | |
10228 | { | |
10229 | if (DECL_NAME (parm) != NULL_TREE) | |
10230 | warning ("parameter `%s' points to incomplete type", | |
10231 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
10232 | else | |
10233 | warning ("parameter points to incomplete type"); | |
10234 | } | |
10235 | } | |
10236 | #endif | |
10237 | parms = TREE_CHAIN (parms); | |
10238 | } | |
10239 | } | |
10240 | ||
10241 | /* Decode the list of parameter types for a function type. | |
10242 | Given the list of things declared inside the parens, | |
10243 | return a list of types. | |
10244 | ||
10245 | The list we receive can have three kinds of elements: | |
10246 | an IDENTIFIER_NODE for names given without types, | |
10247 | a TREE_LIST node for arguments given as typespecs or names with typespecs, | |
10248 | or void_type_node, to mark the end of an argument list | |
10249 | when additional arguments are not permitted (... was not used). | |
10250 | ||
10251 | FUNCDEF_FLAG is nonzero for a function definition, 0 for | |
10252 | a mere declaration. A nonempty identifier-list gets an error message | |
10253 | when FUNCDEF_FLAG is zero. | |
10254 | If FUNCDEF_FLAG is 1, then parameter types must be complete. | |
10255 | If FUNCDEF_FLAG is -1, then parameter types may be incomplete. | |
10256 | ||
10257 | If all elements of the input list contain types, | |
10258 | we return a list of the types. | |
10259 | If all elements contain no type (except perhaps a void_type_node | |
10260 | at the end), we return a null list. | |
10261 | If some have types and some do not, it is an error, and we | |
10262 | return a null list. | |
10263 | ||
10264 | Also set last_function_parms to either | |
10265 | a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs. | |
10266 | A list of names is converted to a chain of PARM_DECLs | |
10267 | by store_parm_decls so that ultimately it is always a chain of decls. | |
10268 | ||
10269 | Note that in C++, parameters can take default values. These default | |
10270 | values are in the TREE_PURPOSE field of the TREE_LIST. It is | |
10271 | an error to specify default values which are followed by parameters | |
10272 | that have no default values, or an ELLIPSES. For simplicities sake, | |
10273 | only parameters which are specified with their types can take on | |
10274 | default values. */ | |
10275 | ||
10276 | static tree | |
10277 | grokparms (first_parm, funcdef_flag) | |
10278 | tree first_parm; | |
10279 | int funcdef_flag; | |
10280 | { | |
10281 | tree result = NULL_TREE; | |
10282 | tree decls = NULL_TREE; | |
10283 | ||
10284 | if (first_parm != NULL_TREE | |
10285 | && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) | |
10286 | { | |
10287 | if (! funcdef_flag) | |
10288 | pedwarn ("parameter names (without types) in function declaration"); | |
10289 | last_function_parms = first_parm; | |
10290 | return NULL_TREE; | |
10291 | } | |
10292 | else if (first_parm != NULL_TREE | |
10293 | && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST | |
10294 | && TREE_VALUE (first_parm) != void_type_node) | |
10295 | my_friendly_abort (145); | |
10296 | else | |
10297 | { | |
10298 | /* Types were specified. This is a list of declarators | |
10299 | each represented as a TREE_LIST node. */ | |
10300 | register tree parm, chain; | |
5566b478 | 10301 | int any_init = 0, any_error = 0; |
8d08fdba MS |
10302 | |
10303 | if (first_parm != NULL_TREE) | |
10304 | { | |
10305 | tree last_result = NULL_TREE; | |
10306 | tree last_decl = NULL_TREE; | |
10307 | ||
10308 | for (parm = first_parm; parm != NULL_TREE; parm = chain) | |
10309 | { | |
a703fb38 | 10310 | tree type = NULL_TREE, list_node = parm; |
8d08fdba MS |
10311 | register tree decl = TREE_VALUE (parm); |
10312 | tree init = TREE_PURPOSE (parm); | |
10313 | ||
10314 | chain = TREE_CHAIN (parm); | |
10315 | /* @@ weak defense against parse errors. */ | |
10316 | if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST) | |
10317 | { | |
10318 | /* Give various messages as the need arises. */ | |
10319 | if (TREE_CODE (decl) == STRING_CST) | |
fc378698 | 10320 | cp_error ("invalid string constant `%E'", decl); |
8d08fdba MS |
10321 | else if (TREE_CODE (decl) == INTEGER_CST) |
10322 | error ("invalid integer constant in parameter list, did you forget to give parameter name?"); | |
10323 | continue; | |
10324 | } | |
10325 | ||
10326 | if (decl != void_type_node) | |
10327 | { | |
8d08fdba MS |
10328 | decl = grokdeclarator (TREE_VALUE (decl), |
10329 | TREE_PURPOSE (decl), | |
f30432d7 | 10330 | PARM, init != NULL_TREE, |
c11b6f21 | 10331 | NULL_TREE); |
8d08fdba MS |
10332 | if (! decl) |
10333 | continue; | |
10334 | type = TREE_TYPE (decl); | |
10335 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
10336 | decl = void_type_node; | |
10337 | else if (TREE_CODE (type) == METHOD_TYPE) | |
10338 | { | |
10339 | if (DECL_NAME (decl)) | |
fc378698 | 10340 | /* Cannot use the decl here because |
8d08fdba | 10341 | we don't have DECL_CONTEXT set up yet. */ |
fc378698 MS |
10342 | cp_error ("parameter `%D' invalidly declared method type", |
10343 | DECL_NAME (decl)); | |
8d08fdba MS |
10344 | else |
10345 | error ("parameter invalidly declared method type"); | |
10346 | type = build_pointer_type (type); | |
10347 | TREE_TYPE (decl) = type; | |
10348 | } | |
10349 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
10350 | { | |
10351 | if (DECL_NAME (decl)) | |
fc378698 MS |
10352 | cp_error ("parameter `%D' invalidly declared offset type", |
10353 | DECL_NAME (decl)); | |
8d08fdba MS |
10354 | else |
10355 | error ("parameter invalidly declared offset type"); | |
10356 | type = build_pointer_type (type); | |
10357 | TREE_TYPE (decl) = type; | |
10358 | } | |
10359 | else if (TREE_CODE (type) == RECORD_TYPE | |
10360 | && TYPE_LANG_SPECIFIC (type) | |
10361 | && CLASSTYPE_ABSTRACT_VIRTUALS (type)) | |
10362 | { | |
10363 | abstract_virtuals_error (decl, type); | |
10364 | any_error = 1; /* seems like a good idea */ | |
10365 | } | |
10366 | else if (TREE_CODE (type) == RECORD_TYPE | |
10367 | && TYPE_LANG_SPECIFIC (type) | |
10368 | && IS_SIGNATURE (type)) | |
10369 | { | |
10370 | signature_error (decl, type); | |
10371 | any_error = 1; /* seems like a good idea */ | |
10372 | } | |
10373 | } | |
10374 | ||
10375 | if (decl == void_type_node) | |
10376 | { | |
10377 | if (result == NULL_TREE) | |
10378 | { | |
10379 | result = void_list_node; | |
10380 | last_result = result; | |
10381 | } | |
10382 | else | |
10383 | { | |
10384 | TREE_CHAIN (last_result) = void_list_node; | |
10385 | last_result = void_list_node; | |
10386 | } | |
8d08fdba MS |
10387 | if (chain |
10388 | && (chain != void_list_node || TREE_CHAIN (chain))) | |
10389 | error ("`void' in parameter list must be entire list"); | |
10390 | break; | |
10391 | } | |
10392 | ||
10393 | /* Since there is a prototype, args are passed in their own types. */ | |
10394 | DECL_ARG_TYPE (decl) = TREE_TYPE (decl); | |
10395 | #ifdef PROMOTE_PROTOTYPES | |
10396 | if ((TREE_CODE (type) == INTEGER_TYPE | |
10397 | || TREE_CODE (type) == ENUMERAL_TYPE) | |
10398 | && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) | |
10399 | DECL_ARG_TYPE (decl) = integer_type_node; | |
10400 | #endif | |
10401 | if (!any_error) | |
10402 | { | |
10403 | if (init) | |
10404 | { | |
10405 | any_init++; | |
10406 | if (TREE_CODE (init) == SAVE_EXPR) | |
10407 | PARM_DECL_EXPR (init) = 1; | |
5156628f | 10408 | else if (processing_template_decl) |
5566b478 | 10409 | ; |
42976354 BK |
10410 | /* Unparsed default arg from in-class decl. */ |
10411 | else if (TREE_CODE (init) == DEFAULT_ARG) | |
10412 | ; | |
b7484fbe MS |
10413 | else if (TREE_CODE (init) == VAR_DECL |
10414 | || TREE_CODE (init) == PARM_DECL) | |
8d08fdba MS |
10415 | { |
10416 | if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init))) | |
10417 | { | |
10418 | /* ``Local variables may not be used in default | |
10419 | argument expressions.'' dpANSI C++ 8.2.6 */ | |
10420 | /* If extern int i; within a function is not | |
10421 | considered a local variable, then this code is | |
e92cc029 | 10422 | wrong. */ |
8d08fdba MS |
10423 | cp_error ("local variable `%D' may not be used as a default argument", init); |
10424 | any_error = 1; | |
10425 | } | |
10426 | else if (TREE_READONLY_DECL_P (init)) | |
10427 | init = decl_constant_value (init); | |
10428 | } | |
10429 | else | |
10430 | init = require_instantiated_type (type, init, integer_zero_node); | |
5156628f | 10431 | if (! processing_template_decl |
42976354 | 10432 | && TREE_CODE (init) != DEFAULT_ARG |
c11b6f21 | 10433 | && ! can_convert_arg (type, TREE_TYPE (init), init)) |
c73964b2 MS |
10434 | cp_pedwarn ("invalid type `%T' for default argument to `%#D'", |
10435 | TREE_TYPE (init), decl); | |
8d08fdba MS |
10436 | } |
10437 | } | |
10438 | else | |
10439 | init = NULL_TREE; | |
10440 | ||
10441 | if (decls == NULL_TREE) | |
10442 | { | |
10443 | decls = decl; | |
10444 | last_decl = decls; | |
10445 | } | |
10446 | else | |
10447 | { | |
10448 | TREE_CHAIN (last_decl) = decl; | |
10449 | last_decl = decl; | |
10450 | } | |
66f2e88d | 10451 | if (! current_function_decl && TREE_PERMANENT (list_node)) |
8d08fdba MS |
10452 | { |
10453 | TREE_PURPOSE (list_node) = init; | |
10454 | TREE_VALUE (list_node) = type; | |
10455 | TREE_CHAIN (list_node) = NULL_TREE; | |
10456 | } | |
10457 | else | |
10458 | list_node = saveable_tree_cons (init, type, NULL_TREE); | |
10459 | if (result == NULL_TREE) | |
10460 | { | |
10461 | result = list_node; | |
10462 | last_result = result; | |
10463 | } | |
10464 | else | |
10465 | { | |
10466 | TREE_CHAIN (last_result) = list_node; | |
10467 | last_result = list_node; | |
10468 | } | |
10469 | } | |
10470 | if (last_result) | |
10471 | TREE_CHAIN (last_result) = NULL_TREE; | |
10472 | /* If there are no parameters, and the function does not end | |
10473 | with `...', then last_decl will be NULL_TREE. */ | |
10474 | if (last_decl != NULL_TREE) | |
10475 | TREE_CHAIN (last_decl) = NULL_TREE; | |
10476 | } | |
10477 | } | |
10478 | ||
10479 | last_function_parms = decls; | |
10480 | ||
10481 | /* In a fcn definition, arg types must be complete. */ | |
10482 | if (funcdef_flag > 0) | |
10483 | require_complete_types_for_parms (last_function_parms); | |
10484 | ||
10485 | return result; | |
10486 | } | |
42976354 BK |
10487 | |
10488 | /* Called from the parser to update an element of TYPE_ARG_TYPES for some | |
10489 | FUNCTION_TYPE with the newly parsed version of its default argument, which | |
10490 | was previously digested as text. See snarf_defarg et al in lex.c. */ | |
10491 | ||
10492 | void | |
10493 | replace_defarg (arg, init) | |
10494 | tree arg, init; | |
10495 | { | |
aa5f3bad | 10496 | if (! processing_template_decl |
42976354 BK |
10497 | && ! can_convert_arg (TREE_VALUE (arg), TREE_TYPE (init), init)) |
10498 | cp_pedwarn ("invalid type `%T' for default argument to `%T'", | |
10499 | TREE_TYPE (init), TREE_VALUE (arg)); | |
10500 | TREE_PURPOSE (arg) = init; | |
10501 | } | |
8d08fdba | 10502 | \f |
c11b6f21 MS |
10503 | int |
10504 | copy_args_p (d) | |
10505 | tree d; | |
10506 | { | |
10507 | tree t = FUNCTION_ARG_CHAIN (d); | |
67437d5b JM |
10508 | if (DECL_CONSTRUCTOR_P (d) |
10509 | && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (d))) | |
10510 | t = TREE_CHAIN (t); | |
c11b6f21 MS |
10511 | if (t && TREE_CODE (TREE_VALUE (t)) == REFERENCE_TYPE |
10512 | && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (t))) | |
10513 | == DECL_CLASS_CONTEXT (d)) | |
10514 | && (TREE_CHAIN (t) == NULL_TREE | |
10515 | || TREE_CHAIN (t) == void_list_node | |
10516 | || TREE_PURPOSE (TREE_CHAIN (t)))) | |
10517 | return 1; | |
10518 | return 0; | |
10519 | } | |
10520 | ||
8d08fdba MS |
10521 | /* These memoizing functions keep track of special properties which |
10522 | a class may have. `grok_ctor_properties' notices whether a class | |
10523 | has a constructor of the form X(X&), and also complains | |
10524 | if the class has a constructor of the form X(X). | |
10525 | `grok_op_properties' takes notice of the various forms of | |
10526 | operator= which are defined, as well as what sorts of type conversion | |
10527 | may apply. Both functions take a FUNCTION_DECL as an argument. */ | |
e92cc029 | 10528 | |
a0a33927 | 10529 | int |
8d08fdba MS |
10530 | grok_ctor_properties (ctype, decl) |
10531 | tree ctype, decl; | |
10532 | { | |
10533 | tree parmtypes = FUNCTION_ARG_CHAIN (decl); | |
10534 | tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; | |
10535 | ||
10536 | /* When a type has virtual baseclasses, a magical first int argument is | |
10537 | added to any ctor so we can tell if the class has been initialized | |
10538 | yet. This could screw things up in this function, so we deliberately | |
10539 | ignore the leading int if we're in that situation. */ | |
10540 | if (parmtypes | |
10541 | && TREE_VALUE (parmtypes) == integer_type_node | |
10542 | && TYPE_USES_VIRTUAL_BASECLASSES (ctype)) | |
10543 | { | |
10544 | parmtypes = TREE_CHAIN (parmtypes); | |
10545 | parmtype = TREE_VALUE (parmtypes); | |
10546 | } | |
10547 | ||
10548 | if (TREE_CODE (parmtype) == REFERENCE_TYPE | |
10549 | && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype) | |
10550 | { | |
10551 | if (TREE_CHAIN (parmtypes) == NULL_TREE | |
10552 | || TREE_CHAIN (parmtypes) == void_list_node | |
10553 | || TREE_PURPOSE (TREE_CHAIN (parmtypes))) | |
10554 | { | |
10555 | TYPE_HAS_INIT_REF (ctype) = 1; | |
10556 | if (TYPE_READONLY (TREE_TYPE (parmtype))) | |
10557 | TYPE_HAS_CONST_INIT_REF (ctype) = 1; | |
10558 | } | |
10559 | else | |
10560 | TYPE_GETS_INIT_AGGR (ctype) = 1; | |
10561 | } | |
10562 | else if (TYPE_MAIN_VARIANT (parmtype) == ctype) | |
10563 | { | |
10564 | if (TREE_CHAIN (parmtypes) != NULL_TREE | |
10565 | && TREE_CHAIN (parmtypes) == void_list_node) | |
a0a33927 | 10566 | { |
f7da6097 | 10567 | cp_error ("invalid constructor; you probably meant `%T (const %T&)'", |
a0a33927 MS |
10568 | ctype, ctype); |
10569 | SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); | |
10570 | ||
10571 | return 0; | |
10572 | } | |
10573 | else | |
10574 | TYPE_GETS_INIT_AGGR (ctype) = 1; | |
8d08fdba MS |
10575 | } |
10576 | else if (TREE_CODE (parmtype) == VOID_TYPE | |
10577 | || TREE_PURPOSE (parmtypes) != NULL_TREE) | |
10578 | TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; | |
a0a33927 MS |
10579 | |
10580 | return 1; | |
8d08fdba MS |
10581 | } |
10582 | ||
10583 | /* An operator with this name can be either unary or binary. */ | |
e92cc029 | 10584 | |
a28e3c7f MS |
10585 | static int |
10586 | ambi_op_p (name) | |
8d08fdba MS |
10587 | tree name; |
10588 | { | |
10589 | return (name == ansi_opname [(int) INDIRECT_REF] | |
10590 | || name == ansi_opname [(int) ADDR_EXPR] | |
10591 | || name == ansi_opname [(int) NEGATE_EXPR] | |
10592 | || name == ansi_opname[(int) POSTINCREMENT_EXPR] | |
10593 | || name == ansi_opname[(int) POSTDECREMENT_EXPR] | |
10594 | || name == ansi_opname [(int) CONVERT_EXPR]); | |
10595 | } | |
10596 | ||
10597 | /* An operator with this name can only be unary. */ | |
e92cc029 | 10598 | |
a28e3c7f MS |
10599 | static int |
10600 | unary_op_p (name) | |
8d08fdba MS |
10601 | tree name; |
10602 | { | |
10603 | return (name == ansi_opname [(int) TRUTH_NOT_EXPR] | |
10604 | || name == ansi_opname [(int) BIT_NOT_EXPR] | |
10605 | || name == ansi_opname [(int) COMPONENT_REF] | |
10606 | || OPERATOR_TYPENAME_P (name)); | |
10607 | } | |
10608 | ||
10609 | /* Do a little sanity-checking on how they declared their operator. */ | |
e92cc029 | 10610 | |
5566b478 | 10611 | void |
8d08fdba MS |
10612 | grok_op_properties (decl, virtualp, friendp) |
10613 | tree decl; | |
10614 | int virtualp, friendp; | |
10615 | { | |
10616 | tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
10617 | int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); | |
10618 | tree name = DECL_NAME (decl); | |
8d08fdba | 10619 | |
a28e3c7f MS |
10620 | if (current_class_type == NULL_TREE) |
10621 | friendp = 1; | |
8d08fdba | 10622 | |
a28e3c7f MS |
10623 | if (! friendp) |
10624 | { | |
10625 | if (name == ansi_opname[(int) MODIFY_EXPR]) | |
10626 | TYPE_HAS_ASSIGNMENT (current_class_type) = 1; | |
10627 | else if (name == ansi_opname[(int) CALL_EXPR]) | |
10628 | TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1; | |
10629 | else if (name == ansi_opname[(int) ARRAY_REF]) | |
10630 | TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1; | |
10631 | else if (name == ansi_opname[(int) COMPONENT_REF] | |
10632 | || name == ansi_opname[(int) MEMBER_REF]) | |
10633 | TYPE_OVERLOADS_ARROW (current_class_type) = 1; | |
10634 | else if (name == ansi_opname[(int) NEW_EXPR]) | |
10635 | TYPE_GETS_NEW (current_class_type) |= 1; | |
10636 | else if (name == ansi_opname[(int) DELETE_EXPR]) | |
10637 | TYPE_GETS_DELETE (current_class_type) |= 1; | |
10638 | else if (name == ansi_opname[(int) VEC_NEW_EXPR]) | |
10639 | TYPE_GETS_NEW (current_class_type) |= 2; | |
10640 | else if (name == ansi_opname[(int) VEC_DELETE_EXPR]) | |
10641 | TYPE_GETS_DELETE (current_class_type) |= 2; | |
10642 | } | |
10643 | ||
10644 | if (name == ansi_opname[(int) NEW_EXPR] | |
10645 | || name == ansi_opname[(int) VEC_NEW_EXPR]) | |
8d08fdba | 10646 | { |
8d08fdba MS |
10647 | /* When the compiler encounters the definition of A::operator new, it |
10648 | doesn't look at the class declaration to find out if it's static. */ | |
a28e3c7f | 10649 | if (methodp) |
700f8a87 | 10650 | revert_static_member_fn (&decl, NULL, NULL); |
8d08fdba MS |
10651 | |
10652 | /* Take care of function decl if we had syntax errors. */ | |
10653 | if (argtypes == NULL_TREE) | |
beb53fb8 JM |
10654 | TREE_TYPE (decl) |
10655 | = build_function_type (ptr_type_node, | |
10656 | hash_tree_chain (integer_type_node, | |
10657 | void_list_node)); | |
8d08fdba | 10658 | else |
a28e3c7f | 10659 | TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); |
8d08fdba | 10660 | } |
a28e3c7f MS |
10661 | else if (name == ansi_opname[(int) DELETE_EXPR] |
10662 | || name == ansi_opname[(int) VEC_DELETE_EXPR]) | |
8d08fdba | 10663 | { |
a28e3c7f | 10664 | if (methodp) |
700f8a87 | 10665 | revert_static_member_fn (&decl, NULL, NULL); |
8d08fdba MS |
10666 | |
10667 | if (argtypes == NULL_TREE) | |
beb53fb8 JM |
10668 | TREE_TYPE (decl) |
10669 | = build_function_type (void_type_node, | |
10670 | hash_tree_chain (ptr_type_node, | |
10671 | void_list_node)); | |
8d08fdba | 10672 | else |
a28e3c7f MS |
10673 | { |
10674 | TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); | |
10675 | ||
10676 | if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR] | |
10677 | && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))) | |
10678 | != void_list_node)) | |
10679 | TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1; | |
10680 | } | |
8d08fdba | 10681 | } |
8d08fdba MS |
10682 | else |
10683 | { | |
10684 | /* An operator function must either be a non-static member function | |
10685 | or have at least one parameter of a class, a reference to a class, | |
10686 | an enumeration, or a reference to an enumeration. 13.4.0.6 */ | |
700f8a87 | 10687 | if (! methodp || DECL_STATIC_FUNCTION_P (decl)) |
8d08fdba MS |
10688 | { |
10689 | if (OPERATOR_TYPENAME_P (name) | |
10690 | || name == ansi_opname[(int) CALL_EXPR] | |
10691 | || name == ansi_opname[(int) MODIFY_EXPR] | |
10692 | || name == ansi_opname[(int) COMPONENT_REF] | |
10693 | || name == ansi_opname[(int) ARRAY_REF]) | |
10694 | cp_error ("`%D' must be a nonstatic member function", decl); | |
10695 | else | |
10696 | { | |
10697 | tree p = argtypes; | |
10698 | ||
700f8a87 MS |
10699 | if (DECL_STATIC_FUNCTION_P (decl)) |
10700 | cp_error ("`%D' must be either a non-static member function or a non-member function", decl); | |
10701 | ||
8d08fdba MS |
10702 | if (p) |
10703 | for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p)) | |
10704 | { | |
10705 | tree arg = TREE_VALUE (p); | |
10706 | if (TREE_CODE (arg) == REFERENCE_TYPE) | |
10707 | arg = TREE_TYPE (arg); | |
10708 | ||
10709 | /* This lets bad template code slip through. */ | |
10710 | if (IS_AGGR_TYPE (arg) | |
10711 | || TREE_CODE (arg) == ENUMERAL_TYPE | |
73b0fce8 KL |
10712 | || TREE_CODE (arg) == TEMPLATE_TYPE_PARM |
10713 | || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM) | |
8d08fdba MS |
10714 | goto foundaggr; |
10715 | } | |
10716 | cp_error | |
10717 | ("`%D' must have an argument of class or enumerated type", | |
10718 | decl); | |
10719 | foundaggr: | |
10720 | ; | |
10721 | } | |
10722 | } | |
10723 | ||
10724 | if (name == ansi_opname[(int) CALL_EXPR] | |
10725 | || name == ansi_opname[(int) METHOD_CALL_EXPR]) | |
10726 | return; /* no restrictions on args */ | |
10727 | ||
9a3b49ac | 10728 | if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl)) |
a0a33927 MS |
10729 | { |
10730 | tree t = TREE_TYPE (name); | |
10731 | if (TREE_CODE (t) == VOID_TYPE) | |
10732 | pedwarn ("void is not a valid type conversion operator"); | |
10733 | else if (! friendp) | |
10734 | { | |
10735 | int ref = (TREE_CODE (t) == REFERENCE_TYPE); | |
10736 | char *what = 0; | |
10737 | if (ref) | |
10738 | t = TYPE_MAIN_VARIANT (TREE_TYPE (t)); | |
10739 | ||
10740 | if (t == current_class_type) | |
10741 | what = "the same type"; | |
9a3b49ac | 10742 | /* Don't force t to be complete here. */ |
a0a33927 | 10743 | else if (IS_AGGR_TYPE (t) |
9a3b49ac | 10744 | && TYPE_SIZE (t) |
a0a33927 MS |
10745 | && DERIVED_FROM_P (t, current_class_type)) |
10746 | what = "a base class"; | |
10747 | ||
10748 | if (what) | |
10749 | warning ("conversion to %s%s will never use a type conversion operator", | |
10750 | ref ? "a reference to " : "", what); | |
10751 | } | |
10752 | } | |
10753 | ||
8d08fdba MS |
10754 | if (name == ansi_opname[(int) MODIFY_EXPR]) |
10755 | { | |
10756 | tree parmtype; | |
10757 | ||
10758 | if (list_length (argtypes) != 3 && methodp) | |
10759 | { | |
10760 | cp_error ("`%D' must take exactly one argument", decl); | |
10761 | return; | |
10762 | } | |
10763 | parmtype = TREE_VALUE (TREE_CHAIN (argtypes)); | |
10764 | ||
f0e01782 | 10765 | if (copy_assignment_arg_p (parmtype, virtualp) |
a28e3c7f | 10766 | && ! friendp) |
8d08fdba MS |
10767 | { |
10768 | TYPE_HAS_ASSIGN_REF (current_class_type) = 1; | |
f0e01782 MS |
10769 | if (TREE_CODE (parmtype) != REFERENCE_TYPE |
10770 | || TYPE_READONLY (TREE_TYPE (parmtype))) | |
8d08fdba MS |
10771 | TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1; |
10772 | } | |
10773 | } | |
10774 | else if (name == ansi_opname[(int) COND_EXPR]) | |
10775 | { | |
10776 | /* 13.4.0.3 */ | |
10777 | pedwarn ("ANSI C++ prohibits overloading operator ?:"); | |
10778 | if (list_length (argtypes) != 4) | |
10779 | cp_error ("`%D' must take exactly three arguments", decl); | |
10780 | } | |
10781 | else if (ambi_op_p (name)) | |
10782 | { | |
10783 | if (list_length (argtypes) == 2) | |
10784 | /* prefix */; | |
10785 | else if (list_length (argtypes) == 3) | |
10786 | { | |
10787 | if ((name == ansi_opname[(int) POSTINCREMENT_EXPR] | |
10788 | || name == ansi_opname[(int) POSTDECREMENT_EXPR]) | |
5156628f | 10789 | && ! processing_template_decl |
8d08fdba MS |
10790 | && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node) |
10791 | { | |
10792 | if (methodp) | |
10793 | cp_error ("postfix `%D' must take `int' as its argument", | |
10794 | decl); | |
10795 | else | |
10796 | cp_error | |
10797 | ("postfix `%D' must take `int' as its second argument", | |
10798 | decl); | |
10799 | } | |
10800 | } | |
10801 | else | |
10802 | { | |
10803 | if (methodp) | |
10804 | cp_error ("`%D' must take either zero or one argument", decl); | |
10805 | else | |
10806 | cp_error ("`%D' must take either one or two arguments", decl); | |
10807 | } | |
824b9a4c MS |
10808 | |
10809 | /* More Effective C++ rule 6. */ | |
eb448459 | 10810 | if (warn_ecpp |
824b9a4c MS |
10811 | && (name == ansi_opname[(int) POSTINCREMENT_EXPR] |
10812 | || name == ansi_opname[(int) POSTDECREMENT_EXPR])) | |
10813 | { | |
10814 | tree arg = TREE_VALUE (argtypes); | |
10815 | tree ret = TREE_TYPE (TREE_TYPE (decl)); | |
10816 | if (methodp || TREE_CODE (arg) == REFERENCE_TYPE) | |
10817 | arg = TREE_TYPE (arg); | |
10818 | arg = TYPE_MAIN_VARIANT (arg); | |
10819 | if (list_length (argtypes) == 2) | |
10820 | { | |
10821 | if (TREE_CODE (ret) != REFERENCE_TYPE | |
10822 | || !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), | |
10823 | arg, 1)) | |
10824 | cp_warning ("prefix `%D' should return `%T'", decl, | |
10825 | build_reference_type (arg)); | |
10826 | } | |
10827 | else | |
10828 | { | |
10829 | if (!comptypes (TYPE_MAIN_VARIANT (ret), arg, 1)) | |
10830 | cp_warning ("postfix `%D' should return `%T'", decl, arg); | |
10831 | } | |
10832 | } | |
8d08fdba MS |
10833 | } |
10834 | else if (unary_op_p (name)) | |
10835 | { | |
10836 | if (list_length (argtypes) != 2) | |
10837 | { | |
10838 | if (methodp) | |
10839 | cp_error ("`%D' must take `void'", decl); | |
10840 | else | |
10841 | cp_error ("`%D' must take exactly one argument", decl); | |
10842 | } | |
10843 | } | |
10844 | else /* if (binary_op_p (name)) */ | |
10845 | { | |
10846 | if (list_length (argtypes) != 3) | |
10847 | { | |
10848 | if (methodp) | |
10849 | cp_error ("`%D' must take exactly one argument", decl); | |
10850 | else | |
10851 | cp_error ("`%D' must take exactly two arguments", decl); | |
10852 | } | |
824b9a4c MS |
10853 | |
10854 | /* More Effective C++ rule 7. */ | |
eb448459 | 10855 | if (warn_ecpp |
824b9a4c MS |
10856 | && (name == ansi_opname [TRUTH_ANDIF_EXPR] |
10857 | || name == ansi_opname [TRUTH_ORIF_EXPR] | |
10858 | || name == ansi_opname [COMPOUND_EXPR])) | |
10859 | cp_warning ("user-defined `%D' always evaluates both arguments", | |
10860 | decl); | |
10861 | } | |
10862 | ||
10863 | /* Effective C++ rule 23. */ | |
eb448459 | 10864 | if (warn_ecpp |
824b9a4c MS |
10865 | && list_length (argtypes) == 3 |
10866 | && (name == ansi_opname [PLUS_EXPR] | |
10867 | || name == ansi_opname [MINUS_EXPR] | |
10868 | || name == ansi_opname [TRUNC_DIV_EXPR] | |
10869 | || name == ansi_opname [MULT_EXPR]) | |
10870 | && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE) | |
10871 | cp_warning ("`%D' should return by value", decl); | |
8d08fdba MS |
10872 | |
10873 | /* 13.4.0.8 */ | |
10874 | if (argtypes) | |
10875 | for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes)) | |
10876 | if (TREE_PURPOSE (argtypes)) | |
10877 | { | |
10878 | TREE_PURPOSE (argtypes) = NULL_TREE; | |
10879 | if (name == ansi_opname[(int) POSTINCREMENT_EXPR] | |
10880 | || name == ansi_opname[(int) POSTDECREMENT_EXPR]) | |
10881 | { | |
10882 | if (pedantic) | |
10883 | cp_pedwarn ("`%D' cannot have default arguments", decl); | |
10884 | } | |
10885 | else | |
10886 | cp_error ("`%D' cannot have default arguments", decl); | |
10887 | } | |
10888 | } | |
10889 | } | |
10890 | \f | |
10891 | /* Get the struct, enum or union (CODE says which) with tag NAME. | |
10892 | Define the tag as a forward-reference if it is not defined. | |
10893 | ||
10894 | C++: If a class derivation is given, process it here, and report | |
10895 | an error if multiple derivation declarations are not identical. | |
10896 | ||
10897 | If this is a definition, come in through xref_tag and only look in | |
10898 | the current frame for the name (since C++ allows new names in any | |
10899 | scope.) */ | |
10900 | ||
8d08fdba MS |
10901 | tree |
10902 | xref_tag (code_type_node, name, binfo, globalize) | |
10903 | tree code_type_node; | |
10904 | tree name, binfo; | |
10905 | int globalize; | |
10906 | { | |
10907 | enum tag_types tag_code; | |
10908 | enum tree_code code; | |
10909 | int temp = 0; | |
8d08fdba MS |
10910 | register tree ref, t; |
10911 | struct binding_level *b = inner_binding_level; | |
a80e4195 | 10912 | int got_type = 0; |
8d08fdba MS |
10913 | |
10914 | tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); | |
10915 | switch (tag_code) | |
10916 | { | |
10917 | case record_type: | |
10918 | case class_type: | |
8d08fdba MS |
10919 | case signature_type: |
10920 | code = RECORD_TYPE; | |
8d08fdba MS |
10921 | break; |
10922 | case union_type: | |
10923 | code = UNION_TYPE; | |
8d08fdba MS |
10924 | break; |
10925 | case enum_type: | |
10926 | code = ENUMERAL_TYPE; | |
10927 | break; | |
10928 | default: | |
10929 | my_friendly_abort (18); | |
10930 | } | |
10931 | ||
10932 | /* If a cross reference is requested, look up the type | |
10933 | already defined for this tag and return it. */ | |
be99da77 MS |
10934 | if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') |
10935 | { | |
10936 | t = name; | |
a80e4195 MS |
10937 | name = TYPE_IDENTIFIER (t); |
10938 | got_type = 1; | |
be99da77 MS |
10939 | } |
10940 | else | |
10941 | t = IDENTIFIER_TYPE_VALUE (name); | |
73b0fce8 KL |
10942 | if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM |
10943 | && TREE_CODE (t) != TEMPLATE_TEMPLATE_PARM) | |
a0a33927 MS |
10944 | t = NULL_TREE; |
10945 | ||
8ccc31eb | 10946 | if (! globalize) |
8d08fdba | 10947 | { |
73b0fce8 KL |
10948 | if (pedantic && t && (TREE_CODE (t) == TEMPLATE_TYPE_PARM |
10949 | || TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)) | |
ec255269 MS |
10950 | { |
10951 | cp_pedwarn ("redeclaration of template type-parameter `%T'", name); | |
10952 | cp_pedwarn_at (" previously declared here", t); | |
10953 | } | |
a80e4195 | 10954 | if (t && TYPE_CONTEXT (t) && got_type) |
8ccc31eb | 10955 | ref = t; |
8d08fdba | 10956 | else |
e92cc029 MS |
10957 | { |
10958 | /* If we know we are defining this tag, only look it up in | |
10959 | this scope and don't try to find it as a type. */ | |
10960 | ref = lookup_tag (code, name, b, 1); | |
10961 | } | |
8d08fdba MS |
10962 | } |
10963 | else | |
10964 | { | |
10965 | if (t) | |
10966 | ref = t; | |
10967 | else | |
10968 | ref = lookup_tag (code, name, b, 0); | |
10969 | ||
10970 | if (! ref) | |
10971 | { | |
10972 | /* Try finding it as a type declaration. If that wins, use it. */ | |
10973 | ref = lookup_name (name, 1); | |
10974 | if (ref && TREE_CODE (ref) == TYPE_DECL | |
10975 | && TREE_CODE (TREE_TYPE (ref)) == code) | |
10976 | ref = TREE_TYPE (ref); | |
10977 | else | |
10978 | ref = NULL_TREE; | |
10979 | } | |
10980 | } | |
10981 | ||
10982 | push_obstacks_nochange (); | |
10983 | ||
10984 | if (! ref) | |
10985 | { | |
10986 | /* If no such tag is yet defined, create a forward-reference node | |
10987 | and record it as the "definition". | |
10988 | When a real declaration of this type is found, | |
10989 | the forward-reference will be altered into a real type. */ | |
10990 | ||
10991 | /* In C++, since these migrate into the global scope, we must | |
10992 | build them on the permanent obstack. */ | |
10993 | ||
10994 | temp = allocation_temporary_p (); | |
10995 | if (temp) | |
10996 | end_temporary_allocation (); | |
10997 | ||
10998 | if (code == ENUMERAL_TYPE) | |
10999 | { | |
fc378698 MS |
11000 | cp_error ("use of enum `%#D' without previous declaration", name); |
11001 | ||
8d08fdba MS |
11002 | ref = make_node (ENUMERAL_TYPE); |
11003 | ||
11004 | /* Give the type a default layout like unsigned int | |
11005 | to avoid crashing if it does not get defined. */ | |
11006 | TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); | |
11007 | TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); | |
11008 | TREE_UNSIGNED (ref) = 1; | |
11009 | TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); | |
11010 | TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); | |
11011 | TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); | |
11012 | ||
11013 | /* Enable us to recognize when a type is created in class context. | |
11014 | To do nested classes correctly, this should probably be cleared | |
11015 | out when we leave this classes scope. Currently this in only | |
11016 | done in `start_enum'. */ | |
11017 | ||
11018 | pushtag (name, ref, globalize); | |
8d08fdba | 11019 | } |
8d08fdba MS |
11020 | else |
11021 | { | |
8d08fdba | 11022 | struct binding_level *old_b = class_binding_level; |
8d08fdba MS |
11023 | |
11024 | ref = make_lang_type (code); | |
11025 | ||
8d08fdba MS |
11026 | if (tag_code == signature_type) |
11027 | { | |
11028 | SET_SIGNATURE (ref); | |
f376e137 MS |
11029 | /* Since a signature type will be turned into the type |
11030 | of signature tables, it's not only an interface. */ | |
8d08fdba | 11031 | CLASSTYPE_INTERFACE_ONLY (ref) = 0; |
f376e137 MS |
11032 | SET_CLASSTYPE_INTERFACE_KNOWN (ref); |
11033 | /* A signature doesn't have a vtable. */ | |
00595019 | 11034 | CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0; |
8d08fdba MS |
11035 | } |
11036 | ||
8d08fdba MS |
11037 | #ifdef NONNESTED_CLASSES |
11038 | /* Class types don't nest the way enums do. */ | |
11039 | class_binding_level = (struct binding_level *)0; | |
11040 | #endif | |
11041 | pushtag (name, ref, globalize); | |
11042 | class_binding_level = old_b; | |
8d08fdba MS |
11043 | } |
11044 | } | |
11045 | else | |
11046 | { | |
8d08fdba | 11047 | /* If it no longer looks like a nested type, make sure it's |
30394414 JM |
11048 | in global scope. |
11049 | If it is not an IDENTIFIER, this is not a declaration */ | |
8d08fdba | 11050 | if (b == global_binding_level && !class_binding_level |
30394414 JM |
11051 | && TREE_CODE (name) == IDENTIFIER_NODE) |
11052 | { | |
11053 | tree binding; | |
11054 | binding = binding_for_name (name, current_namespace); | |
11055 | if (BINDING_VALUE (binding) == NULL_TREE) | |
11056 | BINDING_VALUE (binding) = TYPE_NAME (ref); | |
11057 | } | |
8d08fdba MS |
11058 | } |
11059 | ||
11060 | if (binfo) | |
8ccc31eb | 11061 | xref_basetypes (code_type_node, name, ref, binfo); |
8d08fdba | 11062 | |
8d08fdba MS |
11063 | /* Until the type is defined, tentatively accept whatever |
11064 | structure tag the user hands us. */ | |
11065 | if (TYPE_SIZE (ref) == NULL_TREE | |
11066 | && ref != current_class_type | |
11067 | /* Have to check this, in case we have contradictory tag info. */ | |
11068 | && IS_AGGR_TYPE_CODE (TREE_CODE (ref))) | |
11069 | { | |
11070 | if (tag_code == class_type) | |
11071 | CLASSTYPE_DECLARED_CLASS (ref) = 1; | |
11072 | else if (tag_code == record_type || tag_code == signature_type) | |
11073 | CLASSTYPE_DECLARED_CLASS (ref) = 0; | |
11074 | } | |
11075 | ||
11076 | pop_obstacks (); | |
11077 | ||
11078 | return ref; | |
11079 | } | |
8ccc31eb | 11080 | |
fc378698 MS |
11081 | tree |
11082 | xref_tag_from_type (old, id, globalize) | |
11083 | tree old, id; | |
11084 | int globalize; | |
11085 | { | |
11086 | tree code_type_node; | |
11087 | ||
11088 | if (TREE_CODE (old) == RECORD_TYPE) | |
11089 | code_type_node = (CLASSTYPE_DECLARED_CLASS (old) | |
11090 | ? class_type_node : record_type_node); | |
11091 | else | |
11092 | code_type_node = union_type_node; | |
11093 | ||
11094 | if (id == NULL_TREE) | |
11095 | id = TYPE_IDENTIFIER (old); | |
11096 | ||
11097 | return xref_tag (code_type_node, id, NULL_TREE, globalize); | |
11098 | } | |
11099 | ||
8ccc31eb MS |
11100 | void |
11101 | xref_basetypes (code_type_node, name, ref, binfo) | |
11102 | tree code_type_node; | |
11103 | tree name, ref; | |
11104 | tree binfo; | |
11105 | { | |
11106 | /* In the declaration `A : X, Y, ... Z' we mark all the types | |
11107 | (A, X, Y, ..., Z) so we can check for duplicates. */ | |
11108 | tree binfos; | |
11109 | int i, len; | |
11110 | enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); | |
11111 | ||
11112 | if (tag_code == union_type) | |
11113 | { | |
11114 | cp_error ("derived union `%T' invalid", ref); | |
11115 | return; | |
11116 | } | |
11117 | ||
11118 | len = list_length (binfo); | |
11119 | push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref)); | |
11120 | ||
11121 | SET_CLASSTYPE_MARKED (ref); | |
11122 | BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len); | |
11123 | ||
11124 | for (i = 0; binfo; binfo = TREE_CHAIN (binfo)) | |
11125 | { | |
11126 | /* The base of a derived struct is public by default. */ | |
11127 | int via_public | |
be99da77 MS |
11128 | = (TREE_PURPOSE (binfo) == access_public_node |
11129 | || TREE_PURPOSE (binfo) == access_public_virtual_node | |
8ccc31eb | 11130 | || (tag_code != class_type |
be99da77 MS |
11131 | && (TREE_PURPOSE (binfo) == access_default_node |
11132 | || TREE_PURPOSE (binfo) == access_default_virtual_node))); | |
d8b55a76 JM |
11133 | int via_protected |
11134 | = (TREE_PURPOSE (binfo) == access_protected_node | |
11135 | || TREE_PURPOSE (binfo) == access_protected_virtual_node); | |
8ccc31eb | 11136 | int via_virtual |
be99da77 | 11137 | = (TREE_PURPOSE (binfo) == access_private_virtual_node |
d8b55a76 | 11138 | || TREE_PURPOSE (binfo) == access_protected_virtual_node |
be99da77 MS |
11139 | || TREE_PURPOSE (binfo) == access_public_virtual_node |
11140 | || TREE_PURPOSE (binfo) == access_default_virtual_node); | |
11141 | tree basetype = TREE_VALUE (binfo); | |
8ccc31eb MS |
11142 | tree base_binfo; |
11143 | ||
11144 | GNU_xref_hier (IDENTIFIER_POINTER (name), | |
11145 | IDENTIFIER_POINTER (TREE_VALUE (binfo)), | |
11146 | via_public, via_virtual, 0); | |
11147 | ||
11148 | if (basetype && TREE_CODE (basetype) == TYPE_DECL) | |
11149 | basetype = TREE_TYPE (basetype); | |
5566b478 MS |
11150 | if (!basetype |
11151 | || (TREE_CODE (basetype) != RECORD_TYPE | |
a80e4195 | 11152 | && TREE_CODE (basetype) != TYPENAME_TYPE |
73b0fce8 KL |
11153 | && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM |
11154 | && TREE_CODE (basetype) != TEMPLATE_TEMPLATE_PARM)) | |
8ccc31eb MS |
11155 | { |
11156 | cp_error ("base type `%T' fails to be a struct or class type", | |
11157 | TREE_VALUE (binfo)); | |
11158 | continue; | |
11159 | } | |
11160 | #if 1 | |
8adf5b5e JM |
11161 | /* This code replaces similar code in layout_basetypes. |
11162 | We put the complete_type first for implicit `typename'. */ | |
11163 | else if (TYPE_SIZE (complete_type (basetype)) == NULL_TREE | |
11164 | && ! (current_template_parms && uses_template_parms (basetype))) | |
8ccc31eb MS |
11165 | { |
11166 | cp_error ("base class `%T' has incomplete type", basetype); | |
11167 | continue; | |
11168 | } | |
11169 | #endif | |
11170 | else | |
11171 | { | |
11172 | if (CLASSTYPE_MARKED (basetype)) | |
11173 | { | |
11174 | if (basetype == ref) | |
11175 | cp_error ("recursive type `%T' undefined", basetype); | |
11176 | else | |
11177 | cp_error ("duplicate base type `%T' invalid", basetype); | |
11178 | continue; | |
11179 | } | |
11180 | ||
11181 | /* Note that the BINFO records which describe individual | |
11182 | inheritances are *not* shared in the lattice! They | |
11183 | cannot be shared because a given baseclass may be | |
11184 | inherited with different `accessibility' by different | |
11185 | derived classes. (Each BINFO record describing an | |
11186 | individual inheritance contains flags which say what | |
11187 | the `accessibility' of that particular inheritance is.) */ | |
11188 | ||
11189 | base_binfo = make_binfo (integer_zero_node, basetype, | |
11190 | TYPE_BINFO_VTABLE (basetype), | |
11191 | TYPE_BINFO_VIRTUALS (basetype), NULL_TREE); | |
11192 | ||
11193 | TREE_VEC_ELT (binfos, i) = base_binfo; | |
11194 | TREE_VIA_PUBLIC (base_binfo) = via_public; | |
11195 | TREE_VIA_PROTECTED (base_binfo) = via_protected; | |
11196 | TREE_VIA_VIRTUAL (base_binfo) = via_virtual; | |
11197 | BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref); | |
11198 | ||
11199 | SET_CLASSTYPE_MARKED (basetype); | |
9e9ff709 | 11200 | |
8ccc31eb MS |
11201 | /* We are free to modify these bits because they are meaningless |
11202 | at top level, and BASETYPE is a top-level type. */ | |
11203 | if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) | |
11204 | { | |
11205 | TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1; | |
11206 | TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; | |
11207 | } | |
11208 | ||
11209 | TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype); | |
11210 | TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype); | |
11211 | TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype); | |
11212 | CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype); | |
11213 | i += 1; | |
11214 | } | |
11215 | } | |
11216 | if (i) | |
11217 | TREE_VEC_LENGTH (binfos) = i; | |
11218 | else | |
11219 | BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE; | |
11220 | ||
11221 | if (i > 1) | |
11222 | TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; | |
11223 | else if (i == 1) | |
11224 | TYPE_USES_MULTIPLE_INHERITANCE (ref) | |
11225 | = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0))); | |
11226 | if (TYPE_USES_MULTIPLE_INHERITANCE (ref)) | |
11227 | TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; | |
11228 | ||
11229 | /* Unmark all the types. */ | |
11230 | while (--i >= 0) | |
11231 | CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i))); | |
11232 | CLEAR_CLASSTYPE_MARKED (ref); | |
11233 | ||
11234 | pop_obstacks (); | |
11235 | } | |
11236 | ||
8d08fdba | 11237 | \f |
b3d5a58b | 11238 | tree current_local_enum = NULL_TREE; |
8d08fdba MS |
11239 | |
11240 | /* Begin compiling the definition of an enumeration type. | |
11241 | NAME is its name (or null if anonymous). | |
11242 | Returns the type object, as yet incomplete. | |
11243 | Also records info about it so that build_enumerator | |
11244 | may be used to declare the individual values as they are read. */ | |
11245 | ||
11246 | tree | |
11247 | start_enum (name) | |
11248 | tree name; | |
11249 | { | |
11250 | register tree enumtype = NULL_TREE; | |
11251 | struct binding_level *b = inner_binding_level; | |
11252 | ||
b87692e5 MS |
11253 | if (processing_template_decl && current_function_decl) |
11254 | end_temporary_allocation (); | |
11255 | ||
8d08fdba MS |
11256 | /* If this is the real definition for a previous forward reference, |
11257 | fill in the contents in the same object that used to be the | |
11258 | forward reference. */ | |
11259 | ||
11260 | if (name != NULL_TREE) | |
11261 | enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); | |
11262 | ||
11263 | if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE) | |
c91a56d2 | 11264 | cp_error ("multiple definition of `%#T'", enumtype); |
8d08fdba MS |
11265 | else |
11266 | { | |
11267 | enumtype = make_node (ENUMERAL_TYPE); | |
11268 | pushtag (name, enumtype, 0); | |
11269 | } | |
11270 | ||
c91a56d2 MS |
11271 | if (b->pseudo_global) |
11272 | cp_error ("template declaration of `%#T'", enumtype); | |
11273 | ||
8d08fdba MS |
11274 | if (current_class_type) |
11275 | TREE_ADDRESSABLE (b->tags) = 1; | |
c91a56d2 | 11276 | |
8d08fdba MS |
11277 | current_local_enum = NULL_TREE; |
11278 | ||
e92cc029 MS |
11279 | /* We don't copy this value because build_enumerator needs to do it. */ |
11280 | enum_next_value = integer_zero_node; | |
7177d104 | 11281 | enum_overflow = 0; |
8d08fdba MS |
11282 | |
11283 | GNU_xref_decl (current_function_decl, enumtype); | |
11284 | return enumtype; | |
11285 | } | |
11286 | ||
11287 | /* After processing and defining all the values of an enumeration type, | |
11288 | install their decls in the enumeration type and finish it off. | |
11289 | ENUMTYPE is the type object and VALUES a list of name-value pairs. | |
11290 | Returns ENUMTYPE. */ | |
11291 | ||
11292 | tree | |
11293 | finish_enum (enumtype, values) | |
11294 | register tree enumtype, values; | |
11295 | { | |
a703fb38 | 11296 | register tree minnode = NULL_TREE, maxnode = NULL_TREE; |
8d08fdba MS |
11297 | /* Calculate the maximum value of any enumerator in this type. */ |
11298 | ||
11299 | if (values) | |
11300 | { | |
f376e137 MS |
11301 | register tree pair; |
11302 | register tree value = DECL_INITIAL (TREE_VALUE (values)); | |
5566b478 | 11303 | |
5156628f | 11304 | if (! processing_template_decl) |
5566b478 MS |
11305 | { |
11306 | /* Speed up the main loop by performing some precalculations */ | |
11307 | TREE_TYPE (TREE_VALUE (values)) = enumtype; | |
11308 | TREE_TYPE (value) = enumtype; | |
11309 | minnode = maxnode = value; | |
11310 | } | |
f376e137 | 11311 | TREE_VALUE (values) = value; |
8d08fdba MS |
11312 | |
11313 | for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) | |
11314 | { | |
f376e137 | 11315 | value = DECL_INITIAL (TREE_VALUE (pair)); |
5156628f | 11316 | if (! processing_template_decl) |
5566b478 MS |
11317 | { |
11318 | TREE_TYPE (TREE_VALUE (pair)) = enumtype; | |
11319 | TREE_TYPE (value) = enumtype; | |
11320 | if (tree_int_cst_lt (maxnode, value)) | |
11321 | maxnode = value; | |
11322 | else if (tree_int_cst_lt (value, minnode)) | |
11323 | minnode = value; | |
11324 | } | |
f376e137 | 11325 | TREE_VALUE (pair) = value; |
8d08fdba MS |
11326 | } |
11327 | } | |
f376e137 MS |
11328 | else |
11329 | maxnode = minnode = integer_zero_node; | |
8d08fdba | 11330 | |
de22184b | 11331 | TYPE_VALUES (enumtype) = nreverse (values); |
2986ae00 | 11332 | |
5156628f | 11333 | if (processing_template_decl) |
b87692e5 MS |
11334 | { |
11335 | if (current_function_decl) | |
11336 | { | |
11337 | add_tree (build_min (TAG_DEFN, enumtype)); | |
11338 | resume_temporary_allocation (); | |
11339 | } | |
11340 | return enumtype; | |
11341 | } | |
5566b478 | 11342 | |
f376e137 MS |
11343 | { |
11344 | int unsignedp = tree_int_cst_sgn (minnode) >= 0; | |
11345 | int lowprec = min_precision (minnode, unsignedp); | |
11346 | int highprec = min_precision (maxnode, unsignedp); | |
11347 | int precision = MAX (lowprec, highprec); | |
8d08fdba | 11348 | |
6060a796 | 11349 | TYPE_SIZE (enumtype) = NULL_TREE; |
13fbb038 | 11350 | |
8ccc31eb | 11351 | /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */ |
8d08fdba | 11352 | |
f376e137 | 11353 | TYPE_PRECISION (enumtype) = precision; |
f376e137 | 11354 | if (unsignedp) |
8d08fdba | 11355 | fixup_unsigned_type (enumtype); |
f376e137 MS |
11356 | else |
11357 | fixup_signed_type (enumtype); | |
8ccc31eb | 11358 | |
5566b478 | 11359 | if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node))) |
8ccc31eb MS |
11360 | /* Use the width of the narrowest normal C type which is wide enough. */ |
11361 | TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size | |
11362 | (precision, 1)); | |
11363 | else | |
11364 | TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); | |
11365 | ||
11366 | TYPE_SIZE (enumtype) = 0; | |
11367 | layout_type (enumtype); | |
f376e137 | 11368 | } |
8d08fdba | 11369 | |
f376e137 MS |
11370 | { |
11371 | register tree tem; | |
11372 | ||
11373 | /* Fix up all variant types of this enum type. */ | |
11374 | for (tem = TYPE_MAIN_VARIANT (enumtype); tem; | |
11375 | tem = TYPE_NEXT_VARIANT (tem)) | |
11376 | { | |
11377 | TYPE_VALUES (tem) = TYPE_VALUES (enumtype); | |
11378 | TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); | |
11379 | TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); | |
11380 | TYPE_SIZE (tem) = TYPE_SIZE (enumtype); | |
11381 | TYPE_MODE (tem) = TYPE_MODE (enumtype); | |
11382 | TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); | |
11383 | TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); | |
11384 | TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); | |
11385 | } | |
11386 | } | |
8d08fdba MS |
11387 | |
11388 | /* Finish debugging output for this type. */ | |
d2e5ee5c | 11389 | rest_of_type_compilation (enumtype, global_bindings_p ()); |
8d08fdba MS |
11390 | |
11391 | return enumtype; | |
11392 | } | |
11393 | ||
11394 | /* Build and install a CONST_DECL for one value of the | |
11395 | current enumeration type (one that was begun with start_enum). | |
11396 | Return a tree-list containing the name and its value. | |
11397 | Assignment of sequential values by default is handled here. */ | |
11398 | ||
11399 | tree | |
11400 | build_enumerator (name, value) | |
11401 | tree name, value; | |
11402 | { | |
11403 | tree decl, result; | |
8d08fdba MS |
11404 | |
11405 | /* Remove no-op casts from the value. */ | |
11406 | if (value) | |
11407 | STRIP_TYPE_NOPS (value); | |
11408 | ||
5156628f | 11409 | if (! processing_template_decl) |
5566b478 MS |
11410 | { |
11411 | /* Validate and default VALUE. */ | |
11412 | if (value != NULL_TREE) | |
11413 | { | |
11414 | if (TREE_READONLY_DECL_P (value)) | |
e92cc029 | 11415 | value = decl_constant_value (value); |
5566b478 MS |
11416 | |
11417 | if (TREE_CODE (value) == INTEGER_CST) | |
11418 | { | |
11419 | value = default_conversion (value); | |
11420 | constant_expression_warning (value); | |
11421 | } | |
11422 | else | |
11423 | { | |
11424 | cp_error ("enumerator value for `%D' not integer constant", name); | |
11425 | value = NULL_TREE; | |
11426 | } | |
11427 | } | |
11428 | ||
5566b478 | 11429 | /* Default based on previous value. */ |
5156628f | 11430 | if (value == NULL_TREE && ! processing_template_decl) |
5566b478 MS |
11431 | { |
11432 | value = enum_next_value; | |
11433 | if (enum_overflow) | |
11434 | cp_error ("overflow in enumeration values at `%D'", name); | |
11435 | } | |
11436 | ||
11437 | /* Remove no-op casts from the value. */ | |
11438 | if (value) | |
11439 | STRIP_TYPE_NOPS (value); | |
11440 | ||
e92cc029 MS |
11441 | /* We have to always copy here; not all INTEGER_CSTs are unshared, |
11442 | and there's no wedding ring. Look at size_int()...*/ | |
11443 | value = copy_node (value); | |
013bc8af MS |
11444 | #if 0 |
11445 | /* To fix MAX_VAL enum consts. (bkoz) */ | |
e92cc029 | 11446 | TREE_TYPE (value) = integer_type_node; |
013bc8af | 11447 | #endif |
5566b478 | 11448 | } |
8d08fdba | 11449 | |
8d08fdba MS |
11450 | /* C++ associates enums with global, function, or class declarations. */ |
11451 | ||
7177d104 MS |
11452 | decl = current_scope (); |
11453 | if (decl && decl == current_class_type) | |
8d08fdba MS |
11454 | { |
11455 | /* This enum declaration is local to the class, so we must put | |
11456 | it in that class's list of decls. */ | |
11457 | decl = build_lang_field_decl (CONST_DECL, name, integer_type_node); | |
11458 | DECL_INITIAL (decl) = value; | |
11459 | TREE_READONLY (decl) = 1; | |
11460 | pushdecl_class_level (decl); | |
11461 | TREE_CHAIN (decl) = current_local_enum; | |
11462 | current_local_enum = decl; | |
11463 | } | |
11464 | else | |
11465 | { | |
11466 | /* It's a global enum, or it's local to a function. (Note local to | |
11467 | a function could mean local to a class method. */ | |
11468 | decl = build_decl (CONST_DECL, name, integer_type_node); | |
11469 | DECL_INITIAL (decl) = value; | |
42976354 | 11470 | TREE_READONLY (decl) = 1; |
8d08fdba MS |
11471 | |
11472 | pushdecl (decl); | |
11473 | GNU_xref_decl (current_function_decl, decl); | |
11474 | } | |
11475 | ||
5156628f | 11476 | if (! processing_template_decl) |
5566b478 MS |
11477 | { |
11478 | /* Set basis for default for next value. */ | |
11479 | enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, | |
11480 | integer_one_node, PLUS_EXPR); | |
11481 | enum_overflow = tree_int_cst_lt (enum_next_value, value); | |
5566b478 | 11482 | } |
8d08fdba | 11483 | |
8d2733ca | 11484 | result = saveable_tree_cons (name, decl, NULL_TREE); |
8d08fdba MS |
11485 | return result; |
11486 | } | |
11487 | ||
11488 | tree | |
86052cc3 JM |
11489 | grok_enum_decls (decl) |
11490 | tree decl; | |
8d08fdba MS |
11491 | { |
11492 | tree d = current_local_enum; | |
11493 | ||
11494 | if (d == NULL_TREE) | |
11495 | return decl; | |
11496 | ||
11497 | while (1) | |
11498 | { | |
8d08fdba MS |
11499 | if (TREE_CHAIN (d) == NULL_TREE) |
11500 | { | |
11501 | TREE_CHAIN (d) = decl; | |
11502 | break; | |
11503 | } | |
11504 | d = TREE_CHAIN (d); | |
11505 | } | |
11506 | ||
11507 | decl = current_local_enum; | |
11508 | current_local_enum = NULL_TREE; | |
11509 | ||
11510 | return decl; | |
11511 | } | |
11512 | \f | |
5566b478 MS |
11513 | static int function_depth; |
11514 | ||
8d08fdba MS |
11515 | /* Create the FUNCTION_DECL for a function definition. |
11516 | DECLSPECS and DECLARATOR are the parts of the declaration; | |
11517 | they describe the function's name and the type it returns, | |
11518 | but twisted together in a fashion that parallels the syntax of C. | |
11519 | ||
11520 | This function creates a binding context for the function body | |
11521 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
11522 | ||
11523 | Returns 1 on success. If the DECLARATOR is not suitable for a function | |
11524 | (it defines a datum instead), we return 0, which tells | |
11525 | yyparse to report a parse error. | |
11526 | ||
11527 | For C++, we must first check whether that datum makes any sense. | |
11528 | For example, "class A local_a(1,2);" means that variable local_a | |
11529 | is an aggregate of type A, which should have a constructor | |
11530 | applied to it with the argument list [1, 2]. | |
11531 | ||
11532 | @@ There is currently no way to retrieve the storage | |
11533 | @@ allocated to FUNCTION (or all of its parms) if we return | |
11534 | @@ something we had previously. */ | |
11535 | ||
11536 | int | |
c11b6f21 MS |
11537 | start_function (declspecs, declarator, attrs, pre_parsed_p) |
11538 | tree declspecs, declarator, attrs; | |
8d08fdba MS |
11539 | int pre_parsed_p; |
11540 | { | |
5566b478 | 11541 | tree decl1; |
8d08fdba MS |
11542 | tree ctype = NULL_TREE; |
11543 | tree fntype; | |
11544 | tree restype; | |
11545 | extern int have_extern_spec; | |
11546 | extern int used_extern_spec; | |
11547 | int doing_friend = 0; | |
11548 | ||
8d08fdba MS |
11549 | /* Sanity check. */ |
11550 | my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160); | |
11551 | my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); | |
11552 | ||
e92cc029 | 11553 | /* Assume, until we see it does. */ |
8d08fdba MS |
11554 | current_function_returns_value = 0; |
11555 | current_function_returns_null = 0; | |
11556 | warn_about_return_type = 0; | |
fd378c9d JM |
11557 | named_labels = 0; |
11558 | shadowed_labels = 0; | |
8d08fdba MS |
11559 | current_function_assigns_this = 0; |
11560 | current_function_just_assigned_this = 0; | |
11561 | current_function_parms_stored = 0; | |
11562 | original_result_rtx = NULL_RTX; | |
a9aedbc2 | 11563 | base_init_expr = NULL_TREE; |
79ff2c6c MS |
11564 | current_base_init_list = NULL_TREE; |
11565 | current_member_init_list = NULL_TREE; | |
f30432d7 | 11566 | ctor_label = dtor_label = NULL_TREE; |
42976354 | 11567 | static_labelno = 0; |
8d08fdba MS |
11568 | |
11569 | clear_temp_name (); | |
11570 | ||
e92cc029 | 11571 | /* This should only be done once on the top most decl. */ |
8d08fdba MS |
11572 | if (have_extern_spec && !used_extern_spec) |
11573 | { | |
11574 | declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); | |
11575 | used_extern_spec = 1; | |
11576 | } | |
11577 | ||
11578 | if (pre_parsed_p) | |
11579 | { | |
11580 | decl1 = declarator; | |
11581 | ||
11582 | if (! DECL_ARGUMENTS (decl1) | |
11583 | && !DECL_STATIC_FUNCTION_P (decl1) | |
11584 | && DECL_CONTEXT (decl1) | |
d2e5ee5c MS |
11585 | && TYPE_IDENTIFIER (DECL_CONTEXT (decl1)) |
11586 | && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (DECL_CONTEXT (decl1)))) | |
8d08fdba | 11587 | { |
30394414 JM |
11588 | tree binding = binding_for_name (DECL_NAME (decl1), |
11589 | current_namespace); | |
8d08fdba MS |
11590 | cp_error ("redeclaration of `%#D'", decl1); |
11591 | if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))) | |
11592 | cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))); | |
30394414 JM |
11593 | else if (BINDING_VALUE (binding)) |
11594 | cp_error_at ("previous declaration here", BINDING_VALUE (binding)); | |
8d08fdba MS |
11595 | } |
11596 | ||
8d08fdba MS |
11597 | fntype = TREE_TYPE (decl1); |
11598 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
11599 | ctype = TYPE_METHOD_BASETYPE (fntype); | |
11600 | ||
11601 | /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a | |
11602 | class is in the (lexical) scope of the class in which it is | |
11603 | defined. */ | |
11604 | if (!ctype && DECL_FRIEND_P (decl1)) | |
11605 | { | |
11606 | ctype = DECL_CLASS_CONTEXT (decl1); | |
11607 | ||
11608 | /* CTYPE could be null here if we're dealing with a template; | |
11609 | for example, `inline friend float foo()' inside a template | |
11610 | will have no CTYPE set. */ | |
11611 | if (ctype && TREE_CODE (ctype) != RECORD_TYPE) | |
11612 | ctype = NULL_TREE; | |
11613 | else | |
11614 | doing_friend = 1; | |
11615 | } | |
11616 | ||
8d08fdba | 11617 | /* In a fcn definition, arg types must be complete. */ |
5566b478 | 11618 | require_complete_types_for_parms (DECL_ARGUMENTS (decl1)); |
9fffd093 RK |
11619 | |
11620 | /* In case some arg types were completed since the declaration was | |
11621 | parsed, fix up the decls. */ | |
11622 | { | |
5566b478 | 11623 | tree t = DECL_ARGUMENTS (decl1); |
9fffd093 RK |
11624 | for (; t; t = TREE_CHAIN (t)) |
11625 | layout_decl (t, 0); | |
11626 | } | |
5566b478 MS |
11627 | |
11628 | last_function_parms = DECL_ARGUMENTS (decl1); | |
11629 | last_function_parm_tags = NULL_TREE; | |
8d08fdba MS |
11630 | } |
11631 | else | |
11632 | { | |
c11b6f21 | 11633 | decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL_TREE); |
8d08fdba MS |
11634 | /* If the declarator is not suitable for a function definition, |
11635 | cause a syntax error. */ | |
11636 | if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0; | |
11637 | ||
11638 | fntype = TREE_TYPE (decl1); | |
11639 | ||
11640 | restype = TREE_TYPE (fntype); | |
11641 | if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype) | |
11642 | && ! CLASSTYPE_GOT_SEMICOLON (restype)) | |
11643 | { | |
11644 | cp_error ("semicolon missing after declaration of `%#T'", restype); | |
e66d884e | 11645 | shadow_tag (build_expr_list (NULL_TREE, restype)); |
8d08fdba MS |
11646 | CLASSTYPE_GOT_SEMICOLON (restype) = 1; |
11647 | if (TREE_CODE (fntype) == FUNCTION_TYPE) | |
11648 | fntype = build_function_type (integer_type_node, | |
11649 | TYPE_ARG_TYPES (fntype)); | |
11650 | else | |
11651 | fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)), | |
11652 | integer_type_node, | |
11653 | TYPE_ARG_TYPES (fntype)); | |
11654 | TREE_TYPE (decl1) = fntype; | |
11655 | } | |
11656 | ||
11657 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
11658 | ctype = TYPE_METHOD_BASETYPE (fntype); | |
11659 | else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4 | |
11660 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main") | |
11661 | && DECL_CONTEXT (decl1) == NULL_TREE) | |
11662 | { | |
11663 | /* If this doesn't return integer_type, complain. */ | |
11664 | if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node) | |
11665 | { | |
a28e3c7f | 11666 | if (pedantic || warn_return_type) |
5566b478 | 11667 | pedwarn ("return type for `main' changed to `int'"); |
8d08fdba MS |
11668 | TREE_TYPE (decl1) = fntype = default_function_type; |
11669 | } | |
11670 | warn_about_return_type = 0; | |
11671 | } | |
11672 | } | |
11673 | ||
11674 | /* Warn if function was previously implicitly declared | |
11675 | (but not if we warned then). */ | |
11676 | if (! warn_implicit | |
11677 | && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE) | |
11678 | cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))); | |
11679 | ||
11680 | current_function_decl = decl1; | |
5566b478 MS |
11681 | /* Save the parm names or decls from this function's declarator |
11682 | where store_parm_decls will find them. */ | |
11683 | current_function_parms = last_function_parms; | |
11684 | current_function_parm_tags = last_function_parm_tags; | |
8d08fdba | 11685 | |
9e9ff709 | 11686 | announce_function (decl1); |
8d08fdba | 11687 | |
5156628f | 11688 | if (! processing_template_decl) |
8d08fdba | 11689 | { |
5566b478 MS |
11690 | if (TYPE_SIZE (complete_type (TREE_TYPE (fntype))) == NULL_TREE) |
11691 | { | |
11692 | cp_error ("return-type `%#T' is an incomplete type", | |
11693 | TREE_TYPE (fntype)); | |
8d08fdba | 11694 | |
5566b478 MS |
11695 | /* Make it return void instead, but don't change the |
11696 | type of the DECL_RESULT, in case we have a named return value. */ | |
11697 | if (ctype) | |
11698 | TREE_TYPE (decl1) | |
11699 | = build_cplus_method_type (build_type_variant (ctype, | |
11700 | TREE_READONLY (decl1), | |
11701 | TREE_SIDE_EFFECTS (decl1)), | |
11702 | void_type_node, | |
11703 | FUNCTION_ARG_CHAIN (decl1)); | |
11704 | else | |
11705 | TREE_TYPE (decl1) | |
11706 | = build_function_type (void_type_node, | |
11707 | TYPE_ARG_TYPES (TREE_TYPE (decl1))); | |
11708 | DECL_RESULT (decl1) | |
11709 | = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype))); | |
11710 | TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype)); | |
11711 | TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype)); | |
11712 | } | |
11713 | ||
11714 | if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype)) | |
11715 | && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype))) | |
11716 | abstract_virtuals_error (decl1, TREE_TYPE (fntype)); | |
11717 | } | |
b7484fbe | 11718 | |
8d08fdba | 11719 | if (warn_about_return_type) |
59f1f2c4 | 11720 | pedwarn ("return-type defaults to `int'"); |
8d08fdba | 11721 | |
824b9a4c | 11722 | /* Effective C++ rule 15. See also c_expand_return. */ |
eb448459 | 11723 | if (warn_ecpp |
824b9a4c MS |
11724 | && DECL_NAME (decl1) == ansi_opname[(int) MODIFY_EXPR] |
11725 | && TREE_TYPE (fntype) == void_type_node) | |
11726 | cp_warning ("`operator=' should return a reference to `*this'"); | |
11727 | ||
8d08fdba MS |
11728 | /* Make the init_value nonzero so pushdecl knows this is not tentative. |
11729 | error_mark_node is replaced below (in poplevel) with the BLOCK. */ | |
11730 | DECL_INITIAL (decl1) = error_mark_node; | |
11731 | ||
8d08fdba MS |
11732 | /* This function exists in static storage. |
11733 | (This does not mean `static' in the C sense!) */ | |
11734 | TREE_STATIC (decl1) = 1; | |
11735 | ||
878cd289 MS |
11736 | /* Record the decl so that the function name is defined. |
11737 | If we already have a decl for this name, and it is a FUNCTION_DECL, | |
11738 | use the old decl. */ | |
11739 | ||
5156628f | 11740 | if (processing_template_decl) |
3ac3d9ea | 11741 | decl1 = push_template_decl (decl1); |
5566b478 | 11742 | else if (pre_parsed_p == 0) |
878cd289 | 11743 | { |
75650646 MM |
11744 | /* A specialization is not used to guide overload resolution. */ |
11745 | if (flag_guiding_decls | |
11746 | || !DECL_TEMPLATE_SPECIALIZATION (decl1)) | |
11747 | decl1 = pushdecl (decl1); | |
878cd289 MS |
11748 | DECL_MAIN_VARIANT (decl1) = decl1; |
11749 | fntype = TREE_TYPE (decl1); | |
11750 | } | |
5566b478 MS |
11751 | |
11752 | current_function_decl = decl1; | |
878cd289 | 11753 | |
db5ae43f | 11754 | if (DECL_INTERFACE_KNOWN (decl1)) |
faae18ab | 11755 | { |
86052cc3 JM |
11756 | tree ctx = hack_decl_function_context (decl1); |
11757 | ||
faae18ab MS |
11758 | if (DECL_NOT_REALLY_EXTERN (decl1)) |
11759 | DECL_EXTERNAL (decl1) = 0; | |
86052cc3 JM |
11760 | |
11761 | if (ctx != NULL_TREE && DECL_THIS_INLINE (ctx) | |
11762 | && TREE_PUBLIC (ctx)) | |
11763 | /* This is a function in a local class in an extern inline | |
11764 | function. */ | |
11765 | comdat_linkage (decl1); | |
faae18ab | 11766 | } |
8d08fdba MS |
11767 | /* If this function belongs to an interface, it is public. |
11768 | If it belongs to someone else's interface, it is also external. | |
11769 | It doesn't matter whether it's inline or not. */ | |
5566b478 MS |
11770 | else if (interface_unknown == 0 |
11771 | && (! DECL_TEMPLATE_INSTANTIATION (decl1) | |
d11ad92e | 11772 | || flag_alt_external_templates)) |
8d08fdba | 11773 | { |
5566b478 | 11774 | if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1) |
5156628f | 11775 | || processing_template_decl) |
db5ae43f MS |
11776 | DECL_EXTERNAL (decl1) |
11777 | = (interface_only | |
faae18ab | 11778 | || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines)); |
db5ae43f | 11779 | else |
893de33c | 11780 | DECL_EXTERNAL (decl1) = 0; |
e8abc66f | 11781 | DECL_NOT_REALLY_EXTERN (decl1) = 0; |
db5ae43f | 11782 | DECL_INTERFACE_KNOWN (decl1) = 1; |
8d08fdba MS |
11783 | } |
11784 | else | |
a0a33927 MS |
11785 | { |
11786 | /* This is a definition, not a reference. | |
b7484fbe MS |
11787 | So clear DECL_EXTERNAL. */ |
11788 | DECL_EXTERNAL (decl1) = 0; | |
faae18ab | 11789 | |
5566b478 MS |
11790 | if ((DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)) |
11791 | && ! DECL_INTERFACE_KNOWN (decl1) | |
11792 | /* Don't try to defer nested functions for now. */ | |
e76a2646 | 11793 | && ! hack_decl_function_context (decl1)) |
878cd289 MS |
11794 | DECL_DEFER_OUTPUT (decl1) = 1; |
11795 | else | |
893de33c | 11796 | DECL_INTERFACE_KNOWN (decl1) = 1; |
db5ae43f | 11797 | } |
a9aedbc2 | 11798 | |
8d08fdba MS |
11799 | if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) |
11800 | { | |
11801 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
11802 | TREE_TYPE (decl1) = fntype | |
11803 | = build_function_type (TREE_TYPE (fntype), | |
11804 | TREE_CHAIN (TYPE_ARG_TYPES (fntype))); | |
5566b478 MS |
11805 | current_function_parms = TREE_CHAIN (current_function_parms); |
11806 | DECL_ARGUMENTS (decl1) = current_function_parms; | |
8d08fdba MS |
11807 | ctype = NULL_TREE; |
11808 | } | |
11809 | restype = TREE_TYPE (fntype); | |
11810 | ||
8d08fdba MS |
11811 | if (ctype) |
11812 | { | |
11813 | push_nested_class (ctype, 1); | |
11814 | ||
11815 | /* If we're compiling a friend function, neither of the variables | |
4ac14744 | 11816 | current_class_ptr nor current_class_type will have values. */ |
8d08fdba MS |
11817 | if (! doing_friend) |
11818 | { | |
11819 | /* We know that this was set up by `grokclassfn'. | |
11820 | We do not wait until `store_parm_decls', since evil | |
11821 | parse errors may never get us to that point. Here | |
11822 | we keep the consistency between `current_class_type' | |
4ac14744 | 11823 | and `current_class_ptr'. */ |
5566b478 | 11824 | tree t = current_function_parms; |
5f34005f RK |
11825 | |
11826 | my_friendly_assert (t != NULL_TREE | |
11827 | && TREE_CODE (t) == PARM_DECL, 162); | |
11828 | ||
dff6b454 RK |
11829 | if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE) |
11830 | { | |
11831 | int i = suspend_momentary (); | |
11832 | ||
11833 | /* Fool build_indirect_ref. */ | |
4ac14744 MS |
11834 | current_class_ptr = NULL_TREE; |
11835 | current_class_ref = build_indirect_ref (t, NULL_PTR); | |
11836 | current_class_ptr = t; | |
dff6b454 RK |
11837 | resume_momentary (i); |
11838 | } | |
11839 | else | |
11840 | /* We're having a signature pointer here. */ | |
4ac14744 | 11841 | current_class_ref = current_class_ptr = t; |
dff6b454 | 11842 | |
8d08fdba MS |
11843 | } |
11844 | } | |
11845 | else | |
11846 | { | |
11847 | if (DECL_STATIC_FUNCTION_P (decl1)) | |
11848 | push_nested_class (DECL_CONTEXT (decl1), 2); | |
11849 | else | |
11850 | push_memoized_context (0, 1); | |
4ac14744 | 11851 | current_class_ptr = current_class_ref = NULL_TREE; |
8d08fdba MS |
11852 | } |
11853 | ||
db5ae43f MS |
11854 | pushlevel (0); |
11855 | current_binding_level->parm_flag = 1; | |
11856 | ||
db5ae43f MS |
11857 | GNU_xref_function (decl1, current_function_parms); |
11858 | ||
f30432d7 MS |
11859 | if (attrs) |
11860 | cplus_decl_attributes (decl1, NULL_TREE, attrs); | |
db5ae43f MS |
11861 | make_function_rtl (decl1); |
11862 | ||
8d08fdba MS |
11863 | /* Promote the value to int before returning it. */ |
11864 | if (C_PROMOTING_INTEGER_TYPE_P (restype)) | |
5566b478 MS |
11865 | restype = type_promotes_to (restype); |
11866 | ||
11867 | /* If this fcn was already referenced via a block-scope `extern' decl | |
11868 | (or an implicit decl), propagate certain information about the usage. */ | |
11869 | if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) | |
11870 | TREE_ADDRESSABLE (decl1) = 1; | |
11871 | ||
8d08fdba | 11872 | if (DECL_RESULT (decl1) == NULL_TREE) |
f30432d7 MS |
11873 | { |
11874 | DECL_RESULT (decl1) | |
11875 | = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype)); | |
11876 | TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype); | |
11877 | TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype); | |
11878 | } | |
8d08fdba | 11879 | |
5566b478 MS |
11880 | /* Allocate further tree nodes temporarily during compilation |
11881 | of this function only. Tiemann moved up here from bottom of fn. */ | |
11882 | temporary_allocation (); | |
11883 | ||
5156628f | 11884 | if (processing_template_decl) |
5566b478 | 11885 | { |
5566b478 MS |
11886 | ++minimal_parse_mode; |
11887 | last_tree = DECL_SAVED_TREE (decl1) | |
11888 | = build_nt (EXPR_STMT, void_zero_node); | |
11889 | } | |
11890 | ||
11891 | ++function_depth; | |
11892 | ||
f30432d7 MS |
11893 | if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)) |
11894 | && DECL_LANGUAGE (decl1) == lang_cplusplus) | |
8d08fdba MS |
11895 | { |
11896 | dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
11897 | ctor_label = NULL_TREE; | |
11898 | } | |
11899 | else | |
11900 | { | |
11901 | dtor_label = NULL_TREE; | |
11902 | if (DECL_CONSTRUCTOR_P (decl1)) | |
11903 | ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
11904 | } | |
11905 | ||
8d08fdba MS |
11906 | return 1; |
11907 | } | |
11908 | \f | |
9664b89e JM |
11909 | /* Called after store_parm_decls for a function-try-block. We need to update |
11910 | last_parm_cleanup_insn so that the base initializers for a constructor | |
11911 | are run within this block, not before it. */ | |
6467930b MS |
11912 | |
11913 | void | |
11914 | expand_start_early_try_stmts () | |
11915 | { | |
6467930b | 11916 | expand_start_try_stmts (); |
9664b89e | 11917 | last_parm_cleanup_insn = get_last_insn (); |
f30432d7 MS |
11918 | } |
11919 | ||
8d08fdba MS |
11920 | /* Store the parameter declarations into the current function declaration. |
11921 | This is called after parsing the parameter declarations, before | |
11922 | digesting the body of the function. | |
11923 | ||
11924 | Also install to binding contour return value identifier, if any. */ | |
11925 | ||
11926 | void | |
11927 | store_parm_decls () | |
11928 | { | |
11929 | register tree fndecl = current_function_decl; | |
11930 | register tree parm; | |
11931 | int parms_have_cleanups = 0; | |
eb66be0e | 11932 | tree cleanups = NULL_TREE; |
8d08fdba MS |
11933 | |
11934 | /* This is either a chain of PARM_DECLs (when a prototype is used). */ | |
11935 | tree specparms = current_function_parms; | |
11936 | ||
11937 | /* This is a list of types declared among parms in a prototype. */ | |
11938 | tree parmtags = current_function_parm_tags; | |
11939 | ||
11940 | /* This is a chain of any other decls that came in among the parm | |
11941 | declarations. If a parm is declared with enum {foo, bar} x; | |
11942 | then CONST_DECLs for foo and bar are put here. */ | |
11943 | tree nonparms = NULL_TREE; | |
11944 | ||
a9aedbc2 | 11945 | if (toplevel_bindings_p ()) |
8d08fdba MS |
11946 | fatal ("parse errors have confused me too much"); |
11947 | ||
11948 | /* Initialize RTL machinery. */ | |
11949 | init_function_start (fndecl, input_filename, lineno); | |
11950 | ||
11951 | /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ | |
11952 | declare_function_name (); | |
11953 | ||
11954 | /* Create a binding level for the parms. */ | |
11955 | expand_start_bindings (0); | |
11956 | ||
8d08fdba MS |
11957 | if (specparms != NULL_TREE) |
11958 | { | |
11959 | /* This case is when the function was defined with an ANSI prototype. | |
11960 | The parms already have decls, so we need not do anything here | |
11961 | except record them as in effect | |
11962 | and complain if any redundant old-style parm decls were written. */ | |
11963 | ||
11964 | register tree next; | |
11965 | ||
11966 | /* Must clear this because it might contain TYPE_DECLs declared | |
11967 | at class level. */ | |
11968 | storedecls (NULL_TREE); | |
5566b478 | 11969 | |
8d08fdba MS |
11970 | for (parm = nreverse (specparms); parm; parm = next) |
11971 | { | |
11972 | next = TREE_CHAIN (parm); | |
11973 | if (TREE_CODE (parm) == PARM_DECL) | |
11974 | { | |
5566b478 | 11975 | tree cleanup; |
8d08fdba MS |
11976 | if (DECL_NAME (parm) == NULL_TREE) |
11977 | { | |
8d08fdba | 11978 | pushdecl (parm); |
8d08fdba MS |
11979 | } |
11980 | else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) | |
11981 | cp_error ("parameter `%D' declared void", parm); | |
11982 | else | |
11983 | { | |
11984 | /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls. | |
11985 | A parameter is assumed not to have any side effects. | |
11986 | If this should change for any reason, then this | |
11987 | will have to wrap the bashed reference type in a save_expr. | |
11988 | ||
11989 | Also, if the parameter type is declared to be an X | |
11990 | and there is an X(X&) constructor, we cannot lay it | |
11991 | into the stack (any more), so we make this parameter | |
11992 | look like it is really of reference type. Functions | |
11993 | which pass parameters to this function will know to | |
11994 | create a temporary in their frame, and pass a reference | |
11995 | to that. */ | |
11996 | ||
11997 | if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE | |
11998 | && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm)))) | |
11999 | SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm)); | |
12000 | ||
12001 | pushdecl (parm); | |
12002 | } | |
5156628f | 12003 | if (! processing_template_decl |
5566b478 | 12004 | && (cleanup = maybe_build_cleanup (parm), cleanup)) |
8d08fdba MS |
12005 | { |
12006 | expand_decl (parm); | |
8d08fdba | 12007 | parms_have_cleanups = 1; |
eb66be0e MS |
12008 | |
12009 | /* Keep track of the cleanups. */ | |
12010 | cleanups = tree_cons (parm, cleanup, cleanups); | |
8d08fdba MS |
12011 | } |
12012 | } | |
12013 | else | |
12014 | { | |
12015 | /* If we find an enum constant or a type tag, | |
12016 | put it aside for the moment. */ | |
12017 | TREE_CHAIN (parm) = NULL_TREE; | |
12018 | nonparms = chainon (nonparms, parm); | |
12019 | } | |
12020 | } | |
12021 | ||
12022 | /* Get the decls in their original chain order | |
12023 | and record in the function. This is all and only the | |
12024 | PARM_DECLs that were pushed into scope by the loop above. */ | |
12025 | DECL_ARGUMENTS (fndecl) = getdecls (); | |
12026 | ||
12027 | storetags (chainon (parmtags, gettags ())); | |
12028 | } | |
12029 | else | |
12030 | DECL_ARGUMENTS (fndecl) = NULL_TREE; | |
12031 | ||
12032 | /* Now store the final chain of decls for the arguments | |
12033 | as the decl-chain of the current lexical scope. | |
12034 | Put the enumerators in as well, at the front so that | |
12035 | DECL_ARGUMENTS is not modified. */ | |
12036 | ||
12037 | storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); | |
12038 | ||
12039 | /* Initialize the RTL code for the function. */ | |
12040 | DECL_SAVED_INSNS (fndecl) = NULL_RTX; | |
5156628f | 12041 | if (! processing_template_decl) |
5566b478 | 12042 | expand_function_start (fndecl, parms_have_cleanups); |
8d08fdba | 12043 | |
eb448459 MS |
12044 | current_function_parms_stored = 1; |
12045 | ||
12046 | /* If this function is `main', emit a call to `__main' | |
12047 | to run global initializers, etc. */ | |
12048 | if (DECL_NAME (fndecl) | |
12049 | && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 | |
12050 | && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 | |
12051 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
12052 | { | |
12053 | expand_main_function (); | |
12054 | } | |
12055 | ||
eb66be0e MS |
12056 | /* Now that we have initialized the parms, we can start their |
12057 | cleanups. We cannot do this before, since expand_decl_cleanup | |
12058 | should not be called before the parm can be used. */ | |
eb448459 | 12059 | if (cleanups |
eb66be0e MS |
12060 | && ! processing_template_decl) |
12061 | { | |
12062 | for (cleanups = nreverse (cleanups); cleanups; cleanups = TREE_CHAIN (cleanups)) | |
12063 | { | |
12064 | if (! expand_decl_cleanup (TREE_PURPOSE (cleanups), TREE_VALUE (cleanups))) | |
12065 | cp_error ("parser lost in parsing declaration of `%D'", | |
12066 | TREE_PURPOSE (cleanups)); | |
12067 | } | |
12068 | } | |
12069 | ||
8d08fdba MS |
12070 | /* Create a binding contour which can be used to catch |
12071 | cleanup-generated temporaries. Also, if the return value needs or | |
12072 | has initialization, deal with that now. */ | |
12073 | if (parms_have_cleanups) | |
12074 | { | |
12075 | pushlevel (0); | |
12076 | expand_start_bindings (0); | |
12077 | } | |
12078 | ||
5156628f | 12079 | if (! processing_template_decl && flag_exceptions) |
f30432d7 | 12080 | { |
f30432d7 MS |
12081 | /* Do the starting of the exception specifications, if we have any. */ |
12082 | if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) | |
12083 | expand_start_eh_spec (); | |
f30432d7 | 12084 | } |
eb448459 | 12085 | |
5c825fc2 | 12086 | last_parm_cleanup_insn = get_last_insn (); |
72b7eeff | 12087 | last_dtor_insn = get_last_insn (); |
8d08fdba MS |
12088 | } |
12089 | ||
12090 | /* Bind a name and initialization to the return value of | |
12091 | the current function. */ | |
e92cc029 | 12092 | |
8d08fdba MS |
12093 | void |
12094 | store_return_init (return_id, init) | |
12095 | tree return_id, init; | |
12096 | { | |
12097 | tree decl = DECL_RESULT (current_function_decl); | |
12098 | ||
e1cd6e56 | 12099 | if (pedantic) |
8d08fdba MS |
12100 | /* Give this error as many times as there are occurrences, |
12101 | so that users can use Emacs compilation buffers to find | |
12102 | and fix all such places. */ | |
8926095f | 12103 | pedwarn ("ANSI C++ does not permit named return values"); |
8d08fdba MS |
12104 | |
12105 | if (return_id != NULL_TREE) | |
12106 | { | |
12107 | if (DECL_NAME (decl) == NULL_TREE) | |
12108 | { | |
12109 | DECL_NAME (decl) = return_id; | |
12110 | DECL_ASSEMBLER_NAME (decl) = return_id; | |
12111 | } | |
12112 | else | |
e76a2646 | 12113 | cp_error ("return identifier `%D' already in place", decl); |
8d08fdba MS |
12114 | } |
12115 | ||
12116 | /* Can't let this happen for constructors. */ | |
12117 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
12118 | { | |
12119 | error ("can't redefine default return value for constructors"); | |
12120 | return; | |
12121 | } | |
12122 | ||
12123 | /* If we have a named return value, put that in our scope as well. */ | |
12124 | if (DECL_NAME (decl) != NULL_TREE) | |
12125 | { | |
12126 | /* If this named return value comes in a register, | |
12127 | put it in a pseudo-register. */ | |
12128 | if (DECL_REGISTER (decl)) | |
12129 | { | |
12130 | original_result_rtx = DECL_RTL (decl); | |
12131 | DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); | |
12132 | } | |
12133 | ||
82580166 | 12134 | /* Let `cp_finish_decl' know that this initializer is ok. */ |
8d08fdba MS |
12135 | DECL_INITIAL (decl) = init; |
12136 | pushdecl (decl); | |
e76a2646 MS |
12137 | |
12138 | if (minimal_parse_mode) | |
12139 | add_tree (build_min_nt (RETURN_INIT, return_id, | |
12140 | copy_to_permanent (init))); | |
12141 | else | |
dae1d6f6 | 12142 | cp_finish_decl (decl, init, NULL_TREE, 0, 0); |
8d08fdba MS |
12143 | } |
12144 | } | |
12145 | ||
8d08fdba MS |
12146 | \f |
12147 | /* Finish up a function declaration and compile that function | |
12148 | all the way to assembler language output. The free the storage | |
12149 | for the function definition. | |
12150 | ||
12151 | This is called after parsing the body of the function definition. | |
12152 | LINENO is the current line number. | |
12153 | ||
12154 | C++: CALL_POPLEVEL is non-zero if an extra call to poplevel | |
12155 | (and expand_end_bindings) must be made to take care of the binding | |
12156 | contour for the base initializers. This is only relevant for | |
e92cc029 MS |
12157 | constructors. |
12158 | ||
12159 | NESTED is nonzero if we were in the middle of compiling another function | |
12160 | when we started on this one. */ | |
8d08fdba MS |
12161 | |
12162 | void | |
db5ae43f | 12163 | finish_function (lineno, call_poplevel, nested) |
8d08fdba MS |
12164 | int lineno; |
12165 | int call_poplevel; | |
db5ae43f | 12166 | int nested; |
8d08fdba MS |
12167 | { |
12168 | register tree fndecl = current_function_decl; | |
12169 | tree fntype, ctype = NULL_TREE; | |
f30432d7 | 12170 | rtx last_parm_insn, insns; |
8d08fdba MS |
12171 | /* Label to use if this function is supposed to return a value. */ |
12172 | tree no_return_label = NULL_TREE; | |
12173 | tree decls = NULL_TREE; | |
12174 | ||
12175 | /* When we get some parse errors, we can end up without a | |
12176 | current_function_decl, so cope. */ | |
12177 | if (fndecl == NULL_TREE) | |
12178 | return; | |
12179 | ||
e92cc029 MS |
12180 | if (! nested && function_depth > 1) |
12181 | nested = 1; | |
12182 | ||
8d08fdba MS |
12183 | fntype = TREE_TYPE (fndecl); |
12184 | ||
12185 | /* TREE_READONLY (fndecl) = 1; | |
12186 | This caused &foo to be of type ptr-to-const-function | |
12187 | which then got a warning when stored in a ptr-to-function variable. */ | |
12188 | ||
12189 | /* This happens on strange parse errors. */ | |
12190 | if (! current_function_parms_stored) | |
12191 | { | |
12192 | call_poplevel = 0; | |
12193 | store_parm_decls (); | |
12194 | } | |
12195 | ||
5156628f | 12196 | if (processing_template_decl) |
8d08fdba | 12197 | { |
5566b478 MS |
12198 | if (DECL_CONSTRUCTOR_P (fndecl) && call_poplevel) |
12199 | { | |
12200 | decls = getdecls (); | |
12201 | expand_end_bindings (decls, decls != NULL_TREE, 0); | |
12202 | poplevel (decls != NULL_TREE, 0, 0); | |
12203 | } | |
12204 | } | |
12205 | else | |
12206 | { | |
12207 | if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/) | |
8d08fdba | 12208 | { |
5566b478 MS |
12209 | tree ttype = target_type (fntype); |
12210 | tree parmdecl; | |
12211 | ||
8d08fdba MS |
12212 | if (IS_AGGR_TYPE (ttype)) |
12213 | /* Let debugger know it should output info for this type. */ | |
12214 | note_debug_info_needed (ttype); | |
5566b478 MS |
12215 | |
12216 | for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) | |
12217 | { | |
12218 | ttype = target_type (TREE_TYPE (parmdecl)); | |
12219 | if (IS_AGGR_TYPE (ttype)) | |
12220 | /* Let debugger know it should output info for this type. */ | |
12221 | note_debug_info_needed (ttype); | |
12222 | } | |
8d08fdba | 12223 | } |
8d08fdba | 12224 | |
5566b478 MS |
12225 | /* Clean house because we will need to reorder insns here. */ |
12226 | do_pending_stack_adjust (); | |
8d08fdba | 12227 | |
5566b478 | 12228 | if (dtor_label) |
8d08fdba | 12229 | { |
5566b478 MS |
12230 | tree binfo = TYPE_BINFO (current_class_type); |
12231 | tree cond = integer_one_node; | |
12232 | tree exprstmt; | |
12233 | tree in_charge_node = lookup_name (in_charge_identifier, 0); | |
12234 | tree virtual_size; | |
12235 | int ok_to_optimize_dtor = 0; | |
12236 | int empty_dtor = get_last_insn () == last_dtor_insn; | |
8d08fdba | 12237 | |
5566b478 MS |
12238 | if (current_function_assigns_this) |
12239 | cond = build (NE_EXPR, boolean_type_node, | |
4ac14744 | 12240 | current_class_ptr, integer_zero_node); |
5566b478 MS |
12241 | else |
12242 | { | |
12243 | int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); | |
12244 | ||
12245 | /* If this destructor is empty, then we don't need to check | |
12246 | whether `this' is NULL in some cases. */ | |
12247 | if ((flag_this_is_variable & 1) == 0) | |
12248 | ok_to_optimize_dtor = 1; | |
12249 | else if (empty_dtor) | |
12250 | ok_to_optimize_dtor | |
12251 | = (n_baseclasses == 0 | |
12252 | || (n_baseclasses == 1 | |
12253 | && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); | |
12254 | } | |
8d08fdba | 12255 | |
5566b478 MS |
12256 | /* These initializations might go inline. Protect |
12257 | the binding level of the parms. */ | |
12258 | pushlevel (0); | |
12259 | expand_start_bindings (0); | |
8d08fdba | 12260 | |
5566b478 MS |
12261 | if (current_function_assigns_this) |
12262 | { | |
12263 | current_function_assigns_this = 0; | |
12264 | current_function_just_assigned_this = 0; | |
12265 | } | |
8d08fdba | 12266 | |
5566b478 MS |
12267 | /* Generate the code to call destructor on base class. |
12268 | If this destructor belongs to a class with virtual | |
12269 | functions, then set the virtual function table | |
12270 | pointer to represent the type of our base class. */ | |
8d08fdba | 12271 | |
5566b478 MS |
12272 | /* This side-effect makes call to `build_delete' generate the |
12273 | code we have to have at the end of this destructor. */ | |
12274 | TYPE_HAS_DESTRUCTOR (current_class_type) = 0; | |
8d08fdba | 12275 | |
5566b478 MS |
12276 | /* These are two cases where we cannot delegate deletion. */ |
12277 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) | |
12278 | || TYPE_GETS_REG_DELETE (current_class_type)) | |
4ac14744 | 12279 | exprstmt = build_delete (current_class_type, current_class_ref, integer_zero_node, |
e92cc029 | 12280 | LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); |
5566b478 | 12281 | else |
4ac14744 | 12282 | exprstmt = build_delete (current_class_type, current_class_ref, in_charge_node, |
e92cc029 | 12283 | LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); |
5566b478 MS |
12284 | |
12285 | /* If we did not assign to this, then `this' is non-zero at | |
12286 | the end of a destructor. As a special optimization, don't | |
12287 | emit test if this is an empty destructor. If it does nothing, | |
12288 | it does nothing. If it calls a base destructor, the base | |
12289 | destructor will perform the test. */ | |
12290 | ||
12291 | if (exprstmt != error_mark_node | |
12292 | && (TREE_CODE (exprstmt) != NOP_EXPR | |
12293 | || TREE_OPERAND (exprstmt, 0) != integer_zero_node | |
12294 | || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) | |
8d08fdba | 12295 | { |
5566b478 MS |
12296 | expand_label (dtor_label); |
12297 | if (cond != integer_one_node) | |
12298 | expand_start_cond (cond, 0); | |
12299 | if (exprstmt != void_zero_node) | |
12300 | /* Don't call `expand_expr_stmt' if we're not going to do | |
12301 | anything, since -Wall will give a diagnostic. */ | |
12302 | expand_expr_stmt (exprstmt); | |
12303 | ||
12304 | /* Run destructor on all virtual baseclasses. */ | |
12305 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) | |
8d08fdba | 12306 | { |
5566b478 MS |
12307 | tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); |
12308 | expand_start_cond (build (BIT_AND_EXPR, integer_type_node, | |
12309 | in_charge_node, integer_two_node), 0); | |
12310 | while (vbases) | |
8d08fdba | 12311 | { |
5566b478 MS |
12312 | if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) |
12313 | { | |
bd6dd845 MS |
12314 | tree vb = get_vbase |
12315 | (BINFO_TYPE (vbases), | |
12316 | TYPE_BINFO (current_class_type)); | |
e92cc029 | 12317 | expand_expr_stmt |
bd6dd845 MS |
12318 | (build_scoped_method_call |
12319 | (current_class_ref, vb, dtor_identifier, | |
e66d884e | 12320 | build_expr_list (NULL_TREE, integer_zero_node))); |
5566b478 MS |
12321 | } |
12322 | vbases = TREE_CHAIN (vbases); | |
8d08fdba | 12323 | } |
5566b478 | 12324 | expand_end_cond (); |
8d08fdba | 12325 | } |
5566b478 MS |
12326 | |
12327 | do_pending_stack_adjust (); | |
12328 | if (cond != integer_one_node) | |
12329 | expand_end_cond (); | |
8d08fdba MS |
12330 | } |
12331 | ||
5566b478 MS |
12332 | TYPE_HAS_DESTRUCTOR (current_class_type) = 1; |
12333 | ||
12334 | virtual_size = c_sizeof (current_class_type); | |
12335 | ||
12336 | /* At the end, call delete if that's what's requested. */ | |
12337 | if (TYPE_GETS_REG_DELETE (current_class_type)) | |
12338 | /* This NOP_EXPR means we are in a static call context. */ | |
beb53fb8 JM |
12339 | exprstmt |
12340 | = build_method_call (build_indirect_ref (build1 (NOP_EXPR, | |
12341 | build_pointer_type (current_class_type), | |
12342 | error_mark_node), | |
12343 | NULL_PTR), | |
12344 | ansi_opname[(int) DELETE_EXPR], | |
e66d884e JM |
12345 | expr_tree_cons (NULL_TREE, current_class_ptr, |
12346 | build_expr_list (NULL_TREE, virtual_size)), | |
beb53fb8 | 12347 | NULL_TREE, LOOKUP_NORMAL); |
5566b478 | 12348 | else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) |
4ac14744 | 12349 | exprstmt = build_x_delete (ptr_type_node, current_class_ptr, 0, |
5566b478 MS |
12350 | virtual_size); |
12351 | else | |
12352 | exprstmt = NULL_TREE; | |
8d08fdba | 12353 | |
5566b478 MS |
12354 | if (exprstmt) |
12355 | { | |
12356 | cond = build (BIT_AND_EXPR, integer_type_node, | |
12357 | in_charge_node, integer_one_node); | |
12358 | expand_start_cond (cond, 0); | |
12359 | expand_expr_stmt (exprstmt); | |
12360 | expand_end_cond (); | |
12361 | } | |
8d08fdba | 12362 | |
5566b478 | 12363 | /* End of destructor. */ |
fc378698 | 12364 | expand_end_bindings (NULL_TREE, getdecls () != NULL_TREE, 0); |
5566b478 MS |
12365 | poplevel (2, 0, 0); /* XXX change to 1 */ |
12366 | ||
12367 | /* Back to the top of destructor. */ | |
956d6950 | 12368 | /* Don't execute destructor code if `this' is NULL. */ |
5566b478 MS |
12369 | |
12370 | start_sequence (); | |
12371 | ||
12372 | /* If the dtor is empty, and we know there is not possible way we | |
12373 | could use any vtable entries, before they are possibly set by | |
12374 | a base class dtor, we don't have to setup the vtables, as we | |
12375 | know that any base class dtoring will set up any vtables it | |
12376 | needs. We avoid MI, because one base class dtor can do a | |
12377 | virtual dispatch to an overridden function that would need to | |
12378 | have a non-related vtable set up, we cannot avoid setting up | |
12379 | vtables in that case. We could change this to see if there is | |
12380 | just one vtable. */ | |
12381 | if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type)) | |
12382 | { | |
12383 | /* Make all virtual function table pointers in non-virtual base | |
12384 | classes point to CURRENT_CLASS_TYPE's virtual function | |
12385 | tables. */ | |
4ac14744 | 12386 | expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr); |
8d08fdba | 12387 | |
5566b478 | 12388 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) |
4ac14744 | 12389 | expand_indirect_vtbls_init (binfo, current_class_ref, current_class_ptr); |
5566b478 MS |
12390 | } |
12391 | ||
12392 | if (! ok_to_optimize_dtor) | |
12393 | { | |
12394 | cond = build_binary_op (NE_EXPR, | |
4ac14744 | 12395 | current_class_ptr, integer_zero_node, 1); |
5566b478 MS |
12396 | expand_start_cond (cond, 0); |
12397 | } | |
8d08fdba | 12398 | |
5566b478 MS |
12399 | insns = get_insns (); |
12400 | end_sequence (); | |
f30432d7 | 12401 | |
5566b478 MS |
12402 | last_parm_insn = get_first_nonparm_insn (); |
12403 | if (last_parm_insn == NULL_RTX) | |
12404 | last_parm_insn = get_last_insn (); | |
12405 | else | |
12406 | last_parm_insn = previous_insn (last_parm_insn); | |
8d08fdba | 12407 | |
5566b478 | 12408 | emit_insns_after (insns, last_parm_insn); |
72b7eeff | 12409 | |
5566b478 MS |
12410 | if (! ok_to_optimize_dtor) |
12411 | expand_end_cond (); | |
72b7eeff | 12412 | } |
5566b478 | 12413 | else if (current_function_assigns_this) |
8d08fdba | 12414 | { |
5566b478 MS |
12415 | /* Does not need to call emit_base_init, because |
12416 | that is done (if needed) just after assignment to this | |
12417 | is seen. */ | |
12418 | ||
12419 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
12420 | { | |
12421 | end_protect_partials (); | |
12422 | expand_label (ctor_label); | |
12423 | ctor_label = NULL_TREE; | |
12424 | ||
12425 | if (call_poplevel) | |
12426 | { | |
12427 | decls = getdecls (); | |
12428 | expand_end_bindings (decls, decls != NULL_TREE, 0); | |
12429 | poplevel (decls != NULL_TREE, 0, 0); | |
12430 | } | |
4ac14744 | 12431 | c_expand_return (current_class_ptr); |
5566b478 MS |
12432 | } |
12433 | else if (TYPE_MAIN_VARIANT (TREE_TYPE ( | |
12434 | DECL_RESULT (current_function_decl))) != void_type_node | |
12435 | && return_label != NULL_RTX) | |
12436 | no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
12437 | ||
12438 | current_function_assigns_this = 0; | |
12439 | current_function_just_assigned_this = 0; | |
12440 | base_init_expr = NULL_TREE; | |
8d08fdba | 12441 | } |
5566b478 MS |
12442 | else if (DECL_CONSTRUCTOR_P (fndecl)) |
12443 | { | |
a703fb38 | 12444 | tree cond = NULL_TREE, thenclause = NULL_TREE; |
5566b478 MS |
12445 | /* Allow constructor for a type to get a new instance of the object |
12446 | using `build_new'. */ | |
12447 | tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); | |
12448 | CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; | |
f30432d7 | 12449 | |
5566b478 | 12450 | DECL_RETURNS_FIRST_ARG (fndecl) = 1; |
f30432d7 | 12451 | |
5566b478 MS |
12452 | if (flag_this_is_variable > 0) |
12453 | { | |
12454 | cond = build_binary_op (EQ_EXPR, | |
4ac14744 MS |
12455 | current_class_ptr, integer_zero_node, 1); |
12456 | thenclause = build_modify_expr (current_class_ptr, NOP_EXPR, | |
5566b478 MS |
12457 | build_new (NULL_TREE, current_class_type, void_type_node, 0)); |
12458 | } | |
f30432d7 | 12459 | |
5566b478 | 12460 | CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; |
f30432d7 | 12461 | |
5566b478 MS |
12462 | start_sequence (); |
12463 | ||
12464 | if (flag_this_is_variable > 0) | |
12465 | { | |
12466 | expand_start_cond (cond, 0); | |
12467 | expand_expr_stmt (thenclause); | |
12468 | expand_end_cond (); | |
12469 | } | |
12470 | ||
12471 | /* Emit insns from `emit_base_init' which sets up virtual | |
12472 | function table pointer(s). */ | |
12473 | if (base_init_expr) | |
12474 | { | |
12475 | expand_expr_stmt (base_init_expr); | |
12476 | base_init_expr = NULL_TREE; | |
12477 | } | |
12478 | ||
12479 | insns = get_insns (); | |
12480 | end_sequence (); | |
12481 | ||
b87692e5 | 12482 | /* This is where the body of the constructor begins. */ |
5566b478 | 12483 | |
b87692e5 | 12484 | emit_insns_after (insns, last_parm_cleanup_insn); |
8d08fdba | 12485 | |
b7484fbe | 12486 | end_protect_partials (); |
5566b478 MS |
12487 | |
12488 | /* This is where the body of the constructor ends. */ | |
8d08fdba MS |
12489 | expand_label (ctor_label); |
12490 | ctor_label = NULL_TREE; | |
12491 | ||
12492 | if (call_poplevel) | |
12493 | { | |
12494 | decls = getdecls (); | |
8d08fdba | 12495 | expand_end_bindings (decls, decls != NULL_TREE, 0); |
5566b478 | 12496 | poplevel (decls != NULL_TREE, 1, 0); |
8d08fdba | 12497 | } |
8d08fdba | 12498 | |
4ac14744 | 12499 | c_expand_return (current_class_ptr); |
8d08fdba | 12500 | |
5566b478 MS |
12501 | current_function_assigns_this = 0; |
12502 | current_function_just_assigned_this = 0; | |
12503 | } | |
12504 | else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 | |
12505 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") | |
12506 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
8d08fdba | 12507 | { |
5566b478 MS |
12508 | /* Make it so that `main' always returns 0 by default. */ |
12509 | #ifdef VMS | |
12510 | c_expand_return (integer_one_node); | |
12511 | #else | |
12512 | c_expand_return (integer_zero_node); | |
12513 | #endif | |
8d08fdba | 12514 | } |
5566b478 MS |
12515 | else if (return_label != NULL_RTX |
12516 | && current_function_return_value == NULL_TREE | |
12517 | && ! DECL_NAME (DECL_RESULT (current_function_decl))) | |
12518 | no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
8d08fdba | 12519 | |
eb448459 MS |
12520 | if (flag_exceptions) |
12521 | expand_exception_blocks (); | |
12522 | ||
5566b478 MS |
12523 | /* If this function is supposed to return a value, ensure that |
12524 | we do not fall into the cleanups by mistake. The end of our | |
12525 | function will look like this: | |
12526 | ||
12527 | user code (may have return stmt somewhere) | |
12528 | goto no_return_label | |
12529 | cleanup_label: | |
12530 | cleanups | |
12531 | goto return_label | |
12532 | no_return_label: | |
12533 | NOTE_INSN_FUNCTION_END | |
12534 | return_label: | |
12535 | things for return | |
12536 | ||
12537 | If the user omits a return stmt in the USER CODE section, we | |
12538 | will have a control path which reaches NOTE_INSN_FUNCTION_END. | |
12539 | Otherwise, we won't. */ | |
12540 | if (no_return_label) | |
8d08fdba | 12541 | { |
5566b478 MS |
12542 | DECL_CONTEXT (no_return_label) = fndecl; |
12543 | DECL_INITIAL (no_return_label) = error_mark_node; | |
12544 | DECL_SOURCE_FILE (no_return_label) = input_filename; | |
12545 | DECL_SOURCE_LINE (no_return_label) = lineno; | |
12546 | expand_goto (no_return_label); | |
8d08fdba MS |
12547 | } |
12548 | ||
5566b478 | 12549 | if (cleanup_label) |
a9aedbc2 | 12550 | { |
5566b478 MS |
12551 | /* remove the binding contour which is used |
12552 | to catch cleanup-generated temporaries. */ | |
12553 | expand_end_bindings (0, 0, 0); | |
12554 | poplevel (0, 0, 0); | |
8d08fdba | 12555 | |
eb448459 MS |
12556 | /* Emit label at beginning of cleanup code for parameters. */ |
12557 | emit_label (cleanup_label); | |
12558 | } | |
b7484fbe | 12559 | |
5566b478 MS |
12560 | /* Get return value into register if that's where it's supposed to be. */ |
12561 | if (original_result_rtx) | |
12562 | fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); | |
8d08fdba | 12563 | |
5566b478 MS |
12564 | /* Finish building code that will trigger warnings if users forget |
12565 | to make their functions return values. */ | |
12566 | if (no_return_label || cleanup_label) | |
12567 | emit_jump (return_label); | |
12568 | if (no_return_label) | |
8d08fdba | 12569 | { |
5566b478 MS |
12570 | /* We don't need to call `expand_*_return' here because we |
12571 | don't need any cleanups here--this path of code is only | |
12572 | for error checking purposes. */ | |
12573 | expand_label (no_return_label); | |
8d08fdba MS |
12574 | } |
12575 | ||
5566b478 MS |
12576 | /* Generate rtl for function exit. */ |
12577 | expand_function_end (input_filename, lineno, 1); | |
8d08fdba | 12578 | } |
8d2733ca | 12579 | |
8d08fdba MS |
12580 | /* This must come after expand_function_end because cleanups might |
12581 | have declarations (from inline functions) that need to go into | |
12582 | this function's blocks. */ | |
12583 | if (current_binding_level->parm_flag != 1) | |
12584 | my_friendly_abort (122); | |
12585 | poplevel (1, 0, 1); | |
12586 | ||
db5ae43f MS |
12587 | /* reset scope for C++: if we were in the scope of a class, |
12588 | then when we finish this function, we are not longer so. | |
12589 | This cannot be done until we know for sure that no more | |
12590 | class members will ever be referenced in this function | |
12591 | (i.e., calls to destructors). */ | |
12592 | if (current_class_name) | |
12593 | { | |
12594 | ctype = current_class_type; | |
12595 | pop_nested_class (1); | |
12596 | } | |
12597 | else | |
12598 | pop_memoized_context (1); | |
12599 | ||
8d08fdba | 12600 | /* Must mark the RESULT_DECL as being in this function. */ |
c73964b2 | 12601 | DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; |
8d08fdba | 12602 | |
8d08fdba MS |
12603 | /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point |
12604 | to the FUNCTION_DECL node itself. */ | |
12605 | BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; | |
12606 | ||
5156628f | 12607 | if (! processing_template_decl) |
5566b478 | 12608 | { |
75650646 MM |
12609 | int saved_flag_keep_inline_functions = |
12610 | flag_keep_inline_functions; | |
12611 | ||
5566b478 MS |
12612 | /* So we can tell if jump_optimize sets it to 1. */ |
12613 | can_reach_end = 0; | |
8d08fdba | 12614 | |
75650646 | 12615 | if (DECL_CONTEXT (fndecl) != NULL_TREE |
e1467ff2 | 12616 | && hack_decl_function_context (fndecl)) |
75650646 MM |
12617 | /* Trick rest_of_compilation into not deferring output of this |
12618 | function, even if it is inline, since the rtl_obstack for | |
12619 | this function is the function_obstack of the enclosing | |
12620 | function and will be deallocated when the enclosing | |
12621 | function is gone. See save_tree_status. */ | |
12622 | flag_keep_inline_functions = 1; | |
12623 | ||
6633d636 MS |
12624 | /* Run the optimizers and output the assembler code for this |
12625 | function. */ | |
12626 | ||
12627 | if (DECL_ARTIFICIAL (fndecl)) | |
12628 | { | |
12629 | /* Do we really *want* to inline this synthesized method? */ | |
12630 | ||
12631 | int save_fif = flag_inline_functions; | |
12632 | flag_inline_functions = 1; | |
12633 | ||
12634 | /* Turn off DECL_INLINE for the moment so function_cannot_inline_p | |
12635 | will check our size. */ | |
12636 | DECL_INLINE (fndecl) = 0; | |
12637 | ||
12638 | rest_of_compilation (fndecl); | |
12639 | flag_inline_functions = save_fif; | |
12640 | } | |
12641 | else | |
12642 | rest_of_compilation (fndecl); | |
8d08fdba | 12643 | |
75650646 MM |
12644 | flag_keep_inline_functions = saved_flag_keep_inline_functions; |
12645 | ||
5566b478 MS |
12646 | if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl)) |
12647 | { | |
12648 | /* Set DECL_EXTERNAL so that assemble_external will be called as | |
12649 | necessary. We'll clear it again in finish_file. */ | |
12650 | if (! DECL_EXTERNAL (fndecl)) | |
12651 | DECL_NOT_REALLY_EXTERN (fndecl) = 1; | |
12652 | DECL_EXTERNAL (fndecl) = 1; | |
12653 | mark_inline_for_output (fndecl); | |
12654 | } | |
8926095f | 12655 | |
d2e5ee5c MS |
12656 | if (ctype && TREE_ASM_WRITTEN (fndecl)) |
12657 | note_debug_info_needed (ctype); | |
12658 | ||
5566b478 | 12659 | current_function_returns_null |= can_reach_end; |
8d08fdba | 12660 | |
5566b478 MS |
12661 | /* Since we don't normally go through c_expand_return for constructors, |
12662 | this normally gets the wrong value. | |
12663 | Also, named return values have their return codes emitted after | |
12664 | NOTE_INSN_FUNCTION_END, confusing jump.c. */ | |
12665 | if (DECL_CONSTRUCTOR_P (fndecl) | |
12666 | || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) | |
12667 | current_function_returns_null = 0; | |
8d08fdba | 12668 | |
5566b478 MS |
12669 | if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) |
12670 | cp_warning ("`noreturn' function `%D' does return", fndecl); | |
12671 | else if ((warn_return_type || pedantic) | |
12672 | && current_function_returns_null | |
12673 | && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node) | |
12674 | { | |
12675 | /* If this function returns non-void and control can drop through, | |
12676 | complain. */ | |
14e403d4 | 12677 | cp_warning ("control reaches end of non-void function `%D'", fndecl); |
5566b478 MS |
12678 | } |
12679 | /* With just -W, complain only if function returns both with | |
12680 | and without a value. */ | |
12681 | else if (extra_warnings | |
12682 | && current_function_returns_value && current_function_returns_null) | |
12683 | warning ("this function may return with or without a value"); | |
8d08fdba | 12684 | } |
5566b478 MS |
12685 | |
12686 | --function_depth; | |
8d08fdba MS |
12687 | |
12688 | /* Free all the tree nodes making up this function. */ | |
12689 | /* Switch back to allocating nodes permanently | |
12690 | until we start another function. */ | |
5156628f | 12691 | if (processing_template_decl) |
5566b478 MS |
12692 | { |
12693 | --minimal_parse_mode; | |
12694 | DECL_SAVED_TREE (fndecl) = TREE_CHAIN (DECL_SAVED_TREE (fndecl)); | |
12695 | } | |
12696 | ||
db5ae43f MS |
12697 | if (! nested) |
12698 | permanent_allocation (1); | |
8d08fdba | 12699 | |
8d08fdba MS |
12700 | if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) |
12701 | { | |
d2e5ee5c MS |
12702 | tree t; |
12703 | ||
8d08fdba MS |
12704 | /* Stop pointing to the local nodes about to be freed. */ |
12705 | /* But DECL_INITIAL must remain nonzero so we know this | |
12706 | was an actual function definition. */ | |
12707 | DECL_INITIAL (fndecl) = error_mark_node; | |
d2e5ee5c | 12708 | for (t = DECL_ARGUMENTS (fndecl); t; t = TREE_CHAIN (t)) |
de22184b | 12709 | DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX; |
8d08fdba MS |
12710 | } |
12711 | ||
e1cd6e56 MS |
12712 | if (DECL_STATIC_CONSTRUCTOR (fndecl)) |
12713 | static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors); | |
12714 | if (DECL_STATIC_DESTRUCTOR (fndecl)) | |
12715 | static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors); | |
12716 | ||
28cbf42c MS |
12717 | if (! nested) |
12718 | { | |
12719 | /* Let the error reporting routines know that we're outside a | |
12720 | function. For a nested function, this value is used in | |
12721 | pop_cp_function_context and then reset via pop_function_context. */ | |
12722 | current_function_decl = NULL_TREE; | |
12723 | } | |
12724 | ||
e349ee73 | 12725 | named_label_uses = NULL; |
4ac14744 MS |
12726 | current_class_ptr = NULL_TREE; |
12727 | current_class_ref = NULL_TREE; | |
8d08fdba MS |
12728 | } |
12729 | \f | |
12730 | /* Create the FUNCTION_DECL for a function definition. | |
12731 | LINE1 is the line number that the definition absolutely begins on. | |
12732 | LINE2 is the line number that the name of the function appears on. | |
12733 | DECLSPECS and DECLARATOR are the parts of the declaration; | |
12734 | they describe the return type and the name of the function, | |
12735 | but twisted together in a fashion that parallels the syntax of C. | |
12736 | ||
12737 | This function creates a binding context for the function body | |
12738 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
12739 | ||
12740 | Returns a FUNCTION_DECL on success. | |
12741 | ||
12742 | If the DECLARATOR is not suitable for a function (it defines a datum | |
12743 | instead), we return 0, which tells yyparse to report a parse error. | |
12744 | ||
12745 | May return void_type_node indicating that this method is actually | |
12746 | a friend. See grokfield for more details. | |
12747 | ||
12748 | Came here with a `.pushlevel' . | |
12749 | ||
12750 | DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING | |
12751 | CHANGES TO CODE IN `grokfield'. */ | |
e92cc029 | 12752 | |
8d08fdba | 12753 | tree |
c11b6f21 MS |
12754 | start_method (declspecs, declarator) |
12755 | tree declarator, declspecs; | |
8d08fdba | 12756 | { |
c11b6f21 | 12757 | tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, |
f30432d7 | 12758 | NULL_TREE); |
8d08fdba MS |
12759 | |
12760 | /* Something too ugly to handle. */ | |
12761 | if (fndecl == NULL_TREE) | |
12762 | return NULL_TREE; | |
12763 | ||
12764 | /* Pass friends other than inline friend functions back. */ | |
12765 | if (TYPE_MAIN_VARIANT (fndecl) == void_type_node) | |
12766 | return fndecl; | |
12767 | ||
12768 | if (TREE_CODE (fndecl) != FUNCTION_DECL) | |
12769 | /* Not a function, tell parser to report parse error. */ | |
12770 | return NULL_TREE; | |
12771 | ||
12772 | if (IS_SIGNATURE (current_class_type)) | |
824b9a4c | 12773 | IS_DEFAULT_IMPLEMENTATION (fndecl) = 1; |
8d08fdba MS |
12774 | |
12775 | if (DECL_IN_AGGR_P (fndecl)) | |
12776 | { | |
12777 | if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) | |
12778 | { | |
12779 | if (DECL_CONTEXT (fndecl)) | |
12780 | cp_error ("`%D' is already defined in class %s", fndecl, | |
12781 | TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); | |
12782 | } | |
12783 | return void_type_node; | |
12784 | } | |
12785 | ||
faae18ab MS |
12786 | DECL_THIS_INLINE (fndecl) = 1; |
12787 | ||
8926095f | 12788 | if (flag_default_inline) |
8d08fdba MS |
12789 | DECL_INLINE (fndecl) = 1; |
12790 | ||
75650646 | 12791 | if (processing_template_decl) |
3ac3d9ea | 12792 | fndecl = push_template_decl (fndecl); |
a0a33927 | 12793 | |
8d08fdba MS |
12794 | /* We read in the parameters on the maybepermanent_obstack, |
12795 | but we won't be getting back to them until after we | |
12796 | may have clobbered them. So the call to preserve_data | |
12797 | will keep them safe. */ | |
12798 | preserve_data (); | |
12799 | ||
12800 | if (! DECL_FRIEND_P (fndecl)) | |
12801 | { | |
12802 | if (DECL_CHAIN (fndecl) != NULL_TREE) | |
12803 | { | |
12804 | /* Need a fresh node here so that we don't get circularity | |
12805 | when we link these together. If FNDECL was a friend, then | |
12806 | `pushdecl' does the right thing, which is nothing wrt its | |
12807 | current value of DECL_CHAIN. */ | |
12808 | fndecl = copy_node (fndecl); | |
12809 | } | |
12810 | if (TREE_CHAIN (fndecl)) | |
12811 | { | |
12812 | fndecl = copy_node (fndecl); | |
12813 | TREE_CHAIN (fndecl) = NULL_TREE; | |
12814 | } | |
12815 | ||
12816 | if (DECL_CONSTRUCTOR_P (fndecl)) | |
a0a33927 MS |
12817 | { |
12818 | if (! grok_ctor_properties (current_class_type, fndecl)) | |
12819 | return void_type_node; | |
12820 | } | |
8d08fdba MS |
12821 | else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) |
12822 | grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0); | |
12823 | } | |
12824 | ||
82580166 | 12825 | cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0); |
8d08fdba MS |
12826 | |
12827 | /* Make a place for the parms */ | |
12828 | pushlevel (0); | |
12829 | current_binding_level->parm_flag = 1; | |
12830 | ||
12831 | DECL_IN_AGGR_P (fndecl) = 1; | |
12832 | return fndecl; | |
12833 | } | |
12834 | ||
12835 | /* Go through the motions of finishing a function definition. | |
12836 | We don't compile this method until after the whole class has | |
12837 | been processed. | |
12838 | ||
12839 | FINISH_METHOD must return something that looks as though it | |
12840 | came from GROKFIELD (since we are defining a method, after all). | |
12841 | ||
12842 | This is called after parsing the body of the function definition. | |
12843 | STMTS is the chain of statements that makes up the function body. | |
12844 | ||
12845 | DECL is the ..._DECL that `start_method' provided. */ | |
12846 | ||
12847 | tree | |
12848 | finish_method (decl) | |
12849 | tree decl; | |
12850 | { | |
12851 | register tree fndecl = decl; | |
12852 | tree old_initial; | |
8d08fdba MS |
12853 | |
12854 | register tree link; | |
12855 | ||
12856 | if (TYPE_MAIN_VARIANT (decl) == void_type_node) | |
12857 | return decl; | |
12858 | ||
12859 | old_initial = DECL_INITIAL (fndecl); | |
12860 | ||
12861 | /* Undo the level for the parms (from start_method). | |
12862 | This is like poplevel, but it causes nothing to be | |
12863 | saved. Saving information here confuses symbol-table | |
12864 | output routines. Besides, this information will | |
12865 | be correctly output when this method is actually | |
12866 | compiled. */ | |
12867 | ||
12868 | /* Clear out the meanings of the local variables of this level; | |
12869 | also record in each decl which block it belongs to. */ | |
12870 | ||
12871 | for (link = current_binding_level->names; link; link = TREE_CHAIN (link)) | |
12872 | { | |
12873 | if (DECL_NAME (link) != NULL_TREE) | |
12874 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; | |
12875 | my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163); | |
12876 | DECL_CONTEXT (link) = NULL_TREE; | |
12877 | } | |
12878 | ||
12879 | /* Restore all name-meanings of the outer levels | |
12880 | that were shadowed by this level. */ | |
12881 | ||
12882 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
12883 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
12884 | for (link = current_binding_level->class_shadowed; | |
12885 | link; link = TREE_CHAIN (link)) | |
12886 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
12887 | for (link = current_binding_level->type_shadowed; | |
12888 | link; link = TREE_CHAIN (link)) | |
12889 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
12890 | ||
12891 | GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, | |
12892 | (HOST_WIDE_INT) current_binding_level->level_chain, | |
12893 | current_binding_level->parm_flag, | |
5566b478 | 12894 | current_binding_level->keep); |
8d08fdba MS |
12895 | |
12896 | poplevel (0, 0, 0); | |
12897 | ||
12898 | DECL_INITIAL (fndecl) = old_initial; | |
12899 | ||
12900 | /* We used to check if the context of FNDECL was different from | |
12901 | current_class_type as another way to get inside here. This didn't work | |
12902 | for String.cc in libg++. */ | |
12903 | if (DECL_FRIEND_P (fndecl)) | |
12904 | { | |
12905 | CLASSTYPE_INLINE_FRIENDS (current_class_type) | |
12906 | = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type)); | |
12907 | decl = void_type_node; | |
12908 | } | |
12909 | ||
12910 | return decl; | |
12911 | } | |
12912 | \f | |
12913 | /* Called when a new struct TYPE is defined. | |
12914 | If this structure or union completes the type of any previous | |
12915 | variable declaration, lay it out and output its rtl. */ | |
12916 | ||
12917 | void | |
12918 | hack_incomplete_structures (type) | |
12919 | tree type; | |
12920 | { | |
f30432d7 | 12921 | tree *list; |
8d08fdba | 12922 | |
f30432d7 | 12923 | if (current_binding_level->incomplete == NULL_TREE) |
8d08fdba MS |
12924 | return; |
12925 | ||
12926 | if (!type) /* Don't do this for class templates. */ | |
12927 | return; | |
12928 | ||
f30432d7 MS |
12929 | for (list = ¤t_binding_level->incomplete; *list; ) |
12930 | { | |
12931 | tree decl = TREE_VALUE (*list); | |
a703fb38 | 12932 | if ((decl && TREE_TYPE (decl) == type) |
f30432d7 MS |
12933 | || (TREE_TYPE (decl) |
12934 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
12935 | && TREE_TYPE (TREE_TYPE (decl)) == type)) | |
12936 | { | |
12937 | int toplevel = toplevel_bindings_p (); | |
12938 | if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
12939 | && TREE_TYPE (TREE_TYPE (decl)) == type) | |
12940 | layout_type (TREE_TYPE (decl)); | |
12941 | layout_decl (decl, 0); | |
12942 | rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); | |
12943 | if (! toplevel) | |
12944 | { | |
12945 | tree cleanup; | |
12946 | expand_decl (decl); | |
12947 | cleanup = maybe_build_cleanup (decl); | |
12948 | expand_decl_init (decl); | |
e349ee73 | 12949 | if (! expand_decl_cleanup (decl, cleanup)) |
f30432d7 MS |
12950 | cp_error ("parser lost in parsing declaration of `%D'", |
12951 | decl); | |
12952 | } | |
12953 | *list = TREE_CHAIN (*list); | |
12954 | } | |
12955 | else | |
12956 | list = &TREE_CHAIN (*list); | |
12957 | } | |
8d08fdba MS |
12958 | } |
12959 | ||
8d08fdba | 12960 | /* If DECL is of a type which needs a cleanup, build that cleanup here. |
c73964b2 | 12961 | See build_delete for information about AUTO_DELETE. |
8d08fdba MS |
12962 | |
12963 | Don't build these on the momentary obstack; they must live | |
12964 | the life of the binding contour. */ | |
e92cc029 | 12965 | |
c73964b2 MS |
12966 | static tree |
12967 | maybe_build_cleanup_1 (decl, auto_delete) | |
12968 | tree decl, auto_delete; | |
8d08fdba MS |
12969 | { |
12970 | tree type = TREE_TYPE (decl); | |
12971 | if (TYPE_NEEDS_DESTRUCTOR (type)) | |
12972 | { | |
12973 | int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; | |
12974 | tree rval; | |
8d08fdba MS |
12975 | |
12976 | if (TREE_CODE (decl) != PARM_DECL) | |
12977 | temp = suspend_momentary (); | |
12978 | ||
12979 | if (TREE_CODE (type) == ARRAY_TYPE) | |
12980 | rval = decl; | |
12981 | else | |
12982 | { | |
12983 | mark_addressable (decl); | |
12984 | rval = build_unary_op (ADDR_EXPR, decl, 0); | |
12985 | } | |
12986 | ||
12987 | /* Optimize for space over speed here. */ | |
12988 | if (! TYPE_USES_VIRTUAL_BASECLASSES (type) | |
12989 | || flag_expensive_optimizations) | |
12990 | flags |= LOOKUP_NONVIRTUAL; | |
12991 | ||
c73964b2 | 12992 | rval = build_delete (TREE_TYPE (rval), rval, auto_delete, flags, 0); |
8d08fdba MS |
12993 | |
12994 | if (TYPE_USES_VIRTUAL_BASECLASSES (type) | |
12995 | && ! TYPE_HAS_DESTRUCTOR (type)) | |
e66d884e JM |
12996 | rval = build_compound_expr (expr_tree_cons (NULL_TREE, rval, |
12997 | build_expr_list (NULL_TREE, build_vbase_delete (type, decl)))); | |
8d08fdba | 12998 | |
8d08fdba MS |
12999 | if (TREE_CODE (decl) != PARM_DECL) |
13000 | resume_momentary (temp); | |
13001 | ||
8d08fdba MS |
13002 | return rval; |
13003 | } | |
13004 | return 0; | |
13005 | } | |
c73964b2 MS |
13006 | |
13007 | /* If DECL is of a type which needs a cleanup, build that cleanup | |
13008 | here. The cleanup does free the storage with a call to delete. */ | |
13009 | ||
13010 | tree | |
13011 | maybe_build_cleanup_and_delete (decl) | |
13012 | tree decl; | |
13013 | { | |
13014 | return maybe_build_cleanup_1 (decl, integer_three_node); | |
13015 | } | |
13016 | ||
13017 | /* If DECL is of a type which needs a cleanup, build that cleanup | |
13018 | here. The cleanup does not free the storage with a call a delete. */ | |
13019 | ||
13020 | tree | |
13021 | maybe_build_cleanup (decl) | |
13022 | tree decl; | |
13023 | { | |
13024 | return maybe_build_cleanup_1 (decl, integer_two_node); | |
13025 | } | |
8d08fdba MS |
13026 | \f |
13027 | /* Expand a C++ expression at the statement level. | |
13028 | This is needed to ferret out nodes which have UNKNOWN_TYPE. | |
13029 | The C++ type checker should get all of these out when | |
13030 | expressions are combined with other, type-providing, expressions, | |
13031 | leaving only orphan expressions, such as: | |
13032 | ||
e92cc029 | 13033 | &class::bar; / / takes its address, but does nothing with it. */ |
8d08fdba | 13034 | |
8d08fdba MS |
13035 | void |
13036 | cplus_expand_expr_stmt (exp) | |
13037 | tree exp; | |
13038 | { | |
5156628f | 13039 | if (processing_template_decl) |
5566b478 MS |
13040 | { |
13041 | add_tree (build_min_nt (EXPR_STMT, exp)); | |
13042 | return; | |
13043 | } | |
13044 | ||
eb66be0e MS |
13045 | /* Arrange for all temps to disappear. */ |
13046 | expand_start_target_temps (); | |
13047 | ||
8d08fdba MS |
13048 | if (TREE_TYPE (exp) == unknown_type_node) |
13049 | { | |
13050 | if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST) | |
13051 | error ("address of overloaded function with no contextual type information"); | |
13052 | else if (TREE_CODE (exp) == COMPONENT_REF) | |
13053 | warning ("useless reference to a member function name, did you forget the ()?"); | |
13054 | } | |
13055 | else | |
13056 | { | |
8d08fdba MS |
13057 | if (TREE_CODE (exp) == FUNCTION_DECL) |
13058 | { | |
13059 | cp_warning ("reference, not call, to function `%D'", exp); | |
13060 | warning ("at this point in file"); | |
13061 | } | |
8d08fdba | 13062 | |
63c68bb7 MS |
13063 | #if 0 |
13064 | /* We should do this eventually, but right now this causes regex.o from | |
13065 | libg++ to miscompile, and tString to core dump. */ | |
5b605f68 | 13066 | exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp); |
63c68bb7 | 13067 | #endif |
d2e5ee5c MS |
13068 | /* If we don't do this, we end up down inside expand_expr |
13069 | trying to do TYPE_MODE on the ERROR_MARK, and really | |
13070 | go outside the bounds of the type. */ | |
13071 | if (exp != error_mark_node) | |
13072 | expand_expr_stmt (break_out_cleanups (exp)); | |
8d08fdba MS |
13073 | } |
13074 | ||
13075 | /* Clean up any pending cleanups. This happens when a function call | |
13076 | returns a cleanup-needing value that nobody uses. */ | |
eb66be0e | 13077 | expand_end_target_temps (); |
8d08fdba MS |
13078 | } |
13079 | ||
13080 | /* When a stmt has been parsed, this function is called. | |
13081 | ||
13082 | Currently, this function only does something within a | |
13083 | constructor's scope: if a stmt has just assigned to this, | |
13084 | and we are in a derived class, we call `emit_base_init'. */ | |
13085 | ||
13086 | void | |
13087 | finish_stmt () | |
13088 | { | |
13089 | extern struct nesting *cond_stack, *loop_stack, *case_stack; | |
13090 | ||
13091 | ||
13092 | if (current_function_assigns_this | |
13093 | || ! current_function_just_assigned_this) | |
13094 | return; | |
13095 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
13096 | { | |
13097 | /* Constructors must wait until we are out of control | |
13098 | zones before calling base constructors. */ | |
13099 | if (cond_stack || loop_stack || case_stack) | |
13100 | return; | |
a9aedbc2 | 13101 | expand_expr_stmt (base_init_expr); |
8d08fdba MS |
13102 | check_base_init (current_class_type); |
13103 | } | |
13104 | current_function_assigns_this = 1; | |
8d08fdba MS |
13105 | } |
13106 | ||
8d08fdba | 13107 | /* Change a static member function definition into a FUNCTION_TYPE, instead |
700f8a87 MS |
13108 | of the METHOD_TYPE that we create when it's originally parsed. |
13109 | ||
13110 | WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES | |
13111 | (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of | |
13112 | other decls. Either pass the addresses of local variables or NULL. */ | |
13113 | ||
8857f91e | 13114 | void |
700f8a87 MS |
13115 | revert_static_member_fn (decl, fn, argtypes) |
13116 | tree *decl, *fn, *argtypes; | |
8d08fdba | 13117 | { |
700f8a87 MS |
13118 | tree tmp; |
13119 | tree function = fn ? *fn : TREE_TYPE (*decl); | |
13120 | tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function); | |
8d08fdba | 13121 | |
f30432d7 MS |
13122 | if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args)))) |
13123 | cp_error ("static member function `%#D' declared const", *decl); | |
13124 | if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args)))) | |
13125 | cp_error ("static member function `%#D' declared volatile", *decl); | |
13126 | ||
700f8a87 MS |
13127 | args = TREE_CHAIN (args); |
13128 | tmp = build_function_type (TREE_TYPE (function), args); | |
8d08fdba MS |
13129 | tmp = build_type_variant (tmp, TYPE_READONLY (function), |
13130 | TYPE_VOLATILE (function)); | |
f30432d7 | 13131 | tmp = build_exception_variant (tmp, |
8d08fdba MS |
13132 | TYPE_RAISES_EXCEPTIONS (function)); |
13133 | TREE_TYPE (*decl) = tmp; | |
f30432d7 MS |
13134 | if (DECL_ARGUMENTS (*decl)) |
13135 | DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl)); | |
8d08fdba | 13136 | DECL_STATIC_FUNCTION_P (*decl) = 1; |
700f8a87 MS |
13137 | if (fn) |
13138 | *fn = tmp; | |
13139 | if (argtypes) | |
13140 | *argtypes = args; | |
8d08fdba | 13141 | } |
a4443a08 MS |
13142 | |
13143 | int | |
13144 | id_in_current_class (id) | |
13145 | tree id; | |
13146 | { | |
13147 | return !!purpose_member (id, class_binding_level->class_shadowed); | |
13148 | } | |
db5ae43f MS |
13149 | |
13150 | struct cp_function | |
13151 | { | |
13152 | int returns_value; | |
13153 | int returns_null; | |
13154 | int warn_about_return_type; | |
db5ae43f MS |
13155 | int assigns_this; |
13156 | int just_assigned_this; | |
13157 | int parms_stored; | |
7215f9a0 | 13158 | int temp_name_counter; |
db5ae43f MS |
13159 | tree named_labels; |
13160 | tree shadowed_labels; | |
13161 | tree ctor_label; | |
13162 | tree dtor_label; | |
72b7eeff | 13163 | rtx last_dtor_insn; |
b87692e5 | 13164 | rtx last_parm_cleanup_insn; |
79ff2c6c MS |
13165 | tree base_init_list; |
13166 | tree member_init_list; | |
a9aedbc2 | 13167 | tree base_init_expr; |
4ac14744 MS |
13168 | tree current_class_ptr; |
13169 | tree current_class_ref; | |
db5ae43f MS |
13170 | rtx result_rtx; |
13171 | struct cp_function *next; | |
13172 | struct binding_level *binding_level; | |
42976354 | 13173 | int static_labelno; |
db5ae43f MS |
13174 | }; |
13175 | ||
bd6dd845 | 13176 | static struct cp_function *cp_function_chain; |
db5ae43f | 13177 | |
7215f9a0 MS |
13178 | extern int temp_name_counter; |
13179 | ||
db5ae43f MS |
13180 | /* Save and reinitialize the variables |
13181 | used during compilation of a C++ function. */ | |
13182 | ||
13183 | void | |
28cbf42c MS |
13184 | push_cp_function_context (context) |
13185 | tree context; | |
db5ae43f MS |
13186 | { |
13187 | struct cp_function *p | |
13188 | = (struct cp_function *) xmalloc (sizeof (struct cp_function)); | |
13189 | ||
28cbf42c | 13190 | push_function_context_to (context); |
db5ae43f MS |
13191 | |
13192 | p->next = cp_function_chain; | |
13193 | cp_function_chain = p; | |
13194 | ||
13195 | p->named_labels = named_labels; | |
13196 | p->shadowed_labels = shadowed_labels; | |
13197 | p->returns_value = current_function_returns_value; | |
13198 | p->returns_null = current_function_returns_null; | |
13199 | p->warn_about_return_type = warn_about_return_type; | |
db5ae43f MS |
13200 | p->binding_level = current_binding_level; |
13201 | p->ctor_label = ctor_label; | |
13202 | p->dtor_label = dtor_label; | |
72b7eeff | 13203 | p->last_dtor_insn = last_dtor_insn; |
b87692e5 | 13204 | p->last_parm_cleanup_insn = last_parm_cleanup_insn; |
db5ae43f MS |
13205 | p->assigns_this = current_function_assigns_this; |
13206 | p->just_assigned_this = current_function_just_assigned_this; | |
13207 | p->parms_stored = current_function_parms_stored; | |
13208 | p->result_rtx = original_result_rtx; | |
a9aedbc2 | 13209 | p->base_init_expr = base_init_expr; |
7215f9a0 | 13210 | p->temp_name_counter = temp_name_counter; |
79ff2c6c MS |
13211 | p->base_init_list = current_base_init_list; |
13212 | p->member_init_list = current_member_init_list; | |
4ac14744 MS |
13213 | p->current_class_ptr = current_class_ptr; |
13214 | p->current_class_ref = current_class_ref; | |
42976354 | 13215 | p->static_labelno = static_labelno; |
db5ae43f MS |
13216 | } |
13217 | ||
13218 | /* Restore the variables used during compilation of a C++ function. */ | |
13219 | ||
13220 | void | |
28cbf42c MS |
13221 | pop_cp_function_context (context) |
13222 | tree context; | |
db5ae43f MS |
13223 | { |
13224 | struct cp_function *p = cp_function_chain; | |
13225 | tree link; | |
13226 | ||
13227 | /* Bring back all the labels that were shadowed. */ | |
13228 | for (link = shadowed_labels; link; link = TREE_CHAIN (link)) | |
13229 | if (DECL_NAME (TREE_VALUE (link)) != 0) | |
13230 | SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), | |
13231 | TREE_VALUE (link)); | |
13232 | ||
28cbf42c | 13233 | pop_function_context_from (context); |
db5ae43f MS |
13234 | |
13235 | cp_function_chain = p->next; | |
13236 | ||
13237 | named_labels = p->named_labels; | |
13238 | shadowed_labels = p->shadowed_labels; | |
13239 | current_function_returns_value = p->returns_value; | |
13240 | current_function_returns_null = p->returns_null; | |
13241 | warn_about_return_type = p->warn_about_return_type; | |
db5ae43f MS |
13242 | current_binding_level = p->binding_level; |
13243 | ctor_label = p->ctor_label; | |
13244 | dtor_label = p->dtor_label; | |
72b7eeff | 13245 | last_dtor_insn = p->last_dtor_insn; |
b87692e5 | 13246 | last_parm_cleanup_insn = p->last_parm_cleanup_insn; |
db5ae43f MS |
13247 | current_function_assigns_this = p->assigns_this; |
13248 | current_function_just_assigned_this = p->just_assigned_this; | |
13249 | current_function_parms_stored = p->parms_stored; | |
13250 | original_result_rtx = p->result_rtx; | |
a9aedbc2 | 13251 | base_init_expr = p->base_init_expr; |
7215f9a0 | 13252 | temp_name_counter = p->temp_name_counter; |
79ff2c6c MS |
13253 | current_base_init_list = p->base_init_list; |
13254 | current_member_init_list = p->member_init_list; | |
4ac14744 MS |
13255 | current_class_ptr = p->current_class_ptr; |
13256 | current_class_ref = p->current_class_ref; | |
42976354 | 13257 | static_labelno = p->static_labelno; |
db5ae43f MS |
13258 | |
13259 | free (p); | |
13260 | } | |
ebfc180f | 13261 | |
5566b478 MS |
13262 | int |
13263 | in_function_p () | |
13264 | { | |
13265 | return function_depth != 0; | |
13266 | } |