Deleted Added
full compact
init.c (18334) init.c (50397)
1/* Handle initialization things in C++.
1/* Handle initialization things in C++.
2 Copyright (C) 1987, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
2 Copyright (C) 1987, 89, 92-96, 1997 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22/* High-level class interface. */
22
23
23/* High-level class interface. */
24
25#include "config.h"
24#include "config.h"
25#include "system.h"
26#include "tree.h"
27#include "rtl.h"
28#include "cp-tree.h"
29#include "flags.h"
30#include "output.h"
26#include "tree.h"
27#include "rtl.h"
28#include "cp-tree.h"
29#include "flags.h"
30#include "output.h"
31#include "except.h"
32#include "expr.h"
33#include "toplev.h"
31
34
32#undef NULL
33#define NULL 0
35extern void compiler_error ();
34
35/* In C++, structures with well-defined constructors are initialized by
36 those constructors, unasked. CURRENT_BASE_INIT_LIST
37 holds a list of stmts for a BASE_INIT term in the grammar.
38 This list has one element for each base class which must be
39 initialized. The list elements are [basename, init], with
40 type basetype. This allows the possibly anachronistic form
41 (assuming d : a, b, c) "d (int a) : c(a+5), b (a-4), a (a+3)"
42 where each successive term can be handed down the constructor
43 line. Perhaps this was not intended. */
44tree current_base_init_list, current_member_init_list;
45
36
37/* In C++, structures with well-defined constructors are initialized by
38 those constructors, unasked. CURRENT_BASE_INIT_LIST
39 holds a list of stmts for a BASE_INIT term in the grammar.
40 This list has one element for each base class which must be
41 initialized. The list elements are [basename, init], with
42 type basetype. This allows the possibly anachronistic form
43 (assuming d : a, b, c) "d (int a) : c(a+5), b (a-4), a (a+3)"
44 where each successive term can be handed down the constructor
45 line. Perhaps this was not intended. */
46tree current_base_init_list, current_member_init_list;
47
46void emit_base_init ();
47void check_base_init ();
48static void expand_aggr_vbase_init ();
49void expand_member_init ();
50void expand_aggr_init ();
51
52static void expand_aggr_init_1 ();
53static void expand_recursive_init_1 ();
54static void expand_recursive_init ();
48static void expand_aggr_vbase_init_1 PROTO((tree, tree, tree, tree));
49static void expand_aggr_vbase_init PROTO((tree, tree, tree, tree));
50static void expand_aggr_init_1 PROTO((tree, tree, tree, tree, int,
51 int));
52static void expand_default_init PROTO((tree, tree, tree, tree, int,
53 int));
54static tree build_vec_delete_1 PROTO((tree, tree, tree, tree, tree,
55 int));
56static void perform_member_init PROTO((tree, tree, tree, int));
57static void sort_base_init PROTO((tree, tree *, tree *));
58static tree build_builtin_call PROTO((tree, tree, tree));
59static tree build_array_eh_cleanup PROTO((tree, tree, tree));
60static int member_init_ok_or_else PROTO((tree, tree, char *));
55static void expand_virtual_init PROTO((tree, tree));
61static void expand_virtual_init PROTO((tree, tree));
56tree expand_vec_init ();
62static tree sort_member_init PROTO((tree));
63static tree build_partial_cleanup_for PROTO((tree));
64static tree initializing_context PROTO((tree));
57
65
58static void add_friend (), add_friends ();
59
60/* Cache _builtin_new and _builtin_delete exprs. */
61static tree BIN, BID, BIVN, BIVD;
62
66/* Cache _builtin_new and _builtin_delete exprs. */
67static tree BIN, BID, BIVN, BIVD;
68
63/* Cache the identifier nodes for the two magic field of a new cookie. */
69/* Cache the identifier nodes for the magic field of a new cookie. */
64static tree nc_nelts_field_id;
70static tree nc_nelts_field_id;
65#if 0
66static tree nc_ptr_2comp_field_id;
67#endif
68
69static tree minus_one;
70
71/* Set up local variable for this file. MUST BE CALLED AFTER
72 INIT_DECL_PROCESSING. */
73
71
72static tree minus_one;
73
74/* Set up local variable for this file. MUST BE CALLED AFTER
75 INIT_DECL_PROCESSING. */
76
74tree BI_header_type, BI_header_size;
77static tree BI_header_type, BI_header_size;
75
76void init_init_processing ()
77{
78 tree fields[1];
79
80 /* Define implicit `operator new' and `operator delete' functions. */
81 BIN = default_conversion (get_first_fn (IDENTIFIER_GLOBAL_VALUE (ansi_opname[(int) NEW_EXPR])));
82 TREE_USED (TREE_OPERAND (BIN, 0)) = 0;

--- 31 unchanged lines hidden (view full) ---

114 for all virtual table pointers in virtual base classes. REAL_BINFO
115 is used to find the BINFO_VTABLE that we initialize with. BINFO is
116 used for conversions of addr to subobjects.
117
118 BINFO_TYPE (real_binfo) must be BINFO_TYPE (binfo).
119
120 Relies upon binfo being inside TYPE_BINFO (TREE_TYPE (TREE_TYPE
121 (addr))). */
78
79void init_init_processing ()
80{
81 tree fields[1];
82
83 /* Define implicit `operator new' and `operator delete' functions. */
84 BIN = default_conversion (get_first_fn (IDENTIFIER_GLOBAL_VALUE (ansi_opname[(int) NEW_EXPR])));
85 TREE_USED (TREE_OPERAND (BIN, 0)) = 0;

--- 31 unchanged lines hidden (view full) ---

117 for all virtual table pointers in virtual base classes. REAL_BINFO
118 is used to find the BINFO_VTABLE that we initialize with. BINFO is
119 used for conversions of addr to subobjects.
120
121 BINFO_TYPE (real_binfo) must be BINFO_TYPE (binfo).
122
123 Relies upon binfo being inside TYPE_BINFO (TREE_TYPE (TREE_TYPE
124 (addr))). */
125
122void
123expand_direct_vtbls_init (real_binfo, binfo, init_self, can_elide, addr)
124 tree real_binfo, binfo, addr;
125 int init_self, can_elide;
126{
127 tree real_binfos = BINFO_BASETYPES (real_binfo);
128 tree binfos = BINFO_BASETYPES (binfo);
129 int i, n_baselinks = real_binfos ? TREE_VEC_LENGTH (real_binfos) : 0;
130
131 for (i = 0; i < n_baselinks; i++)
132 {
133 tree real_base_binfo = TREE_VEC_ELT (real_binfos, i);
134 tree base_binfo = TREE_VEC_ELT (binfos, i);
126void
127expand_direct_vtbls_init (real_binfo, binfo, init_self, can_elide, addr)
128 tree real_binfo, binfo, addr;
129 int init_self, can_elide;
130{
131 tree real_binfos = BINFO_BASETYPES (real_binfo);
132 tree binfos = BINFO_BASETYPES (binfo);
133 int i, n_baselinks = real_binfos ? TREE_VEC_LENGTH (real_binfos) : 0;
134
135 for (i = 0; i < n_baselinks; i++)
136 {
137 tree real_base_binfo = TREE_VEC_ELT (real_binfos, i);
138 tree base_binfo = TREE_VEC_ELT (binfos, i);
135 int is_not_base_vtable =
136 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo));
139 int is_not_base_vtable
140 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo));
137 if (! TREE_VIA_VIRTUAL (real_base_binfo))
138 expand_direct_vtbls_init (real_base_binfo, base_binfo,
139 is_not_base_vtable, can_elide, addr);
140 }
141#if 0
142 /* Before turning this on, make sure it is correct. */
143 if (can_elide && ! BINFO_MODIFIED (binfo))
144 return;
145#endif
146 /* Should we use something besides CLASSTYPE_VFIELDS? */
147 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo)))
148 {
149 tree base_ptr = convert_pointer_to_real (binfo, addr);
150 expand_virtual_init (real_binfo, base_ptr);
151 }
152}
153
154/* 348 - 351 */
155/* Subroutine of emit_base_init. */
141 if (! TREE_VIA_VIRTUAL (real_base_binfo))
142 expand_direct_vtbls_init (real_base_binfo, base_binfo,
143 is_not_base_vtable, can_elide, addr);
144 }
145#if 0
146 /* Before turning this on, make sure it is correct. */
147 if (can_elide && ! BINFO_MODIFIED (binfo))
148 return;
149#endif
150 /* Should we use something besides CLASSTYPE_VFIELDS? */
151 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo)))
152 {
153 tree base_ptr = convert_pointer_to_real (binfo, addr);
154 expand_virtual_init (real_binfo, base_ptr);
155 }
156}
157
158/* 348 - 351 */
159/* Subroutine of emit_base_init. */
160
156static void
161static void
157perform_member_init (member, name, init, explicit, protect_list)
158 tree member, name, init, *protect_list;
162perform_member_init (member, name, init, explicit)
163 tree member, name, init;
159 int explicit;
160{
161 tree decl;
162 tree type = TREE_TYPE (member);
163
164 int explicit;
165{
166 tree decl;
167 tree type = TREE_TYPE (member);
168
169 expand_start_target_temps ();
170
164 if (TYPE_NEEDS_CONSTRUCTING (type)
165 || (init && TYPE_HAS_CONSTRUCTOR (type)))
166 {
167 /* Since `init' is already a TREE_LIST on the current_member_init_list,
168 only build it into one if we aren't already a list. */
169 if (init != NULL_TREE && TREE_CODE (init) != TREE_LIST)
171 if (TYPE_NEEDS_CONSTRUCTING (type)
172 || (init && TYPE_HAS_CONSTRUCTOR (type)))
173 {
174 /* Since `init' is already a TREE_LIST on the current_member_init_list,
175 only build it into one if we aren't already a list. */
176 if (init != NULL_TREE && TREE_CODE (init) != TREE_LIST)
170 init = build_tree_list (NULL_TREE, init);
177 init = build_expr_list (NULL_TREE, init);
171
178
172 decl = build_component_ref (C_C_D, name, 0, explicit);
179 decl = build_component_ref (current_class_ref, name, NULL_TREE, explicit);
173
174 if (explicit
175 && TREE_CODE (type) == ARRAY_TYPE
176 && init != NULL_TREE
177 && TREE_CHAIN (init) == NULL_TREE
178 && TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE)
179 {
180 /* Initialization of one array from another. */

--- 4 unchanged lines hidden (view full) ---

185 expand_aggr_init (decl, init, 0, 0);
186 }
187 else
188 {
189 if (init == NULL_TREE)
190 {
191 if (explicit)
192 {
180
181 if (explicit
182 && TREE_CODE (type) == ARRAY_TYPE
183 && init != NULL_TREE
184 && TREE_CHAIN (init) == NULL_TREE
185 && TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE)
186 {
187 /* Initialization of one array from another. */

--- 4 unchanged lines hidden (view full) ---

192 expand_aggr_init (decl, init, 0, 0);
193 }
194 else
195 {
196 if (init == NULL_TREE)
197 {
198 if (explicit)
199 {
193 cp_error ("incomplete initializer for member `%D' of class `%T' which has no constructor",
194 member, current_class_type);
195 init = error_mark_node;
200 /* default-initialization. */
201 if (AGGREGATE_TYPE_P (type))
202 init = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
203 else if (TREE_CODE (type) == REFERENCE_TYPE)
204 {
205 cp_error ("default-initialization of `%#D', which has reference type",
206 member);
207 init = error_mark_node;
208 }
209 else
210 init = integer_zero_node;
196 }
197 /* member traversal: note it leaves init NULL */
198 else if (TREE_CODE (TREE_TYPE (member)) == REFERENCE_TYPE)
199 cp_pedwarn ("uninitialized reference member `%D'", member);
200 }
201 else if (TREE_CODE (init) == TREE_LIST)
202 {
203 /* There was an explicit member initialization. Do some

--- 6 unchanged lines hidden (view full) ---

210 else
211 init = TREE_VALUE (init);
212 }
213
214 /* We only build this with a null init if we got it from the
215 current_member_init_list. */
216 if (init || explicit)
217 {
211 }
212 /* member traversal: note it leaves init NULL */
213 else if (TREE_CODE (TREE_TYPE (member)) == REFERENCE_TYPE)
214 cp_pedwarn ("uninitialized reference member `%D'", member);
215 }
216 else if (TREE_CODE (init) == TREE_LIST)
217 {
218 /* There was an explicit member initialization. Do some

--- 6 unchanged lines hidden (view full) ---

225 else
226 init = TREE_VALUE (init);
227 }
228
229 /* We only build this with a null init if we got it from the
230 current_member_init_list. */
231 if (init || explicit)
232 {
218 decl = build_component_ref (C_C_D, name, 0, explicit);
233 decl = build_component_ref (current_class_ref, name, NULL_TREE,
234 explicit);
219 expand_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
220 }
221 }
235 expand_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
236 }
237 }
222 expand_cleanups_to (NULL_TREE);
223
238
239 expand_end_target_temps ();
240 free_temp_slots ();
241
224 if (TYPE_NEEDS_DESTRUCTOR (type))
225 {
242 if (TYPE_NEEDS_DESTRUCTOR (type))
243 {
226 tree expr = build_component_ref (C_C_D, name, 0, explicit);
244 tree expr;
245
246 /* All cleanups must be on the function_obstack. */
247 push_obstacks_nochange ();
248 resume_temporary_allocation ();
249
250 expr = build_component_ref (current_class_ref, name, NULL_TREE,
251 explicit);
227 expr = build_delete (type, expr, integer_zero_node,
228 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
229
230 if (expr != error_mark_node)
252 expr = build_delete (type, expr, integer_zero_node,
253 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
254
255 if (expr != error_mark_node)
231 {
232 start_protect ();
233 *protect_list = tree_cons (NULL_TREE, expr, *protect_list);
234 }
256 add_partial_entry (expr);
257
258 pop_obstacks ();
235 }
236}
237
238extern int warn_reorder;
239
240/* Subroutine of emit_member_init. */
259 }
260}
261
262extern int warn_reorder;
263
264/* Subroutine of emit_member_init. */
265
241static tree
242sort_member_init (t)
243 tree t;
244{
266static tree
267sort_member_init (t)
268 tree t;
269{
245 tree x, member, name, field, init;
270 tree x, member, name, field;
246 tree init_list = NULL_TREE;
271 tree init_list = NULL_TREE;
247 tree fields_to_unmark = NULL_TREE;
248 int last_pos = 0;
272 int last_pos = 0;
249 tree last_field;
273 tree last_field = NULL_TREE;
250
251 for (member = TYPE_FIELDS (t); member ; member = TREE_CHAIN (member))
252 {
253 int pos;
254
255 /* member could be, for example, a CONST_DECL for an enumerated
256 tag; we don't want to try to initialize that, since it already
257 has a value. */
258 if (TREE_CODE (member) != FIELD_DECL || !DECL_NAME (member))
259 continue;
260
261 for (x = current_member_init_list, pos = 0; x; x = TREE_CHAIN (x), ++pos)
262 {
263 /* If we cleared this out, then pay no attention to it. */
264 if (TREE_PURPOSE (x) == NULL_TREE)
265 continue;
266 name = TREE_PURPOSE (x);
267
268#if 0
274
275 for (member = TYPE_FIELDS (t); member ; member = TREE_CHAIN (member))
276 {
277 int pos;
278
279 /* member could be, for example, a CONST_DECL for an enumerated
280 tag; we don't want to try to initialize that, since it already
281 has a value. */
282 if (TREE_CODE (member) != FIELD_DECL || !DECL_NAME (member))
283 continue;
284
285 for (x = current_member_init_list, pos = 0; x; x = TREE_CHAIN (x), ++pos)
286 {
287 /* If we cleared this out, then pay no attention to it. */
288 if (TREE_PURPOSE (x) == NULL_TREE)
289 continue;
290 name = TREE_PURPOSE (x);
291
292#if 0
293 /* This happens in templates, since the IDENTIFIER is replaced
294 with the COMPONENT_REF in tsubst_expr. */
269 field = (TREE_CODE (name) == COMPONENT_REF
270 ? TREE_OPERAND (name, 1) : IDENTIFIER_CLASS_VALUE (name));
271#else
272 /* Let's find out when this happens. */
273 my_friendly_assert (TREE_CODE (name) != COMPONENT_REF, 348);
274 field = IDENTIFIER_CLASS_VALUE (name);
275#endif
276

--- 71 unchanged lines hidden (view full) ---

348 tree vbases = NULL_TREE;
349
350 /* First walk through and splice out vbase and invalid initializers.
351 Also replace names with binfos. */
352
353 last = tree_cons (NULL_TREE, NULL_TREE, current_base_init_list);
354 for (x = TREE_CHAIN (last); x; x = TREE_CHAIN (x))
355 {
295 field = (TREE_CODE (name) == COMPONENT_REF
296 ? TREE_OPERAND (name, 1) : IDENTIFIER_CLASS_VALUE (name));
297#else
298 /* Let's find out when this happens. */
299 my_friendly_assert (TREE_CODE (name) != COMPONENT_REF, 348);
300 field = IDENTIFIER_CLASS_VALUE (name);
301#endif
302

--- 71 unchanged lines hidden (view full) ---

374 tree vbases = NULL_TREE;
375
376 /* First walk through and splice out vbase and invalid initializers.
377 Also replace names with binfos. */
378
379 last = tree_cons (NULL_TREE, NULL_TREE, current_base_init_list);
380 for (x = TREE_CHAIN (last); x; x = TREE_CHAIN (x))
381 {
356 tree basename = TREE_PURPOSE (x);
357 tree binfo;
382 tree basetype = TREE_PURPOSE (x);
383 tree binfo = NULL_TREE;
358
384
359 if (basename == NULL_TREE)
385 if (basetype == NULL_TREE)
360 {
361 /* Initializer for single base class. Must not
362 use multiple inheritance or this is ambiguous. */
363 switch (n_baseclasses)
364 {
365 case 0:
366 cp_error ("`%T' does not have a base class to initialize",
367 current_class_type);
368 return;
369 case 1:
370 break;
371 default:
372 cp_error ("unnamed initializer ambiguous for `%T' which uses multiple inheritance",
373 current_class_type);
374 return;
375 }
376 binfo = TREE_VEC_ELT (binfos, 0);
377 }
386 {
387 /* Initializer for single base class. Must not
388 use multiple inheritance or this is ambiguous. */
389 switch (n_baseclasses)
390 {
391 case 0:
392 cp_error ("`%T' does not have a base class to initialize",
393 current_class_type);
394 return;
395 case 1:
396 break;
397 default:
398 cp_error ("unnamed initializer ambiguous for `%T' which uses multiple inheritance",
399 current_class_type);
400 return;
401 }
402 binfo = TREE_VEC_ELT (binfos, 0);
403 }
378 else if (is_aggr_typedef (basename, 1))
404 else if (is_aggr_type (basetype, 1))
379 {
405 {
380 binfo = binfo_or_else (IDENTIFIER_TYPE_VALUE (basename), t);
406 binfo = binfo_or_else (basetype, t);
381 if (binfo == NULL_TREE)
382 continue;
383
384 /* Virtual base classes are special cases. Their initializers
385 are recorded with this constructor, and they are used when
386 this constructor is the top-level constructor called. */
387 if (TREE_VIA_VIRTUAL (binfo))
388 {

--- 8 unchanged lines hidden (view full) ---

397 {
398 /* Otherwise, if it is not an immediate base class, complain. */
399 for (i = n_baseclasses-1; i >= 0; i--)
400 if (BINFO_TYPE (binfo) == BINFO_TYPE (TREE_VEC_ELT (binfos, i)))
401 break;
402 if (i < 0)
403 {
404 cp_error ("`%T' is not an immediate base class of `%T'",
407 if (binfo == NULL_TREE)
408 continue;
409
410 /* Virtual base classes are special cases. Their initializers
411 are recorded with this constructor, and they are used when
412 this constructor is the top-level constructor called. */
413 if (TREE_VIA_VIRTUAL (binfo))
414 {

--- 8 unchanged lines hidden (view full) ---

423 {
424 /* Otherwise, if it is not an immediate base class, complain. */
425 for (i = n_baseclasses-1; i >= 0; i--)
426 if (BINFO_TYPE (binfo) == BINFO_TYPE (TREE_VEC_ELT (binfos, i)))
427 break;
428 if (i < 0)
429 {
430 cp_error ("`%T' is not an immediate base class of `%T'",
405 IDENTIFIER_TYPE_VALUE (basename),
406 current_class_type);
431 basetype, current_class_type);
407 continue;
408 }
409 }
410 }
411 else
412 my_friendly_abort (365);
413
414 TREE_PURPOSE (x) = binfo;

--- 48 unchanged lines hidden (view full) ---

463 rbases = chainon (rbases, x);
464 }
465
466 *rbase_ptr = rbases;
467 *vbase_ptr = vbases;
468}
469
470/* Perform partial cleanups for a base for exception handling. */
432 continue;
433 }
434 }
435 }
436 else
437 my_friendly_abort (365);
438
439 TREE_PURPOSE (x) = binfo;

--- 48 unchanged lines hidden (view full) ---

488 rbases = chainon (rbases, x);
489 }
490
491 *rbase_ptr = rbases;
492 *vbase_ptr = vbases;
493}
494
495/* Perform partial cleanups for a base for exception handling. */
496
471static tree
472build_partial_cleanup_for (binfo)
473 tree binfo;
474{
497static tree
498build_partial_cleanup_for (binfo)
499 tree binfo;
500{
475 tree expr = convert_pointer_to_real (binfo,
476 build_unary_op (ADDR_EXPR, C_C_D, 0));
477
478 return build_delete (TREE_TYPE (expr),
479 expr,
480 integer_zero_node,
481 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
501 return build_scoped_method_call
502 (current_class_ref, binfo, dtor_identifier,
503 build_expr_list (NULL_TREE, integer_zero_node));
482}
483
484/* Perform whatever initializations have yet to be done on the base
485 class of the class variable. These actions are in the global
486 variable CURRENT_BASE_INIT_LIST. Such an action could be
487 NULL_TREE, meaning that the user has explicitly called the base
488 class constructor with no arguments.
489

--- 11 unchanged lines hidden (view full) ---

501
502extern tree base_init_expr, rtl_expr_chain;
503
504void
505emit_base_init (t, immediately)
506 tree t;
507 int immediately;
508{
504}
505
506/* Perform whatever initializations have yet to be done on the base
507 class of the class variable. These actions are in the global
508 variable CURRENT_BASE_INIT_LIST. Such an action could be
509 NULL_TREE, meaning that the user has explicitly called the base
510 class constructor with no arguments.
511

--- 11 unchanged lines hidden (view full) ---

523
524extern tree base_init_expr, rtl_expr_chain;
525
526void
527emit_base_init (t, immediately)
528 tree t;
529 int immediately;
530{
509 extern tree in_charge_identifier;
510
511 tree member, x;
531 tree member;
512 tree mem_init_list;
513 tree rbase_init_list, vbase_init_list;
514 tree t_binfo = TYPE_BINFO (t);
515 tree binfos = BINFO_BASETYPES (t_binfo);
516 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
517 tree expr = NULL_TREE;
518
532 tree mem_init_list;
533 tree rbase_init_list, vbase_init_list;
534 tree t_binfo = TYPE_BINFO (t);
535 tree binfos = BINFO_BASETYPES (t_binfo);
536 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
537 tree expr = NULL_TREE;
538
519 my_friendly_assert (protect_list == NULL_TREE, 999);
520
521 if (! immediately)
522 {
523 int momentary;
524 do_pending_stack_adjust ();
525 /* Make the RTL_EXPR node temporary, not momentary,
526 so that rtl_expr_chain doesn't become garbage. */
527 momentary = suspend_momentary ();
528 expr = make_node (RTL_EXPR);

--- 15 unchanged lines hidden (view full) ---

544 sort_base_init (t, &rbase_init_list, &vbase_init_list);
545 current_base_init_list = NULL_TREE;
546
547 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
548 {
549 tree first_arg = TREE_CHAIN (DECL_ARGUMENTS (current_function_decl));
550
551 expand_start_cond (first_arg, 0);
539 if (! immediately)
540 {
541 int momentary;
542 do_pending_stack_adjust ();
543 /* Make the RTL_EXPR node temporary, not momentary,
544 so that rtl_expr_chain doesn't become garbage. */
545 momentary = suspend_momentary ();
546 expr = make_node (RTL_EXPR);

--- 15 unchanged lines hidden (view full) ---

562 sort_base_init (t, &rbase_init_list, &vbase_init_list);
563 current_base_init_list = NULL_TREE;
564
565 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
566 {
567 tree first_arg = TREE_CHAIN (DECL_ARGUMENTS (current_function_decl));
568
569 expand_start_cond (first_arg, 0);
552 expand_aggr_vbase_init (t_binfo, C_C_D, current_class_decl,
570 expand_aggr_vbase_init (t_binfo, current_class_ref, current_class_ptr,
553 vbase_init_list);
554 expand_end_cond ();
555 }
556
557 /* Now, perform initialization of non-virtual base classes. */
558 for (i = 0; i < n_baseclasses; i++)
559 {
571 vbase_init_list);
572 expand_end_cond ();
573 }
574
575 /* Now, perform initialization of non-virtual base classes. */
576 for (i = 0; i < n_baseclasses; i++)
577 {
560 tree base = current_class_decl;
561 tree base_binfo = TREE_VEC_ELT (binfos, i);
562 tree init = void_list_node;
563
564 if (TREE_VIA_VIRTUAL (base_binfo))
565 continue;
566
567#if 0 /* Once unsharing happens soon enough. */
578 tree base_binfo = TREE_VEC_ELT (binfos, i);
579 tree init = void_list_node;
580
581 if (TREE_VIA_VIRTUAL (base_binfo))
582 continue;
583
584#if 0 /* Once unsharing happens soon enough. */
568 my_friendly_assert (BINFO_INHERITANCE_CHAIN (base_binfo) == t_binfo);
585 my_friendly_assert (BINFO_INHERITANCE_CHAIN (base_binfo) == t_binfo, 999);
569#else
570 BINFO_INHERITANCE_CHAIN (base_binfo) = t_binfo;
571#endif
572
573 if (TREE_PURPOSE (rbase_init_list))
574 init = TREE_VALUE (rbase_init_list);
575 else if (TYPE_NEEDS_CONSTRUCTING (BINFO_TYPE (base_binfo)))
586#else
587 BINFO_INHERITANCE_CHAIN (base_binfo) = t_binfo;
588#endif
589
590 if (TREE_PURPOSE (rbase_init_list))
591 init = TREE_VALUE (rbase_init_list);
592 else if (TYPE_NEEDS_CONSTRUCTING (BINFO_TYPE (base_binfo)))
576 init = NULL_TREE;
593 {
594 init = NULL_TREE;
595 if (extra_warnings && copy_args_p (current_function_decl))
596 cp_warning ("base class `%#T' should be explicitly initialized in the copy constructor",
597 BINFO_TYPE (base_binfo));
598 }
577
578 if (init != void_list_node)
579 {
599
600 if (init != void_list_node)
601 {
580 member = convert_pointer_to_real (base_binfo, current_class_decl);
581 expand_aggr_init_1 (base_binfo, 0,
602 expand_start_target_temps ();
603
604 member = convert_pointer_to_real (base_binfo, current_class_ptr);
605 expand_aggr_init_1 (base_binfo, NULL_TREE,
582 build_indirect_ref (member, NULL_PTR), init,
583 BINFO_OFFSET_ZEROP (base_binfo), LOOKUP_NORMAL);
606 build_indirect_ref (member, NULL_PTR), init,
607 BINFO_OFFSET_ZEROP (base_binfo), LOOKUP_NORMAL);
584 expand_cleanups_to (NULL_TREE);
608
609 expand_end_target_temps ();
610 free_temp_slots ();
585 }
586
587 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo)))
588 {
611 }
612
613 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo)))
614 {
589 start_protect ();
590 protect_list = tree_cons (NULL_TREE,
591 build_partial_cleanup_for (base_binfo),
592 protect_list);
615 tree expr;
616
617 /* All cleanups must be on the function_obstack. */
618 push_obstacks_nochange ();
619 resume_temporary_allocation ();
620 expr = build_partial_cleanup_for (base_binfo);
621 pop_obstacks ();
622 add_partial_entry (expr);
593 }
594
595 rbase_init_list = TREE_CHAIN (rbase_init_list);
596 }
597
598 /* Initialize all the virtual function table fields that
623 }
624
625 rbase_init_list = TREE_CHAIN (rbase_init_list);
626 }
627
628 /* Initialize all the virtual function table fields that
599 do come from virtual base classes. */
629 do come from virtual base classes. */
600 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
630 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
601 expand_indirect_vtbls_init (t_binfo, C_C_D, current_class_decl, 0);
631 expand_indirect_vtbls_init (t_binfo, current_class_ref, current_class_ptr);
602
603 /* Initialize all the virtual function table fields that
604 do not come from virtual base classes. */
632
633 /* Initialize all the virtual function table fields that
634 do not come from virtual base classes. */
605 expand_direct_vtbls_init (t_binfo, t_binfo, 1, 1, current_class_decl);
635 expand_direct_vtbls_init (t_binfo, t_binfo, 1, 1, current_class_ptr);
606
607 for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
608 {
609 tree init, name;
610 int from_init_list;
611
612 /* member could be, for example, a CONST_DECL for an enumerated
613 tag; we don't want to try to initialize that, since it already
614 has a value. */
615 if (TREE_CODE (member) != FIELD_DECL || !DECL_NAME (member))
616 continue;
617
618 /* See if we had a user-specified member initialization. */
619 if (TREE_PURPOSE (mem_init_list))
620 {
621 name = TREE_PURPOSE (mem_init_list);
622 init = TREE_VALUE (mem_init_list);
623 from_init_list = 1;
624
636
637 for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
638 {
639 tree init, name;
640 int from_init_list;
641
642 /* member could be, for example, a CONST_DECL for an enumerated
643 tag; we don't want to try to initialize that, since it already
644 has a value. */
645 if (TREE_CODE (member) != FIELD_DECL || !DECL_NAME (member))
646 continue;
647
648 /* See if we had a user-specified member initialization. */
649 if (TREE_PURPOSE (mem_init_list))
650 {
651 name = TREE_PURPOSE (mem_init_list);
652 init = TREE_VALUE (mem_init_list);
653 from_init_list = 1;
654
655#if 0
656 if (TREE_CODE (name) == COMPONENT_REF)
657 name = DECL_NAME (TREE_OPERAND (name, 1));
658#else
625 /* Also see if it's ever a COMPONENT_REF here. If it is, we
626 need to do `expand_assignment (name, init, 0, 0);' and
627 a continue. */
628 my_friendly_assert (TREE_CODE (name) != COMPONENT_REF, 349);
659 /* Also see if it's ever a COMPONENT_REF here. If it is, we
660 need to do `expand_assignment (name, init, 0, 0);' and
661 a continue. */
662 my_friendly_assert (TREE_CODE (name) != COMPONENT_REF, 349);
663#endif
629 }
630 else
631 {
632 name = DECL_NAME (member);
633 init = DECL_INITIAL (member);
634
635 from_init_list = 0;
664 }
665 else
666 {
667 name = DECL_NAME (member);
668 init = DECL_INITIAL (member);
669
670 from_init_list = 0;
671
672 /* Effective C++ rule 12. */
673 if (warn_ecpp && init == NULL_TREE
674 && !DECL_ARTIFICIAL (member)
675 && TREE_CODE (TREE_TYPE (member)) != ARRAY_TYPE)
676 cp_warning ("`%D' should be initialized in the member initialization list", member);
636 }
637
677 }
678
638 perform_member_init (member, name, init, from_init_list, &protect_list);
679 perform_member_init (member, name, init, from_init_list);
639 mem_init_list = TREE_CHAIN (mem_init_list);
640 }
641
642 /* Now initialize any members from our bases. */
643 while (mem_init_list)
644 {
645 tree name, init, field;
646

--- 21 unchanged lines hidden (view full) ---

668
669 /* The code in this for loop is derived from a general loop
670 which had this check in it. Theoretically, we've hit
671 every initialization for the list of members in T, so
672 we shouldn't have anything but these left in this list. */
673 my_friendly_assert (DECL_FIELD_CONTEXT (field) != t, 351);
674#endif
675
680 mem_init_list = TREE_CHAIN (mem_init_list);
681 }
682
683 /* Now initialize any members from our bases. */
684 while (mem_init_list)
685 {
686 tree name, init, field;
687

--- 21 unchanged lines hidden (view full) ---

709
710 /* The code in this for loop is derived from a general loop
711 which had this check in it. Theoretically, we've hit
712 every initialization for the list of members in T, so
713 we shouldn't have anything but these left in this list. */
714 my_friendly_assert (DECL_FIELD_CONTEXT (field) != t, 351);
715#endif
716
676 perform_member_init (field, name, init, 1, &protect_list);
717 perform_member_init (field, name, init, 1);
677 }
678 mem_init_list = TREE_CHAIN (mem_init_list);
679 }
680
681 if (! immediately)
682 {
683 do_pending_stack_adjust ();
684 my_friendly_assert (base_init_expr == 0, 207);

--- 7 unchanged lines hidden (view full) ---

692 }
693
694 /* All the implicit try blocks we built up will be zapped
695 when we come to a real binding contour boundary. */
696}
697
698/* Check that all fields are properly initialized after
699 an assignment to `this'. */
718 }
719 mem_init_list = TREE_CHAIN (mem_init_list);
720 }
721
722 if (! immediately)
723 {
724 do_pending_stack_adjust ();
725 my_friendly_assert (base_init_expr == 0, 207);

--- 7 unchanged lines hidden (view full) ---

733 }
734
735 /* All the implicit try blocks we built up will be zapped
736 when we come to a real binding contour boundary. */
737}
738
739/* Check that all fields are properly initialized after
740 an assignment to `this'. */
741
700void
701check_base_init (t)
702 tree t;
703{
704 tree member;
705 for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
706 if (DECL_NAME (member) && TREE_USED (member))
707 cp_error ("field `%D' used before initialized (after assignment to `this')",
708 member);
709}
710
711/* This code sets up the virtual function tables appropriate for
712 the pointer DECL. It is a one-ply initialization.
713
714 BINFO is the exact type that DECL is supposed to be. In
715 multiple inheritance, this might mean "C's A" if C : A, B. */
742void
743check_base_init (t)
744 tree t;
745{
746 tree member;
747 for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
748 if (DECL_NAME (member) && TREE_USED (member))
749 cp_error ("field `%D' used before initialized (after assignment to `this')",
750 member);
751}
752
753/* This code sets up the virtual function tables appropriate for
754 the pointer DECL. It is a one-ply initialization.
755
756 BINFO is the exact type that DECL is supposed to be. In
757 multiple inheritance, this might mean "C's A" if C : A, B. */
758
716static void
717expand_virtual_init (binfo, decl)
718 tree binfo, decl;
719{
720 tree type = BINFO_TYPE (binfo);
721 tree vtbl, vtbl_ptr;
722 tree vtype, vtype_binfo;
723

--- 14 unchanged lines hidden (view full) ---

738 /* Have to convert VTBL since array sizes may be different. */
739 vtbl = convert_force (TREE_TYPE (vtbl_ptr), vtbl, 0);
740 expand_expr_stmt (build_modify_expr (vtbl_ptr, NOP_EXPR, vtbl));
741}
742
743/* Subroutine of `expand_aggr_vbase_init'.
744 BINFO is the binfo of the type that is being initialized.
745 INIT_LIST is the list of initializers for the virtual baseclass. */
759static void
760expand_virtual_init (binfo, decl)
761 tree binfo, decl;
762{
763 tree type = BINFO_TYPE (binfo);
764 tree vtbl, vtbl_ptr;
765 tree vtype, vtype_binfo;
766

--- 14 unchanged lines hidden (view full) ---

781 /* Have to convert VTBL since array sizes may be different. */
782 vtbl = convert_force (TREE_TYPE (vtbl_ptr), vtbl, 0);
783 expand_expr_stmt (build_modify_expr (vtbl_ptr, NOP_EXPR, vtbl));
784}
785
786/* Subroutine of `expand_aggr_vbase_init'.
787 BINFO is the binfo of the type that is being initialized.
788 INIT_LIST is the list of initializers for the virtual baseclass. */
789
746static void
747expand_aggr_vbase_init_1 (binfo, exp, addr, init_list)
748 tree binfo, exp, addr, init_list;
749{
750 tree init = purpose_member (binfo, init_list);
751 tree ref = build_indirect_ref (addr, NULL_PTR);
790static void
791expand_aggr_vbase_init_1 (binfo, exp, addr, init_list)
792 tree binfo, exp, addr, init_list;
793{
794 tree init = purpose_member (binfo, init_list);
795 tree ref = build_indirect_ref (addr, NULL_PTR);
796
797 expand_start_target_temps ();
798
752 if (init)
753 init = TREE_VALUE (init);
754 /* Call constructors, but don't set up vtables. */
755 expand_aggr_init_1 (binfo, exp, ref, init, 0, LOOKUP_COMPLAIN);
799 if (init)
800 init = TREE_VALUE (init);
801 /* Call constructors, but don't set up vtables. */
802 expand_aggr_init_1 (binfo, exp, ref, init, 0, LOOKUP_COMPLAIN);
756 expand_cleanups_to (NULL_TREE);
803
804 expand_end_target_temps ();
805 free_temp_slots ();
757}
758
759/* Initialize this object's virtual base class pointers. This must be
760 done only at the top-level of the object being constructed.
761
762 INIT_LIST is list of initialization for constructor to perform. */
806}
807
808/* Initialize this object's virtual base class pointers. This must be
809 done only at the top-level of the object being constructed.
810
811 INIT_LIST is list of initialization for constructor to perform. */
812
763static void
764expand_aggr_vbase_init (binfo, exp, addr, init_list)
765 tree binfo;
766 tree exp;
767 tree addr;
768 tree init_list;
769{
770 tree type = BINFO_TYPE (binfo);

--- 12 unchanged lines hidden (view full) ---

783 tree tmp = purpose_member (vbases, result);
784 expand_aggr_vbase_init_1 (vbases, exp,
785 TREE_OPERAND (TREE_VALUE (tmp), 0),
786 init_list);
787 }
788 }
789}
790
813static void
814expand_aggr_vbase_init (binfo, exp, addr, init_list)
815 tree binfo;
816 tree exp;
817 tree addr;
818 tree init_list;
819{
820 tree type = BINFO_TYPE (binfo);

--- 12 unchanged lines hidden (view full) ---

833 tree tmp = purpose_member (vbases, result);
834 expand_aggr_vbase_init_1 (vbases, exp,
835 TREE_OPERAND (TREE_VALUE (tmp), 0),
836 init_list);
837 }
838 }
839}
840
791/* Subroutine to perform parser actions for member initialization.
792 S_ID is the scoped identifier.
793 NAME is the name of the member.
794 INIT is the initializer, or `void_type_node' if none. */
795void
796do_member_init (s_id, name, init)
797 tree s_id, name, init;
841/* Find the context in which this FIELD can be initialized. */
842
843static tree
844initializing_context (field)
845 tree field;
798{
846{
799 tree binfo, base;
847 tree t = DECL_CONTEXT (field);
800
848
801 if (current_class_type == NULL_TREE
802 || ! is_aggr_typedef (s_id, 1))
803 return;
804 binfo = get_binfo (IDENTIFIER_TYPE_VALUE (s_id),
805 current_class_type, 1);
806 if (binfo == error_mark_node)
807 return;
808 if (binfo == 0)
809 {
810 error_not_base_type (IDENTIFIER_TYPE_VALUE (s_id), current_class_type);
811 return;
812 }
813
814 base = convert_pointer_to (binfo, current_class_decl);
815 expand_member_init (build_indirect_ref (base, NULL_PTR), name, init);
849 /* Anonymous union members can be initialized in the first enclosing
850 non-anonymous union context. */
851 while (t && ANON_UNION_TYPE_P (t))
852 t = TYPE_CONTEXT (t);
853 return t;
816}
817
818/* Function to give error message if member initialization specification
819 is erroneous. FIELD is the member we decided to initialize.
820 TYPE is the type for which the initialization is being performed.
854}
855
856/* Function to give error message if member initialization specification
857 is erroneous. FIELD is the member we decided to initialize.
858 TYPE is the type for which the initialization is being performed.
821 FIELD must be a member of TYPE, or the base type from which FIELD
822 comes must not need a constructor.
859 FIELD must be a member of TYPE.
823
824 MEMBER_NAME is the name of the member. */
825
826static int
827member_init_ok_or_else (field, type, member_name)
828 tree field;
829 tree type;
830 char *member_name;
831{
832 if (field == error_mark_node)
833 return 0;
860
861 MEMBER_NAME is the name of the member. */
862
863static int
864member_init_ok_or_else (field, type, member_name)
865 tree field;
866 tree type;
867 char *member_name;
868{
869 if (field == error_mark_node)
870 return 0;
834 if (field == NULL_TREE)
871 if (field == NULL_TREE || initializing_context (field) != type)
835 {
836 cp_error ("class `%T' does not have any field named `%s'", type,
837 member_name);
838 return 0;
839 }
872 {
873 cp_error ("class `%T' does not have any field named `%s'", type,
874 member_name);
875 return 0;
876 }
840 if (DECL_CONTEXT (field) != type
841 && TYPE_NEEDS_CONSTRUCTING (DECL_CONTEXT (field)))
842 {
843 if (current_function_decl && DECL_CONSTRUCTOR_P (current_function_decl))
844 cp_error ("initialization of `%D' inside constructor for `%T'",
845 field, type);
846 else
847 cp_error ("member `%D' comes from base class needing constructor",
848 field);
849 return 0;
850 }
851 if (TREE_STATIC (field))
852 {
853 cp_error ("field `%#D' is static; only point of initialization is its declaration",
854 field);
855 return 0;
856 }
857
858 return 1;

--- 9 unchanged lines hidden (view full) ---

868
869 We do not yet have a fixed-point finder to instantiate types
870 being fed to overloaded constructors. If there is a unique
871 constructor, then argument types can be got from that one.
872
873 If INIT is non-NULL, then it the initialization should
874 be placed in `current_base_init_list', where it will be processed
875 by `emit_base_init'. */
877 if (TREE_STATIC (field))
878 {
879 cp_error ("field `%#D' is static; only point of initialization is its declaration",
880 field);
881 return 0;
882 }
883
884 return 1;

--- 9 unchanged lines hidden (view full) ---

894
895 We do not yet have a fixed-point finder to instantiate types
896 being fed to overloaded constructors. If there is a unique
897 constructor, then argument types can be got from that one.
898
899 If INIT is non-NULL, then it the initialization should
900 be placed in `current_base_init_list', where it will be processed
901 by `emit_base_init'. */
902
876void
877expand_member_init (exp, name, init)
878 tree exp, name, init;
879{
903void
904expand_member_init (exp, name, init)
905 tree exp, name, init;
906{
880 extern tree ptr_type_node; /* should be in tree.h */
881
882 tree basetype = NULL_TREE, field;
907 tree basetype = NULL_TREE, field;
883 tree parm;
884 tree rval, type;
885 tree actual_name;
908 tree type;
886
887 if (exp == NULL_TREE)
888 return; /* complain about this later */
889
890 type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
891
909
910 if (exp == NULL_TREE)
911 return; /* complain about this later */
912
913 type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
914
915 if (name && TREE_CODE (name) == TYPE_DECL)
916 {
917 basetype = TREE_TYPE (name);
918 name = DECL_NAME (name);
919 }
920
892 if (name == NULL_TREE && IS_AGGR_TYPE (type))
893 switch (CLASSTYPE_N_BASECLASSES (type))
894 {
895 case 0:
896 error ("base class initializer specified, but no base class to initialize");
897 return;
898 case 1:
899 basetype = TYPE_BINFO_BASETYPE (type, 0);
900 break;
901 default:
902 error ("initializer for unnamed base class ambiguous");
903 cp_error ("(type `%T' uses multiple inheritance)", type);
904 return;
905 }
906
921 if (name == NULL_TREE && IS_AGGR_TYPE (type))
922 switch (CLASSTYPE_N_BASECLASSES (type))
923 {
924 case 0:
925 error ("base class initializer specified, but no base class to initialize");
926 return;
927 case 1:
928 basetype = TYPE_BINFO_BASETYPE (type, 0);
929 break;
930 default:
931 error ("initializer for unnamed base class ambiguous");
932 cp_error ("(type `%T' uses multiple inheritance)", type);
933 return;
934 }
935
907 if (init)
908 {
909 /* The grammar should not allow fields which have names
910 that are TYPENAMEs. Therefore, if the field has
911 a non-NULL TREE_TYPE, we may assume that this is an
912 attempt to initialize a base class member of the current
913 type. Otherwise, it is an attempt to initialize a
914 member field. */
936 my_friendly_assert (init != NULL_TREE, 0);
915
937
916 if (init == void_type_node)
917 init = NULL_TREE;
938 /* The grammar should not allow fields which have names that are
939 TYPENAMEs. Therefore, if the field has a non-NULL TREE_TYPE, we
940 may assume that this is an attempt to initialize a base class
941 member of the current type. Otherwise, it is an attempt to
942 initialize a member field. */
918
943
919 if (name == NULL_TREE || IDENTIFIER_HAS_TYPE_VALUE (name))
920 {
921 tree base_init;
944 if (init == void_type_node)
945 init = NULL_TREE;
922
946
923 if (name == NULL_TREE)
924 {
925/*
926 if (basetype)
927 name = TYPE_IDENTIFIER (basetype);
928 else
929 {
930 error ("no base class to initialize");
931 return;
932 }
933*/
934 }
947 if (name == NULL_TREE || basetype)
948 {
949 tree base_init;
950
951 if (name == NULL_TREE)
952 {
953#if 0
954 if (basetype)
955 name = TYPE_IDENTIFIER (basetype);
935 else
936 {
956 else
957 {
937 basetype = IDENTIFIER_TYPE_VALUE (name);
938 if (basetype != type
939 && ! binfo_member (basetype, TYPE_BINFO (type))
940 && ! binfo_member (basetype, CLASSTYPE_VBASECLASSES (type)))
941 {
942 if (IDENTIFIER_CLASS_VALUE (name))
943 goto try_member;
944 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
945 error ("type `%s' is not an immediate or virtual basetype for `%s'",
946 IDENTIFIER_POINTER (name),
947 TYPE_NAME_STRING (type));
948 else
949 error ("type `%s' is not an immediate basetype for `%s'",
950 IDENTIFIER_POINTER (name),
951 TYPE_NAME_STRING (type));
952 return;
953 }
954 }
955
956 if (purpose_member (name, current_base_init_list))
957 {
958 error ("base class `%s' already initialized",
959 IDENTIFIER_POINTER (name));
958 error ("no base class to initialize");
960 return;
961 }
959 return;
960 }
962
963 base_init = build_tree_list (name, init);
964 TREE_TYPE (base_init) = basetype;
965 current_base_init_list = chainon (current_base_init_list, base_init);
961#endif
966 }
962 }
967 else
963 else if (basetype != type
964 && ! current_template_parms
965 && ! vec_binfo_member (basetype,
966 TYPE_BINFO_BASETYPES (type))
967 && ! binfo_member (basetype, CLASSTYPE_VBASECLASSES (type)))
968 {
968 {
969 tree member_init;
970
971 try_member:
972 field = lookup_field (type, name, 1, 0);
973
974 if (! member_init_ok_or_else (field, type, IDENTIFIER_POINTER (name)))
975 return;
976
977 if (purpose_member (name, current_member_init_list))
978 {
979 error ("field `%s' already initialized", IDENTIFIER_POINTER (name));
980 return;
981 }
982
983 member_init = build_tree_list (name, init);
984 TREE_TYPE (member_init) = TREE_TYPE (field);
985 current_member_init_list = chainon (current_member_init_list, member_init);
969 if (IDENTIFIER_CLASS_VALUE (name))
970 goto try_member;
971 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
972 cp_error ("type `%T' is not an immediate or virtual basetype for `%T'",
973 basetype, type);
974 else
975 cp_error ("type `%T' is not an immediate basetype for `%T'",
976 basetype, type);
977 return;
986 }
978 }
987 return;
988 }
989 else if (name == NULL_TREE)
990 {
991 compiler_error ("expand_member_init: name == NULL_TREE");
992 return;
993 }
994
979
995 basetype = type;
996 field = lookup_field (basetype, name, 0, 0);
997
998 if (! member_init_ok_or_else (field, basetype, IDENTIFIER_POINTER (name)))
999 return;
1000
1001 /* now see if there is a constructor for this type
1002 which will take these args. */
1003
1004 if (TYPE_HAS_CONSTRUCTOR (TREE_TYPE (field)))
1005 {
1006 tree parmtypes, fndecl;
1007
1008 if (TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == PARM_DECL)
980 if (purpose_member (basetype, current_base_init_list))
1009 {
981 {
1010 /* just know that we've seen something for this node */
1011 DECL_INITIAL (exp) = error_mark_node;
1012 TREE_USED (exp) = 1;
982 cp_error ("base class `%T' already initialized", basetype);
983 return;
1013 }
984 }
1014 type = TYPE_MAIN_VARIANT (TREE_TYPE (field));
1015 actual_name = TYPE_IDENTIFIER (type);
1016 parm = build_component_ref (exp, name, 0, 0);
1017
985
1018 /* Now get to the constructor. */
1019 fndecl = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0);
1020 /* Get past destructor, if any. */
1021 if (TYPE_HAS_DESTRUCTOR (type))
1022 fndecl = DECL_CHAIN (fndecl);
1023
1024 if (fndecl)
1025 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 209);
1026
1027 /* If the field is unique, we can use the parameter
1028 types to guide possible type instantiation. */
1029 if (DECL_CHAIN (fndecl) == NULL_TREE)
986 if (warn_reorder && current_member_init_list)
1030 {
987 {
1031 /* There was a confusion here between
1032 FIELD and FNDECL. The following code
1033 should be correct, but abort is here
1034 to make sure. */
1035 my_friendly_abort (48);
1036 parmtypes = FUNCTION_ARG_CHAIN (fndecl);
988 cp_warning ("base initializer for `%T'", basetype);
989 warning (" will be re-ordered to precede member initializations");
1037 }
990 }
1038 else
1039 {
1040 parmtypes = NULL_TREE;
1041 fndecl = NULL_TREE;
1042 }
1043
991
1044 init = convert_arguments (parm, parmtypes, NULL_TREE, fndecl, LOOKUP_NORMAL);
1045 if (init == NULL_TREE || TREE_TYPE (init) != error_mark_node)
1046 rval = build_method_call (NULL_TREE, actual_name, init, NULL_TREE, LOOKUP_NORMAL);
1047 else
992 base_init = build_tree_list (basetype, init);
993 current_base_init_list = chainon (current_base_init_list, base_init);
994 }
995 else
996 {
997 tree member_init;
998
999 try_member:
1000 field = lookup_field (type, name, 1, 0);
1001
1002 if (! member_init_ok_or_else (field, type, IDENTIFIER_POINTER (name)))
1048 return;
1049
1003 return;
1004
1050 if (rval != error_mark_node)
1005 if (purpose_member (name, current_member_init_list))
1051 {
1006 {
1052 /* Now, fill in the first parm with our guy */
1053 TREE_VALUE (TREE_OPERAND (rval, 1))
1054 = build_unary_op (ADDR_EXPR, parm, 0);
1055 TREE_TYPE (rval) = ptr_type_node;
1056 TREE_SIDE_EFFECTS (rval) = 1;
1007 cp_error ("field `%D' already initialized", field);
1008 return;
1057 }
1009 }
1058 }
1059 else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field)))
1060 {
1061 parm = build_component_ref (exp, name, 0, 0);
1062 expand_aggr_init (parm, NULL_TREE, 0, 0);
1063 rval = error_mark_node;
1064 }
1065
1010
1066 /* Now initialize the member. It does not have to
1067 be of aggregate type to receive initialization. */
1068 if (rval != error_mark_node)
1069 expand_expr_stmt (rval);
1011 member_init = build_tree_list (name, init);
1012 current_member_init_list = chainon (current_member_init_list, member_init);
1013 }
1070}
1071
1072/* This is like `expand_member_init', only it stores one aggregate
1073 value into another.
1074
1075 INIT comes in two flavors: it is either a value which
1076 is to be stored in EXP, or it is a parameter list
1077 to go to a constructor, which will operate on EXP.
1078 If INIT is not a parameter list for a constructor, then set
1079 LOOKUP_ONLYCONVERTING.
1080 If FLAGS is LOOKUP_ONLYCONVERTING then it is the = init form of
1081 the initializer, if FLAGS is 0, then it is the (init) form.
1082 If `init' is a CONSTRUCTOR, then we emit a warning message,
1083 explaining that such initializations are invalid.
1084
1085 ALIAS_THIS is nonzero iff we are initializing something which is
1014}
1015
1016/* This is like `expand_member_init', only it stores one aggregate
1017 value into another.
1018
1019 INIT comes in two flavors: it is either a value which
1020 is to be stored in EXP, or it is a parameter list
1021 to go to a constructor, which will operate on EXP.
1022 If INIT is not a parameter list for a constructor, then set
1023 LOOKUP_ONLYCONVERTING.
1024 If FLAGS is LOOKUP_ONLYCONVERTING then it is the = init form of
1025 the initializer, if FLAGS is 0, then it is the (init) form.
1026 If `init' is a CONSTRUCTOR, then we emit a warning message,
1027 explaining that such initializations are invalid.
1028
1029 ALIAS_THIS is nonzero iff we are initializing something which is
1086 essentially an alias for C_C_D. In this case, the base constructor
1087 may move it on us, and we must keep track of such deviations.
1030 essentially an alias for current_class_ref. In this case, the base
1031 constructor may move it on us, and we must keep track of such
1032 deviations.
1088
1089 If INIT resolves to a CALL_EXPR which happens to return
1090 something of the type we are looking for, then we know
1091 that we can safely use that call to perform the
1092 initialization.
1093
1094 The virtual function table pointer cannot be set up here, because
1095 we do not really know its type.
1096
1097 Virtual baseclass pointers are also set up here.
1098
1099 This never calls operator=().
1100
1101 When initializing, nothing is CONST.
1102
1103 A default copy constructor may have to be used to perform the
1104 initialization.
1105
1106 A constructor or a conversion operator may have to be used to
1033
1034 If INIT resolves to a CALL_EXPR which happens to return
1035 something of the type we are looking for, then we know
1036 that we can safely use that call to perform the
1037 initialization.
1038
1039 The virtual function table pointer cannot be set up here, because
1040 we do not really know its type.
1041
1042 Virtual baseclass pointers are also set up here.
1043
1044 This never calls operator=().
1045
1046 When initializing, nothing is CONST.
1047
1048 A default copy constructor may have to be used to perform the
1049 initialization.
1050
1051 A constructor or a conversion operator may have to be used to
1107 perform the initialization, but not both, as it would be ambiguous.
1108 */
1052 perform the initialization, but not both, as it would be ambiguous. */
1109
1110void
1111expand_aggr_init (exp, init, alias_this, flags)
1112 tree exp, init;
1113 int alias_this;
1114 int flags;
1115{
1116 tree type = TREE_TYPE (exp);

--- 64 unchanged lines hidden (view full) ---

1181 expand_aggr_init_1 (TYPE_BINFO (type), exp, exp,
1182 init, alias_this, LOOKUP_NORMAL|flags);
1183 TREE_TYPE (exp) = type;
1184 TREE_READONLY (exp) = was_const;
1185 TREE_THIS_VOLATILE (exp) = was_volatile;
1186}
1187
1188static void
1053
1054void
1055expand_aggr_init (exp, init, alias_this, flags)
1056 tree exp, init;
1057 int alias_this;
1058 int flags;
1059{
1060 tree type = TREE_TYPE (exp);

--- 64 unchanged lines hidden (view full) ---

1125 expand_aggr_init_1 (TYPE_BINFO (type), exp, exp,
1126 init, alias_this, LOOKUP_NORMAL|flags);
1127 TREE_TYPE (exp) = type;
1128 TREE_READONLY (exp) = was_const;
1129 TREE_THIS_VOLATILE (exp) = was_volatile;
1130}
1131
1132static void
1189expand_default_init (binfo, true_exp, exp, type, init, alias_this, flags)
1133expand_default_init (binfo, true_exp, exp, init, alias_this, flags)
1190 tree binfo;
1191 tree true_exp, exp;
1134 tree binfo;
1135 tree true_exp, exp;
1192 tree type;
1193 tree init;
1194 int alias_this;
1195 int flags;
1196{
1136 tree init;
1137 int alias_this;
1138 int flags;
1139{
1140 tree type = TREE_TYPE (exp);
1141
1197 /* It fails because there may not be a constructor which takes
1198 its own type as the first (or only parameter), but which does
1199 take other types via a conversion. So, if the thing initializing
1200 the expression is a unit element of type X, first try X(X&),
1201 followed by initialization by X. If neither of these work
1202 out, then look hard. */
1203 tree rval;
1204 tree parms;
1205
1142 /* It fails because there may not be a constructor which takes
1143 its own type as the first (or only parameter), but which does
1144 take other types via a conversion. So, if the thing initializing
1145 the expression is a unit element of type X, first try X(X&),
1146 followed by initialization by X. If neither of these work
1147 out, then look hard. */
1148 tree rval;
1149 tree parms;
1150
1151 if (init && TREE_CODE (init) != TREE_LIST
1152 && (flags & LOOKUP_ONLYCONVERTING))
1153 {
1154 /* Base subobjects should only get direct-initialization. */
1155 if (true_exp != exp)
1156 abort ();
1157
1158 /* We special-case TARGET_EXPRs here to avoid an error about
1159 private copy constructors for temporaries bound to reference vars.
1160 If the TARGET_EXPR represents a call to a function that has
1161 permission to create such objects, a reference can bind directly
1162 to the return value. An object variable must be initialized
1163 via the copy constructor, even if the call is elided. */
1164 if (! (TREE_CODE (exp) == VAR_DECL && DECL_ARTIFICIAL (exp)
1165 && TREE_CODE (init) == TARGET_EXPR && TREE_TYPE (init) == type))
1166 init = ocp_convert (type, init, CONV_IMPLICIT|CONV_FORCE_TEMP, flags);
1167
1168 if (TREE_CODE (init) == TRY_CATCH_EXPR)
1169 /* We need to protect the initialization of a catch parm
1170 with a call to terminate(), which shows up as a TRY_CATCH_EXPR
1171 around the TARGET_EXPR for the copy constructor. See
1172 expand_start_catch_block. */
1173 TREE_OPERAND (init, 0) = build (INIT_EXPR, TREE_TYPE (exp), exp,
1174 TREE_OPERAND (init, 0));
1175 else
1176 init = build (INIT_EXPR, TREE_TYPE (exp), exp, init);
1177 TREE_SIDE_EFFECTS (init) = 1;
1178 expand_expr_stmt (init);
1179 return;
1180 }
1181
1206 if (init == NULL_TREE
1207 || (TREE_CODE (init) == TREE_LIST && ! TREE_TYPE (init)))
1208 {
1209 parms = init;
1210 if (parms)
1211 init = TREE_VALUE (parms);
1212 }
1182 if (init == NULL_TREE
1183 || (TREE_CODE (init) == TREE_LIST && ! TREE_TYPE (init)))
1184 {
1185 parms = init;
1186 if (parms)
1187 init = TREE_VALUE (parms);
1188 }
1213 else if (TREE_CODE (init) == INDIRECT_REF && TREE_HAS_CONSTRUCTOR (init)
1214 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (init)))
1215 {
1216 rval = convert_for_initialization (exp, type, init, 0, 0, 0, 0);
1217 TREE_USED (rval) = 1;
1218 expand_expr_stmt (rval);
1219 return;
1220 }
1221 else
1189 else
1222 parms = build_tree_list (NULL_TREE, init);
1190 parms = build_expr_list (NULL_TREE, init);
1223
1224 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
1225 {
1226 if (true_exp == exp)
1191
1192 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
1193 {
1194 if (true_exp == exp)
1227 parms = tree_cons (NULL_TREE, integer_one_node, parms);
1195 parms = expr_tree_cons (NULL_TREE, integer_one_node, parms);
1228 else
1196 else
1229 parms = tree_cons (NULL_TREE, integer_zero_node, parms);
1197 parms = expr_tree_cons (NULL_TREE, integer_zero_node, parms);
1230 flags |= LOOKUP_HAS_IN_CHARGE;
1231 }
1232
1198 flags |= LOOKUP_HAS_IN_CHARGE;
1199 }
1200
1233 if (init && TREE_CHAIN (parms) == NULL_TREE
1234 && TYPE_HAS_TRIVIAL_INIT_REF (type)
1235 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (init)))
1236 {
1237 rval = build (INIT_EXPR, type, exp, init);
1238 TREE_SIDE_EFFECTS (rval) = 1;
1239 expand_expr_stmt (rval);
1240 }
1241 else
1242 {
1243 if (flags & LOOKUP_ONLYCONVERTING)
1244 flags |= LOOKUP_NO_CONVERSION;
1245 rval = build_method_call (exp, constructor_name_full (type),
1246 parms, binfo, flags);
1247
1248 /* Private, protected, or otherwise unavailable. */
1249 if (rval == error_mark_node)
1250 {
1251 if (flags & LOOKUP_COMPLAIN)
1252 cp_error ("in base initialization for %sclass `%T'",
1253 TREE_VIA_VIRTUAL (binfo) ? "virtual base " : "",
1254 binfo);
1255 }
1256 else if (rval == NULL_TREE)
1257 my_friendly_abort (361);
1258 else
1259 {
1260 /* p. 222: if the base class assigns to `this', then that
1261 value is used in the derived class. */
1262 if ((flag_this_is_variable & 1) && alias_this)
1263 {
1264 TREE_TYPE (rval) = TREE_TYPE (current_class_decl);
1265 expand_assignment (current_class_decl, rval, 0, 0);
1266 }
1267 else
1268 expand_expr_stmt (rval);
1269 }
1270 }
1201 rval = build_method_call (exp, ctor_identifier,
1202 parms, binfo, flags);
1203 if (TREE_SIDE_EFFECTS (rval))
1204 expand_expr_stmt (rval);
1271}
1272
1273/* This function is responsible for initializing EXP with INIT
1274 (if any).
1275
1276 BINFO is the binfo of the type for who we are performing the
1277 initialization. For example, if W is a virtual base class of A and B,
1278 and C : A, B.

--- 17 unchanged lines hidden (view full) ---

1296expand_aggr_init_1 (binfo, true_exp, exp, init, alias_this, flags)
1297 tree binfo;
1298 tree true_exp, exp;
1299 tree init;
1300 int alias_this;
1301 int flags;
1302{
1303 tree type = TREE_TYPE (exp);
1205}
1206
1207/* This function is responsible for initializing EXP with INIT
1208 (if any).
1209
1210 BINFO is the binfo of the type for who we are performing the
1211 initialization. For example, if W is a virtual base class of A and B,
1212 and C : A, B.

--- 17 unchanged lines hidden (view full) ---

1230expand_aggr_init_1 (binfo, true_exp, exp, init, alias_this, flags)
1231 tree binfo;
1232 tree true_exp, exp;
1233 tree init;
1234 int alias_this;
1235 int flags;
1236{
1237 tree type = TREE_TYPE (exp);
1304 tree init_type = NULL_TREE;
1305
1306 my_friendly_assert (init != error_mark_node && type != error_mark_node, 211);
1307
1308 /* Use a function returning the desired type to initialize EXP for us.
1309 If the function is a constructor, and its first argument is
1310 NULL_TREE, know that it was meant for us--just slide exp on
1311 in and expand the constructor. Constructors now come
1312 as TARGET_EXPRs. */
1238
1239 my_friendly_assert (init != error_mark_node && type != error_mark_node, 211);
1240
1241 /* Use a function returning the desired type to initialize EXP for us.
1242 If the function is a constructor, and its first argument is
1243 NULL_TREE, know that it was meant for us--just slide exp on
1244 in and expand the constructor. Constructors now come
1245 as TARGET_EXPRs. */
1313 if (init)
1314 {
1315 tree init_list = NULL_TREE;
1316
1246
1317 if (TREE_CODE (init) == TREE_LIST)
1247 if (init && TREE_CODE (exp) == VAR_DECL
1248 && TREE_CODE (init) == CONSTRUCTOR
1249 && TREE_HAS_CONSTRUCTOR (init))
1250 {
1251 tree t = store_init_value (exp, init);
1252 if (!t)
1318 {
1253 {
1319 init_list = init;
1320 if (TREE_CHAIN (init) == NULL_TREE)
1321 init = TREE_VALUE (init);
1322 }
1323
1324 init_type = TREE_TYPE (init);
1325
1326 if (TREE_CODE (init) != TREE_LIST)
1327 {
1328 if (TREE_CODE (init_type) == ERROR_MARK)
1329 return;
1330
1331#if 0
1332 /* These lines are found troublesome 5/11/89. */
1333 if (TREE_CODE (init_type) == REFERENCE_TYPE)
1334 init_type = TREE_TYPE (init_type);
1335#endif
1336
1337 /* This happens when we use C++'s functional cast notation.
1338 If the types match, then just use the TARGET_EXPR
1339 directly. Otherwise, we need to create the initializer
1340 separately from the object being initialized. */
1341 if (TREE_CODE (init) == TARGET_EXPR)
1342 {
1343 if (TYPE_MAIN_VARIANT (init_type) == TYPE_MAIN_VARIANT (type))
1344 {
1345 if (TREE_CODE (exp) == VAR_DECL
1346 || TREE_CODE (exp) == RESULT_DECL)
1347 /* Unify the initialization targets. */
1348 DECL_RTL (TREE_OPERAND (init, 0)) = DECL_RTL (exp);
1349 else
1350 DECL_RTL (TREE_OPERAND (init, 0)) = expand_expr (exp, NULL_RTX, 0, 0);
1351
1352 expand_expr_stmt (init);
1353 return;
1354 }
1355 else
1356 {
1357 init = TREE_OPERAND (init, 1);
1358 init = build (CALL_EXPR, init_type,
1359 TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), 0);
1360 TREE_SIDE_EFFECTS (init) = 1;
1361 if (init_list)
1362 TREE_VALUE (init_list) = init;
1363 }
1364 }
1365
1366 if (init_type == type && TREE_CODE (init) == CALL_EXPR
1367#if 0
1368 /* It is valid to directly initialize from a CALL_EXPR
1369 without going through X(X&), apparently. */
1370 && ! TYPE_GETS_INIT_REF (type)
1371#endif
1372 )
1373 {
1374 /* A CALL_EXPR is a legitimate form of initialization, so
1375 we should not print this warning message. */
1376#if 0
1377 /* Should have gone away due to 5/11/89 change. */
1378 if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
1379 init = convert_from_reference (init);
1380#endif
1381 expand_assignment (exp, init, 0, 0);
1382 if (exp == DECL_RESULT (current_function_decl))
1383 {
1384 /* Failing this assertion means that the return value
1385 from receives multiple initializations. */
1386 my_friendly_assert (DECL_INITIAL (exp) == NULL_TREE
1387 || DECL_INITIAL (exp) == error_mark_node,
1388 212);
1389 DECL_INITIAL (exp) = init;
1390 }
1391 return;
1392 }
1393 else if (init_type == type
1394 && TREE_CODE (init) == COND_EXPR)
1395 {
1396 /* Push value to be initialized into the cond, where possible.
1397 Avoid spurious warning messages when initializing the
1398 result of this function. */
1399 TREE_OPERAND (init, 1)
1400 = build_modify_expr (exp, INIT_EXPR, TREE_OPERAND (init, 1));
1401 if (exp == DECL_RESULT (current_function_decl))
1402 DECL_INITIAL (exp) = NULL_TREE;
1403 TREE_OPERAND (init, 2)
1404 = build_modify_expr (exp, INIT_EXPR, TREE_OPERAND (init, 2));
1405 if (exp == DECL_RESULT (current_function_decl))
1406 DECL_INITIAL (exp) = init;
1407 TREE_SIDE_EFFECTS (init) = 1;
1408 expand_expr (init, const0_rtx, VOIDmode, 0);
1409 free_temp_slots ();
1410 return;
1411 }
1412 }
1413
1414 /* We did not know what we were initializing before. Now we do. */
1415 if (TREE_CODE (init) == TARGET_EXPR)
1416 {
1417 tree tmp = TREE_OPERAND (TREE_OPERAND (init, 1), 1);
1418
1419 if (TREE_CODE (TREE_VALUE (tmp)) == NOP_EXPR
1420 && TREE_OPERAND (TREE_VALUE (tmp), 0) == integer_zero_node)
1421 {
1422 /* In order for this to work for RESULT_DECLs, if their
1423 type has a constructor, then they must be BLKmode
1424 so that they will be meaningfully addressable. */
1425 tree arg = build_unary_op (ADDR_EXPR, exp, 0);
1426 init = TREE_OPERAND (init, 1);
1427 init = build (CALL_EXPR, build_pointer_type (TREE_TYPE (init)),
1428 TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), 0);
1429 TREE_SIDE_EFFECTS (init) = 1;
1430 TREE_VALUE (TREE_OPERAND (init, 1))
1431 = convert_pointer_to (TREE_TYPE (TREE_TYPE (TREE_VALUE (tmp))), arg);
1432
1433 if (alias_this)
1434 {
1435 expand_assignment (current_function_decl, init, 0, 0);
1436 return;
1437 }
1438 if (exp == DECL_RESULT (current_function_decl))
1439 {
1440 if (DECL_INITIAL (DECL_RESULT (current_function_decl)))
1441 fatal ("return value from function receives multiple initializations");
1442 DECL_INITIAL (exp) = init;
1443 }
1444 expand_expr_stmt (init);
1445 return;
1446 }
1447 }
1448
1449 if (TREE_CODE (exp) == VAR_DECL
1450 && TREE_CODE (init) == CONSTRUCTOR
1451 && TREE_HAS_CONSTRUCTOR (init))
1452 {
1453 tree t = store_init_value (exp, init);
1454 if (!t)
1455 {
1456 expand_decl_init (exp);
1457 return;
1458 }
1459 t = build (INIT_EXPR, type, exp, init);
1460 TREE_SIDE_EFFECTS (t) = 1;
1461 expand_expr_stmt (t);
1254 expand_decl_init (exp);
1462 return;
1463 }
1255 return;
1256 }
1464
1465 /* Handle this case: when calling a constructor: xyzzy foo(bar);
1466 which really means: xyzzy foo = bar; Ugh!
1467
1468 More useful for this case: xyzzy *foo = new xyzzy (bar); */
1469
1470 if (! TYPE_NEEDS_CONSTRUCTING (type) && ! IS_AGGR_TYPE (type))
1471 {
1472 if (init_list && TREE_CHAIN (init_list))
1473 {
1474 warning ("initializer list being treated as compound expression");
1475 init = convert (type, build_compound_expr (init_list));
1476 if (init == error_mark_node)
1477 return;
1478 }
1479
1480 expand_assignment (exp, init, 0, 0);
1481
1482 return;
1483 }
1484 /* See whether we can go through a type conversion operator.
1485 This wins over going through a non-existent constructor. If
1486 there is a constructor, it is ambiguous. */
1487 if (TREE_CODE (init) != TREE_LIST)
1488 {
1489 tree ttype = TREE_CODE (init_type) == REFERENCE_TYPE
1490 ? TREE_TYPE (init_type) : init_type;
1491
1492 if (ttype != type && IS_AGGR_TYPE (ttype))
1493 {
1494 tree rval = build_type_conversion (CONVERT_EXPR, type, init, 0);
1495
1496 if (rval)
1497 {
1498 /* See if there is a constructor for``type'' that takes a
1499 ``ttype''-typed object. */
1500 tree parms = build_tree_list (NULL_TREE, init);
1501 tree as_cons = NULL_TREE;
1502 if (TYPE_HAS_CONSTRUCTOR (type))
1503 as_cons = build_method_call (exp, constructor_name_full (type),
1504 parms, binfo,
1505 LOOKUP_SPECULATIVELY|LOOKUP_NO_CONVERSION);
1506 if (as_cons != NULL_TREE && as_cons != error_mark_node)
1507 /* ANSI C++ June 5 1992 WP 12.3.2.6.1 */
1508 cp_error ("ambiguity between conversion to `%T' and constructor",
1509 type);
1510 else
1511 expand_assignment (exp, rval, 0, 0);
1512 return;
1513 }
1514 }
1515 }
1257 t = build (INIT_EXPR, type, exp, init);
1258 TREE_SIDE_EFFECTS (t) = 1;
1259 expand_expr_stmt (t);
1260 return;
1516 }
1517
1261 }
1262
1518 /* Handle default copy constructors here, does not matter if there is
1519 a constructor or not. */
1520 if (type == init_type && IS_AGGR_TYPE (type)
1521 && init && TREE_CODE (init) != TREE_LIST)
1522 expand_default_init (binfo, true_exp, exp, type, init, alias_this, flags);
1523 /* Not sure why this is here... */
1524 else if (TYPE_HAS_CONSTRUCTOR (type))
1525 expand_default_init (binfo, true_exp, exp, type, init, alias_this, flags);
1526 else if (TREE_CODE (type) == ARRAY_TYPE)
1527 {
1528 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type)))
1529 expand_vec_init (exp, exp, array_type_nelts (type), init, 0);
1530 else if (TYPE_VIRTUAL_P (TREE_TYPE (type)))
1531 sorry ("arrays of objects with virtual functions but no constructors");
1532 }
1533 else
1534 expand_recursive_init (binfo, true_exp, exp, init,
1535 CLASSTYPE_BASE_INIT_LIST (type), alias_this);
1263 /* We know that expand_default_init can handle everything we want
1264 at this point. */
1265 expand_default_init (binfo, true_exp, exp, init, alias_this, flags);
1536}
1537
1266}
1267
1538/* A pointer which holds the initializer. First call to
1539 expand_aggr_init gets this value pointed to, and sets it to init_null. */
1540static tree *init_ptr, init_null;
1541
1542/* Subroutine of expand_recursive_init:
1543
1544 ADDR is the address of the expression being initialized.
1545 INIT_LIST is the cons-list of initializations to be performed.
1546 ALIAS_THIS is its same, lovable self. */
1547static void
1548expand_recursive_init_1 (binfo, true_exp, addr, init_list, alias_this)
1549 tree binfo, true_exp, addr;
1550 tree init_list;
1551 int alias_this;
1552{
1553 while (init_list)
1554 {
1555 if (TREE_PURPOSE (init_list))
1556 {
1557 if (TREE_CODE (TREE_PURPOSE (init_list)) == FIELD_DECL)
1558 {
1559 tree member = TREE_PURPOSE (init_list);
1560 tree subexp = build_indirect_ref (convert_pointer_to (TREE_VALUE (init_list), addr), NULL_PTR);
1561 tree member_base = build (COMPONENT_REF, TREE_TYPE (member), subexp, member);
1562 if (IS_AGGR_TYPE (TREE_TYPE (member)))
1563 expand_aggr_init (member_base, DECL_INITIAL (member), 0, 0);
1564 else if (TREE_CODE (TREE_TYPE (member)) == ARRAY_TYPE
1565 && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (member)))
1566 {
1567 member_base = save_expr (default_conversion (member_base));
1568 expand_vec_init (member, member_base,
1569 array_type_nelts (TREE_TYPE (member)),
1570 DECL_INITIAL (member), 0);
1571 }
1572 else
1573 expand_expr_stmt (build_modify_expr (member_base, INIT_EXPR, DECL_INITIAL (member)));
1574 }
1575 else if (TREE_CODE (TREE_PURPOSE (init_list)) == TREE_LIST)
1576 {
1577 expand_recursive_init_1 (binfo, true_exp, addr, TREE_PURPOSE (init_list), alias_this);
1578 expand_recursive_init_1 (binfo, true_exp, addr, TREE_VALUE (init_list), alias_this);
1579 }
1580 else if (TREE_CODE (TREE_PURPOSE (init_list)) == ERROR_MARK)
1581 {
1582 /* Only initialize the virtual function tables if we
1583 are initializing the ultimate users of those vtables. */
1584 if (TREE_VALUE (init_list))
1585 {
1586 /* We have to ensure that the first argment to
1587 expand_virtual_init is in binfo's hierarchy. */
1588 /* Is it the case that this is exactly the right binfo? */
1589 /* If it is ok, then fixup expand_virtual_init, to make
1590 it much simpler. */
1591 expand_virtual_init (get_binfo (TREE_VALUE (init_list), binfo, 0),
1592 addr);
1593 if (TREE_VALUE (init_list) == binfo
1594 && TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
1595 expand_indirect_vtbls_init (binfo, true_exp, addr, 1);
1596 }
1597 }
1598 else
1599 my_friendly_abort (49);
1600 }
1601 else if (TREE_VALUE (init_list)
1602 && TREE_CODE (TREE_VALUE (init_list)) == TREE_VEC)
1603 {
1604 tree subexp = build_indirect_ref (convert_pointer_to (TREE_VALUE (init_list), addr), NULL_PTR);
1605 expand_aggr_init_1 (binfo, true_exp, subexp, *init_ptr,
1606 alias_this && BINFO_OFFSET_ZEROP (TREE_VALUE (init_list)),
1607 LOOKUP_COMPLAIN);
1608
1609 /* INIT_PTR is used up. */
1610 init_ptr = &init_null;
1611 }
1612 else
1613 my_friendly_abort (50);
1614 init_list = TREE_CHAIN (init_list);
1615 }
1616}
1617
1618/* Initialize EXP with INIT. Type EXP does not have a constructor,
1619 but it has a baseclass with a constructor or a virtual function
1620 table which needs initializing.
1621
1622 INIT_LIST is a cons-list describing what parts of EXP actually
1623 need to be initialized. INIT is given to the *unique*, first
1624 constructor within INIT_LIST. If there are multiple first
1625 constructors, such as with multiple inheritance, INIT must
1626 be zero or an ambiguity error is reported.
1627
1628 ALIAS_THIS is passed from `expand_aggr_init'. See comments
1629 there. */
1630
1631static void
1632expand_recursive_init (binfo, true_exp, exp, init, init_list, alias_this)
1633 tree binfo, true_exp, exp, init;
1634 tree init_list;
1635 int alias_this;
1636{
1637 tree *old_init_ptr = init_ptr;
1638 tree addr = build_unary_op (ADDR_EXPR, exp, 0);
1639 init_ptr = &init;
1640
1641 if (true_exp == exp && TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
1642 {
1643 expand_aggr_vbase_init (binfo, exp, addr, init_list);
1644 expand_indirect_vtbls_init (binfo, true_exp, addr, 1);
1645 }
1646 expand_recursive_init_1 (binfo, true_exp, addr, init_list, alias_this);
1647
1648 if (*init_ptr)
1649 {
1650 tree type = TREE_TYPE (exp);
1651
1652 if (TREE_CODE (type) == REFERENCE_TYPE)
1653 type = TREE_TYPE (type);
1654 if (IS_AGGR_TYPE (type))
1655 cp_error ("unexpected argument to constructor `%T'", type);
1656 else
1657 error ("unexpected argument to constructor");
1658 }
1659 init_ptr = old_init_ptr;
1660}
1661
1662/* Report an error if NAME is not the name of a user-defined,
1663 aggregate type. If OR_ELSE is nonzero, give an error message. */
1268/* Report an error if NAME is not the name of a user-defined,
1269 aggregate type. If OR_ELSE is nonzero, give an error message. */
1270
1664int
1665is_aggr_typedef (name, or_else)
1666 tree name;
1667 int or_else;
1668{
1669 tree type;
1670
1671 if (name == error_mark_node)

--- 4 unchanged lines hidden (view full) ---

1676 else
1677 {
1678 if (or_else)
1679 cp_error ("`%T' is not an aggregate typedef", name);
1680 return 0;
1681 }
1682
1683 if (! IS_AGGR_TYPE (type)
1271int
1272is_aggr_typedef (name, or_else)
1273 tree name;
1274 int or_else;
1275{
1276 tree type;
1277
1278 if (name == error_mark_node)

--- 4 unchanged lines hidden (view full) ---

1283 else
1284 {
1285 if (or_else)
1286 cp_error ("`%T' is not an aggregate typedef", name);
1287 return 0;
1288 }
1289
1290 if (! IS_AGGR_TYPE (type)
1684 && TREE_CODE (type) != TEMPLATE_TYPE_PARM)
1291 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1292 && TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM)
1685 {
1686 if (or_else)
1687 cp_error ("`%T' is not an aggregate type", type);
1688 return 0;
1689 }
1690 return 1;
1691}
1692
1293 {
1294 if (or_else)
1295 cp_error ("`%T' is not an aggregate type", type);
1296 return 0;
1297 }
1298 return 1;
1299}
1300
1301/* Report an error if TYPE is not a user-defined, aggregate type. If
1302 OR_ELSE is nonzero, give an error message. */
1303
1304int
1305is_aggr_type (type, or_else)
1306 tree type;
1307 int or_else;
1308{
1309 if (type == error_mark_node)
1310 return 0;
1311
1312 if (! IS_AGGR_TYPE (type)
1313 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1314 && TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM)
1315 {
1316 if (or_else)
1317 cp_error ("`%T' is not an aggregate type", type);
1318 return 0;
1319 }
1320 return 1;
1321}
1322
1693/* Like is_aggr_typedef, but returns typedef if successful. */
1323/* Like is_aggr_typedef, but returns typedef if successful. */
1324
1694tree
1695get_aggr_from_typedef (name, or_else)
1696 tree name;
1697 int or_else;
1698{
1699 tree type;
1700
1701 if (name == error_mark_node)

--- 4 unchanged lines hidden (view full) ---

1706 else
1707 {
1708 if (or_else)
1709 cp_error ("`%T' fails to be an aggregate typedef", name);
1710 return NULL_TREE;
1711 }
1712
1713 if (! IS_AGGR_TYPE (type)
1325tree
1326get_aggr_from_typedef (name, or_else)
1327 tree name;
1328 int or_else;
1329{
1330 tree type;
1331
1332 if (name == error_mark_node)

--- 4 unchanged lines hidden (view full) ---

1337 else
1338 {
1339 if (or_else)
1340 cp_error ("`%T' fails to be an aggregate typedef", name);
1341 return NULL_TREE;
1342 }
1343
1344 if (! IS_AGGR_TYPE (type)
1714 && TREE_CODE (type) != TEMPLATE_TYPE_PARM)
1345 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1346 && TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM)
1715 {
1716 if (or_else)
1717 cp_error ("type `%T' is of non-aggregate type", type);
1718 return NULL_TREE;
1719 }
1720 return type;
1721}
1722

--- 9 unchanged lines hidden (view full) ---

1732 else
1733 return NULL_TREE;
1734}
1735
1736
1737/* This code could just as well go in `class.c', but is placed here for
1738 modularity. */
1739
1347 {
1348 if (or_else)
1349 cp_error ("type `%T' is of non-aggregate type", type);
1350 return NULL_TREE;
1351 }
1352 return type;
1353}
1354

--- 9 unchanged lines hidden (view full) ---

1364 else
1365 return NULL_TREE;
1366}
1367
1368
1369/* This code could just as well go in `class.c', but is placed here for
1370 modularity. */
1371
1740/* For an expression of the form CNAME :: NAME (PARMLIST), build
1372/* For an expression of the form TYPE :: NAME (PARMLIST), build
1741 the appropriate function call. */
1373 the appropriate function call. */
1374
1742tree
1375tree
1743build_member_call (cname, name, parmlist)
1744 tree cname, name, parmlist;
1376build_member_call (type, name, parmlist)
1377 tree type, name, parmlist;
1745{
1378{
1746 tree type, t;
1747 tree method_name = name;
1379 tree t;
1380 tree method_name;
1748 int dtor = 0;
1749 int dont_use_this = 0;
1750 tree basetype_path, decl;
1751
1381 int dtor = 0;
1382 int dont_use_this = 0;
1383 tree basetype_path, decl;
1384
1385 if (TREE_CODE (name) == TEMPLATE_ID_EXPR
1386 && TREE_CODE (type) == NAMESPACE_DECL)
1387 {
1388 /* 'name' already refers to the decls from the namespace, since we
1389 hit do_identifier for template_ids. */
1390 my_friendly_assert (is_overloaded_fn (TREE_OPERAND (name, 0)), 980519);
1391 return build_x_function_call (name, parmlist, current_class_ref);
1392 }
1393
1394 if (type == std_node)
1395 return build_x_function_call (do_scoped_id (name, 0), parmlist,
1396 current_class_ref);
1397 if (TREE_CODE (type) == NAMESPACE_DECL)
1398 return build_x_function_call (lookup_namespace_name (type, name),
1399 parmlist, current_class_ref);
1400
1401 if (TREE_CODE (name) != TEMPLATE_ID_EXPR)
1402 method_name = name;
1403 else
1404 method_name = TREE_OPERAND (name, 0);
1405
1752 if (TREE_CODE (method_name) == BIT_NOT_EXPR)
1753 {
1754 method_name = TREE_OPERAND (method_name, 0);
1755 dtor = 1;
1756 }
1757
1406 if (TREE_CODE (method_name) == BIT_NOT_EXPR)
1407 {
1408 method_name = TREE_OPERAND (method_name, 0);
1409 dtor = 1;
1410 }
1411
1758 if (TREE_CODE (cname) == SCOPE_REF)
1759 cname = resolve_scope_to_name (NULL_TREE, cname);
1760
1761 /* This shouldn't be here, and build_member_call shouldn't appear in
1762 parse.y! (mrs) */
1412 /* This shouldn't be here, and build_member_call shouldn't appear in
1413 parse.y! (mrs) */
1763 if (cname && get_aggr_from_typedef (cname, 0) == 0
1764 && TREE_CODE (cname) == IDENTIFIER_NODE)
1414 if (type && TREE_CODE (type) == IDENTIFIER_NODE
1415 && get_aggr_from_typedef (type, 0) == 0)
1765 {
1416 {
1766 tree ns = lookup_name (cname, 0);
1417 tree ns = lookup_name (type, 0);
1767 if (ns && TREE_CODE (ns) == NAMESPACE_DECL)
1768 {
1418 if (ns && TREE_CODE (ns) == NAMESPACE_DECL)
1419 {
1769 return build_x_function_call (build_offset_ref (cname, name), parmlist, current_class_decl);
1420 return build_x_function_call (build_offset_ref (type, name), parmlist, current_class_ref);
1770 }
1771 }
1772
1421 }
1422 }
1423
1773 if (cname == NULL_TREE || ! (type = get_aggr_from_typedef (cname, 1)))
1424 if (type == NULL_TREE || ! is_aggr_type (type, 1))
1774 return error_mark_node;
1775
1776 /* An operator we did not like. */
1777 if (name == NULL_TREE)
1778 return error_mark_node;
1779
1780 if (dtor)
1781 {
1425 return error_mark_node;
1426
1427 /* An operator we did not like. */
1428 if (name == NULL_TREE)
1429 return error_mark_node;
1430
1431 if (dtor)
1432 {
1782#if 0
1783 /* Everything can explicitly call a destructor; see 12.4 */
1784 if (! TYPE_HAS_DESTRUCTOR (type))
1785 cp_error ("type `%#T' does not have a destructor", type);
1786 else
1787#endif
1788 cp_error ("cannot call destructor `%T::~%T' without object", type,
1789 method_name);
1790 return error_mark_node;
1791 }
1792
1793 /* No object? Then just fake one up, and let build_method_call
1794 figure out what to do. */
1795 if (current_class_type == 0
1796 || get_base_distance (type, current_class_type, 0, &basetype_path) == -1)
1797 dont_use_this = 1;
1798
1799 if (dont_use_this)
1800 {
1801 basetype_path = TYPE_BINFO (type);
1802 decl = build1 (NOP_EXPR, build_pointer_type (type), error_mark_node);
1803 }
1433 cp_error ("cannot call destructor `%T::~%T' without object", type,
1434 method_name);
1435 return error_mark_node;
1436 }
1437
1438 /* No object? Then just fake one up, and let build_method_call
1439 figure out what to do. */
1440 if (current_class_type == 0
1441 || get_base_distance (type, current_class_type, 0, &basetype_path) == -1)
1442 dont_use_this = 1;
1443
1444 if (dont_use_this)
1445 {
1446 basetype_path = TYPE_BINFO (type);
1447 decl = build1 (NOP_EXPR, build_pointer_type (type), error_mark_node);
1448 }
1804 else if (current_class_decl == 0)
1449 else if (current_class_ptr == 0)
1805 {
1806 dont_use_this = 1;
1807 decl = build1 (NOP_EXPR, build_pointer_type (type), error_mark_node);
1808 }
1809 else
1810 {
1450 {
1451 dont_use_this = 1;
1452 decl = build1 (NOP_EXPR, build_pointer_type (type), error_mark_node);
1453 }
1454 else
1455 {
1811 tree olddecl = current_class_decl;
1456 tree olddecl = current_class_ptr;
1812 tree oldtype = TREE_TYPE (TREE_TYPE (olddecl));
1813 if (oldtype != type)
1814 {
1815 tree newtype = build_type_variant (type, TYPE_READONLY (oldtype),
1816 TYPE_VOLATILE (oldtype));
1817 decl = convert_force (build_pointer_type (newtype), olddecl, 0);
1818 }
1819 else
1820 decl = olddecl;
1821 }
1822
1823 decl = build_indirect_ref (decl, NULL_PTR);
1824
1825 if (method_name == constructor_name (type)
1826 || method_name == constructor_name_full (type))
1827 return build_functional_cast (type, parmlist);
1457 tree oldtype = TREE_TYPE (TREE_TYPE (olddecl));
1458 if (oldtype != type)
1459 {
1460 tree newtype = build_type_variant (type, TYPE_READONLY (oldtype),
1461 TYPE_VOLATILE (oldtype));
1462 decl = convert_force (build_pointer_type (newtype), olddecl, 0);
1463 }
1464 else
1465 decl = olddecl;
1466 }
1467
1468 decl = build_indirect_ref (decl, NULL_PTR);
1469
1470 if (method_name == constructor_name (type)
1471 || method_name == constructor_name_full (type))
1472 return build_functional_cast (type, parmlist);
1828 if (t = lookup_fnfields (basetype_path, method_name, 0))
1829 return build_method_call (decl, method_name, parmlist, basetype_path,
1473 if ((t = lookup_fnfields (basetype_path, method_name, 0)))
1474 return build_method_call (decl,
1475 TREE_CODE (name) == TEMPLATE_ID_EXPR
1476 ? name : method_name,
1477 parmlist, basetype_path,
1830 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL);
1831 if (TREE_CODE (name) == IDENTIFIER_NODE
1832 && ((t = lookup_field (TYPE_BINFO (type), name, 1, 0))))
1833 {
1834 if (t == error_mark_node)
1835 return error_mark_node;
1836 if (TREE_CODE (t) == FIELD_DECL)
1837 {

--- 6 unchanged lines hidden (view full) ---

1844 }
1845 else if (TREE_CODE (t) == VAR_DECL)
1846 decl = t;
1847 else
1848 {
1849 cp_error ("invalid use of member `%D'", t);
1850 return error_mark_node;
1851 }
1478 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL);
1479 if (TREE_CODE (name) == IDENTIFIER_NODE
1480 && ((t = lookup_field (TYPE_BINFO (type), name, 1, 0))))
1481 {
1482 if (t == error_mark_node)
1483 return error_mark_node;
1484 if (TREE_CODE (t) == FIELD_DECL)
1485 {

--- 6 unchanged lines hidden (view full) ---

1492 }
1493 else if (TREE_CODE (t) == VAR_DECL)
1494 decl = t;
1495 else
1496 {
1497 cp_error ("invalid use of member `%D'", t);
1498 return error_mark_node;
1499 }
1852 if (TYPE_LANG_SPECIFIC (TREE_TYPE (decl))
1853 && TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (decl)))
1854 return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, decl, parmlist, NULL_TREE);
1500 if (TYPE_LANG_SPECIFIC (TREE_TYPE (decl)))
1501 return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, decl,
1502 parmlist, NULL_TREE);
1855 return build_function_call (decl, parmlist);
1856 }
1857 else
1858 {
1859 cp_error ("no method `%T::%D'", type, name);
1860 return error_mark_node;
1861 }
1862}
1863
1864/* Build a reference to a member of an aggregate. This is not a
1865 C++ `&', but really something which can have its address taken,
1503 return build_function_call (decl, parmlist);
1504 }
1505 else
1506 {
1507 cp_error ("no method `%T::%D'", type, name);
1508 return error_mark_node;
1509 }
1510}
1511
1512/* Build a reference to a member of an aggregate. This is not a
1513 C++ `&', but really something which can have its address taken,
1866 and then act as a pointer to member, for example CNAME :: FIELD
1867 can have its address taken by saying & CNAME :: FIELD.
1514 and then act as a pointer to member, for example TYPE :: FIELD
1515 can have its address taken by saying & TYPE :: FIELD.
1868
1869 @@ Prints out lousy diagnostics for operator <typename>
1870 @@ fields.
1871
1872 @@ This function should be rewritten and placed in search.c. */
1516
1517 @@ Prints out lousy diagnostics for operator <typename>
1518 @@ fields.
1519
1520 @@ This function should be rewritten and placed in search.c. */
1521
1873tree
1522tree
1874build_offset_ref (cname, name)
1875 tree cname, name;
1523build_offset_ref (type, name)
1524 tree type, name;
1876{
1525{
1877 tree decl, type, fnfields, fields, t = error_mark_node;
1878 tree basetypes = NULL_TREE;
1879 int dtor = 0;
1526 tree decl, fnfields, fields, t = error_mark_node;
1527 tree basebinfo = NULL_TREE;
1528 tree orig_name = name;
1880
1529
1881 if (TREE_CODE (cname) == SCOPE_REF)
1882 cname = resolve_scope_to_name (NULL_TREE, cname);
1530 /* class templates can come in as TEMPLATE_DECLs here. */
1531 if (TREE_CODE (name) == TEMPLATE_DECL)
1532 return name;
1883
1533
1534 if (type == std_node)
1535 return do_scoped_id (name, 0);
1536
1537 if (processing_template_decl || uses_template_parms (type))
1538 return build_min_nt (SCOPE_REF, type, name);
1539
1884 /* Handle namespace names fully here. */
1540 /* Handle namespace names fully here. */
1885 if (TREE_CODE (cname) == IDENTIFIER_NODE
1886 && get_aggr_from_typedef (cname, 0) == 0)
1541 if (TREE_CODE (type) == NAMESPACE_DECL)
1887 {
1542 {
1888 tree ns = lookup_name (cname, 0);
1889 tree val;
1890 if (ns && TREE_CODE (ns) == NAMESPACE_DECL)
1543 t = lookup_namespace_name (type, name);
1544 if (! type_unknown_p (t))
1891 {
1545 {
1892 val = lookup_namespace_name (ns, name);
1893 if (val)
1894 return val;
1895 cp_error ("namespace `%D' has no member named `%D'", ns, name);
1896 return error_mark_node;
1546 mark_used (t);
1547 t = convert_from_reference (t);
1897 }
1548 }
1549 return t;
1898 }
1899
1550 }
1551
1900 if (cname == NULL_TREE || ! is_aggr_typedef (cname, 1))
1552 if (type == NULL_TREE || ! is_aggr_type (type, 1))
1901 return error_mark_node;
1902
1553 return error_mark_node;
1554
1903 type = IDENTIFIER_TYPE_VALUE (cname);
1555 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
1556 {
1557 /* If the NAME is a TEMPLATE_ID_EXPR, we are looking at
1558 something like `a.template f<int>' or the like. For the most
1559 part, we treat this just like a.f. We do remember, however,
1560 the template-id that was used. */
1561 name = TREE_OPERAND (orig_name, 0);
1562 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 0);
1563 }
1904
1905 if (TREE_CODE (name) == BIT_NOT_EXPR)
1906 {
1564
1565 if (TREE_CODE (name) == BIT_NOT_EXPR)
1566 {
1907 dtor = 1;
1908 name = TREE_OPERAND (name, 0);
1567 if (! check_dtor_name (type, name))
1568 cp_error ("qualified type `%T' does not match destructor name `~%T'",
1569 type, TREE_OPERAND (name, 0));
1570 name = dtor_identifier;
1909 }
1571 }
1572#if 0
1573 /* I think this is wrong, but the draft is unclear. --jason 6/15/98 */
1574 else if (name == constructor_name_full (type)
1575 || name == constructor_name (type))
1576 name = ctor_identifier;
1577#endif
1910
1578
1911 if (TYPE_SIZE (type) == 0)
1579 if (TYPE_SIZE (complete_type (type)) == 0)
1912 {
1580 {
1913 t = IDENTIFIER_CLASS_VALUE (name);
1581 if (type == current_class_type)
1582 t = IDENTIFIER_CLASS_VALUE (name);
1583 else
1584 t = NULL_TREE;
1914 if (t == 0)
1915 {
1916 cp_error ("incomplete type `%T' does not have member `%D'", type,
1917 name);
1918 return error_mark_node;
1919 }
1920 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == VAR_DECL
1921 || TREE_CODE (t) == CONST_DECL)
1922 {
1585 if (t == 0)
1586 {
1587 cp_error ("incomplete type `%T' does not have member `%D'", type,
1588 name);
1589 return error_mark_node;
1590 }
1591 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == VAR_DECL
1592 || TREE_CODE (t) == CONST_DECL)
1593 {
1923 TREE_USED (t) = 1;
1594 mark_used (t);
1924 return t;
1925 }
1926 if (TREE_CODE (t) == FIELD_DECL)
1927 sorry ("use of member in incomplete aggregate type");
1928 else if (TREE_CODE (t) == FUNCTION_DECL)
1929 sorry ("use of member function in incomplete aggregate type");
1930 else
1931 my_friendly_abort (52);
1932 return error_mark_node;
1933 }
1934
1595 return t;
1596 }
1597 if (TREE_CODE (t) == FIELD_DECL)
1598 sorry ("use of member in incomplete aggregate type");
1599 else if (TREE_CODE (t) == FUNCTION_DECL)
1600 sorry ("use of member function in incomplete aggregate type");
1601 else
1602 my_friendly_abort (52);
1603 return error_mark_node;
1604 }
1605
1935#if 0
1936 if (TREE_CODE (name) == TYPE_EXPR)
1937 /* Pass a TYPE_DECL to build_component_type_expr. */
1938 return build_component_type_expr (TYPE_NAME (TREE_TYPE (cname)),
1939 name, NULL_TREE, 1);
1940#endif
1941
1942 if (current_class_type == 0
1606 if (current_class_type == 0
1943 || get_base_distance (type, current_class_type, 0, &basetypes) == -1)
1607 || get_base_distance (type, current_class_type, 0, &basebinfo) == -1)
1944 {
1608 {
1945 basetypes = TYPE_BINFO (type);
1946 decl = build1 (NOP_EXPR,
1947 IDENTIFIER_TYPE_VALUE (cname),
1948 error_mark_node);
1609 basebinfo = TYPE_BINFO (type);
1610 decl = build1 (NOP_EXPR, type, error_mark_node);
1949 }
1611 }
1950 else if (current_class_decl == 0)
1951 decl = build1 (NOP_EXPR, IDENTIFIER_TYPE_VALUE (cname),
1952 error_mark_node);
1612 else if (current_class_ptr == 0)
1613 decl = build1 (NOP_EXPR, type, error_mark_node);
1953 else
1614 else
1954 decl = C_C_D;
1615 decl = current_class_ref;
1955
1616
1956 fnfields = lookup_fnfields (basetypes, name, 1);
1957 fields = lookup_field (basetypes, name, 0, 0);
1617 fnfields = lookup_fnfields (basebinfo, name, 1);
1618 fields = lookup_field (basebinfo, name, 0, 0);
1958
1959 if (fields == error_mark_node || fnfields == error_mark_node)
1960 return error_mark_node;
1961
1962 /* A lot of this logic is now handled in lookup_field and
1619
1620 if (fields == error_mark_node || fnfields == error_mark_node)
1621 return error_mark_node;
1622
1623 /* A lot of this logic is now handled in lookup_field and
1963 lookup_fnfield. */
1624 lookup_fnfield. */
1964 if (fnfields)
1965 {
1625 if (fnfields)
1626 {
1966 basetypes = TREE_PURPOSE (fnfields);
1627 extern int flag_save_memoized_contexts;
1967
1968 /* Go from the TREE_BASELINK to the member function info. */
1969 t = TREE_VALUE (fnfields);
1970
1628
1629 /* Go from the TREE_BASELINK to the member function info. */
1630 t = TREE_VALUE (fnfields);
1631
1971 if (fields)
1632 if (TREE_CODE (orig_name) == TEMPLATE_ID_EXPR)
1972 {
1633 {
1973 if (DECL_FIELD_CONTEXT (fields) == DECL_FIELD_CONTEXT (t))
1974 {
1975 error ("ambiguous member reference: member `%s' defined as both field and function",
1976 IDENTIFIER_POINTER (name));
1977 return error_mark_node;
1978 }
1979 if (UNIQUELY_DERIVED_FROM_P (DECL_FIELD_CONTEXT (fields), DECL_FIELD_CONTEXT (t)))
1980 ;
1981 else if (UNIQUELY_DERIVED_FROM_P (DECL_FIELD_CONTEXT (t), DECL_FIELD_CONTEXT (fields)))
1982 t = fields;
1983 else
1984 {
1985 error ("ambiguous member reference: member `%s' derives from distinct classes in multiple inheritance lattice");
1986 return error_mark_node;
1987 }
1634 /* The FNFIELDS are going to contain functions that aren't
1635 necessarily templates, and templates that don't
1636 necessarily match the explicit template parameters. We
1637 save all the functions, and the explicit parameters, and
1638 then figure out exactly what to instantiate with what
1639 arguments in instantiate_type. */
1640
1641 if (TREE_CODE (t) != OVERLOAD)
1642 /* The code in instantiate_type which will process this
1643 expects to encounter OVERLOADs, not raw functions. */
1644 t = ovl_cons (t, NULL_TREE);
1645
1646 return build (OFFSET_REF,
1647 build_offset_type (type, unknown_type_node),
1648 decl,
1649 build (TEMPLATE_ID_EXPR,
1650 TREE_TYPE (t),
1651 t,
1652 TREE_OPERAND (orig_name, 1)));
1988 }
1989
1653 }
1654
1990 if (t == TREE_VALUE (fnfields))
1655 if (!really_overloaded_fn (t))
1991 {
1656 {
1992 extern int flag_save_memoized_contexts;
1657 tree access;
1993
1658
1994 if (DECL_CHAIN (t) == NULL_TREE || dtor)
1995 {
1996 enum access_type access;
1659 /* Get rid of a potential OVERLOAD around it */
1660 t = OVL_CURRENT (t);
1997
1661
1998 /* unique functions are handled easily. */
1999 unique:
2000 access = compute_access (basetypes, t);
2001 if (access == access_protected)
2002 {
2003 cp_error_at ("member function `%#D' is protected", t);
2004 error ("in this context");
2005 return error_mark_node;
2006 }
2007 if (access == access_private)
2008 {
2009 cp_error_at ("member function `%#D' is private", t);
2010 error ("in this context");
2011 return error_mark_node;
2012 }
2013 assemble_external (t);
2014 return build (OFFSET_REF, TREE_TYPE (t), decl, t);
1662 /* unique functions are handled easily. */
1663 basebinfo = TREE_PURPOSE (fnfields);
1664 access = compute_access (basebinfo, t);
1665 if (access == access_protected_node)
1666 {
1667 cp_error_at ("member function `%#D' is protected", t);
1668 error ("in this context");
1669 return error_mark_node;
2015 }
1670 }
2016
2017 /* overloaded functions may need more work. */
2018 if (cname == name)
1671 if (access == access_private_node)
2019 {
1672 {
2020 if (TYPE_HAS_DESTRUCTOR (type)
2021 && DECL_CHAIN (DECL_CHAIN (t)) == NULL_TREE)
2022 {
2023 t = DECL_CHAIN (t);
2024 goto unique;
2025 }
1673 cp_error_at ("member function `%#D' is private", t);
1674 error ("in this context");
1675 return error_mark_node;
2026 }
1676 }
2027 /* FNFIELDS is most likely allocated on the search_obstack,
2028 which will go away after this class scope. If we need
2029 to save this value for later (either for memoization
2030 or for use as an initializer for a static variable), then
2031 do so here.
1677 mark_used (t);
1678 return build (OFFSET_REF, TREE_TYPE (t), decl, t);
1679 }
2032
1680
2033 ??? The smart thing to do for the case of saving initializers
2034 is to resolve them before we're done with this scope. */
2035 if (!TREE_PERMANENT (fnfields)
2036 && ((flag_save_memoized_contexts && global_bindings_p ())
2037 || ! allocation_temporary_p ()))
2038 fnfields = copy_list (fnfields);
1681 /* FNFIELDS is most likely allocated on the search_obstack,
1682 which will go away after this class scope. If we need
1683 to save this value for later (either for memoization
1684 or for use as an initializer for a static variable), then
1685 do so here.
2039
1686
2040 for (t = TREE_VALUE (fnfields); t; t = DECL_CHAIN (t))
2041 assemble_external (t);
1687 ??? The smart thing to do for the case of saving initializers
1688 is to resolve them before we're done with this scope. */
1689 if (!TREE_PERMANENT (fnfields)
1690 && ((flag_save_memoized_contexts && toplevel_bindings_p ())
1691 || ! allocation_temporary_p ()))
1692 fnfields = copy_list (fnfields);
2042
1693
2043 t = build_tree_list (error_mark_node, fnfields);
2044 TREE_TYPE (t) = build_offset_type (type, unknown_type_node);
2045 return t;
2046 }
1694 t = build_tree_list (error_mark_node, fnfields);
1695 TREE_TYPE (t) = build_offset_type (type, unknown_type_node);
1696 return t;
2047 }
2048
2049 /* Now that we know we are looking for a field, see if we
2050 have access to that field. Lookup_field will give us the
2051 error message. */
2052
1697 }
1698
1699 /* Now that we know we are looking for a field, see if we
1700 have access to that field. Lookup_field will give us the
1701 error message. */
1702
2053 t = lookup_field (basetypes, name, 1, 0);
1703 t = lookup_field (basebinfo, name, 1, 0);
2054
2055 if (t == error_mark_node)
2056 return error_mark_node;
2057
2058 if (t == NULL_TREE)
2059 {
2060 cp_error ("`%D' is not a member of type `%T'", name, type);
2061 return error_mark_node;
2062 }
2063
2064 if (TREE_CODE (t) == TYPE_DECL)
2065 {
2066 TREE_USED (t) = 1;
2067 return t;
2068 }
2069 /* static class members and class-specific enum
2070 values can be returned without further ado. */
2071 if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == CONST_DECL)
2072 {
1704
1705 if (t == error_mark_node)
1706 return error_mark_node;
1707
1708 if (t == NULL_TREE)
1709 {
1710 cp_error ("`%D' is not a member of type `%T'", name, type);
1711 return error_mark_node;
1712 }
1713
1714 if (TREE_CODE (t) == TYPE_DECL)
1715 {
1716 TREE_USED (t) = 1;
1717 return t;
1718 }
1719 /* static class members and class-specific enum
1720 values can be returned without further ado. */
1721 if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == CONST_DECL)
1722 {
2073 assemble_external (t);
2074 TREE_USED (t) = 1;
2075 return t;
1723 mark_used (t);
1724 return convert_from_reference (t);
2076 }
2077
2078 if (TREE_CODE (t) == FIELD_DECL && DECL_BIT_FIELD (t))
2079 {
2080 cp_error ("illegal pointer to bit field `%D'", t);
2081 return error_mark_node;
2082 }
2083
2084 /* static class functions too. */
1725 }
1726
1727 if (TREE_CODE (t) == FIELD_DECL && DECL_BIT_FIELD (t))
1728 {
1729 cp_error ("illegal pointer to bit field `%D'", t);
1730 return error_mark_node;
1731 }
1732
1733 /* static class functions too. */
2085 if (TREE_CODE (t) == FUNCTION_DECL && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1734 if (TREE_CODE (t) == FUNCTION_DECL
1735 && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
2086 my_friendly_abort (53);
2087
1736 my_friendly_abort (53);
1737
2088 /* In member functions, the form `cname::name' is no longer
2089 equivalent to `this->cname::name'. */
1738 /* In member functions, the form `type::name' is no longer
1739 equivalent to `this->type::name', at least not until
1740 resolve_offset_ref. */
2090 return build (OFFSET_REF, build_offset_type (type, TREE_TYPE (t)), decl, t);
2091}
2092
1741 return build (OFFSET_REF, build_offset_type (type, TREE_TYPE (t)), decl, t);
1742}
1743
2093/* Given an object EXP and a member function reference MEMBER,
2094 return the address of the actual member function. */
2095tree
2096get_member_function (exp_addr_ptr, exp, member)
2097 tree *exp_addr_ptr;
2098 tree exp, member;
2099{
2100 tree ctype = TREE_TYPE (exp);
2101 tree function = save_expr (build_unary_op (ADDR_EXPR, member, 0));
2102
2103 if (TYPE_VIRTUAL_P (ctype)
2104 || (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (ctype)))
2105 {
2106 tree e0, e1, e3;
2107 tree exp_addr;
2108
2109 /* Save away the unadulterated `this' pointer. */
2110 exp_addr = save_expr (*exp_addr_ptr);
2111
2112 /* Cast function to signed integer. */
2113 e0 = build1 (NOP_EXPR, integer_type_node, function);
2114
2115 /* There is a hack here that takes advantage of
2116 twos complement arithmetic, and the fact that
2117 there are more than one UNITS to the WORD.
2118 If the high bit is set for the `function',
2119 then we pretend it is a virtual function,
2120 and the array indexing will knock this bit
2121 out the top, leaving a valid index. */
2122 if (UNITS_PER_WORD <= 1)
2123 my_friendly_abort (54);
2124
2125 e1 = build (GT_EXPR, boolean_type_node, e0, integer_zero_node);
2126 e1 = build_compound_expr (tree_cons (NULL_TREE, exp_addr,
2127 build_tree_list (NULL_TREE, e1)));
2128 e1 = save_expr (e1);
2129
2130 if (TREE_SIDE_EFFECTS (*exp_addr_ptr))
2131 {
2132 exp = build_indirect_ref (exp_addr, NULL_PTR);
2133 *exp_addr_ptr = exp_addr;
2134 }
2135
2136 /* This is really hairy: if the function pointer is a pointer
2137 to a non-virtual member function, then we can't go mucking
2138 with the `this' pointer (any more than we already have to
2139 this point). If it is a pointer to a virtual member function,
2140 then we have to adjust the `this' pointer according to
2141 what the virtual function table tells us. */
2142
2143 e3 = build_vfn_ref (exp_addr_ptr, exp, e0);
2144 my_friendly_assert (e3 != error_mark_node, 213);
2145
2146 /* Change this pointer type from `void *' to the
2147 type it is really supposed to be. */
2148 TREE_TYPE (e3) = TREE_TYPE (function);
2149
2150 /* If non-virtual, use what we had originally. Otherwise,
2151 use the value we get from the virtual function table. */
2152 *exp_addr_ptr = build_conditional_expr (e1, exp_addr, *exp_addr_ptr);
2153
2154 function = build_conditional_expr (e1, function, e3);
2155 }
2156 return build_indirect_ref (function, NULL_PTR);
2157}
2158
2159/* If a OFFSET_REF made it through to here, then it did
2160 not have its address taken. */
2161
2162tree
2163resolve_offset_ref (exp)
2164 tree exp;
2165{
2166 tree type = TREE_TYPE (exp);
2167 tree base = NULL_TREE;
2168 tree member;
2169 tree basetype, addr;
2170
2171 if (TREE_CODE (exp) == TREE_LIST)
1744/* If a OFFSET_REF made it through to here, then it did
1745 not have its address taken. */
1746
1747tree
1748resolve_offset_ref (exp)
1749 tree exp;
1750{
1751 tree type = TREE_TYPE (exp);
1752 tree base = NULL_TREE;
1753 tree member;
1754 tree basetype, addr;
1755
1756 if (TREE_CODE (exp) == TREE_LIST)
2172 return build_unary_op (ADDR_EXPR, exp, 0);
1757 {
1758 cp_pedwarn ("assuming & on overloaded member function");
1759 return build_unary_op (ADDR_EXPR, exp, 0);
1760 }
2173
1761
2174 if (TREE_CODE (exp) != OFFSET_REF)
1762 if (TREE_CODE (exp) == OFFSET_REF)
2175 {
1763 {
1764 member = TREE_OPERAND (exp, 1);
1765 base = TREE_OPERAND (exp, 0);
1766 }
1767 else
1768 {
2176 my_friendly_assert (TREE_CODE (type) == OFFSET_TYPE, 214);
2177 if (TYPE_OFFSET_BASETYPE (type) != current_class_type)
2178 {
2179 error ("object missing in use of pointer-to-member construct");
2180 return error_mark_node;
2181 }
2182 member = exp;
2183 type = TREE_TYPE (type);
1769 my_friendly_assert (TREE_CODE (type) == OFFSET_TYPE, 214);
1770 if (TYPE_OFFSET_BASETYPE (type) != current_class_type)
1771 {
1772 error ("object missing in use of pointer-to-member construct");
1773 return error_mark_node;
1774 }
1775 member = exp;
1776 type = TREE_TYPE (type);
2184 base = C_C_D;
1777 base = current_class_ref;
2185 }
1778 }
2186 else
2187 {
2188 member = TREE_OPERAND (exp, 1);
2189 base = TREE_OPERAND (exp, 0);
2190 }
2191
2192 if ((TREE_CODE (member) == VAR_DECL
2193 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (member)))
1779
1780 if ((TREE_CODE (member) == VAR_DECL
1781 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (member)))
2194 || TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE)
1782 || TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE
1783 || TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE)
2195 {
2196 /* These were static members. */
2197 if (mark_addressable (member) == 0)
2198 return error_mark_node;
2199 return member;
2200 }
2201
1784 {
1785 /* These were static members. */
1786 if (mark_addressable (member) == 0)
1787 return error_mark_node;
1788 return member;
1789 }
1790
1791 if (TREE_CODE (TREE_TYPE (member)) == POINTER_TYPE
1792 && TREE_CODE (TREE_TYPE (TREE_TYPE (member))) == METHOD_TYPE)
1793 return member;
1794
2202 /* Syntax error can cause a member which should
2203 have been seen as static to be grok'd as non-static. */
1795 /* Syntax error can cause a member which should
1796 have been seen as static to be grok'd as non-static. */
2204 if (TREE_CODE (member) == FIELD_DECL && C_C_D == NULL_TREE)
1797 if (TREE_CODE (member) == FIELD_DECL && current_class_ref == NULL_TREE)
2205 {
2206 if (TREE_ADDRESSABLE (member) == 0)
2207 {
2208 cp_error_at ("member `%D' is non-static but referenced as a static member",
2209 member);
2210 error ("at this point in file");
2211 TREE_ADDRESSABLE (member) = 1;
2212 }
2213 return error_mark_node;
2214 }
2215
2216 /* The first case is really just a reference to a member of `this'. */
2217 if (TREE_CODE (member) == FIELD_DECL
1798 {
1799 if (TREE_ADDRESSABLE (member) == 0)
1800 {
1801 cp_error_at ("member `%D' is non-static but referenced as a static member",
1802 member);
1803 error ("at this point in file");
1804 TREE_ADDRESSABLE (member) = 1;
1805 }
1806 return error_mark_node;
1807 }
1808
1809 /* The first case is really just a reference to a member of `this'. */
1810 if (TREE_CODE (member) == FIELD_DECL
2218 && (base == C_C_D
1811 && (base == current_class_ref
2219 || (TREE_CODE (base) == NOP_EXPR
2220 && TREE_OPERAND (base, 0) == error_mark_node)))
2221 {
1812 || (TREE_CODE (base) == NOP_EXPR
1813 && TREE_OPERAND (base, 0) == error_mark_node)))
1814 {
2222 tree basetype_path;
2223 enum access_type access;
1815 tree basetype_path, access;
2224
2225 if (TREE_CODE (exp) == OFFSET_REF && TREE_CODE (type) == OFFSET_TYPE)
2226 basetype = TYPE_OFFSET_BASETYPE (type);
2227 else
2228 basetype = DECL_CONTEXT (member);
2229
1816
1817 if (TREE_CODE (exp) == OFFSET_REF && TREE_CODE (type) == OFFSET_TYPE)
1818 basetype = TYPE_OFFSET_BASETYPE (type);
1819 else
1820 basetype = DECL_CONTEXT (member);
1821
2230 base = current_class_decl;
1822 base = current_class_ptr;
2231
2232 if (get_base_distance (basetype, TREE_TYPE (TREE_TYPE (base)), 0, &basetype_path) < 0)
2233 {
2234 error_not_base_type (basetype, TREE_TYPE (TREE_TYPE (base)));
2235 return error_mark_node;
2236 }
1823
1824 if (get_base_distance (basetype, TREE_TYPE (TREE_TYPE (base)), 0, &basetype_path) < 0)
1825 {
1826 error_not_base_type (basetype, TREE_TYPE (TREE_TYPE (base)));
1827 return error_mark_node;
1828 }
2237 addr = convert_pointer_to (basetype, base);
1829 /* Kludge: we need to use basetype_path now, because
1830 convert_pointer_to will bash it. */
2238 access = compute_access (basetype_path, member);
1831 access = compute_access (basetype_path, member);
2239 if (access == access_public)
1832 addr = convert_pointer_to (basetype, base);
1833 if (access == access_public_node)
2240 return build (COMPONENT_REF, TREE_TYPE (member),
2241 build_indirect_ref (addr, NULL_PTR), member);
1834 return build (COMPONENT_REF, TREE_TYPE (member),
1835 build_indirect_ref (addr, NULL_PTR), member);
2242 if (access == access_protected)
1836 if (access == access_protected_node)
2243 {
2244 cp_error_at ("member `%D' is protected", member);
2245 error ("in this context");
2246 return error_mark_node;
2247 }
1837 {
1838 cp_error_at ("member `%D' is protected", member);
1839 error ("in this context");
1840 return error_mark_node;
1841 }
2248 if (access == access_private)
1842 if (access == access_private_node)
2249 {
2250 cp_error_at ("member `%D' is private", member);
2251 error ("in this context");
2252 return error_mark_node;
2253 }
2254 my_friendly_abort (55);
2255 }
2256
1843 {
1844 cp_error_at ("member `%D' is private", member);
1845 error ("in this context");
1846 return error_mark_node;
1847 }
1848 my_friendly_abort (55);
1849 }
1850
2257 /* If this is a reference to a member function, then return
2258 the address of the member function (which may involve going
2259 through the object's vtable), otherwise, return an expression
2260 for the dereferenced pointer-to-member construct. */
2261 addr = build_unary_op (ADDR_EXPR, base, 0);
2262
2263 if (TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE)
1851 /* Ensure that we have an object. */
1852 if (TREE_CODE (base) == NOP_EXPR
1853 && TREE_OPERAND (base, 0) == error_mark_node)
1854 addr = error_mark_node;
1855 else
2264 {
1856 {
2265 basetype = DECL_CLASS_CONTEXT (member);
2266 addr = convert_pointer_to (basetype, addr);
2267 return build_unary_op (ADDR_EXPR, get_member_function (&addr, build_indirect_ref (addr, NULL_PTR), member), 0);
1857 /* If this is a reference to a member function, then return the
1858 address of the member function (which may involve going
1859 through the object's vtable), otherwise, return an expression
1860 for the dereferenced pointer-to-member construct. */
1861 addr = build_unary_op (ADDR_EXPR, base, 0);
2268 }
1862 }
2269 else if (TREE_CODE (TREE_TYPE (member)) == OFFSET_TYPE)
1863
1864 if (TREE_CODE (TREE_TYPE (member)) == OFFSET_TYPE)
2270 {
1865 {
1866 if (addr == error_mark_node)
1867 {
1868 cp_error ("object missing in `%E'", exp);
1869 return error_mark_node;
1870 }
1871
2271 basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (member));
2272 addr = convert_pointer_to (basetype, addr);
1872 basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (member));
1873 addr = convert_pointer_to (basetype, addr);
2273 member = convert (ptrdiff_type_node,
2274 build_unary_op (ADDR_EXPR, member, 0));
1874 member = cp_convert (ptrdiff_type_node,
1875 build_unary_op (ADDR_EXPR, member, 0));
1876
1877 /* Pointer to data members are offset by one, so that a null
1878 pointer with a real value of 0 is distinguishable from an
1879 offset of the first member of a structure. */
1880 member = build_binary_op (MINUS_EXPR, member,
1881 cp_convert (ptrdiff_type_node, integer_one_node),
1882 0);
1883
2275 return build1 (INDIRECT_REF, type,
2276 build (PLUS_EXPR, build_pointer_type (type),
2277 addr, member));
2278 }
2279 else if (TYPE_PTRMEMFUNC_P (TREE_TYPE (member)))
2280 {
2281 return get_member_function_from_ptrfunc (&addr, member);
2282 }

--- 12 unchanged lines hidden (view full) ---

2295#if 0
2296 /* These may be necessary for C, but they break C++. */
2297 ! TREE_PUBLIC (decl)
2298 /* Don't change a variable array bound or initial value to a constant
2299 in a place where a variable is invalid. */
2300 && ! pedantic
2301#endif /* 0 */
2302 && DECL_INITIAL (decl) != 0
1884 return build1 (INDIRECT_REF, type,
1885 build (PLUS_EXPR, build_pointer_type (type),
1886 addr, member));
1887 }
1888 else if (TYPE_PTRMEMFUNC_P (TREE_TYPE (member)))
1889 {
1890 return get_member_function_from_ptrfunc (&addr, member);
1891 }

--- 12 unchanged lines hidden (view full) ---

1904#if 0
1905 /* These may be necessary for C, but they break C++. */
1906 ! TREE_PUBLIC (decl)
1907 /* Don't change a variable array bound or initial value to a constant
1908 in a place where a variable is invalid. */
1909 && ! pedantic
1910#endif /* 0 */
1911 && DECL_INITIAL (decl) != 0
2303 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
1912 && DECL_INITIAL (decl) != error_mark_node
2304 /* This is invalid if initial value is not constant.
2305 If it has either a function call, a memory reference,
2306 or a variable, then re-evaluating it could give different results. */
2307 && TREE_CONSTANT (DECL_INITIAL (decl))
2308 /* Check for cases where this is sub-optimal, even though valid. */
2309 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
2310#if 0
2311 /* We must allow this to work outside of functions so that
2312 static constants can be used for array sizes. */
2313 && current_function_decl != 0
2314 && DECL_MODE (decl) != BLKmode
2315#endif
2316 )
2317 return DECL_INITIAL (decl);
2318 return decl;
2319}
2320
1913 /* This is invalid if initial value is not constant.
1914 If it has either a function call, a memory reference,
1915 or a variable, then re-evaluating it could give different results. */
1916 && TREE_CONSTANT (DECL_INITIAL (decl))
1917 /* Check for cases where this is sub-optimal, even though valid. */
1918 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
1919#if 0
1920 /* We must allow this to work outside of functions so that
1921 static constants can be used for array sizes. */
1922 && current_function_decl != 0
1923 && DECL_MODE (decl) != BLKmode
1924#endif
1925 )
1926 return DECL_INITIAL (decl);
1927 return decl;
1928}
1929
2321/* Friend handling routines. */
2322/* Friend data structures:
2323
2324 Lists of friend functions come from TYPE_DECL nodes. Since all
2325 aggregate types are automatically typedef'd, these nodes are guaranteed
2326 to exist.
2327
2328 The TREE_PURPOSE of a friend list is the name of the friend,
2329 and its TREE_VALUE is another list.
2330
2331 For each element of that list, either the TREE_VALUE or the TREE_PURPOSE
2332 will be filled in, but not both. The TREE_VALUE of that list is an
2333 individual function which is a friend. The TREE_PURPOSE of that list
2334 indicates a type in which all functions by that name are friends.
2335
2336 Lists of friend classes come from _TYPE nodes. Love that consistency
2337 thang. */
2338
2339int
2340is_friend_type (type1, type2)
2341 tree type1, type2;
2342{
2343 return is_friend (type1, type2);
2344}
2345
2346int
2347is_friend (type, supplicant)
2348 tree type, supplicant;
2349{
2350 int declp;
2351 register tree list;
2352
2353 if (supplicant == NULL_TREE || type == NULL_TREE)
2354 return 0;
2355
2356 declp = (TREE_CODE_CLASS (TREE_CODE (supplicant)) == 'd');
2357
2358 if (declp)
2359 /* It's a function decl. */
2360 {
2361 tree list = DECL_FRIENDLIST (TYPE_NAME (type));
2362 tree name = DECL_NAME (supplicant);
2363 tree ctype;
2364
2365 if (DECL_FUNCTION_MEMBER_P (supplicant))
2366 ctype = DECL_CLASS_CONTEXT (supplicant);
2367 else
2368 ctype = NULL_TREE;
2369
2370 for (; list ; list = TREE_CHAIN (list))
2371 {
2372 if (name == TREE_PURPOSE (list))
2373 {
2374 tree friends = TREE_VALUE (list);
2375 name = DECL_ASSEMBLER_NAME (supplicant);
2376 for (; friends ; friends = TREE_CHAIN (friends))
2377 {
2378 if (ctype == TREE_PURPOSE (friends))
2379 return 1;
2380 if (name == DECL_ASSEMBLER_NAME (TREE_VALUE (friends)))
2381 return 1;
2382 }
2383 break;
2384 }
2385 }
2386 }
2387 else
2388 /* It's a type. */
2389 {
2390 if (type == supplicant)
2391 return 1;
2392
2393 list = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (TYPE_NAME (type)));
2394 for (; list ; list = TREE_CHAIN (list))
2395 if (supplicant == TREE_VALUE (list))
2396 return 1;
2397 }
2398
2399 {
2400 tree context;
2401
2402 if (! declp)
2403 context = DECL_CONTEXT (TYPE_NAME (supplicant));
2404 else if (DECL_FUNCTION_MEMBER_P (supplicant))
2405 context = DECL_CLASS_CONTEXT (supplicant);
2406 else
2407 context = NULL_TREE;
2408
2409 if (context)
2410 return is_friend (type, context);
2411 }
2412
2413 return 0;
2414}
2415
2416/* Add a new friend to the friends of the aggregate type TYPE.
2417 DECL is the FUNCTION_DECL of the friend being added. */
2418static void
2419add_friend (type, decl)
2420 tree type, decl;
2421{
2422 tree typedecl = TYPE_NAME (type);
2423 tree list = DECL_FRIENDLIST (typedecl);
2424 tree name = DECL_NAME (decl);
2425
2426 while (list)
2427 {
2428 if (name == TREE_PURPOSE (list))
2429 {
2430 tree friends = TREE_VALUE (list);
2431 for (; friends ; friends = TREE_CHAIN (friends))
2432 {
2433 if (decl == TREE_VALUE (friends))
2434 {
2435 cp_warning ("`%D' is already a friend of class `%T'",
2436 decl, type);
2437 cp_warning_at ("previous friend declaration of `%D'",
2438 TREE_VALUE (friends));
2439 return;
2440 }
2441 }
2442 TREE_VALUE (list) = tree_cons (error_mark_node, decl,
2443 TREE_VALUE (list));
2444 return;
2445 }
2446 list = TREE_CHAIN (list);
2447 }
2448 DECL_FRIENDLIST (typedecl)
2449 = tree_cons (DECL_NAME (decl), build_tree_list (error_mark_node, decl),
2450 DECL_FRIENDLIST (typedecl));
2451 if (DECL_NAME (decl) == ansi_opname[(int) MODIFY_EXPR])
2452 {
2453 tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
2454 TYPE_HAS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
2455 if (parmtypes && TREE_CHAIN (parmtypes))
2456 {
2457 tree parmtype = TREE_VALUE (TREE_CHAIN (parmtypes));
2458 if (TREE_CODE (parmtype) == REFERENCE_TYPE
2459 && TREE_TYPE (parmtypes) == TREE_TYPE (typedecl))
2460 TYPE_HAS_ASSIGN_REF (TREE_TYPE (typedecl)) = 1;
2461 }
2462 }
2463}
2464
2465/* Declare that every member function NAME in FRIEND_TYPE
2466 (which may be NULL_TREE) is a friend of type TYPE. */
2467static void
2468add_friends (type, name, friend_type)
2469 tree type, name, friend_type;
2470{
2471 tree typedecl = TYPE_NAME (type);
2472 tree list = DECL_FRIENDLIST (typedecl);
2473
2474 while (list)
2475 {
2476 if (name == TREE_PURPOSE (list))
2477 {
2478 tree friends = TREE_VALUE (list);
2479 while (friends && TREE_PURPOSE (friends) != friend_type)
2480 friends = TREE_CHAIN (friends);
2481 if (friends)
2482 if (friend_type)
2483 warning ("method `%s::%s' is already a friend of class",
2484 TYPE_NAME_STRING (friend_type),
2485 IDENTIFIER_POINTER (name));
2486 else
2487 warning ("function `%s' is already a friend of class `%s'",
2488 IDENTIFIER_POINTER (name),
2489 IDENTIFIER_POINTER (DECL_NAME (typedecl)));
2490 else
2491 TREE_VALUE (list) = tree_cons (friend_type, NULL_TREE,
2492 TREE_VALUE (list));
2493 return;
2494 }
2495 list = TREE_CHAIN (list);
2496 }
2497 DECL_FRIENDLIST (typedecl) =
2498 tree_cons (name,
2499 build_tree_list (friend_type, NULL_TREE),
2500 DECL_FRIENDLIST (typedecl));
2501 if (! strncmp (IDENTIFIER_POINTER (name),
2502 IDENTIFIER_POINTER (ansi_opname[(int) MODIFY_EXPR]),
2503 strlen (IDENTIFIER_POINTER (ansi_opname[(int) MODIFY_EXPR]))))
2504 {
2505 TYPE_HAS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
2506 sorry ("declaring \"friend operator =\" will not find \"operator = (X&)\" if it exists");
2507 }
2508}
2509
2510/* Set up a cross reference so that type TYPE will make member function
2511 CTYPE::DECL a friend when CTYPE is finally defined. For more than
2512 one, set up a cross reference so that functions with the name DECL
2513 and type CTYPE know that they are friends of TYPE. */
2514static void
2515xref_friend (type, decl, ctype)
2516 tree type, decl, ctype;
2517{
2518 tree friend_decl = TYPE_NAME (ctype);
2519#if 0
2520 tree typedecl = TYPE_NAME (type);
2521 tree t = tree_cons (NULL_TREE, ctype, DECL_UNDEFINED_FRIENDS (typedecl));
2522
2523 DECL_UNDEFINED_FRIENDS (typedecl) = t;
2524#else
2525 tree t = 0;
2526#endif
2527 SET_DECL_WAITING_FRIENDS (friend_decl,
2528 tree_cons (type, t,
2529 DECL_WAITING_FRIENDS (friend_decl)));
2530 TREE_TYPE (DECL_WAITING_FRIENDS (friend_decl)) = decl;
2531}
2532
2533/* Make FRIEND_TYPE a friend class to TYPE. If FRIEND_TYPE has already
2534 been defined, we make all of its member functions friends of
2535 TYPE. If not, we make it a pending friend, which can later be added
2536 when its definition is seen. If a type is defined, then its TYPE_DECL's
2537 DECL_UNDEFINED_FRIENDS contains a (possibly empty) list of friend
2538 classes that are not defined. If a type has not yet been defined,
2539 then the DECL_WAITING_FRIENDS contains a list of types
2540 waiting to make it their friend. Note that these two can both
2541 be in use at the same time! */
2542void
2543make_friend_class (type, friend_type)
2544 tree type, friend_type;
2545{
2546 tree classes;
2547
2548 if (IS_SIGNATURE (type))
2549 {
2550 error ("`friend' declaration in signature definition");
2551 return;
2552 }
2553 if (IS_SIGNATURE (friend_type))
2554 {
2555 error ("signature type `%s' declared `friend'",
2556 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (friend_type))));
2557 return;
2558 }
2559 if (type == friend_type)
2560 {
2561 pedwarn ("class `%s' is implicitly friends with itself",
2562 TYPE_NAME_STRING (type));
2563 return;
2564 }
2565
2566 GNU_xref_hier (TYPE_NAME_STRING (type),
2567 TYPE_NAME_STRING (friend_type), 0, 0, 1);
2568
2569 classes = CLASSTYPE_FRIEND_CLASSES (type);
2570 while (classes && TREE_VALUE (classes) != friend_type)
2571 classes = TREE_CHAIN (classes);
2572 if (classes)
2573 warning ("class `%s' is already friends with class `%s'",
2574 TYPE_NAME_STRING (TREE_VALUE (classes)), TYPE_NAME_STRING (type));
2575 else
2576 {
2577 CLASSTYPE_FRIEND_CLASSES (type)
2578 = tree_cons (NULL_TREE, friend_type, CLASSTYPE_FRIEND_CLASSES (type));
2579 }
2580}
2581
2582/* Main friend processor. This is large, and for modularity purposes,
2583 has been removed from grokdeclarator. It returns `void_type_node'
2584 to indicate that something happened, though a FIELD_DECL is
2585 not returned.
2586
2587 CTYPE is the class this friend belongs to.
2588
2589 DECLARATOR is the name of the friend.
2590
2591 DECL is the FUNCTION_DECL that the friend is.
2592
2593 In case we are parsing a friend which is part of an inline
2594 definition, we will need to store PARM_DECL chain that comes
2595 with it into the DECL_ARGUMENTS slot of the FUNCTION_DECL.
2596
2597 FLAGS is just used for `grokclassfn'.
2598
2599 QUALS say what special qualifies should apply to the object
2600 pointed to by `this'. */
2601tree
2602do_friend (ctype, declarator, decl, parmdecls, flags, quals)
2603 tree ctype, declarator, decl, parmdecls;
2604 enum overload_flags flags;
2605 tree quals;
2606{
2607 /* Every decl that gets here is a friend of something. */
2608 DECL_FRIEND_P (decl) = 1;
2609
2610 if (ctype)
2611 {
2612 tree cname = TYPE_NAME (ctype);
2613 if (TREE_CODE (cname) == TYPE_DECL)
2614 cname = DECL_NAME (cname);
2615
2616 /* A method friend. */
2617 if (TREE_CODE (decl) == FUNCTION_DECL)
2618 {
2619 if (flags == NO_SPECIAL && ctype && declarator == cname)
2620 DECL_CONSTRUCTOR_P (decl) = 1;
2621
2622 /* This will set up DECL_ARGUMENTS for us. */
2623 grokclassfn (ctype, cname, decl, flags, quals);
2624 if (TYPE_SIZE (ctype) != 0)
2625 check_classfn (ctype, cname, decl);
2626
2627 if (TREE_TYPE (decl) != error_mark_node)
2628 {
2629 if (TYPE_SIZE (ctype))
2630 {
2631 /* We don't call pushdecl here yet, or ever on this
2632 actual FUNCTION_DECL. We must preserve its TREE_CHAIN
2633 until the end. */
2634 make_decl_rtl (decl, NULL_PTR, 1);
2635 add_friend (current_class_type, decl);
2636 }
2637 else
2638 {
2639 register char *classname
2640 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (ctype)));
2641
2642 error ("member declared as friend before type `%s' defined",
2643 classname);
2644 }
2645 }
2646 }
2647 else
2648 {
2649 /* Possibly a bunch of method friends. */
2650
2651 /* Get the class they belong to. */
2652 tree ctype = IDENTIFIER_TYPE_VALUE (cname);
2653
2654 /* This class is defined, use its methods now. */
2655 if (TYPE_SIZE (ctype))
2656 {
2657 tree fields = lookup_fnfields (TYPE_BINFO (ctype), declarator, 0);
2658 if (fields)
2659 add_friends (current_class_type, declarator, ctype);
2660 else
2661 error ("method `%s' is not a member of class `%s'",
2662 IDENTIFIER_POINTER (declarator),
2663 IDENTIFIER_POINTER (cname));
2664 }
2665 else
2666 /* Note: DECLARATOR actually has more than one; in this
2667 case, we're making sure that fns with the name DECLARATOR
2668 and type CTYPE know they are friends of the current
2669 class type. */
2670 xref_friend (current_class_type, declarator, ctype);
2671 decl = void_type_node;
2672 }
2673 }
2674 else if (TREE_CODE (decl) == FUNCTION_DECL
2675 && ((IDENTIFIER_LENGTH (declarator) == 4
2676 && IDENTIFIER_POINTER (declarator)[0] == 'm'
2677 && ! strcmp (IDENTIFIER_POINTER (declarator), "main"))
2678 || (IDENTIFIER_LENGTH (declarator) > 10
2679 && IDENTIFIER_POINTER (declarator)[0] == '_'
2680 && IDENTIFIER_POINTER (declarator)[1] == '_'
2681 && strncmp (IDENTIFIER_POINTER (declarator)+2,
2682 "builtin_", 8) == 0)))
2683 {
2684 /* raw "main", and builtin functions never gets overloaded,
2685 but they can become friends. */
2686 add_friend (current_class_type, decl);
2687 DECL_FRIEND_P (decl) = 1;
2688 decl = void_type_node;
2689 }
2690 /* A global friend.
2691 @@ or possibly a friend from a base class ?!? */
2692 else if (TREE_CODE (decl) == FUNCTION_DECL)
2693 {
2694 /* Friends must all go through the overload machinery,
2695 even though they may not technically be overloaded.
2696
2697 Note that because classes all wind up being top-level
2698 in their scope, their friend wind up in top-level scope as well. */
2699 DECL_ASSEMBLER_NAME (decl)
2700 = build_decl_overload (declarator, TYPE_ARG_TYPES (TREE_TYPE (decl)),
2701 TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
2702 DECL_ARGUMENTS (decl) = parmdecls;
2703 DECL_CLASS_CONTEXT (decl) = current_class_type;
2704
2705 /* We can call pushdecl here, because the TREE_CHAIN of this
2706 FUNCTION_DECL is not needed for other purposes. */
2707 decl = pushdecl (decl);
2708
2709 make_decl_rtl (decl, NULL_PTR, 1);
2710 add_friend (current_class_type, decl);
2711
2712 DECL_FRIEND_P (decl) = 1;
2713#if 0
2714 TREE_OVERLOADED (declarator) = 1;
2715#endif
2716 }
2717 else
2718 {
2719 /* @@ Should be able to ingest later definitions of this function
2720 before use. */
2721 tree decl = lookup_name_nonclass (declarator);
2722 if (decl == NULL_TREE)
2723 {
2724 warning ("implicitly declaring `%s' as struct",
2725 IDENTIFIER_POINTER (declarator));
2726 decl = xref_tag (record_type_node, declarator, NULL_TREE, 1);
2727 decl = TYPE_NAME (decl);
2728 }
2729
2730 /* Allow abbreviated declarations of overloaded functions,
2731 but not if those functions are really class names. */
2732 if (TREE_CODE (decl) == TREE_LIST && TREE_TYPE (TREE_PURPOSE (decl)))
2733 {
2734 warning ("`friend %s' archaic, use `friend class %s' instead",
2735 IDENTIFIER_POINTER (declarator),
2736 IDENTIFIER_POINTER (declarator));
2737 decl = TREE_TYPE (TREE_PURPOSE (decl));
2738 }
2739
2740 if (TREE_CODE (decl) == TREE_LIST)
2741 add_friends (current_class_type, TREE_PURPOSE (decl), NULL_TREE);
2742 else
2743 make_friend_class (current_class_type, TREE_TYPE (decl));
2744 decl = void_type_node;
2745 }
2746 return decl;
2747}
2748
2749/* TYPE has now been defined. It may, however, have a number of things
2750 waiting make make it their friend. We resolve these references
2751 here. */
2752void
2753embrace_waiting_friends (type)
2754 tree type;
2755{
2756 tree decl = TYPE_NAME (type);
2757 tree waiters;
2758
2759 if (TREE_CODE (decl) != TYPE_DECL)
2760 return;
2761
2762 for (waiters = DECL_WAITING_FRIENDS (decl); waiters;
2763 waiters = TREE_CHAIN (waiters))
2764 {
2765 tree waiter = TREE_PURPOSE (waiters);
2766#if 0
2767 tree waiter_prev = TREE_VALUE (waiters);
2768#endif
2769 tree decl = TREE_TYPE (waiters);
2770 tree name = decl ? (TREE_CODE (decl) == IDENTIFIER_NODE
2771 ? decl : DECL_NAME (decl)) : NULL_TREE;
2772 if (name)
2773 {
2774 /* @@ There may be work to be done since we have not verified
2775 @@ consistency between original and friend declarations
2776 @@ of the functions waiting to become friends. */
2777 tree field = lookup_fnfields (TYPE_BINFO (type), name, 0);
2778 if (field)
2779 if (decl == name)
2780 add_friends (waiter, name, type);
2781 else
2782 add_friend (waiter, decl);
2783 else
2784 error_with_file_and_line (DECL_SOURCE_FILE (TYPE_NAME (waiter)),
2785 DECL_SOURCE_LINE (TYPE_NAME (waiter)),
2786 "no method `%s' defined in class `%s' to be friend",
2787 IDENTIFIER_POINTER (DECL_NAME (TREE_TYPE (waiters))),
2788 TYPE_NAME_STRING (type));
2789 }
2790 else
2791 make_friend_class (type, waiter);
2792
2793#if 0
2794 if (TREE_CHAIN (waiter_prev))
2795 TREE_CHAIN (waiter_prev) = TREE_CHAIN (TREE_CHAIN (waiter_prev));
2796 else
2797 DECL_UNDEFINED_FRIENDS (TYPE_NAME (waiter)) = NULL_TREE;
2798#endif
2799 }
2800}
2801
2802/* Common subroutines of build_new and build_vec_delete. */
2803
2804/* Common interface for calling "builtin" functions that are not
2805 really builtin. */
2806
1930/* Common subroutines of build_new and build_vec_delete. */
1931
1932/* Common interface for calling "builtin" functions that are not
1933 really builtin. */
1934
2807tree
1935static tree
2808build_builtin_call (type, node, arglist)
2809 tree type;
2810 tree node;
2811 tree arglist;
2812{
1936build_builtin_call (type, node, arglist)
1937 tree type;
1938 tree node;
1939 tree arglist;
1940{
2813 tree rval = build (CALL_EXPR, type, node, arglist, 0);
1941 tree rval = build (CALL_EXPR, type, node, arglist, NULL_TREE);
2814 TREE_SIDE_EFFECTS (rval) = 1;
2815 assemble_external (TREE_OPERAND (node, 0));
2816 TREE_USED (TREE_OPERAND (node, 0)) = 1;
2817 return rval;
2818}
2819
2820/* Generate a C++ "new" expression. DECL is either a TREE_LIST
2821 (which needs to go through some sort of groktypename) or it

--- 24 unchanged lines hidden (view full) ---

2846extern int flag_check_new;
2847
2848tree
2849build_new (placement, decl, init, use_global_new)
2850 tree placement;
2851 tree decl, init;
2852 int use_global_new;
2853{
1942 TREE_SIDE_EFFECTS (rval) = 1;
1943 assemble_external (TREE_OPERAND (node, 0));
1944 TREE_USED (TREE_OPERAND (node, 0)) = 1;
1945 return rval;
1946}
1947
1948/* Generate a C++ "new" expression. DECL is either a TREE_LIST
1949 (which needs to go through some sort of groktypename) or it

--- 24 unchanged lines hidden (view full) ---

1974extern int flag_check_new;
1975
1976tree
1977build_new (placement, decl, init, use_global_new)
1978 tree placement;
1979 tree decl, init;
1980 int use_global_new;
1981{
2854 tree type, true_type, size, rval;
2855 tree nelts;
2856 tree alloc_expr, alloc_temp;
1982 tree type, rval;
1983 tree nelts = NULL_TREE, t;
2857 int has_array = 0;
1984 int has_array = 0;
2858 enum tree_code code = NEW_EXPR;
2859
2860 tree pending_sizes = NULL_TREE;
2861
2862 if (decl == error_mark_node)
2863 return error_mark_node;
2864
2865 if (TREE_CODE (decl) == TREE_LIST)
2866 {
2867 tree absdcl = TREE_VALUE (decl);
2868 tree last_absdcl = NULL_TREE;
1985
1986 tree pending_sizes = NULL_TREE;
1987
1988 if (decl == error_mark_node)
1989 return error_mark_node;
1990
1991 if (TREE_CODE (decl) == TREE_LIST)
1992 {
1993 tree absdcl = TREE_VALUE (decl);
1994 tree last_absdcl = NULL_TREE;
2869 int old_immediate_size_expand;
1995 int old_immediate_size_expand = 0;
2870
2871 if (current_function_decl
2872 && DECL_CONSTRUCTOR_P (current_function_decl))
2873 {
2874 old_immediate_size_expand = immediate_size_expand;
2875 immediate_size_expand = 0;
2876 }
2877

--- 20 unchanged lines hidden (view full) ---

2898 }
2899
2900 has_array = 1;
2901 this_nelts = TREE_OPERAND (absdcl, 1);
2902 if (this_nelts != error_mark_node)
2903 {
2904 if (this_nelts == NULL_TREE)
2905 error ("new of array type fails to specify size");
1996
1997 if (current_function_decl
1998 && DECL_CONSTRUCTOR_P (current_function_decl))
1999 {
2000 old_immediate_size_expand = immediate_size_expand;
2001 immediate_size_expand = 0;
2002 }
2003

--- 20 unchanged lines hidden (view full) ---

2024 }
2025
2026 has_array = 1;
2027 this_nelts = TREE_OPERAND (absdcl, 1);
2028 if (this_nelts != error_mark_node)
2029 {
2030 if (this_nelts == NULL_TREE)
2031 error ("new of array type fails to specify size");
2032 else if (processing_template_decl)
2033 {
2034 nelts = this_nelts;
2035 absdcl = TREE_OPERAND (absdcl, 0);
2036 }
2906 else
2907 {
2037 else
2038 {
2908 this_nelts = save_expr (convert (sizetype, this_nelts));
2039 this_nelts = save_expr (cp_convert (sizetype, this_nelts));
2909 absdcl = TREE_OPERAND (absdcl, 0);
2910 if (this_nelts == integer_zero_node)
2911 {
2912 warning ("zero size array reserves no space");
2913 nelts = integer_zero_node;
2914 }
2915 else
2916 nelts = build_binary_op (MULT_EXPR, nelts, this_nelts, 1);
2917 }
2918 }
2919 else
2920 nelts = integer_zero_node;
2921 }
2922
2923 if (last_absdcl)
2924 TREE_OPERAND (last_absdcl, 0) = absdcl;
2925 else
2926 TREE_VALUE (decl) = absdcl;
2927
2040 absdcl = TREE_OPERAND (absdcl, 0);
2041 if (this_nelts == integer_zero_node)
2042 {
2043 warning ("zero size array reserves no space");
2044 nelts = integer_zero_node;
2045 }
2046 else
2047 nelts = build_binary_op (MULT_EXPR, nelts, this_nelts, 1);
2048 }
2049 }
2050 else
2051 nelts = integer_zero_node;
2052 }
2053
2054 if (last_absdcl)
2055 TREE_OPERAND (last_absdcl, 0) = absdcl;
2056 else
2057 TREE_VALUE (decl) = absdcl;
2058
2928 type = true_type = groktypename (decl);
2059 type = groktypename (decl);
2929 if (! type || type == error_mark_node)
2930 {
2931 immediate_size_expand = old_immediate_size_expand;
2932 return error_mark_node;
2933 }
2934
2935 if (current_function_decl
2936 && DECL_CONSTRUCTOR_P (current_function_decl))
2937 {
2938 pending_sizes = get_pending_sizes ();
2939 immediate_size_expand = old_immediate_size_expand;
2940 }
2941 }
2942 else if (TREE_CODE (decl) == IDENTIFIER_NODE)
2943 {
2944 if (IDENTIFIER_HAS_TYPE_VALUE (decl))
2945 {
2946 /* An aggregate type. */
2947 type = IDENTIFIER_TYPE_VALUE (decl);
2060 if (! type || type == error_mark_node)
2061 {
2062 immediate_size_expand = old_immediate_size_expand;
2063 return error_mark_node;
2064 }
2065
2066 if (current_function_decl
2067 && DECL_CONSTRUCTOR_P (current_function_decl))
2068 {
2069 pending_sizes = get_pending_sizes ();
2070 immediate_size_expand = old_immediate_size_expand;
2071 }
2072 }
2073 else if (TREE_CODE (decl) == IDENTIFIER_NODE)
2074 {
2075 if (IDENTIFIER_HAS_TYPE_VALUE (decl))
2076 {
2077 /* An aggregate type. */
2078 type = IDENTIFIER_TYPE_VALUE (decl);
2948 decl = TYPE_NAME (type);
2079 decl = TYPE_MAIN_DECL (type);
2949 }
2950 else
2951 {
2952 /* A builtin type. */
2953 decl = lookup_name (decl, 1);
2954 my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 215);
2955 type = TREE_TYPE (decl);
2956 }
2080 }
2081 else
2082 {
2083 /* A builtin type. */
2084 decl = lookup_name (decl, 1);
2085 my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 215);
2086 type = TREE_TYPE (decl);
2087 }
2957 true_type = type;
2958 }
2959 else if (TREE_CODE (decl) == TYPE_DECL)
2960 {
2961 type = TREE_TYPE (decl);
2088 }
2089 else if (TREE_CODE (decl) == TYPE_DECL)
2090 {
2091 type = TREE_TYPE (decl);
2962 true_type = type;
2963 }
2964 else
2965 {
2966 type = decl;
2092 }
2093 else
2094 {
2095 type = decl;
2967 true_type = type;
2968 decl = TYPE_NAME (type);
2096 decl = TYPE_MAIN_DECL (type);
2969 }
2970
2097 }
2098
2099 if (processing_template_decl)
2100 {
2101 if (has_array)
2102 t = min_tree_cons (min_tree_cons (NULL_TREE, type, NULL_TREE),
2103 build_min_nt (ARRAY_REF, NULL_TREE, nelts),
2104 NULL_TREE);
2105 else
2106 t = type;
2107
2108 rval = build_min_nt (NEW_EXPR, placement, t, init);
2109 NEW_EXPR_USE_GLOBAL (rval) = use_global_new;
2110 return rval;
2111 }
2112
2971 /* ``A reference cannot be created by the new operator. A reference
2972 is not an object (8.2.2, 8.4.3), so a pointer to it could not be
2973 returned by new.'' ARM 5.3.3 */
2974 if (TREE_CODE (type) == REFERENCE_TYPE)
2975 {
2976 error ("new cannot be applied to a reference type");
2113 /* ``A reference cannot be created by the new operator. A reference
2114 is not an object (8.2.2, 8.4.3), so a pointer to it could not be
2115 returned by new.'' ARM 5.3.3 */
2116 if (TREE_CODE (type) == REFERENCE_TYPE)
2117 {
2118 error ("new cannot be applied to a reference type");
2977 type = true_type = TREE_TYPE (type);
2119 type = TREE_TYPE (type);
2978 }
2979
2980 if (TREE_CODE (type) == FUNCTION_TYPE)
2981 {
2982 error ("new cannot be applied to a function type");
2983 return error_mark_node;
2984 }
2985
2986 /* When the object being created is an array, the new-expression yields a
2987 pointer to the initial element (if any) of the array. For example,
2988 both new int and new int[10] return an int*. 5.3.4. */
2989 if (TREE_CODE (type) == ARRAY_TYPE && has_array == 0)
2990 {
2991 nelts = array_type_nelts_top (type);
2992 has_array = 1;
2120 }
2121
2122 if (TREE_CODE (type) == FUNCTION_TYPE)
2123 {
2124 error ("new cannot be applied to a function type");
2125 return error_mark_node;
2126 }
2127
2128 /* When the object being created is an array, the new-expression yields a
2129 pointer to the initial element (if any) of the array. For example,
2130 both new int and new int[10] return an int*. 5.3.4. */
2131 if (TREE_CODE (type) == ARRAY_TYPE && has_array == 0)
2132 {
2133 nelts = array_type_nelts_top (type);
2134 has_array = 1;
2993 type = true_type = TREE_TYPE (type);
2135 type = TREE_TYPE (type);
2994 }
2995
2136 }
2137
2138 if (has_array)
2139 t = build_nt (ARRAY_REF, type, nelts);
2140 else
2141 t = type;
2142
2143 rval = build (NEW_EXPR, build_pointer_type (type), placement, t, init);
2144 NEW_EXPR_USE_GLOBAL (rval) = use_global_new;
2145 TREE_SIDE_EFFECTS (rval) = 1;
2146
2147 /* Wrap it in a NOP_EXPR so warn_if_unused_value doesn't complain. */
2148 rval = build1 (NOP_EXPR, TREE_TYPE (rval), rval);
2149 TREE_NO_UNUSED_WARNING (rval) = 1;
2150
2151 if (pending_sizes)
2152 rval = build_compound_expr (chainon (pending_sizes,
2153 build_expr_list (NULL_TREE, rval)));
2154
2155 return rval;
2156}
2157
2158/* Called from cplus_expand_expr when expanding a NEW_EXPR. The return
2159 value is immediately handed to expand_expr. */
2160
2161tree
2162build_new_1 (exp)
2163 tree exp;
2164{
2165 tree placement, init;
2166 tree type, true_type, size, rval;
2167 tree nelts = NULL_TREE;
2168 tree alloc_expr, alloc_node = NULL_TREE;
2169 int has_array = 0;
2170 enum tree_code code = NEW_EXPR;
2171 int use_cookie, nothrow, check_new;
2172 int use_global_new;
2173
2174 placement = TREE_OPERAND (exp, 0);
2175 type = TREE_OPERAND (exp, 1);
2176 init = TREE_OPERAND (exp, 2);
2177 use_global_new = NEW_EXPR_USE_GLOBAL (exp);
2178
2179 if (TREE_CODE (type) == ARRAY_REF)
2180 {
2181 has_array = 1;
2182 nelts = TREE_OPERAND (type, 1);
2183 type = TREE_OPERAND (type, 0);
2184 }
2185 true_type = type;
2186
2996 if (TYPE_READONLY (type) || TYPE_VOLATILE (type))
2997 type = TYPE_MAIN_VARIANT (type);
2998
2999 /* If our base type is an array, then make sure we know how many elements
3000 it has. */
3001 while (TREE_CODE (true_type) == ARRAY_TYPE)
3002 {
3003 tree this_nelts = array_type_nelts_top (true_type);
3004 nelts = build_binary_op (MULT_EXPR, nelts, this_nelts, 1);
3005 true_type = TREE_TYPE (true_type);
3006 }
2187 if (TYPE_READONLY (type) || TYPE_VOLATILE (type))
2188 type = TYPE_MAIN_VARIANT (type);
2189
2190 /* If our base type is an array, then make sure we know how many elements
2191 it has. */
2192 while (TREE_CODE (true_type) == ARRAY_TYPE)
2193 {
2194 tree this_nelts = array_type_nelts_top (true_type);
2195 nelts = build_binary_op (MULT_EXPR, nelts, this_nelts, 1);
2196 true_type = TREE_TYPE (true_type);
2197 }
2198
2199 if (!complete_type_or_else (true_type))
2200 return error_mark_node;
2201
3007 if (has_array)
3008 size = fold (build_binary_op (MULT_EXPR, size_in_bytes (true_type),
3009 nelts, 1));
3010 else
3011 size = size_in_bytes (type);
3012
2202 if (has_array)
2203 size = fold (build_binary_op (MULT_EXPR, size_in_bytes (true_type),
2204 nelts, 1));
2205 else
2206 size = size_in_bytes (type);
2207
3013 if (true_type == void_type_node)
2208 if (TREE_CODE (true_type) == VOID_TYPE)
3014 {
3015 error ("invalid type `void' for new");
3016 return error_mark_node;
3017 }
3018
2209 {
2210 error ("invalid type `void' for new");
2211 return error_mark_node;
2212 }
2213
3019 if (TYPE_SIZE (true_type) == 0)
3020 {
3021 incomplete_type_error (0, true_type);
3022 return error_mark_node;
3023 }
3024
3025 if (TYPE_LANG_SPECIFIC (true_type)
3026 && CLASSTYPE_ABSTRACT_VIRTUALS (true_type))
3027 {
3028 abstract_virtuals_error (NULL_TREE, true_type);
3029 return error_mark_node;
3030 }
3031
3032 if (TYPE_LANG_SPECIFIC (true_type) && IS_SIGNATURE (true_type))
3033 {
3034 signature_error (NULL_TREE, true_type);
3035 return error_mark_node;
3036 }
3037
2214 if (TYPE_LANG_SPECIFIC (true_type)
2215 && CLASSTYPE_ABSTRACT_VIRTUALS (true_type))
2216 {
2217 abstract_virtuals_error (NULL_TREE, true_type);
2218 return error_mark_node;
2219 }
2220
2221 if (TYPE_LANG_SPECIFIC (true_type) && IS_SIGNATURE (true_type))
2222 {
2223 signature_error (NULL_TREE, true_type);
2224 return error_mark_node;
2225 }
2226
2227#if 1
3038 /* Get a little extra space to store a couple of things before the new'ed
2228 /* Get a little extra space to store a couple of things before the new'ed
3039 array. */
3040 if (has_array && TYPE_VEC_NEW_USES_COOKIE (true_type))
2229 array, if this isn't the default placement new. */
2230
2231 use_cookie = (has_array && TYPE_VEC_NEW_USES_COOKIE (true_type)
2232 && ! (placement && ! TREE_CHAIN (placement)
2233 && TREE_TYPE (TREE_VALUE (placement)) == ptr_type_node));
2234#else
2235 /* Get a little extra space to store a couple of things before the new'ed
2236 array, if this is either non-placement new or new (nothrow). */
2237
2238 use_cookie = (has_array && TYPE_VEC_NEW_USES_COOKIE (true_type)
2239 && (! placement || nothrow));
2240#endif
2241
2242 if (use_cookie)
3041 {
3042 tree extra = BI_header_size;
3043
3044 size = size_binop (PLUS_EXPR, size, extra);
3045 }
3046
3047 if (has_array)
2243 {
2244 tree extra = BI_header_size;
2245
2246 size = size_binop (PLUS_EXPR, size, extra);
2247 }
2248
2249 if (has_array)
3048 code = VEC_NEW_EXPR;
3049
3050 /* Allocate the object. */
3051 if (! use_global_new && TYPE_LANG_SPECIFIC (true_type)
3052 && (TYPE_GETS_NEW (true_type) & (1 << has_array)))
3053 rval = build_opfncall (code, LOOKUP_NORMAL,
3054 build_pointer_type (true_type), size, placement);
3055 else if (placement)
3056 {
2250 {
3057 rval = build_opfncall (code, LOOKUP_GLOBAL|LOOKUP_COMPLAIN,
3058 ptr_type_node, size, placement);
3059 rval = convert (build_pointer_type (true_type), rval);
2251 code = VEC_NEW_EXPR;
2252
2253 if (init && pedantic)
2254 cp_pedwarn ("initialization in array new");
3060 }
2255 }
3061 else if (! has_array && flag_this_is_variable > 0
3062 && TYPE_NEEDS_CONSTRUCTING (true_type) && init != void_type_node)
2256
2257 /* Allocate the object. */
2258
2259 if (! has_array && ! placement && flag_this_is_variable > 0
2260 && TYPE_NEEDS_CONSTRUCTING (true_type) && init != void_type_node)
3063 {
3064 if (init == NULL_TREE || TREE_CODE (init) == TREE_LIST)
3065 rval = NULL_TREE;
3066 else
3067 {
3068 error ("constructors take parameter lists");
3069 return error_mark_node;
3070 }
3071 }
3072 else
3073 {
2261 {
2262 if (init == NULL_TREE || TREE_CODE (init) == TREE_LIST)
2263 rval = NULL_TREE;
2264 else
2265 {
2266 error ("constructors take parameter lists");
2267 return error_mark_node;
2268 }
2269 }
2270 else
2271 {
3074 rval = build_builtin_call (build_pointer_type (true_type),
3075 has_array ? BIVN : BIN,
3076 build_tree_list (NULL_TREE, size));
3077#if 0
3078 /* See comment above as to why this is disabled. */
3079 if (alignment)
3080 {
3081 rval = build (PLUS_EXPR, build_pointer_type (true_type), rval,
3082 alignment);
3083 rval = build (BIT_AND_EXPR, build_pointer_type (true_type),
3084 rval, build1 (BIT_NOT_EXPR, integer_type_node,
3085 alignment));
3086 }
3087#endif
3088 TREE_CALLS_NEW (rval) = 1;
2272 int susp;
2273
2274 if (flag_exceptions)
2275 /* We will use RVAL when generating an exception handler for
2276 this new-expression, so we must save it. */
2277 susp = suspend_momentary ();
2278
2279 rval = build_op_new_call
2280 (code, true_type, expr_tree_cons (NULL_TREE, size, placement),
2281 LOOKUP_NORMAL | (use_global_new * LOOKUP_GLOBAL));
2282 rval = cp_convert (build_pointer_type (true_type), rval);
2283
2284 if (flag_exceptions)
2285 resume_momentary (susp);
3089 }
3090
2286 }
2287
3091 if (flag_check_new && rval)
2288 /* unless an allocation function is declared with an empty excep-
2289 tion-specification (_except.spec_), throw(), it indicates failure to
2290 allocate storage by throwing a bad_alloc exception (clause _except_,
2291 _lib.bad.alloc_); it returns a non-null pointer otherwise If the allo-
2292 cation function is declared with an empty exception-specification,
2293 throw(), it returns null to indicate failure to allocate storage and a
2294 non-null pointer otherwise.
2295
2296 So check for a null exception spec on the op new we just called. */
2297
2298 nothrow = 0;
2299 if (rval)
3092 {
2300 {
3093 /* For array new, we need to make sure that the call to new is
3094 not expanded as part of the RTL_EXPR for the initialization,
3095 so we can't just use save_expr here. */
2301 /* The CALL_EXPR. */
2302 tree t = TREE_OPERAND (rval, 0);
2303 /* The function. */
2304 t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
2305 t = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t));
3096
2306
3097 alloc_temp = get_temp_name (TREE_TYPE (rval), 0);
3098 alloc_expr = build (MODIFY_EXPR, TREE_TYPE (rval), alloc_temp, rval);
3099 TREE_SIDE_EFFECTS (alloc_expr) = 1;
3100 rval = alloc_temp;
2307 if (t && TREE_VALUE (t) == NULL_TREE)
2308 nothrow = 1;
3101 }
2309 }
2310 check_new = flag_check_new || nothrow;
2311
2312 if ((check_new || flag_exceptions) && rval)
2313 {
2314 alloc_expr = get_target_expr (rval);
2315 alloc_node = rval = TREE_OPERAND (alloc_expr, 0);
2316 }
3102 else
3103 alloc_expr = NULL_TREE;
3104
3105 /* if rval is NULL_TREE I don't have to allocate it, but are we totally
3106 sure we have some extra bytes in that case for the BI_header_size
3107 cookies? And how does that interact with the code below? (mrs) */
3108 /* Finish up some magic for new'ed arrays */
2317 else
2318 alloc_expr = NULL_TREE;
2319
2320 /* if rval is NULL_TREE I don't have to allocate it, but are we totally
2321 sure we have some extra bytes in that case for the BI_header_size
2322 cookies? And how does that interact with the code below? (mrs) */
2323 /* Finish up some magic for new'ed arrays */
3109 if (has_array && TYPE_VEC_NEW_USES_COOKIE (true_type) && rval != NULL_TREE)
2324 if (use_cookie && rval != NULL_TREE)
3110 {
3111 tree extra = BI_header_size;
3112 tree cookie, exp1;
2325 {
2326 tree extra = BI_header_size;
2327 tree cookie, exp1;
3113 rval = convert (ptr_type_node, rval); /* convert to void * first */
3114 rval = convert (string_type_node, rval); /* lets not add void* and ints */
2328 rval = convert (string_type_node, rval); /* for ptr arithmetic */
3115 rval = save_expr (build_binary_op (PLUS_EXPR, rval, extra, 1));
3116 /* Store header info. */
2329 rval = save_expr (build_binary_op (PLUS_EXPR, rval, extra, 1));
2330 /* Store header info. */
3117 cookie = build_indirect_ref (build (MINUS_EXPR, build_pointer_type (BI_header_type),
2331 cookie = build_indirect_ref (build (MINUS_EXPR,
2332 build_pointer_type (BI_header_type),
3118 rval, extra), NULL_PTR);
3119 exp1 = build (MODIFY_EXPR, void_type_node,
2333 rval, extra), NULL_PTR);
2334 exp1 = build (MODIFY_EXPR, void_type_node,
3120 build_component_ref (cookie, nc_nelts_field_id, 0, 0),
2335 build_component_ref (cookie, nc_nelts_field_id,
2336 NULL_TREE, 0),
3121 nelts);
3122 TREE_SIDE_EFFECTS (exp1) = 1;
2337 nelts);
2338 TREE_SIDE_EFFECTS (exp1) = 1;
3123 rval = convert (build_pointer_type (true_type), rval);
3124 TREE_CALLS_NEW (rval) = 1;
3125 TREE_SIDE_EFFECTS (rval) = 1;
3126 rval = build_compound_expr (tree_cons (NULL_TREE, exp1,
3127 build_tree_list (NULL_TREE, rval)));
2339 rval = cp_convert (build_pointer_type (true_type), rval);
2340 rval = build_compound_expr
2341 (expr_tree_cons (NULL_TREE, exp1,
2342 build_expr_list (NULL_TREE, rval)));
3128 }
3129
3130 if (rval == error_mark_node)
3131 return error_mark_node;
3132
3133 /* Don't call any constructors or do any initialization. */
3134 if (init == void_type_node)
3135 goto done;

--- 22 unchanged lines hidden (view full) ---

3158
3159 init = convert_for_initialization (deref, type, init, LOOKUP_NORMAL,
3160 "new", NULL_TREE, 0);
3161 rval = build (COMPOUND_EXPR, TREE_TYPE (rval),
3162 build_modify_expr (deref, NOP_EXPR, init),
3163 rval);
3164 TREE_NO_UNUSED_WARNING (rval) = 1;
3165 TREE_SIDE_EFFECTS (rval) = 1;
2343 }
2344
2345 if (rval == error_mark_node)
2346 return error_mark_node;
2347
2348 /* Don't call any constructors or do any initialization. */
2349 if (init == void_type_node)
2350 goto done;

--- 22 unchanged lines hidden (view full) ---

2373
2374 init = convert_for_initialization (deref, type, init, LOOKUP_NORMAL,
2375 "new", NULL_TREE, 0);
2376 rval = build (COMPOUND_EXPR, TREE_TYPE (rval),
2377 build_modify_expr (deref, NOP_EXPR, init),
2378 rval);
2379 TREE_NO_UNUSED_WARNING (rval) = 1;
2380 TREE_SIDE_EFFECTS (rval) = 1;
3166 TREE_CALLS_NEW (rval) = 1;
3167 }
3168 else if (! has_array)
3169 {
3170 tree newrval;
3171 /* Constructors are never virtual. If it has an initialization, we
3172 need to complain if we aren't allowed to use the ctor that took
3173 that argument. */
3174 int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_COMPLAIN;
3175
3176 if (rval && TYPE_USES_VIRTUAL_BASECLASSES (true_type))
3177 {
2381 }
2382 else if (! has_array)
2383 {
2384 tree newrval;
2385 /* Constructors are never virtual. If it has an initialization, we
2386 need to complain if we aren't allowed to use the ctor that took
2387 that argument. */
2388 int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_COMPLAIN;
2389
2390 if (rval && TYPE_USES_VIRTUAL_BASECLASSES (true_type))
2391 {
3178 init = tree_cons (NULL_TREE, integer_one_node, init);
2392 init = expr_tree_cons (NULL_TREE, integer_one_node, init);
3179 flags |= LOOKUP_HAS_IN_CHARGE;
3180 }
3181
3182 newrval = rval;
3183
3184 if (newrval && TREE_CODE (TREE_TYPE (newrval)) == POINTER_TYPE)
3185 newrval = build_indirect_ref (newrval, NULL_PTR);
3186
2393 flags |= LOOKUP_HAS_IN_CHARGE;
2394 }
2395
2396 newrval = rval;
2397
2398 if (newrval && TREE_CODE (TREE_TYPE (newrval)) == POINTER_TYPE)
2399 newrval = build_indirect_ref (newrval, NULL_PTR);
2400
3187 newrval = build_method_call (newrval, constructor_name_full (true_type),
3188 init, NULL_TREE, flags);
2401 newrval = build_method_call (newrval, ctor_identifier,
2402 init, TYPE_BINFO (true_type), flags);
3189
2403
3190 if (newrval)
3191 {
3192 rval = newrval;
3193 TREE_HAS_CONSTRUCTOR (rval) = 1;
3194 }
3195 else
3196 rval = error_mark_node;
3197 }
3198 else if (current_function_decl == NULL_TREE)
3199 {
3200 extern tree static_aggregates;
2404 if (newrval == NULL_TREE || newrval == error_mark_node)
2405 return error_mark_node;
3201
2406
3202 /* In case of static initialization, SAVE_EXPR is good enough. */
3203 rval = save_expr (rval);
3204 rval = copy_to_permanent (rval);
3205 init = copy_to_permanent (init);
3206 init = expand_vec_init (decl, rval,
3207 build_binary_op (MINUS_EXPR, nelts,
3208 integer_one_node, 1),
3209 init, 0);
3210 init = copy_to_permanent (init);
3211 static_aggregates = perm_tree_cons (init, rval, static_aggregates);
2407 rval = newrval;
2408 TREE_HAS_CONSTRUCTOR (rval) = 1;
3212 }
3213 else
2409 }
2410 else
2411 rval = build (VEC_INIT_EXPR, TREE_TYPE (rval),
2412 save_expr (rval), init, nelts);
2413
2414 /* If any part of the object initialization terminates by throwing
2415 an exception and the new-expression does not contain a
2416 new-placement, then the deallocation function is called to free
2417 the memory in which the object was being constructed. */
2418 if (flag_exceptions && alloc_expr)
3214 {
2419 {
3215 /* Have to wrap this in RTL_EXPR for two cases:
3216 in base or member initialization and if we
3217 are a branch of a ?: operator. Since we
3218 can't easily know the latter, just do it always. */
3219 tree xval = make_node (RTL_EXPR);
2420 enum tree_code dcode = has_array ? VEC_DELETE_EXPR : DELETE_EXPR;
2421 tree cleanup, fn = NULL_TREE;
2422 int flags = LOOKUP_NORMAL | (use_global_new * LOOKUP_GLOBAL);
3220
2423
3221 /* If we want to check the value of the allocation expression,
3222 and the number of elements in the array is not a constant, we
3223 *must* expand the SAVE_EXPR for nelts in alloc_expr before we
3224 expand it in the actual initialization. So we need to build up
3225 an RTL_EXPR for alloc_expr. Sigh. */
3226 if (alloc_expr && ! TREE_CONSTANT (nelts))
2424 /* All cleanups must last longer than normal. */
2425 int yes = suspend_momentary ();
2426
2427 if (placement)
3227 {
2428 {
3228 tree xval = make_node (RTL_EXPR);
3229 rtx rtxval;
3230 TREE_TYPE (xval) = TREE_TYPE (alloc_expr);
3231 do_pending_stack_adjust ();
3232 start_sequence_for_rtl_expr (xval);
3233 emit_note (0, -1);
3234 rtxval = expand_expr (alloc_expr, NULL, VOIDmode, 0);
3235 do_pending_stack_adjust ();
3236 TREE_SIDE_EFFECTS (xval) = 1;
3237 RTL_EXPR_SEQUENCE (xval) = get_insns ();
3238 end_sequence ();
3239 RTL_EXPR_RTL (xval) = rtxval;
3240 TREE_TYPE (xval) = TREE_TYPE (alloc_expr);
3241 alloc_expr = xval;
2429 flags |= LOOKUP_SPECULATIVELY;
2430
2431 /* We expect alloc_expr to look like a TARGET_EXPR around
2432 a NOP_EXPR around the CALL_EXPR we want. */
2433 fn = TREE_OPERAND (alloc_expr, 1);
2434 fn = TREE_OPERAND (fn, 0);
3242 }
3243
2435 }
2436
3244 TREE_TYPE (xval) = TREE_TYPE (rval);
3245 do_pending_stack_adjust ();
3246 start_sequence_for_rtl_expr (xval);
2437 /* Copy size to the saveable obstack. */
2438 size = copy_node (size);
3247
2439
3248 /* As a matter of principle, `start_sequence' should do this. */
3249 emit_note (0, -1);
2440 cleanup = build_op_delete_call (dcode, alloc_node, size, flags, fn);
3250
2441
3251 rval = save_expr (rval);
3252 rval = expand_vec_init (decl, rval,
3253 build_binary_op (MINUS_EXPR, nelts,
3254 integer_one_node, 1),
3255 init, 0);
2442 resume_momentary (yes);
3256
2443
3257 do_pending_stack_adjust ();
2444 /* Ack! First we allocate the memory. Then we set our sentry
2445 variable to true, and expand a cleanup that deletes the memory
2446 if sentry is true. Then we run the constructor and store the
2447 returned pointer in buf. Then we clear sentry and return buf. */
3258
2448
3259 TREE_SIDE_EFFECTS (xval) = 1;
3260 TREE_CALLS_NEW (xval) = 1;
3261 RTL_EXPR_SEQUENCE (xval) = get_insns ();
3262 end_sequence ();
3263
3264 if (TREE_CODE (rval) == SAVE_EXPR)
2449 if (cleanup)
3265 {
2450 {
3266 /* Errors may cause this to not get evaluated. */
3267 if (SAVE_EXPR_RTL (rval) == 0)
3268 SAVE_EXPR_RTL (rval) = const0_rtx;
3269 RTL_EXPR_RTL (xval) = SAVE_EXPR_RTL (rval);
2451#if 0
2452 /* Disable this until flow is fixed so that it doesn't
2453 think the initialization of sentry is a dead write. */
2454 tree end, sentry, begin, buf, t = TREE_TYPE (rval);
2455
2456 begin = get_target_expr (boolean_true_node);
2457 sentry = TREE_OPERAND (begin, 0);
2458
2459 yes = suspend_momentary ();
2460 TREE_OPERAND (begin, 2)
2461 = build (COND_EXPR, void_type_node, sentry,
2462 cleanup, void_zero_node);
2463 resume_momentary (yes);
2464
2465 rval = get_target_expr (rval);
2466
2467 end = build (MODIFY_EXPR, TREE_TYPE (sentry),
2468 sentry, boolean_false_node);
2469 TREE_SIDE_EFFECTS (end) = 1;
2470
2471 buf = TREE_OPERAND (rval, 0);
2472
2473 rval = build (COMPOUND_EXPR, t, begin,
2474 build (COMPOUND_EXPR, t, rval,
2475 build (COMPOUND_EXPR, t, end, buf)));
2476#else
2477 /* FIXME: this is a workaround for a crash due to overlapping
2478 exception regions. Cleanups shouldn't really happen here. */
2479 rval = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (rval), rval);
2480
2481 rval = build (TRY_CATCH_EXPR, TREE_TYPE (rval), rval, cleanup);
2482 rval = build (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval);
2483#endif
3270 }
2484 }
3271 else
3272 {
3273 my_friendly_assert (TREE_CODE (rval) == VAR_DECL, 217);
3274 RTL_EXPR_RTL (xval) = DECL_RTL (rval);
3275 }
3276 rval = xval;
3277 }
3278 }
3279 else if (TYPE_READONLY (true_type))
3280 cp_error ("uninitialized const in `new' of `%#T'", true_type);
3281
3282 done:
3283
2485 }
2486 }
2487 else if (TYPE_READONLY (true_type))
2488 cp_error ("uninitialized const in `new' of `%#T'", true_type);
2489
2490 done:
2491
3284 if (alloc_expr)
2492 if (alloc_expr && rval == alloc_node)
3285 {
2493 {
3286 /* Did we modify the storage? */
3287 if (rval != alloc_temp)
3288 {
3289 tree ifexp = build_binary_op (NE_EXPR, alloc_expr,
3290 integer_zero_node, 1);
3291 rval = build_conditional_expr (ifexp, rval, alloc_temp);
3292 }
3293 else
3294 rval = alloc_expr;
2494 rval = TREE_OPERAND (alloc_expr, 1);
2495 alloc_expr = NULL_TREE;
3295 }
3296
2496 }
2497
3297 if (rval && TREE_TYPE (rval) != build_pointer_type (type))
2498 if (check_new && alloc_expr)
3298 {
2499 {
3299 /* The type of new int [3][3] is not int *, but int [3] * */
3300 rval = build_c_cast (build_pointer_type (type), rval, 0);
2500 /* Did we modify the storage? */
2501 tree ifexp = build_binary_op (NE_EXPR, alloc_node,
2502 integer_zero_node, 1);
2503 rval = build_conditional_expr (ifexp, rval, alloc_node);
3301 }
3302
2504 }
2505
3303 if (pending_sizes)
3304 rval = build_compound_expr (chainon (pending_sizes,
3305 build_tree_list (NULL_TREE, rval)));
2506 if (alloc_expr)
2507 rval = build (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval);
3306
2508
3307 if (flag_gc)
2509 if (rval && TREE_TYPE (rval) != build_pointer_type (type))
3308 {
2510 {
3309 extern tree gc_visible;
3310 tree objbits;
3311 tree update_expr;
3312
3313 rval = save_expr (rval);
3314 /* We don't need a `headof' operation to do this because
3315 we know where the object starts. */
3316 objbits = build1 (INDIRECT_REF, unsigned_type_node,
3317 build (MINUS_EXPR, ptr_type_node,
3318 rval, c_sizeof_nowarn (unsigned_type_node)));
3319 update_expr = build_modify_expr (objbits, BIT_IOR_EXPR, gc_visible);
3320 rval = build_compound_expr (tree_cons (NULL_TREE, rval,
3321 tree_cons (NULL_TREE, update_expr,
3322 build_tree_list (NULL_TREE, rval))));
2511 /* The type of new int [3][3] is not int *, but int [3] * */
2512 rval = build_c_cast (build_pointer_type (type), rval);
3323 }
3324
3325 return rval;
3326}
3327
3328static tree
3329build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete,
3330 use_global_delete)
3331 tree base, maxindex, type;
3332 tree auto_delete_vec, auto_delete;
3333 int use_global_delete;
3334{
3335 tree virtual_size;
2513 }
2514
2515 return rval;
2516}
2517
2518static tree
2519build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete,
2520 use_global_delete)
2521 tree base, maxindex, type;
2522 tree auto_delete_vec, auto_delete;
2523 int use_global_delete;
2524{
2525 tree virtual_size;
3336 tree ptype = build_pointer_type (type);
2526 tree ptype = build_pointer_type (type = complete_type (type));
3337 tree size_exp = size_in_bytes (type);
3338
3339 /* Temporary variables used by the loop. */
3340 tree tbase, tbase_init;
3341
3342 /* This is the body of the loop that implements the deletion of a
3343 single element, and moves temp variables to next elements. */
3344 tree body;

--- 5 unchanged lines hidden (view full) ---

3350 tree deallocate_expr = 0;
3351
3352 /* This is the BIND_EXPR which holds the outermost iterator of the
3353 loop. It is convenient to set this variable up and test it before
3354 executing any other code in the loop.
3355 This is also the containing expression returned by this function. */
3356 tree controller = NULL_TREE;
3357
2527 tree size_exp = size_in_bytes (type);
2528
2529 /* Temporary variables used by the loop. */
2530 tree tbase, tbase_init;
2531
2532 /* This is the body of the loop that implements the deletion of a
2533 single element, and moves temp variables to next elements. */
2534 tree body;

--- 5 unchanged lines hidden (view full) ---

2540 tree deallocate_expr = 0;
2541
2542 /* This is the BIND_EXPR which holds the outermost iterator of the
2543 loop. It is convenient to set this variable up and test it before
2544 executing any other code in the loop.
2545 This is also the containing expression returned by this function. */
2546 tree controller = NULL_TREE;
2547
3358 /* This is the BLOCK to record the symbol binding for debugging. */
3359 tree block;
3360
3361 if (! IS_AGGR_TYPE (type) || ! TYPE_NEEDS_DESTRUCTOR (type))
3362 {
3363 loop = integer_zero_node;
3364 goto no_destructor;
3365 }
3366
3367 /* The below is short by BI_header_size */
3368 virtual_size = fold (size_binop (MULT_EXPR, size_exp, maxindex));
3369
3370 tbase = build_decl (VAR_DECL, NULL_TREE, ptype);
3371 tbase_init = build_modify_expr (tbase, NOP_EXPR,
3372 fold (build (PLUS_EXPR, ptype,
3373 base,
3374 virtual_size)));
3375 DECL_REGISTER (tbase) = 1;
2548 if (! IS_AGGR_TYPE (type) || ! TYPE_NEEDS_DESTRUCTOR (type))
2549 {
2550 loop = integer_zero_node;
2551 goto no_destructor;
2552 }
2553
2554 /* The below is short by BI_header_size */
2555 virtual_size = fold (size_binop (MULT_EXPR, size_exp, maxindex));
2556
2557 tbase = build_decl (VAR_DECL, NULL_TREE, ptype);
2558 tbase_init = build_modify_expr (tbase, NOP_EXPR,
2559 fold (build (PLUS_EXPR, ptype,
2560 base,
2561 virtual_size)));
2562 DECL_REGISTER (tbase) = 1;
3376 controller = build (BIND_EXPR, void_type_node, tbase, 0, 0);
2563 controller = build (BIND_EXPR, void_type_node, tbase, NULL_TREE, NULL_TREE);
3377 TREE_SIDE_EFFECTS (controller) = 1;
2564 TREE_SIDE_EFFECTS (controller) = 1;
3378 block = build_block (tbase, 0, 0, 0, 0);
3379 add_block_current_level (block);
3380
3381 if (auto_delete != integer_zero_node
3382 && auto_delete != integer_two_node)
3383 {
2565
2566 if (auto_delete != integer_zero_node
2567 && auto_delete != integer_two_node)
2568 {
3384 tree base_tbd = convert (ptype,
3385 build_binary_op (MINUS_EXPR,
3386 convert (ptr_type_node, base),
3387 BI_header_size,
3388 1));
2569 tree base_tbd = cp_convert (ptype,
2570 build_binary_op (MINUS_EXPR,
2571 cp_convert (ptr_type_node, base),
2572 BI_header_size,
2573 1));
3389 /* This is the real size */
3390 virtual_size = size_binop (PLUS_EXPR, virtual_size, BI_header_size);
2574 /* This is the real size */
2575 virtual_size = size_binop (PLUS_EXPR, virtual_size, BI_header_size);
3391 body = build_tree_list (NULL_TREE,
2576 body = build_expr_list (NULL_TREE,
3392 build_x_delete (ptype, base_tbd,
3393 2 | use_global_delete,
3394 virtual_size));
3395 body = build (COND_EXPR, void_type_node,
3396 build (BIT_AND_EXPR, integer_type_node,
3397 auto_delete, integer_one_node),
3398 body, integer_zero_node);
3399 }
3400 else
3401 body = NULL_TREE;
3402
2577 build_x_delete (ptype, base_tbd,
2578 2 | use_global_delete,
2579 virtual_size));
2580 body = build (COND_EXPR, void_type_node,
2581 build (BIT_AND_EXPR, integer_type_node,
2582 auto_delete, integer_one_node),
2583 body, integer_zero_node);
2584 }
2585 else
2586 body = NULL_TREE;
2587
3403 body = tree_cons (NULL_TREE,
2588 body = expr_tree_cons (NULL_TREE,
3404 build_delete (ptype, tbase, auto_delete,
3405 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1),
3406 body);
3407
2589 build_delete (ptype, tbase, auto_delete,
2590 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1),
2591 body);
2592
3408 body = tree_cons (NULL_TREE,
2593 body = expr_tree_cons (NULL_TREE,
3409 build_modify_expr (tbase, NOP_EXPR, build (MINUS_EXPR, ptype, tbase, size_exp)),
3410 body);
3411
2594 build_modify_expr (tbase, NOP_EXPR, build (MINUS_EXPR, ptype, tbase, size_exp)),
2595 body);
2596
3412 body = tree_cons (NULL_TREE,
2597 body = expr_tree_cons (NULL_TREE,
3413 build (EXIT_EXPR, void_type_node,
3414 build (EQ_EXPR, boolean_type_node, base, tbase)),
3415 body);
3416
3417 loop = build (LOOP_EXPR, void_type_node, build_compound_expr (body));
3418
2598 build (EXIT_EXPR, void_type_node,
2599 build (EQ_EXPR, boolean_type_node, base, tbase)),
2600 body);
2601
2602 loop = build (LOOP_EXPR, void_type_node, build_compound_expr (body));
2603
3419 loop = tree_cons (NULL_TREE, tbase_init,
3420 tree_cons (NULL_TREE, loop, NULL_TREE));
2604 loop = expr_tree_cons (NULL_TREE, tbase_init,
2605 expr_tree_cons (NULL_TREE, loop, NULL_TREE));
3421 loop = build_compound_expr (loop);
3422
3423 no_destructor:
3424 /* If the delete flag is one, or anything else with the low bit set,
3425 delete the storage. */
3426 if (auto_delete_vec == integer_zero_node
3427 || auto_delete_vec == integer_two_node)
3428 deallocate_expr = integer_zero_node;

--- 4 unchanged lines hidden (view full) ---

3433 /* The below is short by BI_header_size */
3434 virtual_size = fold (size_binop (MULT_EXPR, size_exp, maxindex));
3435
3436 if (! TYPE_VEC_NEW_USES_COOKIE (type))
3437 /* no header */
3438 base_tbd = base;
3439 else
3440 {
2606 loop = build_compound_expr (loop);
2607
2608 no_destructor:
2609 /* If the delete flag is one, or anything else with the low bit set,
2610 delete the storage. */
2611 if (auto_delete_vec == integer_zero_node
2612 || auto_delete_vec == integer_two_node)
2613 deallocate_expr = integer_zero_node;

--- 4 unchanged lines hidden (view full) ---

2618 /* The below is short by BI_header_size */
2619 virtual_size = fold (size_binop (MULT_EXPR, size_exp, maxindex));
2620
2621 if (! TYPE_VEC_NEW_USES_COOKIE (type))
2622 /* no header */
2623 base_tbd = base;
2624 else
2625 {
3441 base_tbd = convert (ptype,
3442 build_binary_op (MINUS_EXPR,
3443 convert (string_type_node, base),
3444 BI_header_size,
3445 1));
3446 /* True size with header. */
2626 base_tbd = cp_convert (ptype,
2627 build_binary_op (MINUS_EXPR,
2628 cp_convert (string_type_node, base),
2629 BI_header_size,
2630 1));
2631 /* True size with header. */
3447 virtual_size = size_binop (PLUS_EXPR, virtual_size, BI_header_size);
3448 }
3449 deallocate_expr = build_x_delete (ptype, base_tbd,
3450 2 | use_global_delete,
3451 virtual_size);
3452 if (auto_delete_vec != integer_one_node)
3453 deallocate_expr = build (COND_EXPR, void_type_node,
3454 build (BIT_AND_EXPR, integer_type_node,
3455 auto_delete_vec, integer_one_node),
3456 deallocate_expr, integer_zero_node);
3457 }
3458
3459 if (loop && deallocate_expr != integer_zero_node)
3460 {
2632 virtual_size = size_binop (PLUS_EXPR, virtual_size, BI_header_size);
2633 }
2634 deallocate_expr = build_x_delete (ptype, base_tbd,
2635 2 | use_global_delete,
2636 virtual_size);
2637 if (auto_delete_vec != integer_one_node)
2638 deallocate_expr = build (COND_EXPR, void_type_node,
2639 build (BIT_AND_EXPR, integer_type_node,
2640 auto_delete_vec, integer_one_node),
2641 deallocate_expr, integer_zero_node);
2642 }
2643
2644 if (loop && deallocate_expr != integer_zero_node)
2645 {
3461 body = tree_cons (NULL_TREE, loop,
3462 tree_cons (NULL_TREE, deallocate_expr, NULL_TREE));
2646 body = expr_tree_cons (NULL_TREE, loop,
2647 expr_tree_cons (NULL_TREE, deallocate_expr, NULL_TREE));
3463 body = build_compound_expr (body);
3464 }
3465 else
3466 body = loop;
3467
3468 /* Outermost wrapper: If pointer is null, punt. */
3469 body = build (COND_EXPR, void_type_node,
3470 build (NE_EXPR, boolean_type_node, base, integer_zero_node),
3471 body, integer_zero_node);
3472 body = build1 (NOP_EXPR, void_type_node, body);
3473
3474 if (controller)
3475 {
3476 TREE_OPERAND (controller, 1) = body;
3477 return controller;
3478 }
3479 else
2648 body = build_compound_expr (body);
2649 }
2650 else
2651 body = loop;
2652
2653 /* Outermost wrapper: If pointer is null, punt. */
2654 body = build (COND_EXPR, void_type_node,
2655 build (NE_EXPR, boolean_type_node, base, integer_zero_node),
2656 body, integer_zero_node);
2657 body = build1 (NOP_EXPR, void_type_node, body);
2658
2659 if (controller)
2660 {
2661 TREE_OPERAND (controller, 1) = body;
2662 return controller;
2663 }
2664 else
3480 return convert (void_type_node, body);
2665 return cp_convert (void_type_node, body);
3481}
3482
3483/* Build a tree to cleanup partially built arrays.
3484 BASE is that starting address of the array.
3485 COUNT is the count of objects that have been built, that need destroying.
3486 TYPE is the type of elements in the array. */
2666}
2667
2668/* Build a tree to cleanup partially built arrays.
2669 BASE is that starting address of the array.
2670 COUNT is the count of objects that have been built, that need destroying.
2671 TYPE is the type of elements in the array. */
2672
3487static tree
3488build_array_eh_cleanup (base, count, type)
3489 tree base, count, type;
3490{
3491 tree expr = build_vec_delete_1 (base, count, type, integer_two_node,
3492 integer_zero_node, 0);
3493 return expr;
3494}

--- 20 unchanged lines hidden (view full) ---

3515 tree decl, base, maxindex, init;
3516 int from_array;
3517{
3518 tree rval;
3519 tree iterator, base2 = NULL_TREE;
3520 tree type = TREE_TYPE (TREE_TYPE (base));
3521 tree size;
3522
2673static tree
2674build_array_eh_cleanup (base, count, type)
2675 tree base, count, type;
2676{
2677 tree expr = build_vec_delete_1 (base, count, type, integer_two_node,
2678 integer_zero_node, 0);
2679 return expr;
2680}

--- 20 unchanged lines hidden (view full) ---

2701 tree decl, base, maxindex, init;
2702 int from_array;
2703{
2704 tree rval;
2705 tree iterator, base2 = NULL_TREE;
2706 tree type = TREE_TYPE (TREE_TYPE (base));
2707 tree size;
2708
3523 maxindex = convert (integer_type_node, maxindex);
2709 maxindex = cp_convert (ptrdiff_type_node, maxindex);
3524 if (maxindex == error_mark_node)
3525 return error_mark_node;
3526
3527 if (current_function_decl == NULL_TREE)
3528 {
3529 rval = make_tree_vec (3);
3530 TREE_VEC_ELT (rval, 0) = base;
3531 TREE_VEC_ELT (rval, 1) = maxindex;
3532 TREE_VEC_ELT (rval, 2) = init;
3533 return rval;
3534 }
3535
3536 size = size_in_bytes (type);
3537
3538 /* Set to zero in case size is <= 0. Optimizer will delete this if
3539 it is not needed. */
3540 rval = get_temp_regvar (build_pointer_type (type),
2710 if (maxindex == error_mark_node)
2711 return error_mark_node;
2712
2713 if (current_function_decl == NULL_TREE)
2714 {
2715 rval = make_tree_vec (3);
2716 TREE_VEC_ELT (rval, 0) = base;
2717 TREE_VEC_ELT (rval, 1) = maxindex;
2718 TREE_VEC_ELT (rval, 2) = init;
2719 return rval;
2720 }
2721
2722 size = size_in_bytes (type);
2723
2724 /* Set to zero in case size is <= 0. Optimizer will delete this if
2725 it is not needed. */
2726 rval = get_temp_regvar (build_pointer_type (type),
3541 convert (build_pointer_type (type), null_pointer_node));
2727 cp_convert (build_pointer_type (type), null_pointer_node));
3542 base = default_conversion (base);
2728 base = default_conversion (base);
3543 base = convert (build_pointer_type (type), base);
2729 base = cp_convert (build_pointer_type (type), base);
3544 expand_assignment (rval, base, 0, 0);
3545 base = get_temp_regvar (build_pointer_type (type), base);
3546
3547 if (init != NULL_TREE
3548 && TREE_CODE (init) == CONSTRUCTOR
2730 expand_assignment (rval, base, 0, 0);
2731 base = get_temp_regvar (build_pointer_type (type), base);
2732
2733 if (init != NULL_TREE
2734 && TREE_CODE (init) == CONSTRUCTOR
3549 && TREE_TYPE (init) == TREE_TYPE (decl))
2735 && (! decl || TREE_TYPE (init) == TREE_TYPE (decl)))
3550 {
3551 /* Initialization of array from {...}. */
3552 tree elts = CONSTRUCTOR_ELTS (init);
3553 tree baseref = build1 (INDIRECT_REF, type, base);
3554 tree baseinc = build (PLUS_EXPR, build_pointer_type (type), base, size);
3555 int host_i = TREE_INT_CST_LOW (maxindex);
3556
3557 if (IS_AGGR_TYPE (type))

--- 11 unchanged lines hidden (view full) ---

3569 {
3570 if (TYPE_NEEDS_CONSTRUCTING (type) == 0)
3571 {
3572 if (obey_regdecls)
3573 use_variable (DECL_RTL (base));
3574 goto done_init;
3575 }
3576
2736 {
2737 /* Initialization of array from {...}. */
2738 tree elts = CONSTRUCTOR_ELTS (init);
2739 tree baseref = build1 (INDIRECT_REF, type, base);
2740 tree baseinc = build (PLUS_EXPR, build_pointer_type (type), base, size);
2741 int host_i = TREE_INT_CST_LOW (maxindex);
2742
2743 if (IS_AGGR_TYPE (type))

--- 11 unchanged lines hidden (view full) ---

2755 {
2756 if (TYPE_NEEDS_CONSTRUCTING (type) == 0)
2757 {
2758 if (obey_regdecls)
2759 use_variable (DECL_RTL (base));
2760 goto done_init;
2761 }
2762
3577 iterator = get_temp_regvar (integer_type_node,
2763 iterator = get_temp_regvar (ptrdiff_type_node,
3578 build_int_2 (host_i, 0));
3579 init = NULL_TREE;
3580 goto init_by_default;
3581 }
3582 }
3583 else
3584 while (elts)
3585 {

--- 5 unchanged lines hidden (view full) ---

3591
3592 if (obey_regdecls)
3593 use_variable (DECL_RTL (base));
3594 }
3595 else
3596 {
3597 tree itype;
3598
2764 build_int_2 (host_i, 0));
2765 init = NULL_TREE;
2766 goto init_by_default;
2767 }
2768 }
2769 else
2770 while (elts)
2771 {

--- 5 unchanged lines hidden (view full) ---

2777
2778 if (obey_regdecls)
2779 use_variable (DECL_RTL (base));
2780 }
2781 else
2782 {
2783 tree itype;
2784
3599 iterator = get_temp_regvar (integer_type_node, maxindex);
2785 iterator = get_temp_regvar (ptrdiff_type_node, maxindex);
3600
3601 init_by_default:
2786
2787 init_by_default:
2788 itype = NULL_TREE;
3602
3603 /* If initializing one array from another,
3604 initialize element by element. */
3605 if (from_array)
3606 {
3607 /* We rely upon the below calls the do argument checking */
3608 if (decl == NULL_TREE)
3609 {

--- 14 unchanged lines hidden (view full) ---

3624 error ("initializer ends prematurely");
3625 return error_mark_node;
3626 }
3627 }
3628
3629 expand_start_cond (build (GE_EXPR, boolean_type_node,
3630 iterator, integer_zero_node), 0);
3631 if (TYPE_NEEDS_DESTRUCTOR (type))
2789
2790 /* If initializing one array from another,
2791 initialize element by element. */
2792 if (from_array)
2793 {
2794 /* We rely upon the below calls the do argument checking */
2795 if (decl == NULL_TREE)
2796 {

--- 14 unchanged lines hidden (view full) ---

2811 error ("initializer ends prematurely");
2812 return error_mark_node;
2813 }
2814 }
2815
2816 expand_start_cond (build (GE_EXPR, boolean_type_node,
2817 iterator, integer_zero_node), 0);
2818 if (TYPE_NEEDS_DESTRUCTOR (type))
3632 start_protect ();
2819 expand_eh_region_start ();
3633 expand_start_loop_continue_elsewhere (1);
3634
2820 expand_start_loop_continue_elsewhere (1);
2821
2822 /* The initialization of each array element is a full-expression. */
2823 expand_start_target_temps ();
2824
3635 if (from_array)
3636 {
3637 tree to = build1 (INDIRECT_REF, type, base);
3638 tree from;
3639
3640 if (base2)
3641 from = build1 (INDIRECT_REF, itype, base2);
3642 else

--- 19 unchanged lines hidden (view full) ---

3662 expand_aggr_init (build1 (INDIRECT_REF, type, base), init, 0, 0);
3663
3664 expand_assignment (base,
3665 build (PLUS_EXPR, build_pointer_type (type), base, size),
3666 0, 0);
3667 if (base2)
3668 expand_assignment (base2,
3669 build (PLUS_EXPR, build_pointer_type (type), base2, size), 0, 0);
2825 if (from_array)
2826 {
2827 tree to = build1 (INDIRECT_REF, type, base);
2828 tree from;
2829
2830 if (base2)
2831 from = build1 (INDIRECT_REF, itype, base2);
2832 else

--- 19 unchanged lines hidden (view full) ---

2852 expand_aggr_init (build1 (INDIRECT_REF, type, base), init, 0, 0);
2853
2854 expand_assignment (base,
2855 build (PLUS_EXPR, build_pointer_type (type), base, size),
2856 0, 0);
2857 if (base2)
2858 expand_assignment (base2,
2859 build (PLUS_EXPR, build_pointer_type (type), base2, size), 0, 0);
2860
2861 /* Cleanup any temporaries needed for the initial value. */
2862 expand_end_target_temps ();
2863
3670 expand_loop_continue_here ();
3671 expand_exit_loop_if_false (0, build (NE_EXPR, boolean_type_node,
2864 expand_loop_continue_here ();
2865 expand_exit_loop_if_false (0, build (NE_EXPR, boolean_type_node,
3672 build (PREDECREMENT_EXPR, integer_type_node, iterator, integer_one_node), minus_one));
2866 build (PREDECREMENT_EXPR, ptrdiff_type_node, iterator, integer_one_node), minus_one));
3673
3674 if (obey_regdecls)
3675 {
3676 use_variable (DECL_RTL (base));
3677 if (base2)
3678 use_variable (DECL_RTL (base2));
3679 }
3680 expand_end_loop ();
2867
2868 if (obey_regdecls)
2869 {
2870 use_variable (DECL_RTL (base));
2871 if (base2)
2872 use_variable (DECL_RTL (base2));
2873 }
2874 expand_end_loop ();
3681 if (TYPE_NEEDS_DESTRUCTOR (type))
3682 end_protect (build_array_eh_cleanup (rval,
3683 build_binary_op (MINUS_EXPR,
3684 maxindex,
3685 iterator,
3686 1),
3687 type));
2875 if (TYPE_NEEDS_DESTRUCTOR (type) && flag_exceptions)
2876 {
2877 /* We have to ensure that this can live to the cleanup
2878 expansion time, since we know it is only ever needed
2879 once, generate code now. */
2880 push_obstacks_nochange ();
2881 resume_temporary_allocation ();
2882 {
2883 tree e1, cleanup = make_node (RTL_EXPR);
2884 TREE_TYPE (cleanup) = void_type_node;
2885 RTL_EXPR_RTL (cleanup) = const0_rtx;
2886 TREE_SIDE_EFFECTS (cleanup) = 1;
2887 do_pending_stack_adjust ();
2888 start_sequence_for_rtl_expr (cleanup);
2889
2890 e1 = build_array_eh_cleanup
2891 (rval,
2892 build_binary_op (MINUS_EXPR, maxindex, iterator, 1),
2893 type);
2894 expand_expr (e1, const0_rtx, VOIDmode, EXPAND_NORMAL);
2895 do_pending_stack_adjust ();
2896 RTL_EXPR_SEQUENCE (cleanup) = get_insns ();
2897 end_sequence ();
2898
2899 cleanup = protect_with_terminate (cleanup);
2900 expand_eh_region_end (cleanup);
2901 }
2902 pop_obstacks ();
2903 }
3688 expand_end_cond ();
3689 if (obey_regdecls)
3690 use_variable (DECL_RTL (iterator));
3691 }
3692 done_init:
3693
3694 if (obey_regdecls)
3695 use_variable (DECL_RTL (rval));

--- 8 unchanged lines hidden (view full) ---

3704 VIRTUAL_SIZE is the amount of storage that was allocated, and is
3705 used as the second argument to operator delete. It can include
3706 things like padding and magic size cookies. It has virtual in it,
3707 because if you have a base pointer and you delete through a virtual
3708 destructor, it should be the size of the dynamic object, not the
3709 static object, see Free Store 12.5 ANSI C++ WP.
3710
3711 This does not call any destructors. */
2904 expand_end_cond ();
2905 if (obey_regdecls)
2906 use_variable (DECL_RTL (iterator));
2907 }
2908 done_init:
2909
2910 if (obey_regdecls)
2911 use_variable (DECL_RTL (rval));

--- 8 unchanged lines hidden (view full) ---

2920 VIRTUAL_SIZE is the amount of storage that was allocated, and is
2921 used as the second argument to operator delete. It can include
2922 things like padding and magic size cookies. It has virtual in it,
2923 because if you have a base pointer and you delete through a virtual
2924 destructor, it should be the size of the dynamic object, not the
2925 static object, see Free Store 12.5 ANSI C++ WP.
2926
2927 This does not call any destructors. */
2928
3712tree
3713build_x_delete (type, addr, which_delete, virtual_size)
3714 tree type, addr;
3715 int which_delete;
3716 tree virtual_size;
3717{
3718 int use_global_delete = which_delete & 1;
3719 int use_vec_delete = !!(which_delete & 2);
2929tree
2930build_x_delete (type, addr, which_delete, virtual_size)
2931 tree type, addr;
2932 int which_delete;
2933 tree virtual_size;
2934{
2935 int use_global_delete = which_delete & 1;
2936 int use_vec_delete = !!(which_delete & 2);
3720 tree rval;
3721 enum tree_code code = use_vec_delete ? VEC_DELETE_EXPR : DELETE_EXPR;
2937 enum tree_code code = use_vec_delete ? VEC_DELETE_EXPR : DELETE_EXPR;
2938 int flags = LOOKUP_NORMAL | (use_global_delete * LOOKUP_GLOBAL);
3722
2939
3723 if (! use_global_delete && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
3724 && (TYPE_GETS_DELETE (TREE_TYPE (type)) & (1 << use_vec_delete)))
3725 rval = build_opfncall (code, LOOKUP_NORMAL, addr, virtual_size, NULL_TREE);
3726 else
3727 rval = build_builtin_call (void_type_node, use_vec_delete ? BIVD : BID,
3728 build_tree_list (NULL_TREE, addr));
3729 return rval;
2940 return build_op_delete_call (code, addr, virtual_size, flags, NULL_TREE);
3730}
3731
3732/* Generate a call to a destructor. TYPE is the type to cast ADDR to.
3733 ADDR is an expression which yields the store to be destroyed.
3734 AUTO_DELETE is nonzero if a call to DELETE should be made or not.
3735 If in the program, (AUTO_DELETE & 2) is non-zero, we tear down the
3736 virtual baseclasses.
3737 If in the program, (AUTO_DELETE & 1) is non-zero, then we deallocate.
3738
3739 FLAGS is the logical disjunction of zero or more LOOKUP_
3740 flags. See cp-tree.h for more info.
3741
3742 This function does not delete an object's virtual base classes. */
2941}
2942
2943/* Generate a call to a destructor. TYPE is the type to cast ADDR to.
2944 ADDR is an expression which yields the store to be destroyed.
2945 AUTO_DELETE is nonzero if a call to DELETE should be made or not.
2946 If in the program, (AUTO_DELETE & 2) is non-zero, we tear down the
2947 virtual baseclasses.
2948 If in the program, (AUTO_DELETE & 1) is non-zero, then we deallocate.
2949
2950 FLAGS is the logical disjunction of zero or more LOOKUP_
2951 flags. See cp-tree.h for more info.
2952
2953 This function does not delete an object's virtual base classes. */
2954
3743tree
3744build_delete (type, addr, auto_delete, flags, use_global_delete)
3745 tree type, addr;
3746 tree auto_delete;
3747 int flags;
3748 int use_global_delete;
3749{
2955tree
2956build_delete (type, addr, auto_delete, flags, use_global_delete)
2957 tree type, addr;
2958 tree auto_delete;
2959 int flags;
2960 int use_global_delete;
2961{
3750 tree function, parms;
3751 tree member;
3752 tree expr;
3753 tree ref;
2962 tree member;
2963 tree expr;
2964 tree ref;
3754 int ptr;
3755
3756 if (addr == error_mark_node)
3757 return error_mark_node;
3758
3759 /* Can happen when CURRENT_EXCEPTION_OBJECT gets its type
3760 set to `error_mark_node' before it gets properly cleaned up. */
3761 if (type == error_mark_node)
3762 return error_mark_node;
3763
3764 type = TYPE_MAIN_VARIANT (type);
3765
3766 if (TREE_CODE (type) == POINTER_TYPE)
3767 {
3768 type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
2965
2966 if (addr == error_mark_node)
2967 return error_mark_node;
2968
2969 /* Can happen when CURRENT_EXCEPTION_OBJECT gets its type
2970 set to `error_mark_node' before it gets properly cleaned up. */
2971 if (type == error_mark_node)
2972 return error_mark_node;
2973
2974 type = TYPE_MAIN_VARIANT (type);
2975
2976 if (TREE_CODE (type) == POINTER_TYPE)
2977 {
2978 type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
3769 if (TYPE_SIZE (type) == 0)
3770 {
3771 incomplete_type_error (0, type);
3772 return error_mark_node;
3773 }
2979 if (!complete_type_or_else (type))
2980 return error_mark_node;
3774 if (TREE_CODE (type) == ARRAY_TYPE)
3775 goto handle_array;
3776 if (! IS_AGGR_TYPE (type))
3777 {
3778 /* Call the builtin operator delete. */
3779 return build_builtin_call (void_type_node, BID,
2981 if (TREE_CODE (type) == ARRAY_TYPE)
2982 goto handle_array;
2983 if (! IS_AGGR_TYPE (type))
2984 {
2985 /* Call the builtin operator delete. */
2986 return build_builtin_call (void_type_node, BID,
3780 build_tree_list (NULL_TREE, addr));
2987 build_expr_list (NULL_TREE, addr));
3781 }
3782 if (TREE_SIDE_EFFECTS (addr))
3783 addr = save_expr (addr);
3784
3785 /* throw away const and volatile on target type of addr */
3786 addr = convert_force (build_pointer_type (type), addr, 0);
3787 ref = build_indirect_ref (addr, NULL_PTR);
2988 }
2989 if (TREE_SIDE_EFFECTS (addr))
2990 addr = save_expr (addr);
2991
2992 /* throw away const and volatile on target type of addr */
2993 addr = convert_force (build_pointer_type (type), addr, 0);
2994 ref = build_indirect_ref (addr, NULL_PTR);
3788 ptr = 1;
3789 }
3790 else if (TREE_CODE (type) == ARRAY_TYPE)
3791 {
3792 handle_array:
3793 if (TREE_SIDE_EFFECTS (addr))
3794 addr = save_expr (addr);
3795 if (TYPE_DOMAIN (type) == NULL_TREE)
3796 {
3797 error ("unknown array size in delete");
3798 return error_mark_node;
3799 }
3800 return build_vec_delete (addr, array_type_nelts (type),
2995 }
2996 else if (TREE_CODE (type) == ARRAY_TYPE)
2997 {
2998 handle_array:
2999 if (TREE_SIDE_EFFECTS (addr))
3000 addr = save_expr (addr);
3001 if (TYPE_DOMAIN (type) == NULL_TREE)
3002 {
3003 error ("unknown array size in delete");
3004 return error_mark_node;
3005 }
3006 return build_vec_delete (addr, array_type_nelts (type),
3801 c_sizeof_nowarn (TREE_TYPE (type)),
3802 auto_delete, integer_two_node,
3803 use_global_delete);
3804 }
3805 else
3806 {
3807 /* Don't check PROTECT here; leave that decision to the
3808 destructor. If the destructor is accessible, call it,
3809 else report error. */
3810 addr = build_unary_op (ADDR_EXPR, addr, 0);
3811 if (TREE_SIDE_EFFECTS (addr))
3812 addr = save_expr (addr);
3813
3814 if (TREE_CONSTANT (addr))
3815 addr = convert_pointer_to (type, addr);
3816 else
3817 addr = convert_force (build_pointer_type (type), addr, 0);
3818
3007 auto_delete, integer_two_node,
3008 use_global_delete);
3009 }
3010 else
3011 {
3012 /* Don't check PROTECT here; leave that decision to the
3013 destructor. If the destructor is accessible, call it,
3014 else report error. */
3015 addr = build_unary_op (ADDR_EXPR, addr, 0);
3016 if (TREE_SIDE_EFFECTS (addr))
3017 addr = save_expr (addr);
3018
3019 if (TREE_CONSTANT (addr))
3020 addr = convert_pointer_to (type, addr);
3021 else
3022 addr = convert_force (build_pointer_type (type), addr, 0);
3023
3819 if (TREE_CODE (addr) == NOP_EXPR
3820 && TREE_OPERAND (addr, 0) == current_class_decl)
3821 ref = C_C_D;
3822 else
3823 ref = build_indirect_ref (addr, NULL_PTR);
3824 ptr = 0;
3024 ref = build_indirect_ref (addr, NULL_PTR);
3825 }
3826
3827 my_friendly_assert (IS_AGGR_TYPE (type), 220);
3828
3829 if (! TYPE_NEEDS_DESTRUCTOR (type))
3830 {
3831 if (auto_delete == integer_zero_node)
3832 return void_zero_node;
3833
3025 }
3026
3027 my_friendly_assert (IS_AGGR_TYPE (type), 220);
3028
3029 if (! TYPE_NEEDS_DESTRUCTOR (type))
3030 {
3031 if (auto_delete == integer_zero_node)
3032 return void_zero_node;
3033
3834 /* Pass the size of the object down to the operator delete() in
3835 addition to the ADDR. */
3836 if (TYPE_GETS_REG_DELETE (type) && !use_global_delete)
3837 {
3838 tree virtual_size = c_sizeof_nowarn (type);
3839 return build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr,
3840 virtual_size, NULL_TREE);
3841 }
3842
3843 /* Call the builtin operator delete. */
3844 return build_builtin_call (void_type_node, BID,
3845 build_tree_list (NULL_TREE, addr));
3034 return build_op_delete_call
3035 (DELETE_EXPR, addr, c_sizeof_nowarn (type),
3036 LOOKUP_NORMAL | (use_global_delete * LOOKUP_GLOBAL),
3037 NULL_TREE);
3846 }
3038 }
3847 parms = build_tree_list (NULL_TREE, addr);
3848
3849 /* Below, we will reverse the order in which these calls are made.
3850 If we have a destructor, then that destructor will take care
3851 of the base classes; otherwise, we must do that here. */
3852 if (TYPE_HAS_DESTRUCTOR (type))
3853 {
3039
3040 /* Below, we will reverse the order in which these calls are made.
3041 If we have a destructor, then that destructor will take care
3042 of the base classes; otherwise, we must do that here. */
3043 if (TYPE_HAS_DESTRUCTOR (type))
3044 {
3854 tree dtor = DECL_MAIN_VARIANT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0));
3855 tree basetypes = TYPE_BINFO (type);
3856 tree passed_auto_delete;
3857 tree do_delete = NULL_TREE;
3045 tree passed_auto_delete;
3046 tree do_delete = NULL_TREE;
3047 tree ifexp;
3858
3859 if (use_global_delete)
3860 {
3861 tree cond = fold (build (BIT_AND_EXPR, integer_type_node,
3862 auto_delete, integer_one_node));
3863 tree call = build_builtin_call
3048
3049 if (use_global_delete)
3050 {
3051 tree cond = fold (build (BIT_AND_EXPR, integer_type_node,
3052 auto_delete, integer_one_node));
3053 tree call = build_builtin_call
3864 (void_type_node, BID, build_tree_list (NULL_TREE, addr));
3054 (void_type_node, BID, build_expr_list (NULL_TREE, addr));
3865
3866 cond = fold (build (COND_EXPR, void_type_node, cond,
3867 call, void_zero_node));
3868 if (cond != void_zero_node)
3869 do_delete = cond;
3870
3871 passed_auto_delete = fold (build (BIT_AND_EXPR, integer_type_node,
3872 auto_delete, integer_two_node));
3873 }
3874 else
3875 passed_auto_delete = auto_delete;
3876
3055
3056 cond = fold (build (COND_EXPR, void_type_node, cond,
3057 call, void_zero_node));
3058 if (cond != void_zero_node)
3059 do_delete = cond;
3060
3061 passed_auto_delete = fold (build (BIT_AND_EXPR, integer_type_node,
3062 auto_delete, integer_two_node));
3063 }
3064 else
3065 passed_auto_delete = auto_delete;
3066
3877 if (flags & LOOKUP_PROTECT)
3878 {
3879 enum access_type access = compute_access (basetypes, dtor);
3067 expr = build_method_call
3068 (ref, dtor_identifier, build_expr_list (NULL_TREE, passed_auto_delete),
3069 NULL_TREE, flags);
3880
3070
3881 if (access == access_private)
3882 {
3883 if (flags & LOOKUP_COMPLAIN)
3884 cp_error ("destructor for type `%T' is private in this scope", type);
3885 return error_mark_node;
3886 }
3887 else if (access == access_protected)
3888 {
3889 if (flags & LOOKUP_COMPLAIN)
3890 cp_error ("destructor for type `%T' is protected in this scope", type);
3891 return error_mark_node;
3892 }
3893 }
3071 if (do_delete)
3072 expr = build (COMPOUND_EXPR, void_type_node, expr, do_delete);
3894
3073
3895 /* Once we are in a destructor, try not going through
3896 the virtual function table to find the next destructor. */
3897 if (DECL_VINDEX (dtor)
3898 && ! (flags & LOOKUP_NONVIRTUAL)
3899 && TREE_CODE (auto_delete) != PARM_DECL
3900 && (ptr == 1 || ! resolves_to_fixed_type_p (ref, 0)))
3901 {
3902 tree binfo, basetype;
3903 /* The code below is probably all broken. See call.c for the
3904 complete right way to do this. this offsets may not be right
3905 in the below. (mrs) */
3906 /* This destructor must be called via virtual function table. */
3907 dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (DECL_CONTEXT (dtor)), 0);
3908 basetype = DECL_CLASS_CONTEXT (dtor);
3909 binfo = get_binfo (basetype,
3910 TREE_TYPE (TREE_TYPE (TREE_VALUE (parms))),
3911 0);
3912 expr = convert_pointer_to_real (binfo, TREE_VALUE (parms));
3913 if (expr != TREE_VALUE (parms))
3914 {
3915 expr = fold (expr);
3916 ref = build_indirect_ref (expr, NULL_PTR);
3917 TREE_VALUE (parms) = expr;
3918 }
3919 function = build_vfn_ref (&TREE_VALUE (parms), ref, DECL_VINDEX (dtor));
3920 if (function == error_mark_node)
3921 return error_mark_node;
3922 TREE_TYPE (function) = build_pointer_type (TREE_TYPE (dtor));
3923 TREE_CHAIN (parms) = build_tree_list (NULL_TREE, passed_auto_delete);
3924 expr = build_function_call (function, parms);
3925 if (do_delete)
3926 expr = build (COMPOUND_EXPR, void_type_node, expr, do_delete);
3927 if (ptr && (flags & LOOKUP_DESTRUCTOR) == 0)
3928 {
3929 /* Handle the case where a virtual destructor is
3930 being called on an item that is 0.
3931
3932 @@ Does this really need to be done? */
3933 tree ifexp = build_binary_op(NE_EXPR, addr, integer_zero_node,1);
3934#if 0
3935 if (TREE_CODE (ref) == VAR_DECL
3936 || TREE_CODE (ref) == COMPONENT_REF)
3937 warning ("losing in build_delete");
3938#endif
3939 expr = build (COND_EXPR, void_type_node,
3940 ifexp, expr, void_zero_node);
3941 }
3942 }
3074 if (flags & LOOKUP_DESTRUCTOR)
3075 /* Explicit destructor call; don't check for null pointer. */
3076 ifexp = integer_one_node;
3943 else
3077 else
3944 {
3945 tree ifexp;
3078 /* Handle deleting a null pointer. */
3079 ifexp = fold (build_binary_op (NE_EXPR, addr, integer_zero_node, 1));
3946
3080
3947 if ((flags & LOOKUP_DESTRUCTOR)
3948 || TREE_CODE (ref) == VAR_DECL
3949 || TREE_CODE (ref) == PARM_DECL
3950 || TREE_CODE (ref) == COMPONENT_REF
3951 || TREE_CODE (ref) == ARRAY_REF)
3952 /* These can't be 0. */
3953 ifexp = integer_one_node;
3954 else
3955 /* Handle the case where a non-virtual destructor is
3956 being called on an item that is 0. */
3957 ifexp = build_binary_op (NE_EXPR, addr, integer_zero_node, 1);
3081 if (ifexp != integer_one_node)
3082 expr = build (COND_EXPR, void_type_node,
3083 ifexp, expr, void_zero_node);
3958
3084
3959 /* Used to mean that this destructor was known to be empty,
3960 but that's now obsolete. */
3961 my_friendly_assert (DECL_INITIAL (dtor) != void_type_node, 221);
3962
3963 TREE_CHAIN (parms) = build_tree_list (NULL_TREE, passed_auto_delete);
3964 expr = build_function_call (dtor, parms);
3965 if (do_delete)
3966 expr = build (COMPOUND_EXPR, void_type_node, expr, do_delete);
3967
3968 if (ifexp != integer_one_node)
3969 expr = build (COND_EXPR, void_type_node,
3970 ifexp, expr, void_zero_node);
3971 }
3972 return expr;
3973 }
3974 else
3975 {
3085 return expr;
3086 }
3087 else
3088 {
3976 /* This can get visibilities wrong. */
3089 /* We only get here from finish_function for a destructor. */
3977 tree binfos = BINFO_BASETYPES (TYPE_BINFO (type));
3978 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3979 tree base_binfo = n_baseclasses > 0 ? TREE_VEC_ELT (binfos, 0) : NULL_TREE;
3980 tree exprstmt = NULL_TREE;
3981 tree parent_auto_delete = auto_delete;
3982 tree cond;
3983
3090 tree binfos = BINFO_BASETYPES (TYPE_BINFO (type));
3091 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3092 tree base_binfo = n_baseclasses > 0 ? TREE_VEC_ELT (binfos, 0) : NULL_TREE;
3093 tree exprstmt = NULL_TREE;
3094 tree parent_auto_delete = auto_delete;
3095 tree cond;
3096
3984 /* If this type does not have a destructor, but does have
3985 operator delete, call the parent parent destructor (if any),
3986 but let this node do the deleting. Otherwise, it is ok
3987 to let the parent destructor do the deleting. */
3988 if (TYPE_GETS_REG_DELETE (type) && !use_global_delete)
3989 {
3990 parent_auto_delete = integer_zero_node;
3991 if (auto_delete == integer_zero_node)
3992 cond = NULL_TREE;
3993 else
3994 {
3995 tree virtual_size;
3996
3997 /* This is probably wrong. It should be the size of the
3998 virtual object being deleted. */
3999 virtual_size = c_sizeof_nowarn (type);
4000
4001 expr = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr,
4002 virtual_size, NULL_TREE);
4003 if (expr == error_mark_node)
4004 return error_mark_node;
4005 if (auto_delete != integer_one_node)
4006 cond = build (COND_EXPR, void_type_node,
4007 build (BIT_AND_EXPR, integer_type_node,
4008 auto_delete, integer_one_node),
4009 expr, void_zero_node);
4010 else
4011 cond = expr;
4012 }
4013 }
3097 /* If we have member delete or vbases, we call delete in
3098 finish_function. */
3099 if (auto_delete == integer_zero_node)
3100 cond = NULL_TREE;
4014 else if (base_binfo == NULL_TREE
3101 else if (base_binfo == NULL_TREE
4015 || (TREE_VIA_VIRTUAL (base_binfo) == 0
4016 && ! TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo))))
3102 || ! TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo)))
4017 {
3103 {
4018 tree virtual_size;
4019
4020 /* This is probably wrong. It should be the size of the virtual
4021 object being deleted. */
4022 virtual_size = c_sizeof_nowarn (type);
4023
4024 cond = build (COND_EXPR, void_type_node,
4025 build (BIT_AND_EXPR, integer_type_node, auto_delete, integer_one_node),
4026 build_builtin_call (void_type_node, BID,
3104 cond = build (COND_EXPR, void_type_node,
3105 build (BIT_AND_EXPR, integer_type_node, auto_delete, integer_one_node),
3106 build_builtin_call (void_type_node, BID,
4027 build_tree_list (NULL_TREE, addr)),
3107 build_expr_list (NULL_TREE, addr)),
4028 void_zero_node);
4029 }
4030 else
4031 cond = NULL_TREE;
4032
4033 if (cond)
3108 void_zero_node);
3109 }
3110 else
3111 cond = NULL_TREE;
3112
3113 if (cond)
4034 exprstmt = build_tree_list (NULL_TREE, cond);
3114 exprstmt = build_expr_list (NULL_TREE, cond);
4035
4036 if (base_binfo
4037 && ! TREE_VIA_VIRTUAL (base_binfo)
4038 && TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo)))
4039 {
4040 tree this_auto_delete;
4041
4042 if (BINFO_OFFSET_ZEROP (base_binfo))
4043 this_auto_delete = parent_auto_delete;
4044 else
4045 this_auto_delete = integer_zero_node;
4046
3115
3116 if (base_binfo
3117 && ! TREE_VIA_VIRTUAL (base_binfo)
3118 && TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo)))
3119 {
3120 tree this_auto_delete;
3121
3122 if (BINFO_OFFSET_ZEROP (base_binfo))
3123 this_auto_delete = parent_auto_delete;
3124 else
3125 this_auto_delete = integer_zero_node;
3126
4047 expr = build_delete (build_pointer_type (BINFO_TYPE (base_binfo)), addr,
4048 this_auto_delete, flags, 0);
4049 exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
3127 expr = build_scoped_method_call
3128 (ref, base_binfo, dtor_identifier,
3129 build_expr_list (NULL_TREE, this_auto_delete));
3130 exprstmt = expr_tree_cons (NULL_TREE, expr, exprstmt);
4050 }
4051
4052 /* Take care of the remaining baseclasses. */
4053 for (i = 1; i < n_baseclasses; i++)
4054 {
4055 base_binfo = TREE_VEC_ELT (binfos, i);
4056 if (! TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo))
4057 || TREE_VIA_VIRTUAL (base_binfo))
4058 continue;
4059
3131 }
3132
3133 /* Take care of the remaining baseclasses. */
3134 for (i = 1; i < n_baseclasses; i++)
3135 {
3136 base_binfo = TREE_VEC_ELT (binfos, i);
3137 if (! TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo))
3138 || TREE_VIA_VIRTUAL (base_binfo))
3139 continue;
3140
4060 /* May be zero offset if other baseclasses are virtual. */
4061 expr = fold (build (PLUS_EXPR, build_pointer_type (BINFO_TYPE (base_binfo)),
4062 addr, BINFO_OFFSET (base_binfo)));
3141 expr = build_scoped_method_call
3142 (ref, base_binfo, dtor_identifier,
3143 build_expr_list (NULL_TREE, integer_zero_node));
4063
3144
4064 expr = build_delete (build_pointer_type (BINFO_TYPE (base_binfo)), expr,
4065 integer_zero_node,
4066 flags, 0);
4067
4068 exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
3145 exprstmt = expr_tree_cons (NULL_TREE, expr, exprstmt);
4069 }
4070
4071 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
4072 {
4073 if (TREE_CODE (member) != FIELD_DECL)
4074 continue;
4075 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (member)))
4076 {
3146 }
3147
3148 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
3149 {
3150 if (TREE_CODE (member) != FIELD_DECL)
3151 continue;
3152 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (member)))
3153 {
4077 tree this_member = build_component_ref (ref, DECL_NAME (member), 0, 0);
3154 tree this_member = build_component_ref (ref, DECL_NAME (member), NULL_TREE, 0);
4078 tree this_type = TREE_TYPE (member);
4079 expr = build_delete (this_type, this_member, integer_two_node, flags, 0);
3155 tree this_type = TREE_TYPE (member);
3156 expr = build_delete (this_type, this_member, integer_two_node, flags, 0);
4080 exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
3157 exprstmt = expr_tree_cons (NULL_TREE, expr, exprstmt);
4081 }
4082 }
4083
4084 if (exprstmt)
4085 return build_compound_expr (exprstmt);
4086 /* Virtual base classes make this function do nothing. */
4087 return void_zero_node;
4088 }

--- 10 unchanged lines hidden (view full) ---

4099 tree addr = build_unary_op (ADDR_EXPR, decl, 0);
4100
4101 my_friendly_assert (addr != error_mark_node, 222);
4102
4103 while (vbases)
4104 {
4105 tree this_addr = convert_force (build_pointer_type (BINFO_TYPE (vbases)),
4106 addr, 0);
3158 }
3159 }
3160
3161 if (exprstmt)
3162 return build_compound_expr (exprstmt);
3163 /* Virtual base classes make this function do nothing. */
3164 return void_zero_node;
3165 }

--- 10 unchanged lines hidden (view full) ---

3176 tree addr = build_unary_op (ADDR_EXPR, decl, 0);
3177
3178 my_friendly_assert (addr != error_mark_node, 222);
3179
3180 while (vbases)
3181 {
3182 tree this_addr = convert_force (build_pointer_type (BINFO_TYPE (vbases)),
3183 addr, 0);
4107 result = tree_cons (NULL_TREE,
3184 result = expr_tree_cons (NULL_TREE,
4108 build_delete (TREE_TYPE (this_addr), this_addr,
4109 integer_zero_node,
4110 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0),
4111 result);
4112 vbases = TREE_CHAIN (vbases);
4113 }
4114 return build_compound_expr (nreverse (result));
4115}

--- 9 unchanged lines hidden (view full) ---

4125 This also calls delete for virtual baseclasses of elements of the vector.
4126
4127 Update: MAXINDEX is no longer needed. The size can be extracted from the
4128 start of the vector for pointers, and from the type for arrays. We still
4129 use MAXINDEX for arrays because it happens to already have one of the
4130 values we'd have to extract. (We could use MAXINDEX with pointers to
4131 confirm the size, and trap if the numbers differ; not clear that it'd
4132 be worth bothering.) */
3185 build_delete (TREE_TYPE (this_addr), this_addr,
3186 integer_zero_node,
3187 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0),
3188 result);
3189 vbases = TREE_CHAIN (vbases);
3190 }
3191 return build_compound_expr (nreverse (result));
3192}

--- 9 unchanged lines hidden (view full) ---

3202 This also calls delete for virtual baseclasses of elements of the vector.
3203
3204 Update: MAXINDEX is no longer needed. The size can be extracted from the
3205 start of the vector for pointers, and from the type for arrays. We still
3206 use MAXINDEX for arrays because it happens to already have one of the
3207 values we'd have to extract. (We could use MAXINDEX with pointers to
3208 confirm the size, and trap if the numbers differ; not clear that it'd
3209 be worth bothering.) */
3210
4133tree
3211tree
4134build_vec_delete (base, maxindex, elt_size, auto_delete_vec, auto_delete,
3212build_vec_delete (base, maxindex, auto_delete_vec, auto_delete,
4135 use_global_delete)
3213 use_global_delete)
4136 tree base, maxindex, elt_size;
3214 tree base, maxindex;
4137 tree auto_delete_vec, auto_delete;
4138 int use_global_delete;
4139{
4140 tree type;
4141
4142 if (TREE_CODE (base) == OFFSET_REF)
4143 base = resolve_offset_ref (base);
4144
4145 type = TREE_TYPE (base);
4146
4147 base = stabilize_reference (base);
4148
3215 tree auto_delete_vec, auto_delete;
3216 int use_global_delete;
3217{
3218 tree type;
3219
3220 if (TREE_CODE (base) == OFFSET_REF)
3221 base = resolve_offset_ref (base);
3222
3223 type = TREE_TYPE (base);
3224
3225 base = stabilize_reference (base);
3226
4149 /* Since we can use base many times, save_expr it. */
3227 /* Since we can use base many times, save_expr it. */
4150 if (TREE_SIDE_EFFECTS (base))
4151 base = save_expr (base);
4152
4153 if (TREE_CODE (type) == POINTER_TYPE)
4154 {
4155 /* Step back one from start of vector, and read dimension. */
4156 tree cookie_addr = build (MINUS_EXPR, build_pointer_type (BI_header_type),
4157 base, BI_header_size);
4158 tree cookie = build_indirect_ref (cookie_addr, NULL_PTR);
3228 if (TREE_SIDE_EFFECTS (base))
3229 base = save_expr (base);
3230
3231 if (TREE_CODE (type) == POINTER_TYPE)
3232 {
3233 /* Step back one from start of vector, and read dimension. */
3234 tree cookie_addr = build (MINUS_EXPR, build_pointer_type (BI_header_type),
3235 base, BI_header_size);
3236 tree cookie = build_indirect_ref (cookie_addr, NULL_PTR);
4159 maxindex = build_component_ref (cookie, nc_nelts_field_id, 0, 0);
3237 maxindex = build_component_ref (cookie, nc_nelts_field_id, NULL_TREE, 0);
4160 do
4161 type = TREE_TYPE (type);
4162 while (TREE_CODE (type) == ARRAY_TYPE);
4163 }
4164 else if (TREE_CODE (type) == ARRAY_TYPE)
4165 {
4166 /* get the total number of things in the array, maxindex is a bad name */
4167 maxindex = array_type_nelts_total (type);
4168 while (TREE_CODE (type) == ARRAY_TYPE)
4169 type = TREE_TYPE (type);
4170 base = build_unary_op (ADDR_EXPR, base, 1);
4171 }
4172 else
4173 {
3238 do
3239 type = TREE_TYPE (type);
3240 while (TREE_CODE (type) == ARRAY_TYPE);
3241 }
3242 else if (TREE_CODE (type) == ARRAY_TYPE)
3243 {
3244 /* get the total number of things in the array, maxindex is a bad name */
3245 maxindex = array_type_nelts_total (type);
3246 while (TREE_CODE (type) == ARRAY_TYPE)
3247 type = TREE_TYPE (type);
3248 base = build_unary_op (ADDR_EXPR, base, 1);
3249 }
3250 else
3251 {
4174 error ("type to vector delete is neither pointer or array type");
3252 if (base != error_mark_node)
3253 error ("type to vector delete is neither pointer or array type");
4175 return error_mark_node;
4176 }
4177
4178 return build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete,
4179 use_global_delete);
4180}
3254 return error_mark_node;
3255 }
3256
3257 return build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete,
3258 use_global_delete);
3259}