]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* Process declarations and variables for C compiler. |
357a4089 | 2 | Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc. |
8d08fdba MS |
3 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
e9fa0c7c RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
21 | |
22 | ||
23 | /* 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 | ||
8d08fdba MS |
66 | /* Stack of places to restore the search obstack back to. */ |
67 | ||
68 | /* Obstack used for remembering local class declarations (like | |
69 | enums and static (const) members. */ | |
70 | #include "stack.h" | |
5566b478 | 71 | struct obstack decl_obstack; |
8d08fdba MS |
72 | static struct stack_level *decl_stack; |
73 | ||
74 | #ifndef CHAR_TYPE_SIZE | |
75 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
76 | #endif | |
77 | ||
78 | #ifndef SHORT_TYPE_SIZE | |
79 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) | |
80 | #endif | |
81 | ||
82 | #ifndef INT_TYPE_SIZE | |
83 | #define INT_TYPE_SIZE BITS_PER_WORD | |
84 | #endif | |
85 | ||
86 | #ifndef LONG_TYPE_SIZE | |
87 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
88 | #endif | |
89 | ||
90 | #ifndef LONG_LONG_TYPE_SIZE | |
91 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
92 | #endif | |
93 | ||
94 | #ifndef WCHAR_UNSIGNED | |
95 | #define WCHAR_UNSIGNED 0 | |
96 | #endif | |
97 | ||
98 | #ifndef FLOAT_TYPE_SIZE | |
99 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
100 | #endif | |
101 | ||
102 | #ifndef DOUBLE_TYPE_SIZE | |
103 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
104 | #endif | |
105 | ||
106 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
107 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
108 | #endif | |
109 | ||
255512c1 | 110 | #ifndef BOOL_TYPE_SIZE |
e1cd6e56 | 111 | #ifdef SLOW_BYTE_ACCESS |
d2e5ee5c | 112 | #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (POINTER_SIZE) : (CHAR_TYPE_SIZE)) |
e1cd6e56 | 113 | #else |
d2e5ee5c | 114 | #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE |
e1cd6e56 | 115 | #endif |
255512c1 JM |
116 | #endif |
117 | ||
8d08fdba MS |
118 | /* We let tm.h override the types used here, to handle trivial differences |
119 | such as the choice of unsigned int or long unsigned int for size_t. | |
120 | When machines start needing nontrivial differences in the size type, | |
121 | it would be best to do something here to figure out automatically | |
122 | from other information what type to use. */ | |
123 | ||
124 | #ifndef SIZE_TYPE | |
125 | #define SIZE_TYPE "long unsigned int" | |
126 | #endif | |
127 | ||
128 | #ifndef PTRDIFF_TYPE | |
129 | #define PTRDIFF_TYPE "long int" | |
130 | #endif | |
131 | ||
132 | #ifndef WCHAR_TYPE | |
133 | #define WCHAR_TYPE "int" | |
134 | #endif | |
135 | ||
8d08fdba MS |
136 | static tree grokparms PROTO((tree, int)); |
137 | static tree lookup_nested_type PROTO((tree, tree)); | |
138 | static char *redeclaration_error_message PROTO((tree, tree)); | |
bd6dd845 MS |
139 | static void revert_static_member_fn PROTO((tree *, tree *, tree *)); |
140 | static tree push_overloaded_decl PROTO((tree, int)); | |
141 | static void push_overloaded_decl_top_level PROTO((tree, int)); | |
8d08fdba | 142 | |
49c249e1 JM |
143 | static struct stack_level *push_decl_level PROTO((struct stack_level *, |
144 | struct obstack *)); | |
145 | static void push_binding_level PROTO((struct binding_level *, int, | |
146 | int)); | |
147 | static void pop_binding_level PROTO((void)); | |
148 | static void suspend_binding_level PROTO((void)); | |
149 | static void resume_binding_level PROTO((struct binding_level *)); | |
150 | static struct binding_level *make_binding_level PROTO((void)); | |
151 | static int namespace_bindings_p PROTO((void)); | |
152 | static void declare_namespace_level PROTO((void)); | |
153 | static tree get_unique_name PROTO((void)); | |
154 | static void signal_catch PROTO((int)); | |
155 | static void storedecls PROTO((tree)); | |
156 | static void storetags PROTO((tree)); | |
157 | static void require_complete_types_for_parms PROTO((tree)); | |
158 | static void push_overloaded_decl_1 PROTO((tree)); | |
159 | static int ambi_op_p PROTO((tree)); | |
160 | static int unary_op_p PROTO((tree)); | |
161 | static tree store_bindings PROTO((tree, tree)); | |
162 | static tree lookup_tag_reverse PROTO((tree, tree)); | |
163 | static tree obscure_complex_init PROTO((tree, tree)); | |
164 | static tree maybe_build_cleanup_1 PROTO((tree, tree)); | |
165 | static tree lookup_name_real PROTO((tree, int, int)); | |
166 | static void warn_extern_redeclared_static PROTO((tree, tree)); | |
167 | static void grok_reference_init PROTO((tree, tree, tree, tree *)); | |
386b8a85 | 168 | static tree grokfndecl PROTO((tree, tree, tree, tree, int, |
49c249e1 | 169 | enum overload_flags, |
386b8a85 | 170 | tree, tree, tree, int, int, int, int, int, int)); |
49c249e1 JM |
171 | static tree grokvardecl PROTO((tree, tree, RID_BIT_TYPE *, int, int)); |
172 | static tree lookup_tag PROTO((enum tree_code, tree, | |
173 | struct binding_level *, int)); | |
174 | static void set_identifier_type_value_with_scope | |
175 | PROTO((tree, tree, struct binding_level *)); | |
176 | static void record_builtin_type PROTO((enum rid, char *, tree)); | |
177 | static int member_function_or_else PROTO((tree, tree, char *)); | |
178 | static void bad_specifiers PROTO((tree, char *, int, int, int, int, | |
179 | int)); | |
8d08fdba MS |
180 | |
181 | /* a node which has tree code ERROR_MARK, and whose type is itself. | |
182 | All erroneous expressions are replaced with this node. All functions | |
183 | that accept nodes as arguments should avoid generating error messages | |
184 | if this node is one of the arguments, since it is undesirable to get | |
185 | multiple error messages from one error in the input. */ | |
186 | ||
187 | tree error_mark_node; | |
188 | ||
189 | /* Erroneous argument lists can use this *IFF* they do not modify it. */ | |
190 | tree error_mark_list; | |
191 | ||
192 | /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ | |
193 | ||
194 | tree short_integer_type_node; | |
195 | tree integer_type_node; | |
196 | tree long_integer_type_node; | |
197 | tree long_long_integer_type_node; | |
198 | ||
199 | tree short_unsigned_type_node; | |
200 | tree unsigned_type_node; | |
201 | tree long_unsigned_type_node; | |
202 | tree long_long_unsigned_type_node; | |
203 | ||
204 | tree ptrdiff_type_node; | |
205 | ||
206 | tree unsigned_char_type_node; | |
207 | tree signed_char_type_node; | |
208 | tree char_type_node; | |
209 | tree wchar_type_node; | |
210 | tree signed_wchar_type_node; | |
211 | tree unsigned_wchar_type_node; | |
212 | ||
f376e137 MS |
213 | tree wchar_decl_node; |
214 | ||
8d08fdba MS |
215 | tree float_type_node; |
216 | tree double_type_node; | |
217 | tree long_double_type_node; | |
218 | ||
37c46b43 MS |
219 | tree complex_integer_type_node; |
220 | tree complex_float_type_node; | |
221 | tree complex_double_type_node; | |
222 | tree complex_long_double_type_node; | |
223 | ||
8d08fdba MS |
224 | tree intQI_type_node; |
225 | tree intHI_type_node; | |
226 | tree intSI_type_node; | |
227 | tree intDI_type_node; | |
228 | ||
229 | tree unsigned_intQI_type_node; | |
230 | tree unsigned_intHI_type_node; | |
231 | tree unsigned_intSI_type_node; | |
232 | tree unsigned_intDI_type_node; | |
233 | ||
234 | /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */ | |
235 | ||
236 | tree void_type_node, void_list_node; | |
237 | tree void_zero_node; | |
238 | ||
239 | /* Nodes for types `void *' and `const void *'. */ | |
240 | ||
bd6dd845 MS |
241 | tree ptr_type_node; |
242 | static tree const_ptr_type_node; | |
8d08fdba MS |
243 | |
244 | /* Nodes for types `char *' and `const char *'. */ | |
245 | ||
246 | tree string_type_node, const_string_type_node; | |
247 | ||
248 | /* Type `char[256]' or something like it. | |
249 | Used when an array of char is needed and the size is irrelevant. */ | |
250 | ||
251 | tree char_array_type_node; | |
252 | ||
253 | /* Type `int[256]' or something like it. | |
254 | Used when an array of int needed and the size is irrelevant. */ | |
255 | ||
256 | tree int_array_type_node; | |
257 | ||
258 | /* Type `wchar_t[256]' or something like it. | |
259 | Used when a wide string literal is created. */ | |
260 | ||
261 | tree wchar_array_type_node; | |
262 | ||
2986ae00 | 263 | /* The bool data type, and constants */ |
255512c1 | 264 | tree boolean_type_node, boolean_true_node, boolean_false_node; |
2986ae00 | 265 | |
8d08fdba MS |
266 | /* type `int ()' -- used for implicit declaration of functions. */ |
267 | ||
268 | tree default_function_type; | |
269 | ||
270 | /* function types `double (double)' and `double (double, double)', etc. */ | |
271 | ||
bd6dd845 MS |
272 | static tree double_ftype_double, double_ftype_double_double; |
273 | static tree int_ftype_int, long_ftype_long; | |
274 | static tree float_ftype_float; | |
275 | static tree ldouble_ftype_ldouble; | |
8d08fdba | 276 | |
8d08fdba | 277 | /* Function type `int (const void *, const void *, size_t)' */ |
5566b478 | 278 | static tree int_ftype_cptr_cptr_sizet; |
8d08fdba MS |
279 | |
280 | /* C++ extensions */ | |
700f8a87 | 281 | tree vtable_entry_type; |
8d08fdba | 282 | tree delta_type_node; |
db5ae43f | 283 | #if 0 |
e92cc029 | 284 | /* Old rtti stuff. */ |
db5ae43f MS |
285 | tree __baselist_desc_type_node; |
286 | tree __i_desc_type_node, __m_desc_type_node; | |
8d08fdba | 287 | tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; |
db5ae43f | 288 | #endif |
5566b478 MS |
289 | tree __t_desc_type_node; |
290 | #if 0 | |
291 | tree __tp_desc_type_node; | |
292 | #endif | |
db5ae43f MS |
293 | tree __access_mode_type_node; |
294 | tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node; | |
295 | tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node; | |
296 | tree __ptmf_desc_type_node, __ptmd_desc_type_node; | |
297 | #if 0 | |
298 | /* Not needed yet? May be needed one day? */ | |
299 | tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type; | |
300 | tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type; | |
301 | tree __ptmf_desc_array_type, __ptmd_desc_array_type; | |
302 | #endif | |
303 | ||
8d08fdba MS |
304 | tree class_star_type_node; |
305 | tree class_type_node, record_type_node, union_type_node, enum_type_node; | |
db5ae43f | 306 | tree unknown_type_node; |
8d08fdba MS |
307 | tree opaque_type_node, signature_type_node; |
308 | tree sigtable_entry_type; | |
8d08fdba | 309 | |
8d08fdba MS |
310 | /* Array type `vtable_entry_type[]' */ |
311 | tree vtbl_type_node; | |
312 | ||
6633d636 MS |
313 | /* namespace std */ |
314 | tree std_node; | |
315 | ||
8d08fdba MS |
316 | /* In a destructor, the point at which all derived class destroying |
317 | has been done, just before any base class destroying will be done. */ | |
318 | ||
319 | tree dtor_label; | |
320 | ||
72b7eeff MS |
321 | /* In a destructor, the last insn emitted after the start of the |
322 | function and the parms. */ | |
323 | ||
bd6dd845 | 324 | static rtx last_dtor_insn; |
72b7eeff | 325 | |
b87692e5 MS |
326 | /* In a constructor, the last insn emitted after the start of the |
327 | function and the parms, but before the start of the exception | |
328 | specification. */ | |
329 | ||
330 | static rtx last_parm_cleanup_insn; | |
331 | ||
8d08fdba MS |
332 | /* In a constructor, the point at which we are ready to return |
333 | the pointer to the initialized object. */ | |
334 | ||
335 | tree ctor_label; | |
336 | ||
8d08fdba MS |
337 | /* A FUNCTION_DECL which can call `abort'. Not necessarily the |
338 | one that the user will declare, but sufficient to be called | |
339 | by routines that want to abort the program. */ | |
340 | ||
341 | tree abort_fndecl; | |
342 | ||
343 | extern rtx cleanup_label, return_label; | |
344 | ||
345 | /* If original DECL_RESULT of current function was a register, | |
346 | but due to being an addressable named return value, would up | |
347 | on the stack, this variable holds the named return value's | |
348 | original location. */ | |
bd6dd845 | 349 | static rtx original_result_rtx; |
8d08fdba MS |
350 | |
351 | /* Sequence of insns which represents base initialization. */ | |
a9aedbc2 | 352 | tree base_init_expr; |
8d08fdba MS |
353 | |
354 | /* C++: Keep these around to reduce calls to `get_identifier'. | |
355 | Identifiers for `this' in member functions and the auto-delete | |
356 | parameter for destructors. */ | |
357 | tree this_identifier, in_charge_identifier; | |
fc378698 | 358 | tree ctor_identifier, dtor_identifier; |
e92cc029 | 359 | /* Used in pointer to member functions, in vtables, and in sigtables. */ |
8d08fdba | 360 | tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; |
9dd70aa4 | 361 | tree pfn_or_delta2_identifier, tag_identifier; |
5566b478 | 362 | tree vt_off_identifier; |
8d08fdba | 363 | |
e349ee73 MS |
364 | struct named_label_list |
365 | { | |
366 | struct binding_level *binding_level; | |
367 | tree names_in_scope; | |
368 | tree label_decl; | |
369 | char *filename_o_goto; | |
370 | int lineno_o_goto; | |
371 | struct named_label_list *next; | |
372 | }; | |
373 | ||
8d08fdba MS |
374 | /* A list (chain of TREE_LIST nodes) of named label uses. |
375 | The TREE_PURPOSE field is the list of variables defined | |
376 | the the label's scope defined at the point of use. | |
377 | The TREE_VALUE field is the LABEL_DECL used. | |
378 | The TREE_TYPE field holds `current_binding_level' at the | |
379 | point of the label's use. | |
380 | ||
e349ee73 MS |
381 | BWAHAHAAHAHahhahahahaah. No, no, no, said the little chicken. |
382 | ||
383 | Look at the pretty struct named_label_list. See the pretty struct | |
384 | with the pretty named fields that describe what they do. See the | |
385 | pretty lack of gratuitous casts. Notice the code got a lot cleaner. | |
386 | ||
8d08fdba MS |
387 | Used only for jumps to as-yet undefined labels, since |
388 | jumps to defined labels can have their validity checked | |
389 | by stmt.c. */ | |
390 | ||
e349ee73 | 391 | static struct named_label_list *named_label_uses = NULL; |
8d08fdba MS |
392 | |
393 | /* A list of objects which have constructors or destructors | |
394 | which reside in the global scope. The decl is stored in | |
395 | the TREE_VALUE slot and the initializer is stored | |
396 | in the TREE_PURPOSE slot. */ | |
397 | tree static_aggregates; | |
398 | ||
8d08fdba MS |
399 | /* -- end of C++ */ |
400 | ||
401 | /* Two expressions that are constants with value zero. | |
402 | The first is of type `int', the second of type `void *'. */ | |
403 | ||
404 | tree integer_zero_node; | |
405 | tree null_pointer_node; | |
406 | ||
d11ad92e MS |
407 | /* The value for __null (NULL), either of type `void *' or, with -ansi, |
408 | an integer type of the same size. */ | |
409 | ||
410 | tree null_node; | |
411 | ||
8d08fdba MS |
412 | /* A node for the integer constants 1, 2, and 3. */ |
413 | ||
414 | tree integer_one_node, integer_two_node, integer_three_node; | |
415 | ||
8d08fdba MS |
416 | /* While defining an enum type, this is 1 plus the last enumerator |
417 | constant value. */ | |
418 | ||
419 | static tree enum_next_value; | |
420 | ||
7177d104 MS |
421 | /* Nonzero means that there was overflow computing enum_next_value. */ |
422 | ||
423 | static int enum_overflow; | |
424 | ||
8d08fdba MS |
425 | /* Parsing a function declarator leaves a list of parameter names |
426 | or a chain or parameter decls here. */ | |
427 | ||
428 | tree last_function_parms; | |
429 | ||
430 | /* Parsing a function declarator leaves here a chain of structure | |
431 | and enum types declared in the parmlist. */ | |
432 | ||
433 | static tree last_function_parm_tags; | |
434 | ||
435 | /* After parsing the declarator that starts a function definition, | |
436 | `start_function' puts here the list of parameter names or chain of decls. | |
437 | `store_parm_decls' finds it here. */ | |
438 | ||
439 | static tree current_function_parms; | |
440 | ||
441 | /* Similar, for last_function_parm_tags. */ | |
442 | static tree current_function_parm_tags; | |
443 | ||
444 | /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function | |
445 | that have names. Here so we can clear out their names' definitions | |
446 | at the end of the function. */ | |
447 | ||
448 | static tree named_labels; | |
449 | ||
450 | /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ | |
451 | ||
452 | static tree shadowed_labels; | |
453 | ||
8d08fdba MS |
454 | /* The FUNCTION_DECL for the function currently being compiled, |
455 | or 0 if between functions. */ | |
456 | tree current_function_decl; | |
457 | ||
458 | /* Set to 0 at beginning of a function definition, set to 1 if | |
459 | a return statement that specifies a return value is seen. */ | |
460 | ||
461 | int current_function_returns_value; | |
462 | ||
463 | /* Set to 0 at beginning of a function definition, set to 1 if | |
464 | a return statement with no argument is seen. */ | |
465 | ||
466 | int current_function_returns_null; | |
467 | ||
468 | /* Set to 0 at beginning of a function definition, and whenever | |
469 | a label (case or named) is defined. Set to value of expression | |
470 | returned from function when that value can be transformed into | |
471 | a named return value. */ | |
472 | ||
473 | tree current_function_return_value; | |
474 | ||
475 | /* Set to nonzero by `grokdeclarator' for a function | |
476 | whose return type is defaulted, if warnings for this are desired. */ | |
477 | ||
478 | static int warn_about_return_type; | |
479 | ||
8d08fdba MS |
480 | /* Nonzero means give `double' the same size as `float'. */ |
481 | ||
482 | extern int flag_short_double; | |
483 | ||
484 | /* Nonzero means don't recognize any builtin functions. */ | |
485 | ||
486 | extern int flag_no_builtin; | |
487 | ||
00595019 MS |
488 | /* Nonzero means don't recognize the non-ANSI builtin functions. |
489 | -ansi sets this. */ | |
490 | ||
491 | extern int flag_no_nonansi_builtin; | |
492 | ||
e1cd6e56 MS |
493 | /* Nonzero means enable obscure ANSI features and disable GNU extensions |
494 | that might cause ANSI-compliant code to be miscompiled. */ | |
8d08fdba MS |
495 | |
496 | extern int flag_ansi; | |
497 | ||
498 | /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) | |
e92cc029 | 499 | objects. */ |
8d08fdba MS |
500 | extern int flag_huge_objects; |
501 | ||
502 | /* Nonzero if we want to conserve space in the .o files. We do this | |
503 | by putting uninitialized data and runtime initialized data into | |
ddd5a7c1 | 504 | .common instead of .data at the expense of not flagging multiple |
8d08fdba MS |
505 | definitions. */ |
506 | extern int flag_conserve_space; | |
507 | ||
508 | /* Pointers to the base and current top of the language name stack. */ | |
509 | ||
510 | extern tree *current_lang_base, *current_lang_stack; | |
511 | \f | |
51c184be | 512 | /* C and C++ flags are in decl2.c. */ |
8d08fdba MS |
513 | |
514 | /* Set to 0 at beginning of a constructor, set to 1 | |
515 | if that function does an allocation before referencing its | |
516 | instance variable. */ | |
5566b478 | 517 | static int current_function_assigns_this; |
8d08fdba MS |
518 | int current_function_just_assigned_this; |
519 | ||
520 | /* Set to 0 at beginning of a function. Set non-zero when | |
521 | store_parm_decls is called. Don't call store_parm_decls | |
522 | if this flag is non-zero! */ | |
523 | int current_function_parms_stored; | |
524 | ||
51c184be | 525 | /* Flag used when debugging spew.c */ |
8d08fdba MS |
526 | |
527 | extern int spew_debug; | |
528 | ||
529 | /* This is a copy of the class_shadowed list of the previous class binding | |
530 | contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs | |
531 | when entering another class scope (i.e. a cache miss). */ | |
532 | extern tree previous_class_values; | |
533 | ||
e92cc029 MS |
534 | /* A expression of value 0 with the same precision as a sizetype |
535 | node, but signed. */ | |
536 | tree signed_size_zero_node; | |
537 | ||
8d08fdba MS |
538 | \f |
539 | /* Allocate a level of searching. */ | |
e92cc029 | 540 | |
824b9a4c | 541 | static |
8d08fdba MS |
542 | struct stack_level * |
543 | push_decl_level (stack, obstack) | |
544 | struct stack_level *stack; | |
545 | struct obstack *obstack; | |
546 | { | |
547 | struct stack_level tem; | |
548 | tem.prev = stack; | |
549 | ||
550 | return push_stack_level (obstack, (char *)&tem, sizeof (tem)); | |
551 | } | |
552 | \f | |
553 | /* For each binding contour we allocate a binding_level structure | |
e92cc029 MS |
554 | which records the names defined in that contour. |
555 | Contours include: | |
556 | 0) the global one | |
557 | 1) one for each function definition, | |
558 | where internal declarations of the parameters appear. | |
559 | 2) one for each compound statement, | |
560 | to record its declarations. | |
561 | ||
562 | The current meaning of a name can be found by searching the levels | |
563 | from the current one out to the global one. | |
564 | ||
565 | Off to the side, may be the class_binding_level. This exists only | |
566 | to catch class-local declarations. It is otherwise nonexistent. | |
567 | ||
568 | Also there may be binding levels that catch cleanups that must be | |
569 | run when exceptions occur. */ | |
8d08fdba MS |
570 | |
571 | /* Note that the information in the `names' component of the global contour | |
572 | is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ | |
573 | ||
574 | struct binding_level | |
575 | { | |
576 | /* A chain of _DECL nodes for all variables, constants, functions, | |
e92cc029 MS |
577 | and typedef types. These are in the reverse of the order |
578 | supplied. */ | |
8d08fdba MS |
579 | tree names; |
580 | ||
e92cc029 MS |
581 | /* A list of structure, union and enum definitions, for looking up |
582 | tag names. | |
583 | It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, | |
584 | or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, | |
585 | or ENUMERAL_TYPE node. | |
586 | ||
587 | C++: the TREE_VALUE nodes can be simple types for | |
588 | component_bindings. */ | |
8d08fdba MS |
589 | tree tags; |
590 | ||
591 | /* For each level, a list of shadowed outer-level local definitions | |
592 | to be restored when this level is popped. | |
593 | Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and | |
594 | whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ | |
595 | tree shadowed; | |
596 | ||
597 | /* Same, for IDENTIFIER_CLASS_VALUE. */ | |
598 | tree class_shadowed; | |
599 | ||
600 | /* Same, for IDENTIFIER_TYPE_VALUE. */ | |
601 | tree type_shadowed; | |
602 | ||
603 | /* For each level (except not the global one), | |
604 | a chain of BLOCK nodes for all the levels | |
605 | that were entered and exited one level down. */ | |
606 | tree blocks; | |
607 | ||
608 | /* The BLOCK node for this level, if one has been preallocated. | |
609 | If 0, the BLOCK is allocated (if needed) when the level is popped. */ | |
610 | tree this_block; | |
611 | ||
612 | /* The binding level which this one is contained in (inherits from). */ | |
613 | struct binding_level *level_chain; | |
614 | ||
f30432d7 | 615 | /* List of decls in `names' that have incomplete |
8d08fdba | 616 | structure or union types. */ |
f30432d7 | 617 | tree incomplete; |
8d08fdba | 618 | |
8d6e462b | 619 | /* List of VAR_DECLS saved from a previous for statement. |
abc95ed3 | 620 | These would be dead in ANSI-conforming code, but might |
d22c8596 | 621 | be referenced in ARM-era code. */ |
8d6e462b PB |
622 | tree dead_vars_from_for; |
623 | ||
8d08fdba MS |
624 | /* 1 for the level that holds the parameters of a function. |
625 | 2 for the level that holds a class declaration. | |
626 | 3 for levels that hold parameter declarations. */ | |
627 | unsigned parm_flag : 4; | |
628 | ||
629 | /* 1 means make a BLOCK for this level regardless of all else. | |
630 | 2 for temporary binding contours created by the compiler. */ | |
631 | unsigned keep : 3; | |
632 | ||
633 | /* Nonzero if this level "doesn't exist" for tags. */ | |
634 | unsigned tag_transparent : 1; | |
635 | ||
636 | /* Nonzero if this level can safely have additional | |
637 | cleanup-needing variables added to it. */ | |
638 | unsigned more_cleanups_ok : 1; | |
639 | unsigned have_cleanups : 1; | |
640 | ||
5566b478 MS |
641 | /* Nonzero if this level is for storing the decls for template |
642 | parameters and generic decls; these decls will be discarded and | |
643 | replaced with a TEMPLATE_DECL. */ | |
8d08fdba MS |
644 | unsigned pseudo_global : 1; |
645 | ||
a9aedbc2 MS |
646 | /* This is set for a namespace binding level. */ |
647 | unsigned namespace_p : 1; | |
648 | ||
2ee887f2 | 649 | /* True if this level is that of a for-statement where we need to |
d22c8596 | 650 | worry about ambiguous (ARM or ANSI) scope rules. */ |
8d6e462b PB |
651 | unsigned is_for_scope : 1; |
652 | ||
5566b478 | 653 | /* Two bits left for this word. */ |
8d08fdba MS |
654 | |
655 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
656 | /* Binding depth at which this level began. */ | |
657 | unsigned binding_depth; | |
658 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
659 | }; | |
660 | ||
661 | #define NULL_BINDING_LEVEL ((struct binding_level *) NULL) | |
662 | ||
663 | /* The (non-class) binding level currently in effect. */ | |
664 | ||
665 | static struct binding_level *current_binding_level; | |
666 | ||
667 | /* The binding level of the current class, if any. */ | |
668 | ||
669 | static struct binding_level *class_binding_level; | |
670 | ||
671 | /* The current (class or non-class) binding level currently in effect. */ | |
672 | ||
673 | #define inner_binding_level \ | |
674 | (class_binding_level ? class_binding_level : current_binding_level) | |
675 | ||
676 | /* A chain of binding_level structures awaiting reuse. */ | |
677 | ||
678 | static struct binding_level *free_binding_level; | |
679 | ||
680 | /* The outermost binding level, for names of file scope. | |
681 | This is created when the compiler is started and exists | |
682 | through the entire run. */ | |
683 | ||
684 | static struct binding_level *global_binding_level; | |
685 | ||
686 | /* Binding level structures are initialized by copying this one. */ | |
687 | ||
688 | static struct binding_level clear_binding_level; | |
689 | ||
690 | /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ | |
691 | ||
692 | static int keep_next_level_flag; | |
693 | ||
694 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
695 | static int binding_depth = 0; | |
696 | static int is_class_level = 0; | |
697 | ||
698 | static void | |
699 | indent () | |
700 | { | |
701 | register unsigned i; | |
702 | ||
703 | for (i = 0; i < binding_depth*2; i++) | |
704 | putc (' ', stderr); | |
705 | } | |
706 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
707 | ||
708 | static tree pushdecl_with_scope PROTO((tree, struct binding_level *)); | |
709 | ||
710 | static void | |
711 | push_binding_level (newlevel, tag_transparent, keep) | |
712 | struct binding_level *newlevel; | |
713 | int tag_transparent, keep; | |
714 | { | |
715 | /* Add this level to the front of the chain (stack) of levels that | |
716 | are active. */ | |
717 | *newlevel = clear_binding_level; | |
718 | if (class_binding_level) | |
719 | { | |
720 | newlevel->level_chain = class_binding_level; | |
721 | class_binding_level = (struct binding_level *)0; | |
722 | } | |
723 | else | |
724 | { | |
725 | newlevel->level_chain = current_binding_level; | |
726 | } | |
727 | current_binding_level = newlevel; | |
728 | newlevel->tag_transparent = tag_transparent; | |
729 | newlevel->more_cleanups_ok = 1; | |
8d08fdba MS |
730 | newlevel->keep = keep; |
731 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
732 | newlevel->binding_depth = binding_depth; | |
733 | indent (); | |
734 | fprintf (stderr, "push %s level 0x%08x line %d\n", | |
735 | (is_class_level) ? "class" : "block", newlevel, lineno); | |
736 | is_class_level = 0; | |
737 | binding_depth++; | |
738 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
739 | } | |
740 | ||
741 | static void | |
742 | pop_binding_level () | |
743 | { | |
744 | if (class_binding_level) | |
745 | current_binding_level = class_binding_level; | |
746 | ||
747 | if (global_binding_level) | |
748 | { | |
e92cc029 | 749 | /* cannot pop a level, if there are none left to pop. */ |
8d08fdba MS |
750 | if (current_binding_level == global_binding_level) |
751 | my_friendly_abort (123); | |
752 | } | |
753 | /* Pop the current level, and free the structure for reuse. */ | |
754 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
755 | binding_depth--; | |
756 | indent (); | |
757 | fprintf (stderr, "pop %s level 0x%08x line %d\n", | |
758 | (is_class_level) ? "class" : "block", | |
759 | current_binding_level, lineno); | |
760 | if (is_class_level != (current_binding_level == class_binding_level)) | |
9e9ff709 MS |
761 | { |
762 | indent (); | |
763 | fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); | |
764 | } | |
8d08fdba MS |
765 | is_class_level = 0; |
766 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
767 | { | |
768 | register struct binding_level *level = current_binding_level; | |
769 | current_binding_level = current_binding_level->level_chain; | |
770 | level->level_chain = free_binding_level; | |
771 | #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
772 | if (level->binding_depth != binding_depth) | |
773 | abort (); | |
774 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
775 | free_binding_level = level; | |
776 | ||
777 | class_binding_level = current_binding_level; | |
778 | if (class_binding_level->parm_flag != 2) | |
779 | class_binding_level = 0; | |
780 | while (current_binding_level->parm_flag == 2) | |
781 | current_binding_level = current_binding_level->level_chain; | |
782 | } | |
783 | } | |
a9aedbc2 MS |
784 | |
785 | static void | |
786 | suspend_binding_level () | |
787 | { | |
788 | if (class_binding_level) | |
789 | current_binding_level = class_binding_level; | |
790 | ||
791 | if (global_binding_level) | |
792 | { | |
e92cc029 | 793 | /* cannot suspend a level, if there are none left to suspend. */ |
a9aedbc2 MS |
794 | if (current_binding_level == global_binding_level) |
795 | my_friendly_abort (123); | |
796 | } | |
797 | /* Suspend the current level. */ | |
798 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
799 | binding_depth--; | |
800 | indent (); | |
801 | fprintf (stderr, "suspend %s level 0x%08x line %d\n", | |
802 | (is_class_level) ? "class" : "block", | |
803 | current_binding_level, lineno); | |
804 | if (is_class_level != (current_binding_level == class_binding_level)) | |
9e9ff709 MS |
805 | { |
806 | indent (); | |
807 | fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); | |
808 | } | |
a9aedbc2 MS |
809 | is_class_level = 0; |
810 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
811 | { | |
a9aedbc2 | 812 | current_binding_level = current_binding_level->level_chain; |
a9aedbc2 MS |
813 | class_binding_level = current_binding_level; |
814 | if (class_binding_level->parm_flag != 2) | |
815 | class_binding_level = 0; | |
816 | while (current_binding_level->parm_flag == 2) | |
817 | current_binding_level = current_binding_level->level_chain; | |
818 | } | |
819 | } | |
820 | ||
824b9a4c | 821 | static void |
a9aedbc2 MS |
822 | resume_binding_level (b) |
823 | struct binding_level *b; | |
824 | { | |
825 | if (class_binding_level) | |
826 | { | |
827 | #if 1 | |
e92cc029 | 828 | /* These are here because we cannot deal with shadows yet. */ |
a9aedbc2 MS |
829 | sorry ("cannot resume a namespace inside class"); |
830 | return; | |
831 | #else | |
832 | b->level_chain = class_binding_level; | |
833 | class_binding_level = (struct binding_level *)0; | |
834 | #endif | |
835 | } | |
836 | else | |
837 | { | |
838 | #if 1 | |
e92cc029 | 839 | /* These are here because we cannot deal with shadows yet. */ |
a9aedbc2 MS |
840 | if (b->level_chain != current_binding_level) |
841 | { | |
842 | sorry ("cannot resume a namespace inside a different namespace"); | |
843 | return; | |
844 | } | |
845 | #endif | |
846 | b->level_chain = current_binding_level; | |
847 | } | |
848 | current_binding_level = b; | |
849 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
850 | b->binding_depth = binding_depth; | |
851 | indent (); | |
852 | fprintf (stderr, "resume %s level 0x%08x line %d\n", | |
853 | (is_class_level) ? "class" : "block", b, lineno); | |
854 | is_class_level = 0; | |
855 | binding_depth++; | |
856 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
857 | } | |
8d08fdba | 858 | \f |
cffa8729 MS |
859 | /* Create a new `struct binding_level'. */ |
860 | ||
861 | static | |
862 | struct binding_level * | |
863 | make_binding_level () | |
864 | { | |
865 | /* NOSTRICT */ | |
866 | return (struct binding_level *) xmalloc (sizeof (struct binding_level)); | |
867 | } | |
868 | ||
8d08fdba MS |
869 | /* Nonzero if we are currently in the global binding level. */ |
870 | ||
871 | int | |
872 | global_bindings_p () | |
873 | { | |
874 | return current_binding_level == global_binding_level; | |
875 | } | |
876 | ||
a9aedbc2 MS |
877 | /* Nonzero if we are currently in a toplevel binding level. This |
878 | means either the global binding level or a namespace in a toplevel | |
879 | binding level. */ | |
880 | ||
881 | int | |
882 | toplevel_bindings_p () | |
883 | { | |
884 | struct binding_level *b = current_binding_level; | |
885 | ||
886 | while (1) | |
887 | { | |
888 | if (b == global_binding_level) | |
889 | return 1; | |
5566b478 MS |
890 | if (b->pseudo_global) |
891 | return 1; | |
a9aedbc2 MS |
892 | if (! b->namespace_p) |
893 | return 0; | |
894 | b=b->level_chain; | |
895 | } | |
896 | } | |
897 | ||
898 | /* Nonzero if this is a namespace scope. */ | |
899 | ||
824b9a4c | 900 | static int |
a9aedbc2 MS |
901 | namespace_bindings_p () |
902 | { | |
903 | return current_binding_level->namespace_p; | |
904 | } | |
905 | ||
8d08fdba MS |
906 | void |
907 | keep_next_level () | |
908 | { | |
909 | keep_next_level_flag = 1; | |
910 | } | |
911 | ||
912 | /* Nonzero if the current level needs to have a BLOCK made. */ | |
913 | ||
914 | int | |
915 | kept_level_p () | |
916 | { | |
917 | return (current_binding_level->blocks != NULL_TREE | |
918 | || current_binding_level->keep | |
919 | || current_binding_level->names != NULL_TREE | |
920 | || (current_binding_level->tags != NULL_TREE | |
921 | && !current_binding_level->tag_transparent)); | |
922 | } | |
923 | ||
924 | /* Identify this binding level as a level of parameters. */ | |
925 | ||
926 | void | |
927 | declare_parm_level () | |
928 | { | |
929 | current_binding_level->parm_flag = 1; | |
930 | } | |
931 | ||
8d08fdba MS |
932 | void |
933 | declare_pseudo_global_level () | |
934 | { | |
935 | current_binding_level->pseudo_global = 1; | |
936 | } | |
937 | ||
824b9a4c | 938 | static void |
a9aedbc2 MS |
939 | declare_namespace_level () |
940 | { | |
941 | current_binding_level->namespace_p = 1; | |
942 | } | |
943 | ||
8d08fdba MS |
944 | int |
945 | pseudo_global_level_p () | |
946 | { | |
947 | return current_binding_level->pseudo_global; | |
948 | } | |
949 | ||
950 | void | |
951 | set_class_shadows (shadows) | |
952 | tree shadows; | |
953 | { | |
954 | class_binding_level->class_shadowed = shadows; | |
955 | } | |
956 | ||
957 | /* Enter a new binding level. | |
958 | If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, | |
959 | not for that of tags. */ | |
960 | ||
961 | void | |
962 | pushlevel (tag_transparent) | |
963 | int tag_transparent; | |
964 | { | |
965 | register struct binding_level *newlevel = NULL_BINDING_LEVEL; | |
966 | ||
967 | /* If this is the top level of a function, | |
968 | just make sure that NAMED_LABELS is 0. | |
969 | They should have been set to 0 at the end of the previous function. */ | |
970 | ||
971 | if (current_binding_level == global_binding_level) | |
972 | my_friendly_assert (named_labels == NULL_TREE, 134); | |
973 | ||
974 | /* Reuse or create a struct for this binding level. */ | |
975 | ||
976 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
977 | if (0) | |
978 | #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
979 | if (free_binding_level) | |
980 | #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
981 | { | |
982 | newlevel = free_binding_level; | |
983 | free_binding_level = free_binding_level->level_chain; | |
984 | } | |
985 | else | |
986 | { | |
cffa8729 | 987 | newlevel = make_binding_level (); |
8d08fdba | 988 | } |
cffa8729 | 989 | |
8d08fdba MS |
990 | push_binding_level (newlevel, tag_transparent, keep_next_level_flag); |
991 | GNU_xref_start_scope ((HOST_WIDE_INT) newlevel); | |
992 | keep_next_level_flag = 0; | |
993 | } | |
994 | ||
5566b478 | 995 | void |
8d6e462b PB |
996 | note_level_for_for () |
997 | { | |
998 | current_binding_level->is_for_scope = 1; | |
999 | } | |
1000 | ||
8d08fdba MS |
1001 | void |
1002 | pushlevel_temporary (tag_transparent) | |
1003 | int tag_transparent; | |
1004 | { | |
1005 | pushlevel (tag_transparent); | |
1006 | current_binding_level->keep = 2; | |
1007 | clear_last_expr (); | |
1008 | ||
1009 | /* Note we don't call push_momentary() here. Otherwise, it would cause | |
1010 | cleanups to be allocated on the momentary obstack, and they will be | |
1011 | overwritten by the next statement. */ | |
1012 | ||
1013 | expand_start_bindings (0); | |
1014 | } | |
1015 | ||
1016 | /* Exit a binding level. | |
1017 | Pop the level off, and restore the state of the identifier-decl mappings | |
1018 | that were in effect when this level was entered. | |
1019 | ||
1020 | If KEEP == 1, this level had explicit declarations, so | |
1021 | and create a "block" (a BLOCK node) for the level | |
1022 | to record its declarations and subblocks for symbol table output. | |
1023 | ||
1024 | If KEEP == 2, this level's subblocks go to the front, | |
1025 | not the back of the current binding level. This happens, | |
1026 | for instance, when code for constructors and destructors | |
1027 | need to generate code at the end of a function which must | |
1028 | be moved up to the front of the function. | |
1029 | ||
1030 | If FUNCTIONBODY is nonzero, this level is the body of a function, | |
1031 | so create a block as if KEEP were set and also clear out all | |
1032 | label names. | |
1033 | ||
1034 | If REVERSE is nonzero, reverse the order of decls before putting | |
1035 | them into the BLOCK. */ | |
1036 | ||
1037 | tree | |
1038 | poplevel (keep, reverse, functionbody) | |
1039 | int keep; | |
1040 | int reverse; | |
1041 | int functionbody; | |
1042 | { | |
1043 | register tree link; | |
1044 | /* The chain of decls was accumulated in reverse order. | |
1045 | Put it into forward order, just for cleanliness. */ | |
1046 | tree decls; | |
1047 | int tmp = functionbody; | |
8d08fdba MS |
1048 | int real_functionbody = current_binding_level->keep == 2 |
1049 | ? ((functionbody = 0), tmp) : functionbody; | |
1050 | tree tags = functionbody >= 0 ? current_binding_level->tags : 0; | |
1051 | tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; | |
1052 | tree block = NULL_TREE; | |
1053 | tree decl; | |
1054 | int block_previously_created; | |
1055 | ||
1056 | GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, | |
1057 | (HOST_WIDE_INT) current_binding_level->level_chain, | |
1058 | current_binding_level->parm_flag, | |
5566b478 | 1059 | current_binding_level->keep); |
8d08fdba MS |
1060 | |
1061 | if (current_binding_level->keep == 1) | |
1062 | keep = 1; | |
1063 | ||
8d08fdba MS |
1064 | /* Get the decls in the order they were written. |
1065 | Usually current_binding_level->names is in reverse order. | |
1066 | But parameter decls were previously put in forward order. */ | |
1067 | ||
1068 | if (reverse) | |
1069 | current_binding_level->names | |
1070 | = decls = nreverse (current_binding_level->names); | |
1071 | else | |
1072 | decls = current_binding_level->names; | |
1073 | ||
1074 | /* Output any nested inline functions within this block | |
1075 | if they weren't already output. */ | |
1076 | ||
1077 | for (decl = decls; decl; decl = TREE_CHAIN (decl)) | |
1078 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1079 | && ! TREE_ASM_WRITTEN (decl) | |
1080 | && DECL_INITIAL (decl) != NULL_TREE | |
6060a796 MS |
1081 | && TREE_ADDRESSABLE (decl) |
1082 | && decl_function_context (decl) == current_function_decl) | |
8d08fdba MS |
1083 | { |
1084 | /* If this decl was copied from a file-scope decl | |
1085 | on account of a block-scope extern decl, | |
1086 | propagate TREE_ADDRESSABLE to the file-scope decl. */ | |
1087 | if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) | |
1088 | TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; | |
1089 | else | |
1090 | { | |
1091 | push_function_context (); | |
1092 | output_inline_function (decl); | |
1093 | pop_function_context (); | |
1094 | } | |
1095 | } | |
1096 | ||
1097 | /* If there were any declarations or structure tags in that level, | |
1098 | or if this level is a function body, | |
1099 | create a BLOCK to record them for the life of this function. */ | |
1100 | ||
1101 | block = NULL_TREE; | |
1102 | block_previously_created = (current_binding_level->this_block != NULL_TREE); | |
1103 | if (block_previously_created) | |
1104 | block = current_binding_level->this_block; | |
1105 | else if (keep == 1 || functionbody) | |
1106 | block = make_node (BLOCK); | |
1107 | if (block != NULL_TREE) | |
1108 | { | |
72b7eeff MS |
1109 | if (block_previously_created) |
1110 | { | |
1111 | if (decls || tags || subblocks) | |
1112 | { | |
be99da77 | 1113 | if (BLOCK_VARS (block) || BLOCK_TYPE_TAGS (block)) |
72b7eeff MS |
1114 | { |
1115 | warning ("internal compiler error: debugging info corrupted"); | |
1116 | } | |
1117 | BLOCK_VARS (block) = decls; | |
1118 | BLOCK_TYPE_TAGS (block) = tags; | |
be99da77 MS |
1119 | |
1120 | /* We can have previous subblocks and new subblocks when | |
1121 | doing fixup_gotos with complex cleanups. We chain the new | |
1122 | subblocks onto the end of any pre-existing subblocks. */ | |
1123 | BLOCK_SUBBLOCKS (block) = chainon (BLOCK_SUBBLOCKS (block), | |
1124 | subblocks); | |
72b7eeff | 1125 | } |
be99da77 MS |
1126 | /* If we created the block earlier on, and we are just |
1127 | diddling it now, then it already should have a proper | |
1128 | BLOCK_END_NOTE value associated with it. */ | |
72b7eeff MS |
1129 | } |
1130 | else | |
1131 | { | |
1132 | BLOCK_VARS (block) = decls; | |
1133 | BLOCK_TYPE_TAGS (block) = tags; | |
1134 | BLOCK_SUBBLOCKS (block) = subblocks; | |
1135 | /* Otherwise, for a new block, install a new BLOCK_END_NOTE value. */ | |
1136 | remember_end_note (block); | |
1137 | } | |
8d08fdba MS |
1138 | } |
1139 | ||
1140 | /* In each subblock, record that this is its superior. */ | |
1141 | ||
1142 | if (keep >= 0) | |
1143 | for (link = subblocks; link; link = TREE_CHAIN (link)) | |
1144 | BLOCK_SUPERCONTEXT (link) = block; | |
1145 | ||
1146 | /* Clear out the meanings of the local variables of this level. */ | |
1147 | ||
8d6e462b PB |
1148 | if (current_binding_level->is_for_scope && flag_new_for_scope == 1) |
1149 | { | |
2ee887f2 | 1150 | struct binding_level *outer = current_binding_level->level_chain; |
8d6e462b PB |
1151 | for (link = decls; link; link = TREE_CHAIN (link)) |
1152 | { | |
1153 | if (TREE_CODE (link) == VAR_DECL) | |
1154 | DECL_DEAD_FOR_LOCAL (link) = 1; | |
e76a2646 MS |
1155 | else |
1156 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
8d6e462b | 1157 | } |
2ee887f2 MS |
1158 | |
1159 | /* Save declarations made in a 'for' statement so we can support pre-ANSI | |
e92cc029 | 1160 | 'for' scoping semantics. */ |
2ee887f2 MS |
1161 | |
1162 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1163 | { | |
1164 | tree id = TREE_PURPOSE (link); | |
1165 | tree decl = IDENTIFIER_LOCAL_VALUE (id); | |
1166 | ||
e76a2646 MS |
1167 | if (decl && DECL_DEAD_FOR_LOCAL (decl)) |
1168 | { | |
1169 | /* In this case keep the dead for-decl visible, | |
e92cc029 | 1170 | but remember what (if anything) it shadowed. */ |
e76a2646 MS |
1171 | DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link); |
1172 | TREE_CHAIN (decl) = outer->dead_vars_from_for; | |
1173 | outer->dead_vars_from_for = decl; | |
1174 | } | |
1175 | else | |
1176 | IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link); | |
2ee887f2 | 1177 | } |
8d6e462b | 1178 | } |
e92cc029 | 1179 | else /* Not special for scope. */ |
8d6e462b PB |
1180 | { |
1181 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1182 | { | |
1183 | if (DECL_NAME (link) != NULL_TREE) | |
8d08fdba | 1184 | { |
8d6e462b PB |
1185 | /* If the ident. was used or addressed via a local extern decl, |
1186 | don't forget that fact. */ | |
1187 | if (DECL_EXTERNAL (link)) | |
1188 | { | |
1189 | if (TREE_USED (link)) | |
1190 | TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; | |
1191 | if (TREE_ADDRESSABLE (link)) | |
1192 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1193 | } | |
1194 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
8d08fdba | 1195 | } |
8d08fdba | 1196 | } |
8d08fdba | 1197 | |
2ee887f2 MS |
1198 | /* Restore all name-meanings of the outer levels |
1199 | that were shadowed by this level. */ | |
8d08fdba | 1200 | |
2ee887f2 MS |
1201 | for (link = current_binding_level->shadowed; |
1202 | link; link = TREE_CHAIN (link)) | |
1203 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1204 | ||
1205 | /* We first restore the regular decls and *then* the dead_vars_from_for | |
1206 | to handle this case: | |
1207 | ||
1208 | int i; // i#1 | |
1209 | { | |
1210 | for (int i; ; ) { ...} // i#2 | |
1211 | int i; // i#3 | |
1212 | } // we are here | |
1213 | ||
1214 | In this case, we want remove the binding for i#3, restoring | |
1215 | that of i#2. Then we want to remove the binding for i#2, | |
e92cc029 | 1216 | and restore that of i#1. */ |
2ee887f2 MS |
1217 | |
1218 | link = current_binding_level->dead_vars_from_for; | |
1219 | for (; link != NULL_TREE; link = TREE_CHAIN (link)) | |
8d6e462b | 1220 | { |
2ee887f2 MS |
1221 | tree id = DECL_NAME (link); |
1222 | if (IDENTIFIER_LOCAL_VALUE (id) == link) | |
1223 | IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link); | |
8d6e462b PB |
1224 | } |
1225 | ||
2ee887f2 MS |
1226 | for (link = current_binding_level->class_shadowed; |
1227 | link; link = TREE_CHAIN (link)) | |
1228 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1229 | for (link = current_binding_level->type_shadowed; | |
1230 | link; link = TREE_CHAIN (link)) | |
1231 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
8d6e462b | 1232 | } |
8d08fdba MS |
1233 | |
1234 | /* If the level being exited is the top level of a function, | |
1235 | check over all the labels. */ | |
1236 | ||
1237 | if (functionbody) | |
1238 | { | |
1239 | /* If this is the top level block of a function, | |
1240 | the vars are the function's parameters. | |
1241 | Don't leave them in the BLOCK because they are | |
1242 | found in the FUNCTION_DECL instead. */ | |
1243 | ||
1244 | BLOCK_VARS (block) = 0; | |
1245 | ||
1246 | /* Clear out the definitions of all label names, | |
1247 | since their scopes end here. */ | |
1248 | ||
1249 | for (link = named_labels; link; link = TREE_CHAIN (link)) | |
1250 | { | |
1251 | register tree label = TREE_VALUE (link); | |
1252 | ||
1253 | if (DECL_INITIAL (label) == NULL_TREE) | |
1254 | { | |
1255 | cp_error_at ("label `%D' used but not defined", label); | |
1256 | /* Avoid crashing later. */ | |
1257 | define_label (input_filename, 1, DECL_NAME (label)); | |
1258 | } | |
1259 | else if (warn_unused && !TREE_USED (label)) | |
1260 | cp_warning_at ("label `%D' defined but not used", label); | |
1261 | SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE); | |
1262 | ||
1263 | /* Put the labels into the "variables" of the | |
1264 | top-level block, so debugger can see them. */ | |
1265 | TREE_CHAIN (label) = BLOCK_VARS (block); | |
1266 | BLOCK_VARS (block) = label; | |
1267 | } | |
1268 | ||
1269 | named_labels = NULL_TREE; | |
1270 | } | |
1271 | ||
1272 | /* Any uses of undefined labels now operate under constraints | |
1273 | of next binding contour. */ | |
1274 | { | |
1275 | struct binding_level *level_chain; | |
1276 | level_chain = current_binding_level->level_chain; | |
1277 | if (level_chain) | |
1278 | { | |
e349ee73 MS |
1279 | struct named_label_list *labels; |
1280 | for (labels = named_label_uses; labels; labels = labels->next) | |
1281 | if (labels->binding_level == current_binding_level) | |
8d08fdba | 1282 | { |
e349ee73 MS |
1283 | labels->binding_level = level_chain; |
1284 | labels->names_in_scope = level_chain->names; | |
8d08fdba MS |
1285 | } |
1286 | } | |
1287 | } | |
1288 | ||
1289 | tmp = current_binding_level->keep; | |
1290 | ||
1291 | pop_binding_level (); | |
1292 | if (functionbody) | |
1293 | DECL_INITIAL (current_function_decl) = block; | |
1294 | else if (block) | |
1295 | { | |
1296 | if (!block_previously_created) | |
1297 | current_binding_level->blocks | |
1298 | = chainon (current_binding_level->blocks, block); | |
1299 | } | |
1300 | /* If we did not make a block for the level just exited, | |
1301 | any blocks made for inner levels | |
1302 | (since they cannot be recorded as subblocks in that level) | |
1303 | must be carried forward so they will later become subblocks | |
1304 | of something else. */ | |
1305 | else if (subblocks) | |
1306 | { | |
1307 | if (keep == 2) | |
1308 | current_binding_level->blocks | |
1309 | = chainon (subblocks, current_binding_level->blocks); | |
1310 | else | |
1311 | current_binding_level->blocks | |
1312 | = chainon (current_binding_level->blocks, subblocks); | |
1313 | } | |
1314 | ||
1315 | /* Take care of compiler's internal binding structures. */ | |
a4443a08 | 1316 | if (tmp == 2) |
8d08fdba | 1317 | { |
8d08fdba MS |
1318 | expand_end_bindings (getdecls (), keep, 1); |
1319 | /* Each and every BLOCK node created here in `poplevel' is important | |
1320 | (e.g. for proper debugging information) so if we created one | |
1321 | earlier, mark it as "used". */ | |
1322 | if (block) | |
1323 | TREE_USED (block) = 1; | |
1324 | block = poplevel (keep, reverse, real_functionbody); | |
1325 | } | |
1326 | ||
1327 | /* Each and every BLOCK node created here in `poplevel' is important | |
1328 | (e.g. for proper debugging information) so if we created one | |
1329 | earlier, mark it as "used". */ | |
1330 | if (block) | |
1331 | TREE_USED (block) = 1; | |
1332 | return block; | |
1333 | } | |
1334 | ||
a9aedbc2 | 1335 | /* Resume a binding level for a namespace. */ |
e92cc029 | 1336 | |
a9aedbc2 MS |
1337 | void |
1338 | resume_level (b) | |
1339 | struct binding_level *b; | |
1340 | { | |
1341 | tree decls, link; | |
1342 | ||
1343 | resume_binding_level (b); | |
1344 | ||
1345 | /* Resume the variable caches. */ | |
1346 | decls = current_binding_level->names; | |
1347 | ||
1348 | /* Restore the meanings of the local variables of this level. */ | |
1349 | ||
1350 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1351 | { | |
cffa8729 MS |
1352 | /* If it doesn't have a name, there is nothing left to do with it. */ |
1353 | if (DECL_NAME (link) == NULL_TREE) | |
1354 | continue; | |
1355 | ||
1356 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link; | |
a9aedbc2 MS |
1357 | |
1358 | /* If this is a TYPE_DECL, push it into the type value slot. */ | |
1359 | if (TREE_CODE (link) == TYPE_DECL) | |
1360 | SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link)); | |
1361 | } | |
1362 | } | |
1363 | ||
8d08fdba MS |
1364 | /* Delete the node BLOCK from the current binding level. |
1365 | This is used for the block inside a stmt expr ({...}) | |
1366 | so that the block can be reinserted where appropriate. */ | |
1367 | ||
1368 | void | |
1369 | delete_block (block) | |
1370 | tree block; | |
1371 | { | |
1372 | tree t; | |
1373 | if (current_binding_level->blocks == block) | |
1374 | current_binding_level->blocks = TREE_CHAIN (block); | |
1375 | for (t = current_binding_level->blocks; t;) | |
1376 | { | |
1377 | if (TREE_CHAIN (t) == block) | |
1378 | TREE_CHAIN (t) = TREE_CHAIN (block); | |
1379 | else | |
1380 | t = TREE_CHAIN (t); | |
1381 | } | |
1382 | TREE_CHAIN (block) = NULL_TREE; | |
1383 | /* Clear TREE_USED which is always set by poplevel. | |
1384 | The flag is set again if insert_block is called. */ | |
1385 | TREE_USED (block) = 0; | |
1386 | } | |
1387 | ||
1388 | /* Insert BLOCK at the end of the list of subblocks of the | |
1389 | current binding level. This is used when a BIND_EXPR is expanded, | |
1390 | to handle the BLOCK node inside the BIND_EXPR. */ | |
1391 | ||
1392 | void | |
1393 | insert_block (block) | |
1394 | tree block; | |
1395 | { | |
1396 | TREE_USED (block) = 1; | |
1397 | current_binding_level->blocks | |
1398 | = chainon (current_binding_level->blocks, block); | |
1399 | } | |
1400 | ||
1401 | /* Add BLOCK to the current list of blocks for this binding contour. */ | |
e92cc029 | 1402 | |
8d08fdba MS |
1403 | void |
1404 | add_block_current_level (block) | |
1405 | tree block; | |
1406 | { | |
1407 | current_binding_level->blocks | |
1408 | = chainon (current_binding_level->blocks, block); | |
1409 | } | |
1410 | ||
1411 | /* Set the BLOCK node for the innermost scope | |
1412 | (the one we are currently in). */ | |
1413 | ||
1414 | void | |
1415 | set_block (block) | |
1416 | register tree block; | |
1417 | { | |
1418 | current_binding_level->this_block = block; | |
1419 | } | |
1420 | ||
1421 | /* Do a pushlevel for class declarations. */ | |
e92cc029 | 1422 | |
8d08fdba MS |
1423 | void |
1424 | pushlevel_class () | |
1425 | { | |
1426 | register struct binding_level *newlevel; | |
1427 | ||
1428 | /* Reuse or create a struct for this binding level. */ | |
1429 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
1430 | if (0) | |
1431 | #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
1432 | if (free_binding_level) | |
1433 | #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ | |
1434 | { | |
1435 | newlevel = free_binding_level; | |
1436 | free_binding_level = free_binding_level->level_chain; | |
1437 | } | |
1438 | else | |
1439 | { | |
cffa8729 | 1440 | newlevel = make_binding_level (); |
8d08fdba MS |
1441 | } |
1442 | ||
1443 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
1444 | is_class_level = 1; | |
1445 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
1446 | ||
1447 | push_binding_level (newlevel, 0, 0); | |
1448 | ||
1449 | decl_stack = push_decl_level (decl_stack, &decl_obstack); | |
1450 | class_binding_level = current_binding_level; | |
1451 | class_binding_level->parm_flag = 2; | |
1452 | /* We have just pushed into a new binding level. Now, fake out the rest | |
1453 | of the compiler. Set the `current_binding_level' back to point to | |
1454 | the most closely containing non-class binding level. */ | |
1455 | do | |
1456 | { | |
1457 | current_binding_level = current_binding_level->level_chain; | |
1458 | } | |
1459 | while (current_binding_level->parm_flag == 2); | |
1460 | } | |
1461 | ||
700f8a87 MS |
1462 | /* ...and a poplevel for class declarations. FORCE is used to force |
1463 | clearing out of CLASS_VALUEs after a class definition. */ | |
e92cc029 | 1464 | |
8d08fdba | 1465 | tree |
700f8a87 MS |
1466 | poplevel_class (force) |
1467 | int force; | |
8d08fdba MS |
1468 | { |
1469 | register struct binding_level *level = class_binding_level; | |
1470 | tree block = NULL_TREE; | |
1471 | tree shadowed; | |
1472 | ||
1473 | my_friendly_assert (level != 0, 354); | |
1474 | ||
1475 | decl_stack = pop_stack_level (decl_stack); | |
1476 | for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
1477 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1478 | /* If we're leaving a toplevel class, don't bother to do the setting | |
ddd5a7c1 | 1479 | of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot |
8d08fdba | 1480 | shouldn't even be used when current_class_type isn't set, and second, |
ddd5a7c1 | 1481 | if we don't touch it here, we're able to use the cache effect if the |
8d08fdba | 1482 | next time we're entering a class scope, it is the same class. */ |
700f8a87 | 1483 | if (current_class_depth != 1 || force) |
8d08fdba MS |
1484 | for (shadowed = level->class_shadowed; |
1485 | shadowed; | |
1486 | shadowed = TREE_CHAIN (shadowed)) | |
1487 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1488 | else | |
1489 | /* Remember to save what IDENTIFIER's were bound in this scope so we | |
1490 | can recover from cache misses. */ | |
e76a2646 MS |
1491 | { |
1492 | previous_class_type = current_class_type; | |
1493 | previous_class_values = class_binding_level->class_shadowed; | |
1494 | } | |
8d08fdba MS |
1495 | for (shadowed = level->type_shadowed; |
1496 | shadowed; | |
1497 | shadowed = TREE_CHAIN (shadowed)) | |
1498 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); | |
1499 | ||
1500 | GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, | |
1501 | (HOST_WIDE_INT) class_binding_level->level_chain, | |
1502 | class_binding_level->parm_flag, | |
5566b478 | 1503 | class_binding_level->keep); |
8d08fdba MS |
1504 | |
1505 | if (class_binding_level->parm_flag != 2) | |
1506 | class_binding_level = (struct binding_level *)0; | |
1507 | ||
1508 | /* Now, pop out of the the binding level which we created up in the | |
1509 | `pushlevel_class' routine. */ | |
1510 | #if defined(DEBUG_CP_BINDING_LEVELS) | |
1511 | is_class_level = 1; | |
1512 | #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ | |
1513 | ||
1514 | pop_binding_level (); | |
1515 | ||
1516 | return block; | |
1517 | } | |
1518 | \f | |
1519 | /* For debugging. */ | |
5566b478 MS |
1520 | static int no_print_functions = 0; |
1521 | static int no_print_builtins = 0; | |
8d08fdba MS |
1522 | |
1523 | void | |
1524 | print_binding_level (lvl) | |
1525 | struct binding_level *lvl; | |
1526 | { | |
1527 | tree t; | |
1528 | int i = 0, len; | |
1529 | fprintf (stderr, " blocks="); | |
1530 | fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks); | |
1531 | fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d", | |
f30432d7 | 1532 | list_length (lvl->incomplete), lvl->parm_flag, lvl->keep); |
8d08fdba MS |
1533 | if (lvl->tag_transparent) |
1534 | fprintf (stderr, " tag-transparent"); | |
1535 | if (lvl->more_cleanups_ok) | |
1536 | fprintf (stderr, " more-cleanups-ok"); | |
1537 | if (lvl->have_cleanups) | |
1538 | fprintf (stderr, " have-cleanups"); | |
8d08fdba MS |
1539 | fprintf (stderr, "\n"); |
1540 | if (lvl->names) | |
1541 | { | |
1542 | fprintf (stderr, " names:\t"); | |
1543 | /* We can probably fit 3 names to a line? */ | |
1544 | for (t = lvl->names; t; t = TREE_CHAIN (t)) | |
1545 | { | |
fc378698 | 1546 | if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL)) |
8d08fdba MS |
1547 | continue; |
1548 | if (no_print_builtins | |
fc378698 MS |
1549 | && (TREE_CODE (t) == TYPE_DECL) |
1550 | && (!strcmp (DECL_SOURCE_FILE (t),"<built-in>"))) | |
8d08fdba MS |
1551 | continue; |
1552 | ||
1553 | /* Function decls tend to have longer names. */ | |
1554 | if (TREE_CODE (t) == FUNCTION_DECL) | |
1555 | len = 3; | |
1556 | else | |
1557 | len = 2; | |
1558 | i += len; | |
1559 | if (i > 6) | |
1560 | { | |
1561 | fprintf (stderr, "\n\t"); | |
1562 | i = len; | |
1563 | } | |
1564 | print_node_brief (stderr, "", t, 0); | |
bd6dd845 | 1565 | if (t == error_mark_node) |
8d08fdba MS |
1566 | break; |
1567 | } | |
1568 | if (i) | |
1569 | fprintf (stderr, "\n"); | |
1570 | } | |
1571 | if (lvl->tags) | |
1572 | { | |
1573 | fprintf (stderr, " tags:\t"); | |
1574 | i = 0; | |
1575 | for (t = lvl->tags; t; t = TREE_CHAIN (t)) | |
1576 | { | |
1577 | if (TREE_PURPOSE (t) == NULL_TREE) | |
1578 | len = 3; | |
1579 | else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) | |
1580 | len = 2; | |
1581 | else | |
1582 | len = 4; | |
1583 | i += len; | |
1584 | if (i > 5) | |
1585 | { | |
1586 | fprintf (stderr, "\n\t"); | |
1587 | i = len; | |
1588 | } | |
1589 | if (TREE_PURPOSE (t) == NULL_TREE) | |
1590 | { | |
1591 | print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0); | |
1592 | fprintf (stderr, ">"); | |
1593 | } | |
1594 | else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) | |
1595 | print_node_brief (stderr, "", TREE_VALUE (t), 0); | |
1596 | else | |
1597 | { | |
1598 | print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0); | |
1599 | print_node_brief (stderr, "", TREE_VALUE (t), 0); | |
1600 | fprintf (stderr, ">"); | |
1601 | } | |
1602 | } | |
1603 | if (i) | |
1604 | fprintf (stderr, "\n"); | |
1605 | } | |
1606 | if (lvl->shadowed) | |
1607 | { | |
1608 | fprintf (stderr, " shadowed:"); | |
1609 | for (t = lvl->shadowed; t; t = TREE_CHAIN (t)) | |
1610 | { | |
1611 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
1612 | } | |
1613 | fprintf (stderr, "\n"); | |
1614 | } | |
1615 | if (lvl->class_shadowed) | |
1616 | { | |
1617 | fprintf (stderr, " class-shadowed:"); | |
1618 | for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t)) | |
1619 | { | |
1620 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
1621 | } | |
1622 | fprintf (stderr, "\n"); | |
1623 | } | |
1624 | if (lvl->type_shadowed) | |
1625 | { | |
1626 | fprintf (stderr, " type-shadowed:"); | |
1627 | for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t)) | |
1628 | { | |
8d08fdba | 1629 | fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); |
8d08fdba MS |
1630 | } |
1631 | fprintf (stderr, "\n"); | |
1632 | } | |
1633 | } | |
1634 | ||
1635 | void | |
1636 | print_other_binding_stack (stack) | |
1637 | struct binding_level *stack; | |
1638 | { | |
1639 | struct binding_level *level; | |
1640 | for (level = stack; level != global_binding_level; level = level->level_chain) | |
1641 | { | |
1642 | fprintf (stderr, "binding level "); | |
1643 | fprintf (stderr, HOST_PTR_PRINTF, level); | |
1644 | fprintf (stderr, "\n"); | |
1645 | print_binding_level (level); | |
1646 | } | |
1647 | } | |
1648 | ||
1649 | void | |
1650 | print_binding_stack () | |
1651 | { | |
1652 | struct binding_level *b; | |
1653 | fprintf (stderr, "current_binding_level="); | |
1654 | fprintf (stderr, HOST_PTR_PRINTF, current_binding_level); | |
1655 | fprintf (stderr, "\nclass_binding_level="); | |
1656 | fprintf (stderr, HOST_PTR_PRINTF, class_binding_level); | |
1657 | fprintf (stderr, "\nglobal_binding_level="); | |
1658 | fprintf (stderr, HOST_PTR_PRINTF, global_binding_level); | |
1659 | fprintf (stderr, "\n"); | |
1660 | if (class_binding_level) | |
1661 | { | |
1662 | for (b = class_binding_level; b; b = b->level_chain) | |
1663 | if (b == current_binding_level) | |
1664 | break; | |
1665 | if (b) | |
1666 | b = class_binding_level; | |
1667 | else | |
1668 | b = current_binding_level; | |
1669 | } | |
1670 | else | |
1671 | b = current_binding_level; | |
1672 | print_other_binding_stack (b); | |
1673 | fprintf (stderr, "global:\n"); | |
1674 | print_binding_level (global_binding_level); | |
1675 | } | |
a9aedbc2 | 1676 | |
dff6b454 RK |
1677 | extern char * first_global_object_name; |
1678 | ||
1679 | /* Get a unique name for each call to this routine for unnamed namespaces. | |
1680 | Mostly copied from get_file_function_name. */ | |
e92cc029 | 1681 | |
dff6b454 RK |
1682 | static tree |
1683 | get_unique_name () | |
1684 | { | |
1685 | static int temp_name_counter = 0; | |
1686 | char *buf; | |
1687 | register char *p; | |
1688 | ||
1689 | if (first_global_object_name) | |
1690 | p = first_global_object_name; | |
1691 | else if (main_input_filename) | |
1692 | p = main_input_filename; | |
1693 | else | |
1694 | p = input_filename; | |
1695 | ||
1696 | #define UNNAMED_NAMESPACE_FORMAT "__%s_%d" | |
1697 | ||
1698 | buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p)); | |
1699 | ||
1700 | sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++); | |
1701 | ||
1702 | /* Don't need to pull weird characters out of global names. */ | |
1703 | if (p != first_global_object_name) | |
1704 | { | |
1705 | for (p = buf+11; *p; p++) | |
1706 | if (! ((*p >= '0' && *p <= '9') | |
dff6b454 RK |
1707 | #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */ |
1708 | || *p == '$' | |
1709 | #endif | |
e92cc029 | 1710 | #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */ |
dff6b454 RK |
1711 | || *p == '.' |
1712 | #endif | |
1713 | || (*p >= 'A' && *p <= 'Z') | |
1714 | || (*p >= 'a' && *p <= 'z'))) | |
1715 | *p = '_'; | |
1716 | } | |
1717 | ||
1718 | return get_identifier (buf); | |
1719 | } | |
1720 | ||
1721 | /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we | |
1722 | select a name that is unique to this compilation unit. */ | |
e92cc029 | 1723 | |
a9aedbc2 MS |
1724 | void |
1725 | push_namespace (name) | |
1726 | tree name; | |
1727 | { | |
6633d636 MS |
1728 | #if 1 |
1729 | static int warned; | |
1730 | if (! warned) | |
1731 | sorry ("namespace"); | |
1732 | ||
1733 | warned = 1; | |
1734 | #else | |
a9aedbc2 MS |
1735 | extern tree current_namespace; |
1736 | tree old_id = get_namespace_id (); | |
1737 | char *buf; | |
72b7eeff | 1738 | tree d; |
a9aedbc2 | 1739 | |
dff6b454 RK |
1740 | if (! name) |
1741 | { | |
abc95ed3 | 1742 | /* Create a truly ugly name! */ |
dff6b454 RK |
1743 | name = get_unique_name (); |
1744 | } | |
1745 | ||
72b7eeff MS |
1746 | d = build_lang_decl (NAMESPACE_DECL, name, void_type_node); |
1747 | ||
a9aedbc2 | 1748 | /* Mark them as external, so redeclaration_error_message doesn't think |
e92cc029 | 1749 | they are duplicates. */ |
72b7eeff | 1750 | |
a9aedbc2 MS |
1751 | DECL_EXTERNAL (d) = 1; |
1752 | d = pushdecl (d); | |
1753 | ||
1754 | if (NAMESPACE_LEVEL (d) == 0) | |
1755 | { | |
1756 | /* This is new for this compilation unit. */ | |
1757 | pushlevel (0); | |
1758 | declare_namespace_level (); | |
72b7eeff | 1759 | NAMESPACE_LEVEL (d) = current_binding_level; |
a9aedbc2 MS |
1760 | } |
1761 | else | |
72b7eeff | 1762 | resume_level (NAMESPACE_LEVEL (d)); |
a9aedbc2 | 1763 | |
e92cc029 | 1764 | /* This code is just is bit old now... */ |
a9aedbc2 MS |
1765 | current_namespace = tree_cons (NULL_TREE, name, current_namespace); |
1766 | buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0) | |
1767 | + IDENTIFIER_LENGTH (name)); | |
1768 | sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "", | |
1769 | IDENTIFIER_POINTER (name)); | |
1770 | TREE_PURPOSE (current_namespace) = get_identifier (buf); | |
6633d636 | 1771 | #endif |
a9aedbc2 MS |
1772 | } |
1773 | ||
1774 | /* Pop from the scope of the current namespace. */ | |
e92cc029 | 1775 | |
a9aedbc2 MS |
1776 | void |
1777 | pop_namespace () | |
1778 | { | |
6633d636 | 1779 | #if 0 |
a9aedbc2 MS |
1780 | extern tree current_namespace; |
1781 | tree decls, link; | |
1782 | current_namespace = TREE_CHAIN (current_namespace); | |
1783 | ||
e92cc029 | 1784 | /* Just in case we get out of sync. */ |
a9aedbc2 MS |
1785 | if (! namespace_bindings_p ()) |
1786 | poplevel (0, 0, 0); | |
1787 | ||
1788 | decls = current_binding_level->names; | |
1789 | ||
1790 | /* Clear out the meanings of the local variables of this level. */ | |
1791 | ||
1792 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1793 | { | |
1794 | if (DECL_NAME (link) != NULL_TREE) | |
1795 | { | |
1796 | /* If the ident. was used or addressed via a local extern decl, | |
1797 | don't forget that fact. */ | |
1798 | if (DECL_EXTERNAL (link)) | |
1799 | { | |
1800 | if (TREE_USED (link)) | |
1801 | TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; | |
1802 | if (TREE_ADDRESSABLE (link)) | |
1803 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1804 | } | |
1805 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; | |
1806 | } | |
1807 | } | |
1808 | ||
1809 | /* Restore all name-meanings of the outer levels | |
1810 | that were shadowed by this level. */ | |
1811 | ||
1812 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1813 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1814 | for (link = current_binding_level->class_shadowed; | |
1815 | link; link = TREE_CHAIN (link)) | |
1816 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1817 | for (link = current_binding_level->type_shadowed; | |
1818 | link; link = TREE_CHAIN (link)) | |
1819 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1820 | ||
1821 | /* suspend a level. */ | |
1822 | suspend_binding_level (); | |
6633d636 | 1823 | #endif |
a9aedbc2 | 1824 | } |
8d08fdba MS |
1825 | \f |
1826 | /* Subroutines for reverting temporarily to top-level for instantiation | |
1827 | of templates and such. We actually need to clear out the class- and | |
1828 | local-value slots of all identifiers, so that only the global values | |
1829 | are at all visible. Simply setting current_binding_level to the global | |
1830 | scope isn't enough, because more binding levels may be pushed. */ | |
1831 | struct saved_scope { | |
1832 | struct binding_level *old_binding_level; | |
1833 | tree old_bindings; | |
1834 | struct saved_scope *prev; | |
5f34005f | 1835 | tree class_name, class_type, function_decl; |
8d08fdba | 1836 | struct binding_level *class_bindings; |
51c184be MS |
1837 | tree *lang_base, *lang_stack, lang_name; |
1838 | int lang_stacksize; | |
5566b478 MS |
1839 | int minimal_parse_mode; |
1840 | tree last_function_parms; | |
e76a2646 | 1841 | tree template_parms; |
5156628f | 1842 | HOST_WIDE_INT processing_template_decl; |
a50f0918 | 1843 | tree previous_class_type, previous_class_values; |
8d08fdba MS |
1844 | }; |
1845 | static struct saved_scope *current_saved_scope; | |
8d08fdba | 1846 | |
e92cc029 | 1847 | static tree |
45537677 MS |
1848 | store_bindings (names, old_bindings) |
1849 | tree names, old_bindings; | |
1850 | { | |
1851 | tree t; | |
1852 | for (t = names; t; t = TREE_CHAIN (t)) | |
1853 | { | |
1854 | tree binding, t1, id; | |
1855 | ||
1856 | if (TREE_CODE (t) == TREE_LIST) | |
1857 | id = TREE_PURPOSE (t); | |
1858 | else | |
1859 | id = DECL_NAME (t); | |
1860 | ||
1861 | if (!id | |
1862 | || (!IDENTIFIER_LOCAL_VALUE (id) | |
1863 | && !IDENTIFIER_CLASS_VALUE (id))) | |
1864 | continue; | |
1865 | ||
1866 | for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) | |
1867 | if (TREE_VEC_ELT (t1, 0) == id) | |
1868 | goto skip_it; | |
1869 | ||
1870 | binding = make_tree_vec (4); | |
1871 | if (id) | |
1872 | { | |
1873 | my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); | |
1874 | TREE_VEC_ELT (binding, 0) = id; | |
1875 | TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id); | |
1876 | TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id); | |
1877 | TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); | |
1878 | IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE; | |
1879 | IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; | |
1880 | } | |
1881 | TREE_CHAIN (binding) = old_bindings; | |
1882 | old_bindings = binding; | |
1883 | skip_it: | |
1884 | ; | |
1885 | } | |
1886 | return old_bindings; | |
1887 | } | |
1888 | ||
8d08fdba | 1889 | void |
5566b478 MS |
1890 | maybe_push_to_top_level (pseudo) |
1891 | int pseudo; | |
8d08fdba | 1892 | { |
51c184be | 1893 | extern int current_lang_stacksize; |
beb53fb8 JM |
1894 | struct saved_scope *s |
1895 | = (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); | |
5566b478 | 1896 | struct binding_level *b = inner_binding_level; |
8d08fdba MS |
1897 | tree old_bindings = NULL_TREE; |
1898 | ||
e349ee73 MS |
1899 | if (current_function_decl) |
1900 | push_cp_function_context (NULL_TREE); | |
1901 | ||
a50f0918 MS |
1902 | if (previous_class_type) |
1903 | old_bindings = store_bindings (previous_class_values, old_bindings); | |
1904 | ||
8d08fdba MS |
1905 | /* Have to include global_binding_level, because class-level decls |
1906 | aren't listed anywhere useful. */ | |
1907 | for (; b; b = b->level_chain) | |
1908 | { | |
1909 | tree t; | |
1910 | ||
5566b478 MS |
1911 | if (b == global_binding_level || (pseudo && b->pseudo_global)) |
1912 | break; | |
8d08fdba | 1913 | |
45537677 | 1914 | old_bindings = store_bindings (b->names, old_bindings); |
cffa8729 | 1915 | /* We also need to check class_shadowed to save class-level type |
45537677 MS |
1916 | bindings, since pushclass doesn't fill in b->names. */ |
1917 | if (b->parm_flag == 2) | |
cffa8729 | 1918 | old_bindings = store_bindings (b->class_shadowed, old_bindings); |
8d08fdba | 1919 | |
8d08fdba MS |
1920 | /* Unwind type-value slots back to top level. */ |
1921 | for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) | |
1922 | SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); | |
1923 | } | |
8d08fdba MS |
1924 | |
1925 | s->old_binding_level = current_binding_level; | |
5566b478 | 1926 | current_binding_level = b; |
8d08fdba MS |
1927 | |
1928 | s->class_name = current_class_name; | |
1929 | s->class_type = current_class_type; | |
8d08fdba MS |
1930 | s->function_decl = current_function_decl; |
1931 | s->class_bindings = class_binding_level; | |
51c184be MS |
1932 | s->lang_stack = current_lang_stack; |
1933 | s->lang_base = current_lang_base; | |
1934 | s->lang_stacksize = current_lang_stacksize; | |
1935 | s->lang_name = current_lang_name; | |
5566b478 MS |
1936 | s->minimal_parse_mode = minimal_parse_mode; |
1937 | s->last_function_parms = last_function_parms; | |
e76a2646 | 1938 | s->template_parms = current_template_parms; |
5156628f | 1939 | s->processing_template_decl = processing_template_decl; |
a50f0918 MS |
1940 | s->previous_class_type = previous_class_type; |
1941 | s->previous_class_values = previous_class_values; | |
e349ee73 | 1942 | |
5f34005f | 1943 | current_class_name = current_class_type = NULL_TREE; |
8d08fdba MS |
1944 | current_function_decl = NULL_TREE; |
1945 | class_binding_level = (struct binding_level *)0; | |
51c184be MS |
1946 | current_lang_stacksize = 10; |
1947 | current_lang_stack = current_lang_base | |
1948 | = (tree *) xmalloc (current_lang_stacksize * sizeof (tree)); | |
1949 | current_lang_name = lang_name_cplusplus; | |
1950 | strict_prototype = strict_prototypes_lang_cplusplus; | |
1951 | named_labels = NULL_TREE; | |
5566b478 | 1952 | minimal_parse_mode = 0; |
a50f0918 | 1953 | previous_class_type = previous_class_values = NULL_TREE; |
e76a2646 | 1954 | if (!pseudo) |
5156628f MS |
1955 | { |
1956 | current_template_parms = NULL_TREE; | |
1957 | processing_template_decl = 0; | |
1958 | } | |
8d08fdba MS |
1959 | |
1960 | s->prev = current_saved_scope; | |
1961 | s->old_bindings = old_bindings; | |
1962 | current_saved_scope = s; | |
5566b478 MS |
1963 | |
1964 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
1965 | } | |
1966 | ||
1967 | void | |
1968 | push_to_top_level () | |
1969 | { | |
1970 | maybe_push_to_top_level (0); | |
8d08fdba MS |
1971 | } |
1972 | ||
1973 | void | |
1974 | pop_from_top_level () | |
1975 | { | |
51c184be | 1976 | extern int current_lang_stacksize; |
8d08fdba MS |
1977 | struct saved_scope *s = current_saved_scope; |
1978 | tree t; | |
1979 | ||
e76a2646 | 1980 | /* Clear out class-level bindings cache. */ |
8d08fdba | 1981 | if (previous_class_type) |
e76a2646 MS |
1982 | { |
1983 | popclass (-1); | |
1984 | previous_class_type = NULL_TREE; | |
1985 | } | |
8d08fdba | 1986 | |
5566b478 MS |
1987 | pop_obstacks (); |
1988 | ||
8d08fdba MS |
1989 | current_binding_level = s->old_binding_level; |
1990 | current_saved_scope = s->prev; | |
1991 | for (t = s->old_bindings; t; t = TREE_CHAIN (t)) | |
1992 | { | |
1993 | tree id = TREE_VEC_ELT (t, 0); | |
1994 | if (id) | |
1995 | { | |
1996 | IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1); | |
1997 | IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2); | |
1998 | IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); | |
1999 | } | |
2000 | } | |
2001 | current_class_name = s->class_name; | |
2002 | current_class_type = s->class_type; | |
8d08fdba MS |
2003 | current_function_decl = s->function_decl; |
2004 | class_binding_level = s->class_bindings; | |
51c184be MS |
2005 | free (current_lang_base); |
2006 | current_lang_base = s->lang_base; | |
2007 | current_lang_stack = s->lang_stack; | |
2008 | current_lang_name = s->lang_name; | |
2009 | current_lang_stacksize = s->lang_stacksize; | |
2010 | if (current_lang_name == lang_name_cplusplus) | |
2011 | strict_prototype = strict_prototypes_lang_cplusplus; | |
2012 | else if (current_lang_name == lang_name_c) | |
2013 | strict_prototype = strict_prototypes_lang_c; | |
5566b478 MS |
2014 | minimal_parse_mode = s->minimal_parse_mode; |
2015 | last_function_parms = s->last_function_parms; | |
e76a2646 | 2016 | current_template_parms = s->template_parms; |
5156628f | 2017 | processing_template_decl = s->processing_template_decl; |
a50f0918 MS |
2018 | previous_class_type = s->previous_class_type; |
2019 | previous_class_values = s->previous_class_values; | |
51c184be | 2020 | |
8d08fdba | 2021 | free (s); |
e349ee73 MS |
2022 | |
2023 | if (current_function_decl) | |
2024 | pop_cp_function_context (NULL_TREE); | |
8d08fdba MS |
2025 | } |
2026 | \f | |
2027 | /* Push a definition of struct, union or enum tag "name". | |
2028 | into binding_level "b". "type" should be the type node, | |
2029 | We assume that the tag "name" is not already defined. | |
2030 | ||
2031 | Note that the definition may really be just a forward reference. | |
2032 | In that case, the TYPE_SIZE will be a NULL_TREE. | |
2033 | ||
e92cc029 | 2034 | C++ gratuitously puts all these tags in the name space. */ |
8d08fdba MS |
2035 | |
2036 | /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID, | |
2037 | record the shadowed value for this binding contour. TYPE is | |
2038 | the type that ID maps to. */ | |
2039 | ||
2040 | static void | |
2041 | set_identifier_type_value_with_scope (id, type, b) | |
2042 | tree id; | |
2043 | tree type; | |
2044 | struct binding_level *b; | |
2045 | { | |
2046 | if (b != global_binding_level) | |
2047 | { | |
2048 | tree old_type_value = IDENTIFIER_TYPE_VALUE (id); | |
2049 | b->type_shadowed | |
2050 | = tree_cons (id, old_type_value, b->type_shadowed); | |
2051 | } | |
2052 | SET_IDENTIFIER_TYPE_VALUE (id, type); | |
2053 | } | |
2054 | ||
e92cc029 | 2055 | /* As set_identifier_type_value_with_scope, but using inner_binding_level. */ |
8d08fdba MS |
2056 | |
2057 | void | |
2058 | set_identifier_type_value (id, type) | |
2059 | tree id; | |
2060 | tree type; | |
2061 | { | |
2062 | set_identifier_type_value_with_scope (id, type, inner_binding_level); | |
2063 | } | |
2064 | ||
a9aedbc2 MS |
2065 | /* Pop off extraneous binding levels left over due to syntax errors. |
2066 | ||
2067 | We don't pop past namespaces, as they might be valid. */ | |
e92cc029 | 2068 | |
8926095f MS |
2069 | void |
2070 | pop_everything () | |
2071 | { | |
2072 | #ifdef DEBUG_CP_BINDING_LEVELS | |
2073 | fprintf (stderr, "XXX entering pop_everything ()\n"); | |
2074 | #endif | |
a9aedbc2 | 2075 | while (! toplevel_bindings_p () && ! pseudo_global_level_p ()) |
8926095f MS |
2076 | { |
2077 | if (class_binding_level) | |
2078 | pop_nested_class (1); | |
2079 | else | |
2080 | poplevel (0, 0, 0); | |
2081 | } | |
2082 | #ifdef DEBUG_CP_BINDING_LEVELS | |
2083 | fprintf (stderr, "XXX leaving pop_everything ()\n"); | |
2084 | #endif | |
2085 | } | |
2086 | ||
8d08fdba | 2087 | /* Push a tag name NAME for struct/class/union/enum type TYPE. |
ddd5a7c1 | 2088 | Normally put into into the inner-most non-tag-transparent scope, |
8d08fdba | 2089 | but if GLOBALIZE is true, put it in the inner-most non-class scope. |
e92cc029 | 2090 | The latter is needed for implicit declarations. */ |
8d08fdba MS |
2091 | |
2092 | void | |
2093 | pushtag (name, type, globalize) | |
2094 | tree name, type; | |
2095 | int globalize; | |
2096 | { | |
2097 | register struct binding_level *b; | |
7177d104 | 2098 | tree context = 0; |
2986ae00 | 2099 | tree c_decl = 0; |
8d08fdba MS |
2100 | |
2101 | b = inner_binding_level; | |
2102 | while (b->tag_transparent | |
2103 | || (globalize && b->parm_flag == 2)) | |
2104 | b = b->level_chain; | |
2105 | ||
a9aedbc2 | 2106 | if (toplevel_bindings_p ()) |
8d08fdba MS |
2107 | b->tags = perm_tree_cons (name, type, b->tags); |
2108 | else | |
2109 | b->tags = saveable_tree_cons (name, type, b->tags); | |
2110 | ||
2111 | if (name) | |
2112 | { | |
7177d104 MS |
2113 | context = type ? TYPE_CONTEXT (type) : NULL_TREE; |
2114 | if (! context && ! globalize) | |
2115 | context = current_scope (); | |
2116 | if (context) | |
2986ae00 | 2117 | c_decl = TREE_CODE (context) == FUNCTION_DECL |
e1cd6e56 | 2118 | ? context : TYPE_MAIN_DECL (context); |
8d08fdba | 2119 | |
8d08fdba | 2120 | /* Do C++ gratuitous typedefing. */ |
db5ae43f | 2121 | if (IDENTIFIER_TYPE_VALUE (name) != type) |
8d08fdba MS |
2122 | { |
2123 | register tree d; | |
2124 | int newdecl = 0; | |
2125 | ||
2126 | if (b->parm_flag != 2 | |
2127 | || TYPE_SIZE (current_class_type) != NULL_TREE) | |
2128 | { | |
2986ae00 | 2129 | d = lookup_nested_type (type, c_decl); |
8d08fdba MS |
2130 | |
2131 | if (d == NULL_TREE) | |
2132 | { | |
2133 | newdecl = 1; | |
8d08fdba | 2134 | d = build_decl (TYPE_DECL, name, type); |
00595019 | 2135 | SET_DECL_ARTIFICIAL (d); |
8d08fdba MS |
2136 | set_identifier_type_value_with_scope (name, type, b); |
2137 | } | |
2138 | else | |
d2e5ee5c | 2139 | d = TYPE_MAIN_DECL (d); |
8d08fdba | 2140 | |
e1cd6e56 | 2141 | TYPE_NAME (type) = d; |
5566b478 | 2142 | DECL_CONTEXT (d) = context; |
5156628f | 2143 | if (! globalize && processing_template_decl && IS_AGGR_TYPE (type)) |
5566b478 | 2144 | push_template_decl (d); |
e1cd6e56 | 2145 | |
faf5394a MS |
2146 | if (b->parm_flag == 2) |
2147 | d = pushdecl_class_level (d); | |
2148 | else | |
2149 | d = pushdecl_with_scope (d, b); | |
8d08fdba MS |
2150 | } |
2151 | else | |
2152 | { | |
2153 | /* Make nested declarations go into class-level scope. */ | |
2154 | newdecl = 1; | |
a0a33927 | 2155 | d = build_decl (TYPE_DECL, name, type); |
00595019 | 2156 | SET_DECL_ARTIFICIAL (d); |
d2e5ee5c | 2157 | TYPE_NAME (type) = d; |
5566b478 | 2158 | DECL_CONTEXT (d) = context; |
5156628f | 2159 | if (! globalize && processing_template_decl && IS_AGGR_TYPE (type)) |
5566b478 | 2160 | push_template_decl (d); |
e1cd6e56 | 2161 | |
8d08fdba | 2162 | d = pushdecl_class_level (d); |
8d08fdba | 2163 | } |
8ccc31eb | 2164 | if (newdecl) |
8d08fdba | 2165 | { |
d2e5ee5c MS |
2166 | if (ANON_AGGRNAME_P (name)) |
2167 | DECL_IGNORED_P (d) = 1; | |
8ccc31eb | 2168 | |
5566b478 | 2169 | TYPE_CONTEXT (type) = DECL_CONTEXT (d); |
8ccc31eb MS |
2170 | DECL_ASSEMBLER_NAME (d) |
2171 | = get_identifier (build_overload_name (type, 1, 1)); | |
8d08fdba | 2172 | } |
8d08fdba MS |
2173 | } |
2174 | if (b->parm_flag == 2) | |
2175 | { | |
2176 | TREE_NONLOCAL_FLAG (type) = 1; | |
2177 | if (TYPE_SIZE (current_class_type) == NULL_TREE) | |
2178 | CLASSTYPE_TAGS (current_class_type) = b->tags; | |
2179 | } | |
2180 | } | |
2181 | ||
2182 | if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) | |
2183 | /* Use the canonical TYPE_DECL for this node. */ | |
2184 | TYPE_STUB_DECL (type) = TYPE_NAME (type); | |
2185 | else | |
2186 | { | |
2187 | /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE | |
2188 | will be the tagged type we just added to the current | |
2189 | binding level. This fake NULL-named TYPE_DECL node helps | |
2190 | dwarfout.c to know when it needs to output a | |
2191 | representation of a tagged type, and it also gives us a | |
2192 | convenient place to record the "scope start" address for | |
2193 | the tagged type. */ | |
2194 | ||
8d08fdba | 2195 | tree d = build_decl (TYPE_DECL, NULL_TREE, type); |
8d08fdba MS |
2196 | TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b); |
2197 | } | |
2198 | } | |
2199 | ||
2200 | /* Counter used to create anonymous type names. */ | |
e92cc029 | 2201 | |
8d08fdba MS |
2202 | static int anon_cnt = 0; |
2203 | ||
2204 | /* Return an IDENTIFIER which can be used as a name for | |
2205 | anonymous structs and unions. */ | |
e92cc029 | 2206 | |
8d08fdba MS |
2207 | tree |
2208 | make_anon_name () | |
2209 | { | |
2210 | char buf[32]; | |
2211 | ||
2212 | sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++); | |
2213 | return get_identifier (buf); | |
2214 | } | |
2215 | ||
2216 | /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames. | |
2217 | This keeps dbxout from getting confused. */ | |
e92cc029 | 2218 | |
8d08fdba MS |
2219 | void |
2220 | clear_anon_tags () | |
2221 | { | |
2222 | register struct binding_level *b; | |
2223 | register tree tags; | |
2224 | static int last_cnt = 0; | |
2225 | ||
2226 | /* Fast out if no new anon names were declared. */ | |
2227 | if (last_cnt == anon_cnt) | |
2228 | return; | |
2229 | ||
2230 | b = current_binding_level; | |
2231 | while (b->tag_transparent) | |
2232 | b = b->level_chain; | |
2233 | tags = b->tags; | |
2234 | while (tags) | |
2235 | { | |
2236 | /* A NULL purpose means we have already processed all tags | |
2237 | from here to the end of the list. */ | |
2238 | if (TREE_PURPOSE (tags) == NULL_TREE) | |
2239 | break; | |
2240 | if (ANON_AGGRNAME_P (TREE_PURPOSE (tags))) | |
2241 | TREE_PURPOSE (tags) = NULL_TREE; | |
2242 | tags = TREE_CHAIN (tags); | |
2243 | } | |
2244 | last_cnt = anon_cnt; | |
2245 | } | |
2246 | \f | |
2247 | /* Subroutine of duplicate_decls: return truthvalue of whether | |
2248 | or not types of these decls match. | |
2249 | ||
2250 | For C++, we must compare the parameter list so that `int' can match | |
2251 | `int&' in a parameter position, but `int&' is not confused with | |
2252 | `const int&'. */ | |
e92cc029 | 2253 | |
6060a796 | 2254 | int |
8d08fdba MS |
2255 | decls_match (newdecl, olddecl) |
2256 | tree newdecl, olddecl; | |
2257 | { | |
2258 | int types_match; | |
2259 | ||
a28e3c7f MS |
2260 | if (TREE_CODE (newdecl) == FUNCTION_DECL |
2261 | && TREE_CODE (olddecl) == FUNCTION_DECL) | |
8d08fdba MS |
2262 | { |
2263 | tree f1 = TREE_TYPE (newdecl); | |
2264 | tree f2 = TREE_TYPE (olddecl); | |
2265 | tree p1 = TYPE_ARG_TYPES (f1); | |
2266 | tree p2 = TYPE_ARG_TYPES (f2); | |
2267 | ||
2268 | /* When we parse a static member function definition, | |
2269 | we put together a FUNCTION_DECL which thinks its type | |
2270 | is METHOD_TYPE. Change that to FUNCTION_TYPE, and | |
2271 | proceed. */ | |
2272 | if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl)) | |
700f8a87 | 2273 | revert_static_member_fn (&newdecl, &f1, &p1); |
8d08fdba MS |
2274 | else if (TREE_CODE (f2) == METHOD_TYPE |
2275 | && DECL_STATIC_FUNCTION_P (newdecl)) | |
700f8a87 | 2276 | revert_static_member_fn (&olddecl, &f2, &p2); |
8d08fdba MS |
2277 | |
2278 | /* Here we must take care of the case where new default | |
2279 | parameters are specified. Also, warn if an old | |
2280 | declaration becomes ambiguous because default | |
2281 | parameters may cause the two to be ambiguous. */ | |
2282 | if (TREE_CODE (f1) != TREE_CODE (f2)) | |
2283 | { | |
2284 | if (TREE_CODE (f1) == OFFSET_TYPE) | |
2285 | cp_compiler_error ("`%D' redeclared as member function", newdecl); | |
2286 | else | |
2287 | cp_compiler_error ("`%D' redeclared as non-member function", newdecl); | |
2288 | return 0; | |
2289 | } | |
2290 | ||
39211cd5 | 2291 | if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1)) |
8926095f | 2292 | { |
a28e3c7f | 2293 | if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c |
8926095f | 2294 | && p2 == NULL_TREE) |
a28e3c7f MS |
2295 | { |
2296 | types_match = self_promoting_args_p (p1); | |
2297 | if (p1 == void_list_node) | |
2298 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl); | |
2299 | } | |
2300 | else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c | |
2301 | && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE) | |
2302 | { | |
2303 | types_match = self_promoting_args_p (p2); | |
2304 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl); | |
2305 | } | |
8926095f | 2306 | else |
a4443a08 | 2307 | types_match = compparms (p1, p2, 3); |
8926095f | 2308 | } |
8d08fdba MS |
2309 | else |
2310 | types_match = 0; | |
2311 | } | |
51c184be MS |
2312 | else if (TREE_CODE (newdecl) == TEMPLATE_DECL |
2313 | && TREE_CODE (olddecl) == TEMPLATE_DECL) | |
2314 | { | |
2315 | tree newargs = DECL_TEMPLATE_PARMS (newdecl); | |
2316 | tree oldargs = DECL_TEMPLATE_PARMS (olddecl); | |
98c1c668 | 2317 | int i; |
51c184be | 2318 | |
98c1c668 JM |
2319 | /* Run through all the levels of template parmaters, checking |
2320 | that they match. */ | |
2321 | while (newargs && oldargs) | |
51c184be | 2322 | { |
98c1c668 JM |
2323 | int len = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS (newargs)); |
2324 | ||
2325 | if (TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS (oldargs)) != len) | |
51c184be | 2326 | return 0; |
98c1c668 JM |
2327 | |
2328 | for (i = 0; i < len; i++) | |
2329 | { | |
2330 | tree newarg = | |
2331 | TREE_VALUE (TREE_VEC_ELT | |
2332 | (INNERMOST_TEMPLATE_PARMS (newargs), i)); | |
2333 | tree oldarg = | |
2334 | TREE_VALUE (TREE_VEC_ELT | |
2335 | (INNERMOST_TEMPLATE_PARMS (oldargs), i)); | |
2336 | if (TREE_CODE (newarg) != TREE_CODE (oldarg)) | |
2337 | return 0; | |
2338 | else if (TREE_CODE (newarg) == TYPE_DECL) | |
2339 | /* continue */; | |
2340 | else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1)) | |
2341 | return 0; | |
2342 | } | |
2343 | newargs = TREE_CHAIN (newargs); | |
2344 | oldargs = TREE_CHAIN (oldargs); | |
51c184be MS |
2345 | } |
2346 | ||
98c1c668 JM |
2347 | if ((newargs == NULL_TREE) != (oldargs == NULL_TREE)) |
2348 | /* One declaration has more levels that the other. */ | |
2349 | return 0; | |
2350 | ||
5566b478 | 2351 | if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) |
51c184be MS |
2352 | types_match = 1; |
2353 | else | |
2354 | types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl), | |
2355 | DECL_TEMPLATE_RESULT (newdecl)); | |
2356 | } | |
8d08fdba MS |
2357 | else |
2358 | { | |
2359 | if (TREE_TYPE (newdecl) == error_mark_node) | |
2360 | types_match = TREE_TYPE (olddecl) == error_mark_node; | |
2361 | else if (TREE_TYPE (olddecl) == NULL_TREE) | |
2362 | types_match = TREE_TYPE (newdecl) == NULL_TREE; | |
a0a33927 MS |
2363 | else if (TREE_TYPE (newdecl) == NULL_TREE) |
2364 | types_match = 0; | |
72b7eeff MS |
2365 | /* Qualifiers must match, and they may be present on either, the type |
2366 | or the decl. */ | |
2367 | else if ((TREE_READONLY (newdecl) | |
2368 | || TYPE_READONLY (TREE_TYPE (newdecl))) | |
2369 | == (TREE_READONLY (olddecl) | |
2370 | || TYPE_READONLY (TREE_TYPE (olddecl))) | |
2371 | && (TREE_THIS_VOLATILE (newdecl) | |
2372 | || TYPE_VOLATILE (TREE_TYPE (newdecl))) | |
2373 | == (TREE_THIS_VOLATILE (olddecl) | |
2374 | || TYPE_VOLATILE (TREE_TYPE (olddecl)))) | |
2375 | types_match = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (newdecl)), | |
2376 | TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)), 1); | |
8d08fdba | 2377 | else |
72b7eeff | 2378 | types_match = 0; |
8d08fdba MS |
2379 | } |
2380 | ||
2381 | return types_match; | |
2382 | } | |
2383 | ||
2384 | /* If NEWDECL is `static' and an `extern' was seen previously, | |
2385 | warn about it. (OLDDECL may be NULL_TREE; NAME contains | |
2386 | information about previous usage as an `extern'.) | |
2387 | ||
2388 | Note that this does not apply to the C++ case of declaring | |
2389 | a variable `extern const' and then later `const'. | |
2390 | ||
8d08fdba MS |
2391 | Don't complain about built-in functions, since they are beyond |
2392 | the user's control. */ | |
2393 | ||
2394 | static void | |
2395 | warn_extern_redeclared_static (newdecl, olddecl) | |
2396 | tree newdecl, olddecl; | |
2397 | { | |
2398 | tree name; | |
2399 | ||
2400 | static char *explicit_extern_static_warning | |
2401 | = "`%D' was declared `extern' and later `static'"; | |
2402 | static char *implicit_extern_static_warning | |
2403 | = "`%D' was declared implicitly `extern' and later `static'"; | |
2404 | ||
d22c8596 | 2405 | if (TREE_CODE (newdecl) == TYPE_DECL) |
8d08fdba MS |
2406 | return; |
2407 | ||
2408 | name = DECL_ASSEMBLER_NAME (newdecl); | |
faae18ab | 2409 | if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl)) |
8d08fdba MS |
2410 | { |
2411 | /* It's okay to redeclare an ANSI built-in function as static, | |
2412 | or to declare a non-ANSI built-in function as anything. */ | |
2413 | if (! (TREE_CODE (newdecl) == FUNCTION_DECL | |
2414 | && olddecl != NULL_TREE | |
2415 | && TREE_CODE (olddecl) == FUNCTION_DECL | |
2416 | && (DECL_BUILT_IN (olddecl) | |
2417 | || DECL_BUILT_IN_NONANSI (olddecl)))) | |
2418 | { | |
a9aedbc2 | 2419 | cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name) |
8d08fdba MS |
2420 | ? implicit_extern_static_warning |
2421 | : explicit_extern_static_warning, newdecl); | |
2422 | if (olddecl != NULL_TREE) | |
a9aedbc2 | 2423 | cp_pedwarn_at ("previous declaration of `%D'", olddecl); |
8d08fdba MS |
2424 | } |
2425 | } | |
2426 | } | |
2427 | ||
2428 | /* Handle when a new declaration NEWDECL has the same name as an old | |
2429 | one OLDDECL in the same binding contour. Prints an error message | |
2430 | if appropriate. | |
2431 | ||
2432 | If safely possible, alter OLDDECL to look like NEWDECL, and return 1. | |
2433 | Otherwise, return 0. */ | |
2434 | ||
51c184be | 2435 | int |
8d08fdba | 2436 | duplicate_decls (newdecl, olddecl) |
824b9a4c | 2437 | tree newdecl, olddecl; |
8d08fdba MS |
2438 | { |
2439 | extern struct obstack permanent_obstack; | |
2440 | unsigned olddecl_uid = DECL_UID (olddecl); | |
2441 | int olddecl_friend = 0, types_match = 0; | |
2442 | int new_defines_function; | |
5566b478 MS |
2443 | |
2444 | if (newdecl == olddecl) | |
2445 | return 1; | |
8d08fdba | 2446 | |
f6abb50a BK |
2447 | if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd') |
2448 | DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl); | |
2449 | ||
8926095f | 2450 | types_match = decls_match (newdecl, olddecl); |
8d08fdba MS |
2451 | |
2452 | if (TREE_CODE (olddecl) != TREE_LIST) | |
2453 | olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl); | |
2454 | ||
2455 | /* If either the type of the new decl or the type of the old decl is an | |
2456 | error_mark_node, then that implies that we have already issued an | |
2457 | error (earlier) for some bogus type specification, and in that case, | |
2458 | it is rather pointless to harass the user with yet more error message | |
2459 | about the same declaration, so well just pretent the types match here. */ | |
bd6dd845 MS |
2460 | if (TREE_TYPE (newdecl) == error_mark_node |
2461 | || TREE_TYPE (olddecl) == error_mark_node) | |
8d08fdba MS |
2462 | types_match = 1; |
2463 | ||
d22c8596 MS |
2464 | if (TREE_CODE (olddecl) == FUNCTION_DECL |
2465 | && DECL_ARTIFICIAL (olddecl) | |
2466 | && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl))) | |
8d08fdba MS |
2467 | { |
2468 | /* If you declare a built-in or predefined function name as static, | |
a4443a08 MS |
2469 | the old definition is overridden, but optionally warn this was a |
2470 | bad choice of name. Ditto for overloads. */ | |
893de33c | 2471 | if (! TREE_PUBLIC (newdecl) |
a4443a08 MS |
2472 | || (TREE_CODE (newdecl) == FUNCTION_DECL |
2473 | && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))) | |
2474 | { | |
2475 | if (warn_shadow) | |
2476 | cp_warning ("shadowing %s function `%#D'", | |
2477 | DECL_BUILT_IN (olddecl) ? "built-in" : "library", | |
2478 | olddecl); | |
2479 | /* Discard the old built-in function. */ | |
2480 | return 0; | |
2481 | } | |
2482 | else if (! types_match) | |
8d08fdba | 2483 | { |
a4443a08 MS |
2484 | if (TREE_CODE (newdecl) != FUNCTION_DECL) |
2485 | { | |
2486 | /* If the built-in is not ansi, then programs can override | |
2487 | it even globally without an error. */ | |
2488 | if (! DECL_BUILT_IN (olddecl)) | |
2489 | cp_warning ("library function `%#D' redeclared as non-function `%#D'", | |
2490 | olddecl, newdecl); | |
2491 | else | |
2492 | { | |
2493 | cp_error ("declaration of `%#D'", newdecl); | |
2494 | cp_error ("conflicts with built-in declaration `%#D'", | |
2495 | olddecl); | |
2496 | } | |
2497 | return 0; | |
2498 | } | |
2499 | ||
8d08fdba MS |
2500 | cp_warning ("declaration of `%#D'", newdecl); |
2501 | cp_warning ("conflicts with built-in declaration `%#D'", | |
2502 | olddecl); | |
8d08fdba | 2503 | } |
39211cd5 MS |
2504 | } |
2505 | else if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) | |
2506 | { | |
2507 | if ((TREE_CODE (newdecl) == FUNCTION_DECL | |
5566b478 | 2508 | && DECL_FUNCTION_TEMPLATE_P (olddecl)) |
39211cd5 | 2509 | || (TREE_CODE (olddecl) == FUNCTION_DECL |
5566b478 | 2510 | && DECL_FUNCTION_TEMPLATE_P (newdecl))) |
39211cd5 MS |
2511 | return 0; |
2512 | ||
2513 | cp_error ("`%#D' redeclared as different kind of symbol", newdecl); | |
2514 | if (TREE_CODE (olddecl) == TREE_LIST) | |
2515 | olddecl = TREE_VALUE (olddecl); | |
2516 | cp_error_at ("previous declaration of `%#D'", olddecl); | |
2517 | ||
2518 | /* New decl is completely inconsistent with the old one => | |
2519 | tell caller to replace the old one. */ | |
2520 | ||
2521 | return 0; | |
8d08fdba | 2522 | } |
8d08fdba MS |
2523 | else if (!types_match) |
2524 | { | |
8926095f | 2525 | if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
f0e01782 MS |
2526 | { |
2527 | /* The name of a class template may not be declared to refer to | |
2528 | any other template, class, function, object, namespace, value, | |
e92cc029 | 2529 | or type in the same scope. */ |
5566b478 MS |
2530 | if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL |
2531 | || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) | |
f0e01782 MS |
2532 | { |
2533 | cp_error ("declaration of template `%#D'", newdecl); | |
2534 | cp_error_at ("conflicts with previous declaration `%#D'", | |
2535 | olddecl); | |
2536 | } | |
ec255269 MS |
2537 | else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL |
2538 | && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL | |
2539 | && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))), | |
2540 | TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))), 3)) | |
2541 | { | |
2542 | cp_error ("new declaration `%#D'", newdecl); | |
2543 | cp_error_at ("ambiguates old declaration `%#D'", olddecl); | |
2544 | } | |
f0e01782 MS |
2545 | return 0; |
2546 | } | |
8926095f MS |
2547 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
2548 | { | |
2549 | if (DECL_LANGUAGE (newdecl) == lang_c | |
2550 | && DECL_LANGUAGE (olddecl) == lang_c) | |
2551 | { | |
2552 | cp_error ("declaration of C function `%#D' conflicts with", | |
2553 | newdecl); | |
2554 | cp_error_at ("previous declaration `%#D' here", olddecl); | |
2555 | } | |
00595019 | 2556 | else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)), |
28cbf42c | 2557 | TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3)) |
700f8a87 MS |
2558 | { |
2559 | cp_error ("new declaration `%#D'", newdecl); | |
2560 | cp_error_at ("ambiguates old declaration `%#D'", olddecl); | |
2561 | } | |
2562 | else | |
2563 | return 0; | |
8926095f | 2564 | } |
8d08fdba MS |
2565 | |
2566 | /* Already complained about this, so don't do so again. */ | |
a4443a08 | 2567 | else if (current_class_type == NULL_TREE |
8d08fdba MS |
2568 | || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) |
2569 | { | |
f376e137 | 2570 | cp_error ("conflicting types for `%#D'", newdecl); |
8926095f | 2571 | cp_error_at ("previous declaration as `%#D'", olddecl); |
8d08fdba MS |
2572 | } |
2573 | } | |
386b8a85 JM |
2574 | else if ((TREE_CODE (olddecl) == FUNCTION_DECL |
2575 | && DECL_TEMPLATE_SPECIALIZATION (olddecl) | |
2576 | && (!DECL_TEMPLATE_SPECIALIZATION (newdecl) | |
2577 | || (DECL_TI_TEMPLATE (newdecl) | |
2578 | != DECL_TI_TEMPLATE (olddecl)))) | |
2579 | || (TREE_CODE (newdecl) == FUNCTION_DECL | |
2580 | && DECL_TEMPLATE_SPECIALIZATION (newdecl) | |
2581 | && (!DECL_TEMPLATE_SPECIALIZATION (olddecl) | |
2582 | || (DECL_TI_TEMPLATE (olddecl) != DECL_TI_TEMPLATE | |
2583 | (newdecl))))) | |
2584 | /* It's OK to have a template specialization and a non-template | |
2585 | with the same type, or to have specializations of two | |
2586 | different templates with the same type. */ | |
2587 | return 0; | |
8d08fdba MS |
2588 | else |
2589 | { | |
2590 | char *errmsg = redeclaration_error_message (newdecl, olddecl); | |
2591 | if (errmsg) | |
2592 | { | |
51c184be | 2593 | cp_error (errmsg, newdecl); |
8d08fdba MS |
2594 | if (DECL_NAME (olddecl) != NULL_TREE) |
2595 | cp_error_at ((DECL_INITIAL (olddecl) | |
2596 | && current_binding_level == global_binding_level) | |
2597 | ? "`%#D' previously defined here" | |
2598 | : "`%#D' previously declared here", olddecl); | |
2599 | } | |
2600 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
2601 | && DECL_INITIAL (olddecl) != NULL_TREE | |
2602 | && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE | |
2603 | && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE) | |
2604 | { | |
2605 | /* Prototype decl follows defn w/o prototype. */ | |
2606 | cp_warning_at ("prototype for `%#D'", newdecl); | |
2607 | cp_warning_at ("follows non-prototype definition here", olddecl); | |
2608 | } | |
2609 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
2610 | && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)) | |
8926095f MS |
2611 | { |
2612 | /* extern "C" int foo (); | |
2613 | int foo () { bar (); } | |
2614 | is OK. */ | |
2615 | if (current_lang_stack == current_lang_base) | |
a28e3c7f | 2616 | DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); |
8926095f MS |
2617 | else |
2618 | { | |
2619 | cp_error_at ("previous declaration of `%#D' with %L linkage", | |
2620 | olddecl, DECL_LANGUAGE (olddecl)); | |
2621 | cp_error ("conflicts with new declaration with %L linkage", | |
2622 | DECL_LANGUAGE (newdecl)); | |
2623 | } | |
2624 | } | |
e1cd6e56 | 2625 | |
a6f02587 | 2626 | if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl)) |
c32381b1 JM |
2627 | ; |
2628 | else if (TREE_CODE (olddecl) == FUNCTION_DECL) | |
e1cd6e56 MS |
2629 | { |
2630 | tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl)); | |
2631 | tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)); | |
2632 | int i = 1; | |
2633 | ||
2634 | if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) | |
2635 | t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); | |
2636 | ||
2637 | for (; t1 && t1 != void_list_node; | |
2638 | t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) | |
2639 | if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) | |
2640 | { | |
2507f3b5 RK |
2641 | if (1 == simple_cst_equal (TREE_PURPOSE (t1), |
2642 | TREE_PURPOSE (t2))) | |
e1cd6e56 MS |
2643 | { |
2644 | if (pedantic) | |
2645 | { | |
2646 | cp_pedwarn ("default argument given for parameter %d of `%#D'", | |
2647 | i, newdecl); | |
2648 | cp_pedwarn_at ("after previous specification in `%#D'", | |
2649 | olddecl); | |
2650 | } | |
2651 | } | |
2652 | else | |
2653 | { | |
2654 | cp_error ("default argument given for parameter %d of `%#D'", | |
2655 | i, newdecl); | |
da20811c | 2656 | cp_error_at ("after previous specification in `%#D'", |
e1cd6e56 MS |
2657 | olddecl); |
2658 | } | |
2659 | } | |
a5894242 | 2660 | |
7fcdf4c2 MS |
2661 | if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl) |
2662 | && TREE_ADDRESSABLE (olddecl) && warn_inline) | |
dff6b454 | 2663 | { |
7fcdf4c2 MS |
2664 | cp_warning ("`%#D' was used before it was declared inline", |
2665 | newdecl); | |
2666 | cp_warning_at ("previous non-inline declaration here", | |
2667 | olddecl); | |
dff6b454 | 2668 | } |
e1cd6e56 | 2669 | } |
8ccc31eb MS |
2670 | /* These bits are logically part of the type for non-functions. */ |
2671 | else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) | |
2672 | || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)) | |
2673 | { | |
2674 | cp_pedwarn ("type qualifiers for `%#D'", newdecl); | |
2675 | cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl); | |
2676 | } | |
8d08fdba MS |
2677 | } |
2678 | ||
2679 | /* If new decl is `static' and an `extern' was seen previously, | |
2680 | warn about it. */ | |
2681 | warn_extern_redeclared_static (newdecl, olddecl); | |
2682 | ||
e92cc029 | 2683 | /* We have committed to returning 1 at this point. */ |
8d08fdba MS |
2684 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
2685 | { | |
2686 | /* Now that functions must hold information normally held | |
2687 | by field decls, there is extra work to do so that | |
2688 | declaration information does not get destroyed during | |
2689 | definition. */ | |
2690 | if (DECL_VINDEX (olddecl)) | |
2691 | DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl); | |
2692 | if (DECL_CONTEXT (olddecl)) | |
2693 | DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); | |
2694 | if (DECL_CLASS_CONTEXT (olddecl)) | |
2695 | DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); | |
2696 | if (DECL_CHAIN (newdecl) == NULL_TREE) | |
2697 | DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); | |
2698 | if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) | |
2699 | DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); | |
e1cd6e56 MS |
2700 | DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl); |
2701 | DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); | |
7215f9a0 | 2702 | DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl); |
8d08fdba MS |
2703 | } |
2704 | ||
2705 | /* Deal with C++: must preserve virtual function table size. */ | |
2706 | if (TREE_CODE (olddecl) == TYPE_DECL) | |
2707 | { | |
2708 | register tree newtype = TREE_TYPE (newdecl); | |
2709 | register tree oldtype = TREE_TYPE (olddecl); | |
2710 | ||
2711 | if (newtype != error_mark_node && oldtype != error_mark_node | |
2712 | && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype)) | |
2713 | { | |
2714 | CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype); | |
2715 | CLASSTYPE_FRIEND_CLASSES (newtype) | |
2716 | = CLASSTYPE_FRIEND_CLASSES (oldtype); | |
2717 | } | |
8d08fdba MS |
2718 | } |
2719 | ||
2720 | /* Special handling ensues if new decl is a function definition. */ | |
2721 | new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL | |
2722 | && DECL_INITIAL (newdecl) != NULL_TREE); | |
2723 | ||
2724 | /* Optionally warn about more than one declaration for the same name, | |
2725 | but don't warn about a function declaration followed by a definition. */ | |
2726 | if (warn_redundant_decls | |
700f8a87 | 2727 | && ! DECL_ARTIFICIAL (olddecl) |
8d08fdba MS |
2728 | && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE) |
2729 | /* Don't warn about extern decl followed by (tentative) definition. */ | |
2730 | && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) | |
2731 | { | |
2732 | cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); | |
44a8d0b3 | 2733 | cp_warning_at ("previous declaration of `%D'", olddecl); |
8d08fdba MS |
2734 | } |
2735 | ||
2736 | /* Copy all the DECL_... slots specified in the new decl | |
2737 | except for any that we copy here from the old type. */ | |
2738 | ||
5566b478 MS |
2739 | if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
2740 | { | |
37dac039 JM |
2741 | if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE) |
2742 | { | |
2743 | TREE_TYPE (olddecl) = TREE_TYPE (newdecl); | |
2744 | DECL_TEMPLATE_RESULT (olddecl) = DECL_TEMPLATE_RESULT (newdecl); | |
2745 | DECL_TEMPLATE_PARMS (olddecl) = DECL_TEMPLATE_PARMS (newdecl); | |
2746 | } | |
5566b478 MS |
2747 | return 1; |
2748 | } | |
2749 | ||
8d08fdba MS |
2750 | if (types_match) |
2751 | { | |
2752 | /* Automatically handles default parameters. */ | |
2753 | tree oldtype = TREE_TYPE (olddecl); | |
e1cd6e56 | 2754 | tree newtype; |
8d08fdba | 2755 | |
e1cd6e56 MS |
2756 | /* Make sure we put the new type in the same obstack as the old one. */ |
2757 | if (oldtype) | |
39211cd5 MS |
2758 | push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); |
2759 | else | |
2760 | { | |
2761 | push_obstacks_nochange (); | |
2762 | end_temporary_allocation (); | |
2763 | } | |
2764 | ||
e1cd6e56 MS |
2765 | /* Merge the data types specified in the two decls. */ |
2766 | newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); | |
2767 | ||
8d08fdba MS |
2768 | if (TREE_CODE (newdecl) == VAR_DECL) |
2769 | DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl); | |
2770 | /* Do this after calling `common_type' so that default | |
2771 | parameters don't confuse us. */ | |
2772 | else if (TREE_CODE (newdecl) == FUNCTION_DECL | |
2773 | && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)) | |
2774 | != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)))) | |
2775 | { | |
f30432d7 | 2776 | TREE_TYPE (newdecl) = build_exception_variant (newtype, |
8d08fdba | 2777 | TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); |
f30432d7 | 2778 | TREE_TYPE (olddecl) = build_exception_variant (newtype, |
8d08fdba MS |
2779 | TYPE_RAISES_EXCEPTIONS (oldtype)); |
2780 | ||
824b9a4c | 2781 | if ((pedantic || ! DECL_IN_SYSTEM_HEADER (olddecl)) |
da20811c | 2782 | && flag_exceptions |
824b9a4c | 2783 | && ! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl))) |
8d08fdba | 2784 | { |
824b9a4c | 2785 | cp_pedwarn ("declaration of `%D' throws different exceptions", |
a28e3c7f | 2786 | newdecl); |
824b9a4c | 2787 | cp_pedwarn_at ("previous declaration here", olddecl); |
8d08fdba MS |
2788 | } |
2789 | } | |
2790 | TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; | |
2791 | ||
2792 | /* Lay the type out, unless already done. */ | |
b7484fbe | 2793 | if (oldtype != TREE_TYPE (newdecl) |
5566b478 | 2794 | && TREE_TYPE (newdecl) != error_mark_node |
5156628f | 2795 | && !(processing_template_decl && uses_template_parms (newdecl))) |
b7484fbe MS |
2796 | layout_type (TREE_TYPE (newdecl)); |
2797 | ||
5566b478 MS |
2798 | if ((TREE_CODE (newdecl) == VAR_DECL |
2799 | || TREE_CODE (newdecl) == PARM_DECL | |
2800 | || TREE_CODE (newdecl) == RESULT_DECL | |
2801 | || TREE_CODE (newdecl) == FIELD_DECL | |
2802 | || TREE_CODE (newdecl) == TYPE_DECL) | |
5156628f | 2803 | && !(processing_template_decl && uses_template_parms (newdecl))) |
b7484fbe | 2804 | layout_decl (newdecl, 0); |
8d08fdba MS |
2805 | |
2806 | /* Merge the type qualifiers. */ | |
2807 | if (TREE_READONLY (newdecl)) | |
2808 | TREE_READONLY (olddecl) = 1; | |
2809 | if (TREE_THIS_VOLATILE (newdecl)) | |
2810 | TREE_THIS_VOLATILE (olddecl) = 1; | |
2811 | ||
2812 | /* Merge the initialization information. */ | |
8926095f MS |
2813 | if (DECL_INITIAL (newdecl) == NULL_TREE |
2814 | && DECL_INITIAL (olddecl) != NULL_TREE) | |
2815 | { | |
2816 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
2817 | DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); | |
2818 | DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); | |
2819 | } | |
39211cd5 MS |
2820 | |
2821 | /* Merge the section attribute. | |
2822 | We want to issue an error if the sections conflict but that must be | |
2823 | done later in decl_attributes since we are called before attributes | |
2824 | are assigned. */ | |
2825 | if (DECL_SECTION_NAME (newdecl) == NULL_TREE) | |
2826 | DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); | |
2827 | ||
8d08fdba MS |
2828 | /* Keep the old rtl since we can safely use it, unless it's the |
2829 | call to abort() used for abstract virtuals. */ | |
2830 | if ((DECL_LANG_SPECIFIC (olddecl) | |
2831 | && !DECL_ABSTRACT_VIRTUAL_P (olddecl)) | |
2832 | || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl)) | |
2833 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
39211cd5 MS |
2834 | |
2835 | pop_obstacks (); | |
8d08fdba MS |
2836 | } |
2837 | /* If cannot merge, then use the new type and qualifiers, | |
2838 | and don't preserve the old rtl. */ | |
2839 | else | |
2840 | { | |
2841 | /* Clean out any memory we had of the old declaration. */ | |
2842 | tree oldstatic = value_member (olddecl, static_aggregates); | |
2843 | if (oldstatic) | |
2844 | TREE_VALUE (oldstatic) = error_mark_node; | |
2845 | ||
2846 | TREE_TYPE (olddecl) = TREE_TYPE (newdecl); | |
2847 | TREE_READONLY (olddecl) = TREE_READONLY (newdecl); | |
2848 | TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); | |
2849 | TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); | |
2850 | } | |
2851 | ||
2852 | /* Merge the storage class information. */ | |
a9aedbc2 | 2853 | DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); |
e92cc029 | 2854 | DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl); |
a9aedbc2 MS |
2855 | TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); |
2856 | TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl); | |
2857 | if (! DECL_EXTERNAL (olddecl)) | |
2858 | DECL_EXTERNAL (newdecl) = 0; | |
8d08fdba | 2859 | |
5566b478 | 2860 | if (DECL_LANG_SPECIFIC (newdecl)) |
8d08fdba | 2861 | { |
a9aedbc2 MS |
2862 | DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl); |
2863 | DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl); | |
8d08fdba MS |
2864 | } |
2865 | ||
8d08fdba MS |
2866 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
2867 | { | |
faae18ab MS |
2868 | DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl); |
2869 | ||
2870 | /* If either decl says `inline', this fn is inline, unless its | |
2871 | definition was passed already. */ | |
2872 | if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE) | |
2873 | DECL_INLINE (olddecl) = 1; | |
2874 | DECL_INLINE (newdecl) = DECL_INLINE (olddecl); | |
2875 | ||
700f8a87 MS |
2876 | if (! types_match) |
2877 | { | |
2878 | DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl); | |
2879 | DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl); | |
5566b478 MS |
2880 | DECL_RTL (olddecl) = DECL_RTL (newdecl); |
2881 | } | |
2882 | if (! types_match || new_defines_function) | |
2883 | { | |
2884 | /* These need to be copied so that the names are available. */ | |
700f8a87 MS |
2885 | DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl); |
2886 | DECL_RESULT (olddecl) = DECL_RESULT (newdecl); | |
700f8a87 | 2887 | } |
8d08fdba MS |
2888 | if (new_defines_function) |
2889 | /* If defining a function declared with other language | |
2890 | linkage, use the previously declared language linkage. */ | |
2891 | DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); | |
2892 | else | |
2893 | { | |
2894 | /* If redeclaring a builtin function, and not a definition, | |
2895 | it stays built in. */ | |
2896 | if (DECL_BUILT_IN (olddecl)) | |
2897 | { | |
2898 | DECL_BUILT_IN (newdecl) = 1; | |
39211cd5 | 2899 | DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); |
8d08fdba MS |
2900 | /* If we're keeping the built-in definition, keep the rtl, |
2901 | regardless of declaration matches. */ | |
2902 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
2903 | } | |
2904 | else | |
2905 | DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); | |
2906 | ||
2907 | DECL_RESULT (newdecl) = DECL_RESULT (olddecl); | |
8926095f | 2908 | if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))) |
8d08fdba MS |
2909 | /* Previously saved insns go together with |
2910 | the function's previous definition. */ | |
2911 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
2912 | /* Don't clear out the arguments if we're redefining a function. */ | |
2913 | if (DECL_ARGUMENTS (olddecl)) | |
2914 | DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); | |
2915 | } | |
6060a796 MS |
2916 | if (DECL_LANG_SPECIFIC (olddecl)) |
2917 | DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl); | |
8d08fdba MS |
2918 | } |
2919 | ||
a9aedbc2 MS |
2920 | if (TREE_CODE (newdecl) == NAMESPACE_DECL) |
2921 | { | |
2922 | NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl); | |
2923 | } | |
2924 | ||
8926095f MS |
2925 | if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
2926 | { | |
8926095f MS |
2927 | DECL_TEMPLATE_INSTANTIATIONS (newdecl) |
2928 | = DECL_TEMPLATE_INSTANTIATIONS (olddecl); | |
f376e137 MS |
2929 | if (DECL_CHAIN (newdecl) == NULL_TREE) |
2930 | DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); | |
8926095f | 2931 | } |
5566b478 | 2932 | |
8d08fdba MS |
2933 | /* Now preserve various other info from the definition. */ |
2934 | TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); | |
2935 | TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); | |
2936 | DECL_COMMON (newdecl) = DECL_COMMON (olddecl); | |
f376e137 | 2937 | DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl); |
8d08fdba MS |
2938 | |
2939 | /* Don't really know how much of the language-specific | |
2940 | values we should copy from old to new. */ | |
2941 | if (DECL_LANG_SPECIFIC (olddecl)) | |
2942 | { | |
2943 | DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); | |
2944 | DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); | |
db5ae43f | 2945 | DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); |
5566b478 MS |
2946 | if (DECL_TEMPLATE_INFO (newdecl) == NULL_TREE) |
2947 | { | |
2948 | DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); | |
2949 | DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl); | |
2950 | } | |
8d08fdba MS |
2951 | } |
2952 | ||
2953 | if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
2954 | { | |
2955 | int function_size; | |
2956 | struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl); | |
2957 | struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl); | |
2958 | ||
2959 | function_size = sizeof (struct tree_decl); | |
2960 | ||
2961 | bcopy ((char *) newdecl + sizeof (struct tree_common), | |
2962 | (char *) olddecl + sizeof (struct tree_common), | |
2963 | function_size - sizeof (struct tree_common)); | |
2964 | ||
2965 | /* Can we safely free the storage used by newdecl? */ | |
2966 | ||
2967 | #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \ | |
2968 | & ~ obstack_alignment_mask (&permanent_obstack)) | |
2969 | ||
2970 | if ((char *)newdecl + ROUND (function_size) | |
2971 | + ROUND (sizeof (struct lang_decl)) | |
2972 | == obstack_next_free (&permanent_obstack)) | |
2973 | { | |
2974 | DECL_MAIN_VARIANT (newdecl) = olddecl; | |
2975 | DECL_LANG_SPECIFIC (olddecl) = ol; | |
2976 | bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl)); | |
2977 | ||
2978 | obstack_free (&permanent_obstack, newdecl); | |
2979 | } | |
d22c8596 | 2980 | else if (LANG_DECL_PERMANENT (ol) && ol != nl) |
8d08fdba MS |
2981 | { |
2982 | if (DECL_MAIN_VARIANT (olddecl) == olddecl) | |
2983 | { | |
2984 | /* Save these lang_decls that would otherwise be lost. */ | |
2985 | extern tree free_lang_decl_chain; | |
2986 | tree free_lang_decl = (tree) ol; | |
d22c8596 MS |
2987 | |
2988 | if (DECL_LANG_SPECIFIC (olddecl) == ol) | |
2989 | abort (); | |
2990 | ||
8d08fdba MS |
2991 | TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; |
2992 | free_lang_decl_chain = free_lang_decl; | |
2993 | } | |
2994 | else | |
2995 | { | |
bd6dd845 | 2996 | /* Storage leak. */; |
8d08fdba MS |
2997 | } |
2998 | } | |
2999 | } | |
3000 | else | |
3001 | { | |
3002 | bcopy ((char *) newdecl + sizeof (struct tree_common), | |
3003 | (char *) olddecl + sizeof (struct tree_common), | |
3004 | sizeof (struct tree_decl) - sizeof (struct tree_common) | |
3005 | + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); | |
3006 | } | |
3007 | ||
3008 | DECL_UID (olddecl) = olddecl_uid; | |
3009 | if (olddecl_friend) | |
3010 | DECL_FRIEND_P (olddecl) = 1; | |
3011 | ||
3012 | return 1; | |
3013 | } | |
3014 | ||
3015 | /* Record a decl-node X as belonging to the current lexical scope. | |
3016 | Check for errors (such as an incompatible declaration for the same | |
3017 | name already seen in the same scope). | |
3018 | ||
3019 | Returns either X or an old decl for the same name. | |
3020 | If an old decl is returned, it may have been smashed | |
3021 | to agree with what X says. */ | |
3022 | ||
3023 | tree | |
3024 | pushdecl (x) | |
3025 | tree x; | |
3026 | { | |
3027 | register tree t; | |
8d08fdba | 3028 | register tree name = DECL_ASSEMBLER_NAME (x); |
8d08fdba MS |
3029 | register struct binding_level *b = current_binding_level; |
3030 | ||
8d08fdba | 3031 | if (x != current_function_decl |
700f8a87 MS |
3032 | /* Don't change DECL_CONTEXT of virtual methods. */ |
3033 | && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x)) | |
8d08fdba MS |
3034 | && ! DECL_CONTEXT (x)) |
3035 | DECL_CONTEXT (x) = current_function_decl; | |
3036 | /* A local declaration for a function doesn't constitute nesting. */ | |
3037 | if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0) | |
3038 | DECL_CONTEXT (x) = 0; | |
3039 | ||
8d08fdba | 3040 | /* Type are looked up using the DECL_NAME, as that is what the rest of the |
e92cc029 | 3041 | compiler wants to use. */ |
a9aedbc2 | 3042 | if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL |
98c1c668 | 3043 | || TREE_CODE (x) == NAMESPACE_DECL || TREE_CODE (x) == TEMPLATE_TYPE_PARM) |
8d08fdba | 3044 | name = DECL_NAME (x); |
8d08fdba MS |
3045 | |
3046 | if (name) | |
3047 | { | |
5566b478 MS |
3048 | #if 0 |
3049 | /* Not needed...see below. */ | |
8d08fdba MS |
3050 | char *file; |
3051 | int line; | |
5566b478 | 3052 | #endif |
386b8a85 JM |
3053 | if (TREE_CODE (name) == TEMPLATE_ID_EXPR) |
3054 | name = TREE_OPERAND (name, 0); | |
3055 | ||
700f8a87 | 3056 | t = lookup_name_current_level (name); |
8d08fdba MS |
3057 | if (t == error_mark_node) |
3058 | { | |
3059 | /* error_mark_node is 0 for a while during initialization! */ | |
3060 | t = NULL_TREE; | |
3061 | cp_error_at ("`%#D' used prior to declaration", x); | |
3062 | } | |
3063 | ||
51c184be | 3064 | else if (t != NULL_TREE) |
8d08fdba | 3065 | { |
5566b478 MS |
3066 | #if 0 |
3067 | /* This is turned off until I have time to do it right (bpk). */ | |
e92cc029 | 3068 | /* With the code below that uses it... */ |
8d6e462b PB |
3069 | file = DECL_SOURCE_FILE (t); |
3070 | line = DECL_SOURCE_LINE (t); | |
5566b478 | 3071 | #endif |
2ee887f2 | 3072 | if (TREE_CODE (t) == PARM_DECL) |
8d08fdba MS |
3073 | { |
3074 | if (DECL_CONTEXT (t) == NULL_TREE) | |
3075 | fatal ("parse errors have confused me too much"); | |
be99da77 | 3076 | |
e92cc029 | 3077 | /* Check for duplicate params. */ |
be99da77 MS |
3078 | if (duplicate_decls (x, t)) |
3079 | return t; | |
8d08fdba | 3080 | } |
8d6e462b | 3081 | else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c) |
5566b478 MS |
3082 | || DECL_FUNCTION_TEMPLATE_P (x)) |
3083 | && is_overloaded_fn (t)) | |
8926095f | 3084 | /* don't do anything just yet */; |
e1cd6e56 MS |
3085 | else if (t == wchar_decl_node) |
3086 | { | |
3087 | if (pedantic && ! DECL_IN_SYSTEM_HEADER (x)) | |
3088 | cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x)); | |
3089 | ||
3090 | /* Throw away the redeclaration. */ | |
3091 | return t; | |
3092 | } | |
8926095f | 3093 | else if (TREE_CODE (t) != TREE_CODE (x)) |
8d08fdba | 3094 | { |
ec255269 MS |
3095 | if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t) |
3096 | && TREE_CODE (x) != TYPE_DECL | |
3097 | && ! (TREE_CODE (x) == TEMPLATE_DECL | |
3098 | && TREE_CODE (DECL_TEMPLATE_RESULT (x)) == TYPE_DECL)) | |
3099 | || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) | |
3100 | && TREE_CODE (t) != TYPE_DECL | |
3101 | && ! (TREE_CODE (t) == TEMPLATE_DECL | |
3102 | && (TREE_CODE (DECL_TEMPLATE_RESULT (t)) | |
3103 | == TYPE_DECL)))) | |
51c184be MS |
3104 | { |
3105 | /* We do nothing special here, because C++ does such nasty | |
3106 | things with TYPE_DECLs. Instead, just let the TYPE_DECL | |
3107 | get shadowed, and know that if we need to find a TYPE_DECL | |
3108 | for a given name, we can look in the IDENTIFIER_TYPE_VALUE | |
3109 | slot of the identifier. */ | |
3110 | ; | |
3111 | } | |
3112 | else if (duplicate_decls (x, t)) | |
3113 | return t; | |
8d08fdba MS |
3114 | } |
3115 | else if (duplicate_decls (x, t)) | |
51c184be | 3116 | { |
8d08fdba | 3117 | #if 0 |
8926095f | 3118 | /* This is turned off until I have time to do it right (bpk). */ |
8d08fdba | 3119 | |
8926095f MS |
3120 | /* Also warn if they did a prototype with `static' on it, but |
3121 | then later left the `static' off. */ | |
3122 | if (! TREE_PUBLIC (name) && TREE_PUBLIC (x)) | |
8d08fdba | 3123 | { |
8926095f MS |
3124 | if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t)) |
3125 | return t; | |
8d08fdba | 3126 | |
8926095f MS |
3127 | if (extra_warnings) |
3128 | { | |
a28e3c7f MS |
3129 | cp_warning ("`static' missing from declaration of `%D'", |
3130 | t); | |
8926095f MS |
3131 | warning_with_file_and_line (file, line, |
3132 | "previous declaration of `%s'", | |
3133 | decl_as_string (t, 0)); | |
3134 | } | |
8d08fdba | 3135 | |
8926095f MS |
3136 | /* Now fix things so it'll do what they expect. */ |
3137 | if (current_function_decl) | |
3138 | TREE_PUBLIC (current_function_decl) = 0; | |
3139 | } | |
51c184be MS |
3140 | /* Due to interference in memory reclamation (X may be |
3141 | obstack-deallocated at this point), we must guard against | |
8926095f MS |
3142 | one really special case. [jason: This should be handled |
3143 | by start_function] */ | |
51c184be MS |
3144 | if (current_function_decl == x) |
3145 | current_function_decl = t; | |
8926095f | 3146 | #endif |
7177d104 MS |
3147 | if (TREE_CODE (t) == TYPE_DECL) |
3148 | SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t)); | |
f30432d7 MS |
3149 | else if (TREE_CODE (t) == FUNCTION_DECL) |
3150 | check_default_args (t); | |
7177d104 | 3151 | |
51c184be MS |
3152 | return t; |
3153 | } | |
8d08fdba | 3154 | } |
8926095f MS |
3155 | |
3156 | if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x)) | |
3157 | { | |
3158 | t = push_overloaded_decl (x, 1); | |
3159 | if (t != x || DECL_LANGUAGE (x) == lang_c) | |
3160 | return t; | |
3161 | } | |
5566b478 | 3162 | else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_CONTEXT (x) == NULL_TREE) |
8926095f | 3163 | return push_overloaded_decl (x, 0); |
8d08fdba MS |
3164 | |
3165 | /* If declaring a type as a typedef, and the type has no known | |
3166 | typedef name, install this TYPE_DECL as its typedef name. */ | |
3167 | if (TREE_CODE (x) == TYPE_DECL) | |
3168 | { | |
3169 | tree type = TREE_TYPE (x); | |
3170 | tree name = (type != error_mark_node) ? TYPE_NAME (type) : x; | |
3171 | ||
3172 | if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL) | |
3173 | { | |
3174 | /* If these are different names, and we're at the global | |
3175 | binding level, make two equivalent definitions. */ | |
3176 | name = x; | |
3177 | if (global_bindings_p ()) | |
3178 | TYPE_NAME (type) = x; | |
3179 | } | |
8d08fdba MS |
3180 | my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140); |
3181 | ||
8d08fdba MS |
3182 | if (type != error_mark_node |
3183 | && TYPE_NAME (type) | |
3184 | && TYPE_IDENTIFIER (type)) | |
3185 | set_identifier_type_value_with_scope (DECL_NAME (x), type, b); | |
3186 | } | |
3187 | ||
3188 | /* Multiple external decls of the same identifier ought to match. | |
3189 | ||
3190 | We get warnings about inline functions where they are defined. | |
39211cd5 MS |
3191 | We get warnings about other functions from push_overloaded_decl. |
3192 | ||
8d08fdba | 3193 | Avoid duplicate warnings where they are used. */ |
39211cd5 | 3194 | if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL) |
8d08fdba MS |
3195 | { |
3196 | tree decl; | |
3197 | ||
3198 | if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE | |
3199 | && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name)) | |
3200 | || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))) | |
3201 | decl = IDENTIFIER_GLOBAL_VALUE (name); | |
3202 | else | |
3203 | decl = NULL_TREE; | |
3204 | ||
39211cd5 | 3205 | if (decl |
8d08fdba MS |
3206 | /* If different sort of thing, we already gave an error. */ |
3207 | && TREE_CODE (decl) == TREE_CODE (x) | |
39211cd5 | 3208 | && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1)) |
8d08fdba MS |
3209 | { |
3210 | cp_pedwarn ("type mismatch with previous external decl", x); | |
8926095f | 3211 | cp_pedwarn_at ("previous external decl of `%#D'", decl); |
8d08fdba MS |
3212 | } |
3213 | } | |
3214 | ||
8d08fdba MS |
3215 | /* This name is new in its binding level. |
3216 | Install the new declaration and return it. */ | |
3217 | if (b == global_binding_level) | |
3218 | { | |
3219 | /* Install a global value. */ | |
3220 | ||
8d08fdba MS |
3221 | /* If the first global decl has external linkage, |
3222 | warn if we later see static one. */ | |
893de33c | 3223 | if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x)) |
8d08fdba MS |
3224 | TREE_PUBLIC (name) = 1; |
3225 | ||
e1cd6e56 MS |
3226 | /* Don't install an artificial TYPE_DECL if we already have |
3227 | another _DECL with that name. */ | |
8d08fdba MS |
3228 | if (TREE_CODE (x) != TYPE_DECL |
3229 | || t == NULL_TREE | |
e1cd6e56 | 3230 | || ! DECL_ARTIFICIAL (x)) |
8d08fdba MS |
3231 | IDENTIFIER_GLOBAL_VALUE (name) = x; |
3232 | ||
3233 | /* Don't forget if the function was used via an implicit decl. */ | |
3234 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
3235 | && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) | |
3236 | TREE_USED (x) = 1; | |
3237 | ||
3238 | /* Don't forget if its address was taken in that way. */ | |
3239 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
3240 | && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) | |
3241 | TREE_ADDRESSABLE (x) = 1; | |
3242 | ||
3243 | /* Warn about mismatches against previous implicit decl. */ | |
3244 | if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE | |
3245 | /* If this real decl matches the implicit, don't complain. */ | |
3246 | && ! (TREE_CODE (x) == FUNCTION_DECL | |
3247 | && TREE_TYPE (TREE_TYPE (x)) == integer_type_node)) | |
3248 | cp_warning | |
3249 | ("`%D' was previously implicitly declared to return `int'", x); | |
3250 | ||
3251 | /* If new decl is `static' and an `extern' was seen previously, | |
3252 | warn about it. */ | |
a0a33927 MS |
3253 | if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t)) |
3254 | warn_extern_redeclared_static (x, t); | |
8d08fdba MS |
3255 | } |
3256 | else | |
3257 | { | |
3258 | /* Here to install a non-global value. */ | |
3259 | tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); | |
3260 | tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); | |
3261 | ||
e1cd6e56 MS |
3262 | /* Don't install an artificial TYPE_DECL if we already have |
3263 | another _DECL with that name. */ | |
3264 | if (TREE_CODE (x) != TYPE_DECL | |
3265 | || t == NULL_TREE | |
3266 | || ! DECL_ARTIFICIAL (x)) | |
3267 | { | |
3268 | b->shadowed = tree_cons (name, oldlocal, b->shadowed); | |
3269 | IDENTIFIER_LOCAL_VALUE (name) = x; | |
3270 | } | |
8d08fdba MS |
3271 | |
3272 | /* If this is a TYPE_DECL, push it into the type value slot. */ | |
3273 | if (TREE_CODE (x) == TYPE_DECL) | |
3274 | set_identifier_type_value_with_scope (name, TREE_TYPE (x), b); | |
3275 | ||
a9aedbc2 MS |
3276 | /* Clear out any TYPE_DECL shadowed by a namespace so that |
3277 | we won't think this is a type. The C struct hack doesn't | |
3278 | go through namespaces. */ | |
3279 | if (TREE_CODE (x) == NAMESPACE_DECL) | |
3280 | set_identifier_type_value_with_scope (name, NULL_TREE, b); | |
3281 | ||
8d08fdba MS |
3282 | /* If this is an extern function declaration, see if we |
3283 | have a global definition or declaration for the function. */ | |
3284 | if (oldlocal == NULL_TREE | |
faae18ab | 3285 | && DECL_EXTERNAL (x) |
8d08fdba MS |
3286 | && oldglobal != NULL_TREE |
3287 | && TREE_CODE (x) == FUNCTION_DECL | |
3288 | && TREE_CODE (oldglobal) == FUNCTION_DECL) | |
3289 | { | |
3290 | /* We have one. Their types must agree. */ | |
44a8d0b3 | 3291 | if (decls_match (x, oldglobal)) |
6060a796 MS |
3292 | /* OK */; |
3293 | else | |
8d08fdba MS |
3294 | { |
3295 | cp_warning ("extern declaration of `%#D' doesn't match", x); | |
3296 | cp_warning_at ("global declaration `%#D'", oldglobal); | |
3297 | } | |
8d08fdba MS |
3298 | } |
3299 | /* If we have a local external declaration, | |
3300 | and no file-scope declaration has yet been seen, | |
3301 | then if we later have a file-scope decl it must not be static. */ | |
3302 | if (oldlocal == NULL_TREE | |
3303 | && oldglobal == NULL_TREE | |
3304 | && DECL_EXTERNAL (x) | |
3305 | && TREE_PUBLIC (x)) | |
3306 | { | |
3307 | TREE_PUBLIC (name) = 1; | |
3308 | } | |
3309 | ||
3310 | if (DECL_FROM_INLINE (x)) | |
3311 | /* Inline decls shadow nothing. */; | |
3312 | ||
3313 | /* Warn if shadowing an argument at the top level of the body. */ | |
3314 | else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) | |
3315 | && TREE_CODE (oldlocal) == PARM_DECL | |
3316 | && TREE_CODE (x) != PARM_DECL) | |
3317 | { | |
3318 | /* Go to where the parms should be and see if we | |
3319 | find them there. */ | |
3320 | struct binding_level *b = current_binding_level->level_chain; | |
3321 | ||
3322 | if (cleanup_label) | |
3323 | b = b->level_chain; | |
3324 | ||
3325 | /* ARM $8.3 */ | |
3326 | if (b->parm_flag == 1) | |
3327 | cp_error ("declaration of `%#D' shadows a parameter", name); | |
3328 | } | |
72b7eeff | 3329 | else if (warn_shadow && oldlocal != NULL_TREE && b->is_for_scope |
8d6e462b PB |
3330 | && !DECL_DEAD_FOR_LOCAL (oldlocal)) |
3331 | { | |
3332 | warning ("variable `%s' shadows local", | |
3333 | IDENTIFIER_POINTER (name)); | |
3334 | cp_warning_at (" this is the shadowed declaration", oldlocal); | |
3335 | } | |
8d08fdba MS |
3336 | /* Maybe warn if shadowing something else. */ |
3337 | else if (warn_shadow && !DECL_EXTERNAL (x) | |
3338 | /* No shadow warnings for internally generated vars. */ | |
700f8a87 | 3339 | && ! DECL_ARTIFICIAL (x) |
8d08fdba MS |
3340 | /* No shadow warnings for vars made for inlining. */ |
3341 | && ! DECL_FROM_INLINE (x)) | |
3342 | { | |
3343 | char *warnstring = NULL; | |
3344 | ||
3345 | if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) | |
3346 | warnstring = "declaration of `%s' shadows a parameter"; | |
3347 | else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE | |
4ac14744 | 3348 | && current_class_ptr |
8d08fdba MS |
3349 | && !TREE_STATIC (name)) |
3350 | warnstring = "declaration of `%s' shadows a member of `this'"; | |
3351 | else if (oldlocal != NULL_TREE) | |
3352 | warnstring = "declaration of `%s' shadows previous local"; | |
3353 | else if (oldglobal != NULL_TREE) | |
3354 | warnstring = "declaration of `%s' shadows global declaration"; | |
3355 | ||
3356 | if (warnstring) | |
3357 | warning (warnstring, IDENTIFIER_POINTER (name)); | |
3358 | } | |
e1cd6e56 | 3359 | } |
8d08fdba | 3360 | |
e1cd6e56 | 3361 | if (TREE_CODE (x) == FUNCTION_DECL) |
f30432d7 | 3362 | check_default_args (x); |
8145f082 MS |
3363 | |
3364 | /* Keep count of variables in this level with incomplete type. */ | |
8145f082 | 3365 | if (TREE_CODE (x) == VAR_DECL |
28cbf42c | 3366 | && TREE_TYPE (x) != error_mark_node |
f30432d7 MS |
3367 | && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE |
3368 | && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) | |
3369 | /* RTTI TD entries are created while defining the type_info. */ | |
3370 | || (TYPE_LANG_SPECIFIC (TREE_TYPE (x)) | |
3371 | && TYPE_BEING_DEFINED (TREE_TYPE (x))))) | |
3372 | b->incomplete = tree_cons (NULL_TREE, x, b->incomplete); | |
8d08fdba MS |
3373 | } |
3374 | ||
8d08fdba MS |
3375 | /* Put decls on list in reverse order. |
3376 | We will reverse them later if necessary. */ | |
3377 | TREE_CHAIN (x) = b->names; | |
3378 | b->names = x; | |
3379 | if (! (b != global_binding_level || TREE_PERMANENT (x))) | |
3380 | my_friendly_abort (124); | |
3381 | ||
3382 | return x; | |
3383 | } | |
3384 | ||
5566b478 MS |
3385 | /* Same as pushdecl, but define X in binding-level LEVEL. We rely on the |
3386 | caller to set DECL_CONTEXT properly. */ | |
8d08fdba MS |
3387 | |
3388 | static tree | |
3389 | pushdecl_with_scope (x, level) | |
3390 | tree x; | |
3391 | struct binding_level *level; | |
3392 | { | |
3393 | register struct binding_level *b = current_binding_level; | |
5566b478 | 3394 | tree function_decl = current_function_decl; |
8d08fdba | 3395 | |
5566b478 | 3396 | current_function_decl = NULL_TREE; |
8d08fdba MS |
3397 | current_binding_level = level; |
3398 | x = pushdecl (x); | |
3399 | current_binding_level = b; | |
5566b478 | 3400 | current_function_decl = function_decl; |
8d08fdba MS |
3401 | return x; |
3402 | } | |
3403 | ||
3404 | /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, | |
3405 | if appropriate. */ | |
e92cc029 | 3406 | |
8d08fdba MS |
3407 | tree |
3408 | pushdecl_top_level (x) | |
3409 | tree x; | |
3410 | { | |
3411 | register struct binding_level *b = inner_binding_level; | |
3412 | register tree t = pushdecl_with_scope (x, global_binding_level); | |
3413 | ||
3414 | /* Now, the type_shadowed stack may screw us. Munge it so it does | |
3415 | what we want. */ | |
3416 | if (TREE_CODE (x) == TYPE_DECL) | |
3417 | { | |
3418 | tree name = DECL_NAME (x); | |
3419 | tree newval; | |
3420 | tree *ptr = (tree *)0; | |
3421 | for (; b != global_binding_level; b = b->level_chain) | |
3422 | { | |
3423 | tree shadowed = b->type_shadowed; | |
3424 | for (; shadowed; shadowed = TREE_CHAIN (shadowed)) | |
3425 | if (TREE_PURPOSE (shadowed) == name) | |
3426 | { | |
3427 | ptr = &TREE_VALUE (shadowed); | |
3428 | /* Can't break out of the loop here because sometimes | |
3429 | a binding level will have duplicate bindings for | |
3430 | PT names. It's gross, but I haven't time to fix it. */ | |
3431 | } | |
3432 | } | |
3433 | newval = TREE_TYPE (x); | |
3434 | if (ptr == (tree *)0) | |
3435 | { | |
3436 | /* @@ This shouldn't be needed. My test case "zstring.cc" trips | |
3437 | up here if this is changed to an assertion. --KR */ | |
3438 | SET_IDENTIFIER_TYPE_VALUE (name, newval); | |
3439 | } | |
3440 | else | |
3441 | { | |
8d08fdba MS |
3442 | *ptr = newval; |
3443 | } | |
3444 | } | |
3445 | return t; | |
3446 | } | |
3447 | ||
3448 | /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL, | |
3449 | if appropriate. */ | |
e92cc029 | 3450 | |
bd6dd845 | 3451 | static void |
8d08fdba MS |
3452 | push_overloaded_decl_top_level (x, forget) |
3453 | tree x; | |
3454 | int forget; | |
3455 | { | |
3456 | struct binding_level *b = current_binding_level; | |
3457 | ||
3458 | current_binding_level = global_binding_level; | |
3459 | push_overloaded_decl (x, forget); | |
3460 | current_binding_level = b; | |
3461 | } | |
3462 | ||
3463 | /* Make the declaration of X appear in CLASS scope. */ | |
e92cc029 | 3464 | |
8d08fdba MS |
3465 | tree |
3466 | pushdecl_class_level (x) | |
3467 | tree x; | |
3468 | { | |
3469 | /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class | |
3470 | scope looks for the pre-mangled name. */ | |
3471 | register tree name = DECL_NAME (x); | |
3472 | ||
3473 | if (name) | |
3474 | { | |
8d2733ca MS |
3475 | if (TYPE_BEING_DEFINED (current_class_type)) |
3476 | { | |
3477 | /* Check for inconsistent use of this name in the class body. | |
3478 | Types, enums, and static vars are checked here; other | |
3479 | members are checked in finish_struct. */ | |
3480 | tree icv = IDENTIFIER_CLASS_VALUE (name); | |
3481 | ||
5566b478 | 3482 | if (icv && icv != x |
a4443a08 MS |
3483 | /* Don't complain about inherited names. */ |
3484 | && id_in_current_class (name) | |
3485 | /* Or shadowed tags. */ | |
3486 | && !(TREE_CODE (icv) == TYPE_DECL | |
3487 | && DECL_CONTEXT (icv) == current_class_type)) | |
8d2733ca MS |
3488 | { |
3489 | cp_error ("declaration of identifier `%D' as `%#D'", name, x); | |
3490 | cp_error_at ("conflicts with previous use in class as `%#D'", | |
3491 | icv); | |
3492 | } | |
3493 | } | |
3494 | ||
8d08fdba MS |
3495 | push_class_level_binding (name, x); |
3496 | if (TREE_CODE (x) == TYPE_DECL) | |
3497 | { | |
3498 | set_identifier_type_value (name, TREE_TYPE (x)); | |
8d08fdba MS |
3499 | } |
3500 | } | |
3501 | return x; | |
3502 | } | |
3503 | ||
bd6dd845 | 3504 | #if 0 |
7177d104 MS |
3505 | /* This function is used to push the mangled decls for nested types into |
3506 | the appropriate scope. Previously pushdecl_top_level was used, but that | |
3507 | is incorrect for members of local classes. */ | |
e92cc029 | 3508 | |
5566b478 | 3509 | void |
7177d104 MS |
3510 | pushdecl_nonclass_level (x) |
3511 | tree x; | |
3512 | { | |
3513 | struct binding_level *b = current_binding_level; | |
3514 | ||
7177d104 | 3515 | my_friendly_assert (b->parm_flag != 2, 180); |
7177d104 | 3516 | |
5566b478 | 3517 | #if 0 |
7177d104 MS |
3518 | /* Get out of template binding levels */ |
3519 | while (b->pseudo_global) | |
3520 | b = b->level_chain; | |
5566b478 | 3521 | #endif |
7177d104 MS |
3522 | |
3523 | pushdecl_with_scope (x, b); | |
3524 | } | |
bd6dd845 | 3525 | #endif |
7177d104 | 3526 | |
8d08fdba MS |
3527 | /* Make the declaration(s) of X appear in CLASS scope |
3528 | under the name NAME. */ | |
e92cc029 | 3529 | |
8d08fdba MS |
3530 | void |
3531 | push_class_level_binding (name, x) | |
3532 | tree name; | |
3533 | tree x; | |
3534 | { | |
98c1c668 JM |
3535 | /* The class_binding_level will be NULL if x is a template |
3536 | parameter name in a member template. */ | |
3537 | if (!class_binding_level) | |
3538 | return; | |
3539 | ||
e1cd6e56 MS |
3540 | if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) |
3541 | && purpose_member (name, class_binding_level->class_shadowed)) | |
3542 | return; | |
3543 | ||
8d08fdba MS |
3544 | maybe_push_cache_obstack (); |
3545 | class_binding_level->class_shadowed | |
3546 | = tree_cons (name, IDENTIFIER_CLASS_VALUE (name), | |
3547 | class_binding_level->class_shadowed); | |
3548 | pop_obstacks (); | |
3549 | IDENTIFIER_CLASS_VALUE (name) = x; | |
3550 | obstack_ptr_grow (&decl_obstack, x); | |
3551 | } | |
3552 | ||
3553 | /* Tell caller how to interpret a TREE_LIST which contains | |
3554 | chains of FUNCTION_DECLS. */ | |
e92cc029 | 3555 | |
8d08fdba MS |
3556 | int |
3557 | overloaded_globals_p (list) | |
3558 | tree list; | |
3559 | { | |
3560 | my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142); | |
3561 | ||
3562 | /* Don't commit caller to seeing them as globals. */ | |
3563 | if (TREE_NONLOCAL_FLAG (list)) | |
3564 | return -1; | |
8d08fdba | 3565 | /* Do commit caller to not seeing them as globals. */ |
5566b478 MS |
3566 | if (TREE_CODE (TREE_VALUE (list)) == TREE_LIST) |
3567 | return 0; | |
3568 | /* Do commit caller to seeing them as globals. */ | |
3569 | return 1; | |
8d08fdba MS |
3570 | } |
3571 | ||
700f8a87 MS |
3572 | /* DECL is a FUNCTION_DECL which may have other definitions already in |
3573 | place. We get around this by making the value of the identifier point | |
3574 | to a list of all the things that want to be referenced by that name. It | |
3575 | is then up to the users of that name to decide what to do with that | |
8d08fdba MS |
3576 | list. |
3577 | ||
3578 | DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT | |
3579 | slot. It is dealt with the same way. | |
3580 | ||
3581 | The value returned may be a previous declaration if we guessed wrong | |
3582 | about what language DECL should belong to (C or C++). Otherwise, | |
3583 | it's always DECL (and never something that's not a _DECL). */ | |
e92cc029 | 3584 | |
bd6dd845 | 3585 | static tree |
8d08fdba MS |
3586 | push_overloaded_decl (decl, forgettable) |
3587 | tree decl; | |
3588 | int forgettable; | |
3589 | { | |
3590 | tree orig_name = DECL_NAME (decl); | |
700f8a87 | 3591 | tree old; |
5566b478 | 3592 | int doing_global = (global_bindings_p () || ! forgettable); |
700f8a87 MS |
3593 | |
3594 | if (doing_global) | |
3595 | { | |
3596 | old = IDENTIFIER_GLOBAL_VALUE (orig_name); | |
3597 | if (old && TREE_CODE (old) == FUNCTION_DECL | |
a4443a08 | 3598 | && DECL_ARTIFICIAL (old) |
700f8a87 MS |
3599 | && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old))) |
3600 | { | |
a4443a08 MS |
3601 | if (duplicate_decls (decl, old)) |
3602 | return old; | |
700f8a87 MS |
3603 | old = NULL_TREE; |
3604 | } | |
3605 | } | |
3606 | else | |
3607 | { | |
3608 | old = IDENTIFIER_LOCAL_VALUE (orig_name); | |
a4443a08 | 3609 | |
700f8a87 MS |
3610 | if (! purpose_member (orig_name, current_binding_level->shadowed)) |
3611 | { | |
3612 | current_binding_level->shadowed | |
3613 | = tree_cons (orig_name, old, current_binding_level->shadowed); | |
3614 | old = NULL_TREE; | |
3615 | } | |
3616 | } | |
8d08fdba | 3617 | |
700f8a87 | 3618 | if (old) |
8d08fdba | 3619 | { |
e1cd6e56 | 3620 | if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) |
8926095f | 3621 | { |
700f8a87 | 3622 | tree t = TREE_TYPE (old); |
cdf5b885 MS |
3623 | if (IS_AGGR_TYPE (t) && warn_shadow |
3624 | && (! DECL_IN_SYSTEM_HEADER (decl) | |
3625 | || ! DECL_IN_SYSTEM_HEADER (old))) | |
8926095f | 3626 | cp_warning ("`%#D' hides constructor for `%#T'", decl, t); |
5b605f68 | 3627 | old = NULL_TREE; |
8926095f | 3628 | } |
700f8a87 | 3629 | else if (is_overloaded_fn (old)) |
8d08fdba | 3630 | { |
8d08fdba MS |
3631 | tree tmp; |
3632 | ||
700f8a87 MS |
3633 | for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp)) |
3634 | if (decl == tmp || duplicate_decls (decl, tmp)) | |
3635 | return tmp; | |
8d08fdba | 3636 | } |
e1cd6e56 MS |
3637 | else |
3638 | { | |
3639 | cp_error_at ("previous non-function declaration `%#D'", old); | |
3640 | cp_error ("conflicts with function declaration `%#D'", decl); | |
a9aedbc2 | 3641 | return decl; |
e1cd6e56 | 3642 | } |
8d08fdba | 3643 | } |
7177d104 | 3644 | |
700f8a87 | 3645 | if (old || TREE_CODE (decl) == TEMPLATE_DECL) |
8d08fdba | 3646 | { |
700f8a87 MS |
3647 | if (old && is_overloaded_fn (old)) |
3648 | DECL_CHAIN (decl) = get_first_fn (old); | |
8d08fdba MS |
3649 | else |
3650 | DECL_CHAIN (decl) = NULL_TREE; | |
700f8a87 MS |
3651 | old = tree_cons (orig_name, decl, NULL_TREE); |
3652 | TREE_TYPE (old) = unknown_type_node; | |
8d08fdba MS |
3653 | } |
3654 | else | |
3655 | /* orig_name is not ambiguous. */ | |
700f8a87 MS |
3656 | old = decl; |
3657 | ||
3658 | if (doing_global) | |
3659 | IDENTIFIER_GLOBAL_VALUE (orig_name) = old; | |
3660 | else | |
3661 | IDENTIFIER_LOCAL_VALUE (orig_name) = old; | |
3662 | ||
8d08fdba MS |
3663 | return decl; |
3664 | } | |
3665 | \f | |
3666 | /* Generate an implicit declaration for identifier FUNCTIONID | |
3667 | as a function of type int (). Print a warning if appropriate. */ | |
3668 | ||
3669 | tree | |
3670 | implicitly_declare (functionid) | |
3671 | tree functionid; | |
3672 | { | |
3673 | register tree decl; | |
3674 | int temp = allocation_temporary_p (); | |
3675 | ||
3676 | push_obstacks_nochange (); | |
3677 | ||
3678 | /* Save the decl permanently so we can warn if definition follows. | |
3679 | In ANSI C, warn_implicit is usually false, so the saves little space. | |
3680 | But in C++, it's usually true, hence the extra code. */ | |
d22c8596 | 3681 | if (temp && (! warn_implicit || toplevel_bindings_p ())) |
8d08fdba MS |
3682 | end_temporary_allocation (); |
3683 | ||
3684 | /* We used to reuse an old implicit decl here, | |
3685 | but this loses with inline functions because it can clobber | |
3686 | the saved decl chains. */ | |
3687 | decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type); | |
3688 | ||
3689 | DECL_EXTERNAL (decl) = 1; | |
3690 | TREE_PUBLIC (decl) = 1; | |
3691 | ||
3692 | /* ANSI standard says implicit declarations are in the innermost block. | |
d22c8596 | 3693 | So we record the decl in the standard fashion. */ |
8d08fdba MS |
3694 | pushdecl (decl); |
3695 | rest_of_decl_compilation (decl, NULL_PTR, 0, 0); | |
3696 | ||
3697 | if (warn_implicit | |
3698 | /* Only one warning per identifier. */ | |
3699 | && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE) | |
3700 | { | |
3701 | cp_pedwarn ("implicit declaration of function `%#D'", decl); | |
3702 | } | |
3703 | ||
3704 | SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl); | |
3705 | ||
3706 | pop_obstacks (); | |
3707 | ||
3708 | return decl; | |
3709 | } | |
3710 | ||
3711 | /* Return zero if the declaration NEWDECL is valid | |
3712 | when the declaration OLDDECL (assumed to be for the same name) | |
3713 | has already been seen. | |
3714 | Otherwise return an error message format string with a %s | |
3715 | where the identifier should go. */ | |
3716 | ||
3717 | static char * | |
3718 | redeclaration_error_message (newdecl, olddecl) | |
3719 | tree newdecl, olddecl; | |
3720 | { | |
3721 | if (TREE_CODE (newdecl) == TYPE_DECL) | |
3722 | { | |
3723 | /* Because C++ can put things into name space for free, | |
3724 | constructs like "typedef struct foo { ... } foo" | |
3725 | would look like an erroneous redeclaration. */ | |
8926095f | 3726 | if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0)) |
8d08fdba MS |
3727 | return 0; |
3728 | else | |
51c184be | 3729 | return "redefinition of `%#D'"; |
8d08fdba MS |
3730 | } |
3731 | else if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
3732 | { | |
3733 | /* If this is a pure function, its olddecl will actually be | |
3734 | the original initialization to `0' (which we force to call | |
3735 | abort()). Don't complain about redefinition in this case. */ | |
3736 | if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) | |
3737 | return 0; | |
3738 | ||
db5ae43f MS |
3739 | /* We'll complain about linkage mismatches in |
3740 | warn_extern_redeclared_static. */ | |
3741 | ||
3742 | /* defining the same name twice is no good. */ | |
8d08fdba | 3743 | if (DECL_INITIAL (olddecl) != NULL_TREE |
faae18ab | 3744 | && DECL_INITIAL (newdecl) != NULL_TREE) |
8d08fdba MS |
3745 | { |
3746 | if (DECL_NAME (olddecl) == NULL_TREE) | |
51c184be | 3747 | return "`%#D' not declared in class"; |
8d08fdba | 3748 | else |
51c184be | 3749 | return "redefinition of `%#D'"; |
8d08fdba MS |
3750 | } |
3751 | return 0; | |
3752 | } | |
51c184be MS |
3753 | else if (TREE_CODE (newdecl) == TEMPLATE_DECL) |
3754 | { | |
ec255269 MS |
3755 | if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL |
3756 | && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) | |
3757 | && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl))) | |
3758 | || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL | |
3759 | && TYPE_SIZE (TREE_TYPE (newdecl)) | |
3760 | && TYPE_SIZE (TREE_TYPE (olddecl)))) | |
51c184be MS |
3761 | return "redefinition of `%#D'"; |
3762 | return 0; | |
3763 | } | |
5566b478 | 3764 | else if (toplevel_bindings_p ()) |
8d08fdba MS |
3765 | { |
3766 | /* Objects declared at top level: */ | |
3767 | /* If at least one is a reference, it's ok. */ | |
3768 | if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) | |
3769 | return 0; | |
8926095f MS |
3770 | /* Reject two definitions. */ |
3771 | return "redefinition of `%#D'"; | |
8d08fdba MS |
3772 | } |
3773 | else | |
3774 | { | |
3775 | /* Objects declared with block scope: */ | |
3776 | /* Reject two definitions, and reject a definition | |
3777 | together with an external reference. */ | |
3778 | if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))) | |
51c184be | 3779 | return "redeclaration of `%#D'"; |
8d08fdba MS |
3780 | return 0; |
3781 | } | |
3782 | } | |
3783 | \f | |
3784 | /* Get the LABEL_DECL corresponding to identifier ID as a label. | |
3785 | Create one if none exists so far for the current function. | |
3786 | This function is called for both label definitions and label references. */ | |
3787 | ||
3788 | tree | |
3789 | lookup_label (id) | |
3790 | tree id; | |
3791 | { | |
3792 | register tree decl = IDENTIFIER_LABEL_VALUE (id); | |
3793 | ||
3794 | if (current_function_decl == NULL_TREE) | |
3795 | { | |
3796 | error ("label `%s' referenced outside of any function", | |
3797 | IDENTIFIER_POINTER (id)); | |
3798 | return NULL_TREE; | |
3799 | } | |
3800 | ||
3801 | if ((decl == NULL_TREE | |
3802 | || DECL_SOURCE_LINE (decl) == 0) | |
e349ee73 MS |
3803 | && (named_label_uses == NULL |
3804 | || named_label_uses->names_in_scope != current_binding_level->names | |
3805 | || named_label_uses->label_decl != decl)) | |
3806 | { | |
3807 | struct named_label_list *new_ent; | |
3808 | new_ent | |
3809 | = (struct named_label_list*)oballoc (sizeof (struct named_label_list)); | |
3810 | new_ent->label_decl = decl; | |
3811 | new_ent->names_in_scope = current_binding_level->names; | |
3812 | new_ent->binding_level = current_binding_level; | |
3813 | new_ent->lineno_o_goto = lineno; | |
3814 | new_ent->filename_o_goto = input_filename; | |
3815 | new_ent->next = named_label_uses; | |
3816 | named_label_uses = new_ent; | |
8d08fdba MS |
3817 | } |
3818 | ||
3819 | /* Use a label already defined or ref'd with this name. */ | |
3820 | if (decl != NULL_TREE) | |
3821 | { | |
3822 | /* But not if it is inherited and wasn't declared to be inheritable. */ | |
3823 | if (DECL_CONTEXT (decl) != current_function_decl | |
3824 | && ! C_DECLARED_LABEL_FLAG (decl)) | |
3825 | return shadow_label (id); | |
3826 | return decl; | |
3827 | } | |
3828 | ||
3829 | decl = build_decl (LABEL_DECL, id, void_type_node); | |
3830 | ||
cffa8729 MS |
3831 | /* Make sure every label has an rtx. */ |
3832 | label_rtx (decl); | |
3833 | ||
8d08fdba MS |
3834 | /* A label not explicitly declared must be local to where it's ref'd. */ |
3835 | DECL_CONTEXT (decl) = current_function_decl; | |
3836 | ||
3837 | DECL_MODE (decl) = VOIDmode; | |
3838 | ||
3839 | /* Say where one reference is to the label, | |
3840 | for the sake of the error if it is not defined. */ | |
3841 | DECL_SOURCE_LINE (decl) = lineno; | |
3842 | DECL_SOURCE_FILE (decl) = input_filename; | |
3843 | ||
3844 | SET_IDENTIFIER_LABEL_VALUE (id, decl); | |
3845 | ||
3846 | named_labels = tree_cons (NULL_TREE, decl, named_labels); | |
e349ee73 | 3847 | named_label_uses->label_decl = decl; |
8d08fdba MS |
3848 | |
3849 | return decl; | |
3850 | } | |
3851 | ||
3852 | /* Make a label named NAME in the current function, | |
3853 | shadowing silently any that may be inherited from containing functions | |
3854 | or containing scopes. | |
3855 | ||
3856 | Note that valid use, if the label being shadowed | |
3857 | comes from another scope in the same function, | |
3858 | requires calling declare_nonlocal_label right away. */ | |
3859 | ||
3860 | tree | |
3861 | shadow_label (name) | |
3862 | tree name; | |
3863 | { | |
3864 | register tree decl = IDENTIFIER_LABEL_VALUE (name); | |
3865 | ||
3866 | if (decl != NULL_TREE) | |
3867 | { | |
3868 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
3869 | SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); | |
3870 | SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE); | |
3871 | } | |
3872 | ||
3873 | return lookup_label (name); | |
3874 | } | |
3875 | ||
3876 | /* Define a label, specifying the location in the source file. | |
3877 | Return the LABEL_DECL node for the label, if the definition is valid. | |
3878 | Otherwise return 0. */ | |
3879 | ||
3880 | tree | |
3881 | define_label (filename, line, name) | |
3882 | char *filename; | |
3883 | int line; | |
3884 | tree name; | |
3885 | { | |
5566b478 MS |
3886 | tree decl; |
3887 | ||
3888 | if (minimal_parse_mode) | |
3889 | { | |
3890 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
3891 | decl = build_decl (LABEL_DECL, name, void_type_node); | |
3892 | pop_obstacks (); | |
3893 | DECL_SOURCE_LINE (decl) = line; | |
3894 | DECL_SOURCE_FILE (decl) = filename; | |
3895 | add_tree (decl); | |
3896 | return decl; | |
3897 | } | |
3898 | ||
3899 | decl = lookup_label (name); | |
8d08fdba MS |
3900 | |
3901 | /* After labels, make any new cleanups go into their | |
3902 | own new (temporary) binding contour. */ | |
3903 | current_binding_level->more_cleanups_ok = 0; | |
3904 | ||
3905 | /* If label with this name is known from an outer context, shadow it. */ | |
3906 | if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl) | |
3907 | { | |
3908 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
3909 | SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); | |
3910 | decl = lookup_label (name); | |
3911 | } | |
3912 | ||
e1cd6e56 MS |
3913 | if (name == get_identifier ("wchar_t")) |
3914 | cp_pedwarn ("label named wchar_t"); | |
3915 | ||
8d08fdba MS |
3916 | if (DECL_INITIAL (decl) != NULL_TREE) |
3917 | { | |
3918 | cp_error ("duplicate label `%D'", decl); | |
3919 | return 0; | |
3920 | } | |
3921 | else | |
3922 | { | |
e349ee73 | 3923 | struct named_label_list *uses, *prev; |
28cbf42c | 3924 | int identified = 0; |
8d08fdba MS |
3925 | |
3926 | /* Mark label as having been defined. */ | |
3927 | DECL_INITIAL (decl) = error_mark_node; | |
3928 | /* Say where in the source. */ | |
3929 | DECL_SOURCE_FILE (decl) = filename; | |
3930 | DECL_SOURCE_LINE (decl) = line; | |
3931 | ||
e349ee73 MS |
3932 | prev = NULL; |
3933 | uses = named_label_uses; | |
3934 | while (uses != NULL) | |
3935 | if (uses->label_decl == decl) | |
8d08fdba MS |
3936 | { |
3937 | struct binding_level *b = current_binding_level; | |
3938 | while (b) | |
3939 | { | |
3940 | tree new_decls = b->names; | |
e349ee73 MS |
3941 | tree old_decls = (b == uses->binding_level) |
3942 | ? uses->names_in_scope : NULL_TREE; | |
8d08fdba MS |
3943 | while (new_decls != old_decls) |
3944 | { | |
3945 | if (TREE_CODE (new_decls) == VAR_DECL | |
3946 | /* Don't complain about crossing initialization | |
3947 | of internal entities. They can't be accessed, | |
3948 | and they should be cleaned up | |
3949 | by the time we get to the label. */ | |
700f8a87 | 3950 | && ! DECL_ARTIFICIAL (new_decls) |
8d08fdba MS |
3951 | && ((DECL_INITIAL (new_decls) != NULL_TREE |
3952 | && DECL_INITIAL (new_decls) != error_mark_node) | |
3953 | || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) | |
3954 | { | |
e349ee73 MS |
3955 | if (! identified) |
3956 | { | |
3957 | cp_error ("jump to label `%D'", decl); | |
3958 | error_with_file_and_line (uses->filename_o_goto, | |
3959 | uses->lineno_o_goto, | |
3960 | " from here"); | |
3961 | identified = 1; | |
3962 | } | |
28cbf42c MS |
3963 | cp_error_at (" crosses initialization of `%#D'", |
3964 | new_decls); | |
8d08fdba MS |
3965 | } |
3966 | new_decls = TREE_CHAIN (new_decls); | |
3967 | } | |
e349ee73 | 3968 | if (b == uses->binding_level) |
8d08fdba MS |
3969 | break; |
3970 | b = b->level_chain; | |
3971 | } | |
3972 | ||
e349ee73 MS |
3973 | if (prev != NULL) |
3974 | prev->next = uses->next; | |
8d08fdba | 3975 | else |
e349ee73 MS |
3976 | named_label_uses = uses->next; |
3977 | ||
3978 | uses = uses->next; | |
3979 | } | |
3980 | else | |
3981 | { | |
3982 | prev = uses; | |
3983 | uses = uses->next; | |
8d08fdba MS |
3984 | } |
3985 | current_function_return_value = NULL_TREE; | |
3986 | return decl; | |
3987 | } | |
3988 | } | |
3989 | ||
a5894242 MS |
3990 | struct cp_switch |
3991 | { | |
3992 | struct binding_level *level; | |
3993 | struct cp_switch *next; | |
3994 | }; | |
3995 | ||
3996 | static struct cp_switch *switch_stack; | |
3997 | ||
3998 | void | |
3999 | push_switch () | |
4000 | { | |
4001 | struct cp_switch *p | |
4002 | = (struct cp_switch *) oballoc (sizeof (struct cp_switch)); | |
4003 | p->level = current_binding_level; | |
4004 | p->next = switch_stack; | |
4005 | switch_stack = p; | |
4006 | } | |
4007 | ||
4008 | void | |
4009 | pop_switch () | |
4010 | { | |
4011 | switch_stack = switch_stack->next; | |
4012 | } | |
4013 | ||
8d08fdba MS |
4014 | /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ |
4015 | /* XXX Note decl is never actually used. (bpk) */ | |
e92cc029 | 4016 | |
8d08fdba MS |
4017 | void |
4018 | define_case_label (decl) | |
4019 | tree decl; | |
4020 | { | |
4021 | tree cleanup = last_cleanup_this_contour (); | |
a5894242 MS |
4022 | struct binding_level *b = current_binding_level; |
4023 | int identified = 0; | |
4024 | ||
8d08fdba MS |
4025 | if (cleanup) |
4026 | { | |
4027 | static int explained = 0; | |
a5894242 MS |
4028 | cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup)); |
4029 | warning ("where case label appears here"); | |
8d08fdba MS |
4030 | if (!explained) |
4031 | { | |
a5894242 MS |
4032 | warning ("(enclose actions of previous case statements requiring"); |
4033 | warning ("destructors in their own binding contours.)"); | |
8d08fdba MS |
4034 | explained = 1; |
4035 | } | |
4036 | } | |
4037 | ||
a5894242 MS |
4038 | for (; b && b != switch_stack->level; b = b->level_chain) |
4039 | { | |
4040 | tree new_decls = b->names; | |
4041 | for (; new_decls; new_decls = TREE_CHAIN (new_decls)) | |
4042 | { | |
4043 | if (TREE_CODE (new_decls) == VAR_DECL | |
4044 | /* Don't complain about crossing initialization | |
4045 | of internal entities. They can't be accessed, | |
4046 | and they should be cleaned up | |
4047 | by the time we get to the label. */ | |
4048 | && ! DECL_ARTIFICIAL (new_decls) | |
4049 | && ((DECL_INITIAL (new_decls) != NULL_TREE | |
4050 | && DECL_INITIAL (new_decls) != error_mark_node) | |
4051 | || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) | |
4052 | { | |
4053 | if (! identified) | |
4054 | error ("jump to case label"); | |
4055 | identified = 1; | |
4056 | cp_error_at (" crosses initialization of `%#D'", | |
4057 | new_decls); | |
4058 | } | |
4059 | } | |
4060 | } | |
4061 | ||
8d08fdba MS |
4062 | /* After labels, make any new cleanups go into their |
4063 | own new (temporary) binding contour. */ | |
4064 | ||
4065 | current_binding_level->more_cleanups_ok = 0; | |
4066 | current_function_return_value = NULL_TREE; | |
4067 | } | |
4068 | \f | |
4069 | /* Return the list of declarations of the current level. | |
4070 | Note that this list is in reverse order unless/until | |
4071 | you nreverse it; and when you do nreverse it, you must | |
4072 | store the result back using `storedecls' or you will lose. */ | |
4073 | ||
4074 | tree | |
4075 | getdecls () | |
4076 | { | |
4077 | return current_binding_level->names; | |
4078 | } | |
4079 | ||
4080 | /* Return the list of type-tags (for structs, etc) of the current level. */ | |
4081 | ||
4082 | tree | |
4083 | gettags () | |
4084 | { | |
4085 | return current_binding_level->tags; | |
4086 | } | |
4087 | ||
4088 | /* Store the list of declarations of the current level. | |
4089 | This is done for the parameter declarations of a function being defined, | |
4090 | after they are modified in the light of any missing parameters. */ | |
4091 | ||
4092 | static void | |
4093 | storedecls (decls) | |
4094 | tree decls; | |
4095 | { | |
4096 | current_binding_level->names = decls; | |
4097 | } | |
4098 | ||
4099 | /* Similarly, store the list of tags of the current level. */ | |
4100 | ||
4101 | static void | |
4102 | storetags (tags) | |
4103 | tree tags; | |
4104 | { | |
4105 | current_binding_level->tags = tags; | |
4106 | } | |
4107 | \f | |
4108 | /* Given NAME, an IDENTIFIER_NODE, | |
4109 | return the structure (or union or enum) definition for that name. | |
4110 | Searches binding levels from BINDING_LEVEL up to the global level. | |
4111 | If THISLEVEL_ONLY is nonzero, searches only the specified context | |
4112 | (but skips any tag-transparent contexts to find one that is | |
4113 | meaningful for tags). | |
4114 | FORM says which kind of type the caller wants; | |
4115 | it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. | |
4116 | If the wrong kind of type is found, and it's not a template, an error is | |
4117 | reported. */ | |
4118 | ||
4119 | static tree | |
4120 | lookup_tag (form, name, binding_level, thislevel_only) | |
4121 | enum tree_code form; | |
8d08fdba | 4122 | tree name; |
cffa8729 | 4123 | struct binding_level *binding_level; |
8d08fdba MS |
4124 | int thislevel_only; |
4125 | { | |
4126 | register struct binding_level *level; | |
4127 | ||
4128 | for (level = binding_level; level; level = level->level_chain) | |
4129 | { | |
4130 | register tree tail; | |
4131 | if (ANON_AGGRNAME_P (name)) | |
4132 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
4133 | { | |
4134 | /* There's no need for error checking here, because | |
4135 | anon names are unique throughout the compilation. */ | |
4136 | if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name) | |
4137 | return TREE_VALUE (tail); | |
4138 | } | |
4139 | else | |
4140 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
4141 | { | |
a80e4195 | 4142 | if (TREE_PURPOSE (tail) == name) |
8d08fdba MS |
4143 | { |
4144 | enum tree_code code = TREE_CODE (TREE_VALUE (tail)); | |
4145 | /* Should tighten this up; it'll probably permit | |
4146 | UNION_TYPE and a struct template, for example. */ | |
4147 | if (code != form | |
5566b478 | 4148 | && !(form != ENUMERAL_TYPE && code == TEMPLATE_DECL)) |
8d08fdba MS |
4149 | { |
4150 | /* Definition isn't the kind we were looking for. */ | |
4151 | cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail), | |
4152 | form); | |
72b7eeff | 4153 | return NULL_TREE; |
8d08fdba MS |
4154 | } |
4155 | return TREE_VALUE (tail); | |
4156 | } | |
4157 | } | |
4158 | if (thislevel_only && ! level->tag_transparent) | |
5566b478 MS |
4159 | { |
4160 | if (level->pseudo_global) | |
4161 | { | |
4162 | tree t = IDENTIFIER_GLOBAL_VALUE (name); | |
4163 | if (t && TREE_CODE (t) == TEMPLATE_DECL | |
4164 | && TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL) | |
4165 | return TREE_TYPE (t); | |
4166 | } | |
4167 | return NULL_TREE; | |
4168 | } | |
8d08fdba MS |
4169 | if (current_class_type && level->level_chain == global_binding_level) |
4170 | { | |
4171 | /* Try looking in this class's tags before heading into | |
4172 | global binding level. */ | |
4173 | tree context = current_class_type; | |
4174 | while (context) | |
4175 | { | |
4176 | switch (TREE_CODE_CLASS (TREE_CODE (context))) | |
4177 | { | |
4178 | tree these_tags; | |
4179 | case 't': | |
4180 | these_tags = CLASSTYPE_TAGS (context); | |
4181 | if (ANON_AGGRNAME_P (name)) | |
4182 | while (these_tags) | |
4183 | { | |
4184 | if (TYPE_IDENTIFIER (TREE_VALUE (these_tags)) | |
4185 | == name) | |
4186 | return TREE_VALUE (tail); | |
4187 | these_tags = TREE_CHAIN (these_tags); | |
4188 | } | |
4189 | else | |
4190 | while (these_tags) | |
4191 | { | |
4192 | if (TREE_PURPOSE (these_tags) == name) | |
4193 | { | |
4194 | if (TREE_CODE (TREE_VALUE (these_tags)) != form) | |
4195 | { | |
4196 | cp_error ("`%#D' redeclared as %C in class scope", | |
4197 | TREE_VALUE (tail), form); | |
72b7eeff | 4198 | return NULL_TREE; |
8d08fdba MS |
4199 | } |
4200 | return TREE_VALUE (tail); | |
4201 | } | |
4202 | these_tags = TREE_CHAIN (these_tags); | |
4203 | } | |
4204 | /* If this type is not yet complete, then don't | |
4205 | look at its context. */ | |
4206 | if (TYPE_SIZE (context) == NULL_TREE) | |
4207 | goto no_context; | |
4208 | /* Go to next enclosing type, if any. */ | |
d2e5ee5c | 4209 | context = DECL_CONTEXT (TYPE_MAIN_DECL (context)); |
8d08fdba MS |
4210 | break; |
4211 | case 'd': | |
4212 | context = DECL_CONTEXT (context); | |
4213 | break; | |
4214 | default: | |
4215 | my_friendly_abort (10); | |
4216 | } | |
4217 | continue; | |
4218 | no_context: | |
4219 | break; | |
4220 | } | |
4221 | } | |
4222 | } | |
4223 | return NULL_TREE; | |
4224 | } | |
4225 | ||
bd6dd845 | 4226 | #if 0 |
8d08fdba MS |
4227 | void |
4228 | set_current_level_tags_transparency (tags_transparent) | |
4229 | int tags_transparent; | |
4230 | { | |
4231 | current_binding_level->tag_transparent = tags_transparent; | |
4232 | } | |
bd6dd845 | 4233 | #endif |
8d08fdba MS |
4234 | |
4235 | /* Given a type, find the tag that was defined for it and return the tag name. | |
4236 | Otherwise return 0. However, the value can never be 0 | |
4237 | in the cases in which this is used. | |
4238 | ||
4239 | C++: If NAME is non-zero, this is the new name to install. This is | |
4240 | done when replacing anonymous tags with real tag names. */ | |
4241 | ||
4242 | static tree | |
4243 | lookup_tag_reverse (type, name) | |
4244 | tree type; | |
4245 | tree name; | |
4246 | { | |
4247 | register struct binding_level *level; | |
4248 | ||
4249 | for (level = current_binding_level; level; level = level->level_chain) | |
4250 | { | |
4251 | register tree tail; | |
4252 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
4253 | { | |
4254 | if (TREE_VALUE (tail) == type) | |
4255 | { | |
4256 | if (name) | |
4257 | TREE_PURPOSE (tail) = name; | |
4258 | return TREE_PURPOSE (tail); | |
4259 | } | |
4260 | } | |
4261 | } | |
4262 | return NULL_TREE; | |
4263 | } | |
8d08fdba MS |
4264 | \f |
4265 | /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). | |
4266 | Return the type value, or NULL_TREE if not found. */ | |
e92cc029 | 4267 | |
8d08fdba MS |
4268 | static tree |
4269 | lookup_nested_type (type, context) | |
4270 | tree type; | |
4271 | tree context; | |
4272 | { | |
4273 | if (context == NULL_TREE) | |
4274 | return NULL_TREE; | |
4275 | while (context) | |
4276 | { | |
4277 | switch (TREE_CODE (context)) | |
4278 | { | |
4279 | case TYPE_DECL: | |
4280 | { | |
4281 | tree ctype = TREE_TYPE (context); | |
4282 | tree match = value_member (type, CLASSTYPE_TAGS (ctype)); | |
4283 | if (match) | |
4284 | return TREE_VALUE (match); | |
4285 | context = DECL_CONTEXT (context); | |
4286 | ||
4287 | /* When we have a nested class whose member functions have | |
4288 | local types (e.g., a set of enums), we'll arrive here | |
4289 | with the DECL_CONTEXT as the actual RECORD_TYPE node for | |
4290 | the enclosing class. Instead, we want to make sure we | |
4291 | come back in here with the TYPE_DECL, not the RECORD_TYPE. */ | |
4292 | if (context && TREE_CODE (context) == RECORD_TYPE) | |
4293 | context = TREE_CHAIN (context); | |
4294 | } | |
4295 | break; | |
4296 | case FUNCTION_DECL: | |
e1cd6e56 MS |
4297 | if (TYPE_NAME (type) && TYPE_IDENTIFIER (type)) |
4298 | return lookup_name (TYPE_IDENTIFIER (type), 1); | |
4299 | return NULL_TREE; | |
8d08fdba MS |
4300 | default: |
4301 | my_friendly_abort (12); | |
4302 | } | |
4303 | } | |
4304 | return NULL_TREE; | |
4305 | } | |
4306 | ||
a9aedbc2 | 4307 | /* Look up NAME in the NAMESPACE. */ |
e92cc029 | 4308 | |
a9aedbc2 MS |
4309 | tree |
4310 | lookup_namespace_name (namespace, name) | |
4311 | tree namespace, name; | |
4312 | { | |
4313 | struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace); | |
fc378698 | 4314 | tree x = NULL_TREE; |
a9aedbc2 | 4315 | |
fc378698 MS |
4316 | #if 1 |
4317 | /* This searches just one level. */ | |
4318 | if (b) | |
a9aedbc2 MS |
4319 | { |
4320 | for (x = b->names; x; x = TREE_CHAIN (x)) | |
4321 | if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name) | |
4322 | break; | |
a9aedbc2 | 4323 | } |
fc378698 MS |
4324 | #else |
4325 | /* This searches all levels. */ | |
4326 | for (; b && !x; b = b->level_chain) | |
4327 | { | |
4328 | for (x = b->names; x; x = TREE_CHAIN (x)) | |
4329 | if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name) | |
4330 | break; | |
4331 | } | |
4332 | #endif | |
a9aedbc2 MS |
4333 | return x; |
4334 | } | |
4335 | ||
5566b478 MS |
4336 | tree |
4337 | make_typename_type (context, name) | |
4338 | tree context, name; | |
4339 | { | |
a80e4195 MS |
4340 | tree t, d; |
4341 | ||
653cc74a JM |
4342 | if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') |
4343 | name = TYPE_IDENTIFIER (name); | |
4344 | else if (TREE_CODE (name) == TYPE_DECL) | |
a80e4195 MS |
4345 | name = DECL_NAME (name); |
4346 | else if (TREE_CODE (name) != IDENTIFIER_NODE) | |
4347 | my_friendly_abort (2000); | |
5566b478 | 4348 | |
85b71cf2 | 4349 | if (! uses_template_parms (context) |
7fcdf4c2 | 4350 | || context == current_class_type) |
5566b478 | 4351 | { |
ffb690bd JM |
4352 | if (IS_AGGR_TYPE (context)) |
4353 | t = lookup_field (context, name, 0, 1); | |
4354 | else | |
4355 | t = NULL_TREE; | |
4356 | ||
5566b478 MS |
4357 | if (t == NULL_TREE) |
4358 | { | |
e76a2646 | 4359 | cp_error ("no type named `%#T' in `%#T'", name, context); |
5566b478 MS |
4360 | return error_mark_node; |
4361 | } | |
4362 | return TREE_TYPE (t); | |
4363 | } | |
4364 | ||
5156628f | 4365 | if (processing_template_decl) |
5566b478 MS |
4366 | push_obstacks (&permanent_obstack, &permanent_obstack); |
4367 | t = make_lang_type (TYPENAME_TYPE); | |
4368 | d = build_decl (TYPE_DECL, name, t); | |
5156628f | 4369 | if (processing_template_decl) |
5566b478 MS |
4370 | pop_obstacks (); |
4371 | ||
4372 | TYPE_CONTEXT (t) = context; | |
d2e5ee5c MS |
4373 | TYPE_NAME (TREE_TYPE (d)) = d; |
4374 | TYPE_STUB_DECL (TREE_TYPE (d)) = d; | |
5566b478 | 4375 | DECL_CONTEXT (d) = context; |
7fcdf4c2 | 4376 | CLASSTYPE_GOT_SEMICOLON (t) = 1; |
5566b478 MS |
4377 | |
4378 | return t; | |
4379 | } | |
4380 | ||
8d08fdba MS |
4381 | /* Look up NAME in the current binding level and its superiors in the |
4382 | namespace of variables, functions and typedefs. Return a ..._DECL | |
4383 | node of some kind representing its definition if there is only one | |
4384 | such declaration, or return a TREE_LIST with all the overloaded | |
4385 | definitions if there are many, or return 0 if it is undefined. | |
4386 | ||
4387 | If PREFER_TYPE is > 0, we prefer TYPE_DECLs. | |
a28e3c7f | 4388 | If PREFER_TYPE is -2, we're being called from yylex(). (UGLY) |
51c184be | 4389 | Otherwise we prefer non-TYPE_DECLs. */ |
8d08fdba | 4390 | |
824b9a4c | 4391 | static tree |
700f8a87 | 4392 | lookup_name_real (name, prefer_type, nonclass) |
8d08fdba | 4393 | tree name; |
700f8a87 | 4394 | int prefer_type, nonclass; |
8d08fdba MS |
4395 | { |
4396 | register tree val; | |
a28e3c7f | 4397 | int yylex = 0; |
e1cd6e56 | 4398 | tree from_obj = NULL_TREE; |
e76a2646 | 4399 | tree locval, classval; |
8d08fdba | 4400 | |
a28e3c7f MS |
4401 | if (prefer_type == -2) |
4402 | { | |
4403 | extern int looking_for_typename; | |
fc378698 | 4404 | tree type = NULL_TREE; |
a28e3c7f MS |
4405 | |
4406 | yylex = 1; | |
4407 | prefer_type = looking_for_typename; | |
e1cd6e56 | 4408 | |
653cc74a JM |
4409 | /* std:: becomes :: for now. */ |
4410 | if (got_scope == std_node) | |
4411 | got_scope = void_type_node; | |
4412 | ||
e1cd6e56 MS |
4413 | if (got_scope) |
4414 | type = got_scope; | |
dff6b454 | 4415 | else if (got_object != error_mark_node) |
e1cd6e56 | 4416 | type = got_object; |
a28e3c7f | 4417 | |
e1cd6e56 | 4418 | if (type) |
a28e3c7f | 4419 | { |
e1cd6e56 | 4420 | if (type == error_mark_node) |
f376e137 | 4421 | return error_mark_node; |
a80e4195 MS |
4422 | if (TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type)) |
4423 | type = TREE_TYPE (type); | |
5566b478 MS |
4424 | |
4425 | type = complete_type (type); | |
4426 | ||
4427 | if (type == void_type_node) | |
a28e3c7f | 4428 | val = IDENTIFIER_GLOBAL_VALUE (name); |
a9aedbc2 MS |
4429 | else if (TREE_CODE (type) == NAMESPACE_DECL) |
4430 | { | |
4431 | val = lookup_namespace_name (type, name); | |
4432 | } | |
5566b478 | 4433 | else if (! IS_AGGR_TYPE (type) |
5156628f MS |
4434 | || TREE_CODE (type) == TEMPLATE_TYPE_PARM |
4435 | || TREE_CODE (type) == TYPENAME_TYPE) | |
e92cc029 | 4436 | /* Someone else will give an error about this if needed. */ |
a28e3c7f | 4437 | val = NULL_TREE; |
e1cd6e56 | 4438 | else if (TYPE_BEING_DEFINED (type)) |
700f8a87 MS |
4439 | { |
4440 | val = IDENTIFIER_CLASS_VALUE (name); | |
e1cd6e56 | 4441 | if (val && DECL_CONTEXT (val) != type) |
700f8a87 MS |
4442 | { |
4443 | struct binding_level *b = class_binding_level; | |
4444 | for (val = NULL_TREE; b; b = b->level_chain) | |
4445 | { | |
4446 | tree t = purpose_member (name, b->class_shadowed); | |
4447 | if (t && TREE_VALUE (t) | |
e1cd6e56 | 4448 | && DECL_CONTEXT (TREE_VALUE (t)) == type) |
700f8a87 MS |
4449 | { |
4450 | val = TREE_VALUE (t); | |
4451 | break; | |
4452 | } | |
4453 | } | |
4454 | } | |
5566b478 | 4455 | if (val == NULL_TREE) |
e1cd6e56 | 4456 | val = lookup_field (type, name, 0, 1); |
700f8a87 | 4457 | } |
e1cd6e56 | 4458 | else if (type == current_class_type) |
a28e3c7f | 4459 | val = IDENTIFIER_CLASS_VALUE (name); |
a28e3c7f | 4460 | else |
e1cd6e56 | 4461 | val = lookup_field (type, name, 0, prefer_type); |
a28e3c7f | 4462 | } |
e1cd6e56 MS |
4463 | else |
4464 | val = NULL_TREE; | |
4465 | ||
85b71cf2 | 4466 | /* Add implicit 'typename' to scoped types from other classes. */ |
5156628f | 4467 | if (got_scope && processing_template_decl |
7fcdf4c2 | 4468 | && got_scope != current_class_type |
a80e4195 MS |
4469 | && uses_template_parms (got_scope) |
4470 | && val && TREE_CODE (val) == TYPE_DECL | |
4471 | && ! DECL_ARTIFICIAL (val)) | |
4472 | { | |
4473 | tree t = make_typename_type (got_scope, DECL_NAME (val)); | |
4474 | TREE_TYPE (t) = TREE_TYPE (val); | |
4475 | val = TYPE_MAIN_DECL (t); | |
4476 | } | |
a80e4195 | 4477 | |
594740f3 | 4478 | if (got_scope) |
e1cd6e56 | 4479 | goto done; |
594740f3 | 4480 | else if (got_object && val) |
e1cd6e56 | 4481 | from_obj = val; |
a28e3c7f | 4482 | } |
e76a2646 MS |
4483 | |
4484 | locval = classval = NULL_TREE; | |
4485 | ||
8d08fdba MS |
4486 | if (current_binding_level != global_binding_level |
4487 | && IDENTIFIER_LOCAL_VALUE (name)) | |
e76a2646 MS |
4488 | locval = IDENTIFIER_LOCAL_VALUE (name); |
4489 | ||
8d08fdba MS |
4490 | /* In C++ class fields are between local and global scope, |
4491 | just before the global scope. */ | |
e76a2646 | 4492 | if (current_class_type && ! nonclass) |
8d08fdba | 4493 | { |
e76a2646 MS |
4494 | classval = IDENTIFIER_CLASS_VALUE (name); |
4495 | if (classval == NULL_TREE && TYPE_BEING_DEFINED (current_class_type)) | |
700f8a87 MS |
4496 | /* Try to find values from base classes if we are presently |
4497 | defining a type. We are presently only interested in | |
4498 | TYPE_DECLs. */ | |
e76a2646 | 4499 | classval = lookup_field (current_class_type, name, 0, 1); |
8d08fdba MS |
4500 | |
4501 | /* yylex() calls this with -2, since we should never start digging for | |
4502 | the nested name at the point where we haven't even, for example, | |
4503 | created the COMPONENT_REF or anything like that. */ | |
e76a2646 MS |
4504 | if (classval == NULL_TREE) |
4505 | classval = lookup_nested_field (name, ! yylex); | |
85b71cf2 JM |
4506 | |
4507 | /* Add implicit 'typename' to types from base classes. */ | |
4508 | if (processing_template_decl | |
4509 | && classval && TREE_CODE (classval) == TYPE_DECL | |
4510 | && DECL_CONTEXT (classval) != current_class_type | |
4511 | && uses_template_parms (DECL_CONTEXT (classval)) | |
4512 | && ! DECL_ARTIFICIAL (classval)) | |
4513 | { | |
4514 | tree t = make_typename_type (DECL_CONTEXT (classval), | |
4515 | DECL_NAME (classval)); | |
4516 | TREE_TYPE (t) = TREE_TYPE (classval); | |
4517 | classval = TYPE_MAIN_DECL (t); | |
4518 | } | |
e76a2646 | 4519 | } |
8d08fdba | 4520 | |
e76a2646 MS |
4521 | if (locval && classval) |
4522 | { | |
4523 | if (current_scope () == current_function_decl | |
4524 | && ! hack_decl_function_context (current_function_decl)) | |
4525 | /* Not in a nested function. */ | |
4526 | val = locval; | |
4527 | else | |
4528 | { | |
4529 | /* This is incredibly horrible. The whole concept of | |
4530 | IDENTIFIER_LOCAL_VALUE / IDENTIFIER_CLASS_VALUE / | |
4531 | IDENTIFIER_GLOBAL_VALUE needs to be scrapped for local | |
4532 | classes. */ | |
4533 | tree lctx = hack_decl_function_context (locval); | |
4534 | tree cctx = hack_decl_function_context (classval); | |
4535 | ||
4536 | if (lctx == current_scope ()) | |
4537 | val = locval; | |
4538 | else if (lctx == cctx) | |
4539 | val = classval; | |
4540 | else | |
4541 | /* I don't know which is right; let's just guess for now. */ | |
4542 | val = locval; | |
4543 | } | |
8d08fdba | 4544 | } |
e76a2646 MS |
4545 | else if (locval) |
4546 | val = locval; | |
4547 | else if (classval) | |
4548 | val = classval; | |
8d08fdba MS |
4549 | else |
4550 | val = IDENTIFIER_GLOBAL_VALUE (name); | |
4551 | ||
a28e3c7f | 4552 | done: |
8d08fdba MS |
4553 | if (val) |
4554 | { | |
c91a56d2 | 4555 | /* This should only warn about types used in qualified-ids. */ |
e1cd6e56 | 4556 | if (from_obj && from_obj != val) |
5566b478 | 4557 | { |
c91a56d2 MS |
4558 | if (looking_for_typename && TREE_CODE (from_obj) == TYPE_DECL |
4559 | && TREE_CODE (val) == TYPE_DECL | |
4560 | && TREE_TYPE (from_obj) != TREE_TYPE (val)) | |
4561 | { | |
4562 | cp_pedwarn ("lookup of `%D' in the scope of `%#T' (`%#T')", | |
4563 | name, got_object, TREE_TYPE (from_obj)); | |
4564 | cp_pedwarn (" does not match lookup in the current scope (`%#T')", | |
4565 | TREE_TYPE (val)); | |
4566 | } | |
594740f3 MS |
4567 | |
4568 | val = from_obj; | |
5566b478 | 4569 | } |
e1cd6e56 | 4570 | |
a0a33927 MS |
4571 | if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template) |
4572 | || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0) | |
e1cd6e56 MS |
4573 | ; |
4574 | else if (IDENTIFIER_HAS_TYPE_VALUE (name)) | |
d2e5ee5c | 4575 | val = TYPE_MAIN_DECL (IDENTIFIER_TYPE_VALUE (name)); |
e1cd6e56 MS |
4576 | else if (TREE_TYPE (val) == error_mark_node) |
4577 | val = error_mark_node; | |
8d08fdba | 4578 | } |
e1cd6e56 MS |
4579 | else if (from_obj) |
4580 | val = from_obj; | |
8d08fdba MS |
4581 | |
4582 | return val; | |
4583 | } | |
4584 | ||
700f8a87 MS |
4585 | tree |
4586 | lookup_name_nonclass (name) | |
4587 | tree name; | |
4588 | { | |
4589 | return lookup_name_real (name, 0, 1); | |
4590 | } | |
4591 | ||
4592 | tree | |
4593 | lookup_name (name, prefer_type) | |
4594 | tree name; | |
4595 | int prefer_type; | |
4596 | { | |
4597 | return lookup_name_real (name, prefer_type, 0); | |
4598 | } | |
4599 | ||
8d08fdba MS |
4600 | /* Similar to `lookup_name' but look only at current binding level. */ |
4601 | ||
4602 | tree | |
4603 | lookup_name_current_level (name) | |
4604 | tree name; | |
4605 | { | |
4606 | register tree t = NULL_TREE; | |
4607 | ||
4608 | if (current_binding_level == global_binding_level) | |
4609 | { | |
4610 | t = IDENTIFIER_GLOBAL_VALUE (name); | |
4611 | ||
4612 | /* extern "C" function() */ | |
4613 | if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST) | |
4614 | t = TREE_VALUE (t); | |
4615 | } | |
4616 | else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE) | |
4617 | { | |
a4443a08 MS |
4618 | struct binding_level *b = current_binding_level; |
4619 | while (1) | |
4620 | { | |
4621 | for (t = b->names; t; t = TREE_CHAIN (t)) | |
e1cd6e56 | 4622 | if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name) |
a4443a08 MS |
4623 | goto out; |
4624 | if (b->keep == 2) | |
4625 | b = b->level_chain; | |
4626 | else | |
4627 | break; | |
4628 | } | |
4629 | out: | |
4630 | ; | |
8d08fdba MS |
4631 | } |
4632 | ||
4633 | return t; | |
4634 | } | |
4635 | \f | |
4636 | /* Arrange for the user to get a source line number, even when the | |
4637 | compiler is going down in flames, so that she at least has a | |
4638 | chance of working around problems in the compiler. We used to | |
4639 | call error(), but that let the segmentation fault continue | |
4640 | through; now, it's much more passive by asking them to send the | |
4641 | maintainers mail about the problem. */ | |
4642 | ||
4643 | static void | |
4644 | signal_catch (sig) | |
4645 | int sig; | |
4646 | { | |
4647 | signal (SIGSEGV, SIG_DFL); | |
4648 | #ifdef SIGIOT | |
4649 | signal (SIGIOT, SIG_DFL); | |
4650 | #endif | |
4651 | #ifdef SIGILL | |
4652 | signal (SIGILL, SIG_DFL); | |
4653 | #endif | |
4654 | #ifdef SIGABRT | |
4655 | signal (SIGABRT, SIG_DFL); | |
4656 | #endif | |
4657 | #ifdef SIGBUS | |
4658 | signal (SIGBUS, SIG_DFL); | |
4659 | #endif | |
4660 | my_friendly_abort (0); | |
4661 | } | |
4662 | ||
de22184b MS |
4663 | #if 0 |
4664 | /* Unused -- brendan 970107 */ | |
8d08fdba MS |
4665 | /* Array for holding types considered "built-in". These types |
4666 | are output in the module in which `main' is defined. */ | |
4667 | static tree *builtin_type_tdescs_arr; | |
4668 | static int builtin_type_tdescs_len, builtin_type_tdescs_max; | |
de22184b | 4669 | #endif |
8d08fdba MS |
4670 | |
4671 | /* Push the declarations of builtin types into the namespace. | |
4672 | RID_INDEX, if < RID_MAX is the index of the builtin type | |
4673 | in the array RID_POINTERS. NAME is the name used when looking | |
4674 | up the builtin type. TYPE is the _TYPE node for the builtin type. */ | |
4675 | ||
4676 | static void | |
4677 | record_builtin_type (rid_index, name, type) | |
4678 | enum rid rid_index; | |
4679 | char *name; | |
4680 | tree type; | |
4681 | { | |
4682 | tree rname = NULL_TREE, tname = NULL_TREE; | |
4683 | tree tdecl; | |
4684 | ||
4685 | if ((int) rid_index < (int) RID_MAX) | |
4686 | rname = ridpointers[(int) rid_index]; | |
4687 | if (name) | |
4688 | tname = get_identifier (name); | |
4689 | ||
4690 | TYPE_BUILT_IN (type) = 1; | |
4691 | ||
4692 | if (tname) | |
4693 | { | |
8d08fdba | 4694 | tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); |
8d08fdba MS |
4695 | set_identifier_type_value (tname, NULL_TREE); |
4696 | if ((int) rid_index < (int) RID_MAX) | |
4697 | IDENTIFIER_GLOBAL_VALUE (tname) = tdecl; | |
4698 | } | |
4699 | if (rname != NULL_TREE) | |
4700 | { | |
4701 | if (tname != NULL_TREE) | |
4702 | { | |
4703 | set_identifier_type_value (rname, NULL_TREE); | |
4704 | IDENTIFIER_GLOBAL_VALUE (rname) = tdecl; | |
4705 | } | |
4706 | else | |
4707 | { | |
8d08fdba | 4708 | tdecl = pushdecl (build_decl (TYPE_DECL, rname, type)); |
8d08fdba MS |
4709 | set_identifier_type_value (rname, NULL_TREE); |
4710 | } | |
4711 | } | |
8d08fdba MS |
4712 | } |
4713 | ||
8d08fdba MS |
4714 | /* Push overloaded decl, in global scope, with one argument so it |
4715 | can be used as a callback from define_function. */ | |
e92cc029 | 4716 | |
8d08fdba MS |
4717 | static void |
4718 | push_overloaded_decl_1 (x) | |
4719 | tree x; | |
4720 | { | |
4721 | push_overloaded_decl (x, 0); | |
4722 | } | |
4723 | ||
8ccc31eb MS |
4724 | #ifdef __GNUC__ |
4725 | __inline | |
4726 | #endif | |
6b5fbb55 MS |
4727 | tree |
4728 | auto_function (name, type, code) | |
8ccc31eb MS |
4729 | tree name, type; |
4730 | enum built_in_function code; | |
4731 | { | |
4732 | return define_function | |
49c249e1 | 4733 | (IDENTIFIER_POINTER (name), type, code, push_overloaded_decl_1, |
8ccc31eb MS |
4734 | IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type), |
4735 | 0))); | |
4736 | } | |
4737 | ||
8d08fdba MS |
4738 | /* Create the predefined scalar types of C, |
4739 | and some nodes representing standard constants (0, 1, (void *)0). | |
4740 | Initialize the global binding level. | |
4741 | Make definitions for built-in primitive functions. */ | |
4742 | ||
4743 | void | |
4744 | init_decl_processing () | |
4745 | { | |
4746 | tree decl; | |
de22184b | 4747 | register tree endlink, int_endlink, double_endlink, unsigned_endlink; |
8d08fdba | 4748 | tree fields[20]; |
8d08fdba | 4749 | /* Data type of memcpy. */ |
cffa8729 | 4750 | tree memcpy_ftype, strlen_ftype; |
8d08fdba MS |
4751 | int wchar_type_size; |
4752 | tree temp; | |
4753 | tree array_domain_type; | |
e1cd6e56 | 4754 | extern int flag_strict_prototype; |
5566b478 MS |
4755 | tree vb_off_identifier; |
4756 | /* Function type `char *(char *, char *)' and similar ones */ | |
4757 | tree string_ftype_ptr_ptr, int_ftype_string_string; | |
de22184b MS |
4758 | tree sizetype_endlink; |
4759 | tree ptr_ftype, ptr_ftype_unsigned, ptr_ftype_sizetype; | |
ca55abae | 4760 | tree void_ftype, void_ftype_int, void_ftype_ptr, ptr_ftype_void; |
8d08fdba MS |
4761 | |
4762 | /* Have to make these distinct before we try using them. */ | |
4763 | lang_name_cplusplus = get_identifier ("C++"); | |
4764 | lang_name_c = get_identifier ("C"); | |
4765 | ||
e1cd6e56 MS |
4766 | if (flag_strict_prototype == 2) |
4767 | { | |
4768 | if (pedantic) | |
4769 | strict_prototypes_lang_c = strict_prototypes_lang_cplusplus; | |
4770 | } | |
4771 | else | |
4772 | strict_prototypes_lang_c = flag_strict_prototype; | |
8926095f | 4773 | |
8d08fdba MS |
4774 | /* Initially, C. */ |
4775 | current_lang_name = lang_name_c; | |
4776 | ||
4777 | current_function_decl = NULL_TREE; | |
4778 | named_labels = NULL_TREE; | |
e349ee73 | 4779 | named_label_uses = NULL; |
8d08fdba MS |
4780 | current_binding_level = NULL_BINDING_LEVEL; |
4781 | free_binding_level = NULL_BINDING_LEVEL; | |
4782 | ||
42976354 | 4783 | #ifndef __CYGWIN32__ |
8d08fdba MS |
4784 | /* Because most segmentation signals can be traced back into user |
4785 | code, catch them and at least give the user a chance of working | |
e92cc029 | 4786 | around compiler bugs. */ |
8d08fdba MS |
4787 | signal (SIGSEGV, signal_catch); |
4788 | ||
4789 | /* We will also catch aborts in the back-end through signal_catch and | |
4790 | give the user a chance to see where the error might be, and to defeat | |
4791 | aborts in the back-end when there have been errors previously in their | |
e92cc029 | 4792 | code. */ |
8d08fdba MS |
4793 | #ifdef SIGIOT |
4794 | signal (SIGIOT, signal_catch); | |
4795 | #endif | |
4796 | #ifdef SIGILL | |
4797 | signal (SIGILL, signal_catch); | |
4798 | #endif | |
4799 | #ifdef SIGABRT | |
4800 | signal (SIGABRT, signal_catch); | |
4801 | #endif | |
4802 | #ifdef SIGBUS | |
4803 | signal (SIGBUS, signal_catch); | |
4804 | #endif | |
7834ab39 MS |
4805 | #else /* ndef __CYGWIN32__ */ |
4806 | /* Cygwin32 cannot handle catching signals other than | |
4807 | SIGABRT yet. We hope this will cease to be the case soon. */ | |
4808 | #ifdef SIGABRT | |
4809 | signal (SIGABRT, signal_catch); | |
4810 | #endif | |
4811 | #endif /* ndef __CYGWIN32__ */ | |
8d08fdba MS |
4812 | |
4813 | gcc_obstack_init (&decl_obstack); | |
8d08fdba MS |
4814 | |
4815 | /* Must lay these out before anything else gets laid out. */ | |
4816 | error_mark_node = make_node (ERROR_MARK); | |
4817 | TREE_PERMANENT (error_mark_node) = 1; | |
4818 | TREE_TYPE (error_mark_node) = error_mark_node; | |
4819 | error_mark_list = build_tree_list (error_mark_node, error_mark_node); | |
4820 | TREE_TYPE (error_mark_list) = error_mark_node; | |
4821 | ||
a28e3c7f MS |
4822 | /* Make the binding_level structure for global names. */ |
4823 | pushlevel (0); | |
8d08fdba MS |
4824 | global_binding_level = current_binding_level; |
4825 | ||
4826 | this_identifier = get_identifier (THIS_NAME); | |
4827 | in_charge_identifier = get_identifier (IN_CHARGE_NAME); | |
fc378698 MS |
4828 | ctor_identifier = get_identifier (CTOR_NAME); |
4829 | dtor_identifier = get_identifier (DTOR_NAME); | |
8d08fdba MS |
4830 | pfn_identifier = get_identifier (VTABLE_PFN_NAME); |
4831 | index_identifier = get_identifier (VTABLE_INDEX_NAME); | |
4832 | delta_identifier = get_identifier (VTABLE_DELTA_NAME); | |
4833 | delta2_identifier = get_identifier (VTABLE_DELTA2_NAME); | |
4834 | pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2"); | |
dff6b454 RK |
4835 | if (flag_handle_signatures) |
4836 | { | |
4837 | tag_identifier = get_identifier (SIGTABLE_TAG_NAME); | |
9dd70aa4 GB |
4838 | vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME); |
4839 | vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME); | |
dff6b454 | 4840 | } |
8d08fdba MS |
4841 | |
4842 | /* Define `int' and `char' first so that dbx will output them first. */ | |
4843 | ||
4844 | integer_type_node = make_signed_type (INT_TYPE_SIZE); | |
4845 | record_builtin_type (RID_INT, NULL_PTR, integer_type_node); | |
4846 | ||
4847 | /* Define `char', which is like either `signed char' or `unsigned char' | |
4848 | but not the same as either. */ | |
4849 | ||
beb53fb8 JM |
4850 | char_type_node |
4851 | = (flag_signed_char | |
4852 | ? make_signed_type (CHAR_TYPE_SIZE) | |
4853 | : make_unsigned_type (CHAR_TYPE_SIZE)); | |
8d08fdba MS |
4854 | record_builtin_type (RID_CHAR, "char", char_type_node); |
4855 | ||
4856 | long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); | |
4857 | record_builtin_type (RID_LONG, "long int", long_integer_type_node); | |
4858 | ||
4859 | unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); | |
4860 | record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); | |
4861 | ||
4862 | long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); | |
4863 | record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node); | |
4864 | record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); | |
4865 | ||
4866 | long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); | |
4867 | record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node); | |
4868 | ||
4869 | long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); | |
4870 | record_builtin_type (RID_MAX, "long long unsigned int", | |
4871 | long_long_unsigned_type_node); | |
4872 | record_builtin_type (RID_MAX, "long long unsigned", | |
4873 | long_long_unsigned_type_node); | |
4874 | ||
5156628f MS |
4875 | short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); |
4876 | record_builtin_type (RID_SHORT, "short int", short_integer_type_node); | |
4877 | short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); | |
4878 | record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); | |
4879 | record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); | |
4880 | ||
8d08fdba | 4881 | /* `unsigned long' is the standard type for sizeof. |
8d08fdba MS |
4882 | Note that stddef.h uses `unsigned long', |
4883 | and this must agree, even of long and int are the same size. */ | |
4884 | sizetype | |
4885 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))); | |
8d08fdba MS |
4886 | |
4887 | ptrdiff_type_node | |
4888 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); | |
4889 | ||
4890 | TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype; | |
4891 | TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype; | |
4892 | TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype; | |
4893 | TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype; | |
4894 | TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype; | |
4895 | TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype; | |
4896 | TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype; | |
5156628f MS |
4897 | TREE_TYPE (TYPE_SIZE (short_integer_type_node)) = sizetype; |
4898 | TREE_TYPE (TYPE_SIZE (short_unsigned_type_node)) = sizetype; | |
8d08fdba MS |
4899 | |
4900 | /* Define both `signed char' and `unsigned char'. */ | |
4901 | signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); | |
4902 | record_builtin_type (RID_MAX, "signed char", signed_char_type_node); | |
4903 | unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); | |
4904 | record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); | |
4905 | ||
4906 | /* These are types that type_for_size and type_for_mode use. */ | |
4907 | intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); | |
4908 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); | |
4909 | intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); | |
4910 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); | |
4911 | intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); | |
4912 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); | |
4913 | intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); | |
4914 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); | |
4915 | unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); | |
4916 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); | |
4917 | unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); | |
4918 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); | |
4919 | unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); | |
4920 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); | |
4921 | unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); | |
4922 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); | |
4923 | ||
4924 | float_type_node = make_node (REAL_TYPE); | |
4925 | TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; | |
4926 | record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node); | |
4927 | layout_type (float_type_node); | |
4928 | ||
4929 | double_type_node = make_node (REAL_TYPE); | |
4930 | if (flag_short_double) | |
4931 | TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; | |
4932 | else | |
4933 | TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; | |
4934 | record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node); | |
4935 | layout_type (double_type_node); | |
4936 | ||
4937 | long_double_type_node = make_node (REAL_TYPE); | |
4938 | TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; | |
4939 | record_builtin_type (RID_MAX, "long double", long_double_type_node); | |
4940 | layout_type (long_double_type_node); | |
4941 | ||
37c46b43 MS |
4942 | complex_integer_type_node = make_node (COMPLEX_TYPE); |
4943 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"), | |
4944 | complex_integer_type_node)); | |
4945 | TREE_TYPE (complex_integer_type_node) = integer_type_node; | |
4946 | layout_type (complex_integer_type_node); | |
4947 | ||
4948 | complex_float_type_node = make_node (COMPLEX_TYPE); | |
4949 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"), | |
4950 | complex_float_type_node)); | |
4951 | TREE_TYPE (complex_float_type_node) = float_type_node; | |
4952 | layout_type (complex_float_type_node); | |
4953 | ||
4954 | complex_double_type_node = make_node (COMPLEX_TYPE); | |
4955 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"), | |
4956 | complex_double_type_node)); | |
4957 | TREE_TYPE (complex_double_type_node) = double_type_node; | |
4958 | layout_type (complex_double_type_node); | |
4959 | ||
4960 | complex_long_double_type_node = make_node (COMPLEX_TYPE); | |
4961 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"), | |
4962 | complex_long_double_type_node)); | |
4963 | TREE_TYPE (complex_long_double_type_node) = long_double_type_node; | |
4964 | layout_type (complex_long_double_type_node); | |
4965 | ||
8d08fdba MS |
4966 | integer_zero_node = build_int_2 (0, 0); |
4967 | TREE_TYPE (integer_zero_node) = integer_type_node; | |
4968 | integer_one_node = build_int_2 (1, 0); | |
4969 | TREE_TYPE (integer_one_node) = integer_type_node; | |
4970 | integer_two_node = build_int_2 (2, 0); | |
4971 | TREE_TYPE (integer_two_node) = integer_type_node; | |
4972 | integer_three_node = build_int_2 (3, 0); | |
4973 | TREE_TYPE (integer_three_node) = integer_type_node; | |
8d08fdba | 4974 | |
255512c1 JM |
4975 | boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); |
4976 | TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); | |
4977 | record_builtin_type (RID_BOOL, "bool", boolean_type_node); | |
4978 | boolean_false_node = build_int_2 (0, 0); | |
4979 | TREE_TYPE (boolean_false_node) = boolean_type_node; | |
4980 | boolean_true_node = build_int_2 (1, 0); | |
4981 | TREE_TYPE (boolean_true_node) = boolean_type_node; | |
2986ae00 | 4982 | |
8d08fdba MS |
4983 | /* These are needed by stor-layout.c. */ |
4984 | size_zero_node = size_int (0); | |
4985 | size_one_node = size_int (1); | |
4986 | ||
e92cc029 MS |
4987 | signed_size_zero_node = build_int_2 (0, 0); |
4988 | TREE_TYPE (signed_size_zero_node) = make_signed_type (TYPE_PRECISION (sizetype)); | |
4989 | ||
8d08fdba MS |
4990 | void_type_node = make_node (VOID_TYPE); |
4991 | record_builtin_type (RID_VOID, NULL_PTR, void_type_node); | |
4992 | layout_type (void_type_node); /* Uses integer_zero_node. */ | |
4993 | void_list_node = build_tree_list (NULL_TREE, void_type_node); | |
4994 | TREE_PARMLIST (void_list_node) = 1; | |
4995 | ||
d11ad92e | 4996 | null_pointer_node = build_int_2 (0, 0); |
8d08fdba | 4997 | TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); |
d11ad92e MS |
4998 | layout_type (TREE_TYPE (null_pointer_node)); |
4999 | ||
5000 | if (flag_ansi) | |
5001 | TREE_TYPE (null_node) = type_for_size (POINTER_SIZE, 0); | |
5002 | else | |
5003 | TREE_TYPE (null_node) = build_pointer_type (void_type_node); | |
8d08fdba MS |
5004 | |
5005 | /* Used for expressions that do nothing, but are not errors. */ | |
5006 | void_zero_node = build_int_2 (0, 0); | |
5007 | TREE_TYPE (void_zero_node) = void_type_node; | |
5008 | ||
5009 | string_type_node = build_pointer_type (char_type_node); | |
beb53fb8 JM |
5010 | const_string_type_node |
5011 | = build_pointer_type (build_type_variant (char_type_node, 1, 0)); | |
6b5fbb55 | 5012 | #if 0 |
8d08fdba | 5013 | record_builtin_type (RID_MAX, NULL_PTR, string_type_node); |
6b5fbb55 | 5014 | #endif |
8d08fdba MS |
5015 | |
5016 | /* Make a type to be the domain of a few array types | |
5017 | whose domains don't really matter. | |
5018 | 200 is small enough that it always fits in size_t | |
5019 | and large enough that it can hold most function names for the | |
5020 | initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ | |
5021 | array_domain_type = build_index_type (build_int_2 (200, 0)); | |
5022 | ||
5023 | /* make a type for arrays of characters. | |
5024 | With luck nothing will ever really depend on the length of this | |
5025 | array type. */ | |
5026 | char_array_type_node | |
5027 | = build_array_type (char_type_node, array_domain_type); | |
5028 | /* Likewise for arrays of ints. */ | |
5029 | int_array_type_node | |
5030 | = build_array_type (integer_type_node, array_domain_type); | |
5031 | ||
5032 | /* This is just some anonymous class type. Nobody should ever | |
5033 | need to look inside this envelope. */ | |
5034 | class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE)); | |
5035 | ||
5036 | default_function_type | |
5037 | = build_function_type (integer_type_node, NULL_TREE); | |
8d08fdba MS |
5038 | |
5039 | ptr_type_node = build_pointer_type (void_type_node); | |
beb53fb8 JM |
5040 | const_ptr_type_node |
5041 | = build_pointer_type (build_type_variant (void_type_node, 1, 0)); | |
6b5fbb55 | 5042 | #if 0 |
8d08fdba | 5043 | record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node); |
6b5fbb55 | 5044 | #endif |
8d08fdba MS |
5045 | endlink = void_list_node; |
5046 | int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); | |
5047 | double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); | |
de22184b MS |
5048 | unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink); |
5049 | ||
5050 | ptr_ftype = build_function_type (ptr_type_node, NULL_TREE); | |
5051 | ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink); | |
5052 | sizetype_endlink = tree_cons (NULL_TREE, sizetype, endlink); | |
5053 | /* We realloc here because sizetype could be int or unsigned. S'ok. */ | |
5054 | ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink); | |
5055 | ||
5056 | void_ftype = build_function_type (void_type_node, endlink); | |
5057 | void_ftype_int = build_function_type (void_type_node, int_endlink); | |
5058 | void_ftype_ptr | |
5059 | = build_function_type (void_type_node, | |
5060 | tree_cons (NULL_TREE, ptr_type_node, endlink)); | |
824b9a4c MS |
5061 | void_ftype_ptr |
5062 | = build_exception_variant (void_ftype_ptr, | |
5063 | tree_cons (NULL_TREE, NULL_TREE, NULL_TREE)); | |
8d08fdba | 5064 | |
cffa8729 MS |
5065 | float_ftype_float |
5066 | = build_function_type (float_type_node, | |
5067 | tree_cons (NULL_TREE, float_type_node, endlink)); | |
5068 | ||
8d08fdba MS |
5069 | double_ftype_double |
5070 | = build_function_type (double_type_node, double_endlink); | |
5071 | ||
cffa8729 MS |
5072 | ldouble_ftype_ldouble |
5073 | = build_function_type (long_double_type_node, | |
5074 | tree_cons (NULL_TREE, long_double_type_node, | |
5075 | endlink)); | |
5076 | ||
8d08fdba MS |
5077 | double_ftype_double_double |
5078 | = build_function_type (double_type_node, | |
a28e3c7f MS |
5079 | tree_cons (NULL_TREE, double_type_node, |
5080 | double_endlink)); | |
8d08fdba MS |
5081 | |
5082 | int_ftype_int | |
5083 | = build_function_type (integer_type_node, int_endlink); | |
5084 | ||
5085 | long_ftype_long | |
5086 | = build_function_type (long_integer_type_node, | |
a28e3c7f MS |
5087 | tree_cons (NULL_TREE, long_integer_type_node, |
5088 | endlink)); | |
8d08fdba | 5089 | |
8d08fdba MS |
5090 | int_ftype_cptr_cptr_sizet |
5091 | = build_function_type (integer_type_node, | |
5092 | tree_cons (NULL_TREE, const_ptr_type_node, | |
5093 | tree_cons (NULL_TREE, const_ptr_type_node, | |
5094 | tree_cons (NULL_TREE, | |
5095 | sizetype, | |
5096 | endlink)))); | |
5097 | ||
8d08fdba MS |
5098 | string_ftype_ptr_ptr /* strcpy prototype */ |
5099 | = build_function_type (string_type_node, | |
5100 | tree_cons (NULL_TREE, string_type_node, | |
5101 | tree_cons (NULL_TREE, | |
5102 | const_string_type_node, | |
5103 | endlink))); | |
5104 | ||
8d08fdba MS |
5105 | int_ftype_string_string /* strcmp prototype */ |
5106 | = build_function_type (integer_type_node, | |
5107 | tree_cons (NULL_TREE, const_string_type_node, | |
5108 | tree_cons (NULL_TREE, | |
5109 | const_string_type_node, | |
5110 | endlink))); | |
5111 | ||
cffa8729 | 5112 | strlen_ftype /* strlen prototype */ |
8d08fdba MS |
5113 | = build_function_type (sizetype, |
5114 | tree_cons (NULL_TREE, const_string_type_node, | |
5115 | endlink)); | |
5116 | ||
8d08fdba | 5117 | memcpy_ftype /* memcpy prototype */ |
d22c8596 | 5118 | = build_function_type (ptr_type_node, |
8d08fdba MS |
5119 | tree_cons (NULL_TREE, ptr_type_node, |
5120 | tree_cons (NULL_TREE, const_ptr_type_node, | |
de22184b | 5121 | sizetype_endlink))); |
8d08fdba MS |
5122 | |
5123 | if (flag_huge_objects) | |
5124 | delta_type_node = long_integer_type_node; | |
5125 | else | |
5126 | delta_type_node = short_integer_type_node; | |
5127 | ||
b9620d0e | 5128 | builtin_function ("__builtin_constant_p", default_function_type, |
8d08fdba MS |
5129 | BUILT_IN_CONSTANT_P, NULL_PTR); |
5130 | ||
beb53fb8 JM |
5131 | builtin_return_address_fndecl |
5132 | = builtin_function ("__builtin_return_address", ptr_ftype_unsigned, | |
5133 | BUILT_IN_RETURN_ADDRESS, NULL_PTR); | |
8926095f | 5134 | |
de22184b | 5135 | builtin_function ("__builtin_frame_address", ptr_ftype_unsigned, |
8926095f MS |
5136 | BUILT_IN_FRAME_ADDRESS, NULL_PTR); |
5137 | ||
ca55abae JM |
5138 | ptr_ftype_void = build_function_type (ptr_type_node, endlink); |
5139 | builtin_function ("__builtin_fp", ptr_ftype_void, BUILT_IN_FP, NULL_PTR); | |
5140 | builtin_function ("__builtin_sp", ptr_ftype_void, BUILT_IN_SP, NULL_PTR); | |
5141 | ||
de22184b | 5142 | builtin_function ("__builtin_alloca", ptr_ftype_sizetype, |
8d08fdba | 5143 | BUILT_IN_ALLOCA, "alloca"); |
cffa8729 | 5144 | builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); |
00595019 MS |
5145 | /* Define alloca, ffs as builtins. |
5146 | Declare _exit just to mark it as volatile. */ | |
5147 | if (! flag_no_builtin && !flag_no_nonansi_builtin) | |
5148 | { | |
de22184b | 5149 | temp = builtin_function ("alloca", ptr_ftype_sizetype, |
00595019 MS |
5150 | BUILT_IN_ALLOCA, NULL_PTR); |
5151 | /* Suppress error if redefined as a non-function. */ | |
5152 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
00595019 MS |
5153 | temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); |
5154 | /* Suppress error if redefined as a non-function. */ | |
5155 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
de22184b | 5156 | temp = builtin_function ("_exit", void_ftype_int, |
00595019 MS |
5157 | NOT_BUILT_IN, NULL_PTR); |
5158 | TREE_THIS_VOLATILE (temp) = 1; | |
5159 | TREE_SIDE_EFFECTS (temp) = 1; | |
5160 | /* Suppress error if redefined as a non-function. */ | |
5161 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
5162 | } | |
8d08fdba | 5163 | |
cffa8729 MS |
5164 | builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); |
5165 | builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS, | |
5166 | NULL_PTR); | |
5167 | builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, | |
5168 | NULL_PTR); | |
5169 | builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, | |
5170 | NULL_PTR); | |
8d08fdba MS |
5171 | builtin_function ("__builtin_labs", long_ftype_long, |
5172 | BUILT_IN_LABS, NULL_PTR); | |
de22184b | 5173 | builtin_function ("__builtin_saveregs", ptr_ftype, |
8d08fdba | 5174 | BUILT_IN_SAVEREGS, NULL_PTR); |
8d08fdba MS |
5175 | builtin_function ("__builtin_classify_type", default_function_type, |
5176 | BUILT_IN_CLASSIFY_TYPE, NULL_PTR); | |
de22184b | 5177 | builtin_function ("__builtin_next_arg", ptr_ftype, |
8d08fdba | 5178 | BUILT_IN_NEXT_ARG, NULL_PTR); |
de22184b | 5179 | builtin_function ("__builtin_args_info", int_ftype_int, |
8d08fdba | 5180 | BUILT_IN_ARGS_INFO, NULL_PTR); |
eb66be0e MS |
5181 | builtin_function ("__builtin_setjmp", |
5182 | build_function_type (integer_type_node, | |
5183 | tree_cons (NULL_TREE, ptr_type_node, | |
5184 | endlink)), | |
5185 | BUILT_IN_SETJMP, NULL_PTR); | |
5186 | builtin_function ("__builtin_longjmp", | |
5187 | build_function_type (integer_type_node, | |
5188 | tree_cons (NULL_TREE, ptr_type_node, | |
5189 | tree_cons (NULL_TREE, | |
5190 | integer_type_node, | |
5191 | endlink))), | |
5192 | BUILT_IN_LONGJMP, NULL_PTR); | |
8d08fdba MS |
5193 | |
5194 | /* Untyped call and return. */ | |
de22184b | 5195 | builtin_function ("__builtin_apply_args", ptr_ftype, |
8d08fdba MS |
5196 | BUILT_IN_APPLY_ARGS, NULL_PTR); |
5197 | ||
5198 | temp = tree_cons (NULL_TREE, | |
5199 | build_pointer_type (build_function_type (void_type_node, | |
5200 | NULL_TREE)), | |
de22184b | 5201 | ptr_ftype_sizetype); |
8d08fdba MS |
5202 | builtin_function ("__builtin_apply", |
5203 | build_function_type (ptr_type_node, temp), | |
5204 | BUILT_IN_APPLY, NULL_PTR); | |
de22184b | 5205 | builtin_function ("__builtin_return", void_ftype_ptr, |
8d08fdba MS |
5206 | BUILT_IN_RETURN, NULL_PTR); |
5207 | ||
5208 | /* Currently under experimentation. */ | |
5209 | builtin_function ("__builtin_memcpy", memcpy_ftype, | |
5210 | BUILT_IN_MEMCPY, "memcpy"); | |
5211 | builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, | |
5212 | BUILT_IN_MEMCMP, "memcmp"); | |
5213 | builtin_function ("__builtin_strcmp", int_ftype_string_string, | |
5214 | BUILT_IN_STRCMP, "strcmp"); | |
5215 | builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, | |
5216 | BUILT_IN_STRCPY, "strcpy"); | |
cffa8729 | 5217 | builtin_function ("__builtin_strlen", strlen_ftype, |
8d08fdba | 5218 | BUILT_IN_STRLEN, "strlen"); |
cffa8729 MS |
5219 | builtin_function ("__builtin_sqrtf", float_ftype_float, |
5220 | BUILT_IN_FSQRT, "sqrtf"); | |
5221 | builtin_function ("__builtin_fsqrt", double_ftype_double, | |
5222 | BUILT_IN_FSQRT, NULL_PTR); | |
5223 | builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble, | |
5224 | BUILT_IN_FSQRT, "sqrtl"); | |
5225 | builtin_function ("__builtin_sinf", float_ftype_float, | |
5226 | BUILT_IN_SIN, "sinf"); | |
5227 | builtin_function ("__builtin_sin", double_ftype_double, | |
5228 | BUILT_IN_SIN, "sin"); | |
5229 | builtin_function ("__builtin_sinl", ldouble_ftype_ldouble, | |
5230 | BUILT_IN_SIN, "sinl"); | |
5231 | builtin_function ("__builtin_cosf", float_ftype_float, | |
5232 | BUILT_IN_COS, "cosf"); | |
5233 | builtin_function ("__builtin_cos", double_ftype_double, | |
5234 | BUILT_IN_COS, "cos"); | |
5235 | builtin_function ("__builtin_cosl", ldouble_ftype_ldouble, | |
5236 | BUILT_IN_COS, "cosl"); | |
8d08fdba MS |
5237 | |
5238 | if (!flag_no_builtin) | |
5239 | { | |
5240 | #if 0 /* These do not work well with libg++. */ | |
5241 | builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); | |
5242 | builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); | |
5243 | builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); | |
5244 | #endif | |
cffa8729 MS |
5245 | builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR); |
5246 | builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, | |
5247 | NULL_PTR); | |
8d08fdba MS |
5248 | builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); |
5249 | builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, | |
5250 | NULL_PTR); | |
cffa8729 MS |
5251 | builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, |
5252 | NULL_PTR); | |
a28e3c7f MS |
5253 | builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, |
5254 | NULL_PTR); | |
cffa8729 MS |
5255 | builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR); |
5256 | builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR); | |
5257 | builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR); | |
5258 | builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT, | |
5259 | NULL_PTR); | |
5260 | builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR); | |
8d08fdba | 5261 | builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); |
cffa8729 MS |
5262 | builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR); |
5263 | builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR); | |
8d08fdba | 5264 | builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); |
cffa8729 | 5265 | builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR); |
00595019 MS |
5266 | |
5267 | /* Declare these functions volatile | |
5268 | to avoid spurious "control drops through" warnings. */ | |
de22184b | 5269 | temp = builtin_function ("abort", void_ftype, |
00595019 MS |
5270 | NOT_BUILT_IN, NULL_PTR); |
5271 | TREE_THIS_VOLATILE (temp) = 1; | |
5272 | TREE_SIDE_EFFECTS (temp) = 1; | |
5273 | /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on | |
5274 | them... */ | |
5275 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
de22184b | 5276 | temp = builtin_function ("exit", void_ftype_int, |
00595019 MS |
5277 | NOT_BUILT_IN, NULL_PTR); |
5278 | TREE_THIS_VOLATILE (temp) = 1; | |
5279 | TREE_SIDE_EFFECTS (temp) = 1; | |
5280 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
8d08fdba MS |
5281 | } |
5282 | ||
5283 | #if 0 | |
5284 | /* Support for these has not been written in either expand_builtin | |
5285 | or build_function_call. */ | |
72b7eeff MS |
5286 | builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR); |
5287 | builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR); | |
a28e3c7f | 5288 | builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, |
72b7eeff | 5289 | NULL_PTR); |
cffa8729 MS |
5290 | builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, |
5291 | NULL_PTR); | |
a28e3c7f | 5292 | builtin_function ("__builtin_fmod", double_ftype_double_double, |
72b7eeff | 5293 | BUILT_IN_FMOD, NULL_PTR); |
a28e3c7f | 5294 | builtin_function ("__builtin_frem", double_ftype_double_double, |
72b7eeff | 5295 | BUILT_IN_FREM, NULL_PTR); |
cffa8729 MS |
5296 | builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, |
5297 | BUILT_IN_MEMSET, NULL_PTR); | |
a28e3c7f | 5298 | builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, |
72b7eeff | 5299 | NULL_PTR); |
a28e3c7f | 5300 | builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, |
72b7eeff | 5301 | NULL_PTR); |
8d08fdba MS |
5302 | #endif |
5303 | ||
5304 | /* C++ extensions */ | |
5305 | ||
5306 | unknown_type_node = make_node (UNKNOWN_TYPE); | |
8d08fdba MS |
5307 | decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"), |
5308 | unknown_type_node)); | |
5309 | /* Make sure the "unknown type" typedecl gets ignored for debug info. */ | |
5310 | DECL_IGNORED_P (decl) = 1; | |
39211cd5 | 5311 | TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; |
8d08fdba MS |
5312 | TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node); |
5313 | TYPE_ALIGN (unknown_type_node) = 1; | |
5314 | TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node); | |
5315 | /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ | |
5316 | TREE_TYPE (unknown_type_node) = unknown_type_node; | |
e92cc029 | 5317 | /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */ |
8d08fdba MS |
5318 | TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; |
5319 | TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; | |
5320 | ||
5321 | /* This is for handling opaque types in signatures. */ | |
5322 | opaque_type_node = copy_node (ptr_type_node); | |
5323 | TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node; | |
5324 | record_builtin_type (RID_MAX, 0, opaque_type_node); | |
5325 | ||
e92cc029 | 5326 | /* This is special for C++ so functions can be overloaded. */ |
8d08fdba MS |
5327 | wchar_type_node |
5328 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); | |
5329 | wchar_type_size = TYPE_PRECISION (wchar_type_node); | |
5330 | signed_wchar_type_node = make_signed_type (wchar_type_size); | |
5331 | unsigned_wchar_type_node = make_unsigned_type (wchar_type_size); | |
5332 | wchar_type_node | |
5333 | = TREE_UNSIGNED (wchar_type_node) | |
5334 | ? unsigned_wchar_type_node | |
5335 | : signed_wchar_type_node; | |
5336 | record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node); | |
5337 | ||
f376e137 MS |
5338 | /* Artificial declaration of wchar_t -- can be bashed */ |
5339 | wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"), | |
5340 | wchar_type_node); | |
5341 | pushdecl (wchar_decl_node); | |
5342 | ||
8d08fdba MS |
5343 | /* This is for wide string constants. */ |
5344 | wchar_array_type_node | |
5345 | = build_array_type (wchar_type_node, array_domain_type); | |
5346 | ||
8926095f | 5347 | if (flag_vtable_thunks) |
700f8a87 MS |
5348 | { |
5349 | /* Make sure we get a unique function type, so we can give | |
5350 | its pointer type a name. (This wins for gdb.) */ | |
5351 | tree vfunc_type = make_node (FUNCTION_TYPE); | |
5352 | TREE_TYPE (vfunc_type) = integer_type_node; | |
5353 | TYPE_ARG_TYPES (vfunc_type) = NULL_TREE; | |
5354 | layout_type (vfunc_type); | |
5355 | ||
5356 | vtable_entry_type = build_pointer_type (vfunc_type); | |
5357 | } | |
8926095f | 5358 | else |
700f8a87 MS |
5359 | { |
5360 | vtable_entry_type = make_lang_type (RECORD_TYPE); | |
5361 | fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, | |
5362 | delta_type_node); | |
5363 | fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, | |
5364 | delta_type_node); | |
5365 | fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, | |
5366 | ptr_type_node); | |
5367 | finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2, | |
5368 | double_type_node); | |
5369 | ||
5370 | /* Make this part of an invisible union. */ | |
5371 | fields[3] = copy_node (fields[2]); | |
5372 | TREE_TYPE (fields[3]) = delta_type_node; | |
5373 | DECL_NAME (fields[3]) = delta2_identifier; | |
5374 | DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node); | |
5375 | DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node); | |
5376 | TREE_UNSIGNED (fields[3]) = 0; | |
5377 | TREE_CHAIN (fields[2]) = fields[3]; | |
5378 | vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0); | |
5379 | } | |
5380 | record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type); | |
8d08fdba | 5381 | |
8d08fdba MS |
5382 | vtbl_type_node |
5383 | = build_array_type (vtable_entry_type, NULL_TREE); | |
5384 | layout_type (vtbl_type_node); | |
f376e137 | 5385 | vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0); |
8d08fdba MS |
5386 | record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node); |
5387 | ||
5388 | /* Simplify life by making a "sigtable_entry_type". Give its | |
5389 | fields names so that the debugger can use them. */ | |
5390 | ||
5391 | if (flag_handle_signatures) | |
5392 | { | |
5393 | sigtable_entry_type = make_lang_type (RECORD_TYPE); | |
dff6b454 RK |
5394 | fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier, |
5395 | delta_type_node); | |
9dd70aa4 | 5396 | fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier, |
dff6b454 | 5397 | delta_type_node); |
9dd70aa4 | 5398 | fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier, |
dff6b454 RK |
5399 | delta_type_node); |
5400 | fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier, | |
5401 | delta_type_node); | |
9dd70aa4 GB |
5402 | fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier, |
5403 | ptr_type_node); | |
5404 | ||
5405 | /* Set the alignment to the max of the alignment of ptr_type_node and | |
5406 | delta_type_node. Double alignment wastes a word on the Sparc. */ | |
5407 | finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4, | |
5408 | (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node)) | |
5409 | ? ptr_type_node | |
5410 | : delta_type_node); | |
dff6b454 RK |
5411 | |
5412 | /* Make this part of an invisible union. */ | |
9dd70aa4 GB |
5413 | fields[5] = copy_node (fields[4]); |
5414 | TREE_TYPE (fields[5]) = delta_type_node; | |
5415 | DECL_NAME (fields[5]) = vt_off_identifier; | |
5416 | DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node); | |
5417 | DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node); | |
5418 | TREE_UNSIGNED (fields[5]) = 0; | |
5419 | TREE_CHAIN (fields[4]) = fields[5]; | |
dff6b454 | 5420 | |
8d08fdba MS |
5421 | sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0); |
5422 | record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type); | |
5423 | } | |
5424 | ||
6633d636 MS |
5425 | std_node = build_decl (NAMESPACE_DECL, get_identifier ("std"), |
5426 | void_type_node); | |
5427 | pushdecl (std_node); | |
5428 | ||
db5ae43f MS |
5429 | #if 0 |
5430 | if (flag_rtti) | |
8d08fdba MS |
5431 | { |
5432 | /* Must build __t_desc type. Currently, type descriptors look like this: | |
5433 | ||
5434 | struct __t_desc | |
5435 | { | |
5436 | const char *name; | |
5437 | int size; | |
5438 | int bits; | |
5439 | struct __t_desc *points_to; | |
5440 | int ivars_count, meths_count; | |
5441 | struct __i_desc *ivars[]; | |
5442 | struct __m_desc *meths[]; | |
5443 | struct __t_desc *parents[]; | |
5444 | struct __t_desc *vbases[]; | |
5445 | int offsets[]; | |
5446 | }; | |
5447 | ||
5448 | ...as per Linton's paper. */ | |
5449 | ||
5450 | __t_desc_type_node = make_lang_type (RECORD_TYPE); | |
5451 | __i_desc_type_node = make_lang_type (RECORD_TYPE); | |
5452 | __m_desc_type_node = make_lang_type (RECORD_TYPE); | |
beb53fb8 JM |
5453 | __t_desc_array_type |
5454 | = build_array_type (build_pointer_type (__t_desc_type_node), | |
5455 | NULL_TREE); | |
5456 | __i_desc_array_type | |
5457 | = build_array_type (build_pointer_type (__i_desc_type_node), | |
5458 | NULL_TREE); | |
5459 | __m_desc_array_type | |
5460 | = build_array_type (build_pointer_type (__m_desc_type_node), | |
5461 | NULL_TREE); | |
8d08fdba MS |
5462 | |
5463 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), | |
5464 | string_type_node); | |
5465 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"), | |
5466 | unsigned_type_node); | |
5467 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"), | |
5468 | unsigned_type_node); | |
a28e3c7f MS |
5469 | fields[3] = build_lang_field_decl (FIELD_DECL, |
5470 | get_identifier ("points_to"), | |
f30432d7 | 5471 | build_pointer_type (__t_desc_type_node)); |
8d08fdba MS |
5472 | fields[4] = build_lang_field_decl (FIELD_DECL, |
5473 | get_identifier ("ivars_count"), | |
5474 | integer_type_node); | |
5475 | fields[5] = build_lang_field_decl (FIELD_DECL, | |
5476 | get_identifier ("meths_count"), | |
5477 | integer_type_node); | |
5478 | fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"), | |
5479 | build_pointer_type (__i_desc_array_type)); | |
5480 | fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"), | |
5481 | build_pointer_type (__m_desc_array_type)); | |
5482 | fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"), | |
5483 | build_pointer_type (__t_desc_array_type)); | |
5484 | fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"), | |
5485 | build_pointer_type (__t_desc_array_type)); | |
5486 | fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"), | |
5487 | build_pointer_type (integer_type_node)); | |
5488 | finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node); | |
5489 | ||
5490 | /* ivar descriptors look like this: | |
5491 | ||
5492 | struct __i_desc | |
5493 | { | |
5494 | const char *name; | |
5495 | int offset; | |
5496 | struct __t_desc *type; | |
5497 | }; | |
5498 | */ | |
5499 | ||
5500 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), | |
5501 | string_type_node); | |
5502 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"), | |
5503 | integer_type_node); | |
5504 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"), | |
f30432d7 | 5505 | build_pointer_type (__t_desc_type_node)); |
a28e3c7f MS |
5506 | finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, |
5507 | integer_type_node); | |
8d08fdba MS |
5508 | |
5509 | /* method descriptors look like this: | |
5510 | ||
5511 | struct __m_desc | |
5512 | { | |
5513 | const char *name; | |
5514 | int vindex; | |
5515 | struct __t_desc *vcontext; | |
5516 | struct __t_desc *return_type; | |
5517 | void (*address)(); | |
5518 | short parm_count; | |
5519 | short required_parms; | |
5520 | struct __t_desc *parm_types[]; | |
5521 | }; | |
5522 | */ | |
5523 | ||
5524 | fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), | |
5525 | string_type_node); | |
5526 | fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"), | |
5527 | integer_type_node); | |
5528 | fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"), | |
f30432d7 | 5529 | build_pointer_type (__t_desc_type_node)); |
8d08fdba | 5530 | fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"), |
f30432d7 | 5531 | build_pointer_type (__t_desc_type_node)); |
8d08fdba MS |
5532 | fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"), |
5533 | build_pointer_type (default_function_type)); | |
5534 | fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"), | |
5535 | short_integer_type_node); | |
5536 | fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"), | |
5537 | short_integer_type_node); | |
5538 | fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"), | |
f30432d7 | 5539 | build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE))); |
a28e3c7f MS |
5540 | finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, |
5541 | integer_type_node); | |
8d08fdba | 5542 | } |
db5ae43f MS |
5543 | #endif /*flag_rtti*/ |
5544 | ||
5545 | /* Now, C++. */ | |
5546 | current_lang_name = lang_name_cplusplus; | |
8d08fdba | 5547 | |
de22184b | 5548 | auto_function (ansi_opname[(int) NEW_EXPR], ptr_ftype_sizetype, |
8d08fdba | 5549 | NOT_BUILT_IN); |
de22184b | 5550 | auto_function (ansi_opname[(int) VEC_NEW_EXPR], ptr_ftype_sizetype, |
a28e3c7f | 5551 | NOT_BUILT_IN); |
de22184b | 5552 | auto_function (ansi_opname[(int) DELETE_EXPR], void_ftype_ptr, |
8d08fdba | 5553 | NOT_BUILT_IN); |
de22184b | 5554 | auto_function (ansi_opname[(int) VEC_DELETE_EXPR], void_ftype_ptr, |
a28e3c7f | 5555 | NOT_BUILT_IN); |
8d08fdba MS |
5556 | |
5557 | abort_fndecl | |
de22184b | 5558 | = define_function ("__pure_virtual", void_ftype, |
8d08fdba MS |
5559 | NOT_BUILT_IN, 0, 0); |
5560 | ||
8d08fdba MS |
5561 | /* Perform other language dependent initializations. */ |
5562 | init_class_processing (); | |
5563 | init_init_processing (); | |
5564 | init_search_processing (); | |
6b5fbb55 | 5565 | init_rtti_processing (); |
8d08fdba | 5566 | |
6467930b | 5567 | if (flag_exceptions) |
8d2733ca | 5568 | init_exception_processing (); |
8d08fdba MS |
5569 | if (flag_no_inline) |
5570 | { | |
5571 | flag_inline_functions = 0; | |
8d08fdba | 5572 | } |
9e9ff709 | 5573 | |
7fcdf4c2 | 5574 | if (! supports_one_only ()) |
72b7eeff | 5575 | flag_weak = 0; |
8d08fdba MS |
5576 | |
5577 | /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ | |
5578 | declare_function_name (); | |
5579 | ||
5580 | /* Prepare to check format strings against argument lists. */ | |
5581 | init_function_format_info (); | |
5582 | } | |
5583 | ||
e92cc029 | 5584 | /* initialize type descriptor type node of various rtti type. */ |
db5ae43f MS |
5585 | |
5586 | int | |
5587 | init_type_desc() | |
5588 | { | |
5589 | tree tdecl; | |
5590 | ||
5591 | tdecl = lookup_name (get_identifier ("type_info"), 0); | |
5592 | if (tdecl == NULL_TREE) | |
5593 | return 0; | |
fc378698 | 5594 | __t_desc_type_node = TREE_TYPE (tdecl); |
5566b478 | 5595 | #if 0 |
db5ae43f | 5596 | __tp_desc_type_node = build_pointer_type (__t_desc_type_node); |
5566b478 | 5597 | #endif |
db5ae43f MS |
5598 | |
5599 | #if 0 | |
5600 | tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0); | |
5601 | if (tdecl == NULL_TREE) | |
5602 | return 0; | |
5603 | __baselist_desc_type_node = TREE_TYPE (tdecl); | |
5604 | #endif | |
5605 | ||
5606 | tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0); | |
5607 | if (tdecl == NULL_TREE) | |
5608 | return 0; | |
5609 | __bltn_desc_type_node = TREE_TYPE (tdecl); | |
5610 | ||
5611 | tdecl = lookup_name (get_identifier ("__user_type_info"), 0); | |
5612 | if (tdecl == NULL_TREE) | |
5613 | return 0; | |
5614 | __user_desc_type_node = TREE_TYPE (tdecl); | |
5615 | ||
5616 | tdecl = lookup_name (get_identifier ("__class_type_info"), 0); | |
5617 | if (tdecl == NULL_TREE) | |
5618 | return 0; | |
5619 | __class_desc_type_node = TREE_TYPE (tdecl); | |
5620 | ||
5621 | tdecl = lookup_field (__class_desc_type_node, | |
5622 | get_identifier ("access_mode"), 0, 0); | |
5623 | if (tdecl == NULL_TREE) | |
5624 | return 0; | |
5625 | __access_mode_type_node = TREE_TYPE (tdecl); | |
5626 | ||
5627 | tdecl = lookup_name (get_identifier ("__attr_type_info"), 0); | |
5628 | if (tdecl == NULL_TREE) | |
5629 | return 0; | |
5630 | __attr_desc_type_node = TREE_TYPE (tdecl); | |
5631 | ||
5632 | tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0); | |
5633 | if (tdecl == NULL_TREE) | |
5634 | return 0; | |
5635 | __ptr_desc_type_node = TREE_TYPE (tdecl); | |
5636 | ||
5637 | tdecl = lookup_name (get_identifier ("__func_type_info"), 0); | |
5638 | if (tdecl == NULL_TREE) | |
5639 | return 0; | |
5640 | __func_desc_type_node = TREE_TYPE (tdecl); | |
5641 | ||
5642 | tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0); | |
5643 | if (tdecl == NULL_TREE) | |
5644 | return 0; | |
5645 | __ptmf_desc_type_node = TREE_TYPE (tdecl); | |
5646 | ||
5647 | tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0); | |
5648 | if (tdecl == NULL_TREE) | |
5649 | return 0; | |
5650 | __ptmd_desc_type_node = TREE_TYPE (tdecl); | |
5651 | ||
5652 | return 1; | |
5653 | } | |
8d08fdba MS |
5654 | /* Make a definition for a builtin function named NAME and whose data type |
5655 | is TYPE. TYPE should be a function type with argument types. | |
5656 | FUNCTION_CODE tells later passes how to compile calls to this function. | |
5657 | See tree.h for its possible values. | |
5658 | ||
5659 | If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, | |
5660 | the name to be called if we can't opencode the function. */ | |
5661 | ||
5662 | tree | |
5663 | define_function (name, type, function_code, pfn, library_name) | |
5664 | char *name; | |
5665 | tree type; | |
5666 | enum built_in_function function_code; | |
49c249e1 | 5667 | void (*pfn) PROTO((tree)); |
8d08fdba MS |
5668 | char *library_name; |
5669 | { | |
5670 | tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); | |
5671 | DECL_EXTERNAL (decl) = 1; | |
5672 | TREE_PUBLIC (decl) = 1; | |
863adfc0 | 5673 | DECL_ARTIFICIAL (decl) = 1; |
8d08fdba MS |
5674 | |
5675 | /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, | |
5676 | we cannot change DECL_ASSEMBLER_NAME until we have installed this | |
5677 | function in the namespace. */ | |
5678 | if (pfn) (*pfn) (decl); | |
5679 | if (library_name) | |
5680 | DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); | |
5681 | make_function_rtl (decl); | |
5682 | if (function_code != NOT_BUILT_IN) | |
5683 | { | |
5684 | DECL_BUILT_IN (decl) = 1; | |
39211cd5 | 5685 | DECL_FUNCTION_CODE (decl) = function_code; |
8d08fdba MS |
5686 | } |
5687 | return decl; | |
5688 | } | |
5689 | \f | |
5690 | /* Called when a declaration is seen that contains no names to declare. | |
5691 | If its type is a reference to a structure, union or enum inherited | |
5692 | from a containing scope, shadow that tag name for the current scope | |
5693 | with a forward reference. | |
5694 | If its type defines a new named structure or union | |
5695 | or defines an enum, it is valid but we need not do anything here. | |
5696 | Otherwise, it is an error. | |
5697 | ||
5698 | C++: may have to grok the declspecs to learn about static, | |
5699 | complain for anonymous unions. */ | |
5700 | ||
5701 | void | |
5702 | shadow_tag (declspecs) | |
5703 | tree declspecs; | |
5704 | { | |
5705 | int found_tag = 0; | |
2986ae00 | 5706 | tree ob_modifier = NULL_TREE; |
8d08fdba MS |
5707 | register tree link; |
5708 | register enum tree_code code, ok_code = ERROR_MARK; | |
5709 | register tree t = NULL_TREE; | |
5710 | ||
5711 | for (link = declspecs; link; link = TREE_CHAIN (link)) | |
5712 | { | |
5713 | register tree value = TREE_VALUE (link); | |
5714 | ||
5715 | code = TREE_CODE (value); | |
5716 | if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE) | |
8d08fdba | 5717 | { |
d2e5ee5c | 5718 | my_friendly_assert (TYPE_MAIN_DECL (value) != NULL_TREE, 261); |
8d08fdba | 5719 | |
fc378698 | 5720 | if (IS_AGGR_TYPE (value) && CLASSTYPE_USE_TEMPLATE (value)) |
5566b478 MS |
5721 | { |
5722 | if (CLASSTYPE_IMPLICIT_INSTANTIATION (value) | |
5723 | && TYPE_SIZE (value) == NULL_TREE) | |
73aad9b9 JM |
5724 | { |
5725 | SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (value); | |
5156628f | 5726 | if (processing_template_decl) |
73aad9b9 JM |
5727 | push_template_decl (TYPE_MAIN_DECL (value)); |
5728 | } | |
5566b478 MS |
5729 | else if (CLASSTYPE_TEMPLATE_INSTANTIATION (value)) |
5730 | cp_error ("specialization after instantiation of `%T'", value); | |
5731 | } | |
5732 | ||
b8bca6f2 JM |
5733 | t = value; |
5734 | ok_code = code; | |
5735 | found_tag++; | |
8d08fdba MS |
5736 | } |
5737 | else if (value == ridpointers[(int) RID_STATIC] | |
2986ae00 MS |
5738 | || value == ridpointers[(int) RID_EXTERN] |
5739 | || value == ridpointers[(int) RID_AUTO] | |
28cbf42c MS |
5740 | || value == ridpointers[(int) RID_REGISTER] |
5741 | || value == ridpointers[(int) RID_INLINE] | |
5742 | || value == ridpointers[(int) RID_VIRTUAL] | |
5743 | || value == ridpointers[(int) RID_EXPLICIT]) | |
2986ae00 | 5744 | ob_modifier = value; |
8d08fdba MS |
5745 | } |
5746 | ||
5747 | /* This is where the variables in an anonymous union are | |
5748 | declared. An anonymous union declaration looks like: | |
5749 | union { ... } ; | |
5750 | because there is no declarator after the union, the parser | |
5751 | sends that declaration here. */ | |
5752 | if (ok_code == UNION_TYPE | |
5753 | && t != NULL_TREE | |
5754 | && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE | |
5755 | && ANON_AGGRNAME_P (TYPE_NAME (t))) | |
5756 | || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL | |
5757 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))) | |
5758 | { | |
d2e5ee5c | 5759 | /* See also grok_x_components. */ |
d2e5ee5c MS |
5760 | tree *q; |
5761 | ||
5762 | /* Wipe out memory of synthesized methods */ | |
5763 | TYPE_HAS_CONSTRUCTOR (t) = 0; | |
5764 | TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0; | |
5765 | TYPE_HAS_INIT_REF (t) = 0; | |
5766 | TYPE_HAS_CONST_INIT_REF (t) = 0; | |
5767 | TYPE_HAS_ASSIGN_REF (t) = 0; | |
5768 | TYPE_HAS_ASSIGNMENT (t) = 0; | |
5769 | TYPE_HAS_CONST_ASSIGN_REF (t) = 0; | |
5770 | ||
5771 | q = &TYPE_METHODS (t); | |
5772 | while (*q) | |
5773 | { | |
5774 | if (DECL_ARTIFICIAL (*q)) | |
5775 | *q = TREE_CHAIN (*q); | |
5776 | else | |
5777 | q = &TREE_CHAIN (*q); | |
5778 | } | |
f49422da | 5779 | |
8d08fdba MS |
5780 | /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have |
5781 | function members. */ | |
d2e5ee5c MS |
5782 | if (TYPE_METHODS (t)) |
5783 | error ("an anonymous union cannot have function members"); | |
c91a56d2 | 5784 | |
8d08fdba MS |
5785 | if (TYPE_FIELDS (t)) |
5786 | { | |
a28e3c7f | 5787 | tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, |
c11b6f21 | 5788 | NULL_TREE); |
8d08fdba MS |
5789 | finish_anon_union (decl); |
5790 | } | |
8d08fdba MS |
5791 | } |
5792 | else | |
5793 | { | |
5794 | /* Anonymous unions are objects, that's why we only check for | |
2986ae00 | 5795 | inappropriate specifiers in this branch. */ |
28cbf42c | 5796 | |
2986ae00 | 5797 | if (ob_modifier) |
28cbf42c MS |
5798 | { |
5799 | if (ob_modifier == ridpointers[(int) RID_INLINE] | |
5800 | || ob_modifier == ridpointers[(int) RID_VIRTUAL]) | |
5801 | cp_error ("`%D' can only be specified for functions", ob_modifier); | |
5802 | else if (ob_modifier == ridpointers[(int) RID_EXPLICIT]) | |
5803 | cp_error ("`%D' can only be specified for constructors", | |
5804 | ob_modifier); | |
5805 | else | |
5806 | cp_error ("`%D' can only be specified for objects and functions", | |
5807 | ob_modifier); | |
5808 | } | |
8d08fdba | 5809 | |
b8bca6f2 | 5810 | if (found_tag == 0) |
2986ae00 | 5811 | pedwarn ("abstract declarator used as declaration"); |
b8bca6f2 | 5812 | else if (found_tag > 1) |
2986ae00 | 5813 | pedwarn ("multiple types in one declaration"); |
8d08fdba MS |
5814 | } |
5815 | } | |
5816 | \f | |
5817 | /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ | |
5818 | ||
5819 | tree | |
5820 | groktypename (typename) | |
5821 | tree typename; | |
5822 | { | |
5823 | if (TREE_CODE (typename) != TREE_LIST) | |
5824 | return typename; | |
5825 | return grokdeclarator (TREE_VALUE (typename), | |
5826 | TREE_PURPOSE (typename), | |
c11b6f21 | 5827 | TYPENAME, 0, NULL_TREE); |
8d08fdba MS |
5828 | } |
5829 | ||
5830 | /* Decode a declarator in an ordinary declaration or data definition. | |
5831 | This is called as soon as the type information and variable name | |
5832 | have been parsed, before parsing the initializer if any. | |
5833 | Here we create the ..._DECL node, fill in its type, | |
5834 | and put it on the list of decls for the current context. | |
5835 | The ..._DECL node is returned as the value. | |
5836 | ||
5837 | Exception: for arrays where the length is not specified, | |
82580166 | 5838 | the type is left null, to be filled in by `cp_finish_decl'. |
8d08fdba MS |
5839 | |
5840 | Function definitions do not come here; they go to start_function | |
5841 | instead. However, external and forward declarations of functions | |
5842 | do go through here. Structure field declarations are done by | |
5843 | grokfield and not through here. */ | |
5844 | ||
5845 | /* Set this to zero to debug not using the temporary obstack | |
5846 | to parse initializers. */ | |
5847 | int debug_temp_inits = 1; | |
5848 | ||
5849 | tree | |
c11b6f21 | 5850 | start_decl (declarator, declspecs, initialized) |
8d08fdba MS |
5851 | tree declarator, declspecs; |
5852 | int initialized; | |
8d08fdba MS |
5853 | { |
5854 | register tree decl; | |
5855 | register tree type, tem; | |
5856 | tree context; | |
5857 | extern int have_extern_spec; | |
5858 | extern int used_extern_spec; | |
5859 | ||
5566b478 MS |
5860 | #if 0 |
5861 | /* See code below that used this. */ | |
8d08fdba | 5862 | int init_written = initialized; |
5566b478 | 5863 | #endif |
8d08fdba | 5864 | |
e92cc029 | 5865 | /* This should only be done once on the top most decl. */ |
8d08fdba MS |
5866 | if (have_extern_spec && !used_extern_spec) |
5867 | { | |
a28e3c7f MS |
5868 | declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), |
5869 | declspecs); | |
8d08fdba MS |
5870 | used_extern_spec = 1; |
5871 | } | |
5872 | ||
c11b6f21 | 5873 | decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, |
f30432d7 | 5874 | NULL_TREE); |
8d08fdba MS |
5875 | if (decl == NULL_TREE || decl == void_type_node) |
5876 | return NULL_TREE; | |
5877 | ||
5878 | type = TREE_TYPE (decl); | |
5879 | ||
5880 | /* Don't lose if destructors must be executed at file-level. */ | |
5156628f | 5881 | if (! processing_template_decl && TREE_STATIC (decl) |
ec255269 | 5882 | && TYPE_NEEDS_DESTRUCTOR (complete_type (type)) |
8d08fdba MS |
5883 | && !TREE_PERMANENT (decl)) |
5884 | { | |
5885 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
5886 | decl = copy_node (decl); | |
5887 | if (TREE_CODE (type) == ARRAY_TYPE) | |
5888 | { | |
5889 | tree itype = TYPE_DOMAIN (type); | |
5890 | if (itype && ! TREE_PERMANENT (itype)) | |
5891 | { | |
5892 | itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype))); | |
5893 | type = build_cplus_array_type (TREE_TYPE (type), itype); | |
5894 | TREE_TYPE (decl) = type; | |
5895 | } | |
5896 | } | |
5897 | pop_obstacks (); | |
5898 | } | |
5899 | ||
8d08fdba MS |
5900 | context |
5901 | = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) | |
5902 | ? DECL_CLASS_CONTEXT (decl) | |
5903 | : DECL_CONTEXT (decl); | |
5904 | ||
8d08fdba MS |
5905 | if (initialized) |
5906 | /* Is it valid for this decl to have an initializer at all? | |
5907 | If not, set INITIALIZED to zero, which will indirectly | |
82580166 | 5908 | tell `cp_finish_decl' to ignore the initializer once it is parsed. */ |
8d08fdba MS |
5909 | switch (TREE_CODE (decl)) |
5910 | { | |
5911 | case TYPE_DECL: | |
5912 | /* typedef foo = bar means give foo the same type as bar. | |
82580166 | 5913 | We haven't parsed bar yet, so `cp_finish_decl' will fix that up. |
8d08fdba MS |
5914 | Any other case of an initialization in a TYPE_DECL is an error. */ |
5915 | if (pedantic || list_length (declspecs) > 1) | |
5916 | { | |
5917 | cp_error ("typedef `%D' is initialized", decl); | |
5918 | initialized = 0; | |
5919 | } | |
5920 | break; | |
5921 | ||
5922 | case FUNCTION_DECL: | |
5923 | cp_error ("function `%#D' is initialized like a variable", decl); | |
5924 | initialized = 0; | |
5925 | break; | |
5926 | ||
5927 | default: | |
5156628f | 5928 | if (! processing_template_decl) |
8d08fdba | 5929 | { |
bd6dd845 | 5930 | if (type != error_mark_node) |
5156628f | 5931 | { |
bd6dd845 MS |
5932 | if (TYPE_SIZE (type) != NULL_TREE |
5933 | && ! TREE_CONSTANT (TYPE_SIZE (type))) | |
5934 | { | |
5935 | cp_error | |
5936 | ("variable-sized object `%D' may not be initialized", | |
5937 | decl); | |
5938 | initialized = 0; | |
5939 | } | |
5156628f | 5940 | |
bd6dd845 MS |
5941 | if (TREE_CODE (type) == ARRAY_TYPE |
5942 | && TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) | |
5943 | { | |
5944 | cp_error | |
5945 | ("elements of array `%#D' have incomplete type", decl); | |
5946 | initialized = 0; | |
5947 | } | |
5156628f | 5948 | } |
8d08fdba MS |
5949 | } |
5950 | } | |
5951 | ||
8d08fdba MS |
5952 | if (initialized) |
5953 | { | |
a9aedbc2 | 5954 | if (! toplevel_bindings_p () |
8d08fdba MS |
5955 | && DECL_EXTERNAL (decl)) |
5956 | cp_warning ("declaration of `%#D' has `extern' and is initialized", | |
5957 | decl); | |
5958 | DECL_EXTERNAL (decl) = 0; | |
5566b478 | 5959 | if (toplevel_bindings_p ()) |
8d08fdba MS |
5960 | TREE_STATIC (decl) = 1; |
5961 | ||
5962 | /* Tell `pushdecl' this is an initialized decl | |
5963 | even though we don't yet have the initializer expression. | |
82580166 | 5964 | Also tell `cp_finish_decl' it may store the real initializer. */ |
8d08fdba MS |
5965 | DECL_INITIAL (decl) = error_mark_node; |
5966 | } | |
5967 | ||
5566b478 | 5968 | if (context && TYPE_SIZE (complete_type (context)) != NULL_TREE) |
5b605f68 MS |
5969 | { |
5970 | if (TREE_CODE (decl) == VAR_DECL) | |
5971 | { | |
5972 | tree field = lookup_field (context, DECL_NAME (decl), 0, 0); | |
5973 | if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) | |
5974 | cp_error ("`%#D' is not a static member of `%#T'", decl, context); | |
e349ee73 MS |
5975 | else |
5976 | { | |
5977 | if (DECL_CONTEXT (field) != context) | |
5978 | cp_pedwarn ("ANSI C++ does not permit `%T::%D' to be defined as `%T::%D'", DECL_CONTEXT (field), DECL_NAME (decl), context, DECL_NAME (decl)); | |
5979 | if (duplicate_decls (decl, field)) | |
5980 | decl = field; | |
5981 | } | |
5b605f68 | 5982 | } |
f30432d7 MS |
5983 | else |
5984 | { | |
5566b478 | 5985 | tree field = check_classfn (context, decl); |
f30432d7 MS |
5986 | if (field && duplicate_decls (decl, field)) |
5987 | decl = field; | |
5988 | } | |
5989 | ||
5990 | /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */ | |
5b605f68 MS |
5991 | if (DECL_LANG_SPECIFIC (decl)) |
5992 | DECL_IN_AGGR_P (decl) = 0; | |
f30432d7 MS |
5993 | if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context)) |
5994 | SET_DECL_TEMPLATE_SPECIALIZATION (decl); | |
5995 | ||
5996 | /* Stupid stupid stupid stupid (jason 7/21/95) */ | |
5997 | if (pedantic && DECL_EXTERNAL (decl) | |
5998 | && ! DECL_TEMPLATE_SPECIALIZATION (decl)) | |
5999 | cp_pedwarn ("declaration of `%#D' outside of class is not definition", | |
6000 | decl); | |
6001 | ||
5b605f68 MS |
6002 | pushclass (context, 2); |
6003 | } | |
6004 | ||
8d08fdba MS |
6005 | /* Add this decl to the current binding level, but not if it |
6006 | comes from another scope, e.g. a static member variable. | |
6007 | TEM may equal DECL or it may be a previous decl of the same name. */ | |
5b605f68 | 6008 | |
8d08fdba MS |
6009 | if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE) |
6010 | || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ()) | |
6011 | || TREE_CODE (type) == LANG_TYPE) | |
6012 | tem = decl; | |
6013 | else | |
8926095f | 6014 | tem = pushdecl (decl); |
2ee887f2 | 6015 | |
5156628f | 6016 | if (processing_template_decl) |
5566b478 MS |
6017 | { |
6018 | if (! current_function_decl) | |
6019 | push_template_decl (tem); | |
6020 | else if (minimal_parse_mode) | |
6021 | DECL_VINDEX (decl) | |
6022 | = build_min_nt (DECL_STMT, copy_to_permanent (declarator), | |
6023 | copy_to_permanent (declspecs), | |
c11b6f21 | 6024 | NULL_TREE); |
5566b478 MS |
6025 | } |
6026 | ||
6027 | ||
2ee887f2 | 6028 | #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) |
a3203465 | 6029 | /* Tell the back-end to use or not use .common as appropriate. If we say |
a50f0918 MS |
6030 | -fconserve-space, we want this to save .data space, at the expense of |
6031 | wrong semantics. If we say -fno-conserve-space, we want this to | |
6032 | produce errors about redefs; to do this we force variables into the | |
6033 | data segment. */ | |
a3203465 | 6034 | DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem); |
2ee887f2 | 6035 | #endif |
8d08fdba | 6036 | |
5156628f | 6037 | if (! processing_template_decl) |
5566b478 | 6038 | start_decl_1 (tem); |
8d08fdba | 6039 | |
5566b478 MS |
6040 | /* Corresponding pop_obstacks is done in `cp_finish_decl'. */ |
6041 | push_obstacks_nochange (); | |
8d08fdba | 6042 | |
5566b478 MS |
6043 | #if 0 |
6044 | /* We have no way of knowing whether the initializer will need to be | |
6045 | evaluated at run-time or not until we've parsed it, so let's just put | |
6046 | it in the permanent obstack. (jason) */ | |
8d08fdba MS |
6047 | if (init_written |
6048 | && ! (TREE_CODE (tem) == PARM_DECL | |
6049 | || (TREE_READONLY (tem) | |
6050 | && (TREE_CODE (tem) == VAR_DECL | |
6051 | || TREE_CODE (tem) == FIELD_DECL)))) | |
6052 | { | |
6053 | /* When parsing and digesting the initializer, | |
6054 | use temporary storage. Do this even if we will ignore the value. */ | |
a9aedbc2 | 6055 | if (toplevel_bindings_p () && debug_temp_inits) |
8d08fdba | 6056 | { |
5156628f | 6057 | if (processing_template_decl |
5566b478 | 6058 | || TYPE_NEEDS_CONSTRUCTING (type) |
a28e3c7f | 6059 | || TREE_CODE (type) == REFERENCE_TYPE) |
8d08fdba MS |
6060 | /* In this case, the initializer must lay down in permanent |
6061 | storage, since it will be saved until `finish_file' is run. */ | |
6062 | ; | |
6063 | else | |
6064 | temporary_allocation (); | |
6065 | } | |
6066 | } | |
5566b478 | 6067 | #endif |
8d08fdba | 6068 | |
8d08fdba MS |
6069 | return tem; |
6070 | } | |
6071 | ||
5566b478 MS |
6072 | void |
6073 | start_decl_1 (decl) | |
6074 | tree decl; | |
8d08fdba | 6075 | { |
5566b478 MS |
6076 | tree type = TREE_TYPE (decl); |
6077 | int initialized = (DECL_INITIAL (decl) != NULL_TREE); | |
8d08fdba | 6078 | |
5566b478 MS |
6079 | /* If this type of object needs a cleanup, and control may |
6080 | jump past it, make a new binding level so that it is cleaned | |
6081 | up only when it is initialized first. */ | |
6082 | if (TYPE_NEEDS_DESTRUCTOR (type) | |
6083 | && current_binding_level->more_cleanups_ok == 0) | |
6084 | pushlevel_temporary (1); | |
6085 | ||
6086 | if (initialized) | |
6087 | /* Is it valid for this decl to have an initializer at all? | |
6088 | If not, set INITIALIZED to zero, which will indirectly | |
6089 | tell `cp_finish_decl' to ignore the initializer once it is parsed. */ | |
8d08fdba | 6090 | { |
5566b478 MS |
6091 | /* Don't allow initializations for incomplete types except for |
6092 | arrays which might be completed by the initialization. */ | |
6093 | if (type == error_mark_node) | |
6094 | ; /* Don't complain again. */ | |
6095 | else if (TYPE_SIZE (complete_type (type)) != NULL_TREE) | |
6096 | ; /* A complete type is ok. */ | |
6097 | else if (TREE_CODE (type) != ARRAY_TYPE) | |
8d08fdba | 6098 | { |
5566b478 MS |
6099 | cp_error ("variable `%#D' has initializer but incomplete type", |
6100 | decl); | |
6101 | initialized = 0; | |
6102 | } | |
6103 | else if (TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) | |
6104 | { | |
6105 | if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)) | |
6106 | cp_error ("elements of array `%#D' have incomplete type", decl); | |
6107 | /* else we already gave an error in start_decl. */ | |
6108 | initialized = 0; | |
8d08fdba | 6109 | } |
8d08fdba MS |
6110 | } |
6111 | ||
5566b478 MS |
6112 | if (!initialized |
6113 | && TREE_CODE (decl) != TYPE_DECL | |
6114 | && TREE_CODE (decl) != TEMPLATE_DECL | |
6115 | && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) | |
8d08fdba | 6116 | { |
5156628f | 6117 | if ((! processing_template_decl || ! uses_template_parms (type)) |
7fcdf4c2 | 6118 | && TYPE_SIZE (complete_type (type)) == NULL_TREE) |
5566b478 MS |
6119 | { |
6120 | cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", | |
6121 | decl); | |
6122 | /* Change the type so that assemble_variable will give | |
6123 | DECL an rtl we can live with: (mem (const_int 0)). */ | |
6124 | TREE_TYPE (decl) = error_mark_node; | |
6125 | type = error_mark_node; | |
6126 | } | |
6127 | else | |
6128 | { | |
6129 | /* If any base type in the hierarchy of TYPE needs a constructor, | |
6130 | then we set initialized to 1. This way any nodes which are | |
6131 | created for the purposes of initializing this aggregate | |
6132 | will live as long as it does. This is necessary for global | |
6133 | aggregates which do not have their initializers processed until | |
6134 | the end of the file. */ | |
6135 | initialized = TYPE_NEEDS_CONSTRUCTING (type); | |
6136 | } | |
6137 | } | |
6138 | ||
6139 | #if 0 | |
6140 | /* We don't do this yet for GNU C++. */ | |
6141 | /* For a local variable, define the RTL now. */ | |
6142 | if (! toplevel_bindings_p () | |
6143 | /* But not if this is a duplicate decl | |
6144 | and we preserved the rtl from the previous one | |
6145 | (which may or may not happen). */ | |
6146 | && DECL_RTL (tem) == NULL_RTX) | |
6147 | { | |
6148 | if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) | |
6149 | expand_decl (tem); | |
6150 | else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE | |
6151 | && DECL_INITIAL (tem) != NULL_TREE) | |
6152 | expand_decl (tem); | |
6153 | } | |
6154 | #endif | |
6155 | ||
6156 | if (! initialized) | |
6157 | DECL_INITIAL (decl) = NULL_TREE; | |
6158 | } | |
6159 | ||
6160 | /* Handle initialization of references. | |
6161 | These three arguments from from `cp_finish_decl', and have the | |
e92cc029 MS |
6162 | same meaning here that they do there. |
6163 | ||
6164 | Quotes on semantics can be found in ARM 8.4.3. */ | |
6165 | ||
5566b478 MS |
6166 | static void |
6167 | grok_reference_init (decl, type, init, cleanupp) | |
6168 | tree decl, type, init; | |
6169 | tree *cleanupp; | |
6170 | { | |
6171 | tree tmp; | |
6172 | ||
6173 | if (init == NULL_TREE) | |
6174 | { | |
6175 | if ((DECL_LANG_SPECIFIC (decl) == 0 | |
6176 | || DECL_IN_AGGR_P (decl) == 0) | |
6177 | && ! DECL_THIS_EXTERN (decl)) | |
6178 | { | |
6179 | cp_error ("`%D' declared as reference but not initialized", decl); | |
6180 | if (TREE_CODE (decl) == VAR_DECL) | |
6181 | SET_DECL_REFERENCE_SLOT (decl, error_mark_node); | |
6182 | } | |
6183 | return; | |
6184 | } | |
6185 | ||
6186 | if (init == error_mark_node) | |
6187 | return; | |
6188 | ||
6189 | if (TREE_CODE (type) == REFERENCE_TYPE | |
6190 | && TREE_CODE (init) == CONSTRUCTOR) | |
6191 | { | |
6192 | cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl); | |
8d08fdba MS |
6193 | return; |
6194 | } | |
6195 | ||
ec255269 MS |
6196 | if (TREE_TYPE (init) && TREE_CODE (TREE_TYPE (init)) == UNKNOWN_TYPE) |
6197 | /* decay_conversion is probably wrong for references to functions. */ | |
6198 | init = decay_conversion (instantiate_type (TREE_TYPE (type), init, 1)); | |
6199 | ||
8d08fdba MS |
6200 | if (TREE_CODE (init) == TREE_LIST) |
6201 | init = build_compound_expr (init); | |
8d08fdba | 6202 | |
8ccc31eb MS |
6203 | if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE) |
6204 | init = convert_from_reference (init); | |
6205 | ||
8d08fdba MS |
6206 | if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE |
6207 | && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE) | |
6208 | { | |
a3203465 | 6209 | /* Note: default conversion is only called in very special cases. */ |
8d08fdba MS |
6210 | init = default_conversion (init); |
6211 | } | |
6212 | ||
a3203465 | 6213 | tmp = convert_to_reference |
9a3b49ac MS |
6214 | (type, init, CONV_IMPLICIT, |
6215 | LOOKUP_SPECULATIVELY|LOOKUP_NORMAL|DIRECT_BIND, decl); | |
8d08fdba | 6216 | |
a3203465 MS |
6217 | if (tmp == error_mark_node) |
6218 | goto fail; | |
6219 | else if (tmp != NULL_TREE) | |
8d08fdba | 6220 | { |
a3203465 | 6221 | init = tmp; |
4c7bdca6 | 6222 | DECL_INITIAL (decl) = save_expr (init); |
8d08fdba | 6223 | } |
a3203465 | 6224 | else |
8d08fdba | 6225 | { |
a3203465 MS |
6226 | cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init)); |
6227 | goto fail; | |
8d08fdba | 6228 | } |
8d08fdba | 6229 | |
8d08fdba MS |
6230 | /* ?? Can this be optimized in some cases to |
6231 | hand back the DECL_INITIAL slot?? */ | |
6232 | if (TYPE_SIZE (TREE_TYPE (type))) | |
6233 | { | |
6234 | init = convert_from_reference (decl); | |
6235 | if (TREE_PERMANENT (decl)) | |
6236 | init = copy_to_permanent (init); | |
6237 | SET_DECL_REFERENCE_SLOT (decl, init); | |
6238 | } | |
6239 | ||
6240 | if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl))) | |
6241 | { | |
6242 | expand_static_init (decl, DECL_INITIAL (decl)); | |
6243 | DECL_INITIAL (decl) = NULL_TREE; | |
6244 | } | |
6245 | return; | |
6246 | ||
6247 | fail: | |
6248 | if (TREE_CODE (decl) == VAR_DECL) | |
6249 | SET_DECL_REFERENCE_SLOT (decl, error_mark_node); | |
6250 | return; | |
6251 | } | |
6252 | ||
6060a796 MS |
6253 | /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from |
6254 | mucking with forces it does not comprehend (i.e. initialization with a | |
6255 | constructor). If we are at global scope and won't go into COMMON, fill | |
6256 | it in with a dummy CONSTRUCTOR to force the variable into .data; | |
6257 | otherwise we can use error_mark_node. */ | |
6258 | ||
28cbf42c MS |
6259 | static tree |
6260 | obscure_complex_init (decl, init) | |
6261 | tree decl, init; | |
6060a796 | 6262 | { |
28cbf42c MS |
6263 | if (! flag_no_inline && TREE_STATIC (decl)) |
6264 | { | |
6265 | if (extract_init (decl, init)) | |
6266 | return NULL_TREE; | |
6267 | } | |
6268 | ||
2ee887f2 | 6269 | #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) |
a9aedbc2 | 6270 | if (toplevel_bindings_p () && ! DECL_COMMON (decl)) |
6060a796 MS |
6271 | DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE, |
6272 | NULL_TREE); | |
6273 | else | |
2ee887f2 | 6274 | #endif |
6060a796 | 6275 | DECL_INITIAL (decl) = error_mark_node; |
28cbf42c MS |
6276 | |
6277 | return init; | |
6060a796 MS |
6278 | } |
6279 | ||
8d08fdba MS |
6280 | /* Finish processing of a declaration; |
6281 | install its line number and initial value. | |
6282 | If the length of an array type is not known before, | |
6283 | it must be determined now, from the initial value, or it is an error. | |
6284 | ||
6285 | Call `pop_obstacks' iff NEED_POP is nonzero. | |
6286 | ||
82580166 | 6287 | For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers |
8d08fdba MS |
6288 | for aggregates that have constructors alive on the permanent obstack, |
6289 | so that the global initializing functions can be written at the end. | |
6290 | ||
6291 | INIT0 holds the value of an initializer that should be allowed to escape | |
6292 | the normal rules. | |
6293 | ||
6060a796 MS |
6294 | FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0 |
6295 | if the (init) syntax was used. | |
6296 | ||
8d08fdba | 6297 | For functions that take default parameters, DECL points to its |
82580166 | 6298 | "maximal" instantiation. `cp_finish_decl' must then also declared its |
8d08fdba MS |
6299 | subsequently lower and lower forms of instantiation, checking for |
6300 | ambiguity as it goes. This can be sped up later. */ | |
6301 | ||
6302 | void | |
82580166 | 6303 | cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) |
8d08fdba MS |
6304 | tree decl, init; |
6305 | tree asmspec_tree; | |
6306 | int need_pop; | |
6060a796 | 6307 | int flags; |
8d08fdba MS |
6308 | { |
6309 | register tree type; | |
6310 | tree cleanup = NULL_TREE, ttype; | |
6311 | int was_incomplete; | |
6312 | int temporary = allocation_temporary_p (); | |
6313 | char *asmspec = NULL; | |
6314 | int was_readonly = 0; | |
0c4b14c4 | 6315 | int already_used = 0; |
8d08fdba MS |
6316 | |
6317 | /* If this is 0, then we did not change obstacks. */ | |
6318 | if (! decl) | |
6319 | { | |
6320 | if (init) | |
6321 | error ("assignment (not initialization) in declaration"); | |
6322 | return; | |
6323 | } | |
6324 | ||
a4443a08 | 6325 | /* If a name was specified, get the string. */ |
8d08fdba | 6326 | if (asmspec_tree) |
8d08fdba | 6327 | asmspec = TREE_STRING_POINTER (asmspec_tree); |
8d08fdba MS |
6328 | |
6329 | /* If the type of the thing we are declaring either has | |
6330 | a constructor, or has a virtual function table pointer, | |
6331 | AND its initialization was accepted by `start_decl', | |
6332 | then we stayed on the permanent obstack through the | |
6333 | declaration, otherwise, changed obstacks as GCC would. */ | |
6334 | ||
6335 | type = TREE_TYPE (decl); | |
6336 | ||
f376e137 | 6337 | if (type == error_mark_node) |
eac293a1 | 6338 | { |
a9aedbc2 | 6339 | if (toplevel_bindings_p () && temporary) |
eac293a1 MS |
6340 | end_temporary_allocation (); |
6341 | ||
6342 | return; | |
6343 | } | |
f376e137 | 6344 | |
5156628f | 6345 | if (processing_template_decl) |
5566b478 MS |
6346 | { |
6347 | if (init && DECL_INITIAL (decl)) | |
6348 | DECL_INITIAL (decl) = init; | |
faf5394a | 6349 | if (minimal_parse_mode && ! DECL_ARTIFICIAL (decl)) |
5566b478 MS |
6350 | { |
6351 | tree stmt = DECL_VINDEX (decl); | |
6352 | DECL_VINDEX (decl) = NULL_TREE; | |
c11b6f21 | 6353 | TREE_OPERAND (stmt, 2) = copy_to_permanent (init); |
5566b478 MS |
6354 | add_tree (stmt); |
6355 | } | |
8d08fdba | 6356 | |
5566b478 MS |
6357 | goto finish_end0; |
6358 | } | |
8d08fdba MS |
6359 | /* Take care of TYPE_DECLs up front. */ |
6360 | if (TREE_CODE (decl) == TYPE_DECL) | |
6361 | { | |
6362 | if (init && DECL_INITIAL (decl)) | |
6363 | { | |
6364 | /* typedef foo = bar; store the type of bar as the type of foo. */ | |
6365 | TREE_TYPE (decl) = type = TREE_TYPE (init); | |
6366 | DECL_INITIAL (decl) = init = NULL_TREE; | |
6367 | } | |
a0a33927 MS |
6368 | if (type != error_mark_node |
6369 | && IS_AGGR_TYPE (type) && DECL_NAME (decl)) | |
8d08fdba MS |
6370 | { |
6371 | if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type) | |
6372 | cp_warning ("shadowing previous type declaration of `%#D'", decl); | |
6373 | set_identifier_type_value (DECL_NAME (decl), type); | |
6374 | CLASSTYPE_GOT_SEMICOLON (type) = 1; | |
6375 | } | |
6376 | GNU_xref_decl (current_function_decl, decl); | |
cffa8729 MS |
6377 | |
6378 | /* If we have installed this as the canonical typedef for this | |
6379 | type, and that type has not been defined yet, delay emitting | |
6380 | the debug informaion for it, as we will emit it later. */ | |
d2e5ee5c | 6381 | if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl |
cffa8729 MS |
6382 | && TYPE_SIZE (TREE_TYPE (decl)) == NULL_TREE) |
6383 | TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; | |
6384 | ||
8d08fdba | 6385 | rest_of_decl_compilation (decl, NULL_PTR, |
5566b478 | 6386 | DECL_CONTEXT (decl) == NULL_TREE, at_eof); |
8d08fdba MS |
6387 | goto finish_end; |
6388 | } | |
8d08fdba MS |
6389 | if (TREE_CODE (decl) != FUNCTION_DECL) |
6390 | { | |
6391 | ttype = target_type (type); | |
8d08fdba MS |
6392 | } |
6393 | ||
6394 | if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) | |
6395 | && TYPE_NEEDS_CONSTRUCTING (type)) | |
6396 | { | |
6397 | ||
6398 | /* Currently, GNU C++ puts constants in text space, making them | |
6399 | impossible to initialize. In the future, one would hope for | |
6400 | an operating system which understood the difference between | |
6401 | initialization and the running of a program. */ | |
6402 | was_readonly = 1; | |
6403 | TREE_READONLY (decl) = 0; | |
6404 | } | |
6405 | ||
6406 | if (TREE_CODE (decl) == FIELD_DECL) | |
6407 | { | |
6408 | if (init && init != error_mark_node) | |
6409 | my_friendly_assert (TREE_PERMANENT (init), 147); | |
6410 | ||
6411 | if (asmspec) | |
6412 | { | |
6413 | /* This must override the asm specifier which was placed | |
6060a796 | 6414 | by grokclassfn. Lay this out fresh. */ |
8d08fdba MS |
6415 | DECL_RTL (TREE_TYPE (decl)) = NULL_RTX; |
6416 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
6417 | make_decl_rtl (decl, asmspec, 0); | |
6418 | } | |
6419 | } | |
6420 | /* If `start_decl' didn't like having an initialization, ignore it now. */ | |
6421 | else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) | |
6422 | init = NULL_TREE; | |
6423 | else if (DECL_EXTERNAL (decl)) | |
6424 | ; | |
6425 | else if (TREE_CODE (type) == REFERENCE_TYPE | |
6426 | || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type))) | |
6427 | { | |
f376e137 MS |
6428 | if (TREE_STATIC (decl)) |
6429 | make_decl_rtl (decl, NULL_PTR, | |
a9aedbc2 | 6430 | toplevel_bindings_p () |
f376e137 | 6431 | || pseudo_global_level_p ()); |
8d08fdba MS |
6432 | grok_reference_init (decl, type, init, &cleanup); |
6433 | init = NULL_TREE; | |
6434 | } | |
6435 | ||
6436 | GNU_xref_decl (current_function_decl, decl); | |
6437 | ||
a0a33927 | 6438 | if (TREE_CODE (decl) == FIELD_DECL) |
8d08fdba MS |
6439 | ; |
6440 | else if (TREE_CODE (decl) == CONST_DECL) | |
6441 | { | |
6442 | my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); | |
6443 | ||
6444 | DECL_INITIAL (decl) = init; | |
6445 | ||
6446 | /* This will keep us from needing to worry about our obstacks. */ | |
6447 | my_friendly_assert (init != NULL_TREE, 149); | |
6448 | init = NULL_TREE; | |
6449 | } | |
6450 | else if (init) | |
6451 | { | |
6452 | if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type)) | |
6453 | { | |
6454 | if (TREE_CODE (type) == ARRAY_TYPE) | |
6455 | init = digest_init (type, init, (tree *) 0); | |
a3203465 | 6456 | else if (TREE_CODE (init) == CONSTRUCTOR) |
8d08fdba | 6457 | { |
f30432d7 | 6458 | if (TYPE_NON_AGGREGATE_CLASS (type)) |
8d08fdba | 6459 | { |
a28e3c7f MS |
6460 | cp_error ("`%D' must be initialized by constructor, not by `{...}'", |
6461 | decl); | |
8d08fdba MS |
6462 | init = error_mark_node; |
6463 | } | |
6464 | else | |
6465 | goto dont_use_constructor; | |
6466 | } | |
8d08fdba MS |
6467 | } |
6468 | else | |
6469 | { | |
6470 | dont_use_constructor: | |
6471 | if (TREE_CODE (init) != TREE_VEC) | |
6472 | init = store_init_value (decl, init); | |
8d08fdba | 6473 | } |
28cbf42c MS |
6474 | |
6475 | if (init) | |
6476 | /* We must hide the initializer so that expand_decl | |
6477 | won't try to do something it does not understand. */ | |
6478 | init = obscure_complex_init (decl, init); | |
8d08fdba | 6479 | } |
a0a33927 MS |
6480 | else if (DECL_EXTERNAL (decl)) |
6481 | ; | |
8d08fdba MS |
6482 | else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't' |
6483 | && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))) | |
6484 | { | |
6485 | tree ctype = type; | |
6486 | while (TREE_CODE (ctype) == ARRAY_TYPE) | |
6487 | ctype = TREE_TYPE (ctype); | |
6488 | if (! TYPE_NEEDS_CONSTRUCTING (ctype)) | |
6489 | { | |
6490 | if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype)) | |
6491 | cp_error ("structure `%D' with uninitialized const members", decl); | |
6492 | if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype)) | |
a28e3c7f MS |
6493 | cp_error ("structure `%D' with uninitialized reference members", |
6494 | decl); | |
8d08fdba MS |
6495 | } |
6496 | ||
6497 | if (TREE_CODE (decl) == VAR_DECL | |
6498 | && !DECL_INITIAL (decl) | |
6499 | && !TYPE_NEEDS_CONSTRUCTING (type) | |
6500 | && (TYPE_READONLY (type) || TREE_READONLY (decl))) | |
6501 | cp_error ("uninitialized const `%D'", decl); | |
6502 | ||
6060a796 MS |
6503 | if (TYPE_SIZE (type) != NULL_TREE |
6504 | && TYPE_NEEDS_CONSTRUCTING (type)) | |
28cbf42c | 6505 | init = obscure_complex_init (decl, NULL_TREE); |
8d08fdba MS |
6506 | } |
6507 | else if (TREE_CODE (decl) == VAR_DECL | |
6508 | && TREE_CODE (type) != REFERENCE_TYPE | |
6509 | && (TYPE_READONLY (type) || TREE_READONLY (decl))) | |
6510 | { | |
6511 | /* ``Unless explicitly declared extern, a const object does not have | |
6512 | external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 | |
6513 | However, if it's `const int foo = 1; const int foo;', don't complain | |
6514 | about the second decl, since it does have an initializer before. | |
6515 | We deliberately don't complain about arrays, because they're | |
6516 | supposed to be initialized by a constructor. */ | |
6517 | if (! DECL_INITIAL (decl) | |
6518 | && TREE_CODE (type) != ARRAY_TYPE | |
6519 | && (!pedantic || !current_class_type)) | |
6520 | cp_error ("uninitialized const `%#D'", decl); | |
6521 | } | |
6522 | ||
6523 | /* For top-level declaration, the initial value was read in | |
6524 | the temporary obstack. MAXINDEX, rtl, etc. to be made below | |
6525 | must go in the permanent obstack; but don't discard the | |
6526 | temporary data yet. */ | |
6527 | ||
a9aedbc2 | 6528 | if (toplevel_bindings_p () && temporary) |
8d08fdba MS |
6529 | end_temporary_allocation (); |
6530 | ||
6531 | /* Deduce size of array from initialization, if not already known. */ | |
6532 | ||
6533 | if (TREE_CODE (type) == ARRAY_TYPE | |
6534 | && TYPE_DOMAIN (type) == NULL_TREE | |
6535 | && TREE_CODE (decl) != TYPE_DECL) | |
6536 | { | |
6537 | int do_default | |
6538 | = (TREE_STATIC (decl) | |
6539 | /* Even if pedantic, an external linkage array | |
6540 | may have incomplete type at first. */ | |
6541 | ? pedantic && ! DECL_EXTERNAL (decl) | |
6542 | : !DECL_EXTERNAL (decl)); | |
6543 | tree initializer = init ? init : DECL_INITIAL (decl); | |
6544 | int failure = complete_array_type (type, initializer, do_default); | |
6545 | ||
6546 | if (failure == 1) | |
6547 | cp_error ("initializer fails to determine size of `%D'", decl); | |
6548 | ||
6549 | if (failure == 2) | |
6550 | { | |
6551 | if (do_default) | |
6552 | cp_error ("array size missing in `%D'", decl); | |
6553 | /* If a `static' var's size isn't known, make it extern as | |
6554 | well as static, so it does not get allocated. If it's not | |
6555 | `static', then don't mark it extern; finish_incomplete_decl | |
6556 | will give it a default size and it will get allocated. */ | |
6557 | else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) | |
6558 | DECL_EXTERNAL (decl) = 1; | |
6559 | } | |
6560 | ||
6561 | if (pedantic && TYPE_DOMAIN (type) != NULL_TREE | |
6562 | && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), | |
6563 | integer_zero_node)) | |
6564 | cp_error ("zero-size array `%D'", decl); | |
6565 | ||
6566 | layout_decl (decl, 0); | |
6567 | } | |
6568 | ||
6569 | if (TREE_CODE (decl) == VAR_DECL) | |
6570 | { | |
6571 | if (DECL_SIZE (decl) == NULL_TREE | |
ec255269 | 6572 | && TYPE_SIZE (complete_type (TREE_TYPE (decl))) != NULL_TREE) |
8d08fdba MS |
6573 | layout_decl (decl, 0); |
6574 | ||
6575 | if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) | |
6576 | { | |
6577 | /* A static variable with an incomplete type: | |
6578 | that is an error if it is initialized. | |
6579 | Otherwise, let it through, but if it is not `extern' | |
6580 | then it may cause an error message later. */ | |
6581 | if (DECL_INITIAL (decl) != NULL_TREE) | |
6582 | cp_error ("storage size of `%D' isn't known", decl); | |
6583 | init = NULL_TREE; | |
6584 | } | |
6585 | else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) | |
6586 | { | |
6587 | /* An automatic variable with an incomplete type: that is an error. | |
6588 | Don't talk about array types here, since we took care of that | |
6589 | message in grokdeclarator. */ | |
6590 | cp_error ("storage size of `%D' isn't known", decl); | |
6591 | TREE_TYPE (decl) = error_mark_node; | |
6592 | } | |
6593 | else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) | |
6594 | /* Let debugger know it should output info for this type. */ | |
6595 | note_debug_info_needed (ttype); | |
6596 | ||
d2e5ee5c MS |
6597 | if (TREE_STATIC (decl) && DECL_CONTEXT (decl) |
6598 | && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't') | |
6599 | note_debug_info_needed (DECL_CONTEXT (decl)); | |
6600 | ||
8d08fdba MS |
6601 | if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) |
6602 | && DECL_SIZE (decl) != NULL_TREE | |
6603 | && ! TREE_CONSTANT (DECL_SIZE (decl))) | |
6604 | { | |
6605 | if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) | |
6606 | constant_expression_warning (DECL_SIZE (decl)); | |
6607 | else | |
6608 | cp_error ("storage size of `%D' isn't constant", decl); | |
6609 | } | |
6610 | ||
c91a56d2 MS |
6611 | if (! DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type) |
6612 | /* Cleanups for static variables are handled by `finish_file'. */ | |
6613 | && ! TREE_STATIC (decl)) | |
8d08fdba MS |
6614 | { |
6615 | int yes = suspend_momentary (); | |
2ee887f2 | 6616 | cleanup = maybe_build_cleanup (decl); |
8d08fdba MS |
6617 | resume_momentary (yes); |
6618 | } | |
6619 | } | |
6620 | /* PARM_DECLs get cleanups, too. */ | |
6621 | else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type)) | |
6622 | { | |
6623 | if (temporary) | |
6624 | end_temporary_allocation (); | |
6625 | cleanup = maybe_build_cleanup (decl); | |
6626 | if (temporary) | |
6627 | resume_temporary_allocation (); | |
6628 | } | |
6629 | ||
6630 | /* Output the assembler code and/or RTL code for variables and functions, | |
6631 | unless the type is an undefined structure or union. | |
6632 | If not, it will get done when the type is completed. */ | |
6633 | ||
5566b478 MS |
6634 | was_incomplete = (DECL_SIZE (decl) == NULL_TREE); |
6635 | ||
8d08fdba MS |
6636 | if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL |
6637 | || TREE_CODE (decl) == RESULT_DECL) | |
6638 | { | |
6639 | /* ??? FIXME: What about nested classes? */ | |
a9aedbc2 | 6640 | int toplev = toplevel_bindings_p () || pseudo_global_level_p (); |
8d08fdba | 6641 | int was_temp |
d22c8596 | 6642 | = (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type) |
8d08fdba MS |
6643 | && allocation_temporary_p ()); |
6644 | ||
6645 | if (was_temp) | |
6646 | end_temporary_allocation (); | |
6647 | ||
42976354 BK |
6648 | /* Extern inline function static data has external linkage. */ |
6649 | if (TREE_CODE (decl) == VAR_DECL | |
6650 | && TREE_STATIC (decl) | |
6651 | && current_function_decl | |
6652 | && DECL_CONTEXT (decl) == current_function_decl | |
6653 | && DECL_THIS_INLINE (current_function_decl) | |
893de33c | 6654 | && TREE_PUBLIC (current_function_decl)) |
42976354 | 6655 | { |
818045b6 JM |
6656 | if (DECL_INTERFACE_KNOWN (current_function_decl)) |
6657 | { | |
6658 | TREE_PUBLIC (decl) = 1; | |
6659 | DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl); | |
6660 | } | |
42976354 BK |
6661 | /* We can only do this if we can use common or weak, and we |
6662 | can't if it has been initialized and we don't support weak. */ | |
818045b6 JM |
6663 | else if (DECL_INITIAL (decl) == NULL_TREE |
6664 | || DECL_INITIAL (decl) == error_mark_node) | |
42976354 BK |
6665 | { |
6666 | TREE_PUBLIC (decl) = 1; | |
6667 | DECL_COMMON (decl) = 1; | |
6668 | } | |
6669 | else if (flag_weak) | |
6670 | make_decl_one_only (decl); | |
6671 | ||
6672 | if (TREE_PUBLIC (decl)) | |
6673 | DECL_ASSEMBLER_NAME (decl) | |
6674 | = build_static_name (current_function_decl, DECL_NAME (decl)); | |
6675 | else if (! DECL_ARTIFICIAL (decl)) | |
6676 | cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl); | |
6677 | } | |
6678 | ||
8d08fdba MS |
6679 | if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) |
6680 | make_decl_rtl (decl, NULL_PTR, toplev); | |
6681 | else if (TREE_CODE (decl) == VAR_DECL | |
6682 | && TREE_READONLY (decl) | |
6683 | && DECL_INITIAL (decl) != NULL_TREE | |
6684 | && DECL_INITIAL (decl) != error_mark_node | |
a3203465 | 6685 | && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) |
8d08fdba MS |
6686 | { |
6687 | DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); | |
6688 | ||
6689 | if (asmspec) | |
6690 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
6691 | ||
6692 | if (! toplev | |
6693 | && TREE_STATIC (decl) | |
6694 | && ! TREE_SIDE_EFFECTS (decl) | |
6695 | && ! TREE_PUBLIC (decl) | |
6696 | && ! DECL_EXTERNAL (decl) | |
6697 | && ! TYPE_NEEDS_DESTRUCTOR (type) | |
6698 | && DECL_MODE (decl) != BLKmode) | |
6699 | { | |
6700 | /* If this variable is really a constant, then fill its DECL_RTL | |
6701 | slot with something which won't take up storage. | |
6702 | If something later should take its address, we can always give | |
6703 | it legitimate RTL at that time. */ | |
6704 | DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); | |
6705 | store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0); | |
6706 | TREE_ASM_WRITTEN (decl) = 1; | |
6707 | } | |
a0a33927 | 6708 | else if (toplev && ! TREE_PUBLIC (decl)) |
8d08fdba | 6709 | { |
8d08fdba | 6710 | /* If this is a static const, change its apparent linkage |
db5ae43f | 6711 | if it belongs to a #pragma interface. */ |
a0a33927 | 6712 | if (!interface_unknown) |
8d08fdba MS |
6713 | { |
6714 | TREE_PUBLIC (decl) = 1; | |
6715 | DECL_EXTERNAL (decl) = interface_only; | |
6716 | } | |
6717 | make_decl_rtl (decl, asmspec, toplev); | |
6718 | } | |
6719 | else | |
5566b478 | 6720 | rest_of_decl_compilation (decl, asmspec, toplev, at_eof); |
8d08fdba MS |
6721 | } |
6722 | else if (TREE_CODE (decl) == VAR_DECL | |
6723 | && DECL_LANG_SPECIFIC (decl) | |
6724 | && DECL_IN_AGGR_P (decl)) | |
6725 | { | |
6726 | if (TREE_STATIC (decl)) | |
6727 | { | |
6728 | if (init == NULL_TREE | |
6729 | #ifdef DEFAULT_STATIC_DEFS | |
6730 | /* If this code is dead, then users must | |
6731 | explicitly declare static member variables | |
6732 | outside the class def'n as well. */ | |
6733 | && TYPE_NEEDS_CONSTRUCTING (type) | |
6734 | #endif | |
6735 | ) | |
6736 | { | |
6737 | DECL_EXTERNAL (decl) = 1; | |
6738 | make_decl_rtl (decl, asmspec, 1); | |
6739 | } | |
6740 | else | |
5566b478 | 6741 | rest_of_decl_compilation (decl, asmspec, toplev, at_eof); |
8d08fdba MS |
6742 | } |
6743 | else | |
6744 | /* Just a constant field. Should not need any rtl. */ | |
6745 | goto finish_end0; | |
6746 | } | |
6747 | else | |
5566b478 | 6748 | rest_of_decl_compilation (decl, asmspec, toplev, at_eof); |
8d08fdba MS |
6749 | |
6750 | if (was_temp) | |
6751 | resume_temporary_allocation (); | |
6752 | ||
6753 | if (type != error_mark_node | |
6754 | && TYPE_LANG_SPECIFIC (type) | |
6755 | && CLASSTYPE_ABSTRACT_VIRTUALS (type)) | |
6756 | abstract_virtuals_error (decl, type); | |
6757 | else if ((TREE_CODE (type) == FUNCTION_TYPE | |
6758 | || TREE_CODE (type) == METHOD_TYPE) | |
6759 | && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) | |
6760 | && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type))) | |
6761 | abstract_virtuals_error (decl, TREE_TYPE (type)); | |
6762 | ||
6763 | if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type)) | |
6764 | signature_error (decl, type); | |
6765 | else if ((TREE_CODE (type) == FUNCTION_TYPE | |
6766 | || TREE_CODE (type) == METHOD_TYPE) | |
6767 | && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) | |
6768 | && IS_SIGNATURE (TREE_TYPE (type))) | |
6769 | signature_error (decl, TREE_TYPE (type)); | |
6770 | ||
6771 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
faae18ab | 6772 | ; |
67d743fe MS |
6773 | else if (DECL_EXTERNAL (decl) |
6774 | && ! (DECL_LANG_SPECIFIC (decl) | |
6775 | && DECL_NOT_REALLY_EXTERN (decl))) | |
5566b478 MS |
6776 | { |
6777 | if (init) | |
6778 | DECL_INITIAL (decl) = init; | |
6779 | } | |
8d08fdba MS |
6780 | else if (TREE_STATIC (decl) && type != error_mark_node) |
6781 | { | |
6782 | /* Cleanups for static variables are handled by `finish_file'. */ | |
f30432d7 MS |
6783 | if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE |
6784 | || TYPE_NEEDS_DESTRUCTOR (type)) | |
8d08fdba | 6785 | expand_static_init (decl, init); |
8d08fdba MS |
6786 | } |
6787 | else if (! toplev) | |
6788 | { | |
6789 | /* This is a declared decl which must live until the | |
6790 | end of the binding contour. It may need a cleanup. */ | |
6791 | ||
6792 | /* Recompute the RTL of a local array now | |
6793 | if it used to be an incomplete type. */ | |
6794 | if (was_incomplete && ! TREE_STATIC (decl)) | |
6795 | { | |
6796 | /* If we used it already as memory, it must stay in memory. */ | |
6797 | TREE_ADDRESSABLE (decl) = TREE_USED (decl); | |
6798 | /* If it's still incomplete now, no init will save it. */ | |
6799 | if (DECL_SIZE (decl) == NULL_TREE) | |
6800 | DECL_INITIAL (decl) = NULL_TREE; | |
6801 | expand_decl (decl); | |
6802 | } | |
6803 | else if (! TREE_ASM_WRITTEN (decl) | |
6804 | && (TYPE_SIZE (type) != NULL_TREE | |
6805 | || TREE_CODE (type) == ARRAY_TYPE)) | |
6806 | { | |
6807 | /* Do this here, because we did not expand this decl's | |
6808 | rtl in start_decl. */ | |
6809 | if (DECL_RTL (decl) == NULL_RTX) | |
6810 | expand_decl (decl); | |
6811 | else if (cleanup) | |
6812 | { | |
8d2733ca MS |
6813 | /* XXX: Why don't we use decl here? */ |
6814 | /* Ans: Because it was already expanded? */ | |
e349ee73 | 6815 | if (! expand_decl_cleanup (NULL_TREE, cleanup)) |
8d2733ca MS |
6816 | cp_error ("parser lost in parsing declaration of `%D'", |
6817 | decl); | |
8d08fdba MS |
6818 | /* Cleanup used up here. */ |
6819 | cleanup = NULL_TREE; | |
6820 | } | |
6821 | } | |
6822 | ||
2ee887f2 MS |
6823 | if (current_binding_level->is_for_scope) |
6824 | { | |
6825 | struct binding_level *outer = current_binding_level->level_chain; | |
6826 | ||
6827 | /* Check to see if the same name is already bound at | |
6828 | the outer level, either because it was directly declared, | |
6829 | or because a dead for-decl got preserved. In either case, | |
d22c8596 | 6830 | the code would not have been valid under the ARM |
2ee887f2 MS |
6831 | scope rules, so clear is_for_scope for the |
6832 | current_binding_level. | |
6833 | ||
6834 | Otherwise, we need to preserve the temp slot for decl | |
e92cc029 | 6835 | to last into the outer binding level. */ |
2ee887f2 MS |
6836 | |
6837 | int handling_dead_for_vars = 0; | |
6838 | tree link = outer->names; | |
6839 | for (; ; link = TREE_CHAIN (link)) | |
6840 | { | |
6841 | if (link == NULL && handling_dead_for_vars == 0) | |
6842 | { | |
6843 | link = outer->dead_vars_from_for; | |
6844 | handling_dead_for_vars = 1; | |
6845 | } | |
6846 | if (link == NULL) | |
6847 | { | |
cffa8729 | 6848 | if (DECL_IN_MEMORY_P (decl)) |
2ee887f2 MS |
6849 | preserve_temp_slots (DECL_RTL (decl)); |
6850 | break; | |
6851 | } | |
6852 | if (DECL_NAME (link) == DECL_NAME (decl)) | |
6853 | { | |
6854 | if (handling_dead_for_vars) | |
6855 | { | |
6856 | tree shadowing | |
6857 | = purpose_member (DECL_NAME (decl), | |
6858 | current_binding_level->shadowed); | |
6859 | if (shadowing && TREE_VALUE (shadowing) == link) | |
6860 | TREE_VALUE (shadowing) | |
6861 | = DECL_SHADOWED_FOR_VAR (link); | |
6862 | } | |
6863 | current_binding_level->is_for_scope = 0; | |
6864 | break; | |
6865 | } | |
6866 | } | |
6867 | } | |
6868 | ||
eb66be0e | 6869 | expand_start_target_temps (); |
72b7eeff | 6870 | |
8d08fdba MS |
6871 | if (DECL_SIZE (decl) && type != error_mark_node) |
6872 | { | |
6873 | /* Compute and store the initial value. */ | |
6874 | expand_decl_init (decl); | |
0c4b14c4 | 6875 | already_used = TREE_USED (decl) || TREE_USED (type); |
8d08fdba MS |
6876 | |
6877 | if (init || TYPE_NEEDS_CONSTRUCTING (type)) | |
6878 | { | |
a28e3c7f MS |
6879 | emit_line_note (DECL_SOURCE_FILE (decl), |
6880 | DECL_SOURCE_LINE (decl)); | |
6060a796 | 6881 | expand_aggr_init (decl, init, 0, flags); |
8d08fdba MS |
6882 | } |
6883 | ||
00595019 MS |
6884 | /* Set this to 0 so we can tell whether an aggregate which |
6885 | was initialized was ever used. Don't do this if it has a | |
6886 | destructor, so we don't complain about the 'resource | |
6887 | allocation is initialization' idiom. */ | |
0c4b14c4 | 6888 | |
be99da77 | 6889 | if (TYPE_NEEDS_CONSTRUCTING (type) |
0c4b14c4 | 6890 | && ! already_used |
be99da77 MS |
6891 | && cleanup == NULL_TREE |
6892 | && DECL_NAME (decl)) | |
8d08fdba | 6893 | TREE_USED (decl) = 0; |
0c4b14c4 JM |
6894 | |
6895 | if (already_used) | |
6896 | TREE_USED (decl) = 1; | |
934c6b13 | 6897 | } |
eb66be0e | 6898 | |
934c6b13 | 6899 | /* Cleanup any temporaries needed for the initial value. */ |
eb66be0e | 6900 | expand_end_target_temps (); |
8d08fdba | 6901 | |
934c6b13 MS |
6902 | if (DECL_SIZE (decl) && type != error_mark_node) |
6903 | { | |
8d08fdba MS |
6904 | /* Store the cleanup, if there was one. */ |
6905 | if (cleanup) | |
6906 | { | |
e349ee73 | 6907 | if (! expand_decl_cleanup (decl, cleanup)) |
a28e3c7f MS |
6908 | cp_error ("parser lost in parsing declaration of `%D'", |
6909 | decl); | |
8d08fdba MS |
6910 | } |
6911 | } | |
6912 | } | |
6913 | finish_end0: | |
6914 | ||
6915 | /* Undo call to `pushclass' that was done in `start_decl' | |
6916 | due to initialization of qualified member variable. | |
6917 | I.e., Foo::x = 10; */ | |
6918 | { | |
f30432d7 | 6919 | tree context = DECL_REAL_CONTEXT (decl); |
8d08fdba MS |
6920 | if (context |
6921 | && TREE_CODE_CLASS (TREE_CODE (context)) == 't' | |
6922 | && (TREE_CODE (decl) == VAR_DECL | |
6923 | /* We also have a pushclass done that we need to undo here | |
6924 | if we're at top level and declare a method. */ | |
5566b478 MS |
6925 | || TREE_CODE (decl) == FUNCTION_DECL) |
6926 | /* If size hasn't been set, we're still defining it, | |
6927 | and therefore inside the class body; don't pop | |
6928 | the binding level.. */ | |
6929 | && TYPE_SIZE (context) != NULL_TREE | |
6930 | && context == current_class_type) | |
8d08fdba MS |
6931 | popclass (1); |
6932 | } | |
6933 | } | |
6934 | ||
6935 | finish_end: | |
6936 | ||
39211cd5 MS |
6937 | /* If requested, warn about definitions of large data objects. */ |
6938 | ||
6939 | if (warn_larger_than | |
5156628f | 6940 | && ! processing_template_decl |
39211cd5 MS |
6941 | && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) |
6942 | && !DECL_EXTERNAL (decl)) | |
6943 | { | |
6944 | register tree decl_size = DECL_SIZE (decl); | |
6945 | ||
6946 | if (decl_size && TREE_CODE (decl_size) == INTEGER_CST) | |
6947 | { | |
6948 | unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT; | |
6949 | ||
6950 | if (units > larger_than_size) | |
6951 | warning_with_decl (decl, "size of `%s' is %u bytes", units); | |
6952 | } | |
6953 | } | |
6954 | ||
8d08fdba MS |
6955 | if (need_pop) |
6956 | { | |
6957 | /* Resume permanent allocation, if not within a function. */ | |
6958 | /* The corresponding push_obstacks_nochange is in start_decl, | |
6959 | start_method, groktypename, and in grokfield. */ | |
6960 | pop_obstacks (); | |
6961 | } | |
6962 | ||
6963 | if (was_readonly) | |
6964 | TREE_READONLY (decl) = 1; | |
8d08fdba MS |
6965 | } |
6966 | ||
82580166 | 6967 | /* This is here for a midend callback from c-common.c */ |
e92cc029 | 6968 | |
82580166 MS |
6969 | void |
6970 | finish_decl (decl, init, asmspec_tree) | |
6971 | tree decl, init; | |
6972 | tree asmspec_tree; | |
6973 | { | |
6974 | cp_finish_decl (decl, init, asmspec_tree, 1, 0); | |
6975 | } | |
6976 | ||
8d08fdba MS |
6977 | void |
6978 | expand_static_init (decl, init) | |
6979 | tree decl; | |
6980 | tree init; | |
6981 | { | |
6982 | tree oldstatic = value_member (decl, static_aggregates); | |
a4443a08 | 6983 | |
8d08fdba MS |
6984 | if (oldstatic) |
6985 | { | |
6986 | if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) | |
6987 | cp_error ("multiple initializations given for `%D'", decl); | |
6988 | } | |
a9aedbc2 | 6989 | else if (! toplevel_bindings_p () && ! pseudo_global_level_p ()) |
8d08fdba MS |
6990 | { |
6991 | /* Emit code to perform this initialization but once. */ | |
6992 | tree temp; | |
6993 | ||
e92cc029 | 6994 | /* Remember this information until end of file. */ |
8d08fdba MS |
6995 | push_obstacks (&permanent_obstack, &permanent_obstack); |
6996 | ||
6997 | /* Emit code to perform this initialization but once. */ | |
6998 | temp = get_temp_name (integer_type_node, 1); | |
6999 | rest_of_decl_compilation (temp, NULL_PTR, 0, 0); | |
7000 | expand_start_cond (build_binary_op (EQ_EXPR, temp, | |
7001 | integer_zero_node, 1), 0); | |
eb66be0e | 7002 | expand_start_target_temps (); |
72b7eeff | 7003 | |
8d08fdba | 7004 | expand_assignment (temp, integer_one_node, 0, 0); |
28cbf42c | 7005 | if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)) |
f30432d7 | 7006 | || (init && TREE_CODE (init) == TREE_LIST)) |
8d08fdba | 7007 | { |
6060a796 | 7008 | expand_aggr_init (decl, init, 0, 0); |
8d08fdba MS |
7009 | do_pending_stack_adjust (); |
7010 | } | |
f30432d7 | 7011 | else if (init) |
8d08fdba | 7012 | expand_assignment (decl, init, 0, 0); |
f30432d7 | 7013 | |
a4443a08 | 7014 | /* Cleanup any temporaries needed for the initial value. */ |
eb66be0e | 7015 | expand_end_target_temps (); |
72b7eeff MS |
7016 | |
7017 | if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) | |
7018 | { | |
7019 | tree cleanup, fcall; | |
7020 | static tree Atexit = 0; | |
7021 | if (Atexit == 0) | |
7022 | { | |
7023 | tree atexit_fndecl, PFV, pfvlist; | |
e92cc029 | 7024 | /* Remember this information until end of file. */ |
72b7eeff MS |
7025 | push_obstacks (&permanent_obstack, &permanent_obstack); |
7026 | PFV = build_pointer_type (build_function_type | |
7027 | (void_type_node, void_list_node)); | |
7028 | ||
7029 | pfvlist = tree_cons (NULL_TREE, PFV, void_list_node); | |
7030 | ||
7031 | push_lang_context (lang_name_c); | |
beb53fb8 JM |
7032 | atexit_fndecl |
7033 | = builtin_function ("atexit", | |
7034 | build_function_type (void_type_node, | |
7035 | pfvlist), | |
7036 | NOT_BUILT_IN, NULL_PTR); | |
be99da77 | 7037 | assemble_external (atexit_fndecl); |
72b7eeff MS |
7038 | Atexit = default_conversion (atexit_fndecl); |
7039 | pop_lang_context (); | |
7040 | pop_obstacks (); | |
7041 | } | |
7042 | ||
7043 | cleanup = start_anon_func (); | |
7044 | expand_expr_stmt (build_cleanup (decl)); | |
7045 | end_anon_func (); | |
7046 | mark_addressable (cleanup); | |
7047 | cleanup = build_unary_op (ADDR_EXPR, cleanup, 0); | |
7048 | fcall = build_function_call (Atexit, tree_cons (NULL_TREE, cleanup, NULL_TREE)); | |
7049 | expand_expr_stmt (fcall); | |
7050 | } | |
7051 | ||
8d08fdba MS |
7052 | expand_end_cond (); |
7053 | if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) | |
7054 | { | |
7055 | static_aggregates = perm_tree_cons (temp, decl, static_aggregates); | |
7056 | TREE_STATIC (static_aggregates) = 1; | |
7057 | } | |
7058 | ||
e92cc029 | 7059 | /* Resume old (possibly temporary) allocation. */ |
8d08fdba MS |
7060 | pop_obstacks (); |
7061 | } | |
7062 | else | |
7063 | { | |
7064 | /* This code takes into account memory allocation | |
7065 | policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING | |
7066 | does not hold for this object, then we must make permanent | |
7067 | the storage currently in the temporary obstack. */ | |
7068 | if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) | |
7069 | preserve_initializer (); | |
7070 | static_aggregates = perm_tree_cons (init, decl, static_aggregates); | |
7071 | } | |
7072 | } | |
7073 | \f | |
7074 | /* Make TYPE a complete type based on INITIAL_VALUE. | |
7075 | Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, | |
7076 | 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ | |
7077 | ||
7078 | int | |
7079 | complete_array_type (type, initial_value, do_default) | |
7080 | tree type, initial_value; | |
7081 | int do_default; | |
7082 | { | |
7083 | register tree maxindex = NULL_TREE; | |
7084 | int value = 0; | |
7085 | ||
7086 | if (initial_value) | |
7087 | { | |
7088 | /* Note MAXINDEX is really the maximum index, | |
7089 | one less than the size. */ | |
7090 | if (TREE_CODE (initial_value) == STRING_CST) | |
e1cd6e56 MS |
7091 | { |
7092 | int eltsize | |
7093 | = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); | |
7094 | maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) | |
7095 | / eltsize) - 1, 0); | |
7096 | } | |
8d08fdba MS |
7097 | else if (TREE_CODE (initial_value) == CONSTRUCTOR) |
7098 | { | |
e1cd6e56 MS |
7099 | tree elts = CONSTRUCTOR_ELTS (initial_value); |
7100 | maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node); | |
7101 | for (; elts; elts = TREE_CHAIN (elts)) | |
7102 | { | |
7103 | if (TREE_PURPOSE (elts)) | |
7104 | maxindex = TREE_PURPOSE (elts); | |
7105 | else | |
7106 | maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node); | |
7107 | } | |
7108 | maxindex = copy_node (maxindex); | |
8d08fdba MS |
7109 | } |
7110 | else | |
7111 | { | |
7112 | /* Make an error message unless that happened already. */ | |
7113 | if (initial_value != error_mark_node) | |
7114 | value = 1; | |
7115 | ||
7116 | /* Prevent further error messages. */ | |
7117 | maxindex = build_int_2 (0, 0); | |
7118 | } | |
7119 | } | |
7120 | ||
7121 | if (!maxindex) | |
7122 | { | |
7123 | if (do_default) | |
7124 | maxindex = build_int_2 (0, 0); | |
7125 | value = 2; | |
7126 | } | |
7127 | ||
7128 | if (maxindex) | |
7129 | { | |
51c184be MS |
7130 | tree itype; |
7131 | ||
8d08fdba | 7132 | TYPE_DOMAIN (type) = build_index_type (maxindex); |
dff6b454 | 7133 | if (! TREE_TYPE (maxindex)) |
8d08fdba | 7134 | TREE_TYPE (maxindex) = TYPE_DOMAIN (type); |
51c184be MS |
7135 | if (initial_value) |
7136 | itype = TREE_TYPE (initial_value); | |
7137 | else | |
7138 | itype = NULL; | |
7139 | if (itype && !TYPE_DOMAIN (itype)) | |
7140 | TYPE_DOMAIN (itype) = TYPE_DOMAIN (type); | |
dff6b454 RK |
7141 | /* The type of the main variant should never be used for arrays |
7142 | of different sizes. It should only ever be completed with the | |
7143 | size of the array. */ | |
7144 | if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type))) | |
7145 | TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type); | |
8d08fdba MS |
7146 | } |
7147 | ||
7148 | /* Lay out the type now that we can get the real answer. */ | |
7149 | ||
7150 | layout_type (type); | |
7151 | ||
7152 | return value; | |
7153 | } | |
7154 | \f | |
7155 | /* Return zero if something is declared to be a member of type | |
7156 | CTYPE when in the context of CUR_TYPE. STRING is the error | |
7157 | message to print in that case. Otherwise, quietly return 1. */ | |
e92cc029 | 7158 | |
8d08fdba MS |
7159 | static int |
7160 | member_function_or_else (ctype, cur_type, string) | |
7161 | tree ctype, cur_type; | |
7162 | char *string; | |
7163 | { | |
7164 | if (ctype && ctype != cur_type) | |
7165 | { | |
7166 | error (string, TYPE_NAME_STRING (ctype)); | |
7167 | return 0; | |
7168 | } | |
7169 | return 1; | |
7170 | } | |
7171 | \f | |
7172 | /* Subroutine of `grokdeclarator'. */ | |
7173 | ||
7174 | /* Generate errors possibly applicable for a given set of specifiers. | |
7175 | This is for ARM $7.1.2. */ | |
e92cc029 | 7176 | |
8d08fdba MS |
7177 | static void |
7178 | bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) | |
7179 | tree object; | |
7180 | char *type; | |
7181 | int virtualp, quals, friendp, raises, inlinep; | |
7182 | { | |
7183 | if (virtualp) | |
7184 | cp_error ("`%D' declared as a `virtual' %s", object, type); | |
7185 | if (inlinep) | |
7186 | cp_error ("`%D' declared as an `inline' %s", object, type); | |
7187 | if (quals) | |
a28e3c7f MS |
7188 | cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", |
7189 | object, type); | |
8d08fdba MS |
7190 | if (friendp) |
7191 | cp_error_at ("invalid friend declaration", object); | |
7192 | if (raises) | |
6060a796 | 7193 | cp_error_at ("invalid exception specifications", object); |
8d08fdba MS |
7194 | } |
7195 | ||
7196 | /* CTYPE is class type, or null if non-class. | |
7197 | TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE | |
7198 | or METHOD_TYPE. | |
7199 | DECLARATOR is the function's name. | |
7200 | VIRTUALP is truthvalue of whether the function is virtual or not. | |
7201 | FLAGS are to be passed through to `grokclassfn'. | |
7202 | QUALS are qualifiers indicating whether the function is `const' | |
7203 | or `volatile'. | |
7204 | RAISES is a list of exceptions that this function can raise. | |
7205 | CHECK is 1 if we must find this method in CTYPE, 0 if we should | |
7206 | not look, and -1 if we should not call `grokclassfn' at all. */ | |
e92cc029 | 7207 | |
8d08fdba | 7208 | static tree |
386b8a85 JM |
7209 | grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, |
7210 | raises, attrlist, check, friendp, publicp, inlinep, funcdef_flag, | |
7211 | template_count) | |
8d08fdba MS |
7212 | tree ctype, type; |
7213 | tree declarator; | |
386b8a85 | 7214 | tree orig_declarator; |
8d08fdba MS |
7215 | int virtualp; |
7216 | enum overload_flags flags; | |
f30432d7 | 7217 | tree quals, raises, attrlist; |
386b8a85 | 7218 | int check, friendp, publicp, inlinep, funcdef_flag, template_count; |
8d08fdba MS |
7219 | { |
7220 | tree cname, decl; | |
7221 | int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; | |
42976354 | 7222 | tree t; |
8d08fdba MS |
7223 | |
7224 | if (ctype) | |
7225 | cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL | |
7226 | ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype); | |
7227 | else | |
7228 | cname = NULL_TREE; | |
7229 | ||
7230 | if (raises) | |
7231 | { | |
f30432d7 | 7232 | type = build_exception_variant (type, raises); |
8d08fdba | 7233 | } |
c11b6f21 | 7234 | |
8d08fdba MS |
7235 | decl = build_lang_decl (FUNCTION_DECL, declarator, type); |
7236 | /* propagate volatile out from type to decl */ | |
7237 | if (TYPE_VOLATILE (type)) | |
893de33c | 7238 | TREE_THIS_VOLATILE (decl) = 1; |
8d08fdba MS |
7239 | |
7240 | /* Should probably propagate const out from type to decl I bet (mrs). */ | |
7241 | if (staticp) | |
7242 | { | |
7243 | DECL_STATIC_FUNCTION_P (decl) = 1; | |
7244 | DECL_CONTEXT (decl) = ctype; | |
8d08fdba MS |
7245 | } |
7246 | ||
e76a2646 MS |
7247 | if (ctype) |
7248 | DECL_CLASS_CONTEXT (decl) = ctype; | |
7249 | ||
faae18ab MS |
7250 | if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main")) |
7251 | { | |
7252 | if (inlinep) | |
7253 | error ("cannot declare `main' to be inline"); | |
7254 | else if (! publicp) | |
7255 | error ("cannot declare `main' to be static"); | |
7256 | inlinep = 0; | |
7257 | publicp = 1; | |
7258 | } | |
7259 | ||
893de33c | 7260 | TREE_PUBLIC (decl) = publicp; |
faae18ab | 7261 | if (! publicp) |
893de33c JM |
7262 | { |
7263 | DECL_INTERFACE_KNOWN (decl) = 1; | |
7264 | DECL_NOT_REALLY_EXTERN (decl) = 1; | |
7265 | } | |
faae18ab MS |
7266 | |
7267 | if (inlinep) | |
7268 | DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1; | |
8d08fdba MS |
7269 | |
7270 | DECL_EXTERNAL (decl) = 1; | |
7271 | if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) | |
7272 | { | |
7273 | cp_error ("%smember function `%D' cannot have `%T' method qualifier", | |
7274 | (ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); | |
7275 | quals = NULL_TREE; | |
7276 | } | |
7277 | ||
7278 | if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) | |
7279 | grok_op_properties (decl, virtualp, check < 0); | |
7280 | ||
e76a2646 | 7281 | if (ctype && hack_decl_function_context (decl)) |
893de33c | 7282 | DECL_NO_STATIC_CHAIN (decl) = 1; |
e76a2646 | 7283 | |
42976354 BK |
7284 | for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t)) |
7285 | if (TREE_PURPOSE (t) | |
7286 | && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) | |
7287 | { | |
7288 | add_defarg_fn (decl); | |
7289 | break; | |
7290 | } | |
7291 | ||
8d08fdba | 7292 | /* Caller will do the rest of this. */ |
386b8a85 JM |
7293 | check_explicit_specialization (orig_declarator, decl, |
7294 | template_count, | |
7295 | funcdef_flag ? 2 : | |
7296 | (friendp ? 3 : 0)); | |
7297 | ||
8d08fdba MS |
7298 | if (check < 0) |
7299 | return decl; | |
7300 | ||
5566b478 | 7301 | if (check && funcdef_flag) |
d2e5ee5c | 7302 | DECL_INITIAL (decl) = error_mark_node; |
5566b478 | 7303 | |
8d08fdba MS |
7304 | if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) |
7305 | { | |
7306 | tree tmp; | |
7307 | /* Just handle constructors here. We could do this | |
7308 | inside the following if stmt, but I think | |
7309 | that the code is more legible by breaking this | |
7310 | case out. See comments below for what each of | |
7311 | the following calls is supposed to do. */ | |
7312 | DECL_CONSTRUCTOR_P (decl) = 1; | |
7313 | ||
7314 | grokclassfn (ctype, declarator, decl, flags, quals); | |
386b8a85 | 7315 | |
8d08fdba | 7316 | if (check) |
5566b478 MS |
7317 | { |
7318 | tmp = check_classfn (ctype, decl); | |
98c1c668 JM |
7319 | |
7320 | if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) | |
7321 | tmp = DECL_TEMPLATE_RESULT(tmp); | |
7322 | ||
e349ee73 MS |
7323 | if (tmp && DECL_ARTIFICIAL (tmp)) |
7324 | cp_error ("definition of implicitly-declared `%D'", tmp); | |
5566b478 MS |
7325 | if (tmp && duplicate_decls (decl, tmp)) |
7326 | return tmp; | |
7327 | } | |
a0a33927 MS |
7328 | if (! grok_ctor_properties (ctype, decl)) |
7329 | return NULL_TREE; | |
7330 | ||
7177d104 | 7331 | if (check == 0 && ! current_function_decl) |
8d08fdba | 7332 | { |
37c46b43 | 7333 | tmp = IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)); |
8d08fdba MS |
7334 | if (tmp == NULL_TREE) |
7335 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; | |
7336 | else if (TREE_CODE (tmp) != TREE_CODE (decl)) | |
7337 | cp_error ("inconsistent declarations for `%D'", decl); | |
7338 | else | |
7339 | { | |
7340 | duplicate_decls (decl, tmp); | |
7341 | decl = tmp; | |
7342 | /* avoid creating circularities. */ | |
7343 | DECL_CHAIN (decl) = NULL_TREE; | |
7344 | } | |
7345 | make_decl_rtl (decl, NULL_PTR, 1); | |
7346 | } | |
7347 | } | |
7348 | else | |
7349 | { | |
7350 | tree tmp; | |
7351 | ||
7352 | /* Function gets the ugly name, field gets the nice one. | |
7353 | This call may change the type of the function (because | |
7354 | of default parameters)! */ | |
7355 | if (ctype != NULL_TREE) | |
7356 | grokclassfn (ctype, cname, decl, flags, quals); | |
7357 | ||
7358 | if (ctype != NULL_TREE && check) | |
5566b478 MS |
7359 | { |
7360 | tmp = check_classfn (ctype, decl); | |
98c1c668 JM |
7361 | |
7362 | if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) | |
7363 | tmp = DECL_TEMPLATE_RESULT(tmp); | |
7364 | ||
5566b478 MS |
7365 | if (tmp && DECL_STATIC_FUNCTION_P (tmp) |
7366 | && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) | |
7367 | { | |
7368 | /* Remove the `this' parm added by grokclassfn. | |
7369 | XXX Isn't this done in start_function, too? */ | |
7370 | revert_static_member_fn (&decl, NULL, NULL); | |
7371 | last_function_parms = TREE_CHAIN (last_function_parms); | |
7372 | } | |
e349ee73 MS |
7373 | if (tmp && DECL_ARTIFICIAL (tmp)) |
7374 | cp_error ("definition of implicitly-declared `%D'", tmp); | |
7834ab39 MS |
7375 | if (tmp) |
7376 | { | |
7377 | if (!duplicate_decls (decl, tmp)) | |
7378 | my_friendly_abort (892); | |
7379 | return tmp; | |
7380 | } | |
5566b478 | 7381 | } |
8d08fdba MS |
7382 | |
7383 | if (ctype == NULL_TREE || check) | |
7384 | return decl; | |
7385 | ||
7177d104 MS |
7386 | /* Now install the declaration of this function so that others may |
7387 | find it (esp. its DECL_FRIENDLIST). Don't do this for local class | |
7388 | methods, though. */ | |
7389 | if (! current_function_decl) | |
8d08fdba | 7390 | { |
7177d104 MS |
7391 | /* FIXME: this should only need to look at |
7392 | IDENTIFIER_GLOBAL_VALUE. */ | |
7393 | tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); | |
7394 | if (tmp == NULL_TREE) | |
7395 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; | |
7396 | else if (TREE_CODE (tmp) != TREE_CODE (decl)) | |
7397 | cp_error ("inconsistent declarations for `%D'", decl); | |
7398 | else | |
7399 | { | |
7400 | duplicate_decls (decl, tmp); | |
7401 | decl = tmp; | |
7402 | /* avoid creating circularities. */ | |
7403 | DECL_CHAIN (decl) = NULL_TREE; | |
7404 | } | |
f30432d7 MS |
7405 | |
7406 | if (attrlist) | |
7407 | cplus_decl_attributes (decl, TREE_PURPOSE (attrlist), | |
7408 | TREE_VALUE (attrlist)); | |
7177d104 | 7409 | make_decl_rtl (decl, NULL_PTR, 1); |
8d08fdba | 7410 | } |
8d08fdba MS |
7411 | if (virtualp) |
7412 | { | |
2ee887f2 | 7413 | DECL_VIRTUAL_P (decl) = 1; |
8d08fdba MS |
7414 | if (DECL_VINDEX (decl) == NULL_TREE) |
7415 | DECL_VINDEX (decl) = error_mark_node; | |
7416 | IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; | |
8d08fdba MS |
7417 | } |
7418 | } | |
7419 | return decl; | |
7420 | } | |
7421 | ||
7422 | static tree | |
d2e5ee5c | 7423 | grokvardecl (type, declarator, specbits_in, initialized, constp) |
8d08fdba MS |
7424 | tree type; |
7425 | tree declarator; | |
d2e5ee5c | 7426 | RID_BIT_TYPE *specbits_in; |
8d08fdba | 7427 | int initialized; |
a9aedbc2 | 7428 | int constp; |
8d08fdba MS |
7429 | { |
7430 | tree decl; | |
f7da6097 MS |
7431 | RID_BIT_TYPE specbits; |
7432 | ||
7433 | specbits = *specbits_in; | |
8d08fdba MS |
7434 | |
7435 | if (TREE_CODE (type) == OFFSET_TYPE) | |
7436 | { | |
7437 | /* If you declare a static member so that it | |
7438 | can be initialized, the code will reach here. */ | |
5b605f68 MS |
7439 | tree basetype = TYPE_OFFSET_BASETYPE (type); |
7440 | type = TREE_TYPE (type); | |
7441 | decl = build_lang_field_decl (VAR_DECL, declarator, type); | |
7442 | DECL_CONTEXT (decl) = basetype; | |
7443 | DECL_CLASS_CONTEXT (decl) = basetype; | |
f376e137 | 7444 | DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator); |
8d08fdba MS |
7445 | } |
7446 | else | |
e349ee73 | 7447 | decl = build_decl (VAR_DECL, declarator, complete_type (type)); |
8d08fdba | 7448 | |
6060a796 MS |
7449 | DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl)); |
7450 | ||
8d08fdba MS |
7451 | if (RIDBIT_SETP (RID_EXTERN, specbits)) |
7452 | { | |
7453 | DECL_THIS_EXTERN (decl) = 1; | |
7454 | DECL_EXTERNAL (decl) = !initialized; | |
7455 | } | |
7456 | ||
7457 | /* In class context, static means one per class, | |
7458 | public access, and static storage. */ | |
7459 | if (DECL_FIELD_CONTEXT (decl) != NULL_TREE | |
7460 | && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl))) | |
7461 | { | |
7462 | TREE_PUBLIC (decl) = 1; | |
7463 | TREE_STATIC (decl) = 1; | |
5b605f68 | 7464 | DECL_EXTERNAL (decl) = 0; |
8d08fdba MS |
7465 | } |
7466 | /* At top level, either `static' or no s.c. makes a definition | |
7467 | (perhaps tentative), and absence of `static' makes it public. */ | |
a9aedbc2 | 7468 | else if (toplevel_bindings_p ()) |
8d08fdba | 7469 | { |
a9aedbc2 | 7470 | TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits) |
9fffd093 | 7471 | && (DECL_THIS_EXTERN (decl) || ! constp)); |
8d08fdba MS |
7472 | TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); |
7473 | } | |
7474 | /* Not at top level, only `static' makes a static definition. */ | |
7475 | else | |
7476 | { | |
7477 | TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits); | |
7478 | TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); | |
7479 | } | |
7480 | return decl; | |
7481 | } | |
7482 | ||
e92cc029 | 7483 | /* Create a canonical pointer to member function type. */ |
8d08fdba MS |
7484 | |
7485 | tree | |
7486 | build_ptrmemfunc_type (type) | |
7487 | tree type; | |
7488 | { | |
7489 | tree fields[4]; | |
7490 | tree t; | |
7491 | tree u; | |
7492 | ||
7493 | /* If a canonical type already exists for this type, use it. We use | |
7494 | this method instead of type_hash_canon, because it only does a | |
7495 | simple equality check on the list of field members. */ | |
7496 | ||
7497 | if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type))) | |
7498 | return t; | |
7499 | ||
7500 | push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); | |
7501 | ||
7502 | u = make_lang_type (UNION_TYPE); | |
f30432d7 | 7503 | IS_AGGR_TYPE (u) = 0; |
8d08fdba | 7504 | fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type); |
a28e3c7f MS |
7505 | fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, |
7506 | delta_type_node); | |
8d08fdba MS |
7507 | finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node); |
7508 | TYPE_NAME (u) = NULL_TREE; | |
7509 | ||
7510 | t = make_lang_type (RECORD_TYPE); | |
7511 | ||
e92cc029 | 7512 | /* Let the front-end know this is a pointer to member function. */ |
db5ae43f | 7513 | TYPE_PTRMEMFUNC_FLAG (t) = 1; |
f376e137 MS |
7514 | /* and not really an aggregate. */ |
7515 | IS_AGGR_TYPE (t) = 0; | |
8d08fdba | 7516 | |
a28e3c7f MS |
7517 | fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, |
7518 | delta_type_node); | |
7519 | fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, | |
7520 | delta_type_node); | |
8d08fdba MS |
7521 | fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u); |
7522 | finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node); | |
7523 | ||
7524 | pop_obstacks (); | |
7525 | ||
7526 | /* Zap out the name so that the back-end will give us the debugging | |
7527 | information for this anonymous RECORD_TYPE. */ | |
7528 | TYPE_NAME (t) = NULL_TREE; | |
7529 | ||
7530 | TYPE_SET_PTRMEMFUNC_TYPE (type, t); | |
7531 | ||
e92cc029 | 7532 | /* Seems to be wanted. */ |
8d08fdba MS |
7533 | CLASSTYPE_GOT_SEMICOLON (t) = 1; |
7534 | return t; | |
7535 | } | |
7536 | ||
7537 | /* Given declspecs and a declarator, | |
7538 | determine the name and type of the object declared | |
7539 | and construct a ..._DECL node for it. | |
7540 | (In one case we can return a ..._TYPE node instead. | |
7541 | For invalid input we sometimes return 0.) | |
7542 | ||
7543 | DECLSPECS is a chain of tree_list nodes whose value fields | |
7544 | are the storage classes and type specifiers. | |
7545 | ||
7546 | DECL_CONTEXT says which syntactic context this declaration is in: | |
7547 | NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. | |
7548 | FUNCDEF for a function definition. Like NORMAL but a few different | |
7549 | error messages in each case. Return value may be zero meaning | |
7550 | this definition is too screwy to try to parse. | |
7551 | MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to | |
7552 | handle member functions (which have FIELD context). | |
7553 | Return value may be zero meaning this definition is too screwy to | |
7554 | try to parse. | |
7555 | PARM for a parameter declaration (either within a function prototype | |
7556 | or before a function body). Make a PARM_DECL, or return void_type_node. | |
db5ae43f | 7557 | CATCHPARM for a parameter declaration before a catch clause. |
8d08fdba MS |
7558 | TYPENAME if for a typename (in a cast or sizeof). |
7559 | Don't make a DECL node; just return the ..._TYPE node. | |
7560 | FIELD for a struct or union field; make a FIELD_DECL. | |
7561 | BITFIELD for a field with specified width. | |
7562 | INITIALIZED is 1 if the decl has an initializer. | |
7563 | ||
7564 | In the TYPENAME case, DECLARATOR is really an absolute declarator. | |
7565 | It may also be so in the PARM case, for a prototype where the | |
7566 | argument type is specified but not the name. | |
7567 | ||
7568 | This function is where the complicated C meanings of `static' | |
7569 | and `extern' are interpreted. | |
7570 | ||
7571 | For C++, if there is any monkey business to do, the function which | |
7572 | calls this one must do it, i.e., prepending instance variables, | |
7573 | renaming overloaded function names, etc. | |
7574 | ||
7575 | Note that for this C++, it is an error to define a method within a class | |
7576 | which does not belong to that class. | |
7577 | ||
7578 | Except in the case where SCOPE_REFs are implicitly known (such as | |
7579 | methods within a class being redundantly qualified), | |
7580 | declarations which involve SCOPE_REFs are returned as SCOPE_REFs | |
7581 | (class_name::decl_name). The caller must also deal with this. | |
7582 | ||
7583 | If a constructor or destructor is seen, and the context is FIELD, | |
7584 | then the type gains the attribute TREE_HAS_x. If such a declaration | |
7585 | is erroneous, NULL_TREE is returned. | |
7586 | ||
7587 | QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member | |
7588 | function, these are the qualifiers to give to the `this' pointer. | |
7589 | ||
7590 | May return void_type_node if the declarator turned out to be a friend. | |
7591 | See grokfield for details. */ | |
7592 | ||
7593 | enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; | |
7594 | ||
7595 | tree | |
c11b6f21 | 7596 | grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) |
8d08fdba MS |
7597 | tree declspecs; |
7598 | tree declarator; | |
7599 | enum decl_context decl_context; | |
7600 | int initialized; | |
c11b6f21 | 7601 | tree attrlist; |
8d08fdba MS |
7602 | { |
7603 | RID_BIT_TYPE specbits; | |
7604 | int nclasses = 0; | |
7605 | tree spec; | |
7606 | tree type = NULL_TREE; | |
7607 | int longlong = 0; | |
7608 | int constp; | |
7609 | int volatilep; | |
db5ae43f | 7610 | int virtualp, explicitp, friendp, inlinep, staticp; |
8d08fdba MS |
7611 | int explicit_int = 0; |
7612 | int explicit_char = 0; | |
37c46b43 | 7613 | int defaulted_int = 0; |
8d08fdba MS |
7614 | int opaque_typedef = 0; |
7615 | tree typedef_decl = NULL_TREE; | |
7616 | char *name; | |
7617 | tree typedef_type = NULL_TREE; | |
7618 | int funcdef_flag = 0; | |
7619 | enum tree_code innermost_code = ERROR_MARK; | |
7620 | int bitfield = 0; | |
6125f3be DE |
7621 | #if 0 |
7622 | /* See the code below that used this. */ | |
f6abb50a | 7623 | tree decl_machine_attr = NULL_TREE; |
6125f3be | 7624 | #endif |
8d08fdba MS |
7625 | /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. |
7626 | All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ | |
7627 | tree init = NULL_TREE; | |
7628 | ||
7629 | /* Keep track of what sort of function is being processed | |
7630 | so that we can warn about default return values, or explicit | |
7631 | return values which do not match prescribed defaults. */ | |
7632 | enum return_types return_type = return_normal; | |
7633 | ||
7634 | tree dname = NULL_TREE; | |
7635 | tree ctype = current_class_type; | |
7636 | tree ctor_return_type = NULL_TREE; | |
7637 | enum overload_flags flags = NO_SPECIAL; | |
8d08fdba | 7638 | tree quals = NULL_TREE; |
c11b6f21 | 7639 | tree raises = NULL_TREE; |
386b8a85 | 7640 | int template_count = 0; |
8d08fdba MS |
7641 | |
7642 | RIDBIT_RESET_ALL (specbits); | |
7643 | if (decl_context == FUNCDEF) | |
7644 | funcdef_flag = 1, decl_context = NORMAL; | |
7645 | else if (decl_context == MEMFUNCDEF) | |
7646 | funcdef_flag = -1, decl_context = FIELD; | |
7647 | else if (decl_context == BITFIELD) | |
7648 | bitfield = 1, decl_context = FIELD; | |
7649 | ||
8d08fdba MS |
7650 | /* Look inside a declarator for the name being declared |
7651 | and get it as a string, for an error message. */ | |
7652 | { | |
be99da77 MS |
7653 | tree *next = &declarator; |
7654 | register tree decl; | |
8d08fdba MS |
7655 | name = NULL; |
7656 | ||
be99da77 MS |
7657 | while (next && *next) |
7658 | { | |
7659 | decl = *next; | |
7660 | switch (TREE_CODE (decl)) | |
8d08fdba | 7661 | { |
be99da77 MS |
7662 | case COND_EXPR: |
7663 | ctype = NULL_TREE; | |
7664 | next = &TREE_OPERAND (decl, 0); | |
7665 | break; | |
8d08fdba | 7666 | |
be99da77 | 7667 | case BIT_NOT_EXPR: /* for C++ destructors! */ |
8d08fdba | 7668 | { |
be99da77 MS |
7669 | tree name = TREE_OPERAND (decl, 0); |
7670 | tree rename = NULL_TREE; | |
7671 | ||
7672 | my_friendly_assert (flags == NO_SPECIAL, 152); | |
7673 | flags = DTOR_FLAG; | |
7674 | return_type = return_dtor; | |
5566b478 MS |
7675 | if (TREE_CODE (name) == TYPE_DECL) |
7676 | TREE_OPERAND (decl, 0) = name = constructor_name (name); | |
be99da77 MS |
7677 | my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); |
7678 | if (ctype == NULL_TREE) | |
7679 | { | |
7680 | if (current_class_type == NULL_TREE) | |
7681 | { | |
7682 | error ("destructors must be member functions"); | |
7683 | flags = NO_SPECIAL; | |
7684 | } | |
7685 | else | |
7686 | { | |
7687 | tree t = constructor_name (current_class_name); | |
7688 | if (t != name) | |
7689 | rename = t; | |
7690 | } | |
7691 | } | |
8d08fdba | 7692 | else |
be99da77 MS |
7693 | { |
7694 | tree t = constructor_name (ctype); | |
7695 | if (t != name) | |
7696 | rename = t; | |
7697 | } | |
51c184be | 7698 | |
be99da77 | 7699 | if (rename) |
39211cd5 | 7700 | { |
5566b478 MS |
7701 | cp_error ("destructor `%T' must match class name `%T'", |
7702 | name, rename); | |
be99da77 | 7703 | TREE_OPERAND (decl, 0) = rename; |
39211cd5 | 7704 | } |
be99da77 | 7705 | next = &name; |
51c184be | 7706 | } |
be99da77 | 7707 | break; |
8d08fdba | 7708 | |
be99da77 MS |
7709 | case ADDR_EXPR: /* C++ reference declaration */ |
7710 | /* fall through */ | |
7711 | case ARRAY_REF: | |
7712 | case INDIRECT_REF: | |
7713 | ctype = NULL_TREE; | |
7714 | innermost_code = TREE_CODE (decl); | |
7715 | next = &TREE_OPERAND (decl, 0); | |
7716 | break; | |
8d08fdba | 7717 | |
be99da77 MS |
7718 | case CALL_EXPR: |
7719 | if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) | |
8d08fdba | 7720 | { |
be99da77 MS |
7721 | /* This is actually a variable declaration using constructor |
7722 | syntax. We need to call start_decl and cp_finish_decl so we | |
7723 | can get the variable initialized... */ | |
7724 | ||
7725 | *next = TREE_OPERAND (decl, 0); | |
7726 | init = TREE_OPERAND (decl, 1); | |
7727 | ||
c11b6f21 | 7728 | decl = start_decl (declarator, declspecs, 1); |
be99da77 MS |
7729 | finish_decl (decl, init, NULL_TREE); |
7730 | return 0; | |
8d08fdba | 7731 | } |
be99da77 MS |
7732 | innermost_code = TREE_CODE (decl); |
7733 | if (decl_context == FIELD && ctype == NULL_TREE) | |
7734 | ctype = current_class_type; | |
45537677 | 7735 | if (ctype |
c11b6f21 | 7736 | && TREE_OPERAND (decl, 0) |
45537677 MS |
7737 | && (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL |
7738 | && ((DECL_NAME (TREE_OPERAND (decl, 0)) | |
7739 | == constructor_name_full (ctype)) | |
7740 | || (DECL_NAME (TREE_OPERAND (decl, 0)) | |
7741 | == constructor_name (ctype))))) | |
be99da77 MS |
7742 | TREE_OPERAND (decl, 0) = constructor_name (ctype); |
7743 | next = &TREE_OPERAND (decl, 0); | |
7744 | decl = *next; | |
7745 | if (ctype != NULL_TREE | |
7746 | && decl != NULL_TREE && flags != DTOR_FLAG | |
7747 | && decl == constructor_name (ctype)) | |
8d08fdba | 7748 | { |
be99da77 MS |
7749 | return_type = return_ctor; |
7750 | ctor_return_type = ctype; | |
8d08fdba | 7751 | } |
be99da77 MS |
7752 | ctype = NULL_TREE; |
7753 | break; | |
386b8a85 JM |
7754 | |
7755 | case TEMPLATE_ID_EXPR: | |
7756 | { | |
7757 | tree fns = TREE_OPERAND (decl, 0); | |
7758 | ||
7759 | if (TREE_CODE (fns) == LOOKUP_EXPR) | |
7760 | fns = TREE_OPERAND (fns, 0); | |
7761 | ||
7762 | if (TREE_CODE (fns) == IDENTIFIER_NODE) | |
7763 | dname = fns; | |
7764 | else if (really_overloaded_fn (fns)) | |
7765 | dname = DECL_NAME (get_first_fn (fns)); | |
7766 | else | |
7767 | dname = DECL_NAME (fns); | |
7768 | } | |
7769 | /* fall through */ | |
be99da77 MS |
7770 | |
7771 | case IDENTIFIER_NODE: | |
386b8a85 JM |
7772 | if (TREE_CODE (decl) == IDENTIFIER_NODE) |
7773 | dname = decl; | |
7774 | ||
be99da77 MS |
7775 | next = 0; |
7776 | ||
7777 | if (is_rid (dname)) | |
8d08fdba | 7778 | { |
be99da77 MS |
7779 | cp_error ("declarator-id missing; using reserved word `%D'", |
7780 | dname); | |
7781 | name = IDENTIFIER_POINTER (dname); | |
8d08fdba | 7782 | } |
be99da77 MS |
7783 | if (! IDENTIFIER_OPNAME_P (dname) |
7784 | /* Linux headers use '__op'. Arrgh. */ | |
7785 | || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname)) | |
7786 | name = IDENTIFIER_POINTER (dname); | |
8d08fdba MS |
7787 | else |
7788 | { | |
be99da77 | 7789 | if (IDENTIFIER_TYPENAME_P (dname)) |
8d08fdba | 7790 | { |
be99da77 MS |
7791 | my_friendly_assert (flags == NO_SPECIAL, 154); |
7792 | flags = TYPENAME_FLAG; | |
7793 | ctor_return_type = TREE_TYPE (dname); | |
7794 | return_type = return_conversion; | |
8d08fdba | 7795 | } |
be99da77 | 7796 | name = operator_name_string (dname); |
8d08fdba | 7797 | } |
be99da77 | 7798 | break; |
8d08fdba | 7799 | |
be99da77 MS |
7800 | /* C++ extension */ |
7801 | case SCOPE_REF: | |
7802 | { | |
7803 | /* Perform error checking, and decide on a ctype. */ | |
7804 | tree cname = TREE_OPERAND (decl, 0); | |
7805 | if (cname == NULL_TREE) | |
7806 | ctype = NULL_TREE; | |
7807 | else if (! is_aggr_type (cname, 1)) | |
7808 | TREE_OPERAND (decl, 0) = NULL_TREE; | |
7809 | /* Must test TREE_OPERAND (decl, 1), in case user gives | |
7810 | us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ | |
7811 | else if (TREE_OPERAND (decl, 1) | |
7812 | && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) | |
7813 | ctype = cname; | |
5566b478 MS |
7814 | else if (TREE_CODE (cname) == TEMPLATE_TYPE_PARM) |
7815 | { | |
7816 | cp_error ("`%T::%D' is not a valid declarator", cname, | |
7817 | TREE_OPERAND (decl, 1)); | |
7818 | cp_error (" perhaps you want `typename %T::%D' to make it a type", | |
7819 | cname, TREE_OPERAND (decl, 1)); | |
7820 | return void_type_node; | |
7821 | } | |
be99da77 MS |
7822 | else if (ctype == NULL_TREE) |
7823 | ctype = cname; | |
7824 | else if (TREE_COMPLEXITY (decl) == current_class_depth) | |
7825 | TREE_OPERAND (decl, 0) = ctype; | |
7826 | else | |
7827 | { | |
7828 | if (! UNIQUELY_DERIVED_FROM_P (cname, ctype)) | |
7829 | { | |
7830 | cp_error ("type `%T' is not derived from type `%T'", | |
7831 | cname, ctype); | |
7832 | TREE_OPERAND (decl, 0) = NULL_TREE; | |
7833 | } | |
7834 | else | |
7835 | ctype = cname; | |
7836 | } | |
7837 | ||
c91a56d2 MS |
7838 | if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL |
7839 | && ((DECL_NAME (TREE_OPERAND (decl, 1)) | |
7840 | == constructor_name_full (ctype)) | |
7841 | || (DECL_NAME (TREE_OPERAND (decl, 1)) | |
7842 | == constructor_name (ctype)))) | |
be99da77 MS |
7843 | TREE_OPERAND (decl, 1) = constructor_name (ctype); |
7844 | next = &TREE_OPERAND (decl, 1); | |
7845 | decl = *next; | |
7846 | if (ctype) | |
7847 | { | |
7848 | if (TREE_CODE (decl) == IDENTIFIER_NODE | |
7849 | && constructor_name (ctype) == decl) | |
7850 | { | |
7851 | return_type = return_ctor; | |
7852 | ctor_return_type = ctype; | |
7853 | } | |
7854 | else if (TREE_CODE (decl) == BIT_NOT_EXPR | |
7855 | && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE | |
7856 | && (constructor_name (ctype) == TREE_OPERAND (decl, 0) | |
7857 | || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) | |
7858 | { | |
7859 | return_type = return_dtor; | |
7860 | ctor_return_type = ctype; | |
7861 | flags = DTOR_FLAG; | |
7862 | TREE_OPERAND (decl, 0) = constructor_name (ctype); | |
7863 | next = &TREE_OPERAND (decl, 0); | |
7864 | } | |
7865 | } | |
7866 | } | |
7867 | break; | |
7868 | ||
7869 | case ERROR_MARK: | |
7870 | next = 0; | |
7871 | break; | |
7872 | ||
45537677 MS |
7873 | case TYPE_DECL: |
7874 | /* Parse error puts this typespec where | |
7875 | a declarator should go. */ | |
7876 | cp_error ("`%T' specified as declarator-id", DECL_NAME (decl)); | |
7877 | if (TREE_TYPE (decl) == current_class_type) | |
7878 | cp_error (" perhaps you want `%T' for a constructor", | |
7879 | current_class_name); | |
7880 | dname = DECL_NAME (decl); | |
7881 | name = IDENTIFIER_POINTER (dname); | |
7882 | ||
e92cc029 | 7883 | /* Avoid giving two errors for this. */ |
45537677 MS |
7884 | IDENTIFIER_CLASS_VALUE (dname) = NULL_TREE; |
7885 | ||
7886 | declspecs = temp_tree_cons (NULL_TREE, integer_type_node, | |
7887 | declspecs); | |
7888 | *next = dname; | |
7889 | next = 0; | |
7890 | break; | |
7891 | ||
be99da77 | 7892 | default: |
be99da77 MS |
7893 | cp_compiler_error ("`%D' as declarator", decl); |
7894 | return 0; /* We used to do a 155 abort here. */ | |
8d08fdba | 7895 | } |
be99da77 | 7896 | } |
8d08fdba MS |
7897 | if (name == NULL) |
7898 | name = "type name"; | |
7899 | } | |
7900 | ||
7901 | /* A function definition's declarator must have the form of | |
7902 | a function declarator. */ | |
7903 | ||
7904 | if (funcdef_flag && innermost_code != CALL_EXPR) | |
7905 | return 0; | |
7906 | ||
e1cd6e56 MS |
7907 | if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG) |
7908 | && innermost_code != CALL_EXPR | |
7909 | && ! (ctype && declspecs == NULL_TREE)) | |
7910 | { | |
7911 | cp_error ("declaration of `%D' as non-function", dname); | |
7912 | return void_type_node; | |
7913 | } | |
7914 | ||
8d08fdba MS |
7915 | /* Anything declared one level down from the top level |
7916 | must be one of the parameters of a function | |
7917 | (because the body is at least two levels down). */ | |
7918 | ||
7919 | /* This heuristic cannot be applied to C++ nodes! Fixed, however, | |
7920 | by not allowing C++ class definitions to specify their parameters | |
7921 | with xdecls (must be spec.d in the parmlist). | |
7922 | ||
7923 | Since we now wait to push a class scope until we are sure that | |
7924 | we are in a legitimate method context, we must set oldcname | |
a9aedbc2 MS |
7925 | explicitly (since current_class_name is not yet alive). |
7926 | ||
7927 | We also want to avoid calling this a PARM if it is in a namespace. */ | |
8d08fdba | 7928 | |
5566b478 MS |
7929 | if (decl_context == NORMAL && ! namespace_bindings_p () |
7930 | && ! pseudo_global_level_p ()) | |
a9aedbc2 MS |
7931 | { |
7932 | struct binding_level *b = current_binding_level; | |
7933 | current_binding_level = b->level_chain; | |
7934 | if (current_binding_level != 0 && toplevel_bindings_p ()) | |
7935 | decl_context = PARM; | |
7936 | current_binding_level = b; | |
7937 | } | |
8d08fdba MS |
7938 | |
7939 | /* Look through the decl specs and record which ones appear. | |
7940 | Some typespecs are defined as built-in typenames. | |
7941 | Others, the ones that are modifiers of other types, | |
7942 | are represented by bits in SPECBITS: set the bits for | |
7943 | the modifiers that appear. Storage class keywords are also in SPECBITS. | |
7944 | ||
7945 | If there is a typedef name or a type, store the type in TYPE. | |
7946 | This includes builtin typedefs such as `int'. | |
7947 | ||
7948 | Set EXPLICIT_INT if the type is `int' or `char' and did not | |
7949 | come from a user typedef. | |
7950 | ||
7951 | Set LONGLONG if `long' is mentioned twice. | |
7952 | ||
7953 | For C++, constructors and destructors have their own fast treatment. */ | |
7954 | ||
7955 | for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) | |
7956 | { | |
7957 | register int i; | |
7958 | register tree id; | |
7959 | ||
7960 | /* Certain parse errors slip through. For example, | |
7961 | `int class;' is not caught by the parser. Try | |
7962 | weakly to recover here. */ | |
7963 | if (TREE_CODE (spec) != TREE_LIST) | |
7964 | return 0; | |
7965 | ||
7966 | id = TREE_VALUE (spec); | |
7967 | ||
7968 | if (TREE_CODE (id) == IDENTIFIER_NODE) | |
7969 | { | |
a3203465 MS |
7970 | if (id == ridpointers[(int) RID_INT] |
7971 | || id == ridpointers[(int) RID_CHAR] | |
7972 | || id == ridpointers[(int) RID_BOOL] | |
7973 | || id == ridpointers[(int) RID_WCHAR]) | |
8d08fdba MS |
7974 | { |
7975 | if (type) | |
8ccc31eb MS |
7976 | { |
7977 | if (id == ridpointers[(int) RID_BOOL]) | |
7978 | error ("`bool' is now a keyword"); | |
7979 | else | |
7980 | cp_error ("extraneous `%T' ignored", id); | |
7981 | } | |
8d08fdba MS |
7982 | else |
7983 | { | |
a3203465 MS |
7984 | if (id == ridpointers[(int) RID_INT]) |
7985 | explicit_int = 1; | |
7986 | else if (id == ridpointers[(int) RID_CHAR]) | |
7987 | explicit_char = 1; | |
8d08fdba MS |
7988 | type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); |
7989 | } | |
7990 | goto found; | |
7991 | } | |
e92cc029 | 7992 | /* C++ aggregate types. */ |
8d08fdba MS |
7993 | if (IDENTIFIER_HAS_TYPE_VALUE (id)) |
7994 | { | |
7995 | if (type) | |
7996 | cp_error ("multiple declarations `%T' and `%T'", type, id); | |
7997 | else | |
7998 | type = IDENTIFIER_TYPE_VALUE (id); | |
7999 | goto found; | |
8000 | } | |
8001 | ||
f376e137 | 8002 | for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++) |
8d08fdba MS |
8003 | { |
8004 | if (ridpointers[i] == id) | |
8005 | { | |
8006 | if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) | |
8007 | { | |
e1cd6e56 MS |
8008 | if (pedantic && ! in_system_header) |
8009 | pedwarn ("ANSI C++ does not support `long long'"); | |
9a3b49ac | 8010 | if (longlong) |
a0a33927 | 8011 | error ("`long long long' is too long for GCC"); |
8d08fdba MS |
8012 | else |
8013 | longlong = 1; | |
8014 | } | |
8015 | else if (RIDBIT_SETP (i, specbits)) | |
a0a33927 | 8016 | pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); |
8d08fdba MS |
8017 | RIDBIT_SET (i, specbits); |
8018 | goto found; | |
8019 | } | |
8020 | } | |
8021 | } | |
e92cc029 | 8022 | /* C++ aggregate types. */ |
45537677 MS |
8023 | else if (TREE_CODE (id) == TYPE_DECL) |
8024 | { | |
8025 | if (type) | |
8026 | cp_error ("multiple declarations `%T' and `%T'", type, | |
8027 | TREE_TYPE (id)); | |
8028 | else | |
5566b478 MS |
8029 | { |
8030 | type = TREE_TYPE (id); | |
8031 | TREE_VALUE (spec) = type; | |
8032 | } | |
45537677 MS |
8033 | goto found; |
8034 | } | |
8d08fdba MS |
8035 | if (type) |
8036 | error ("two or more data types in declaration of `%s'", name); | |
8037 | else if (TREE_CODE (id) == IDENTIFIER_NODE) | |
8038 | { | |
8039 | register tree t = lookup_name (id, 1); | |
8040 | if (!t || TREE_CODE (t) != TYPE_DECL) | |
8041 | error ("`%s' fails to be a typedef or built in type", | |
8042 | IDENTIFIER_POINTER (id)); | |
8043 | else | |
8044 | { | |
8045 | type = TREE_TYPE (t); | |
6125f3be DE |
8046 | #if 0 |
8047 | /* See the code below that used this. */ | |
f6abb50a | 8048 | decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); |
6125f3be | 8049 | #endif |
8d08fdba MS |
8050 | typedef_decl = t; |
8051 | } | |
8052 | } | |
bd6dd845 | 8053 | else if (id != error_mark_node) |
8d08fdba MS |
8054 | /* Can't change CLASS nodes into RECORD nodes here! */ |
8055 | type = id; | |
8056 | ||
8057 | found: ; | |
8058 | } | |
8059 | ||
8060 | typedef_type = type; | |
8061 | ||
37c46b43 | 8062 | /* No type at all: default to `int', and set DEFAULTED_INT |
8d08fdba MS |
8063 | because it was not a user-defined typedef. |
8064 | Except when we have a `typedef' inside a signature, in | |
8065 | which case the type defaults to `unknown type' and is | |
8066 | instantiated when assigning to a signature pointer or ref. */ | |
8067 | ||
a3203465 MS |
8068 | if (type == NULL_TREE |
8069 | && (RIDBIT_SETP (RID_SIGNED, specbits) | |
8070 | || RIDBIT_SETP (RID_UNSIGNED, specbits) | |
8071 | || RIDBIT_SETP (RID_LONG, specbits) | |
8072 | || RIDBIT_SETP (RID_SHORT, specbits))) | |
8073 | { | |
8074 | /* These imply 'int'. */ | |
8075 | type = integer_type_node; | |
37c46b43 | 8076 | defaulted_int = 1; |
a3203465 MS |
8077 | } |
8078 | ||
8d08fdba MS |
8079 | if (type == NULL_TREE) |
8080 | { | |
8081 | explicit_int = -1; | |
8082 | if (return_type == return_dtor) | |
8083 | type = void_type_node; | |
8084 | else if (return_type == return_ctor) | |
f30432d7 | 8085 | type = build_pointer_type (ctor_return_type); |
51c184be MS |
8086 | else if (return_type == return_conversion) |
8087 | type = ctor_return_type; | |
8d08fdba MS |
8088 | else if (current_class_type |
8089 | && IS_SIGNATURE (current_class_type) | |
fc378698 | 8090 | && RIDBIT_SETP (RID_TYPEDEF, specbits) |
8d08fdba MS |
8091 | && (decl_context == FIELD || decl_context == NORMAL)) |
8092 | { | |
8093 | explicit_int = 0; | |
8094 | opaque_typedef = 1; | |
8095 | type = copy_node (opaque_type_node); | |
8096 | } | |
8097 | else | |
8098 | { | |
a28e3c7f MS |
8099 | if (funcdef_flag) |
8100 | { | |
8101 | if (warn_return_type | |
a3203465 | 8102 | && return_type == return_normal) |
a28e3c7f MS |
8103 | /* Save warning until we know what is really going on. */ |
8104 | warn_about_return_type = 1; | |
8105 | } | |
a3203465 MS |
8106 | else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) |
8107 | pedwarn ("ANSI C++ forbids typedef which does not specify a type"); | |
beb53fb8 JM |
8108 | else if (declspecs == NULL_TREE |
8109 | && (innermost_code != CALL_EXPR || pedantic)) | |
a28e3c7f MS |
8110 | cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class", |
8111 | dname); | |
8d08fdba MS |
8112 | type = integer_type_node; |
8113 | } | |
8114 | } | |
8115 | else if (return_type == return_dtor) | |
8116 | { | |
8117 | error ("return type specification for destructor invalid"); | |
8118 | type = void_type_node; | |
8119 | } | |
8120 | else if (return_type == return_ctor) | |
8121 | { | |
8122 | error ("return type specification for constructor invalid"); | |
f30432d7 | 8123 | type = build_pointer_type (ctor_return_type); |
8d08fdba | 8124 | } |
51c184be MS |
8125 | else if (return_type == return_conversion) |
8126 | { | |
e1cd6e56 | 8127 | if (comptypes (type, ctor_return_type, 1) == 0) |
51c184be MS |
8128 | cp_error ("operator `%T' declared to return `%T'", |
8129 | ctor_return_type, type); | |
8130 | else | |
8131 | cp_pedwarn ("return type specified for `operator %T'", | |
8132 | ctor_return_type); | |
8133 | ||
8134 | type = ctor_return_type; | |
8135 | } | |
8d08fdba MS |
8136 | |
8137 | ctype = NULL_TREE; | |
8138 | ||
8139 | /* Now process the modifiers that were specified | |
8140 | and check for invalid combinations. */ | |
8141 | ||
8142 | /* Long double is a special combination. */ | |
8143 | ||
8144 | if (RIDBIT_SETP (RID_LONG, specbits) | |
8145 | && TYPE_MAIN_VARIANT (type) == double_type_node) | |
8146 | { | |
8147 | RIDBIT_RESET (RID_LONG, specbits); | |
8148 | type = build_type_variant (long_double_type_node, TYPE_READONLY (type), | |
8149 | TYPE_VOLATILE (type)); | |
8150 | } | |
8151 | ||
8152 | /* Check all other uses of type modifiers. */ | |
8153 | ||
8154 | if (RIDBIT_SETP (RID_UNSIGNED, specbits) | |
8155 | || RIDBIT_SETP (RID_SIGNED, specbits) | |
8156 | || RIDBIT_SETP (RID_LONG, specbits) | |
8157 | || RIDBIT_SETP (RID_SHORT, specbits)) | |
8158 | { | |
8159 | int ok = 0; | |
8160 | ||
8161 | if (TREE_CODE (type) == REAL_TYPE) | |
8162 | error ("short, signed or unsigned invalid for `%s'", name); | |
b7484fbe | 8163 | else if (TREE_CODE (type) != INTEGER_TYPE) |
8d08fdba MS |
8164 | error ("long, short, signed or unsigned invalid for `%s'", name); |
8165 | else if (RIDBIT_SETP (RID_LONG, specbits) | |
8166 | && RIDBIT_SETP (RID_SHORT, specbits)) | |
8167 | error ("long and short specified together for `%s'", name); | |
8168 | else if ((RIDBIT_SETP (RID_LONG, specbits) | |
8169 | || RIDBIT_SETP (RID_SHORT, specbits)) | |
8170 | && explicit_char) | |
8171 | error ("long or short specified with char for `%s'", name); | |
8172 | else if ((RIDBIT_SETP (RID_LONG, specbits) | |
8173 | || RIDBIT_SETP (RID_SHORT, specbits)) | |
8174 | && TREE_CODE (type) == REAL_TYPE) | |
8175 | error ("long or short specified with floating type for `%s'", name); | |
8176 | else if (RIDBIT_SETP (RID_SIGNED, specbits) | |
8177 | && RIDBIT_SETP (RID_UNSIGNED, specbits)) | |
8178 | error ("signed and unsigned given together for `%s'", name); | |
8179 | else | |
8180 | { | |
8181 | ok = 1; | |
37c46b43 | 8182 | if (!explicit_int && !defaulted_int && !explicit_char && pedantic) |
8d08fdba MS |
8183 | { |
8184 | pedwarn ("long, short, signed or unsigned used invalidly for `%s'", | |
8185 | name); | |
8186 | if (flag_pedantic_errors) | |
8187 | ok = 0; | |
8188 | } | |
8189 | } | |
8190 | ||
8191 | /* Discard the type modifiers if they are invalid. */ | |
8192 | if (! ok) | |
8193 | { | |
8194 | RIDBIT_RESET (RID_UNSIGNED, specbits); | |
8195 | RIDBIT_RESET (RID_SIGNED, specbits); | |
8196 | RIDBIT_RESET (RID_LONG, specbits); | |
8197 | RIDBIT_RESET (RID_SHORT, specbits); | |
8198 | longlong = 0; | |
8199 | } | |
8200 | } | |
8201 | ||
37c46b43 MS |
8202 | if (RIDBIT_SETP (RID_COMPLEX, specbits) |
8203 | && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) | |
8204 | { | |
8205 | error ("complex invalid for `%s'", name); | |
8206 | RIDBIT_RESET (RID_COMPLEX, specbits); | |
8207 | } | |
8208 | ||
8d08fdba MS |
8209 | /* Decide whether an integer type is signed or not. |
8210 | Optionally treat bitfields as signed by default. */ | |
8211 | if (RIDBIT_SETP (RID_UNSIGNED, specbits) | |
8d08fdba | 8212 | || (bitfield && ! flag_signed_bitfields |
37c46b43 | 8213 | && (explicit_int || defaulted_int || explicit_char |
8d08fdba MS |
8214 | /* A typedef for plain `int' without `signed' |
8215 | can be controlled just like plain `int'. */ | |
8216 | || ! (typedef_decl != NULL_TREE | |
8217 | && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
8218 | && TREE_CODE (type) != ENUMERAL_TYPE | |
8219 | && RIDBIT_NOTSETP (RID_SIGNED, specbits))) | |
8220 | { | |
8221 | if (longlong) | |
8222 | type = long_long_unsigned_type_node; | |
8223 | else if (RIDBIT_SETP (RID_LONG, specbits)) | |
8224 | type = long_unsigned_type_node; | |
8225 | else if (RIDBIT_SETP (RID_SHORT, specbits)) | |
8226 | type = short_unsigned_type_node; | |
8227 | else if (type == char_type_node) | |
8228 | type = unsigned_char_type_node; | |
8229 | else if (typedef_decl) | |
8230 | type = unsigned_type (type); | |
8231 | else | |
8232 | type = unsigned_type_node; | |
8233 | } | |
8234 | else if (RIDBIT_SETP (RID_SIGNED, specbits) | |
8235 | && type == char_type_node) | |
8236 | type = signed_char_type_node; | |
8237 | else if (longlong) | |
8238 | type = long_long_integer_type_node; | |
8239 | else if (RIDBIT_SETP (RID_LONG, specbits)) | |
8240 | type = long_integer_type_node; | |
8241 | else if (RIDBIT_SETP (RID_SHORT, specbits)) | |
8242 | type = short_integer_type_node; | |
8243 | ||
37c46b43 MS |
8244 | if (RIDBIT_SETP (RID_COMPLEX, specbits)) |
8245 | { | |
8246 | /* If we just have "complex", it is equivalent to | |
8247 | "complex double", but if any modifiers at all are specified it is | |
8248 | the complex form of TYPE. E.g, "complex short" is | |
8249 | "complex short int". */ | |
8250 | ||
8251 | if (defaulted_int && ! longlong | |
8252 | && ! (RIDBIT_SETP (RID_LONG, specbits) | |
8253 | || RIDBIT_SETP (RID_SHORT, specbits) | |
8254 | || RIDBIT_SETP (RID_SIGNED, specbits) | |
8255 | || RIDBIT_SETP (RID_UNSIGNED, specbits))) | |
8256 | type = complex_double_type_node; | |
8257 | else if (type == integer_type_node) | |
8258 | type = complex_integer_type_node; | |
8259 | else if (type == float_type_node) | |
8260 | type = complex_float_type_node; | |
8261 | else if (type == double_type_node) | |
8262 | type = complex_double_type_node; | |
8263 | else if (type == long_double_type_node) | |
8264 | type = complex_long_double_type_node; | |
8265 | else | |
8266 | type = build_complex_type (type); | |
8267 | } | |
8268 | ||
8d08fdba MS |
8269 | /* Set CONSTP if this declaration is `const', whether by |
8270 | explicit specification or via a typedef. | |
8271 | Likewise for VOLATILEP. */ | |
8272 | ||
8273 | constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type); | |
8274 | volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type); | |
8275 | staticp = 0; | |
8276 | inlinep = !! RIDBIT_SETP (RID_INLINE, specbits); | |
8d08fdba | 8277 | virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits); |
db5ae43f MS |
8278 | RIDBIT_RESET (RID_VIRTUAL, specbits); |
8279 | explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0; | |
8280 | RIDBIT_RESET (RID_EXPLICIT, specbits); | |
8d08fdba | 8281 | |
8d08fdba MS |
8282 | if (RIDBIT_SETP (RID_STATIC, specbits)) |
8283 | staticp = 1 + (decl_context == FIELD); | |
8284 | ||
8285 | if (virtualp && staticp == 2) | |
8286 | { | |
8287 | cp_error ("member `%D' cannot be declared both virtual and static", | |
8288 | dname); | |
8289 | staticp = 0; | |
8290 | } | |
8291 | friendp = RIDBIT_SETP (RID_FRIEND, specbits); | |
8d08fdba MS |
8292 | RIDBIT_RESET (RID_FRIEND, specbits); |
8293 | ||
8294 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
8295 | { | |
8296 | if (decl_context == PARM) | |
8297 | { | |
db5ae43f | 8298 | error ("non-member `%s' cannot be declared `mutable'", name); |
8d08fdba MS |
8299 | RIDBIT_RESET (RID_MUTABLE, specbits); |
8300 | } | |
8301 | else if (friendp || decl_context == TYPENAME) | |
8302 | { | |
db5ae43f | 8303 | error ("non-object member `%s' cannot be declared `mutable'", name); |
8d08fdba MS |
8304 | RIDBIT_RESET (RID_MUTABLE, specbits); |
8305 | } | |
8d08fdba MS |
8306 | } |
8307 | ||
8308 | /* Warn if two storage classes are given. Default to `auto'. */ | |
8309 | ||
8310 | if (RIDBIT_ANY_SET (specbits)) | |
8311 | { | |
8312 | if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++; | |
8313 | if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++; | |
8314 | if (decl_context == PARM && nclasses > 0) | |
8315 | error ("storage class specifiers invalid in parameter declarations"); | |
8316 | if (RIDBIT_SETP (RID_TYPEDEF, specbits)) | |
8317 | { | |
8318 | if (decl_context == PARM) | |
8319 | error ("typedef declaration invalid in parameter declaration"); | |
8320 | nclasses++; | |
8321 | } | |
8322 | if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++; | |
8323 | if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++; | |
8324 | } | |
8325 | ||
8326 | /* Give error if `virtual' is used outside of class declaration. */ | |
b7484fbe MS |
8327 | if (virtualp |
8328 | && (current_class_name == NULL_TREE || decl_context != FIELD)) | |
8d08fdba MS |
8329 | { |
8330 | error ("virtual outside class declaration"); | |
8331 | virtualp = 0; | |
8332 | } | |
8333 | if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits)) | |
8334 | { | |
8335 | error ("only members can be declared mutable"); | |
8336 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
8337 | } | |
8338 | ||
8339 | /* Static anonymous unions are dealt with here. */ | |
8340 | if (staticp && decl_context == TYPENAME | |
8341 | && TREE_CODE (declspecs) == TREE_LIST | |
8342 | && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE | |
8343 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs)))) | |
8344 | decl_context = FIELD; | |
8345 | ||
8346 | /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual' | |
8347 | is used in a signature member function declaration. */ | |
8348 | if (decl_context == FIELD | |
8349 | && IS_SIGNATURE (current_class_type) | |
fc378698 | 8350 | && RIDBIT_NOTSETP (RID_TYPEDEF, specbits)) |
8d08fdba MS |
8351 | { |
8352 | if (constp) | |
8353 | { | |
8354 | error ("`const' specified for signature member function `%s'", name); | |
8355 | constp = 0; | |
8356 | } | |
8357 | if (volatilep) | |
8358 | { | |
a28e3c7f MS |
8359 | error ("`volatile' specified for signature member function `%s'", |
8360 | name); | |
8d08fdba MS |
8361 | volatilep = 0; |
8362 | } | |
8363 | if (inlinep) | |
8364 | { | |
8365 | error ("`inline' specified for signature member function `%s'", name); | |
8366 | /* Later, we'll make signature member functions inline. */ | |
8367 | inlinep = 0; | |
8368 | } | |
8369 | if (friendp) | |
8370 | { | |
8371 | error ("`friend' declaration in signature definition"); | |
8372 | friendp = 0; | |
8373 | } | |
8374 | if (virtualp) | |
8375 | { | |
a28e3c7f MS |
8376 | error ("`virtual' specified for signature member function `%s'", |
8377 | name); | |
8d08fdba MS |
8378 | /* Later, we'll make signature member functions virtual. */ |
8379 | virtualp = 0; | |
8380 | } | |
8381 | } | |
8382 | ||
8383 | /* Warn about storage classes that are invalid for certain | |
8384 | kinds of declarations (parameters, typenames, etc.). */ | |
8385 | ||
8386 | if (nclasses > 1) | |
8387 | error ("multiple storage classes in declaration of `%s'", name); | |
8388 | else if (decl_context != NORMAL && nclasses > 0) | |
8389 | { | |
db5ae43f | 8390 | if ((decl_context == PARM || decl_context == CATCHPARM) |
8d08fdba MS |
8391 | && (RIDBIT_SETP (RID_REGISTER, specbits) |
8392 | || RIDBIT_SETP (RID_AUTO, specbits))) | |
8393 | ; | |
fc378698 MS |
8394 | else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) |
8395 | ; | |
8d08fdba | 8396 | else if (decl_context == FIELD |
fc378698 | 8397 | && ! IS_SIGNATURE (current_class_type) |
8d08fdba MS |
8398 | /* C++ allows static class elements */ |
8399 | && RIDBIT_SETP (RID_STATIC, specbits)) | |
8400 | /* C++ also allows inlines and signed and unsigned elements, | |
8401 | but in those cases we don't come in here. */ | |
8402 | ; | |
8403 | else | |
8404 | { | |
8405 | if (decl_context == FIELD) | |
8406 | { | |
b7484fbe MS |
8407 | tree tmp = NULL_TREE; |
8408 | register int op = 0; | |
8409 | ||
8410 | if (declarator) | |
8411 | { | |
9e9ff709 MS |
8412 | /* Avoid trying to get an operand off an identifier node. */ |
8413 | if (TREE_CODE (declarator) == IDENTIFIER_NODE) | |
8414 | tmp = declarator; | |
8415 | else | |
8416 | tmp = TREE_OPERAND (declarator, 0); | |
b7484fbe MS |
8417 | op = IDENTIFIER_OPNAME_P (tmp); |
8418 | } | |
8d08fdba MS |
8419 | error ("storage class specified for %s `%s'", |
8420 | IS_SIGNATURE (current_class_type) | |
8421 | ? (op | |
8422 | ? "signature member operator" | |
8423 | : "signature member function") | |
b7484fbe | 8424 | : (op ? "member operator" : "field"), |
8d08fdba MS |
8425 | op ? operator_name_string (tmp) : name); |
8426 | } | |
8427 | else | |
db5ae43f | 8428 | error (((decl_context == PARM || decl_context == CATCHPARM) |
8d08fdba MS |
8429 | ? "storage class specified for parameter `%s'" |
8430 | : "storage class specified for typename"), name); | |
8431 | RIDBIT_RESET (RID_REGISTER, specbits); | |
8432 | RIDBIT_RESET (RID_AUTO, specbits); | |
8433 | RIDBIT_RESET (RID_EXTERN, specbits); | |
8434 | ||
8435 | if (decl_context == FIELD && IS_SIGNATURE (current_class_type)) | |
8436 | { | |
8437 | RIDBIT_RESET (RID_STATIC, specbits); | |
8438 | staticp = 0; | |
8439 | } | |
8440 | } | |
8441 | } | |
8442 | else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag) | |
8443 | { | |
a9aedbc2 | 8444 | if (toplevel_bindings_p ()) |
8d08fdba | 8445 | { |
59be0cdd | 8446 | /* It's common practice (and completely valid) to have a const |
8d08fdba MS |
8447 | be initialized and declared extern. */ |
8448 | if (! constp) | |
8449 | warning ("`%s' initialized and declared `extern'", name); | |
8450 | } | |
8451 | else | |
8452 | error ("`%s' has both `extern' and initializer", name); | |
8453 | } | |
8454 | else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag | |
a9aedbc2 | 8455 | && ! toplevel_bindings_p ()) |
8d08fdba | 8456 | error ("nested function `%s' declared `extern'", name); |
a9aedbc2 | 8457 | else if (toplevel_bindings_p ()) |
8d08fdba MS |
8458 | { |
8459 | if (RIDBIT_SETP (RID_AUTO, specbits)) | |
8460 | error ("top-level declaration of `%s' specifies `auto'", name); | |
8d08fdba MS |
8461 | } |
8462 | ||
909e536a MS |
8463 | if (nclasses > 0 && friendp) |
8464 | error ("storage class specifiers invalid in friend function declarations"); | |
8465 | ||
8d08fdba MS |
8466 | /* Now figure out the structure of the declarator proper. |
8467 | Descend through it, creating more complex types, until we reach | |
8468 | the declared identifier (or NULL_TREE, in an absolute declarator). */ | |
8469 | ||
386b8a85 JM |
8470 | while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE |
8471 | && TREE_CODE (declarator) != TEMPLATE_ID_EXPR) | |
8d08fdba MS |
8472 | { |
8473 | /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), | |
8474 | an INDIRECT_REF (for *...), | |
8475 | a CALL_EXPR (for ...(...)), | |
8476 | an identifier (for the name being declared) | |
8477 | or a null pointer (for the place in an absolute declarator | |
8478 | where the name was omitted). | |
8479 | For the last two cases, we have just exited the loop. | |
8480 | ||
8481 | For C++ it could also be | |
8482 | a SCOPE_REF (for class :: ...). In this case, we have converted | |
8483 | sensible names to types, and those are the values we use to | |
8484 | qualify the member name. | |
8485 | an ADDR_EXPR (for &...), | |
8486 | a BIT_NOT_EXPR (for destructors) | |
8d08fdba MS |
8487 | |
8488 | At this point, TYPE is the type of elements of an array, | |
8489 | or for a function to return, or for a pointer to point to. | |
8490 | After this sequence of ifs, TYPE is the type of the | |
8491 | array or function or pointer, and DECLARATOR has had its | |
8492 | outermost layer removed. */ | |
8493 | ||
bd6dd845 | 8494 | if (type == error_mark_node) |
8d08fdba MS |
8495 | { |
8496 | if (TREE_CODE (declarator) == SCOPE_REF) | |
8497 | declarator = TREE_OPERAND (declarator, 1); | |
8498 | else | |
8499 | declarator = TREE_OPERAND (declarator, 0); | |
8500 | continue; | |
8501 | } | |
8502 | if (quals != NULL_TREE | |
8503 | && (declarator == NULL_TREE | |
8504 | || TREE_CODE (declarator) != SCOPE_REF)) | |
8505 | { | |
8506 | if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE) | |
8507 | ctype = TYPE_METHOD_BASETYPE (type); | |
8508 | if (ctype != NULL_TREE) | |
8509 | { | |
8d08fdba | 8510 | tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); |
8d08fdba MS |
8511 | ctype = grok_method_quals (ctype, dummy, quals); |
8512 | type = TREE_TYPE (dummy); | |
8513 | quals = NULL_TREE; | |
8514 | } | |
8515 | } | |
8516 | switch (TREE_CODE (declarator)) | |
8517 | { | |
8518 | case ARRAY_REF: | |
8519 | { | |
8520 | register tree itype = NULL_TREE; | |
8521 | register tree size = TREE_OPERAND (declarator, 1); | |
b7484fbe MS |
8522 | /* The index is a signed object `sizetype' bits wide. */ |
8523 | tree index_type = signed_type (sizetype); | |
8d08fdba MS |
8524 | |
8525 | declarator = TREE_OPERAND (declarator, 0); | |
8526 | ||
8527 | /* Check for some types that there cannot be arrays of. */ | |
8528 | ||
8529 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
8530 | { | |
8531 | cp_error ("declaration of `%D' as array of voids", dname); | |
8532 | type = error_mark_node; | |
8533 | } | |
8534 | ||
8535 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
8536 | { | |
8537 | cp_error ("declaration of `%D' as array of functions", dname); | |
8538 | type = error_mark_node; | |
8539 | } | |
8540 | ||
8541 | /* ARM $8.4.3: Since you can't have a pointer to a reference, | |
8542 | you can't have arrays of references. If we allowed them, | |
59be0cdd | 8543 | then we'd be saying x[i] is valid for an array x, but |
8d08fdba MS |
8544 | then you'd have to ask: what does `*(x + i)' mean? */ |
8545 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
8546 | { | |
8547 | if (decl_context == TYPENAME) | |
8548 | cp_error ("cannot make arrays of references"); | |
8549 | else | |
8550 | cp_error ("declaration of `%D' as array of references", | |
8551 | dname); | |
8552 | type = error_mark_node; | |
8553 | } | |
8554 | ||
8555 | if (TREE_CODE (type) == OFFSET_TYPE) | |
8556 | { | |
8557 | cp_error ("declaration of `%D' as array of data members", | |
8558 | dname); | |
8559 | type = error_mark_node; | |
8560 | } | |
8561 | ||
8562 | if (TREE_CODE (type) == METHOD_TYPE) | |
8563 | { | |
8564 | cp_error ("declaration of `%D' as array of function members", | |
8565 | dname); | |
8566 | type = error_mark_node; | |
8567 | } | |
8568 | ||
8569 | if (size == error_mark_node) | |
8570 | type = error_mark_node; | |
8571 | ||
8572 | if (type == error_mark_node) | |
8573 | continue; | |
8574 | ||
8575 | if (size) | |
8576 | { | |
8577 | /* Must suspend_momentary here because the index | |
8578 | type may need to live until the end of the function. | |
8579 | For example, it is used in the declaration of a | |
8580 | variable which requires destructing at the end of | |
8581 | the function; then build_vec_delete will need this | |
8582 | value. */ | |
8583 | int yes = suspend_momentary (); | |
8584 | /* might be a cast */ | |
8585 | if (TREE_CODE (size) == NOP_EXPR | |
8586 | && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) | |
8587 | size = TREE_OPERAND (size, 0); | |
8588 | ||
5566b478 MS |
8589 | /* If this involves a template parameter, it'll be |
8590 | constant, but we don't know what the value is yet. */ | |
5156628f | 8591 | if (processing_template_decl) |
5566b478 MS |
8592 | { |
8593 | itype = make_node (INTEGER_TYPE); | |
8594 | TYPE_MIN_VALUE (itype) = size_zero_node; | |
8595 | TYPE_MAX_VALUE (itype) = build_min | |
8596 | (MINUS_EXPR, sizetype, size, integer_one_node); | |
8597 | goto dont_grok_size; | |
8598 | } | |
8d08fdba MS |
8599 | |
8600 | if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE | |
8601 | && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) | |
8602 | { | |
8603 | cp_error ("size of array `%D' has non-integer type", | |
8604 | dname); | |
8605 | size = integer_one_node; | |
8606 | } | |
8607 | if (TREE_READONLY_DECL_P (size)) | |
8608 | size = decl_constant_value (size); | |
e1cd6e56 | 8609 | if (pedantic && integer_zerop (size)) |
8d08fdba MS |
8610 | cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname); |
8611 | if (TREE_CONSTANT (size)) | |
8612 | { | |
dff6b454 RK |
8613 | int old_flag_pedantic_errors = flag_pedantic_errors; |
8614 | int old_pedantic = pedantic; | |
8615 | pedantic = flag_pedantic_errors = 1; | |
8616 | /* Always give overflow errors on array subscripts. */ | |
8d08fdba | 8617 | constant_expression_warning (size); |
dff6b454 RK |
8618 | pedantic = old_pedantic; |
8619 | flag_pedantic_errors = old_flag_pedantic_errors; | |
8d08fdba MS |
8620 | if (INT_CST_LT (size, integer_zero_node)) |
8621 | { | |
8622 | cp_error ("size of array `%D' is negative", dname); | |
8623 | size = integer_one_node; | |
8624 | } | |
8d08fdba MS |
8625 | } |
8626 | else | |
8627 | { | |
e1cd6e56 | 8628 | if (pedantic) |
a0a33927 MS |
8629 | { |
8630 | if (dname) | |
8631 | cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", | |
8632 | dname); | |
8633 | else | |
8634 | cp_pedwarn ("ANSI C++ forbids variable-size array"); | |
8635 | } | |
8d08fdba | 8636 | } |
b7484fbe | 8637 | |
beb53fb8 JM |
8638 | itype |
8639 | = fold (build_binary_op (MINUS_EXPR, | |
37c46b43 MS |
8640 | cp_convert (index_type, size), |
8641 | cp_convert (index_type, | |
8642 | integer_one_node), 1)); | |
b7484fbe MS |
8643 | if (! TREE_CONSTANT (itype)) |
8644 | itype = variable_size (itype); | |
594740f3 MS |
8645 | else if (TREE_OVERFLOW (itype)) |
8646 | { | |
8647 | error ("overflow in array dimension"); | |
8648 | TREE_OVERFLOW (itype) = 0; | |
8649 | } | |
fc378698 MS |
8650 | |
8651 | /* If we're a parm, we need to have a permanent type so | |
8652 | mangling checks for re-use will work right. If both the | |
8653 | element and index types are permanent, the array type | |
8654 | will be, too. */ | |
8655 | if (decl_context == PARM | |
8656 | && allocation_temporary_p () && TREE_PERMANENT (type)) | |
8657 | { | |
8658 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
8659 | itype = build_index_type (itype); | |
8660 | pop_obstacks (); | |
8661 | } | |
8662 | else | |
8663 | itype = build_index_type (itype); | |
8664 | ||
5566b478 | 8665 | dont_grok_size: |
8d08fdba MS |
8666 | resume_momentary (yes); |
8667 | } | |
8668 | ||
8669 | /* Build the array type itself, then merge any constancy or | |
8670 | volatility into the target type. We must do it in this order | |
8671 | to ensure that the TYPE_MAIN_VARIANT field of the array type | |
8672 | is set correctly. */ | |
8673 | ||
8674 | type = build_cplus_array_type (type, itype); | |
8675 | if (constp || volatilep) | |
f376e137 | 8676 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
8677 | |
8678 | ctype = NULL_TREE; | |
8679 | } | |
8680 | break; | |
8681 | ||
8682 | case CALL_EXPR: | |
8683 | { | |
8684 | tree arg_types; | |
f376e137 MS |
8685 | int funcdecl_p; |
8686 | tree inner_parms = TREE_OPERAND (declarator, 1); | |
8687 | tree inner_decl = TREE_OPERAND (declarator, 0); | |
8d08fdba MS |
8688 | |
8689 | /* Declaring a function type. | |
8690 | Make sure we have a valid type for the function to return. */ | |
8691 | #if 0 | |
8692 | /* Is this an error? Should they be merged into TYPE here? */ | |
8693 | if (pedantic && (constp || volatilep)) | |
8694 | pedwarn ("function declared to return const or volatile result"); | |
8695 | #else | |
21474714 MS |
8696 | /* Merge any constancy or volatility into the function return |
8697 | type. */ | |
8d08fdba MS |
8698 | |
8699 | if (constp || volatilep) | |
8700 | { | |
f376e137 | 8701 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
8702 | if (IS_AGGR_TYPE (type)) |
8703 | build_pointer_type (type); | |
8704 | constp = 0; | |
8705 | volatilep = 0; | |
8706 | } | |
8707 | #endif | |
8708 | ||
8709 | /* Warn about some types functions can't return. */ | |
8710 | ||
8711 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
8712 | { | |
8713 | error ("`%s' declared as function returning a function", name); | |
8714 | type = integer_type_node; | |
8715 | } | |
8716 | if (TREE_CODE (type) == ARRAY_TYPE) | |
8717 | { | |
8718 | error ("`%s' declared as function returning an array", name); | |
8719 | type = integer_type_node; | |
8720 | } | |
8721 | ||
f376e137 MS |
8722 | if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) |
8723 | inner_decl = TREE_OPERAND (inner_decl, 1); | |
8724 | ||
386b8a85 JM |
8725 | if (inner_decl && TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR) |
8726 | inner_decl = dname; | |
8727 | ||
b7484fbe MS |
8728 | /* Pick up type qualifiers which should be applied to `this'. */ |
8729 | quals = TREE_OPERAND (declarator, 2); | |
8730 | ||
c11b6f21 MS |
8731 | /* Pick up the exception specifications. */ |
8732 | raises = TREE_TYPE (declarator); | |
8733 | ||
f376e137 MS |
8734 | /* Say it's a definition only for the CALL_EXPR |
8735 | closest to the identifier. */ | |
beb53fb8 | 8736 | funcdecl_p |
386b8a85 JM |
8737 | = inner_decl |
8738 | && (TREE_CODE (inner_decl) == IDENTIFIER_NODE | |
8739 | || TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR | |
8740 | || TREE_CODE (inner_decl) == BIT_NOT_EXPR); | |
8741 | ||
8d08fdba MS |
8742 | if (ctype == NULL_TREE |
8743 | && decl_context == FIELD | |
f376e137 | 8744 | && funcdecl_p |
8d08fdba MS |
8745 | && (friendp == 0 || dname == current_class_name)) |
8746 | ctype = current_class_type; | |
8747 | ||
51c184be | 8748 | if (ctype && return_type == return_conversion) |
8d08fdba MS |
8749 | TYPE_HAS_CONVERSION (ctype) = 1; |
8750 | if (ctype && constructor_name (ctype) == dname) | |
8751 | { | |
8752 | /* We are within a class's scope. If our declarator name | |
8753 | is the same as the class name, and we are defining | |
8754 | a function, then it is a constructor/destructor, and | |
8755 | therefore returns a void type. */ | |
8756 | ||
8757 | if (flags == DTOR_FLAG) | |
8758 | { | |
8759 | /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may | |
8760 | not be declared const or volatile. A destructor | |
8761 | may not be static. */ | |
8762 | if (staticp == 2) | |
8763 | error ("destructor cannot be static member function"); | |
b7484fbe | 8764 | if (quals) |
8d08fdba | 8765 | { |
b7484fbe | 8766 | error ("destructors cannot be declared `const' or `volatile'"); |
8d08fdba MS |
8767 | return void_type_node; |
8768 | } | |
8769 | if (decl_context == FIELD) | |
8770 | { | |
8771 | if (! member_function_or_else (ctype, current_class_type, | |
8772 | "destructor for alien class `%s' cannot be a member")) | |
8773 | return void_type_node; | |
8774 | } | |
8775 | } | |
e92cc029 | 8776 | else /* it's a constructor. */ |
8d08fdba | 8777 | { |
db5ae43f MS |
8778 | if (explicitp == 1) |
8779 | explicitp = 2; | |
8d08fdba MS |
8780 | /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may |
8781 | not be declared const or volatile. A constructor may | |
8782 | not be virtual. A constructor may not be static. */ | |
8783 | if (staticp == 2) | |
8784 | error ("constructor cannot be static member function"); | |
8785 | if (virtualp) | |
8786 | { | |
8787 | pedwarn ("constructors cannot be declared virtual"); | |
8788 | virtualp = 0; | |
8789 | } | |
b7484fbe | 8790 | if (quals) |
8d08fdba | 8791 | { |
b7484fbe | 8792 | error ("constructors cannot be declared `const' or `volatile'"); |
8d08fdba MS |
8793 | return void_type_node; |
8794 | } | |
8d08fdba | 8795 | { |
51c184be | 8796 | RID_BIT_TYPE tmp_bits; |
fc378698 | 8797 | bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof (RID_BIT_TYPE)); |
51c184be MS |
8798 | RIDBIT_RESET (RID_INLINE, tmp_bits); |
8799 | RIDBIT_RESET (RID_STATIC, tmp_bits); | |
8800 | if (RIDBIT_ANY_SET (tmp_bits)) | |
8d08fdba | 8801 | error ("return value type specifier for constructor ignored"); |
8d08fdba | 8802 | } |
f30432d7 | 8803 | type = build_pointer_type (ctype); |
beb53fb8 JM |
8804 | if (decl_context == FIELD |
8805 | && IS_SIGNATURE (current_class_type)) | |
8d08fdba MS |
8806 | { |
8807 | error ("constructor not allowed in signature"); | |
8808 | return void_type_node; | |
8809 | } | |
8810 | else if (decl_context == FIELD) | |
8811 | { | |
8812 | if (! member_function_or_else (ctype, current_class_type, | |
8813 | "constructor for alien class `%s' cannot be member")) | |
8814 | return void_type_node; | |
8815 | TYPE_HAS_CONSTRUCTOR (ctype) = 1; | |
8816 | if (return_type != return_ctor) | |
8817 | return NULL_TREE; | |
8818 | } | |
8819 | } | |
8820 | if (decl_context == FIELD) | |
8821 | staticp = 0; | |
8822 | } | |
b7484fbe | 8823 | else if (friendp) |
8d08fdba | 8824 | { |
b7484fbe MS |
8825 | if (initialized) |
8826 | error ("can't initialize friend function `%s'", name); | |
8827 | if (virtualp) | |
8828 | { | |
8829 | /* Cannot be both friend and virtual. */ | |
8830 | error ("virtual functions cannot be friends"); | |
8831 | RIDBIT_RESET (RID_FRIEND, specbits); | |
8832 | friendp = 0; | |
8833 | } | |
28cbf42c MS |
8834 | if (decl_context == NORMAL) |
8835 | error ("friend declaration not in class definition"); | |
8836 | if (current_function_decl && funcdef_flag) | |
8837 | cp_error ("can't define friend function `%s' in a local class definition", | |
8838 | name); | |
8d08fdba MS |
8839 | } |
8840 | ||
8d08fdba MS |
8841 | /* Construct the function type and go to the next |
8842 | inner layer of declarator. */ | |
8843 | ||
f376e137 | 8844 | declarator = TREE_OPERAND (declarator, 0); |
8d08fdba | 8845 | |
f376e137 MS |
8846 | /* FIXME: This is where default args should be fully |
8847 | processed. */ | |
8d08fdba | 8848 | |
f376e137 | 8849 | arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0); |
8d08fdba MS |
8850 | |
8851 | if (declarator) | |
8852 | { | |
8853 | /* Get past destructors, etc. | |
8854 | We know we have one because FLAGS will be non-zero. | |
8855 | ||
8856 | Complain about improper parameter lists here. */ | |
8857 | if (TREE_CODE (declarator) == BIT_NOT_EXPR) | |
8858 | { | |
8859 | declarator = TREE_OPERAND (declarator, 0); | |
8860 | ||
8861 | if (strict_prototype == 0 && arg_types == NULL_TREE) | |
8862 | arg_types = void_list_node; | |
8863 | else if (arg_types == NULL_TREE | |
8864 | || arg_types != void_list_node) | |
8865 | { | |
8866 | error ("destructors cannot be specified with parameters"); | |
8867 | arg_types = void_list_node; | |
8868 | } | |
8869 | } | |
8870 | } | |
8871 | ||
d22c8596 | 8872 | /* ANSI says that `const int foo ();' |
8d08fdba | 8873 | does not make the function foo const. */ |
d22c8596 | 8874 | type = build_function_type (type, arg_types); |
42976354 BK |
8875 | |
8876 | { | |
8877 | tree t; | |
8878 | for (t = arg_types; t; t = TREE_CHAIN (t)) | |
8879 | if (TREE_PURPOSE (t) | |
8880 | && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) | |
8881 | { | |
8882 | add_defarg_fn (type); | |
8883 | break; | |
8884 | } | |
8885 | } | |
8d08fdba MS |
8886 | } |
8887 | break; | |
8888 | ||
8889 | case ADDR_EXPR: | |
8890 | case INDIRECT_REF: | |
8891 | /* Filter out pointers-to-references and references-to-references. | |
8892 | We can get these if a TYPE_DECL is used. */ | |
8893 | ||
8894 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
8895 | { | |
8896 | error ("cannot declare %s to references", | |
8897 | TREE_CODE (declarator) == ADDR_EXPR | |
8898 | ? "references" : "pointers"); | |
8899 | declarator = TREE_OPERAND (declarator, 0); | |
8900 | continue; | |
8901 | } | |
8902 | ||
a5894242 MS |
8903 | if (TREE_CODE (type) == OFFSET_TYPE |
8904 | && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE | |
8905 | || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE)) | |
8906 | { | |
8907 | cp_error ("cannot declare pointer to `%#T' member", | |
8908 | TREE_TYPE (type)); | |
8909 | type = TREE_TYPE (type); | |
8910 | } | |
8911 | ||
8d08fdba MS |
8912 | /* Merge any constancy or volatility into the target type |
8913 | for the pointer. */ | |
8914 | ||
8915 | if (constp || volatilep) | |
8916 | { | |
8917 | /* A const or volatile signature pointer/reference is | |
8918 | pointing to a const or volatile object, i.e., the | |
8919 | `optr' is const or volatile, respectively, not the | |
8920 | signature pointer/reference itself. */ | |
8921 | if (! IS_SIGNATURE (type)) | |
8922 | { | |
f376e137 | 8923 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
8924 | if (IS_AGGR_TYPE (type)) |
8925 | build_pointer_type (type); | |
8926 | constp = 0; | |
8927 | volatilep = 0; | |
8928 | } | |
8929 | } | |
8930 | ||
8931 | if (IS_SIGNATURE (type)) | |
8932 | { | |
8933 | if (TREE_CODE (declarator) == ADDR_EXPR) | |
8934 | { | |
63718c49 GB |
8935 | if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE |
8936 | && TYPE_SIZE (type)) | |
8937 | cp_warning ("empty signature `%T' used in signature reference declaration", | |
8938 | type); | |
8d08fdba MS |
8939 | #if 0 |
8940 | type = build_signature_reference_type (type, | |
8941 | constp, volatilep); | |
8942 | #else | |
8943 | sorry ("signature reference"); | |
8944 | return NULL_TREE; | |
8945 | #endif | |
8946 | } | |
8947 | else | |
8948 | { | |
63718c49 GB |
8949 | if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE |
8950 | && TYPE_SIZE (type)) | |
8951 | cp_warning ("empty signature `%T' used in signature pointer declaration", | |
8952 | type); | |
8d08fdba MS |
8953 | type = build_signature_pointer_type (type, |
8954 | constp, volatilep); | |
8955 | } | |
8956 | constp = 0; | |
8957 | volatilep = 0; | |
8958 | } | |
8959 | else if (TREE_CODE (declarator) == ADDR_EXPR) | |
8960 | { | |
8961 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
8962 | { | |
8963 | error ("cannot declare references to functions; use pointer to function instead"); | |
8964 | type = build_pointer_type (type); | |
8965 | } | |
8966 | else | |
8967 | { | |
8968 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
8969 | error ("invalid type: `void &'"); | |
8970 | else | |
8971 | type = build_reference_type (type); | |
8972 | } | |
8973 | } | |
8974 | else if (TREE_CODE (type) == METHOD_TYPE) | |
8975 | { | |
8976 | type = build_ptrmemfunc_type (build_pointer_type (type)); | |
8977 | } | |
8978 | else | |
8979 | type = build_pointer_type (type); | |
8980 | ||
8981 | /* Process a list of type modifier keywords (such as | |
8982 | const or volatile) that were given inside the `*' or `&'. */ | |
8983 | ||
8984 | if (TREE_TYPE (declarator)) | |
8985 | { | |
8986 | register tree typemodlist; | |
8987 | int erred = 0; | |
8988 | for (typemodlist = TREE_TYPE (declarator); typemodlist; | |
8989 | typemodlist = TREE_CHAIN (typemodlist)) | |
8990 | { | |
8991 | if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST]) | |
8992 | constp++; | |
8993 | else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE]) | |
8994 | volatilep++; | |
8995 | else if (!erred) | |
8996 | { | |
8997 | erred = 1; | |
8998 | error ("invalid type modifier within %s declarator", | |
8999 | TREE_CODE (declarator) == ADDR_EXPR | |
9000 | ? "reference" : "pointer"); | |
9001 | } | |
9002 | } | |
9003 | if (constp > 1) | |
a0a33927 | 9004 | pedwarn ("duplicate `const'"); |
8d08fdba | 9005 | if (volatilep > 1) |
a0a33927 MS |
9006 | pedwarn ("duplicate `volatile'"); |
9007 | if (TREE_CODE (declarator) == ADDR_EXPR | |
9008 | && (constp || volatilep)) | |
9009 | { | |
9010 | if (constp) | |
e1cd6e56 | 9011 | pedwarn ("discarding `const' applied to a reference"); |
a0a33927 | 9012 | if (volatilep) |
e1cd6e56 | 9013 | pedwarn ("discarding `volatile' applied to a reference"); |
a0a33927 MS |
9014 | constp = volatilep = 0; |
9015 | } | |
8d08fdba MS |
9016 | } |
9017 | declarator = TREE_OPERAND (declarator, 0); | |
9018 | ctype = NULL_TREE; | |
9019 | break; | |
9020 | ||
9021 | case SCOPE_REF: | |
9022 | { | |
9023 | /* We have converted type names to NULL_TREE if the | |
9024 | name was bogus, or to a _TYPE node, if not. | |
9025 | ||
9026 | The variable CTYPE holds the type we will ultimately | |
9027 | resolve to. The code here just needs to build | |
9028 | up appropriate member types. */ | |
9029 | tree sname = TREE_OPERAND (declarator, 1); | |
386b8a85 JM |
9030 | tree t; |
9031 | ||
8d08fdba MS |
9032 | /* Destructors can have their visibilities changed as well. */ |
9033 | if (TREE_CODE (sname) == BIT_NOT_EXPR) | |
9034 | sname = TREE_OPERAND (sname, 0); | |
9035 | ||
9036 | if (TREE_COMPLEXITY (declarator) == 0) | |
9037 | /* This needs to be here, in case we are called | |
9038 | multiple times. */ ; | |
9039 | else if (friendp && (TREE_COMPLEXITY (declarator) < 2)) | |
9040 | /* don't fall out into global scope. Hides real bug? --eichin */ ; | |
5566b478 MS |
9041 | else if (! IS_AGGR_TYPE_CODE |
9042 | (TREE_CODE (TREE_OPERAND (declarator, 0)))) | |
9043 | ; | |
8d08fdba MS |
9044 | else if (TREE_COMPLEXITY (declarator) == current_class_depth) |
9045 | { | |
9a3b49ac MS |
9046 | /* Resolve any TYPENAME_TYPEs from the decl-specifier-seq |
9047 | that refer to ctype. They couldn't be resolved earlier | |
9048 | because we hadn't pushed into the class yet. | |
9049 | Example: resolve 'B<T>::type' in | |
9050 | 'B<typename B<T>::type> B<T>::f () { }'. */ | |
9051 | if (current_template_parms | |
9052 | && uses_template_parms (type) | |
9053 | && uses_template_parms (current_class_type)) | |
9054 | { | |
9055 | tree args = current_template_args (); | |
98c1c668 JM |
9056 | type = tsubst (type, args, |
9057 | TREE_VEC_LENGTH (TREE_VEC_ELT | |
9058 | (args, 0)), | |
9059 | NULL_TREE); | |
9a3b49ac MS |
9060 | } |
9061 | ||
a28e3c7f MS |
9062 | /* This pop_nested_class corresponds to the |
9063 | push_nested_class used to push into class scope for | |
9064 | parsing the argument list of a function decl, in | |
9065 | qualified_id. */ | |
8d08fdba MS |
9066 | pop_nested_class (1); |
9067 | TREE_COMPLEXITY (declarator) = current_class_depth; | |
9068 | } | |
9069 | else | |
9070 | my_friendly_abort (16); | |
9071 | ||
9072 | if (TREE_OPERAND (declarator, 0) == NULL_TREE) | |
9073 | { | |
9074 | /* We had a reference to a global decl, or | |
9075 | perhaps we were given a non-aggregate typedef, | |
9076 | in which case we cleared this out, and should just | |
9077 | keep going as though it wasn't there. */ | |
9078 | declarator = sname; | |
9079 | continue; | |
9080 | } | |
9081 | ctype = TREE_OPERAND (declarator, 0); | |
9082 | ||
386b8a85 JM |
9083 | t = ctype; |
9084 | while (t != NULL_TREE) | |
9085 | { | |
9086 | if (CLASSTYPE_TEMPLATE_INFO (t)) | |
9087 | template_count += 1; | |
9088 | t = TYPE_MAIN_DECL (t); | |
9089 | if (DECL_LANG_SPECIFIC (t)) | |
9090 | t = DECL_CLASS_CONTEXT (t); | |
9091 | else | |
9092 | t = NULL_TREE; | |
9093 | } | |
9094 | ||
8d08fdba MS |
9095 | if (sname == NULL_TREE) |
9096 | goto done_scoping; | |
9097 | ||
9098 | if (TREE_CODE (sname) == IDENTIFIER_NODE) | |
9099 | { | |
9100 | /* This is the `standard' use of the scoping operator: | |
9101 | basetype :: member . */ | |
9102 | ||
db5ae43f | 9103 | if (ctype == current_class_type) |
28cbf42c MS |
9104 | { |
9105 | /* class A { | |
9106 | void A::f (); | |
9107 | }; | |
9108 | ||
9109 | Is this ill-formed? */ | |
9110 | ||
9111 | if (pedantic) | |
9112 | cp_pedwarn ("extra qualification `%T::' on member `%s' ignored", | |
9113 | ctype, name); | |
9114 | } | |
db5ae43f | 9115 | else if (TREE_CODE (type) == FUNCTION_TYPE) |
8d08fdba MS |
9116 | { |
9117 | if (current_class_type == NULL_TREE | |
8d08fdba MS |
9118 | || friendp) |
9119 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
9120 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9121 | else | |
9122 | { | |
5b605f68 | 9123 | cp_error ("cannot declare member function `%T::%s' within `%T'", |
a3203465 | 9124 | ctype, name, current_class_type); |
8d08fdba MS |
9125 | return void_type_node; |
9126 | } | |
9127 | } | |
5566b478 MS |
9128 | else if (RIDBIT_SETP (RID_TYPEDEF, specbits) |
9129 | || TYPE_SIZE (complete_type (ctype)) != NULL_TREE) | |
8d08fdba | 9130 | { |
8d08fdba | 9131 | /* have to move this code elsewhere in this function. |
db5ae43f MS |
9132 | this code is used for i.e., typedef int A::M; M *pm; |
9133 | ||
9134 | It is? How? jason 10/2/94 */ | |
8d08fdba | 9135 | |
8d08fdba MS |
9136 | if (current_class_type) |
9137 | { | |
db5ae43f MS |
9138 | cp_error ("cannot declare member `%T::%s' within `%T'", |
9139 | ctype, name, current_class_type); | |
9140 | return void_type_node; | |
8d08fdba MS |
9141 | } |
9142 | type = build_offset_type (ctype, type); | |
9143 | } | |
9144 | else if (uses_template_parms (ctype)) | |
9145 | { | |
8d08fdba | 9146 | if (TREE_CODE (type) == FUNCTION_TYPE) |
beb53fb8 JM |
9147 | type |
9148 | = build_cplus_method_type (build_type_variant (ctype, | |
9149 | constp, | |
9150 | volatilep), | |
9151 | TREE_TYPE (type), | |
9152 | TYPE_ARG_TYPES (type)); | |
8d08fdba MS |
9153 | } |
9154 | else | |
9155 | { | |
9156 | cp_error ("structure `%T' not yet defined", ctype); | |
9157 | return error_mark_node; | |
9158 | } | |
9159 | ||
9160 | declarator = sname; | |
9161 | } | |
8d08fdba MS |
9162 | else if (TREE_CODE (sname) == SCOPE_REF) |
9163 | my_friendly_abort (17); | |
9164 | else | |
9165 | { | |
9166 | done_scoping: | |
9167 | declarator = TREE_OPERAND (declarator, 1); | |
9168 | if (declarator && TREE_CODE (declarator) == CALL_EXPR) | |
9169 | /* In this case, we will deal with it later. */ | |
9170 | ; | |
9171 | else | |
9172 | { | |
9173 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
9174 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9175 | else | |
9176 | type = build_offset_type (ctype, type); | |
9177 | } | |
9178 | } | |
9179 | } | |
9180 | break; | |
9181 | ||
9182 | case BIT_NOT_EXPR: | |
9183 | declarator = TREE_OPERAND (declarator, 0); | |
9184 | break; | |
9185 | ||
8d08fdba MS |
9186 | case RECORD_TYPE: |
9187 | case UNION_TYPE: | |
9188 | case ENUMERAL_TYPE: | |
9189 | declarator = NULL_TREE; | |
9190 | break; | |
9191 | ||
9192 | case ERROR_MARK: | |
9193 | declarator = NULL_TREE; | |
9194 | break; | |
9195 | ||
9196 | default: | |
9197 | my_friendly_abort (158); | |
9198 | } | |
9199 | } | |
9200 | ||
db5ae43f MS |
9201 | if (explicitp == 1) |
9202 | { | |
9203 | error ("only constructors can be declared `explicit'"); | |
9204 | explicitp = 0; | |
9205 | } | |
9206 | ||
8d08fdba MS |
9207 | /* Now TYPE has the actual type. */ |
9208 | ||
9209 | /* If this is declaring a typedef name, return a TYPE_DECL. */ | |
9210 | ||
f30432d7 MS |
9211 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) |
9212 | { | |
9213 | if (constp) | |
9214 | { | |
9215 | error ("const `%s' cannot be declared `mutable'", name); | |
9216 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
9217 | } | |
9218 | else if (staticp) | |
9219 | { | |
9220 | error ("static `%s' cannot be declared `mutable'", name); | |
9221 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
9222 | } | |
9223 | } | |
9224 | ||
fc378698 | 9225 | if (RIDBIT_SETP (RID_TYPEDEF, specbits) && decl_context != TYPENAME) |
8d08fdba MS |
9226 | { |
9227 | tree decl; | |
9228 | ||
9229 | /* Note that the grammar rejects storage classes | |
9230 | in typenames, fields or parameters. */ | |
9231 | if (constp || volatilep) | |
f376e137 | 9232 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba | 9233 | |
d2e5ee5c MS |
9234 | if (decl_context == FIELD) |
9235 | { | |
9236 | if (declarator == current_class_name) | |
9237 | cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class", | |
9238 | declarator); | |
9239 | decl = build_lang_decl (TYPE_DECL, declarator, type); | |
9240 | if (IS_SIGNATURE (current_class_type) && opaque_typedef) | |
9241 | SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; | |
9242 | } | |
9243 | else | |
9244 | decl = build_decl (TYPE_DECL, declarator, type); | |
9245 | ||
8d08fdba MS |
9246 | /* If the user declares "struct {...} foo" then `foo' will have |
9247 | an anonymous name. Fill that name in now. Nothing can | |
9248 | refer to it, so nothing needs know about the name change. | |
9249 | The TYPE_NAME field was filled in by build_struct_xref. */ | |
9250 | if (type != error_mark_node | |
9251 | && TYPE_NAME (type) | |
9252 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
9253 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) | |
9254 | { | |
9255 | /* replace the anonymous name with the real name everywhere. */ | |
9256 | lookup_tag_reverse (type, declarator); | |
d2e5ee5c | 9257 | TYPE_NAME (type) = decl; |
8d08fdba MS |
9258 | |
9259 | if (TYPE_LANG_SPECIFIC (type)) | |
9260 | TYPE_WAS_ANONYMOUS (type) = 1; | |
9261 | ||
d2e5ee5c MS |
9262 | DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl); |
9263 | DECL_ASSEMBLER_NAME (decl) | |
9264 | = get_identifier (build_overload_name (type, 1, 1)); | |
fc378698 | 9265 | } |
fc378698 | 9266 | |
8d08fdba MS |
9267 | if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE) |
9268 | { | |
9269 | cp_error_at ("typedef name may not be class-qualified", decl); | |
a3203465 | 9270 | return NULL_TREE; |
8d08fdba MS |
9271 | } |
9272 | else if (quals) | |
9273 | { | |
9274 | if (ctype == NULL_TREE) | |
9275 | { | |
9276 | if (TREE_CODE (type) != METHOD_TYPE) | |
9277 | cp_error_at ("invalid type qualifier for non-method type", decl); | |
9278 | else | |
9279 | ctype = TYPE_METHOD_BASETYPE (type); | |
9280 | } | |
9281 | if (ctype != NULL_TREE) | |
9282 | grok_method_quals (ctype, decl, quals); | |
9283 | } | |
9284 | ||
9285 | if (RIDBIT_SETP (RID_SIGNED, specbits) | |
9286 | || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
9287 | C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; | |
9288 | ||
9289 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
9290 | { | |
9291 | error ("non-object member `%s' cannot be declared mutable", name); | |
9292 | } | |
9293 | ||
c91a56d2 MS |
9294 | bad_specifiers (decl, "type", virtualp, quals != NULL_TREE, |
9295 | inlinep, friendp, raises != NULL_TREE); | |
9296 | ||
9297 | if (initialized) | |
9298 | error ("typedef declaration includes an initializer"); | |
9299 | ||
8d08fdba MS |
9300 | return decl; |
9301 | } | |
9302 | ||
9303 | /* Detect the case of an array type of unspecified size | |
9304 | which came, as such, direct from a typedef name. | |
9305 | We must copy the type, so that each identifier gets | |
9306 | a distinct type, so that each identifier's size can be | |
9307 | controlled separately by its own initializer. */ | |
9308 | ||
9309 | if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE | |
9310 | && TYPE_DOMAIN (type) == NULL_TREE) | |
9311 | { | |
9312 | type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); | |
9313 | } | |
9314 | ||
9315 | /* If this is a type name (such as, in a cast or sizeof), | |
9316 | compute the type and return it now. */ | |
9317 | ||
9318 | if (decl_context == TYPENAME) | |
9319 | { | |
9320 | /* Note that the grammar rejects storage classes | |
9321 | in typenames, fields or parameters. */ | |
9322 | if (constp || volatilep) | |
9323 | if (IS_SIGNATURE (type)) | |
9324 | error ("`const' or `volatile' specified with signature type"); | |
9325 | else | |
f376e137 | 9326 | type = cp_build_type_variant (type, constp, volatilep); |
8d08fdba MS |
9327 | |
9328 | /* Special case: "friend class foo" looks like a TYPENAME context. */ | |
9329 | if (friendp) | |
9330 | { | |
b7484fbe MS |
9331 | if (volatilep) |
9332 | { | |
9333 | cp_error ("`volatile' specified for friend class declaration"); | |
9334 | volatilep = 0; | |
9335 | } | |
9336 | if (inlinep) | |
9337 | { | |
9338 | cp_error ("`inline' specified for friend class declaration"); | |
9339 | inlinep = 0; | |
9340 | } | |
9341 | ||
9342 | /* Only try to do this stuff if we didn't already give up. */ | |
9343 | if (type != integer_type_node) | |
9344 | { | |
9345 | /* A friendly class? */ | |
9346 | if (current_class_type) | |
9347 | make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type)); | |
9348 | else | |
9349 | error ("trying to make class `%s' a friend of global scope", | |
9350 | TYPE_NAME_STRING (type)); | |
9351 | type = void_type_node; | |
9352 | } | |
8d08fdba MS |
9353 | } |
9354 | else if (quals) | |
9355 | { | |
8d08fdba | 9356 | tree dummy = build_decl (TYPE_DECL, declarator, type); |
8d08fdba MS |
9357 | if (ctype == NULL_TREE) |
9358 | { | |
9359 | my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); | |
9360 | ctype = TYPE_METHOD_BASETYPE (type); | |
9361 | } | |
9362 | grok_method_quals (ctype, dummy, quals); | |
9363 | type = TREE_TYPE (dummy); | |
9364 | } | |
9365 | ||
9366 | return type; | |
9367 | } | |
9368 | else if (declarator == NULL_TREE && decl_context != PARM | |
db5ae43f | 9369 | && decl_context != CATCHPARM |
8d08fdba MS |
9370 | && TREE_CODE (type) != UNION_TYPE |
9371 | && ! bitfield) | |
9372 | { | |
9373 | cp_error ("abstract declarator `%T' used as declaration", type); | |
9374 | declarator = make_anon_name (); | |
9375 | } | |
9376 | ||
9377 | /* `void' at top level (not within pointer) | |
9378 | is allowed only in typedefs or type names. | |
9379 | We don't complain about parms either, but that is because | |
9380 | a better error message can be made later. */ | |
9381 | ||
9382 | if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM) | |
9383 | { | |
b7484fbe MS |
9384 | if (! declarator) |
9385 | error ("unnamed variable or field declared void"); | |
9386 | else if (TREE_CODE (declarator) == IDENTIFIER_NODE) | |
8d08fdba MS |
9387 | { |
9388 | if (IDENTIFIER_OPNAME_P (declarator)) | |
8d08fdba | 9389 | my_friendly_abort (356); |
8d08fdba MS |
9390 | else |
9391 | error ("variable or field `%s' declared void", name); | |
9392 | } | |
9393 | else | |
9394 | error ("variable or field declared void"); | |
9395 | type = integer_type_node; | |
9396 | } | |
9397 | ||
9398 | /* Now create the decl, which may be a VAR_DECL, a PARM_DECL | |
9399 | or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ | |
9400 | ||
9401 | { | |
9402 | register tree decl; | |
9403 | ||
9404 | if (decl_context == PARM) | |
9405 | { | |
8d08fdba MS |
9406 | if (ctype) |
9407 | error ("cannot use `::' in parameter declaration"); | |
9408 | ||
9409 | /* A parameter declared as an array of T is really a pointer to T. | |
9410 | One declared as a function is really a pointer to a function. | |
39211cd5 | 9411 | One declared as a member is really a pointer to member. */ |
8d08fdba MS |
9412 | |
9413 | if (TREE_CODE (type) == ARRAY_TYPE) | |
9414 | { | |
e92cc029 | 9415 | /* Transfer const-ness of array into that of type pointed to. */ |
39211cd5 | 9416 | type = build_pointer_type |
f376e137 | 9417 | (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); |
39211cd5 | 9418 | volatilep = constp = 0; |
8d08fdba MS |
9419 | } |
9420 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
9421 | type = build_pointer_type (type); | |
9422 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
9423 | type = build_pointer_type (type); | |
b7484fbe MS |
9424 | else if (type == void_type_node && declarator) |
9425 | { | |
9426 | error ("declaration of `%s' as void", name); | |
9427 | return NULL_TREE; | |
9428 | } | |
8d08fdba | 9429 | |
e349ee73 | 9430 | decl = build_decl (PARM_DECL, declarator, complete_type (type)); |
8d08fdba MS |
9431 | |
9432 | bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, | |
9433 | inlinep, friendp, raises != NULL_TREE); | |
9434 | if (current_class_type | |
9435 | && IS_SIGNATURE (current_class_type)) | |
9436 | { | |
9437 | if (inlinep) | |
9438 | error ("parameter of signature member function declared `inline'"); | |
9439 | if (RIDBIT_SETP (RID_AUTO, specbits)) | |
9440 | error ("parameter of signature member function declared `auto'"); | |
9441 | if (RIDBIT_SETP (RID_REGISTER, specbits)) | |
9442 | error ("parameter of signature member function declared `register'"); | |
9443 | } | |
9444 | ||
9445 | /* Compute the type actually passed in the parmlist, | |
9446 | for the case where there is no prototype. | |
9447 | (For example, shorts and chars are passed as ints.) | |
9448 | When there is a prototype, this is overridden later. */ | |
9449 | ||
39211cd5 | 9450 | DECL_ARG_TYPE (decl) = type_promotes_to (type); |
8d08fdba MS |
9451 | } |
9452 | else if (decl_context == FIELD) | |
9453 | { | |
9454 | if (type == error_mark_node) | |
9455 | { | |
9456 | /* Happens when declaring arrays of sizes which | |
9457 | are error_mark_node, for example. */ | |
9458 | decl = NULL_TREE; | |
9459 | } | |
9460 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
9461 | { | |
9462 | int publicp = 0; | |
9463 | ||
72b7eeff MS |
9464 | /* We catch the others as conflicts with the builtin |
9465 | typedefs. */ | |
9466 | if (friendp && declarator == ridpointers[(int) RID_SIGNED]) | |
9467 | { | |
9468 | cp_error ("function `%D' cannot be declared friend", | |
9469 | declarator); | |
9470 | friendp = 0; | |
9471 | } | |
9472 | ||
8d08fdba MS |
9473 | if (friendp == 0) |
9474 | { | |
9475 | if (ctype == NULL_TREE) | |
9476 | ctype = current_class_type; | |
9477 | ||
9478 | if (ctype == NULL_TREE) | |
9479 | { | |
9480 | cp_error ("can't make `%D' into a method -- not in a class", | |
9481 | declarator); | |
9482 | return void_type_node; | |
9483 | } | |
9484 | ||
9485 | /* ``A union may [ ... ] not [ have ] virtual functions.'' | |
9486 | ARM 9.5 */ | |
9487 | if (virtualp && TREE_CODE (ctype) == UNION_TYPE) | |
9488 | { | |
9489 | cp_error ("function `%D' declared virtual inside a union", | |
9490 | declarator); | |
9491 | return void_type_node; | |
9492 | } | |
9493 | ||
9494 | if (declarator == ansi_opname[(int) NEW_EXPR] | |
a28e3c7f MS |
9495 | || declarator == ansi_opname[(int) VEC_NEW_EXPR] |
9496 | || declarator == ansi_opname[(int) DELETE_EXPR] | |
9497 | || declarator == ansi_opname[(int) VEC_DELETE_EXPR]) | |
8d08fdba MS |
9498 | { |
9499 | if (virtualp) | |
9500 | { | |
9501 | cp_error ("`%D' cannot be declared virtual, since it is always static", | |
9502 | declarator); | |
9503 | virtualp = 0; | |
9504 | } | |
9505 | } | |
9506 | else if (staticp < 2) | |
9507 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
9508 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9509 | } | |
9510 | ||
9511 | /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ | |
eb66be0e | 9512 | publicp = (! friendp || ! staticp); |
386b8a85 JM |
9513 | decl = grokfndecl (ctype, type, |
9514 | TREE_CODE (declarator) != TEMPLATE_ID_EXPR | |
9515 | ? declarator : dname, | |
9516 | declarator, | |
f30432d7 | 9517 | virtualp, flags, quals, raises, attrlist, |
386b8a85 JM |
9518 | friendp ? -1 : 0, friendp, publicp, inlinep, |
9519 | funcdef_flag, template_count); | |
f0e01782 MS |
9520 | if (decl == NULL_TREE) |
9521 | return NULL_TREE; | |
6125f3be DE |
9522 | #if 0 |
9523 | /* This clobbers the attrs stored in `decl' from `attrlist'. */ | |
9524 | /* The decl and setting of decl_machine_attr is also turned off. */ | |
71851aaa | 9525 | decl = build_decl_attribute_variant (decl, decl_machine_attr); |
6125f3be | 9526 | #endif |
f0e01782 | 9527 | |
db5ae43f MS |
9528 | if (explicitp == 2) |
9529 | DECL_NONCONVERTING_P (decl) = 1; | |
8d08fdba MS |
9530 | } |
9531 | else if (TREE_CODE (type) == METHOD_TYPE) | |
9532 | { | |
faae18ab MS |
9533 | /* We only get here for friend declarations of |
9534 | members of other classes. */ | |
8d08fdba MS |
9535 | /* All method decls are public, so tell grokfndecl to set |
9536 | TREE_PUBLIC, also. */ | |
386b8a85 | 9537 | decl = grokfndecl (ctype, type, declarator, declarator, |
f30432d7 | 9538 | virtualp, flags, quals, raises, attrlist, |
386b8a85 JM |
9539 | friendp ? -1 : 0, friendp, 1, 0, funcdef_flag, |
9540 | template_count); | |
f0e01782 MS |
9541 | if (decl == NULL_TREE) |
9542 | return NULL_TREE; | |
8d08fdba | 9543 | } |
5566b478 MS |
9544 | else if (!staticp && ! processing_template_decl |
9545 | && TYPE_SIZE (complete_type (type)) == NULL_TREE | |
8d08fdba MS |
9546 | && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) |
9547 | { | |
b7484fbe MS |
9548 | if (declarator) |
9549 | cp_error ("field `%D' has incomplete type", declarator); | |
9550 | else | |
9551 | cp_error ("name `%T' has incomplete type", type); | |
8d08fdba MS |
9552 | |
9553 | /* If we're instantiating a template, tell them which | |
9554 | instantiation made the field's type be incomplete. */ | |
9555 | if (current_class_type | |
9556 | && TYPE_NAME (current_class_type) | |
d2e5ee5c | 9557 | && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type)) |
8d08fdba MS |
9558 | && declspecs && TREE_VALUE (declspecs) |
9559 | && TREE_TYPE (TREE_VALUE (declspecs)) == type) | |
db5ae43f MS |
9560 | cp_error (" in instantiation of template `%T'", |
9561 | current_class_type); | |
9562 | ||
8d08fdba MS |
9563 | type = error_mark_node; |
9564 | decl = NULL_TREE; | |
9565 | } | |
9566 | else | |
9567 | { | |
9568 | if (friendp) | |
9569 | { | |
9570 | error ("`%s' is neither function nor method; cannot be declared friend", | |
9571 | IDENTIFIER_POINTER (declarator)); | |
9572 | friendp = 0; | |
9573 | } | |
9574 | decl = NULL_TREE; | |
9575 | } | |
9576 | ||
9577 | if (friendp) | |
9578 | { | |
9579 | /* Friends are treated specially. */ | |
9580 | if (ctype == current_class_type) | |
9581 | warning ("member functions are implicitly friends of their class"); | |
9582 | else | |
9583 | { | |
9584 | tree t = NULL_TREE; | |
9585 | if (decl && DECL_NAME (decl)) | |
9586 | t = do_friend (ctype, declarator, decl, | |
5566b478 MS |
9587 | last_function_parms, flags, quals, |
9588 | funcdef_flag); | |
8d08fdba MS |
9589 | if (t && funcdef_flag) |
9590 | return t; | |
9591 | ||
9592 | return void_type_node; | |
9593 | } | |
9594 | } | |
9595 | ||
9596 | /* Structure field. It may not be a function, except for C++ */ | |
9597 | ||
9598 | if (decl == NULL_TREE) | |
9599 | { | |
8d08fdba MS |
9600 | if (initialized) |
9601 | { | |
a0a33927 MS |
9602 | /* Motion 10 at San Diego: If a static const integral data |
9603 | member is initialized with an integral constant | |
9604 | expression, the initializer may appear either in the | |
9605 | declaration (within the class), or in the definition, | |
9606 | but not both. If it appears in the class, the member is | |
9607 | a member constant. The file-scope definition is always | |
9608 | required. */ | |
8d08fdba | 9609 | if (staticp) |
a0a33927 MS |
9610 | { |
9611 | if (pedantic) | |
9612 | { | |
9613 | if (! constp) | |
9614 | cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'", | |
9615 | declarator); | |
9616 | ||
9617 | else if (! INTEGRAL_TYPE_P (type)) | |
9618 | cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type); | |
9619 | } | |
9620 | } | |
9621 | ||
8d08fdba MS |
9622 | /* Note that initialization of const members is prohibited |
9623 | by the draft ANSI standard, though it appears to be in | |
9624 | common practice. 12.6.2: The argument list is used to | |
9625 | initialize the named nonstatic member.... This (or an | |
7177d104 MS |
9626 | initializer list) is the only way to initialize |
9627 | nonstatic const and reference members. */ | |
e1cd6e56 | 9628 | else if (pedantic || ! constp) |
a0a33927 MS |
9629 | cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'", |
9630 | constp ? "const member" : "member", declarator); | |
8d08fdba MS |
9631 | } |
9632 | ||
9633 | if (staticp || (constp && initialized)) | |
9634 | { | |
f30432d7 MS |
9635 | /* ANSI C++ Apr '95 wp 9.2 */ |
9636 | if (staticp && declarator == current_class_name) | |
9637 | cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class", | |
9638 | declarator); | |
9639 | ||
8d08fdba MS |
9640 | /* C++ allows static class members. |
9641 | All other work for this is done by grokfield. | |
9642 | This VAR_DECL is built by build_lang_field_decl. | |
9643 | All other VAR_DECLs are built by build_decl. */ | |
9644 | decl = build_lang_field_decl (VAR_DECL, declarator, type); | |
5b605f68 MS |
9645 | TREE_STATIC (decl) = 1; |
9646 | /* In class context, 'static' means public access. */ | |
9647 | TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp; | |
8d08fdba MS |
9648 | } |
9649 | else | |
9650 | { | |
9651 | decl = build_lang_field_decl (FIELD_DECL, declarator, type); | |
9652 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
9653 | { | |
9654 | DECL_MUTABLE_P (decl) = 1; | |
9655 | RIDBIT_RESET (RID_MUTABLE, specbits); | |
9656 | } | |
9657 | } | |
9658 | ||
9659 | bad_specifiers (decl, "field", virtualp, quals != NULL_TREE, | |
9660 | inlinep, friendp, raises != NULL_TREE); | |
9661 | } | |
9662 | } | |
9663 | else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | |
9664 | { | |
386b8a85 | 9665 | tree original_name; |
8d08fdba MS |
9666 | int publicp = 0; |
9667 | ||
9668 | if (! declarator) | |
9669 | return NULL_TREE; | |
9670 | ||
386b8a85 JM |
9671 | if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) |
9672 | original_name = dname; | |
9673 | else | |
9674 | original_name = declarator; | |
9675 | ||
8926095f MS |
9676 | if (RIDBIT_SETP (RID_AUTO, specbits)) |
9677 | error ("storage class `auto' invalid for function `%s'", name); | |
9678 | else if (RIDBIT_SETP (RID_REGISTER, specbits)) | |
9679 | error ("storage class `register' invalid for function `%s'", name); | |
8d08fdba MS |
9680 | |
9681 | /* Function declaration not at top level. | |
9682 | Storage classes other than `extern' are not allowed | |
9683 | and `extern' makes no difference. */ | |
a9aedbc2 | 9684 | if (! toplevel_bindings_p () |
8926095f MS |
9685 | && (RIDBIT_SETP (RID_STATIC, specbits) |
9686 | || RIDBIT_SETP (RID_INLINE, specbits)) | |
8d08fdba | 9687 | && pedantic) |
8926095f MS |
9688 | { |
9689 | if (RIDBIT_SETP (RID_STATIC, specbits)) | |
9690 | pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name); | |
9691 | else | |
9692 | pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name); | |
9693 | } | |
9694 | ||
8d08fdba MS |
9695 | if (ctype == NULL_TREE) |
9696 | { | |
9697 | if (virtualp) | |
9698 | { | |
9699 | error ("virtual non-class function `%s'", name); | |
9700 | virtualp = 0; | |
9701 | } | |
9702 | ||
9703 | if (current_lang_name == lang_name_cplusplus | |
5156628f | 9704 | && ! processing_template_decl |
8d08fdba MS |
9705 | && ! (IDENTIFIER_LENGTH (original_name) == 4 |
9706 | && IDENTIFIER_POINTER (original_name)[0] == 'm' | |
9707 | && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0) | |
9708 | && ! (IDENTIFIER_LENGTH (original_name) > 10 | |
9709 | && IDENTIFIER_POINTER (original_name)[0] == '_' | |
9710 | && IDENTIFIER_POINTER (original_name)[1] == '_' | |
9711 | && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0)) | |
8926095f | 9712 | /* Plain overloading: will not be grok'd by grokclassfn. */ |
386b8a85 JM |
9713 | if (name_mangling_version < 1 |
9714 | || TREE_CODE (declarator) != TEMPLATE_ID_EXPR) | |
9715 | declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0); | |
8d08fdba MS |
9716 | } |
9717 | else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2) | |
9718 | type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), | |
9719 | TREE_TYPE (type), TYPE_ARG_TYPES (type)); | |
9720 | ||
eb66be0e | 9721 | /* Record presence of `static'. */ |
faae18ab | 9722 | publicp = (ctype != NULL_TREE |
a9aedbc2 | 9723 | || RIDBIT_SETP (RID_EXTERN, specbits) |
eb66be0e | 9724 | || !RIDBIT_SETP (RID_STATIC, specbits)); |
8d08fdba | 9725 | |
386b8a85 | 9726 | decl = grokfndecl (ctype, type, original_name, declarator, |
f30432d7 | 9727 | virtualp, flags, quals, raises, attrlist, |
386b8a85 JM |
9728 | friendp ? 2 : 1, friendp, |
9729 | publicp, inlinep, funcdef_flag, | |
9730 | template_count); | |
f0e01782 MS |
9731 | if (decl == NULL_TREE) |
9732 | return NULL_TREE; | |
8d08fdba | 9733 | |
386b8a85 JM |
9734 | if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c |
9735 | && (!DECL_TEMPLATE_SPECIALIZATION (decl) || | |
9736 | name_mangling_version < 1)) | |
6060a796 | 9737 | DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator); |
386b8a85 | 9738 | |
8d08fdba MS |
9739 | if (staticp == 1) |
9740 | { | |
9741 | int illegal_static = 0; | |
9742 | ||
9743 | /* Don't allow a static member function in a class, and forbid | |
9744 | declaring main to be static. */ | |
9745 | if (TREE_CODE (type) == METHOD_TYPE) | |
9746 | { | |
00595019 | 9747 | cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl); |
8d08fdba MS |
9748 | illegal_static = 1; |
9749 | } | |
8d08fdba MS |
9750 | else if (current_function_decl) |
9751 | { | |
9752 | /* FIXME need arm citation */ | |
9753 | error ("cannot declare static function inside another function"); | |
9754 | illegal_static = 1; | |
9755 | } | |
9756 | ||
9757 | if (illegal_static) | |
9758 | { | |
9759 | staticp = 0; | |
9760 | RIDBIT_RESET (RID_STATIC, specbits); | |
9761 | } | |
9762 | } | |
8d08fdba MS |
9763 | } |
9764 | else | |
9765 | { | |
9766 | /* It's a variable. */ | |
9767 | ||
db5ae43f MS |
9768 | if (decl_context == CATCHPARM) |
9769 | { | |
9770 | if (ctype) | |
9771 | { | |
9772 | ctype = NULL_TREE; | |
9773 | error ("cannot use `::' in parameter declaration"); | |
9774 | } | |
9775 | ||
9776 | /* A parameter declared as an array of T is really a pointer to T. | |
9777 | One declared as a function is really a pointer to a function. | |
9778 | One declared as a member is really a pointer to member. */ | |
9779 | ||
9780 | if (TREE_CODE (type) == ARRAY_TYPE) | |
9781 | { | |
e92cc029 MS |
9782 | /* Transfer const-ness of array into that of type |
9783 | pointed to. */ | |
db5ae43f MS |
9784 | type = build_pointer_type |
9785 | (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); | |
9786 | volatilep = constp = 0; | |
9787 | } | |
9788 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
9789 | type = build_pointer_type (type); | |
9790 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
9791 | type = build_pointer_type (type); | |
9792 | } | |
9793 | ||
8d08fdba | 9794 | /* An uninitialized decl with `extern' is a reference. */ |
d2e5ee5c | 9795 | decl = grokvardecl (type, declarator, &specbits, initialized, constp); |
8d08fdba MS |
9796 | bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, |
9797 | inlinep, friendp, raises != NULL_TREE); | |
9798 | ||
9799 | if (ctype) | |
9800 | { | |
f0e01782 | 9801 | DECL_CONTEXT (decl) = ctype; |
8d08fdba MS |
9802 | if (staticp == 1) |
9803 | { | |
f30432d7 | 9804 | cp_pedwarn ("static member `%D' re-declared as static", decl); |
8d08fdba MS |
9805 | staticp = 0; |
9806 | RIDBIT_RESET (RID_STATIC, specbits); | |
9807 | } | |
b7484fbe MS |
9808 | if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl)) |
9809 | { | |
9810 | cp_error ("static member `%D' declared `register'", decl); | |
9811 | RIDBIT_RESET (RID_REGISTER, specbits); | |
9812 | } | |
f30432d7 | 9813 | if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic) |
8d08fdba | 9814 | { |
f30432d7 MS |
9815 | cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage", |
9816 | decl); | |
8d08fdba MS |
9817 | RIDBIT_RESET (RID_EXTERN, specbits); |
9818 | } | |
9819 | } | |
9820 | } | |
9821 | ||
9822 | if (RIDBIT_SETP (RID_MUTABLE, specbits)) | |
9823 | { | |
9824 | error ("`%s' cannot be declared mutable", name); | |
9825 | } | |
9826 | ||
9827 | /* Record `register' declaration for warnings on & | |
9828 | and in case doing stupid register allocation. */ | |
9829 | ||
9830 | if (RIDBIT_SETP (RID_REGISTER, specbits)) | |
9831 | DECL_REGISTER (decl) = 1; | |
9832 | ||
8926095f MS |
9833 | if (RIDBIT_SETP (RID_EXTERN, specbits)) |
9834 | DECL_THIS_EXTERN (decl) = 1; | |
9835 | ||
faae18ab MS |
9836 | if (RIDBIT_SETP (RID_STATIC, specbits)) |
9837 | DECL_THIS_STATIC (decl) = 1; | |
9838 | ||
8d08fdba MS |
9839 | /* Record constancy and volatility. */ |
9840 | ||
9841 | if (constp) | |
9842 | TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE; | |
9843 | if (volatilep) | |
9844 | { | |
9845 | TREE_SIDE_EFFECTS (decl) = 1; | |
9846 | TREE_THIS_VOLATILE (decl) = 1; | |
9847 | } | |
9848 | ||
9849 | return decl; | |
9850 | } | |
9851 | } | |
9852 | \f | |
9853 | /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist. | |
9854 | An empty exprlist is a parmlist. An exprlist which | |
9855 | contains only identifiers at the global level | |
9856 | is a parmlist. Otherwise, it is an exprlist. */ | |
e92cc029 | 9857 | |
8d08fdba MS |
9858 | int |
9859 | parmlist_is_exprlist (exprs) | |
9860 | tree exprs; | |
9861 | { | |
9862 | if (exprs == NULL_TREE || TREE_PARMLIST (exprs)) | |
9863 | return 0; | |
9864 | ||
a9aedbc2 | 9865 | if (toplevel_bindings_p ()) |
8d08fdba MS |
9866 | { |
9867 | /* At the global level, if these are all identifiers, | |
9868 | then it is a parmlist. */ | |
9869 | while (exprs) | |
9870 | { | |
9871 | if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE) | |
9872 | return 1; | |
9873 | exprs = TREE_CHAIN (exprs); | |
9874 | } | |
9875 | return 0; | |
9876 | } | |
9877 | return 1; | |
9878 | } | |
9879 | ||
9880 | /* Subroutine of `grokparms'. In a fcn definition, arg types must | |
9881 | be complete. | |
9882 | ||
9883 | C++: also subroutine of `start_function'. */ | |
e92cc029 | 9884 | |
8d08fdba MS |
9885 | static void |
9886 | require_complete_types_for_parms (parms) | |
9887 | tree parms; | |
9888 | { | |
5566b478 MS |
9889 | if (processing_template_decl) |
9890 | return; | |
9891 | ||
8d08fdba MS |
9892 | while (parms) |
9893 | { | |
9894 | tree type = TREE_TYPE (parms); | |
5566b478 | 9895 | if (TYPE_SIZE (complete_type (type)) == NULL_TREE) |
8d08fdba MS |
9896 | { |
9897 | if (DECL_NAME (parms)) | |
9898 | error ("parameter `%s' has incomplete type", | |
9899 | IDENTIFIER_POINTER (DECL_NAME (parms))); | |
9900 | else | |
9901 | error ("parameter has incomplete type"); | |
9902 | TREE_TYPE (parms) = error_mark_node; | |
9903 | } | |
9904 | #if 0 | |
9905 | /* If the arg types are incomplete in a declaration, | |
9906 | they must include undefined tags. | |
9907 | These tags can never be defined in the scope of the declaration, | |
9908 | so the types can never be completed, | |
9909 | and no call can be compiled successfully. */ | |
9910 | /* This is not the right behavior for C++, but not having | |
9911 | it is also probably wrong. */ | |
9912 | else | |
9913 | { | |
9914 | /* Now warn if is a pointer to an incomplete type. */ | |
9915 | while (TREE_CODE (type) == POINTER_TYPE | |
9916 | || TREE_CODE (type) == REFERENCE_TYPE) | |
9917 | type = TREE_TYPE (type); | |
9918 | type = TYPE_MAIN_VARIANT (type); | |
9919 | if (TYPE_SIZE (type) == NULL_TREE) | |
9920 | { | |
9921 | if (DECL_NAME (parm) != NULL_TREE) | |
9922 | warning ("parameter `%s' points to incomplete type", | |
9923 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
9924 | else | |
9925 | warning ("parameter points to incomplete type"); | |
9926 | } | |
9927 | } | |
9928 | #endif | |
9929 | parms = TREE_CHAIN (parms); | |
9930 | } | |
9931 | } | |
9932 | ||
9933 | /* Decode the list of parameter types for a function type. | |
9934 | Given the list of things declared inside the parens, | |
9935 | return a list of types. | |
9936 | ||
9937 | The list we receive can have three kinds of elements: | |
9938 | an IDENTIFIER_NODE for names given without types, | |
9939 | a TREE_LIST node for arguments given as typespecs or names with typespecs, | |
9940 | or void_type_node, to mark the end of an argument list | |
9941 | when additional arguments are not permitted (... was not used). | |
9942 | ||
9943 | FUNCDEF_FLAG is nonzero for a function definition, 0 for | |
9944 | a mere declaration. A nonempty identifier-list gets an error message | |
9945 | when FUNCDEF_FLAG is zero. | |
9946 | If FUNCDEF_FLAG is 1, then parameter types must be complete. | |
9947 | If FUNCDEF_FLAG is -1, then parameter types may be incomplete. | |
9948 | ||
9949 | If all elements of the input list contain types, | |
9950 | we return a list of the types. | |
9951 | If all elements contain no type (except perhaps a void_type_node | |
9952 | at the end), we return a null list. | |
9953 | If some have types and some do not, it is an error, and we | |
9954 | return a null list. | |
9955 | ||
9956 | Also set last_function_parms to either | |
9957 | a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs. | |
9958 | A list of names is converted to a chain of PARM_DECLs | |
9959 | by store_parm_decls so that ultimately it is always a chain of decls. | |
9960 | ||
9961 | Note that in C++, parameters can take default values. These default | |
9962 | values are in the TREE_PURPOSE field of the TREE_LIST. It is | |
9963 | an error to specify default values which are followed by parameters | |
9964 | that have no default values, or an ELLIPSES. For simplicities sake, | |
9965 | only parameters which are specified with their types can take on | |
9966 | default values. */ | |
9967 | ||
9968 | static tree | |
9969 | grokparms (first_parm, funcdef_flag) | |
9970 | tree first_parm; | |
9971 | int funcdef_flag; | |
9972 | { | |
9973 | tree result = NULL_TREE; | |
9974 | tree decls = NULL_TREE; | |
9975 | ||
9976 | if (first_parm != NULL_TREE | |
9977 | && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) | |
9978 | { | |
9979 | if (! funcdef_flag) | |
9980 | pedwarn ("parameter names (without types) in function declaration"); | |
9981 | last_function_parms = first_parm; | |
9982 | return NULL_TREE; | |
9983 | } | |
9984 | else if (first_parm != NULL_TREE | |
9985 | && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST | |
9986 | && TREE_VALUE (first_parm) != void_type_node) | |
9987 | my_friendly_abort (145); | |
9988 | else | |
9989 | { | |
9990 | /* Types were specified. This is a list of declarators | |
9991 | each represented as a TREE_LIST node. */ | |
9992 | register tree parm, chain; | |
5566b478 | 9993 | int any_init = 0, any_error = 0; |
8d08fdba MS |
9994 | |
9995 | if (first_parm != NULL_TREE) | |
9996 | { | |
9997 | tree last_result = NULL_TREE; | |
9998 | tree last_decl = NULL_TREE; | |
9999 | ||
10000 | for (parm = first_parm; parm != NULL_TREE; parm = chain) | |
10001 | { | |
10002 | tree type, list_node = parm; | |
10003 | register tree decl = TREE_VALUE (parm); | |
10004 | tree init = TREE_PURPOSE (parm); | |
10005 | ||
10006 | chain = TREE_CHAIN (parm); | |
10007 | /* @@ weak defense against parse errors. */ | |
10008 | if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST) | |
10009 | { | |
10010 | /* Give various messages as the need arises. */ | |
10011 | if (TREE_CODE (decl) == STRING_CST) | |
fc378698 | 10012 | cp_error ("invalid string constant `%E'", decl); |
8d08fdba MS |
10013 | else if (TREE_CODE (decl) == INTEGER_CST) |
10014 | error ("invalid integer constant in parameter list, did you forget to give parameter name?"); | |
10015 | continue; | |
10016 | } | |
10017 | ||
10018 | if (decl != void_type_node) | |
10019 | { | |
8d08fdba MS |
10020 | decl = grokdeclarator (TREE_VALUE (decl), |
10021 | TREE_PURPOSE (decl), | |
f30432d7 | 10022 | PARM, init != NULL_TREE, |
c11b6f21 | 10023 | NULL_TREE); |
8d08fdba MS |
10024 | if (! decl) |
10025 | continue; | |
10026 | type = TREE_TYPE (decl); | |
10027 | if (TYPE_MAIN_VARIANT (type) == void_type_node) | |
10028 | decl = void_type_node; | |
10029 | else if (TREE_CODE (type) == METHOD_TYPE) | |
10030 | { | |
10031 | if (DECL_NAME (decl)) | |
fc378698 | 10032 | /* Cannot use the decl here because |
8d08fdba | 10033 | we don't have DECL_CONTEXT set up yet. */ |
fc378698 MS |
10034 | cp_error ("parameter `%D' invalidly declared method type", |
10035 | DECL_NAME (decl)); | |
8d08fdba MS |
10036 | else |
10037 | error ("parameter invalidly declared method type"); | |
10038 | type = build_pointer_type (type); | |
10039 | TREE_TYPE (decl) = type; | |
10040 | } | |
10041 | else if (TREE_CODE (type) == OFFSET_TYPE) | |
10042 | { | |
10043 | if (DECL_NAME (decl)) | |
fc378698 MS |
10044 | cp_error ("parameter `%D' invalidly declared offset type", |
10045 | DECL_NAME (decl)); | |
8d08fdba MS |
10046 | else |
10047 | error ("parameter invalidly declared offset type"); | |
10048 | type = build_pointer_type (type); | |
10049 | TREE_TYPE (decl) = type; | |
10050 | } | |
10051 | else if (TREE_CODE (type) == RECORD_TYPE | |
10052 | && TYPE_LANG_SPECIFIC (type) | |
10053 | && CLASSTYPE_ABSTRACT_VIRTUALS (type)) | |
10054 | { | |
10055 | abstract_virtuals_error (decl, type); | |
10056 | any_error = 1; /* seems like a good idea */ | |
10057 | } | |
10058 | else if (TREE_CODE (type) == RECORD_TYPE | |
10059 | && TYPE_LANG_SPECIFIC (type) | |
10060 | && IS_SIGNATURE (type)) | |
10061 | { | |
10062 | signature_error (decl, type); | |
10063 | any_error = 1; /* seems like a good idea */ | |
10064 | } | |
10065 | } | |
10066 | ||
10067 | if (decl == void_type_node) | |
10068 | { | |
10069 | if (result == NULL_TREE) | |
10070 | { | |
10071 | result = void_list_node; | |
10072 | last_result = result; | |
10073 | } | |
10074 | else | |
10075 | { | |
10076 | TREE_CHAIN (last_result) = void_list_node; | |
10077 | last_result = void_list_node; | |
10078 | } | |
8d08fdba MS |
10079 | if (chain |
10080 | && (chain != void_list_node || TREE_CHAIN (chain))) | |
10081 | error ("`void' in parameter list must be entire list"); | |
10082 | break; | |
10083 | } | |
10084 | ||
10085 | /* Since there is a prototype, args are passed in their own types. */ | |
10086 | DECL_ARG_TYPE (decl) = TREE_TYPE (decl); | |
10087 | #ifdef PROMOTE_PROTOTYPES | |
10088 | if ((TREE_CODE (type) == INTEGER_TYPE | |
10089 | || TREE_CODE (type) == ENUMERAL_TYPE) | |
10090 | && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) | |
10091 | DECL_ARG_TYPE (decl) = integer_type_node; | |
10092 | #endif | |
10093 | if (!any_error) | |
10094 | { | |
10095 | if (init) | |
10096 | { | |
10097 | any_init++; | |
10098 | if (TREE_CODE (init) == SAVE_EXPR) | |
10099 | PARM_DECL_EXPR (init) = 1; | |
5156628f | 10100 | else if (processing_template_decl) |
5566b478 | 10101 | ; |
42976354 BK |
10102 | /* Unparsed default arg from in-class decl. */ |
10103 | else if (TREE_CODE (init) == DEFAULT_ARG) | |
10104 | ; | |
b7484fbe MS |
10105 | else if (TREE_CODE (init) == VAR_DECL |
10106 | || TREE_CODE (init) == PARM_DECL) | |
8d08fdba MS |
10107 | { |
10108 | if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init))) | |
10109 | { | |
10110 | /* ``Local variables may not be used in default | |
10111 | argument expressions.'' dpANSI C++ 8.2.6 */ | |
10112 | /* If extern int i; within a function is not | |
10113 | considered a local variable, then this code is | |
e92cc029 | 10114 | wrong. */ |
8d08fdba MS |
10115 | cp_error ("local variable `%D' may not be used as a default argument", init); |
10116 | any_error = 1; | |
10117 | } | |
10118 | else if (TREE_READONLY_DECL_P (init)) | |
10119 | init = decl_constant_value (init); | |
10120 | } | |
10121 | else | |
10122 | init = require_instantiated_type (type, init, integer_zero_node); | |
5156628f | 10123 | if (! processing_template_decl |
42976354 | 10124 | && TREE_CODE (init) != DEFAULT_ARG |
c11b6f21 | 10125 | && ! can_convert_arg (type, TREE_TYPE (init), init)) |
c73964b2 MS |
10126 | cp_pedwarn ("invalid type `%T' for default argument to `%#D'", |
10127 | TREE_TYPE (init), decl); | |
8d08fdba MS |
10128 | } |
10129 | } | |
10130 | else | |
10131 | init = NULL_TREE; | |
10132 | ||
10133 | if (decls == NULL_TREE) | |
10134 | { | |
10135 | decls = decl; | |
10136 | last_decl = decls; | |
10137 | } | |
10138 | else | |
10139 | { | |
10140 | TREE_CHAIN (last_decl) = decl; | |
10141 | last_decl = decl; | |
10142 | } | |
66f2e88d | 10143 | if (! current_function_decl && TREE_PERMANENT (list_node)) |
8d08fdba MS |
10144 | { |
10145 | TREE_PURPOSE (list_node) = init; | |
10146 | TREE_VALUE (list_node) = type; | |
10147 | TREE_CHAIN (list_node) = NULL_TREE; | |
10148 | } | |
10149 | else | |
10150 | list_node = saveable_tree_cons (init, type, NULL_TREE); | |
10151 | if (result == NULL_TREE) | |
10152 | { | |
10153 | result = list_node; | |
10154 | last_result = result; | |
10155 | } | |
10156 | else | |
10157 | { | |
10158 | TREE_CHAIN (last_result) = list_node; | |
10159 | last_result = list_node; | |
10160 | } | |
10161 | } | |
10162 | if (last_result) | |
10163 | TREE_CHAIN (last_result) = NULL_TREE; | |
10164 | /* If there are no parameters, and the function does not end | |
10165 | with `...', then last_decl will be NULL_TREE. */ | |
10166 | if (last_decl != NULL_TREE) | |
10167 | TREE_CHAIN (last_decl) = NULL_TREE; | |
10168 | } | |
10169 | } | |
10170 | ||
10171 | last_function_parms = decls; | |
10172 | ||
10173 | /* In a fcn definition, arg types must be complete. */ | |
10174 | if (funcdef_flag > 0) | |
10175 | require_complete_types_for_parms (last_function_parms); | |
10176 | ||
10177 | return result; | |
10178 | } | |
42976354 BK |
10179 | |
10180 | /* Called from the parser to update an element of TYPE_ARG_TYPES for some | |
10181 | FUNCTION_TYPE with the newly parsed version of its default argument, which | |
10182 | was previously digested as text. See snarf_defarg et al in lex.c. */ | |
10183 | ||
10184 | void | |
10185 | replace_defarg (arg, init) | |
10186 | tree arg, init; | |
10187 | { | |
aa5f3bad | 10188 | if (! processing_template_decl |
42976354 BK |
10189 | && ! can_convert_arg (TREE_VALUE (arg), TREE_TYPE (init), init)) |
10190 | cp_pedwarn ("invalid type `%T' for default argument to `%T'", | |
10191 | TREE_TYPE (init), TREE_VALUE (arg)); | |
10192 | TREE_PURPOSE (arg) = init; | |
10193 | } | |
8d08fdba | 10194 | \f |
c11b6f21 MS |
10195 | int |
10196 | copy_args_p (d) | |
10197 | tree d; | |
10198 | { | |
10199 | tree t = FUNCTION_ARG_CHAIN (d); | |
10200 | if (t && TREE_CODE (TREE_VALUE (t)) == REFERENCE_TYPE | |
10201 | && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (t))) | |
10202 | == DECL_CLASS_CONTEXT (d)) | |
10203 | && (TREE_CHAIN (t) == NULL_TREE | |
10204 | || TREE_CHAIN (t) == void_list_node | |
10205 | || TREE_PURPOSE (TREE_CHAIN (t)))) | |
10206 | return 1; | |
10207 | return 0; | |
10208 | } | |
10209 | ||
8d08fdba MS |
10210 | /* These memoizing functions keep track of special properties which |
10211 | a class may have. `grok_ctor_properties' notices whether a class | |
10212 | has a constructor of the form X(X&), and also complains | |
10213 | if the class has a constructor of the form X(X). | |
10214 | `grok_op_properties' takes notice of the various forms of | |
10215 | operator= which are defined, as well as what sorts of type conversion | |
10216 | may apply. Both functions take a FUNCTION_DECL as an argument. */ | |
e92cc029 | 10217 | |
a0a33927 | 10218 | int |
8d08fdba MS |
10219 | grok_ctor_properties (ctype, decl) |
10220 | tree ctype, decl; | |
10221 | { | |
10222 | tree parmtypes = FUNCTION_ARG_CHAIN (decl); | |
10223 | tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; | |
10224 | ||
10225 | /* When a type has virtual baseclasses, a magical first int argument is | |
10226 | added to any ctor so we can tell if the class has been initialized | |
10227 | yet. This could screw things up in this function, so we deliberately | |
10228 | ignore the leading int if we're in that situation. */ | |
10229 | if (parmtypes | |
10230 | && TREE_VALUE (parmtypes) == integer_type_node | |
10231 | && TYPE_USES_VIRTUAL_BASECLASSES (ctype)) | |
10232 | { | |
10233 | parmtypes = TREE_CHAIN (parmtypes); | |
10234 | parmtype = TREE_VALUE (parmtypes); | |
10235 | } | |
10236 | ||
10237 | if (TREE_CODE (parmtype) == REFERENCE_TYPE | |
10238 | && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype) | |
10239 | { | |
10240 | if (TREE_CHAIN (parmtypes) == NULL_TREE | |
10241 | || TREE_CHAIN (parmtypes) == void_list_node | |
10242 | || TREE_PURPOSE (TREE_CHAIN (parmtypes))) | |
10243 | { | |
10244 | TYPE_HAS_INIT_REF (ctype) = 1; | |
10245 | if (TYPE_READONLY (TREE_TYPE (parmtype))) | |
10246 | TYPE_HAS_CONST_INIT_REF (ctype) = 1; | |
10247 | } | |
10248 | else | |
10249 | TYPE_GETS_INIT_AGGR (ctype) = 1; | |
10250 | } | |
10251 | else if (TYPE_MAIN_VARIANT (parmtype) == ctype) | |
10252 | { | |
10253 | if (TREE_CHAIN (parmtypes) != NULL_TREE | |
10254 | && TREE_CHAIN (parmtypes) == void_list_node) | |
a0a33927 | 10255 | { |
f7da6097 | 10256 | cp_error ("invalid constructor; you probably meant `%T (const %T&)'", |
a0a33927 MS |
10257 | ctype, ctype); |
10258 | SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); | |
10259 | ||
10260 | return 0; | |
10261 | } | |
10262 | else | |
10263 | TYPE_GETS_INIT_AGGR (ctype) = 1; | |
8d08fdba MS |
10264 | } |
10265 | else if (TREE_CODE (parmtype) == VOID_TYPE | |
10266 | || TREE_PURPOSE (parmtypes) != NULL_TREE) | |
10267 | TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; | |
a0a33927 MS |
10268 | |
10269 | return 1; | |
8d08fdba MS |
10270 | } |
10271 | ||
10272 | /* An operator with this name can be either unary or binary. */ | |
e92cc029 | 10273 | |
a28e3c7f MS |
10274 | static int |
10275 | ambi_op_p (name) | |
8d08fdba MS |
10276 | tree name; |
10277 | { | |
10278 | return (name == ansi_opname [(int) INDIRECT_REF] | |
10279 | || name == ansi_opname [(int) ADDR_EXPR] | |
10280 | || name == ansi_opname [(int) NEGATE_EXPR] | |
10281 | || name == ansi_opname[(int) POSTINCREMENT_EXPR] | |
10282 | || name == ansi_opname[(int) POSTDECREMENT_EXPR] | |
10283 | || name == ansi_opname [(int) CONVERT_EXPR]); | |
10284 | } | |
10285 | ||
10286 | /* An operator with this name can only be unary. */ | |
e92cc029 | 10287 | |
a28e3c7f MS |
10288 | static int |
10289 | unary_op_p (name) | |
8d08fdba MS |
10290 | tree name; |
10291 | { | |
10292 | return (name == ansi_opname [(int) TRUTH_NOT_EXPR] | |
10293 | || name == ansi_opname [(int) BIT_NOT_EXPR] | |
10294 | || name == ansi_opname [(int) COMPONENT_REF] | |
10295 | || OPERATOR_TYPENAME_P (name)); | |
10296 | } | |
10297 | ||
10298 | /* Do a little sanity-checking on how they declared their operator. */ | |
e92cc029 | 10299 | |
5566b478 | 10300 | void |
8d08fdba MS |
10301 | grok_op_properties (decl, virtualp, friendp) |
10302 | tree decl; | |
10303 | int virtualp, friendp; | |
10304 | { | |
10305 | tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
10306 | int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); | |
10307 | tree name = DECL_NAME (decl); | |
8d08fdba | 10308 | |
a28e3c7f MS |
10309 | if (current_class_type == NULL_TREE) |
10310 | friendp = 1; | |
8d08fdba | 10311 | |
a28e3c7f MS |
10312 | if (! friendp) |
10313 | { | |
10314 | if (name == ansi_opname[(int) MODIFY_EXPR]) | |
10315 | TYPE_HAS_ASSIGNMENT (current_class_type) = 1; | |
10316 | else if (name == ansi_opname[(int) CALL_EXPR]) | |
10317 | TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1; | |
10318 | else if (name == ansi_opname[(int) ARRAY_REF]) | |
10319 | TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1; | |
10320 | else if (name == ansi_opname[(int) COMPONENT_REF] | |
10321 | || name == ansi_opname[(int) MEMBER_REF]) | |
10322 | TYPE_OVERLOADS_ARROW (current_class_type) = 1; | |
10323 | else if (name == ansi_opname[(int) NEW_EXPR]) | |
10324 | TYPE_GETS_NEW (current_class_type) |= 1; | |
10325 | else if (name == ansi_opname[(int) DELETE_EXPR]) | |
10326 | TYPE_GETS_DELETE (current_class_type) |= 1; | |
10327 | else if (name == ansi_opname[(int) VEC_NEW_EXPR]) | |
10328 | TYPE_GETS_NEW (current_class_type) |= 2; | |
10329 | else if (name == ansi_opname[(int) VEC_DELETE_EXPR]) | |
10330 | TYPE_GETS_DELETE (current_class_type) |= 2; | |
10331 | } | |
10332 | ||
10333 | if (name == ansi_opname[(int) NEW_EXPR] | |
10334 | || name == ansi_opname[(int) VEC_NEW_EXPR]) | |
8d08fdba | 10335 | { |
8d08fdba MS |
10336 | /* When the compiler encounters the definition of A::operator new, it |
10337 | doesn't look at the class declaration to find out if it's static. */ | |
a28e3c7f | 10338 | if (methodp) |
700f8a87 | 10339 | revert_static_member_fn (&decl, NULL, NULL); |
8d08fdba MS |
10340 | |
10341 | /* Take care of function decl if we had syntax errors. */ | |
10342 | if (argtypes == NULL_TREE) | |
beb53fb8 JM |
10343 | TREE_TYPE (decl) |
10344 | = build_function_type (ptr_type_node, | |
10345 | hash_tree_chain (integer_type_node, | |
10346 | void_list_node)); | |
8d08fdba | 10347 | else |
a28e3c7f | 10348 | TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); |
8d08fdba | 10349 | } |
a28e3c7f MS |
10350 | else if (name == ansi_opname[(int) DELETE_EXPR] |
10351 | || name == ansi_opname[(int) VEC_DELETE_EXPR]) | |
8d08fdba | 10352 | { |
a28e3c7f | 10353 | if (methodp) |
700f8a87 | 10354 | revert_static_member_fn (&decl, NULL, NULL); |
8d08fdba MS |
10355 | |
10356 | if (argtypes == NULL_TREE) | |
beb53fb8 JM |
10357 | TREE_TYPE (decl) |
10358 | = build_function_type (void_type_node, | |
10359 | hash_tree_chain (ptr_type_node, | |
10360 | void_list_node)); | |
8d08fdba | 10361 | else |
a28e3c7f MS |
10362 | { |
10363 | TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); | |
10364 | ||
10365 | if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR] | |
10366 | && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))) | |
10367 | != void_list_node)) | |
10368 | TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1; | |
10369 | } | |
8d08fdba | 10370 | } |
8d08fdba MS |
10371 | else |
10372 | { | |
10373 | /* An operator function must either be a non-static member function | |
10374 | or have at least one parameter of a class, a reference to a class, | |
10375 | an enumeration, or a reference to an enumeration. 13.4.0.6 */ | |
700f8a87 | 10376 | if (! methodp || DECL_STATIC_FUNCTION_P (decl)) |
8d08fdba MS |
10377 | { |
10378 | if (OPERATOR_TYPENAME_P (name) | |
10379 | || name == ansi_opname[(int) CALL_EXPR] | |
10380 | || name == ansi_opname[(int) MODIFY_EXPR] | |
10381 | || name == ansi_opname[(int) COMPONENT_REF] | |
10382 | || name == ansi_opname[(int) ARRAY_REF]) | |
10383 | cp_error ("`%D' must be a nonstatic member function", decl); | |
10384 | else | |
10385 | { | |
10386 | tree p = argtypes; | |
10387 | ||
700f8a87 MS |
10388 | if (DECL_STATIC_FUNCTION_P (decl)) |
10389 | cp_error ("`%D' must be either a non-static member function or a non-member function", decl); | |
10390 | ||
8d08fdba MS |
10391 | if (p) |
10392 | for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p)) | |
10393 | { | |
10394 | tree arg = TREE_VALUE (p); | |
10395 | if (TREE_CODE (arg) == REFERENCE_TYPE) | |
10396 | arg = TREE_TYPE (arg); | |
10397 | ||
10398 | /* This lets bad template code slip through. */ | |
10399 | if (IS_AGGR_TYPE (arg) | |
10400 | || TREE_CODE (arg) == ENUMERAL_TYPE | |
10401 | || TREE_CODE (arg) == TEMPLATE_TYPE_PARM) | |
10402 | goto foundaggr; | |
10403 | } | |
10404 | cp_error | |
10405 | ("`%D' must have an argument of class or enumerated type", | |
10406 | decl); | |
10407 | foundaggr: | |
10408 | ; | |
10409 | } | |
10410 | } | |
10411 | ||
10412 | if (name == ansi_opname[(int) CALL_EXPR] | |
10413 | || name == ansi_opname[(int) METHOD_CALL_EXPR]) | |
10414 | return; /* no restrictions on args */ | |
10415 | ||
9a3b49ac | 10416 | if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl)) |
a0a33927 MS |
10417 | { |
10418 | tree t = TREE_TYPE (name); | |
10419 | if (TREE_CODE (t) == VOID_TYPE) | |
10420 | pedwarn ("void is not a valid type conversion operator"); | |
10421 | else if (! friendp) | |
10422 | { | |
10423 | int ref = (TREE_CODE (t) == REFERENCE_TYPE); | |
10424 | char *what = 0; | |
10425 | if (ref) | |
10426 | t = TYPE_MAIN_VARIANT (TREE_TYPE (t)); | |
10427 | ||
10428 | if (t == current_class_type) | |
10429 | what = "the same type"; | |
9a3b49ac | 10430 | /* Don't force t to be complete here. */ |
a0a33927 | 10431 | else if (IS_AGGR_TYPE (t) |
9a3b49ac | 10432 | && TYPE_SIZE (t) |
a0a33927 MS |
10433 | && DERIVED_FROM_P (t, current_class_type)) |
10434 | what = "a base class"; | |
10435 | ||
10436 | if (what) | |
10437 | warning ("conversion to %s%s will never use a type conversion operator", | |
10438 | ref ? "a reference to " : "", what); | |
10439 | } | |
10440 | } | |
10441 | ||
8d08fdba MS |
10442 | if (name == ansi_opname[(int) MODIFY_EXPR]) |
10443 | { | |
10444 | tree parmtype; | |
10445 | ||
10446 | if (list_length (argtypes) != 3 && methodp) | |
10447 | { | |
10448 | cp_error ("`%D' must take exactly one argument", decl); | |
10449 | return; | |
10450 | } | |
10451 | parmtype = TREE_VALUE (TREE_CHAIN (argtypes)); | |
10452 | ||
f0e01782 | 10453 | if (copy_assignment_arg_p (parmtype, virtualp) |
a28e3c7f | 10454 | && ! friendp) |
8d08fdba MS |
10455 | { |
10456 | TYPE_HAS_ASSIGN_REF (current_class_type) = 1; | |
f0e01782 MS |
10457 | if (TREE_CODE (parmtype) != REFERENCE_TYPE |
10458 | || TYPE_READONLY (TREE_TYPE (parmtype))) | |
8d08fdba MS |
10459 | TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1; |
10460 | } | |
10461 | } | |
10462 | else if (name == ansi_opname[(int) COND_EXPR]) | |
10463 | { | |
10464 | /* 13.4.0.3 */ | |
10465 | pedwarn ("ANSI C++ prohibits overloading operator ?:"); | |
10466 | if (list_length (argtypes) != 4) | |
10467 | cp_error ("`%D' must take exactly three arguments", decl); | |
10468 | } | |
10469 | else if (ambi_op_p (name)) | |
10470 | { | |
10471 | if (list_length (argtypes) == 2) | |
10472 | /* prefix */; | |
10473 | else if (list_length (argtypes) == 3) | |
10474 | { | |
10475 | if ((name == ansi_opname[(int) POSTINCREMENT_EXPR] | |
10476 | || name == ansi_opname[(int) POSTDECREMENT_EXPR]) | |
5156628f | 10477 | && ! processing_template_decl |
8d08fdba MS |
10478 | && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node) |
10479 | { | |
10480 | if (methodp) | |
10481 | cp_error ("postfix `%D' must take `int' as its argument", | |
10482 | decl); | |
10483 | else | |
10484 | cp_error | |
10485 | ("postfix `%D' must take `int' as its second argument", | |
10486 | decl); | |
10487 | } | |
10488 | } | |
10489 | else | |
10490 | { | |
10491 | if (methodp) | |
10492 | cp_error ("`%D' must take either zero or one argument", decl); | |
10493 | else | |
10494 | cp_error ("`%D' must take either one or two arguments", decl); | |
10495 | } | |
824b9a4c MS |
10496 | |
10497 | /* More Effective C++ rule 6. */ | |
eb448459 | 10498 | if (warn_ecpp |
824b9a4c MS |
10499 | && (name == ansi_opname[(int) POSTINCREMENT_EXPR] |
10500 | || name == ansi_opname[(int) POSTDECREMENT_EXPR])) | |
10501 | { | |
10502 | tree arg = TREE_VALUE (argtypes); | |
10503 | tree ret = TREE_TYPE (TREE_TYPE (decl)); | |
10504 | if (methodp || TREE_CODE (arg) == REFERENCE_TYPE) | |
10505 | arg = TREE_TYPE (arg); | |
10506 | arg = TYPE_MAIN_VARIANT (arg); | |
10507 | if (list_length (argtypes) == 2) | |
10508 | { | |
10509 | if (TREE_CODE (ret) != REFERENCE_TYPE | |
10510 | || !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), | |
10511 | arg, 1)) | |
10512 | cp_warning ("prefix `%D' should return `%T'", decl, | |
10513 | build_reference_type (arg)); | |
10514 | } | |
10515 | else | |
10516 | { | |
10517 | if (!comptypes (TYPE_MAIN_VARIANT (ret), arg, 1)) | |
10518 | cp_warning ("postfix `%D' should return `%T'", decl, arg); | |
10519 | } | |
10520 | } | |
8d08fdba MS |
10521 | } |
10522 | else if (unary_op_p (name)) | |
10523 | { | |
10524 | if (list_length (argtypes) != 2) | |
10525 | { | |
10526 | if (methodp) | |
10527 | cp_error ("`%D' must take `void'", decl); | |
10528 | else | |
10529 | cp_error ("`%D' must take exactly one argument", decl); | |
10530 | } | |
10531 | } | |
10532 | else /* if (binary_op_p (name)) */ | |
10533 | { | |
10534 | if (list_length (argtypes) != 3) | |
10535 | { | |
10536 | if (methodp) | |
10537 | cp_error ("`%D' must take exactly one argument", decl); | |
10538 | else | |
10539 | cp_error ("`%D' must take exactly two arguments", decl); | |
10540 | } | |
824b9a4c MS |
10541 | |
10542 | /* More Effective C++ rule 7. */ | |
eb448459 | 10543 | if (warn_ecpp |
824b9a4c MS |
10544 | && (name == ansi_opname [TRUTH_ANDIF_EXPR] |
10545 | || name == ansi_opname [TRUTH_ORIF_EXPR] | |
10546 | || name == ansi_opname [COMPOUND_EXPR])) | |
10547 | cp_warning ("user-defined `%D' always evaluates both arguments", | |
10548 | decl); | |
10549 | } | |
10550 | ||
10551 | /* Effective C++ rule 23. */ | |
eb448459 | 10552 | if (warn_ecpp |
824b9a4c MS |
10553 | && list_length (argtypes) == 3 |
10554 | && (name == ansi_opname [PLUS_EXPR] | |
10555 | || name == ansi_opname [MINUS_EXPR] | |
10556 | || name == ansi_opname [TRUNC_DIV_EXPR] | |
10557 | || name == ansi_opname [MULT_EXPR]) | |
10558 | && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE) | |
10559 | cp_warning ("`%D' should return by value", decl); | |
8d08fdba MS |
10560 | |
10561 | /* 13.4.0.8 */ | |
10562 | if (argtypes) | |
10563 | for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes)) | |
10564 | if (TREE_PURPOSE (argtypes)) | |
10565 | { | |
10566 | TREE_PURPOSE (argtypes) = NULL_TREE; | |
10567 | if (name == ansi_opname[(int) POSTINCREMENT_EXPR] | |
10568 | || name == ansi_opname[(int) POSTDECREMENT_EXPR]) | |
10569 | { | |
10570 | if (pedantic) | |
10571 | cp_pedwarn ("`%D' cannot have default arguments", decl); | |
10572 | } | |
10573 | else | |
10574 | cp_error ("`%D' cannot have default arguments", decl); | |
10575 | } | |
10576 | } | |
10577 | } | |
10578 | \f | |
10579 | /* Get the struct, enum or union (CODE says which) with tag NAME. | |
10580 | Define the tag as a forward-reference if it is not defined. | |
10581 | ||
10582 | C++: If a class derivation is given, process it here, and report | |
10583 | an error if multiple derivation declarations are not identical. | |
10584 | ||
10585 | If this is a definition, come in through xref_tag and only look in | |
10586 | the current frame for the name (since C++ allows new names in any | |
10587 | scope.) */ | |
10588 | ||
8d08fdba MS |
10589 | tree |
10590 | xref_tag (code_type_node, name, binfo, globalize) | |
10591 | tree code_type_node; | |
10592 | tree name, binfo; | |
10593 | int globalize; | |
10594 | { | |
10595 | enum tag_types tag_code; | |
10596 | enum tree_code code; | |
10597 | int temp = 0; | |
8d08fdba MS |
10598 | register tree ref, t; |
10599 | struct binding_level *b = inner_binding_level; | |
a80e4195 | 10600 | int got_type = 0; |
8d08fdba MS |
10601 | |
10602 | tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); | |
10603 | switch (tag_code) | |
10604 | { | |
10605 | case record_type: | |
10606 | case class_type: | |
8d08fdba MS |
10607 | case signature_type: |
10608 | code = RECORD_TYPE; | |
8d08fdba MS |
10609 | break; |
10610 | case union_type: | |
10611 | code = UNION_TYPE; | |
8d08fdba MS |
10612 | break; |
10613 | case enum_type: | |
10614 | code = ENUMERAL_TYPE; | |
10615 | break; | |
10616 | default: | |
10617 | my_friendly_abort (18); | |
10618 | } | |
10619 | ||
10620 | /* If a cross reference is requested, look up the type | |
10621 | already defined for this tag and return it. */ | |
be99da77 MS |
10622 | if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') |
10623 | { | |
10624 | t = name; | |
a80e4195 MS |
10625 | name = TYPE_IDENTIFIER (t); |
10626 | got_type = 1; | |
be99da77 MS |
10627 | } |
10628 | else | |
10629 | t = IDENTIFIER_TYPE_VALUE (name); | |
ec255269 | 10630 | if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM) |
a0a33927 MS |
10631 | t = NULL_TREE; |
10632 | ||
8ccc31eb | 10633 | if (! globalize) |
8d08fdba | 10634 | { |
ec255269 MS |
10635 | if (pedantic && t && TREE_CODE (t) == TEMPLATE_TYPE_PARM) |
10636 | { | |
10637 | cp_pedwarn ("redeclaration of template type-parameter `%T'", name); | |
10638 | cp_pedwarn_at (" previously declared here", t); | |
10639 | } | |
a80e4195 | 10640 | if (t && TYPE_CONTEXT (t) && got_type) |
8ccc31eb | 10641 | ref = t; |
8d08fdba | 10642 | else |
e92cc029 MS |
10643 | { |
10644 | /* If we know we are defining this tag, only look it up in | |
10645 | this scope and don't try to find it as a type. */ | |
10646 | ref = lookup_tag (code, name, b, 1); | |
10647 | } | |
8d08fdba MS |
10648 | } |
10649 | else | |
10650 | { | |
10651 | if (t) | |
10652 | ref = t; | |
10653 | else | |
10654 | ref = lookup_tag (code, name, b, 0); | |
10655 | ||
10656 | if (! ref) | |
10657 | { | |
10658 | /* Try finding it as a type declaration. If that wins, use it. */ | |
10659 | ref = lookup_name (name, 1); | |
10660 | if (ref && TREE_CODE (ref) == TYPE_DECL | |
10661 | && TREE_CODE (TREE_TYPE (ref)) == code) | |
10662 | ref = TREE_TYPE (ref); | |
10663 | else | |
10664 | ref = NULL_TREE; | |
10665 | } | |
10666 | } | |
10667 | ||
10668 | push_obstacks_nochange (); | |
10669 | ||
10670 | if (! ref) | |
10671 | { | |
10672 | /* If no such tag is yet defined, create a forward-reference node | |
10673 | and record it as the "definition". | |
10674 | When a real declaration of this type is found, | |
10675 | the forward-reference will be altered into a real type. */ | |
10676 | ||
10677 | /* In C++, since these migrate into the global scope, we must | |
10678 | build them on the permanent obstack. */ | |
10679 | ||
10680 | temp = allocation_temporary_p (); | |
10681 | if (temp) | |
10682 | end_temporary_allocation (); | |
10683 | ||
10684 | if (code == ENUMERAL_TYPE) | |
10685 | { | |
fc378698 MS |
10686 | cp_error ("use of enum `%#D' without previous declaration", name); |
10687 | ||
8d08fdba MS |
10688 | ref = make_node (ENUMERAL_TYPE); |
10689 | ||
10690 | /* Give the type a default layout like unsigned int | |
10691 | to avoid crashing if it does not get defined. */ | |
10692 | TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); | |
10693 | TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); | |
10694 | TREE_UNSIGNED (ref) = 1; | |
10695 | TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); | |
10696 | TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); | |
10697 | TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); | |
10698 | ||
10699 | /* Enable us to recognize when a type is created in class context. | |
10700 | To do nested classes correctly, this should probably be cleared | |
10701 | out when we leave this classes scope. Currently this in only | |
10702 | done in `start_enum'. */ | |
10703 | ||
10704 | pushtag (name, ref, globalize); | |
8d08fdba | 10705 | } |
8d08fdba MS |
10706 | else |
10707 | { | |
8d08fdba | 10708 | struct binding_level *old_b = class_binding_level; |
8d08fdba MS |
10709 | |
10710 | ref = make_lang_type (code); | |
10711 | ||
8d08fdba MS |
10712 | if (tag_code == signature_type) |
10713 | { | |
10714 | SET_SIGNATURE (ref); | |
f376e137 MS |
10715 | /* Since a signature type will be turned into the type |
10716 | of signature tables, it's not only an interface. */ | |
8d08fdba | 10717 | CLASSTYPE_INTERFACE_ONLY (ref) = 0; |
f376e137 MS |
10718 | SET_CLASSTYPE_INTERFACE_KNOWN (ref); |
10719 | /* A signature doesn't have a vtable. */ | |
00595019 | 10720 | CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0; |
8d08fdba MS |
10721 | } |
10722 | ||
8d08fdba MS |
10723 | #ifdef NONNESTED_CLASSES |
10724 | /* Class types don't nest the way enums do. */ | |
10725 | class_binding_level = (struct binding_level *)0; | |
10726 | #endif | |
10727 | pushtag (name, ref, globalize); | |
10728 | class_binding_level = old_b; | |
8d08fdba MS |
10729 | } |
10730 | } | |
10731 | else | |
10732 | { | |
8d08fdba MS |
10733 | /* If it no longer looks like a nested type, make sure it's |
10734 | in global scope. */ | |
10735 | if (b == global_binding_level && !class_binding_level | |
10736 | && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE) | |
10737 | IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref); | |
8d08fdba MS |
10738 | } |
10739 | ||
10740 | if (binfo) | |
8ccc31eb | 10741 | xref_basetypes (code_type_node, name, ref, binfo); |
8d08fdba MS |
10742 | |
10743 | just_return: | |
10744 | ||
10745 | /* Until the type is defined, tentatively accept whatever | |
10746 | structure tag the user hands us. */ | |
10747 | if (TYPE_SIZE (ref) == NULL_TREE | |
10748 | && ref != current_class_type | |
10749 | /* Have to check this, in case we have contradictory tag info. */ | |
10750 | && IS_AGGR_TYPE_CODE (TREE_CODE (ref))) | |
10751 | { | |
10752 | if (tag_code == class_type) | |
10753 | CLASSTYPE_DECLARED_CLASS (ref) = 1; | |
10754 | else if (tag_code == record_type || tag_code == signature_type) | |
10755 | CLASSTYPE_DECLARED_CLASS (ref) = 0; | |
10756 | } | |
10757 | ||
10758 | pop_obstacks (); | |
10759 | ||
10760 | return ref; | |
10761 | } | |
8ccc31eb | 10762 | |
fc378698 MS |
10763 | tree |
10764 | xref_tag_from_type (old, id, globalize) | |
10765 | tree old, id; | |
10766 | int globalize; | |
10767 | { | |
10768 | tree code_type_node; | |
10769 | ||
10770 | if (TREE_CODE (old) == RECORD_TYPE) | |
10771 | code_type_node = (CLASSTYPE_DECLARED_CLASS (old) | |
10772 | ? class_type_node : record_type_node); | |
10773 | else | |
10774 | code_type_node = union_type_node; | |
10775 | ||
10776 | if (id == NULL_TREE) | |
10777 | id = TYPE_IDENTIFIER (old); | |
10778 | ||
10779 | return xref_tag (code_type_node, id, NULL_TREE, globalize); | |
10780 | } | |
10781 | ||
8ccc31eb MS |
10782 | void |
10783 | xref_basetypes (code_type_node, name, ref, binfo) | |
10784 | tree code_type_node; | |
10785 | tree name, ref; | |
10786 | tree binfo; | |
10787 | { | |
10788 | /* In the declaration `A : X, Y, ... Z' we mark all the types | |
10789 | (A, X, Y, ..., Z) so we can check for duplicates. */ | |
10790 | tree binfos; | |
10791 | int i, len; | |
10792 | enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); | |
10793 | ||
10794 | if (tag_code == union_type) | |
10795 | { | |
10796 | cp_error ("derived union `%T' invalid", ref); | |
10797 | return; | |
10798 | } | |
10799 | ||
10800 | len = list_length (binfo); | |
10801 | push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref)); | |
10802 | ||
10803 | SET_CLASSTYPE_MARKED (ref); | |
10804 | BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len); | |
10805 | ||
10806 | for (i = 0; binfo; binfo = TREE_CHAIN (binfo)) | |
10807 | { | |
10808 | /* The base of a derived struct is public by default. */ | |
10809 | int via_public | |
be99da77 MS |
10810 | = (TREE_PURPOSE (binfo) == access_public_node |
10811 | || TREE_PURPOSE (binfo) == access_public_virtual_node | |
8ccc31eb | 10812 | || (tag_code != class_type |
be99da77 MS |
10813 | && (TREE_PURPOSE (binfo) == access_default_node |
10814 | || TREE_PURPOSE (binfo) == access_default_virtual_node))); | |
10815 | int via_protected = TREE_PURPOSE (binfo) == access_protected_node; | |
8ccc31eb | 10816 | int via_virtual |
be99da77 MS |
10817 | = (TREE_PURPOSE (binfo) == access_private_virtual_node |
10818 | || TREE_PURPOSE (binfo) == access_public_virtual_node | |
10819 | || TREE_PURPOSE (binfo) == access_default_virtual_node); | |
10820 | tree basetype = TREE_VALUE (binfo); | |
8ccc31eb MS |
10821 | tree base_binfo; |
10822 | ||
10823 | GNU_xref_hier (IDENTIFIER_POINTER (name), | |
10824 | IDENTIFIER_POINTER (TREE_VALUE (binfo)), | |
10825 | via_public, via_virtual, 0); | |
10826 | ||
10827 | if (basetype && TREE_CODE (basetype) == TYPE_DECL) | |
10828 | basetype = TREE_TYPE (basetype); | |
5566b478 MS |
10829 | if (!basetype |
10830 | || (TREE_CODE (basetype) != RECORD_TYPE | |
a80e4195 | 10831 | && TREE_CODE (basetype) != TYPENAME_TYPE |
5566b478 | 10832 | && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM)) |
8ccc31eb MS |
10833 | { |
10834 | cp_error ("base type `%T' fails to be a struct or class type", | |
10835 | TREE_VALUE (binfo)); | |
10836 | continue; | |
10837 | } | |
10838 | #if 1 | |
10839 | /* This code replaces similar code in layout_basetypes. */ | |
e9f32eb5 MS |
10840 | else if (TYPE_SIZE (complete_type (basetype)) == NULL_TREE |
10841 | && ! (current_template_parms && uses_template_parms (basetype))) | |
8ccc31eb MS |
10842 | { |
10843 | cp_error ("base class `%T' has incomplete type", basetype); | |
10844 | continue; | |
10845 | } | |
10846 | #endif | |
10847 | else | |
10848 | { | |
10849 | if (CLASSTYPE_MARKED (basetype)) | |
10850 | { | |
10851 | if (basetype == ref) | |
10852 | cp_error ("recursive type `%T' undefined", basetype); | |
10853 | else | |
10854 | cp_error ("duplicate base type `%T' invalid", basetype); | |
10855 | continue; | |
10856 | } | |
10857 | ||
10858 | /* Note that the BINFO records which describe individual | |
10859 | inheritances are *not* shared in the lattice! They | |
10860 | cannot be shared because a given baseclass may be | |
10861 | inherited with different `accessibility' by different | |
10862 | derived classes. (Each BINFO record describing an | |
10863 | individual inheritance contains flags which say what | |
10864 | the `accessibility' of that particular inheritance is.) */ | |
10865 | ||
10866 | base_binfo = make_binfo (integer_zero_node, basetype, | |
10867 | TYPE_BINFO_VTABLE (basetype), | |
10868 | TYPE_BINFO_VIRTUALS (basetype), NULL_TREE); | |
10869 | ||
10870 | TREE_VEC_ELT (binfos, i) = base_binfo; | |
10871 | TREE_VIA_PUBLIC (base_binfo) = via_public; | |
10872 | TREE_VIA_PROTECTED (base_binfo) = via_protected; | |
10873 | TREE_VIA_VIRTUAL (base_binfo) = via_virtual; | |
10874 | BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref); | |
10875 | ||
10876 | SET_CLASSTYPE_MARKED (basetype); | |
9e9ff709 | 10877 | |
8ccc31eb MS |
10878 | /* We are free to modify these bits because they are meaningless |
10879 | at top level, and BASETYPE is a top-level type. */ | |
10880 | if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) | |
10881 | { | |
10882 | TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1; | |
10883 | TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; | |
10884 | } | |
10885 | ||
10886 | TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype); | |
10887 | TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype); | |
10888 | TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype); | |
10889 | CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype); | |
10890 | i += 1; | |
10891 | } | |
10892 | } | |
10893 | if (i) | |
10894 | TREE_VEC_LENGTH (binfos) = i; | |
10895 | else | |
10896 | BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE; | |
10897 | ||
10898 | if (i > 1) | |
10899 | TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; | |
10900 | else if (i == 1) | |
10901 | TYPE_USES_MULTIPLE_INHERITANCE (ref) | |
10902 | = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0))); | |
10903 | if (TYPE_USES_MULTIPLE_INHERITANCE (ref)) | |
10904 | TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; | |
10905 | ||
10906 | /* Unmark all the types. */ | |
10907 | while (--i >= 0) | |
10908 | CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i))); | |
10909 | CLEAR_CLASSTYPE_MARKED (ref); | |
10910 | ||
10911 | pop_obstacks (); | |
10912 | } | |
10913 | ||
8d08fdba | 10914 | \f |
b3d5a58b | 10915 | tree current_local_enum = NULL_TREE; |
8d08fdba MS |
10916 | |
10917 | /* Begin compiling the definition of an enumeration type. | |
10918 | NAME is its name (or null if anonymous). | |
10919 | Returns the type object, as yet incomplete. | |
10920 | Also records info about it so that build_enumerator | |
10921 | may be used to declare the individual values as they are read. */ | |
10922 | ||
10923 | tree | |
10924 | start_enum (name) | |
10925 | tree name; | |
10926 | { | |
10927 | register tree enumtype = NULL_TREE; | |
10928 | struct binding_level *b = inner_binding_level; | |
10929 | ||
b87692e5 MS |
10930 | if (processing_template_decl && current_function_decl) |
10931 | end_temporary_allocation (); | |
10932 | ||
8d08fdba MS |
10933 | /* If this is the real definition for a previous forward reference, |
10934 | fill in the contents in the same object that used to be the | |
10935 | forward reference. */ | |
10936 | ||
10937 | if (name != NULL_TREE) | |
10938 | enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); | |
10939 | ||
10940 | if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE) | |
c91a56d2 | 10941 | cp_error ("multiple definition of `%#T'", enumtype); |
8d08fdba MS |
10942 | else |
10943 | { | |
10944 | enumtype = make_node (ENUMERAL_TYPE); | |
10945 | pushtag (name, enumtype, 0); | |
10946 | } | |
10947 | ||
c91a56d2 MS |
10948 | if (b->pseudo_global) |
10949 | cp_error ("template declaration of `%#T'", enumtype); | |
10950 | ||
8d08fdba MS |
10951 | if (current_class_type) |
10952 | TREE_ADDRESSABLE (b->tags) = 1; | |
c91a56d2 | 10953 | |
8d08fdba MS |
10954 | current_local_enum = NULL_TREE; |
10955 | ||
e92cc029 MS |
10956 | /* We don't copy this value because build_enumerator needs to do it. */ |
10957 | enum_next_value = integer_zero_node; | |
7177d104 | 10958 | enum_overflow = 0; |
8d08fdba MS |
10959 | |
10960 | GNU_xref_decl (current_function_decl, enumtype); | |
10961 | return enumtype; | |
10962 | } | |
10963 | ||
10964 | /* After processing and defining all the values of an enumeration type, | |
10965 | install their decls in the enumeration type and finish it off. | |
10966 | ENUMTYPE is the type object and VALUES a list of name-value pairs. | |
10967 | Returns ENUMTYPE. */ | |
10968 | ||
10969 | tree | |
10970 | finish_enum (enumtype, values) | |
10971 | register tree enumtype, values; | |
10972 | { | |
f376e137 | 10973 | register tree minnode, maxnode; |
8d08fdba MS |
10974 | /* Calculate the maximum value of any enumerator in this type. */ |
10975 | ||
10976 | if (values) | |
10977 | { | |
f376e137 MS |
10978 | register tree pair; |
10979 | register tree value = DECL_INITIAL (TREE_VALUE (values)); | |
5566b478 | 10980 | |
5156628f | 10981 | if (! processing_template_decl) |
5566b478 MS |
10982 | { |
10983 | /* Speed up the main loop by performing some precalculations */ | |
10984 | TREE_TYPE (TREE_VALUE (values)) = enumtype; | |
10985 | TREE_TYPE (value) = enumtype; | |
10986 | minnode = maxnode = value; | |
10987 | } | |
f376e137 | 10988 | TREE_VALUE (values) = value; |
8d08fdba MS |
10989 | |
10990 | for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) | |
10991 | { | |
f376e137 | 10992 | value = DECL_INITIAL (TREE_VALUE (pair)); |
5156628f | 10993 | if (! processing_template_decl) |
5566b478 MS |
10994 | { |
10995 | TREE_TYPE (TREE_VALUE (pair)) = enumtype; | |
10996 | TREE_TYPE (value) = enumtype; | |
10997 | if (tree_int_cst_lt (maxnode, value)) | |
10998 | maxnode = value; | |
10999 | else if (tree_int_cst_lt (value, minnode)) | |
11000 | minnode = value; | |
11001 | } | |
f376e137 | 11002 | TREE_VALUE (pair) = value; |
8d08fdba MS |
11003 | } |
11004 | } | |
f376e137 MS |
11005 | else |
11006 | maxnode = minnode = integer_zero_node; | |
8d08fdba | 11007 | |
de22184b | 11008 | TYPE_VALUES (enumtype) = nreverse (values); |
2986ae00 | 11009 | |
5156628f | 11010 | if (processing_template_decl) |
b87692e5 MS |
11011 | { |
11012 | if (current_function_decl) | |
11013 | { | |
11014 | add_tree (build_min (TAG_DEFN, enumtype)); | |
11015 | resume_temporary_allocation (); | |
11016 | } | |
11017 | return enumtype; | |
11018 | } | |
5566b478 | 11019 | |
f376e137 MS |
11020 | { |
11021 | int unsignedp = tree_int_cst_sgn (minnode) >= 0; | |
11022 | int lowprec = min_precision (minnode, unsignedp); | |
11023 | int highprec = min_precision (maxnode, unsignedp); | |
11024 | int precision = MAX (lowprec, highprec); | |
8d08fdba | 11025 | |
6060a796 | 11026 | TYPE_SIZE (enumtype) = NULL_TREE; |
13fbb038 | 11027 | |
8ccc31eb | 11028 | /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */ |
8d08fdba | 11029 | |
f376e137 | 11030 | TYPE_PRECISION (enumtype) = precision; |
f376e137 | 11031 | if (unsignedp) |
8d08fdba | 11032 | fixup_unsigned_type (enumtype); |
f376e137 MS |
11033 | else |
11034 | fixup_signed_type (enumtype); | |
8ccc31eb | 11035 | |
5566b478 | 11036 | if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node))) |
8ccc31eb MS |
11037 | /* Use the width of the narrowest normal C type which is wide enough. */ |
11038 | TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size | |
11039 | (precision, 1)); | |
11040 | else | |
11041 | TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); | |
11042 | ||
11043 | TYPE_SIZE (enumtype) = 0; | |
11044 | layout_type (enumtype); | |
f376e137 | 11045 | } |
8d08fdba | 11046 | |
f376e137 MS |
11047 | { |
11048 | register tree tem; | |
11049 | ||
11050 | /* Fix up all variant types of this enum type. */ | |
11051 | for (tem = TYPE_MAIN_VARIANT (enumtype); tem; | |
11052 | tem = TYPE_NEXT_VARIANT (tem)) | |
11053 | { | |
11054 | TYPE_VALUES (tem) = TYPE_VALUES (enumtype); | |
11055 | TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); | |
11056 | TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); | |
11057 | TYPE_SIZE (tem) = TYPE_SIZE (enumtype); | |
11058 | TYPE_MODE (tem) = TYPE_MODE (enumtype); | |
11059 | TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); | |
11060 | TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); | |
11061 | TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); | |
11062 | } | |
11063 | } | |
8d08fdba MS |
11064 | |
11065 | /* Finish debugging output for this type. */ | |
d2e5ee5c | 11066 | rest_of_type_compilation (enumtype, global_bindings_p ()); |
8d08fdba MS |
11067 | |
11068 | return enumtype; | |
11069 | } | |
11070 | ||
11071 | /* Build and install a CONST_DECL for one value of the | |
11072 | current enumeration type (one that was begun with start_enum). | |
11073 | Return a tree-list containing the name and its value. | |
11074 | Assignment of sequential values by default is handled here. */ | |
11075 | ||
11076 | tree | |
11077 | build_enumerator (name, value) | |
11078 | tree name, value; | |
11079 | { | |
11080 | tree decl, result; | |
8d08fdba MS |
11081 | |
11082 | /* Remove no-op casts from the value. */ | |
11083 | if (value) | |
11084 | STRIP_TYPE_NOPS (value); | |
11085 | ||
5156628f | 11086 | if (! processing_template_decl) |
5566b478 MS |
11087 | { |
11088 | /* Validate and default VALUE. */ | |
11089 | if (value != NULL_TREE) | |
11090 | { | |
11091 | if (TREE_READONLY_DECL_P (value)) | |
e92cc029 | 11092 | value = decl_constant_value (value); |
5566b478 MS |
11093 | |
11094 | if (TREE_CODE (value) == INTEGER_CST) | |
11095 | { | |
11096 | value = default_conversion (value); | |
11097 | constant_expression_warning (value); | |
11098 | } | |
11099 | else | |
11100 | { | |
11101 | cp_error ("enumerator value for `%D' not integer constant", name); | |
11102 | value = NULL_TREE; | |
11103 | } | |
11104 | } | |
11105 | ||
5566b478 | 11106 | /* Default based on previous value. */ |
5156628f | 11107 | if (value == NULL_TREE && ! processing_template_decl) |
5566b478 MS |
11108 | { |
11109 | value = enum_next_value; | |
11110 | if (enum_overflow) | |
11111 | cp_error ("overflow in enumeration values at `%D'", name); | |
11112 | } | |
11113 | ||
11114 | /* Remove no-op casts from the value. */ | |
11115 | if (value) | |
11116 | STRIP_TYPE_NOPS (value); | |
11117 | ||
e92cc029 MS |
11118 | /* We have to always copy here; not all INTEGER_CSTs are unshared, |
11119 | and there's no wedding ring. Look at size_int()...*/ | |
11120 | value = copy_node (value); | |
013bc8af MS |
11121 | #if 0 |
11122 | /* To fix MAX_VAL enum consts. (bkoz) */ | |
e92cc029 | 11123 | TREE_TYPE (value) = integer_type_node; |
013bc8af | 11124 | #endif |
5566b478 | 11125 | } |
8d08fdba | 11126 | |
8d08fdba MS |
11127 | /* C++ associates enums with global, function, or class declarations. */ |
11128 | ||
7177d104 MS |
11129 | decl = current_scope (); |
11130 | if (decl && decl == current_class_type) | |
8d08fdba MS |
11131 | { |
11132 | /* This enum declaration is local to the class, so we must put | |
11133 | it in that class's list of decls. */ | |
11134 | decl = build_lang_field_decl (CONST_DECL, name, integer_type_node); | |
11135 | DECL_INITIAL (decl) = value; | |
11136 | TREE_READONLY (decl) = 1; | |
11137 | pushdecl_class_level (decl); | |
11138 | TREE_CHAIN (decl) = current_local_enum; | |
11139 | current_local_enum = decl; | |
11140 | } | |
11141 | else | |
11142 | { | |
11143 | /* It's a global enum, or it's local to a function. (Note local to | |
11144 | a function could mean local to a class method. */ | |
11145 | decl = build_decl (CONST_DECL, name, integer_type_node); | |
11146 | DECL_INITIAL (decl) = value; | |
42976354 | 11147 | TREE_READONLY (decl) = 1; |
8d08fdba MS |
11148 | |
11149 | pushdecl (decl); | |
11150 | GNU_xref_decl (current_function_decl, decl); | |
11151 | } | |
11152 | ||
5156628f | 11153 | if (! processing_template_decl) |
5566b478 MS |
11154 | { |
11155 | /* Set basis for default for next value. */ | |
11156 | enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, | |
11157 | integer_one_node, PLUS_EXPR); | |
11158 | enum_overflow = tree_int_cst_lt (enum_next_value, value); | |
5566b478 | 11159 | } |
8d08fdba | 11160 | |
8d2733ca | 11161 | result = saveable_tree_cons (name, decl, NULL_TREE); |
8d08fdba MS |
11162 | return result; |
11163 | } | |
11164 | ||
11165 | tree | |
11166 | grok_enum_decls (type, decl) | |
11167 | tree type, decl; | |
11168 | { | |
11169 | tree d = current_local_enum; | |
11170 | ||
11171 | if (d == NULL_TREE) | |
11172 | return decl; | |
11173 | ||
11174 | while (1) | |
11175 | { | |
11176 | TREE_TYPE (d) = type; | |
11177 | if (TREE_CHAIN (d) == NULL_TREE) | |
11178 | { | |
11179 | TREE_CHAIN (d) = decl; | |
11180 | break; | |
11181 | } | |
11182 | d = TREE_CHAIN (d); | |
11183 | } | |
11184 | ||
11185 | decl = current_local_enum; | |
11186 | current_local_enum = NULL_TREE; | |
11187 | ||
11188 | return decl; | |
11189 | } | |
11190 | \f | |
5566b478 MS |
11191 | static int function_depth; |
11192 | ||
8d08fdba MS |
11193 | /* Create the FUNCTION_DECL for a function definition. |
11194 | DECLSPECS and DECLARATOR are the parts of the declaration; | |
11195 | they describe the function's name and the type it returns, | |
11196 | but twisted together in a fashion that parallels the syntax of C. | |
11197 | ||
11198 | This function creates a binding context for the function body | |
11199 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
11200 | ||
11201 | Returns 1 on success. If the DECLARATOR is not suitable for a function | |
11202 | (it defines a datum instead), we return 0, which tells | |
11203 | yyparse to report a parse error. | |
11204 | ||
11205 | For C++, we must first check whether that datum makes any sense. | |
11206 | For example, "class A local_a(1,2);" means that variable local_a | |
11207 | is an aggregate of type A, which should have a constructor | |
11208 | applied to it with the argument list [1, 2]. | |
11209 | ||
11210 | @@ There is currently no way to retrieve the storage | |
11211 | @@ allocated to FUNCTION (or all of its parms) if we return | |
11212 | @@ something we had previously. */ | |
11213 | ||
11214 | int | |
c11b6f21 MS |
11215 | start_function (declspecs, declarator, attrs, pre_parsed_p) |
11216 | tree declspecs, declarator, attrs; | |
8d08fdba MS |
11217 | int pre_parsed_p; |
11218 | { | |
5566b478 | 11219 | tree decl1; |
8d08fdba MS |
11220 | tree ctype = NULL_TREE; |
11221 | tree fntype; | |
11222 | tree restype; | |
11223 | extern int have_extern_spec; | |
11224 | extern int used_extern_spec; | |
11225 | int doing_friend = 0; | |
11226 | ||
8d08fdba MS |
11227 | /* Sanity check. */ |
11228 | my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160); | |
11229 | my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); | |
11230 | ||
e92cc029 | 11231 | /* Assume, until we see it does. */ |
8d08fdba MS |
11232 | current_function_returns_value = 0; |
11233 | current_function_returns_null = 0; | |
11234 | warn_about_return_type = 0; | |
fd378c9d JM |
11235 | named_labels = 0; |
11236 | shadowed_labels = 0; | |
8d08fdba MS |
11237 | current_function_assigns_this = 0; |
11238 | current_function_just_assigned_this = 0; | |
11239 | current_function_parms_stored = 0; | |
11240 | original_result_rtx = NULL_RTX; | |
a9aedbc2 | 11241 | base_init_expr = NULL_TREE; |
79ff2c6c MS |
11242 | current_base_init_list = NULL_TREE; |
11243 | current_member_init_list = NULL_TREE; | |
f30432d7 | 11244 | ctor_label = dtor_label = NULL_TREE; |
42976354 | 11245 | static_labelno = 0; |
8d08fdba MS |
11246 | |
11247 | clear_temp_name (); | |
11248 | ||
e92cc029 | 11249 | /* This should only be done once on the top most decl. */ |
8d08fdba MS |
11250 | if (have_extern_spec && !used_extern_spec) |
11251 | { | |
11252 | declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); | |
11253 | used_extern_spec = 1; | |
11254 | } | |
11255 | ||
11256 | if (pre_parsed_p) | |
11257 | { | |
11258 | decl1 = declarator; | |
11259 | ||
11260 | if (! DECL_ARGUMENTS (decl1) | |
11261 | && !DECL_STATIC_FUNCTION_P (decl1) | |
11262 | && DECL_CONTEXT (decl1) | |
d2e5ee5c MS |
11263 | && TYPE_IDENTIFIER (DECL_CONTEXT (decl1)) |
11264 | && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (DECL_CONTEXT (decl1)))) | |
8d08fdba MS |
11265 | { |
11266 | cp_error ("redeclaration of `%#D'", decl1); | |
11267 | if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))) | |
11268 | cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))); | |
11269 | else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))) | |
11270 | cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))); | |
11271 | } | |
11272 | ||
8d08fdba MS |
11273 | fntype = TREE_TYPE (decl1); |
11274 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
11275 | ctype = TYPE_METHOD_BASETYPE (fntype); | |
11276 | ||
11277 | /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a | |
11278 | class is in the (lexical) scope of the class in which it is | |
11279 | defined. */ | |
11280 | if (!ctype && DECL_FRIEND_P (decl1)) | |
11281 | { | |
11282 | ctype = DECL_CLASS_CONTEXT (decl1); | |
11283 | ||
11284 | /* CTYPE could be null here if we're dealing with a template; | |
11285 | for example, `inline friend float foo()' inside a template | |
11286 | will have no CTYPE set. */ | |
11287 | if (ctype && TREE_CODE (ctype) != RECORD_TYPE) | |
11288 | ctype = NULL_TREE; | |
11289 | else | |
11290 | doing_friend = 1; | |
11291 | } | |
11292 | ||
8d08fdba | 11293 | /* In a fcn definition, arg types must be complete. */ |
5566b478 | 11294 | require_complete_types_for_parms (DECL_ARGUMENTS (decl1)); |
9fffd093 RK |
11295 | |
11296 | /* In case some arg types were completed since the declaration was | |
11297 | parsed, fix up the decls. */ | |
11298 | { | |
5566b478 | 11299 | tree t = DECL_ARGUMENTS (decl1); |
9fffd093 RK |
11300 | for (; t; t = TREE_CHAIN (t)) |
11301 | layout_decl (t, 0); | |
11302 | } | |
5566b478 MS |
11303 | |
11304 | last_function_parms = DECL_ARGUMENTS (decl1); | |
11305 | last_function_parm_tags = NULL_TREE; | |
8d08fdba MS |
11306 | } |
11307 | else | |
11308 | { | |
c11b6f21 | 11309 | decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL_TREE); |
8d08fdba MS |
11310 | /* If the declarator is not suitable for a function definition, |
11311 | cause a syntax error. */ | |
11312 | if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0; | |
11313 | ||
11314 | fntype = TREE_TYPE (decl1); | |
11315 | ||
11316 | restype = TREE_TYPE (fntype); | |
11317 | if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype) | |
11318 | && ! CLASSTYPE_GOT_SEMICOLON (restype)) | |
11319 | { | |
11320 | cp_error ("semicolon missing after declaration of `%#T'", restype); | |
11321 | shadow_tag (build_tree_list (NULL_TREE, restype)); | |
11322 | CLASSTYPE_GOT_SEMICOLON (restype) = 1; | |
11323 | if (TREE_CODE (fntype) == FUNCTION_TYPE) | |
11324 | fntype = build_function_type (integer_type_node, | |
11325 | TYPE_ARG_TYPES (fntype)); | |
11326 | else | |
11327 | fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)), | |
11328 | integer_type_node, | |
11329 | TYPE_ARG_TYPES (fntype)); | |
11330 | TREE_TYPE (decl1) = fntype; | |
11331 | } | |
11332 | ||
11333 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
11334 | ctype = TYPE_METHOD_BASETYPE (fntype); | |
11335 | else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4 | |
11336 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main") | |
11337 | && DECL_CONTEXT (decl1) == NULL_TREE) | |
11338 | { | |
11339 | /* If this doesn't return integer_type, complain. */ | |
11340 | if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node) | |
11341 | { | |
a28e3c7f | 11342 | if (pedantic || warn_return_type) |
5566b478 | 11343 | pedwarn ("return type for `main' changed to `int'"); |
8d08fdba MS |
11344 | TREE_TYPE (decl1) = fntype = default_function_type; |
11345 | } | |
11346 | warn_about_return_type = 0; | |
11347 | } | |
11348 | } | |
11349 | ||
11350 | /* Warn if function was previously implicitly declared | |
11351 | (but not if we warned then). */ | |
11352 | if (! warn_implicit | |
11353 | && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE) | |
11354 | cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))); | |
11355 | ||
11356 | current_function_decl = decl1; | |
5566b478 MS |
11357 | /* Save the parm names or decls from this function's declarator |
11358 | where store_parm_decls will find them. */ | |
11359 | current_function_parms = last_function_parms; | |
11360 | current_function_parm_tags = last_function_parm_tags; | |
8d08fdba | 11361 | |
9e9ff709 | 11362 | announce_function (decl1); |
8d08fdba | 11363 | |
5156628f | 11364 | if (! processing_template_decl) |
8d08fdba | 11365 | { |
5566b478 MS |
11366 | if (TYPE_SIZE (complete_type (TREE_TYPE (fntype))) == NULL_TREE) |
11367 | { | |
11368 | cp_error ("return-type `%#T' is an incomplete type", | |
11369 | TREE_TYPE (fntype)); | |
8d08fdba | 11370 | |
5566b478 MS |
11371 | /* Make it return void instead, but don't change the |
11372 | type of the DECL_RESULT, in case we have a named return value. */ | |
11373 | if (ctype) | |
11374 | TREE_TYPE (decl1) | |
11375 | = build_cplus_method_type (build_type_variant (ctype, | |
11376 | TREE_READONLY (decl1), | |
11377 | TREE_SIDE_EFFECTS (decl1)), | |
11378 | void_type_node, | |
11379 | FUNCTION_ARG_CHAIN (decl1)); | |
11380 | else | |
11381 | TREE_TYPE (decl1) | |
11382 | = build_function_type (void_type_node, | |
11383 | TYPE_ARG_TYPES (TREE_TYPE (decl1))); | |
11384 | DECL_RESULT (decl1) | |
11385 | = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype))); | |
11386 | TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype)); | |
11387 | TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype)); | |
11388 | } | |
11389 | ||
11390 | if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype)) | |
11391 | && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype))) | |
11392 | abstract_virtuals_error (decl1, TREE_TYPE (fntype)); | |
11393 | } | |
b7484fbe | 11394 | |
8d08fdba | 11395 | if (warn_about_return_type) |
59f1f2c4 | 11396 | pedwarn ("return-type defaults to `int'"); |
8d08fdba | 11397 | |
824b9a4c | 11398 | /* Effective C++ rule 15. See also c_expand_return. */ |
eb448459 | 11399 | if (warn_ecpp |
824b9a4c MS |
11400 | && DECL_NAME (decl1) == ansi_opname[(int) MODIFY_EXPR] |
11401 | && TREE_TYPE (fntype) == void_type_node) | |
11402 | cp_warning ("`operator=' should return a reference to `*this'"); | |
11403 | ||
8d08fdba MS |
11404 | /* Make the init_value nonzero so pushdecl knows this is not tentative. |
11405 | error_mark_node is replaced below (in poplevel) with the BLOCK. */ | |
11406 | DECL_INITIAL (decl1) = error_mark_node; | |
11407 | ||
8d08fdba MS |
11408 | /* This function exists in static storage. |
11409 | (This does not mean `static' in the C sense!) */ | |
11410 | TREE_STATIC (decl1) = 1; | |
11411 | ||
878cd289 MS |
11412 | /* Record the decl so that the function name is defined. |
11413 | If we already have a decl for this name, and it is a FUNCTION_DECL, | |
11414 | use the old decl. */ | |
11415 | ||
5156628f | 11416 | if (processing_template_decl) |
5566b478 MS |
11417 | push_template_decl (decl1); |
11418 | else if (pre_parsed_p == 0) | |
878cd289 | 11419 | { |
5566b478 | 11420 | decl1 = pushdecl (decl1); |
878cd289 MS |
11421 | DECL_MAIN_VARIANT (decl1) = decl1; |
11422 | fntype = TREE_TYPE (decl1); | |
11423 | } | |
5566b478 MS |
11424 | |
11425 | current_function_decl = decl1; | |
878cd289 | 11426 | |
db5ae43f | 11427 | if (DECL_INTERFACE_KNOWN (decl1)) |
faae18ab MS |
11428 | { |
11429 | if (DECL_NOT_REALLY_EXTERN (decl1)) | |
11430 | DECL_EXTERNAL (decl1) = 0; | |
11431 | } | |
8d08fdba MS |
11432 | /* If this function belongs to an interface, it is public. |
11433 | If it belongs to someone else's interface, it is also external. | |
11434 | It doesn't matter whether it's inline or not. */ | |
5566b478 MS |
11435 | else if (interface_unknown == 0 |
11436 | && (! DECL_TEMPLATE_INSTANTIATION (decl1) | |
d11ad92e | 11437 | || flag_alt_external_templates)) |
8d08fdba | 11438 | { |
5566b478 | 11439 | if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1) |
5156628f | 11440 | || processing_template_decl) |
db5ae43f MS |
11441 | DECL_EXTERNAL (decl1) |
11442 | = (interface_only | |
faae18ab | 11443 | || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines)); |
db5ae43f | 11444 | else |
893de33c | 11445 | DECL_EXTERNAL (decl1) = 0; |
e8abc66f | 11446 | DECL_NOT_REALLY_EXTERN (decl1) = 0; |
db5ae43f | 11447 | DECL_INTERFACE_KNOWN (decl1) = 1; |
8d08fdba MS |
11448 | } |
11449 | else | |
a0a33927 MS |
11450 | { |
11451 | /* This is a definition, not a reference. | |
b7484fbe MS |
11452 | So clear DECL_EXTERNAL. */ |
11453 | DECL_EXTERNAL (decl1) = 0; | |
faae18ab | 11454 | |
5566b478 MS |
11455 | if ((DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)) |
11456 | && ! DECL_INTERFACE_KNOWN (decl1) | |
11457 | /* Don't try to defer nested functions for now. */ | |
e76a2646 | 11458 | && ! hack_decl_function_context (decl1)) |
878cd289 MS |
11459 | DECL_DEFER_OUTPUT (decl1) = 1; |
11460 | else | |
893de33c | 11461 | DECL_INTERFACE_KNOWN (decl1) = 1; |
db5ae43f | 11462 | } |
a9aedbc2 | 11463 | |
8d08fdba MS |
11464 | if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) |
11465 | { | |
11466 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
11467 | TREE_TYPE (decl1) = fntype | |
11468 | = build_function_type (TREE_TYPE (fntype), | |
11469 | TREE_CHAIN (TYPE_ARG_TYPES (fntype))); | |
5566b478 MS |
11470 | current_function_parms = TREE_CHAIN (current_function_parms); |
11471 | DECL_ARGUMENTS (decl1) = current_function_parms; | |
8d08fdba MS |
11472 | ctype = NULL_TREE; |
11473 | } | |
11474 | restype = TREE_TYPE (fntype); | |
11475 | ||
8d08fdba MS |
11476 | if (ctype) |
11477 | { | |
11478 | push_nested_class (ctype, 1); | |
11479 | ||
11480 | /* If we're compiling a friend function, neither of the variables | |
4ac14744 | 11481 | current_class_ptr nor current_class_type will have values. */ |
8d08fdba MS |
11482 | if (! doing_friend) |
11483 | { | |
11484 | /* We know that this was set up by `grokclassfn'. | |
11485 | We do not wait until `store_parm_decls', since evil | |
11486 | parse errors may never get us to that point. Here | |
11487 | we keep the consistency between `current_class_type' | |
4ac14744 | 11488 | and `current_class_ptr'. */ |
5566b478 | 11489 | tree t = current_function_parms; |
5f34005f RK |
11490 | |
11491 | my_friendly_assert (t != NULL_TREE | |
11492 | && TREE_CODE (t) == PARM_DECL, 162); | |
11493 | ||
dff6b454 RK |
11494 | if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE) |
11495 | { | |
11496 | int i = suspend_momentary (); | |
11497 | ||
11498 | /* Fool build_indirect_ref. */ | |
4ac14744 MS |
11499 | current_class_ptr = NULL_TREE; |
11500 | current_class_ref = build_indirect_ref (t, NULL_PTR); | |
11501 | current_class_ptr = t; | |
dff6b454 RK |
11502 | resume_momentary (i); |
11503 | } | |
11504 | else | |
11505 | /* We're having a signature pointer here. */ | |
4ac14744 | 11506 | current_class_ref = current_class_ptr = t; |
dff6b454 | 11507 | |
8d08fdba MS |
11508 | } |
11509 | } | |
11510 | else | |
11511 | { | |
11512 | if (DECL_STATIC_FUNCTION_P (decl1)) | |
11513 | push_nested_class (DECL_CONTEXT (decl1), 2); | |
11514 | else | |
11515 | push_memoized_context (0, 1); | |
4ac14744 | 11516 | current_class_ptr = current_class_ref = NULL_TREE; |
8d08fdba MS |
11517 | } |
11518 | ||
db5ae43f MS |
11519 | pushlevel (0); |
11520 | current_binding_level->parm_flag = 1; | |
11521 | ||
db5ae43f MS |
11522 | GNU_xref_function (decl1, current_function_parms); |
11523 | ||
f30432d7 MS |
11524 | if (attrs) |
11525 | cplus_decl_attributes (decl1, NULL_TREE, attrs); | |
db5ae43f MS |
11526 | make_function_rtl (decl1); |
11527 | ||
8d08fdba MS |
11528 | /* Promote the value to int before returning it. */ |
11529 | if (C_PROMOTING_INTEGER_TYPE_P (restype)) | |
5566b478 MS |
11530 | restype = type_promotes_to (restype); |
11531 | ||
11532 | /* If this fcn was already referenced via a block-scope `extern' decl | |
11533 | (or an implicit decl), propagate certain information about the usage. */ | |
11534 | if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) | |
11535 | TREE_ADDRESSABLE (decl1) = 1; | |
11536 | ||
8d08fdba | 11537 | if (DECL_RESULT (decl1) == NULL_TREE) |
f30432d7 MS |
11538 | { |
11539 | DECL_RESULT (decl1) | |
11540 | = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype)); | |
11541 | TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype); | |
11542 | TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype); | |
11543 | } | |
8d08fdba | 11544 | |
5566b478 MS |
11545 | /* Allocate further tree nodes temporarily during compilation |
11546 | of this function only. Tiemann moved up here from bottom of fn. */ | |
11547 | temporary_allocation (); | |
11548 | ||
5156628f | 11549 | if (processing_template_decl) |
5566b478 MS |
11550 | { |
11551 | extern tree last_tree; | |
11552 | ++minimal_parse_mode; | |
11553 | last_tree = DECL_SAVED_TREE (decl1) | |
11554 | = build_nt (EXPR_STMT, void_zero_node); | |
11555 | } | |
11556 | ||
11557 | ++function_depth; | |
11558 | ||
f30432d7 MS |
11559 | if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)) |
11560 | && DECL_LANGUAGE (decl1) == lang_cplusplus) | |
8d08fdba MS |
11561 | { |
11562 | dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
11563 | ctor_label = NULL_TREE; | |
11564 | } | |
11565 | else | |
11566 | { | |
11567 | dtor_label = NULL_TREE; | |
11568 | if (DECL_CONSTRUCTOR_P (decl1)) | |
11569 | ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
11570 | } | |
11571 | ||
8d08fdba MS |
11572 | return 1; |
11573 | } | |
11574 | \f | |
f30432d7 | 11575 | void |
6467930b | 11576 | store_after_parms (insns) |
f30432d7 MS |
11577 | rtx insns; |
11578 | { | |
6467930b MS |
11579 | rtx x; |
11580 | ||
11581 | for (x = get_insns (); x; x = next_insn (x)) | |
11582 | { | |
11583 | if (GET_CODE (x) == NOTE && NOTE_LINE_NUMBER (x) == NOTE_INSN_FUNCTION_BEG) | |
11584 | { | |
11585 | emit_insns_after (insns, x); | |
11586 | return; | |
11587 | } | |
11588 | } | |
11589 | #if 0 | |
11590 | /* This doesn't work, because the inline output routine doesn't reset | |
11591 | last_parm_insn correctly for get_first_nonparm_insn () to work. */ | |
f30432d7 MS |
11592 | |
11593 | last_parm_insn = get_first_nonparm_insn (); | |
11594 | if (last_parm_insn == NULL_RTX) | |
11595 | emit_insns (insns); | |
11596 | else | |
6467930b MS |
11597 | emit_insns_before (insns, last_parm_insn); |
11598 | #endif | |
11599 | } | |
11600 | ||
11601 | void | |
11602 | expand_start_early_try_stmts () | |
11603 | { | |
11604 | rtx insns; | |
11605 | start_sequence (); | |
11606 | expand_start_try_stmts (); | |
11607 | insns = get_insns (); | |
11608 | end_sequence (); | |
11609 | #if 1 | |
11610 | emit_insns_after (insns, get_insns ()); | |
11611 | #else | |
11612 | store_after_parms (insns); | |
11613 | #endif | |
f30432d7 MS |
11614 | } |
11615 | ||
8d08fdba MS |
11616 | /* Store the parameter declarations into the current function declaration. |
11617 | This is called after parsing the parameter declarations, before | |
11618 | digesting the body of the function. | |
11619 | ||
11620 | Also install to binding contour return value identifier, if any. */ | |
11621 | ||
11622 | void | |
11623 | store_parm_decls () | |
11624 | { | |
11625 | register tree fndecl = current_function_decl; | |
11626 | register tree parm; | |
11627 | int parms_have_cleanups = 0; | |
eb66be0e | 11628 | tree cleanups = NULL_TREE; |
8d08fdba MS |
11629 | |
11630 | /* This is either a chain of PARM_DECLs (when a prototype is used). */ | |
11631 | tree specparms = current_function_parms; | |
11632 | ||
11633 | /* This is a list of types declared among parms in a prototype. */ | |
11634 | tree parmtags = current_function_parm_tags; | |
11635 | ||
11636 | /* This is a chain of any other decls that came in among the parm | |
11637 | declarations. If a parm is declared with enum {foo, bar} x; | |
11638 | then CONST_DECLs for foo and bar are put here. */ | |
11639 | tree nonparms = NULL_TREE; | |
11640 | ||
a9aedbc2 | 11641 | if (toplevel_bindings_p ()) |
8d08fdba MS |
11642 | fatal ("parse errors have confused me too much"); |
11643 | ||
11644 | /* Initialize RTL machinery. */ | |
11645 | init_function_start (fndecl, input_filename, lineno); | |
11646 | ||
11647 | /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ | |
11648 | declare_function_name (); | |
11649 | ||
11650 | /* Create a binding level for the parms. */ | |
11651 | expand_start_bindings (0); | |
11652 | ||
8d08fdba MS |
11653 | if (specparms != NULL_TREE) |
11654 | { | |
11655 | /* This case is when the function was defined with an ANSI prototype. | |
11656 | The parms already have decls, so we need not do anything here | |
11657 | except record them as in effect | |
11658 | and complain if any redundant old-style parm decls were written. */ | |
11659 | ||
11660 | register tree next; | |
11661 | ||
11662 | /* Must clear this because it might contain TYPE_DECLs declared | |
11663 | at class level. */ | |
11664 | storedecls (NULL_TREE); | |
5566b478 | 11665 | |
8d08fdba MS |
11666 | for (parm = nreverse (specparms); parm; parm = next) |
11667 | { | |
11668 | next = TREE_CHAIN (parm); | |
11669 | if (TREE_CODE (parm) == PARM_DECL) | |
11670 | { | |
5566b478 | 11671 | tree cleanup; |
8d08fdba MS |
11672 | if (DECL_NAME (parm) == NULL_TREE) |
11673 | { | |
8d08fdba | 11674 | pushdecl (parm); |
8d08fdba MS |
11675 | } |
11676 | else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) | |
11677 | cp_error ("parameter `%D' declared void", parm); | |
11678 | else | |
11679 | { | |
11680 | /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls. | |
11681 | A parameter is assumed not to have any side effects. | |
11682 | If this should change for any reason, then this | |
11683 | will have to wrap the bashed reference type in a save_expr. | |
11684 | ||
11685 | Also, if the parameter type is declared to be an X | |
11686 | and there is an X(X&) constructor, we cannot lay it | |
11687 | into the stack (any more), so we make this parameter | |
11688 | look like it is really of reference type. Functions | |
11689 | which pass parameters to this function will know to | |
11690 | create a temporary in their frame, and pass a reference | |
11691 | to that. */ | |
11692 | ||
11693 | if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE | |
11694 | && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm)))) | |
11695 | SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm)); | |
11696 | ||
11697 | pushdecl (parm); | |
11698 | } | |
5156628f | 11699 | if (! processing_template_decl |
5566b478 | 11700 | && (cleanup = maybe_build_cleanup (parm), cleanup)) |
8d08fdba MS |
11701 | { |
11702 | expand_decl (parm); | |
8d08fdba | 11703 | parms_have_cleanups = 1; |
eb66be0e MS |
11704 | |
11705 | /* Keep track of the cleanups. */ | |
11706 | cleanups = tree_cons (parm, cleanup, cleanups); | |
8d08fdba MS |
11707 | } |
11708 | } | |
11709 | else | |
11710 | { | |
11711 | /* If we find an enum constant or a type tag, | |
11712 | put it aside for the moment. */ | |
11713 | TREE_CHAIN (parm) = NULL_TREE; | |
11714 | nonparms = chainon (nonparms, parm); | |
11715 | } | |
11716 | } | |
11717 | ||
11718 | /* Get the decls in their original chain order | |
11719 | and record in the function. This is all and only the | |
11720 | PARM_DECLs that were pushed into scope by the loop above. */ | |
11721 | DECL_ARGUMENTS (fndecl) = getdecls (); | |
11722 | ||
11723 | storetags (chainon (parmtags, gettags ())); | |
11724 | } | |
11725 | else | |
11726 | DECL_ARGUMENTS (fndecl) = NULL_TREE; | |
11727 | ||
11728 | /* Now store the final chain of decls for the arguments | |
11729 | as the decl-chain of the current lexical scope. | |
11730 | Put the enumerators in as well, at the front so that | |
11731 | DECL_ARGUMENTS is not modified. */ | |
11732 | ||
11733 | storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); | |
11734 | ||
11735 | /* Initialize the RTL code for the function. */ | |
11736 | DECL_SAVED_INSNS (fndecl) = NULL_RTX; | |
5156628f | 11737 | if (! processing_template_decl) |
5566b478 | 11738 | expand_function_start (fndecl, parms_have_cleanups); |
8d08fdba | 11739 | |
eb448459 MS |
11740 | current_function_parms_stored = 1; |
11741 | ||
11742 | /* If this function is `main', emit a call to `__main' | |
11743 | to run global initializers, etc. */ | |
11744 | if (DECL_NAME (fndecl) | |
11745 | && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 | |
11746 | && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 | |
11747 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
11748 | { | |
11749 | expand_main_function (); | |
11750 | } | |
11751 | ||
eb66be0e MS |
11752 | /* Now that we have initialized the parms, we can start their |
11753 | cleanups. We cannot do this before, since expand_decl_cleanup | |
11754 | should not be called before the parm can be used. */ | |
eb448459 | 11755 | if (cleanups |
eb66be0e MS |
11756 | && ! processing_template_decl) |
11757 | { | |
11758 | for (cleanups = nreverse (cleanups); cleanups; cleanups = TREE_CHAIN (cleanups)) | |
11759 | { | |
11760 | if (! expand_decl_cleanup (TREE_PURPOSE (cleanups), TREE_VALUE (cleanups))) | |
11761 | cp_error ("parser lost in parsing declaration of `%D'", | |
11762 | TREE_PURPOSE (cleanups)); | |
11763 | } | |
11764 | } | |
11765 | ||
8d08fdba MS |
11766 | /* Create a binding contour which can be used to catch |
11767 | cleanup-generated temporaries. Also, if the return value needs or | |
11768 | has initialization, deal with that now. */ | |
11769 | if (parms_have_cleanups) | |
11770 | { | |
11771 | pushlevel (0); | |
11772 | expand_start_bindings (0); | |
11773 | } | |
11774 | ||
5156628f | 11775 | if (! processing_template_decl && flag_exceptions) |
f30432d7 | 11776 | { |
f30432d7 MS |
11777 | /* Do the starting of the exception specifications, if we have any. */ |
11778 | if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) | |
11779 | expand_start_eh_spec (); | |
f30432d7 | 11780 | } |
eb448459 | 11781 | |
5c825fc2 | 11782 | last_parm_cleanup_insn = get_last_insn (); |
72b7eeff | 11783 | last_dtor_insn = get_last_insn (); |
8d08fdba MS |
11784 | } |
11785 | ||
11786 | /* Bind a name and initialization to the return value of | |
11787 | the current function. */ | |
e92cc029 | 11788 | |
8d08fdba MS |
11789 | void |
11790 | store_return_init (return_id, init) | |
11791 | tree return_id, init; | |
11792 | { | |
11793 | tree decl = DECL_RESULT (current_function_decl); | |
11794 | ||
e1cd6e56 | 11795 | if (pedantic) |
8d08fdba MS |
11796 | /* Give this error as many times as there are occurrences, |
11797 | so that users can use Emacs compilation buffers to find | |
11798 | and fix all such places. */ | |
8926095f | 11799 | pedwarn ("ANSI C++ does not permit named return values"); |
8d08fdba MS |
11800 | |
11801 | if (return_id != NULL_TREE) | |
11802 | { | |
11803 | if (DECL_NAME (decl) == NULL_TREE) | |
11804 | { | |
11805 | DECL_NAME (decl) = return_id; | |
11806 | DECL_ASSEMBLER_NAME (decl) = return_id; | |
11807 | } | |
11808 | else | |
e76a2646 | 11809 | cp_error ("return identifier `%D' already in place", decl); |
8d08fdba MS |
11810 | } |
11811 | ||
11812 | /* Can't let this happen for constructors. */ | |
11813 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
11814 | { | |
11815 | error ("can't redefine default return value for constructors"); | |
11816 | return; | |
11817 | } | |
11818 | ||
11819 | /* If we have a named return value, put that in our scope as well. */ | |
11820 | if (DECL_NAME (decl) != NULL_TREE) | |
11821 | { | |
11822 | /* If this named return value comes in a register, | |
11823 | put it in a pseudo-register. */ | |
11824 | if (DECL_REGISTER (decl)) | |
11825 | { | |
11826 | original_result_rtx = DECL_RTL (decl); | |
11827 | DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); | |
11828 | } | |
11829 | ||
82580166 | 11830 | /* Let `cp_finish_decl' know that this initializer is ok. */ |
8d08fdba MS |
11831 | DECL_INITIAL (decl) = init; |
11832 | pushdecl (decl); | |
e76a2646 MS |
11833 | |
11834 | if (minimal_parse_mode) | |
11835 | add_tree (build_min_nt (RETURN_INIT, return_id, | |
11836 | copy_to_permanent (init))); | |
11837 | else | |
11838 | cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); | |
8d08fdba MS |
11839 | } |
11840 | } | |
11841 | ||
8d08fdba MS |
11842 | \f |
11843 | /* Finish up a function declaration and compile that function | |
11844 | all the way to assembler language output. The free the storage | |
11845 | for the function definition. | |
11846 | ||
11847 | This is called after parsing the body of the function definition. | |
11848 | LINENO is the current line number. | |
11849 | ||
11850 | C++: CALL_POPLEVEL is non-zero if an extra call to poplevel | |
11851 | (and expand_end_bindings) must be made to take care of the binding | |
11852 | contour for the base initializers. This is only relevant for | |
e92cc029 MS |
11853 | constructors. |
11854 | ||
11855 | NESTED is nonzero if we were in the middle of compiling another function | |
11856 | when we started on this one. */ | |
8d08fdba MS |
11857 | |
11858 | void | |
db5ae43f | 11859 | finish_function (lineno, call_poplevel, nested) |
8d08fdba MS |
11860 | int lineno; |
11861 | int call_poplevel; | |
db5ae43f | 11862 | int nested; |
8d08fdba MS |
11863 | { |
11864 | register tree fndecl = current_function_decl; | |
11865 | tree fntype, ctype = NULL_TREE; | |
f30432d7 | 11866 | rtx last_parm_insn, insns; |
8d08fdba MS |
11867 | /* Label to use if this function is supposed to return a value. */ |
11868 | tree no_return_label = NULL_TREE; | |
11869 | tree decls = NULL_TREE; | |
11870 | ||
11871 | /* When we get some parse errors, we can end up without a | |
11872 | current_function_decl, so cope. */ | |
11873 | if (fndecl == NULL_TREE) | |
11874 | return; | |
11875 | ||
e92cc029 MS |
11876 | if (! nested && function_depth > 1) |
11877 | nested = 1; | |
11878 | ||
8d08fdba MS |
11879 | fntype = TREE_TYPE (fndecl); |
11880 | ||
11881 | /* TREE_READONLY (fndecl) = 1; | |
11882 | This caused &foo to be of type ptr-to-const-function | |
11883 | which then got a warning when stored in a ptr-to-function variable. */ | |
11884 | ||
11885 | /* This happens on strange parse errors. */ | |
11886 | if (! current_function_parms_stored) | |
11887 | { | |
11888 | call_poplevel = 0; | |
11889 | store_parm_decls (); | |
11890 | } | |
11891 | ||
5156628f | 11892 | if (processing_template_decl) |
8d08fdba | 11893 | { |
5566b478 MS |
11894 | if (DECL_CONSTRUCTOR_P (fndecl) && call_poplevel) |
11895 | { | |
11896 | decls = getdecls (); | |
11897 | expand_end_bindings (decls, decls != NULL_TREE, 0); | |
11898 | poplevel (decls != NULL_TREE, 0, 0); | |
11899 | } | |
11900 | } | |
11901 | else | |
11902 | { | |
11903 | if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/) | |
8d08fdba | 11904 | { |
5566b478 MS |
11905 | tree ttype = target_type (fntype); |
11906 | tree parmdecl; | |
11907 | ||
8d08fdba MS |
11908 | if (IS_AGGR_TYPE (ttype)) |
11909 | /* Let debugger know it should output info for this type. */ | |
11910 | note_debug_info_needed (ttype); | |
5566b478 MS |
11911 | |
11912 | for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) | |
11913 | { | |
11914 | ttype = target_type (TREE_TYPE (parmdecl)); | |
11915 | if (IS_AGGR_TYPE (ttype)) | |
11916 | /* Let debugger know it should output info for this type. */ | |
11917 | note_debug_info_needed (ttype); | |
11918 | } | |
8d08fdba | 11919 | } |
8d08fdba | 11920 | |
5566b478 MS |
11921 | /* Clean house because we will need to reorder insns here. */ |
11922 | do_pending_stack_adjust (); | |
8d08fdba | 11923 | |
5566b478 | 11924 | if (dtor_label) |
8d08fdba | 11925 | { |
5566b478 MS |
11926 | tree binfo = TYPE_BINFO (current_class_type); |
11927 | tree cond = integer_one_node; | |
11928 | tree exprstmt; | |
11929 | tree in_charge_node = lookup_name (in_charge_identifier, 0); | |
11930 | tree virtual_size; | |
11931 | int ok_to_optimize_dtor = 0; | |
11932 | int empty_dtor = get_last_insn () == last_dtor_insn; | |
8d08fdba | 11933 | |
5566b478 MS |
11934 | if (current_function_assigns_this) |
11935 | cond = build (NE_EXPR, boolean_type_node, | |
4ac14744 | 11936 | current_class_ptr, integer_zero_node); |
5566b478 MS |
11937 | else |
11938 | { | |
11939 | int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); | |
11940 | ||
11941 | /* If this destructor is empty, then we don't need to check | |
11942 | whether `this' is NULL in some cases. */ | |
11943 | if ((flag_this_is_variable & 1) == 0) | |
11944 | ok_to_optimize_dtor = 1; | |
11945 | else if (empty_dtor) | |
11946 | ok_to_optimize_dtor | |
11947 | = (n_baseclasses == 0 | |
11948 | || (n_baseclasses == 1 | |
11949 | && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); | |
11950 | } | |
8d08fdba | 11951 | |
5566b478 MS |
11952 | /* These initializations might go inline. Protect |
11953 | the binding level of the parms. */ | |
11954 | pushlevel (0); | |
11955 | expand_start_bindings (0); | |
8d08fdba | 11956 | |
5566b478 MS |
11957 | if (current_function_assigns_this) |
11958 | { | |
11959 | current_function_assigns_this = 0; | |
11960 | current_function_just_assigned_this = 0; | |
11961 | } | |
8d08fdba | 11962 | |
5566b478 MS |
11963 | /* Generate the code to call destructor on base class. |
11964 | If this destructor belongs to a class with virtual | |
11965 | functions, then set the virtual function table | |
11966 | pointer to represent the type of our base class. */ | |
8d08fdba | 11967 | |
5566b478 MS |
11968 | /* This side-effect makes call to `build_delete' generate the |
11969 | code we have to have at the end of this destructor. */ | |
11970 | TYPE_HAS_DESTRUCTOR (current_class_type) = 0; | |
8d08fdba | 11971 | |
5566b478 MS |
11972 | /* These are two cases where we cannot delegate deletion. */ |
11973 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) | |
11974 | || TYPE_GETS_REG_DELETE (current_class_type)) | |
4ac14744 | 11975 | exprstmt = build_delete (current_class_type, current_class_ref, integer_zero_node, |
e92cc029 | 11976 | LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); |
5566b478 | 11977 | else |
4ac14744 | 11978 | exprstmt = build_delete (current_class_type, current_class_ref, in_charge_node, |
e92cc029 | 11979 | LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); |
5566b478 MS |
11980 | |
11981 | /* If we did not assign to this, then `this' is non-zero at | |
11982 | the end of a destructor. As a special optimization, don't | |
11983 | emit test if this is an empty destructor. If it does nothing, | |
11984 | it does nothing. If it calls a base destructor, the base | |
11985 | destructor will perform the test. */ | |
11986 | ||
11987 | if (exprstmt != error_mark_node | |
11988 | && (TREE_CODE (exprstmt) != NOP_EXPR | |
11989 | || TREE_OPERAND (exprstmt, 0) != integer_zero_node | |
11990 | || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) | |
8d08fdba | 11991 | { |
5566b478 MS |
11992 | expand_label (dtor_label); |
11993 | if (cond != integer_one_node) | |
11994 | expand_start_cond (cond, 0); | |
11995 | if (exprstmt != void_zero_node) | |
11996 | /* Don't call `expand_expr_stmt' if we're not going to do | |
11997 | anything, since -Wall will give a diagnostic. */ | |
11998 | expand_expr_stmt (exprstmt); | |
11999 | ||
12000 | /* Run destructor on all virtual baseclasses. */ | |
12001 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) | |
8d08fdba | 12002 | { |
5566b478 MS |
12003 | tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); |
12004 | expand_start_cond (build (BIT_AND_EXPR, integer_type_node, | |
12005 | in_charge_node, integer_two_node), 0); | |
12006 | while (vbases) | |
8d08fdba | 12007 | { |
5566b478 MS |
12008 | if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) |
12009 | { | |
bd6dd845 MS |
12010 | tree vb = get_vbase |
12011 | (BINFO_TYPE (vbases), | |
12012 | TYPE_BINFO (current_class_type)); | |
e92cc029 | 12013 | expand_expr_stmt |
bd6dd845 MS |
12014 | (build_scoped_method_call |
12015 | (current_class_ref, vb, dtor_identifier, | |
12016 | build_tree_list (NULL_TREE, integer_zero_node))); | |
5566b478 MS |
12017 | } |
12018 | vbases = TREE_CHAIN (vbases); | |
8d08fdba | 12019 | } |
5566b478 | 12020 | expand_end_cond (); |
8d08fdba | 12021 | } |
5566b478 MS |
12022 | |
12023 | do_pending_stack_adjust (); | |
12024 | if (cond != integer_one_node) | |
12025 | expand_end_cond (); | |
8d08fdba MS |
12026 | } |
12027 | ||
5566b478 MS |
12028 | TYPE_HAS_DESTRUCTOR (current_class_type) = 1; |
12029 | ||
12030 | virtual_size = c_sizeof (current_class_type); | |
12031 | ||
12032 | /* At the end, call delete if that's what's requested. */ | |
12033 | if (TYPE_GETS_REG_DELETE (current_class_type)) | |
12034 | /* This NOP_EXPR means we are in a static call context. */ | |
beb53fb8 JM |
12035 | exprstmt |
12036 | = build_method_call (build_indirect_ref (build1 (NOP_EXPR, | |
12037 | build_pointer_type (current_class_type), | |
12038 | error_mark_node), | |
12039 | NULL_PTR), | |
12040 | ansi_opname[(int) DELETE_EXPR], | |
12041 | tree_cons (NULL_TREE, current_class_ptr, | |
12042 | build_tree_list (NULL_TREE, virtual_size)), | |
12043 | NULL_TREE, LOOKUP_NORMAL); | |
5566b478 | 12044 | else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) |
4ac14744 | 12045 | exprstmt = build_x_delete (ptr_type_node, current_class_ptr, 0, |
5566b478 MS |
12046 | virtual_size); |
12047 | else | |
12048 | exprstmt = NULL_TREE; | |
8d08fdba | 12049 | |
5566b478 MS |
12050 | if (exprstmt) |
12051 | { | |
12052 | cond = build (BIT_AND_EXPR, integer_type_node, | |
12053 | in_charge_node, integer_one_node); | |
12054 | expand_start_cond (cond, 0); | |
12055 | expand_expr_stmt (exprstmt); | |
12056 | expand_end_cond (); | |
12057 | } | |
8d08fdba | 12058 | |
5566b478 | 12059 | /* End of destructor. */ |
fc378698 | 12060 | expand_end_bindings (NULL_TREE, getdecls () != NULL_TREE, 0); |
5566b478 MS |
12061 | poplevel (2, 0, 0); /* XXX change to 1 */ |
12062 | ||
12063 | /* Back to the top of destructor. */ | |
12064 | /* Dont execute destructor code if `this' is NULL. */ | |
12065 | ||
12066 | start_sequence (); | |
12067 | ||
12068 | /* If the dtor is empty, and we know there is not possible way we | |
12069 | could use any vtable entries, before they are possibly set by | |
12070 | a base class dtor, we don't have to setup the vtables, as we | |
12071 | know that any base class dtoring will set up any vtables it | |
12072 | needs. We avoid MI, because one base class dtor can do a | |
12073 | virtual dispatch to an overridden function that would need to | |
12074 | have a non-related vtable set up, we cannot avoid setting up | |
12075 | vtables in that case. We could change this to see if there is | |
12076 | just one vtable. */ | |
12077 | if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type)) | |
12078 | { | |
12079 | /* Make all virtual function table pointers in non-virtual base | |
12080 | classes point to CURRENT_CLASS_TYPE's virtual function | |
12081 | tables. */ | |
4ac14744 | 12082 | expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr); |
8d08fdba | 12083 | |
5566b478 | 12084 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) |
4ac14744 | 12085 | expand_indirect_vtbls_init (binfo, current_class_ref, current_class_ptr); |
5566b478 MS |
12086 | } |
12087 | ||
12088 | if (! ok_to_optimize_dtor) | |
12089 | { | |
12090 | cond = build_binary_op (NE_EXPR, | |
4ac14744 | 12091 | current_class_ptr, integer_zero_node, 1); |
5566b478 MS |
12092 | expand_start_cond (cond, 0); |
12093 | } | |
8d08fdba | 12094 | |
5566b478 MS |
12095 | insns = get_insns (); |
12096 | end_sequence (); | |
f30432d7 | 12097 | |
5566b478 MS |
12098 | last_parm_insn = get_first_nonparm_insn (); |
12099 | if (last_parm_insn == NULL_RTX) | |
12100 | last_parm_insn = get_last_insn (); | |
12101 | else | |
12102 | last_parm_insn = previous_insn (last_parm_insn); | |
8d08fdba | 12103 | |
5566b478 | 12104 | emit_insns_after (insns, last_parm_insn); |
72b7eeff | 12105 | |
5566b478 MS |
12106 | if (! ok_to_optimize_dtor) |
12107 | expand_end_cond (); | |
72b7eeff | 12108 | } |
5566b478 | 12109 | else if (current_function_assigns_this) |
8d08fdba | 12110 | { |
5566b478 MS |
12111 | /* Does not need to call emit_base_init, because |
12112 | that is done (if needed) just after assignment to this | |
12113 | is seen. */ | |
12114 | ||
12115 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
12116 | { | |
12117 | end_protect_partials (); | |
12118 | expand_label (ctor_label); | |
12119 | ctor_label = NULL_TREE; | |
12120 | ||
12121 | if (call_poplevel) | |
12122 | { | |
12123 | decls = getdecls (); | |
12124 | expand_end_bindings (decls, decls != NULL_TREE, 0); | |
12125 | poplevel (decls != NULL_TREE, 0, 0); | |
12126 | } | |
4ac14744 | 12127 | c_expand_return (current_class_ptr); |
5566b478 MS |
12128 | } |
12129 | else if (TYPE_MAIN_VARIANT (TREE_TYPE ( | |
12130 | DECL_RESULT (current_function_decl))) != void_type_node | |
12131 | && return_label != NULL_RTX) | |
12132 | no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
12133 | ||
12134 | current_function_assigns_this = 0; | |
12135 | current_function_just_assigned_this = 0; | |
12136 | base_init_expr = NULL_TREE; | |
8d08fdba | 12137 | } |
5566b478 MS |
12138 | else if (DECL_CONSTRUCTOR_P (fndecl)) |
12139 | { | |
12140 | tree cond, thenclause; | |
12141 | /* Allow constructor for a type to get a new instance of the object | |
12142 | using `build_new'. */ | |
12143 | tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); | |
12144 | CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; | |
f30432d7 | 12145 | |
5566b478 | 12146 | DECL_RETURNS_FIRST_ARG (fndecl) = 1; |
f30432d7 | 12147 | |
5566b478 MS |
12148 | if (flag_this_is_variable > 0) |
12149 | { | |
12150 | cond = build_binary_op (EQ_EXPR, | |
4ac14744 MS |
12151 | current_class_ptr, integer_zero_node, 1); |
12152 | thenclause = build_modify_expr (current_class_ptr, NOP_EXPR, | |
5566b478 MS |
12153 | build_new (NULL_TREE, current_class_type, void_type_node, 0)); |
12154 | } | |
f30432d7 | 12155 | |
5566b478 | 12156 | CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; |
f30432d7 | 12157 | |
5566b478 MS |
12158 | start_sequence (); |
12159 | ||
12160 | if (flag_this_is_variable > 0) | |
12161 | { | |
12162 | expand_start_cond (cond, 0); | |
12163 | expand_expr_stmt (thenclause); | |
12164 | expand_end_cond (); | |
12165 | } | |
12166 | ||
12167 | /* Emit insns from `emit_base_init' which sets up virtual | |
12168 | function table pointer(s). */ | |
12169 | if (base_init_expr) | |
12170 | { | |
12171 | expand_expr_stmt (base_init_expr); | |
12172 | base_init_expr = NULL_TREE; | |
12173 | } | |
12174 | ||
12175 | insns = get_insns (); | |
12176 | end_sequence (); | |
12177 | ||
b87692e5 | 12178 | /* This is where the body of the constructor begins. */ |
5566b478 | 12179 | |
b87692e5 | 12180 | emit_insns_after (insns, last_parm_cleanup_insn); |
8d08fdba | 12181 | |
b7484fbe | 12182 | end_protect_partials (); |
5566b478 MS |
12183 | |
12184 | /* This is where the body of the constructor ends. */ | |
8d08fdba MS |
12185 | expand_label (ctor_label); |
12186 | ctor_label = NULL_TREE; | |
12187 | ||
12188 | if (call_poplevel) | |
12189 | { | |
12190 | decls = getdecls (); | |
8d08fdba | 12191 | expand_end_bindings (decls, decls != NULL_TREE, 0); |
5566b478 | 12192 | poplevel (decls != NULL_TREE, 1, 0); |
8d08fdba | 12193 | } |
8d08fdba | 12194 | |
4ac14744 | 12195 | c_expand_return (current_class_ptr); |
8d08fdba | 12196 | |
5566b478 MS |
12197 | current_function_assigns_this = 0; |
12198 | current_function_just_assigned_this = 0; | |
12199 | } | |
12200 | else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 | |
12201 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") | |
12202 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
8d08fdba | 12203 | { |
5566b478 MS |
12204 | /* Make it so that `main' always returns 0 by default. */ |
12205 | #ifdef VMS | |
12206 | c_expand_return (integer_one_node); | |
12207 | #else | |
12208 | c_expand_return (integer_zero_node); | |
12209 | #endif | |
8d08fdba | 12210 | } |
5566b478 MS |
12211 | else if (return_label != NULL_RTX |
12212 | && current_function_return_value == NULL_TREE | |
12213 | && ! DECL_NAME (DECL_RESULT (current_function_decl))) | |
12214 | no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
8d08fdba | 12215 | |
eb448459 MS |
12216 | if (flag_exceptions) |
12217 | expand_exception_blocks (); | |
12218 | ||
5566b478 MS |
12219 | /* If this function is supposed to return a value, ensure that |
12220 | we do not fall into the cleanups by mistake. The end of our | |
12221 | function will look like this: | |
12222 | ||
12223 | user code (may have return stmt somewhere) | |
12224 | goto no_return_label | |
12225 | cleanup_label: | |
12226 | cleanups | |
12227 | goto return_label | |
12228 | no_return_label: | |
12229 | NOTE_INSN_FUNCTION_END | |
12230 | return_label: | |
12231 | things for return | |
12232 | ||
12233 | If the user omits a return stmt in the USER CODE section, we | |
12234 | will have a control path which reaches NOTE_INSN_FUNCTION_END. | |
12235 | Otherwise, we won't. */ | |
12236 | if (no_return_label) | |
8d08fdba | 12237 | { |
5566b478 MS |
12238 | DECL_CONTEXT (no_return_label) = fndecl; |
12239 | DECL_INITIAL (no_return_label) = error_mark_node; | |
12240 | DECL_SOURCE_FILE (no_return_label) = input_filename; | |
12241 | DECL_SOURCE_LINE (no_return_label) = lineno; | |
12242 | expand_goto (no_return_label); | |
8d08fdba MS |
12243 | } |
12244 | ||
5566b478 | 12245 | if (cleanup_label) |
a9aedbc2 | 12246 | { |
5566b478 MS |
12247 | /* remove the binding contour which is used |
12248 | to catch cleanup-generated temporaries. */ | |
12249 | expand_end_bindings (0, 0, 0); | |
12250 | poplevel (0, 0, 0); | |
8d08fdba | 12251 | |
eb448459 MS |
12252 | /* Emit label at beginning of cleanup code for parameters. */ |
12253 | emit_label (cleanup_label); | |
12254 | } | |
b7484fbe | 12255 | |
5566b478 MS |
12256 | /* Get return value into register if that's where it's supposed to be. */ |
12257 | if (original_result_rtx) | |
12258 | fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); | |
8d08fdba | 12259 | |
5566b478 MS |
12260 | /* Finish building code that will trigger warnings if users forget |
12261 | to make their functions return values. */ | |
12262 | if (no_return_label || cleanup_label) | |
12263 | emit_jump (return_label); | |
12264 | if (no_return_label) | |
8d08fdba | 12265 | { |
5566b478 MS |
12266 | /* We don't need to call `expand_*_return' here because we |
12267 | don't need any cleanups here--this path of code is only | |
12268 | for error checking purposes. */ | |
12269 | expand_label (no_return_label); | |
8d08fdba MS |
12270 | } |
12271 | ||
5566b478 MS |
12272 | /* Generate rtl for function exit. */ |
12273 | expand_function_end (input_filename, lineno, 1); | |
8d08fdba | 12274 | } |
8d2733ca | 12275 | |
8d08fdba MS |
12276 | /* This must come after expand_function_end because cleanups might |
12277 | have declarations (from inline functions) that need to go into | |
12278 | this function's blocks. */ | |
12279 | if (current_binding_level->parm_flag != 1) | |
12280 | my_friendly_abort (122); | |
12281 | poplevel (1, 0, 1); | |
12282 | ||
db5ae43f MS |
12283 | /* reset scope for C++: if we were in the scope of a class, |
12284 | then when we finish this function, we are not longer so. | |
12285 | This cannot be done until we know for sure that no more | |
12286 | class members will ever be referenced in this function | |
12287 | (i.e., calls to destructors). */ | |
12288 | if (current_class_name) | |
12289 | { | |
12290 | ctype = current_class_type; | |
12291 | pop_nested_class (1); | |
12292 | } | |
12293 | else | |
12294 | pop_memoized_context (1); | |
12295 | ||
8d08fdba | 12296 | /* Must mark the RESULT_DECL as being in this function. */ |
c73964b2 | 12297 | DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; |
8d08fdba | 12298 | |
8d08fdba MS |
12299 | /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point |
12300 | to the FUNCTION_DECL node itself. */ | |
12301 | BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; | |
12302 | ||
5156628f | 12303 | if (! processing_template_decl) |
5566b478 MS |
12304 | { |
12305 | /* So we can tell if jump_optimize sets it to 1. */ | |
12306 | can_reach_end = 0; | |
8d08fdba | 12307 | |
6633d636 MS |
12308 | /* Run the optimizers and output the assembler code for this |
12309 | function. */ | |
12310 | ||
12311 | if (DECL_ARTIFICIAL (fndecl)) | |
12312 | { | |
12313 | /* Do we really *want* to inline this synthesized method? */ | |
12314 | ||
12315 | int save_fif = flag_inline_functions; | |
12316 | flag_inline_functions = 1; | |
12317 | ||
12318 | /* Turn off DECL_INLINE for the moment so function_cannot_inline_p | |
12319 | will check our size. */ | |
12320 | DECL_INLINE (fndecl) = 0; | |
12321 | ||
12322 | rest_of_compilation (fndecl); | |
12323 | flag_inline_functions = save_fif; | |
12324 | } | |
12325 | else | |
12326 | rest_of_compilation (fndecl); | |
8d08fdba | 12327 | |
5566b478 MS |
12328 | if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl)) |
12329 | { | |
12330 | /* Set DECL_EXTERNAL so that assemble_external will be called as | |
12331 | necessary. We'll clear it again in finish_file. */ | |
12332 | if (! DECL_EXTERNAL (fndecl)) | |
12333 | DECL_NOT_REALLY_EXTERN (fndecl) = 1; | |
12334 | DECL_EXTERNAL (fndecl) = 1; | |
12335 | mark_inline_for_output (fndecl); | |
12336 | } | |
8926095f | 12337 | |
d2e5ee5c MS |
12338 | if (ctype && TREE_ASM_WRITTEN (fndecl)) |
12339 | note_debug_info_needed (ctype); | |
12340 | ||
5566b478 | 12341 | current_function_returns_null |= can_reach_end; |
8d08fdba | 12342 | |
5566b478 MS |
12343 | /* Since we don't normally go through c_expand_return for constructors, |
12344 | this normally gets the wrong value. | |
12345 | Also, named return values have their return codes emitted after | |
12346 | NOTE_INSN_FUNCTION_END, confusing jump.c. */ | |
12347 | if (DECL_CONSTRUCTOR_P (fndecl) | |
12348 | || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) | |
12349 | current_function_returns_null = 0; | |
8d08fdba | 12350 | |
5566b478 MS |
12351 | if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) |
12352 | cp_warning ("`noreturn' function `%D' does return", fndecl); | |
12353 | else if ((warn_return_type || pedantic) | |
12354 | && current_function_returns_null | |
12355 | && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node) | |
12356 | { | |
12357 | /* If this function returns non-void and control can drop through, | |
12358 | complain. */ | |
238109cd | 12359 | cp_warning ("control reaches end of non-void function `%D'", fndecl); |
5566b478 MS |
12360 | } |
12361 | /* With just -W, complain only if function returns both with | |
12362 | and without a value. */ | |
12363 | else if (extra_warnings | |
12364 | && current_function_returns_value && current_function_returns_null) | |
12365 | warning ("this function may return with or without a value"); | |
8d08fdba | 12366 | } |
5566b478 MS |
12367 | |
12368 | --function_depth; | |
8d08fdba MS |
12369 | |
12370 | /* Free all the tree nodes making up this function. */ | |
12371 | /* Switch back to allocating nodes permanently | |
12372 | until we start another function. */ | |
5156628f | 12373 | if (processing_template_decl) |
5566b478 MS |
12374 | { |
12375 | --minimal_parse_mode; | |
12376 | DECL_SAVED_TREE (fndecl) = TREE_CHAIN (DECL_SAVED_TREE (fndecl)); | |
12377 | } | |
12378 | ||
db5ae43f MS |
12379 | if (! nested) |
12380 | permanent_allocation (1); | |
8d08fdba | 12381 | |
8d08fdba MS |
12382 | if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) |
12383 | { | |
d2e5ee5c MS |
12384 | tree t; |
12385 | ||
8d08fdba MS |
12386 | /* Stop pointing to the local nodes about to be freed. */ |
12387 | /* But DECL_INITIAL must remain nonzero so we know this | |
12388 | was an actual function definition. */ | |
12389 | DECL_INITIAL (fndecl) = error_mark_node; | |
d2e5ee5c | 12390 | for (t = DECL_ARGUMENTS (fndecl); t; t = TREE_CHAIN (t)) |
de22184b | 12391 | DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX; |
8d08fdba MS |
12392 | } |
12393 | ||
e1cd6e56 MS |
12394 | if (DECL_STATIC_CONSTRUCTOR (fndecl)) |
12395 | static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors); | |
12396 | if (DECL_STATIC_DESTRUCTOR (fndecl)) | |
12397 | static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors); | |
12398 | ||
28cbf42c MS |
12399 | if (! nested) |
12400 | { | |
12401 | /* Let the error reporting routines know that we're outside a | |
12402 | function. For a nested function, this value is used in | |
12403 | pop_cp_function_context and then reset via pop_function_context. */ | |
12404 | current_function_decl = NULL_TREE; | |
12405 | } | |
12406 | ||
e349ee73 | 12407 | named_label_uses = NULL; |
4ac14744 MS |
12408 | current_class_ptr = NULL_TREE; |
12409 | current_class_ref = NULL_TREE; | |
8d08fdba MS |
12410 | } |
12411 | \f | |
12412 | /* Create the FUNCTION_DECL for a function definition. | |
12413 | LINE1 is the line number that the definition absolutely begins on. | |
12414 | LINE2 is the line number that the name of the function appears on. | |
12415 | DECLSPECS and DECLARATOR are the parts of the declaration; | |
12416 | they describe the return type and the name of the function, | |
12417 | but twisted together in a fashion that parallels the syntax of C. | |
12418 | ||
12419 | This function creates a binding context for the function body | |
12420 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
12421 | ||
12422 | Returns a FUNCTION_DECL on success. | |
12423 | ||
12424 | If the DECLARATOR is not suitable for a function (it defines a datum | |
12425 | instead), we return 0, which tells yyparse to report a parse error. | |
12426 | ||
12427 | May return void_type_node indicating that this method is actually | |
12428 | a friend. See grokfield for more details. | |
12429 | ||
12430 | Came here with a `.pushlevel' . | |
12431 | ||
12432 | DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING | |
12433 | CHANGES TO CODE IN `grokfield'. */ | |
e92cc029 | 12434 | |
8d08fdba | 12435 | tree |
c11b6f21 MS |
12436 | start_method (declspecs, declarator) |
12437 | tree declarator, declspecs; | |
8d08fdba | 12438 | { |
c11b6f21 | 12439 | tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, |
f30432d7 | 12440 | NULL_TREE); |
8d08fdba MS |
12441 | |
12442 | /* Something too ugly to handle. */ | |
12443 | if (fndecl == NULL_TREE) | |
12444 | return NULL_TREE; | |
12445 | ||
12446 | /* Pass friends other than inline friend functions back. */ | |
12447 | if (TYPE_MAIN_VARIANT (fndecl) == void_type_node) | |
12448 | return fndecl; | |
12449 | ||
12450 | if (TREE_CODE (fndecl) != FUNCTION_DECL) | |
12451 | /* Not a function, tell parser to report parse error. */ | |
12452 | return NULL_TREE; | |
12453 | ||
12454 | if (IS_SIGNATURE (current_class_type)) | |
824b9a4c | 12455 | IS_DEFAULT_IMPLEMENTATION (fndecl) = 1; |
8d08fdba MS |
12456 | |
12457 | if (DECL_IN_AGGR_P (fndecl)) | |
12458 | { | |
12459 | if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) | |
12460 | { | |
12461 | if (DECL_CONTEXT (fndecl)) | |
12462 | cp_error ("`%D' is already defined in class %s", fndecl, | |
12463 | TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); | |
12464 | } | |
12465 | return void_type_node; | |
12466 | } | |
12467 | ||
faae18ab MS |
12468 | DECL_THIS_INLINE (fndecl) = 1; |
12469 | ||
8926095f | 12470 | if (flag_default_inline) |
8d08fdba MS |
12471 | DECL_INLINE (fndecl) = 1; |
12472 | ||
5156628f | 12473 | if (processing_template_decl && ! current_function_decl) |
5566b478 | 12474 | push_template_decl (fndecl); |
a0a33927 | 12475 | |
8d08fdba MS |
12476 | /* We read in the parameters on the maybepermanent_obstack, |
12477 | but we won't be getting back to them until after we | |
12478 | may have clobbered them. So the call to preserve_data | |
12479 | will keep them safe. */ | |
12480 | preserve_data (); | |
12481 | ||
12482 | if (! DECL_FRIEND_P (fndecl)) | |
12483 | { | |
12484 | if (DECL_CHAIN (fndecl) != NULL_TREE) | |
12485 | { | |
12486 | /* Need a fresh node here so that we don't get circularity | |
12487 | when we link these together. If FNDECL was a friend, then | |
12488 | `pushdecl' does the right thing, which is nothing wrt its | |
12489 | current value of DECL_CHAIN. */ | |
12490 | fndecl = copy_node (fndecl); | |
12491 | } | |
12492 | if (TREE_CHAIN (fndecl)) | |
12493 | { | |
12494 | fndecl = copy_node (fndecl); | |
12495 | TREE_CHAIN (fndecl) = NULL_TREE; | |
12496 | } | |
12497 | ||
12498 | if (DECL_CONSTRUCTOR_P (fndecl)) | |
a0a33927 MS |
12499 | { |
12500 | if (! grok_ctor_properties (current_class_type, fndecl)) | |
12501 | return void_type_node; | |
12502 | } | |
8d08fdba MS |
12503 | else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) |
12504 | grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0); | |
12505 | } | |
12506 | ||
82580166 | 12507 | cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0); |
8d08fdba MS |
12508 | |
12509 | /* Make a place for the parms */ | |
12510 | pushlevel (0); | |
12511 | current_binding_level->parm_flag = 1; | |
12512 | ||
12513 | DECL_IN_AGGR_P (fndecl) = 1; | |
12514 | return fndecl; | |
12515 | } | |
12516 | ||
12517 | /* Go through the motions of finishing a function definition. | |
12518 | We don't compile this method until after the whole class has | |
12519 | been processed. | |
12520 | ||
12521 | FINISH_METHOD must return something that looks as though it | |
12522 | came from GROKFIELD (since we are defining a method, after all). | |
12523 | ||
12524 | This is called after parsing the body of the function definition. | |
12525 | STMTS is the chain of statements that makes up the function body. | |
12526 | ||
12527 | DECL is the ..._DECL that `start_method' provided. */ | |
12528 | ||
12529 | tree | |
12530 | finish_method (decl) | |
12531 | tree decl; | |
12532 | { | |
12533 | register tree fndecl = decl; | |
12534 | tree old_initial; | |
8d08fdba MS |
12535 | |
12536 | register tree link; | |
12537 | ||
12538 | if (TYPE_MAIN_VARIANT (decl) == void_type_node) | |
12539 | return decl; | |
12540 | ||
12541 | old_initial = DECL_INITIAL (fndecl); | |
12542 | ||
12543 | /* Undo the level for the parms (from start_method). | |
12544 | This is like poplevel, but it causes nothing to be | |
12545 | saved. Saving information here confuses symbol-table | |
12546 | output routines. Besides, this information will | |
12547 | be correctly output when this method is actually | |
12548 | compiled. */ | |
12549 | ||
12550 | /* Clear out the meanings of the local variables of this level; | |
12551 | also record in each decl which block it belongs to. */ | |
12552 | ||
12553 | for (link = current_binding_level->names; link; link = TREE_CHAIN (link)) | |
12554 | { | |
12555 | if (DECL_NAME (link) != NULL_TREE) | |
12556 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; | |
12557 | my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163); | |
12558 | DECL_CONTEXT (link) = NULL_TREE; | |
12559 | } | |
12560 | ||
12561 | /* Restore all name-meanings of the outer levels | |
12562 | that were shadowed by this level. */ | |
12563 | ||
12564 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
12565 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
12566 | for (link = current_binding_level->class_shadowed; | |
12567 | link; link = TREE_CHAIN (link)) | |
12568 | IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
12569 | for (link = current_binding_level->type_shadowed; | |
12570 | link; link = TREE_CHAIN (link)) | |
12571 | IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
12572 | ||
12573 | GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, | |
12574 | (HOST_WIDE_INT) current_binding_level->level_chain, | |
12575 | current_binding_level->parm_flag, | |
5566b478 | 12576 | current_binding_level->keep); |
8d08fdba MS |
12577 | |
12578 | poplevel (0, 0, 0); | |
12579 | ||
12580 | DECL_INITIAL (fndecl) = old_initial; | |
12581 | ||
12582 | /* We used to check if the context of FNDECL was different from | |
12583 | current_class_type as another way to get inside here. This didn't work | |
12584 | for String.cc in libg++. */ | |
12585 | if (DECL_FRIEND_P (fndecl)) | |
12586 | { | |
12587 | CLASSTYPE_INLINE_FRIENDS (current_class_type) | |
12588 | = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type)); | |
12589 | decl = void_type_node; | |
12590 | } | |
12591 | ||
12592 | return decl; | |
12593 | } | |
12594 | \f | |
12595 | /* Called when a new struct TYPE is defined. | |
12596 | If this structure or union completes the type of any previous | |
12597 | variable declaration, lay it out and output its rtl. */ | |
12598 | ||
12599 | void | |
12600 | hack_incomplete_structures (type) | |
12601 | tree type; | |
12602 | { | |
f30432d7 | 12603 | tree *list; |
8d08fdba | 12604 | |
f30432d7 | 12605 | if (current_binding_level->incomplete == NULL_TREE) |
8d08fdba MS |
12606 | return; |
12607 | ||
12608 | if (!type) /* Don't do this for class templates. */ | |
12609 | return; | |
12610 | ||
f30432d7 MS |
12611 | for (list = ¤t_binding_level->incomplete; *list; ) |
12612 | { | |
12613 | tree decl = TREE_VALUE (*list); | |
12614 | if (decl && TREE_TYPE (decl) == type | |
12615 | || (TREE_TYPE (decl) | |
12616 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
12617 | && TREE_TYPE (TREE_TYPE (decl)) == type)) | |
12618 | { | |
12619 | int toplevel = toplevel_bindings_p (); | |
12620 | if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
12621 | && TREE_TYPE (TREE_TYPE (decl)) == type) | |
12622 | layout_type (TREE_TYPE (decl)); | |
12623 | layout_decl (decl, 0); | |
12624 | rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); | |
12625 | if (! toplevel) | |
12626 | { | |
12627 | tree cleanup; | |
12628 | expand_decl (decl); | |
12629 | cleanup = maybe_build_cleanup (decl); | |
12630 | expand_decl_init (decl); | |
e349ee73 | 12631 | if (! expand_decl_cleanup (decl, cleanup)) |
f30432d7 MS |
12632 | cp_error ("parser lost in parsing declaration of `%D'", |
12633 | decl); | |
12634 | } | |
12635 | *list = TREE_CHAIN (*list); | |
12636 | } | |
12637 | else | |
12638 | list = &TREE_CHAIN (*list); | |
12639 | } | |
8d08fdba MS |
12640 | } |
12641 | ||
8d08fdba | 12642 | /* If DECL is of a type which needs a cleanup, build that cleanup here. |
c73964b2 | 12643 | See build_delete for information about AUTO_DELETE. |
8d08fdba MS |
12644 | |
12645 | Don't build these on the momentary obstack; they must live | |
12646 | the life of the binding contour. */ | |
e92cc029 | 12647 | |
c73964b2 MS |
12648 | static tree |
12649 | maybe_build_cleanup_1 (decl, auto_delete) | |
12650 | tree decl, auto_delete; | |
8d08fdba MS |
12651 | { |
12652 | tree type = TREE_TYPE (decl); | |
12653 | if (TYPE_NEEDS_DESTRUCTOR (type)) | |
12654 | { | |
12655 | int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; | |
12656 | tree rval; | |
8d08fdba MS |
12657 | |
12658 | if (TREE_CODE (decl) != PARM_DECL) | |
12659 | temp = suspend_momentary (); | |
12660 | ||
12661 | if (TREE_CODE (type) == ARRAY_TYPE) | |
12662 | rval = decl; | |
12663 | else | |
12664 | { | |
12665 | mark_addressable (decl); | |
12666 | rval = build_unary_op (ADDR_EXPR, decl, 0); | |
12667 | } | |
12668 | ||
12669 | /* Optimize for space over speed here. */ | |
12670 | if (! TYPE_USES_VIRTUAL_BASECLASSES (type) | |
12671 | || flag_expensive_optimizations) | |
12672 | flags |= LOOKUP_NONVIRTUAL; | |
12673 | ||
c73964b2 | 12674 | rval = build_delete (TREE_TYPE (rval), rval, auto_delete, flags, 0); |
8d08fdba MS |
12675 | |
12676 | if (TYPE_USES_VIRTUAL_BASECLASSES (type) | |
12677 | && ! TYPE_HAS_DESTRUCTOR (type)) | |
12678 | rval = build_compound_expr (tree_cons (NULL_TREE, rval, | |
12679 | build_tree_list (NULL_TREE, build_vbase_delete (type, decl)))); | |
12680 | ||
8d08fdba MS |
12681 | if (TREE_CODE (decl) != PARM_DECL) |
12682 | resume_momentary (temp); | |
12683 | ||
8d08fdba MS |
12684 | return rval; |
12685 | } | |
12686 | return 0; | |
12687 | } | |
c73964b2 MS |
12688 | |
12689 | /* If DECL is of a type which needs a cleanup, build that cleanup | |
12690 | here. The cleanup does free the storage with a call to delete. */ | |
12691 | ||
12692 | tree | |
12693 | maybe_build_cleanup_and_delete (decl) | |
12694 | tree decl; | |
12695 | { | |
12696 | return maybe_build_cleanup_1 (decl, integer_three_node); | |
12697 | } | |
12698 | ||
12699 | /* If DECL is of a type which needs a cleanup, build that cleanup | |
12700 | here. The cleanup does not free the storage with a call a delete. */ | |
12701 | ||
12702 | tree | |
12703 | maybe_build_cleanup (decl) | |
12704 | tree decl; | |
12705 | { | |
12706 | return maybe_build_cleanup_1 (decl, integer_two_node); | |
12707 | } | |
8d08fdba MS |
12708 | \f |
12709 | /* Expand a C++ expression at the statement level. | |
12710 | This is needed to ferret out nodes which have UNKNOWN_TYPE. | |
12711 | The C++ type checker should get all of these out when | |
12712 | expressions are combined with other, type-providing, expressions, | |
12713 | leaving only orphan expressions, such as: | |
12714 | ||
e92cc029 | 12715 | &class::bar; / / takes its address, but does nothing with it. */ |
8d08fdba | 12716 | |
8d08fdba MS |
12717 | void |
12718 | cplus_expand_expr_stmt (exp) | |
12719 | tree exp; | |
12720 | { | |
5156628f | 12721 | if (processing_template_decl) |
5566b478 MS |
12722 | { |
12723 | add_tree (build_min_nt (EXPR_STMT, exp)); | |
12724 | return; | |
12725 | } | |
12726 | ||
eb66be0e MS |
12727 | /* Arrange for all temps to disappear. */ |
12728 | expand_start_target_temps (); | |
12729 | ||
8d08fdba MS |
12730 | if (TREE_TYPE (exp) == unknown_type_node) |
12731 | { | |
12732 | if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST) | |
12733 | error ("address of overloaded function with no contextual type information"); | |
12734 | else if (TREE_CODE (exp) == COMPONENT_REF) | |
12735 | warning ("useless reference to a member function name, did you forget the ()?"); | |
12736 | } | |
12737 | else | |
12738 | { | |
8d08fdba MS |
12739 | if (TREE_CODE (exp) == FUNCTION_DECL) |
12740 | { | |
12741 | cp_warning ("reference, not call, to function `%D'", exp); | |
12742 | warning ("at this point in file"); | |
12743 | } | |
8d08fdba | 12744 | |
63c68bb7 MS |
12745 | #if 0 |
12746 | /* We should do this eventually, but right now this causes regex.o from | |
12747 | libg++ to miscompile, and tString to core dump. */ | |
5b605f68 | 12748 | exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp); |
63c68bb7 | 12749 | #endif |
d2e5ee5c MS |
12750 | /* If we don't do this, we end up down inside expand_expr |
12751 | trying to do TYPE_MODE on the ERROR_MARK, and really | |
12752 | go outside the bounds of the type. */ | |
12753 | if (exp != error_mark_node) | |
12754 | expand_expr_stmt (break_out_cleanups (exp)); | |
8d08fdba MS |
12755 | } |
12756 | ||
12757 | /* Clean up any pending cleanups. This happens when a function call | |
12758 | returns a cleanup-needing value that nobody uses. */ | |
eb66be0e | 12759 | expand_end_target_temps (); |
8d08fdba MS |
12760 | } |
12761 | ||
12762 | /* When a stmt has been parsed, this function is called. | |
12763 | ||
12764 | Currently, this function only does something within a | |
12765 | constructor's scope: if a stmt has just assigned to this, | |
12766 | and we are in a derived class, we call `emit_base_init'. */ | |
12767 | ||
12768 | void | |
12769 | finish_stmt () | |
12770 | { | |
12771 | extern struct nesting *cond_stack, *loop_stack, *case_stack; | |
12772 | ||
12773 | ||
12774 | if (current_function_assigns_this | |
12775 | || ! current_function_just_assigned_this) | |
12776 | return; | |
12777 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
12778 | { | |
12779 | /* Constructors must wait until we are out of control | |
12780 | zones before calling base constructors. */ | |
12781 | if (cond_stack || loop_stack || case_stack) | |
12782 | return; | |
a9aedbc2 | 12783 | expand_expr_stmt (base_init_expr); |
8d08fdba MS |
12784 | check_base_init (current_class_type); |
12785 | } | |
12786 | current_function_assigns_this = 1; | |
8d08fdba MS |
12787 | } |
12788 | ||
8d08fdba | 12789 | /* Change a static member function definition into a FUNCTION_TYPE, instead |
700f8a87 MS |
12790 | of the METHOD_TYPE that we create when it's originally parsed. |
12791 | ||
12792 | WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES | |
12793 | (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of | |
12794 | other decls. Either pass the addresses of local variables or NULL. */ | |
12795 | ||
bd6dd845 | 12796 | static void |
700f8a87 MS |
12797 | revert_static_member_fn (decl, fn, argtypes) |
12798 | tree *decl, *fn, *argtypes; | |
8d08fdba | 12799 | { |
700f8a87 MS |
12800 | tree tmp; |
12801 | tree function = fn ? *fn : TREE_TYPE (*decl); | |
12802 | tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function); | |
8d08fdba | 12803 | |
f30432d7 MS |
12804 | if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args)))) |
12805 | cp_error ("static member function `%#D' declared const", *decl); | |
12806 | if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args)))) | |
12807 | cp_error ("static member function `%#D' declared volatile", *decl); | |
12808 | ||
700f8a87 MS |
12809 | args = TREE_CHAIN (args); |
12810 | tmp = build_function_type (TREE_TYPE (function), args); | |
8d08fdba MS |
12811 | tmp = build_type_variant (tmp, TYPE_READONLY (function), |
12812 | TYPE_VOLATILE (function)); | |
f30432d7 | 12813 | tmp = build_exception_variant (tmp, |
8d08fdba MS |
12814 | TYPE_RAISES_EXCEPTIONS (function)); |
12815 | TREE_TYPE (*decl) = tmp; | |
f30432d7 MS |
12816 | if (DECL_ARGUMENTS (*decl)) |
12817 | DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl)); | |
8d08fdba | 12818 | DECL_STATIC_FUNCTION_P (*decl) = 1; |
700f8a87 MS |
12819 | if (fn) |
12820 | *fn = tmp; | |
12821 | if (argtypes) | |
12822 | *argtypes = args; | |
8d08fdba | 12823 | } |
a4443a08 MS |
12824 | |
12825 | int | |
12826 | id_in_current_class (id) | |
12827 | tree id; | |
12828 | { | |
12829 | return !!purpose_member (id, class_binding_level->class_shadowed); | |
12830 | } | |
db5ae43f MS |
12831 | |
12832 | struct cp_function | |
12833 | { | |
12834 | int returns_value; | |
12835 | int returns_null; | |
12836 | int warn_about_return_type; | |
db5ae43f MS |
12837 | int assigns_this; |
12838 | int just_assigned_this; | |
12839 | int parms_stored; | |
7215f9a0 | 12840 | int temp_name_counter; |
db5ae43f MS |
12841 | tree named_labels; |
12842 | tree shadowed_labels; | |
12843 | tree ctor_label; | |
12844 | tree dtor_label; | |
72b7eeff | 12845 | rtx last_dtor_insn; |
b87692e5 | 12846 | rtx last_parm_cleanup_insn; |
79ff2c6c MS |
12847 | tree base_init_list; |
12848 | tree member_init_list; | |
a9aedbc2 | 12849 | tree base_init_expr; |
4ac14744 MS |
12850 | tree current_class_ptr; |
12851 | tree current_class_ref; | |
db5ae43f MS |
12852 | rtx result_rtx; |
12853 | struct cp_function *next; | |
12854 | struct binding_level *binding_level; | |
42976354 | 12855 | int static_labelno; |
db5ae43f MS |
12856 | }; |
12857 | ||
bd6dd845 | 12858 | static struct cp_function *cp_function_chain; |
db5ae43f | 12859 | |
7215f9a0 MS |
12860 | extern int temp_name_counter; |
12861 | ||
db5ae43f MS |
12862 | /* Save and reinitialize the variables |
12863 | used during compilation of a C++ function. */ | |
12864 | ||
12865 | void | |
28cbf42c MS |
12866 | push_cp_function_context (context) |
12867 | tree context; | |
db5ae43f MS |
12868 | { |
12869 | struct cp_function *p | |
12870 | = (struct cp_function *) xmalloc (sizeof (struct cp_function)); | |
12871 | ||
28cbf42c | 12872 | push_function_context_to (context); |
db5ae43f MS |
12873 | |
12874 | p->next = cp_function_chain; | |
12875 | cp_function_chain = p; | |
12876 | ||
12877 | p->named_labels = named_labels; | |
12878 | p->shadowed_labels = shadowed_labels; | |
12879 | p->returns_value = current_function_returns_value; | |
12880 | p->returns_null = current_function_returns_null; | |
12881 | p->warn_about_return_type = warn_about_return_type; | |
db5ae43f MS |
12882 | p->binding_level = current_binding_level; |
12883 | p->ctor_label = ctor_label; | |
12884 | p->dtor_label = dtor_label; | |
72b7eeff | 12885 | p->last_dtor_insn = last_dtor_insn; |
b87692e5 | 12886 | p->last_parm_cleanup_insn = last_parm_cleanup_insn; |
db5ae43f MS |
12887 | p->assigns_this = current_function_assigns_this; |
12888 | p->just_assigned_this = current_function_just_assigned_this; | |
12889 | p->parms_stored = current_function_parms_stored; | |
12890 | p->result_rtx = original_result_rtx; | |
a9aedbc2 | 12891 | p->base_init_expr = base_init_expr; |
7215f9a0 | 12892 | p->temp_name_counter = temp_name_counter; |
79ff2c6c MS |
12893 | p->base_init_list = current_base_init_list; |
12894 | p->member_init_list = current_member_init_list; | |
4ac14744 MS |
12895 | p->current_class_ptr = current_class_ptr; |
12896 | p->current_class_ref = current_class_ref; | |
42976354 | 12897 | p->static_labelno = static_labelno; |
db5ae43f MS |
12898 | } |
12899 | ||
12900 | /* Restore the variables used during compilation of a C++ function. */ | |
12901 | ||
12902 | void | |
28cbf42c MS |
12903 | pop_cp_function_context (context) |
12904 | tree context; | |
db5ae43f MS |
12905 | { |
12906 | struct cp_function *p = cp_function_chain; | |
12907 | tree link; | |
12908 | ||
12909 | /* Bring back all the labels that were shadowed. */ | |
12910 | for (link = shadowed_labels; link; link = TREE_CHAIN (link)) | |
12911 | if (DECL_NAME (TREE_VALUE (link)) != 0) | |
12912 | SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), | |
12913 | TREE_VALUE (link)); | |
12914 | ||
28cbf42c | 12915 | pop_function_context_from (context); |
db5ae43f MS |
12916 | |
12917 | cp_function_chain = p->next; | |
12918 | ||
12919 | named_labels = p->named_labels; | |
12920 | shadowed_labels = p->shadowed_labels; | |
12921 | current_function_returns_value = p->returns_value; | |
12922 | current_function_returns_null = p->returns_null; | |
12923 | warn_about_return_type = p->warn_about_return_type; | |
db5ae43f MS |
12924 | current_binding_level = p->binding_level; |
12925 | ctor_label = p->ctor_label; | |
12926 | dtor_label = p->dtor_label; | |
72b7eeff | 12927 | last_dtor_insn = p->last_dtor_insn; |
b87692e5 | 12928 | last_parm_cleanup_insn = p->last_parm_cleanup_insn; |
db5ae43f MS |
12929 | current_function_assigns_this = p->assigns_this; |
12930 | current_function_just_assigned_this = p->just_assigned_this; | |
12931 | current_function_parms_stored = p->parms_stored; | |
12932 | original_result_rtx = p->result_rtx; | |
a9aedbc2 | 12933 | base_init_expr = p->base_init_expr; |
7215f9a0 | 12934 | temp_name_counter = p->temp_name_counter; |
79ff2c6c MS |
12935 | current_base_init_list = p->base_init_list; |
12936 | current_member_init_list = p->member_init_list; | |
4ac14744 MS |
12937 | current_class_ptr = p->current_class_ptr; |
12938 | current_class_ref = p->current_class_ref; | |
42976354 | 12939 | static_labelno = p->static_labelno; |
db5ae43f MS |
12940 | |
12941 | free (p); | |
12942 | } | |
ebfc180f | 12943 | |
5566b478 MS |
12944 | int |
12945 | in_function_p () | |
12946 | { | |
12947 | return function_depth != 0; | |
12948 | } | |
12949 | ||
ebfc180f | 12950 | /* FSF LOCAL dje prefix attributes */ |
ebfc180f MS |
12951 | /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes. |
12952 | This function is used by the parser when a rule will accept attributes | |
12953 | in a particular position, but we don't want to support that just yet. | |
12954 | ||
12955 | A warning is issued for every ignored attribute. */ | |
12956 | ||
12957 | tree | |
12958 | strip_attrs (specs_attrs) | |
12959 | tree specs_attrs; | |
12960 | { | |
12961 | tree specs, attrs; | |
12962 | ||
12963 | split_specs_attrs (specs_attrs, &specs, &attrs); | |
12964 | ||
12965 | while (attrs) | |
12966 | { | |
12967 | warning ("`%s' attribute ignored", | |
12968 | IDENTIFIER_POINTER (TREE_PURPOSE (attrs))); | |
12969 | attrs = TREE_CHAIN (attrs); | |
12970 | } | |
12971 | ||
12972 | return specs; | |
12973 | } | |
12974 | /* END FSF LOCAL */ | |
12975 |