]>
Commit | Line | Data |
---|---|---|
8d08fdba MS |
1 | /* Handle the hair of processing (but not expanding) inline functions. |
2 | Also manage function and variable name overloading. | |
e1b7b0cb | 3 | Copyright (C) 1987, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. |
8d08fdba MS |
4 | Contributed by Michael Tiemann (tiemann@cygnus.com) |
5 | ||
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU CC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU CC; see the file COPYING. If not, write to | |
e9fa0c7c RK |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
22 | |
23 | ||
24 | #ifndef PARM_CAN_BE_ARRAY_TYPE | |
25 | #define PARM_CAN_BE_ARRAY_TYPE 1 | |
26 | #endif | |
27 | ||
28 | /* Handle method declarations. */ | |
29 | #include <stdio.h> | |
30 | #include "config.h" | |
31 | #include "tree.h" | |
32 | #include "cp-tree.h" | |
33 | #include "class.h" | |
34 | #include "obstack.h" | |
35 | #include <ctype.h> | |
8926095f MS |
36 | #include "rtl.h" |
37 | #include "expr.h" | |
38 | #include "output.h" | |
39 | #include "hard-reg-set.h" | |
40 | #include "flags.h" | |
8d08fdba MS |
41 | |
42 | /* TREE_LIST of the current inline functions that need to be | |
43 | processed. */ | |
44 | struct pending_inline *pending_inlines; | |
45 | ||
46 | #define obstack_chunk_alloc xmalloc | |
47 | #define obstack_chunk_free free | |
48 | ||
49 | /* Obstack where we build text strings for overloading, etc. */ | |
50 | static struct obstack scratch_obstack; | |
51 | static char *scratch_firstobj; | |
52 | ||
53 | # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0) | |
54 | # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C))) | |
55 | # define OB_PUTC2(C1,C2) \ | |
56 | (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2))) | |
57 | # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1)) | |
58 | # define OB_PUTID(ID) \ | |
59 | (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \ | |
60 | IDENTIFIER_LENGTH (ID))) | |
61 | # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S))) | |
62 | # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0')) | |
db5ae43f | 63 | # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1]) |
8d08fdba MS |
64 | |
65 | #ifdef NO_AUTO_OVERLOAD | |
66 | int is_overloaded (); | |
67 | #endif | |
68 | ||
69 | void | |
70 | init_method () | |
71 | { | |
72 | gcc_obstack_init (&scratch_obstack); | |
73 | scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0); | |
74 | } | |
75 | ||
76 | /* This must be large enough to hold any printed integer or floating-point | |
77 | value. */ | |
78 | static char digit_buffer[128]; | |
79 | ||
80 | /* Move inline function definitions out of structure so that they | |
81 | can be processed normally. CNAME is the name of the class | |
82 | we are working from, METHOD_LIST is the list of method lists | |
83 | of the structure. We delete friend methods here, after | |
84 | saving away their inline function definitions (if any). */ | |
85 | ||
86 | void | |
87 | do_inline_function_hair (type, friend_list) | |
88 | tree type, friend_list; | |
89 | { | |
90 | tree method = TYPE_METHODS (type); | |
91 | ||
92 | if (method && TREE_CODE (method) == TREE_VEC) | |
93 | { | |
94 | if (TREE_VEC_ELT (method, 0)) | |
95 | method = TREE_VEC_ELT (method, 0); | |
96 | else | |
97 | method = TREE_VEC_ELT (method, 1); | |
98 | } | |
99 | ||
100 | while (method) | |
101 | { | |
102 | /* Do inline member functions. */ | |
103 | struct pending_inline *info = DECL_PENDING_INLINE_INFO (method); | |
104 | if (info) | |
105 | { | |
106 | tree args; | |
107 | ||
108 | my_friendly_assert (info->fndecl == method, 238); | |
109 | args = DECL_ARGUMENTS (method); | |
110 | while (args) | |
111 | { | |
112 | DECL_CONTEXT (args) = method; | |
113 | args = TREE_CHAIN (args); | |
114 | } | |
115 | ||
7177d104 MS |
116 | /* Allow this decl to be seen in global scope. Don't do this for |
117 | local class methods, though. */ | |
118 | if (! current_function_decl) | |
119 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method)) = method; | |
8d08fdba MS |
120 | } |
121 | method = TREE_CHAIN (method); | |
122 | } | |
123 | while (friend_list) | |
124 | { | |
125 | tree fndecl = TREE_VALUE (friend_list); | |
126 | struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl); | |
127 | if (info) | |
128 | { | |
129 | tree args; | |
130 | ||
131 | my_friendly_assert (info->fndecl == fndecl, 239); | |
132 | args = DECL_ARGUMENTS (fndecl); | |
133 | while (args) | |
134 | { | |
135 | DECL_CONTEXT (args) = fndecl; | |
136 | args = TREE_CHAIN (args); | |
137 | } | |
138 | ||
139 | /* Allow this decl to be seen in global scope */ | |
700f8a87 MS |
140 | if (! current_function_decl) |
141 | IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl)) = fndecl; | |
8d08fdba MS |
142 | } |
143 | ||
144 | friend_list = TREE_CHAIN (friend_list); | |
145 | } | |
146 | } | |
147 | \f | |
148 | /* Report an argument type mismatch between the best declared function | |
149 | we could find and the current argument list that we have. */ | |
150 | void | |
151 | report_type_mismatch (cp, parmtypes, name_kind) | |
152 | struct candidate *cp; | |
153 | tree parmtypes; | |
154 | char *name_kind; | |
155 | { | |
156 | int i = cp->u.bad_arg; | |
157 | tree ttf, tta; | |
158 | char *tmp_firstobj; | |
159 | ||
160 | switch (i) | |
161 | { | |
162 | case -4: | |
163 | my_friendly_assert (TREE_CODE (cp->function) == TEMPLATE_DECL, 240); | |
164 | cp_error ("type unification failed for function template `%#D'", | |
165 | cp->function); | |
166 | return; | |
167 | ||
8d08fdba MS |
168 | case -2: |
169 | cp_error ("too few arguments for %s `%#D'", name_kind, cp->function); | |
170 | return; | |
171 | case -1: | |
172 | cp_error ("too many arguments for %s `%#D'", name_kind, cp->function); | |
173 | return; | |
174 | case 0: | |
f30432d7 MS |
175 | if (TREE_CODE (TREE_TYPE (cp->function)) != METHOD_TYPE) |
176 | break; | |
177 | case -3: | |
178 | /* Happens when the implicit object parameter is rejected. */ | |
179 | my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes))), | |
180 | 241); | |
72b7eeff MS |
181 | if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes)))) |
182 | && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp->function)))))) | |
183 | cp_error ("call to non-volatile %s `%#D' with volatile object", | |
184 | name_kind, cp->function); | |
185 | else | |
186 | cp_error ("call to non-const %s `%#D' with const object", | |
187 | name_kind, cp->function); | |
f30432d7 | 188 | return; |
8d08fdba MS |
189 | } |
190 | ||
191 | ttf = TYPE_ARG_TYPES (TREE_TYPE (cp->function)); | |
192 | tta = parmtypes; | |
193 | ||
194 | while (i-- > 0) | |
195 | { | |
196 | ttf = TREE_CHAIN (ttf); | |
197 | tta = TREE_CHAIN (tta); | |
198 | } | |
199 | ||
200 | OB_INIT (); | |
201 | OB_PUTS ("bad argument "); | |
202 | sprintf (digit_buffer, "%d", cp->u.bad_arg | |
203 | - (TREE_CODE (TREE_TYPE (cp->function)) == METHOD_TYPE) | |
204 | + 1); | |
205 | OB_PUTCP (digit_buffer); | |
206 | ||
207 | OB_PUTS (" for function `"); | |
208 | OB_PUTCP (decl_as_string (cp->function, 1)); | |
209 | OB_PUTS ("' (type was "); | |
210 | ||
211 | /* Reset `i' so that type printing routines do the right thing. */ | |
212 | if (tta) | |
213 | { | |
214 | enum tree_code code = TREE_CODE (TREE_TYPE (TREE_VALUE (tta))); | |
215 | if (code == ERROR_MARK) | |
216 | OB_PUTS ("(failed type instantiation)"); | |
217 | else | |
218 | { | |
219 | i = (code == FUNCTION_TYPE || code == METHOD_TYPE); | |
220 | OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta)), 1)); | |
221 | } | |
222 | } | |
223 | else OB_PUTS ("void"); | |
224 | OB_PUTC (')'); | |
225 | OB_FINISH (); | |
226 | ||
227 | tmp_firstobj = (char *)alloca (obstack_object_size (&scratch_obstack)); | |
228 | bcopy (obstack_base (&scratch_obstack), tmp_firstobj, | |
229 | obstack_object_size (&scratch_obstack)); | |
230 | error (tmp_firstobj); | |
231 | } | |
232 | \f | |
233 | /* Here is where overload code starts. */ | |
234 | ||
235 | /* Array of types seen so far in top-level call to `build_overload_name'. | |
236 | Allocated and deallocated by caller. */ | |
237 | static tree *typevec; | |
238 | ||
239 | /* Number of types interned by `build_overload_name' so far. */ | |
240 | static int maxtype; | |
241 | ||
242 | /* Number of occurrences of last type seen. */ | |
243 | static int nrepeats; | |
244 | ||
245 | /* Nonzero if we should not try folding parameter types. */ | |
246 | static int nofold; | |
247 | ||
248 | #define ALLOCATE_TYPEVEC(PARMTYPES) \ | |
249 | do { maxtype = 0, nrepeats = 0; \ | |
250 | typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0) | |
251 | ||
252 | #define DEALLOCATE_TYPEVEC(PARMTYPES) \ | |
253 | do { tree t = (PARMTYPES); \ | |
254 | while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \ | |
255 | } while (0) | |
256 | ||
257 | /* Code to concatenate an asciified integer to a string. */ | |
258 | static | |
259 | #ifdef __GNUC__ | |
260 | __inline | |
261 | #endif | |
262 | void | |
263 | icat (i) | |
264 | int i; | |
265 | { | |
266 | /* Handle this case first, to go really quickly. For many common values, | |
267 | the result of i/10 below is 1. */ | |
268 | if (i == 1) | |
269 | { | |
270 | OB_PUTC ('1'); | |
271 | return; | |
272 | } | |
273 | ||
274 | if (i < 0) | |
275 | { | |
276 | OB_PUTC ('m'); | |
277 | i = -i; | |
278 | } | |
279 | if (i < 10) | |
280 | OB_PUTC ('0' + i); | |
281 | else | |
282 | { | |
283 | icat (i / 10); | |
284 | OB_PUTC ('0' + (i % 10)); | |
285 | } | |
286 | } | |
287 | ||
288 | static | |
289 | #ifdef __GNUC__ | |
290 | __inline | |
291 | #endif | |
292 | void | |
293 | flush_repeats (type) | |
294 | tree type; | |
295 | { | |
296 | int tindex = 0; | |
297 | ||
298 | while (typevec[tindex] != type) | |
299 | tindex++; | |
300 | ||
301 | if (nrepeats > 1) | |
302 | { | |
303 | OB_PUTC ('N'); | |
304 | icat (nrepeats); | |
305 | if (nrepeats > 9) | |
306 | OB_PUTC ('_'); | |
307 | } | |
308 | else | |
309 | OB_PUTC ('T'); | |
310 | nrepeats = 0; | |
311 | icat (tindex); | |
312 | if (tindex > 9) | |
313 | OB_PUTC ('_'); | |
314 | } | |
315 | ||
8cb9cd5d | 316 | static int numeric_output_need_bar; |
8d08fdba MS |
317 | static void build_overload_identifier (); |
318 | ||
319 | static void | |
db5ae43f MS |
320 | build_overload_nested_name (decl) |
321 | tree decl; | |
8d08fdba | 322 | { |
db5ae43f | 323 | if (DECL_CONTEXT (decl)) |
8d08fdba | 324 | { |
db5ae43f | 325 | tree context = DECL_CONTEXT (decl); |
8d08fdba | 326 | if (TREE_CODE_CLASS (TREE_CODE (context)) == 't') |
db5ae43f | 327 | context = TYPE_MAIN_DECL (context); |
8d08fdba MS |
328 | build_overload_nested_name (context); |
329 | } | |
db5ae43f MS |
330 | |
331 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
332 | { | |
333 | tree name = DECL_ASSEMBLER_NAME (decl); | |
334 | char *label; | |
335 | extern int var_labelno; | |
336 | ||
337 | ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), var_labelno); | |
338 | var_labelno++; | |
339 | ||
8cb9cd5d | 340 | if (numeric_output_need_bar) |
db5ae43f MS |
341 | { |
342 | OB_PUTC ('_'); | |
8cb9cd5d | 343 | numeric_output_need_bar = 0; |
db5ae43f MS |
344 | } |
345 | icat (strlen (label)); | |
346 | OB_PUTCP (label); | |
347 | } | |
348 | else /* TYPE_DECL */ | |
5566b478 | 349 | build_overload_identifier (decl); |
8d08fdba MS |
350 | } |
351 | ||
e1b7b0cb RK |
352 | /* Encoding for an INTEGER_CST value. */ |
353 | static void | |
354 | build_overload_int (value) | |
355 | tree value; | |
356 | { | |
5566b478 MS |
357 | if (TREE_CODE (value) == TEMPLATE_CONST_PARM) |
358 | { | |
359 | OB_PUTC ('Y'); | |
360 | if (TEMPLATE_CONST_IDX (value) > 9) | |
361 | OB_PUTC ('_'); | |
362 | icat (TEMPLATE_CONST_IDX (value)); | |
363 | if (TEMPLATE_CONST_IDX (value) > 9) | |
364 | OB_PUTC ('_'); | |
365 | return; | |
366 | } | |
ec255269 MS |
367 | else if (current_template_parms |
368 | && TREE_CODE (value) != INTEGER_CST) | |
5566b478 MS |
369 | /* We don't ever want this output, but it's inconvenient not to |
370 | be able to build the string. This should cause assembler | |
371 | errors we'll notice. */ | |
372 | { | |
373 | static int n; | |
374 | sprintf (digit_buffer, " *%d", n++); | |
375 | OB_PUTCP (digit_buffer); | |
376 | return; | |
377 | } | |
378 | ||
e1b7b0cb RK |
379 | my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243); |
380 | if (TYPE_PRECISION (value) == 2 * HOST_BITS_PER_WIDE_INT) | |
381 | { | |
382 | if (tree_int_cst_lt (value, integer_zero_node)) | |
383 | { | |
384 | OB_PUTC ('m'); | |
385 | value = build_int_2 (~ TREE_INT_CST_LOW (value), | |
386 | - TREE_INT_CST_HIGH (value)); | |
387 | } | |
388 | if (TREE_INT_CST_HIGH (value) | |
389 | != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1))) | |
390 | { | |
391 | /* need to print a DImode value in decimal */ | |
392 | sorry ("conversion of long long as PT parameter"); | |
393 | } | |
394 | /* else fall through to print in smaller mode */ | |
395 | } | |
396 | /* Wordsize or smaller */ | |
397 | icat (TREE_INT_CST_LOW (value)); | |
398 | } | |
399 | ||
8d08fdba MS |
400 | static void |
401 | build_overload_value (type, value) | |
402 | tree type, value; | |
403 | { | |
404 | while (TREE_CODE (value) == NON_LVALUE_EXPR | |
405 | || TREE_CODE (value) == NOP_EXPR) | |
406 | value = TREE_OPERAND (value, 0); | |
407 | my_friendly_assert (TREE_CODE (type) == PARM_DECL, 242); | |
408 | type = TREE_TYPE (type); | |
e1b7b0cb RK |
409 | |
410 | if (numeric_output_need_bar) | |
411 | { | |
412 | OB_PUTC ('_'); | |
413 | numeric_output_need_bar = 0; | |
414 | } | |
415 | ||
8145f082 MS |
416 | if (TREE_CODE (type) == POINTER_TYPE |
417 | && TREE_CODE (TREE_TYPE (type)) == OFFSET_TYPE) | |
418 | { | |
e1b7b0cb | 419 | /* Handle a pointer to data member as a template instantiation |
8145f082 MS |
420 | parameter, boy, what fun! */ |
421 | type = integer_type_node; | |
422 | if (TREE_CODE (value) != INTEGER_CST) | |
423 | { | |
424 | sorry ("unknown pointer to member constant"); | |
425 | return; | |
426 | } | |
427 | } | |
428 | ||
e1b7b0cb RK |
429 | if (TYPE_PTRMEMFUNC_P (type)) |
430 | type = TYPE_PTRMEMFUNC_FN_TYPE (type); | |
431 | ||
8d08fdba MS |
432 | switch (TREE_CODE (type)) |
433 | { | |
434 | case INTEGER_TYPE: | |
435 | case ENUMERAL_TYPE: | |
2986ae00 MS |
436 | case BOOLEAN_TYPE: |
437 | { | |
e1b7b0cb RK |
438 | build_overload_int (value); |
439 | numeric_output_need_bar = 1; | |
2986ae00 MS |
440 | return; |
441 | } | |
8d08fdba MS |
442 | #ifndef REAL_IS_NOT_DOUBLE |
443 | case REAL_TYPE: | |
444 | { | |
445 | REAL_VALUE_TYPE val; | |
446 | char *bufp = digit_buffer; | |
447 | extern char *index (); | |
448 | ||
449 | my_friendly_assert (TREE_CODE (value) == REAL_CST, 244); | |
450 | val = TREE_REAL_CST (value); | |
451 | if (val < 0) | |
452 | { | |
453 | val = -val; | |
454 | *bufp++ = 'm'; | |
455 | } | |
456 | sprintf (bufp, "%e", val); | |
457 | bufp = (char *) index (bufp, 'e'); | |
458 | if (!bufp) | |
459 | strcat (digit_buffer, "e0"); | |
460 | else | |
461 | { | |
462 | char *p; | |
463 | bufp++; | |
464 | if (*bufp == '-') | |
465 | { | |
466 | *bufp++ = 'm'; | |
467 | } | |
468 | p = bufp; | |
469 | if (*p == '+') | |
470 | p++; | |
471 | while (*p == '0') | |
472 | p++; | |
473 | if (*p == 0) | |
474 | { | |
475 | *bufp++ = '0'; | |
476 | *bufp = 0; | |
477 | } | |
478 | else if (p != bufp) | |
479 | { | |
480 | while (*p) | |
481 | *bufp++ = *p++; | |
482 | *bufp = 0; | |
483 | } | |
484 | } | |
485 | OB_PUTCP (digit_buffer); | |
e1b7b0cb | 486 | numeric_output_need_bar = 1; |
8d08fdba MS |
487 | return; |
488 | } | |
489 | #endif | |
490 | case POINTER_TYPE: | |
e1b7b0cb RK |
491 | if (TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE |
492 | && TREE_CODE (value) != ADDR_EXPR) | |
493 | { | |
494 | if (TREE_CODE (value) == CONSTRUCTOR) | |
495 | { | |
496 | /* This is dangerous code, crack built up pointer to members. */ | |
497 | tree args = CONSTRUCTOR_ELTS (value); | |
498 | tree a1 = TREE_VALUE (args); | |
499 | tree a2 = TREE_VALUE (TREE_CHAIN (args)); | |
500 | tree a3 = CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)))); | |
501 | a3 = TREE_VALUE (a3); | |
502 | STRIP_NOPS (a3); | |
503 | if (TREE_CODE (a1) == INTEGER_CST | |
504 | && TREE_CODE (a2) == INTEGER_CST) | |
505 | { | |
506 | build_overload_int (a1); | |
507 | OB_PUTC ('_'); | |
508 | build_overload_int (a2); | |
509 | OB_PUTC ('_'); | |
510 | if (TREE_CODE (a3) == ADDR_EXPR) | |
511 | { | |
512 | a3 = TREE_OPERAND (a3, 0); | |
513 | if (TREE_CODE (a3) == FUNCTION_DECL) | |
514 | { | |
515 | numeric_output_need_bar = 0; | |
516 | build_overload_identifier (DECL_ASSEMBLER_NAME (a3)); | |
517 | return; | |
518 | } | |
519 | } | |
520 | else if (TREE_CODE (a3) == INTEGER_CST) | |
521 | { | |
522 | OB_PUTC ('i'); | |
523 | build_overload_int (a3); | |
524 | numeric_output_need_bar = 1; | |
525 | return; | |
526 | } | |
527 | } | |
528 | } | |
529 | sorry ("template instantiation with pointer to method that is too complex"); | |
530 | return; | |
531 | } | |
f30432d7 MS |
532 | if (TREE_CODE (value) == INTEGER_CST) |
533 | { | |
534 | build_overload_int (value); | |
535 | numeric_output_need_bar = 1; | |
536 | return; | |
537 | } | |
8d08fdba MS |
538 | value = TREE_OPERAND (value, 0); |
539 | if (TREE_CODE (value) == VAR_DECL) | |
540 | { | |
541 | my_friendly_assert (DECL_NAME (value) != 0, 245); | |
e76a2646 | 542 | build_overload_identifier (DECL_ASSEMBLER_NAME (value)); |
8d08fdba MS |
543 | return; |
544 | } | |
545 | else if (TREE_CODE (value) == FUNCTION_DECL) | |
546 | { | |
547 | my_friendly_assert (DECL_NAME (value) != 0, 246); | |
e76a2646 | 548 | build_overload_identifier (DECL_ASSEMBLER_NAME (value)); |
8d08fdba MS |
549 | return; |
550 | } | |
551 | else | |
552 | my_friendly_abort (71); | |
553 | break; /* not really needed */ | |
554 | ||
555 | default: | |
556 | sorry ("conversion of %s as template parameter", | |
557 | tree_code_name [(int) TREE_CODE (type)]); | |
558 | my_friendly_abort (72); | |
559 | } | |
560 | } | |
561 | ||
562 | static void | |
563 | build_overload_identifier (name) | |
564 | tree name; | |
565 | { | |
5566b478 MS |
566 | if (TREE_CODE (name) == TYPE_DECL |
567 | && IS_AGGR_TYPE (TREE_TYPE (name)) | |
568 | && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name)) | |
569 | && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name)))) | |
8d08fdba MS |
570 | { |
571 | tree template, parmlist, arglist, tname; | |
572 | int i, nparms; | |
5566b478 | 573 | template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name)); |
8d08fdba MS |
574 | arglist = TREE_VALUE (template); |
575 | template = TREE_PURPOSE (template); | |
576 | tname = DECL_NAME (template); | |
577 | parmlist = DECL_ARGUMENTS (template); | |
578 | nparms = TREE_VEC_LENGTH (parmlist); | |
579 | OB_PUTC ('t'); | |
580 | icat (IDENTIFIER_LENGTH (tname)); | |
581 | OB_PUTID (tname); | |
582 | icat (nparms); | |
583 | for (i = 0; i < nparms; i++) | |
584 | { | |
a292b002 | 585 | tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i)); |
8d08fdba | 586 | tree arg = TREE_VEC_ELT (arglist, i); |
a292b002 | 587 | if (TREE_CODE (parm) == TYPE_DECL) |
8d08fdba MS |
588 | { |
589 | /* This parameter is a type. */ | |
590 | OB_PUTC ('Z'); | |
591 | build_overload_name (arg, 0, 0); | |
592 | } | |
593 | else | |
594 | { | |
e1b7b0cb RK |
595 | parm = tsubst (parm, &TREE_VEC_ELT (arglist, 0), |
596 | TREE_VEC_LENGTH (arglist), NULL_TREE); | |
8d08fdba MS |
597 | /* It's a PARM_DECL. */ |
598 | build_overload_name (TREE_TYPE (parm), 0, 0); | |
599 | build_overload_value (parm, arg); | |
600 | } | |
601 | } | |
602 | } | |
603 | else | |
604 | { | |
5566b478 MS |
605 | if (TREE_CODE (name) == TYPE_DECL) |
606 | name = DECL_NAME (name); | |
8cb9cd5d | 607 | if (numeric_output_need_bar) |
f376e137 MS |
608 | { |
609 | OB_PUTC ('_'); | |
8cb9cd5d | 610 | numeric_output_need_bar = 0; |
f376e137 | 611 | } |
8d08fdba MS |
612 | icat (IDENTIFIER_LENGTH (name)); |
613 | OB_PUTID (name); | |
614 | } | |
615 | } | |
616 | ||
617 | /* Given a list of parameters in PARMTYPES, create an unambiguous | |
618 | overload string. Should distinguish any type that C (or C++) can | |
619 | distinguish. I.e., pointers to functions are treated correctly. | |
620 | ||
621 | Caller must deal with whether a final `e' goes on the end or not. | |
622 | ||
623 | Any default conversions must take place before this function | |
624 | is called. | |
625 | ||
626 | BEGIN and END control initialization and finalization of the | |
627 | obstack where we build the string. */ | |
628 | ||
629 | char * | |
630 | build_overload_name (parmtypes, begin, end) | |
631 | tree parmtypes; | |
632 | int begin, end; | |
633 | { | |
634 | int just_one; | |
635 | tree parmtype; | |
636 | ||
637 | if (begin) OB_INIT (); | |
8cb9cd5d | 638 | numeric_output_need_bar = 0; |
8d08fdba | 639 | |
8926095f | 640 | if ((just_one = (TREE_CODE (parmtypes) != TREE_LIST))) |
8d08fdba MS |
641 | { |
642 | parmtype = parmtypes; | |
643 | goto only_one; | |
644 | } | |
645 | ||
646 | while (parmtypes) | |
647 | { | |
648 | parmtype = TREE_VALUE (parmtypes); | |
649 | ||
650 | only_one: | |
651 | ||
a5894242 | 652 | if (! nofold && ! just_one) |
8d08fdba | 653 | { |
a5894242 MS |
654 | /* Every argument gets counted. */ |
655 | typevec[maxtype++] = parmtype; | |
8d08fdba | 656 | |
a5894242 | 657 | if (TREE_USED (parmtype) && parmtype == typevec[maxtype-2]) |
8d08fdba | 658 | { |
a5894242 | 659 | nrepeats++; |
8d08fdba MS |
660 | goto next; |
661 | } | |
a5894242 | 662 | |
8d08fdba MS |
663 | if (nrepeats) |
664 | flush_repeats (typevec[maxtype-2]); | |
a5894242 MS |
665 | |
666 | if (TREE_USED (parmtype)) | |
667 | { | |
668 | flush_repeats (parmtype); | |
669 | goto next; | |
670 | } | |
671 | ||
672 | /* Only cache types which take more than one character. */ | |
673 | if (parmtype != TYPE_MAIN_VARIANT (parmtype) | |
674 | || (TREE_CODE (parmtype) != INTEGER_TYPE | |
675 | && TREE_CODE (parmtype) != REAL_TYPE)) | |
8d08fdba MS |
676 | TREE_USED (parmtype) = 1; |
677 | } | |
678 | ||
679 | if (TYPE_PTRMEMFUNC_P (parmtype)) | |
680 | parmtype = TYPE_PTRMEMFUNC_FN_TYPE (parmtype); | |
681 | ||
682 | if (TREE_READONLY (parmtype)) | |
683 | OB_PUTC ('C'); | |
684 | if (TREE_CODE (parmtype) == INTEGER_TYPE | |
685 | && TYPE_MAIN_VARIANT (parmtype) == unsigned_type (TYPE_MAIN_VARIANT (parmtype))) | |
686 | OB_PUTC ('U'); | |
687 | if (TYPE_VOLATILE (parmtype)) | |
688 | OB_PUTC ('V'); | |
689 | ||
690 | switch (TREE_CODE (parmtype)) | |
691 | { | |
692 | case OFFSET_TYPE: | |
693 | OB_PUTC ('O'); | |
694 | build_overload_name (TYPE_OFFSET_BASETYPE (parmtype), 0, 0); | |
695 | OB_PUTC ('_'); | |
696 | build_overload_name (TREE_TYPE (parmtype), 0, 0); | |
697 | break; | |
698 | ||
699 | case REFERENCE_TYPE: | |
700 | OB_PUTC ('R'); | |
701 | goto more; | |
702 | ||
703 | case ARRAY_TYPE: | |
704 | #if PARM_CAN_BE_ARRAY_TYPE | |
705 | { | |
706 | tree length; | |
707 | ||
708 | OB_PUTC ('A'); | |
709 | if (TYPE_DOMAIN (parmtype) == NULL_TREE) | |
2986ae00 | 710 | error ("pointer or reference to array of unknown bound in parm type"); |
8d08fdba MS |
711 | else |
712 | { | |
713 | length = array_type_nelts (parmtype); | |
714 | if (TREE_CODE (length) == INTEGER_CST) | |
715 | icat (TREE_INT_CST_LOW (length) + 1); | |
716 | } | |
717 | OB_PUTC ('_'); | |
718 | goto more; | |
719 | } | |
720 | #else | |
721 | OB_PUTC ('P'); | |
722 | goto more; | |
723 | #endif | |
724 | ||
725 | case POINTER_TYPE: | |
726 | OB_PUTC ('P'); | |
727 | more: | |
728 | build_overload_name (TREE_TYPE (parmtype), 0, 0); | |
729 | break; | |
730 | ||
731 | case FUNCTION_TYPE: | |
732 | case METHOD_TYPE: | |
733 | { | |
734 | tree firstarg = TYPE_ARG_TYPES (parmtype); | |
735 | /* Otherwise have to implement reentrant typevecs, | |
736 | unmark and remark types, etc. */ | |
737 | int old_nofold = nofold; | |
738 | nofold = 1; | |
739 | ||
740 | if (nrepeats) | |
741 | flush_repeats (typevec[maxtype-1]); | |
742 | ||
743 | /* @@ It may be possible to pass a function type in | |
744 | which is not preceded by a 'P'. */ | |
745 | if (TREE_CODE (parmtype) == FUNCTION_TYPE) | |
746 | { | |
747 | OB_PUTC ('F'); | |
748 | if (firstarg == NULL_TREE) | |
749 | OB_PUTC ('e'); | |
750 | else if (firstarg == void_list_node) | |
751 | OB_PUTC ('v'); | |
752 | else | |
753 | build_overload_name (firstarg, 0, 0); | |
754 | } | |
755 | else | |
756 | { | |
757 | int constp = TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg))); | |
758 | int volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg))); | |
759 | OB_PUTC ('M'); | |
760 | firstarg = TREE_CHAIN (firstarg); | |
761 | ||
762 | build_overload_name (TYPE_METHOD_BASETYPE (parmtype), 0, 0); | |
763 | if (constp) | |
764 | OB_PUTC ('C'); | |
765 | if (volatilep) | |
766 | OB_PUTC ('V'); | |
767 | ||
768 | /* For cfront 2.0 compatibility. */ | |
769 | OB_PUTC ('F'); | |
770 | ||
771 | if (firstarg == NULL_TREE) | |
772 | OB_PUTC ('e'); | |
773 | else if (firstarg == void_list_node) | |
774 | OB_PUTC ('v'); | |
775 | else | |
776 | build_overload_name (firstarg, 0, 0); | |
777 | } | |
778 | ||
779 | /* Separate args from return type. */ | |
780 | OB_PUTC ('_'); | |
781 | build_overload_name (TREE_TYPE (parmtype), 0, 0); | |
782 | nofold = old_nofold; | |
783 | break; | |
784 | } | |
785 | ||
786 | case INTEGER_TYPE: | |
787 | parmtype = TYPE_MAIN_VARIANT (parmtype); | |
788 | if (parmtype == integer_type_node | |
789 | || parmtype == unsigned_type_node) | |
790 | OB_PUTC ('i'); | |
791 | else if (parmtype == long_integer_type_node | |
792 | || parmtype == long_unsigned_type_node) | |
793 | OB_PUTC ('l'); | |
794 | else if (parmtype == short_integer_type_node | |
795 | || parmtype == short_unsigned_type_node) | |
796 | OB_PUTC ('s'); | |
797 | else if (parmtype == signed_char_type_node) | |
798 | { | |
799 | OB_PUTC ('S'); | |
800 | OB_PUTC ('c'); | |
801 | } | |
802 | else if (parmtype == char_type_node | |
803 | || parmtype == unsigned_char_type_node) | |
804 | OB_PUTC ('c'); | |
805 | else if (parmtype == wchar_type_node) | |
806 | OB_PUTC ('w'); | |
807 | else if (parmtype == long_long_integer_type_node | |
808 | || parmtype == long_long_unsigned_type_node) | |
809 | OB_PUTC ('x'); | |
810 | #if 0 | |
811 | /* it would seem there is no way to enter these in source code, | |
812 | yet. (mrs) */ | |
813 | else if (parmtype == long_long_long_integer_type_node | |
814 | || parmtype == long_long_long_unsigned_type_node) | |
815 | OB_PUTC ('q'); | |
816 | #endif | |
817 | else | |
818 | my_friendly_abort (73); | |
819 | break; | |
820 | ||
2986ae00 MS |
821 | case BOOLEAN_TYPE: |
822 | OB_PUTC ('b'); | |
823 | break; | |
824 | ||
8d08fdba MS |
825 | case REAL_TYPE: |
826 | parmtype = TYPE_MAIN_VARIANT (parmtype); | |
827 | if (parmtype == long_double_type_node) | |
828 | OB_PUTC ('r'); | |
829 | else if (parmtype == double_type_node) | |
830 | OB_PUTC ('d'); | |
831 | else if (parmtype == float_type_node) | |
832 | OB_PUTC ('f'); | |
833 | else my_friendly_abort (74); | |
834 | break; | |
835 | ||
836 | case VOID_TYPE: | |
837 | if (! just_one) | |
838 | { | |
839 | #if 0 | |
840 | extern tree void_list_node; | |
841 | ||
842 | /* See if anybody is wasting memory. */ | |
843 | my_friendly_assert (parmtypes == void_list_node, 247); | |
844 | #endif | |
845 | /* This is the end of a parameter list. */ | |
846 | if (end) OB_FINISH (); | |
847 | return (char *)obstack_base (&scratch_obstack); | |
848 | } | |
849 | OB_PUTC ('v'); | |
850 | break; | |
851 | ||
852 | case ERROR_MARK: /* not right, but nothing is anyway */ | |
853 | break; | |
854 | ||
855 | /* have to do these */ | |
856 | case UNION_TYPE: | |
857 | case RECORD_TYPE: | |
858 | if (! just_one) | |
859 | /* Make this type signature look incompatible | |
860 | with AT&T. */ | |
861 | OB_PUTC ('G'); | |
862 | goto common; | |
863 | case ENUMERAL_TYPE: | |
864 | common: | |
865 | { | |
866 | tree name = TYPE_NAME (parmtype); | |
867 | int i = 1; | |
868 | ||
869 | if (TREE_CODE (name) == TYPE_DECL) | |
870 | { | |
871 | tree context = name; | |
db5ae43f MS |
872 | |
873 | /* If DECL_ASSEMBLER_NAME has been set properly, use it. */ | |
874 | if (DECL_ASSEMBLER_NAME (context) != DECL_NAME (context)) | |
875 | { | |
876 | OB_PUTID (DECL_ASSEMBLER_NAME (context)); | |
877 | break; | |
878 | } | |
8d08fdba MS |
879 | while (DECL_CONTEXT (context)) |
880 | { | |
881 | i += 1; | |
882 | context = DECL_CONTEXT (context); | |
883 | if (TREE_CODE_CLASS (TREE_CODE (context)) == 't') | |
884 | context = TYPE_NAME (context); | |
885 | } | |
886 | name = DECL_NAME (name); | |
887 | } | |
888 | my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 248); | |
889 | if (i > 1) | |
890 | { | |
891 | OB_PUTC ('Q'); | |
892 | if (i > 9) | |
893 | OB_PUTC ('_'); | |
894 | icat (i); | |
895 | if (i > 9) | |
896 | OB_PUTC ('_'); | |
8cb9cd5d | 897 | numeric_output_need_bar = 0; |
db5ae43f | 898 | build_overload_nested_name (TYPE_MAIN_DECL (parmtype)); |
8d08fdba | 899 | } |
5566b478 MS |
900 | else |
901 | build_overload_identifier (TYPE_MAIN_DECL (parmtype)); | |
8d08fdba MS |
902 | break; |
903 | } | |
904 | ||
905 | case UNKNOWN_TYPE: | |
906 | /* This will take some work. */ | |
907 | OB_PUTC ('?'); | |
908 | break; | |
909 | ||
910 | case TEMPLATE_TYPE_PARM: | |
5566b478 MS |
911 | OB_PUTC ('X'); |
912 | if (TEMPLATE_TYPE_IDX (parmtype) > 9) | |
913 | OB_PUTC ('_'); | |
914 | icat (TEMPLATE_TYPE_IDX (parmtype)); | |
915 | if (TEMPLATE_TYPE_IDX (parmtype) > 9) | |
916 | OB_PUTC ('_'); | |
917 | break; | |
918 | ||
919 | case TYPENAME_TYPE: | |
8d08fdba MS |
920 | /* We don't ever want this output, but it's inconvenient not to |
921 | be able to build the string. This should cause assembler | |
922 | errors we'll notice. */ | |
923 | { | |
924 | static int n; | |
925 | sprintf (digit_buffer, " *%d", n++); | |
926 | OB_PUTCP (digit_buffer); | |
927 | } | |
928 | break; | |
929 | ||
930 | default: | |
931 | my_friendly_abort (75); | |
932 | } | |
933 | ||
934 | next: | |
935 | if (just_one) break; | |
936 | parmtypes = TREE_CHAIN (parmtypes); | |
937 | } | |
938 | if (! just_one) | |
939 | { | |
940 | if (nrepeats) | |
941 | flush_repeats (typevec[maxtype-1]); | |
942 | ||
943 | /* To get here, parms must end with `...'. */ | |
944 | OB_PUTC ('e'); | |
945 | } | |
946 | ||
947 | if (end) OB_FINISH (); | |
948 | return (char *)obstack_base (&scratch_obstack); | |
949 | } | |
f376e137 MS |
950 | |
951 | tree | |
952 | build_static_name (basetype, name) | |
953 | tree basetype, name; | |
954 | { | |
955 | char *basename = build_overload_name (basetype, 1, 1); | |
956 | char *buf = (char *) alloca (IDENTIFIER_LENGTH (name) | |
957 | + sizeof (STATIC_NAME_FORMAT) | |
958 | + strlen (basename)); | |
959 | sprintf (buf, STATIC_NAME_FORMAT, basename, IDENTIFIER_POINTER (name)); | |
960 | return get_identifier (buf); | |
961 | } | |
8d08fdba | 962 | \f |
8d08fdba MS |
963 | /* Change the name of a function definition so that it may be |
964 | overloaded. NAME is the name of the function to overload, | |
965 | PARMS is the parameter list (which determines what name the | |
966 | final function obtains). | |
967 | ||
968 | FOR_METHOD is 1 if this overload is being performed | |
969 | for a method, rather than a function type. It is 2 if | |
970 | this overload is being performed for a constructor. */ | |
971 | tree | |
972 | build_decl_overload (dname, parms, for_method) | |
973 | tree dname; | |
974 | tree parms; | |
975 | int for_method; | |
976 | { | |
977 | char *name = IDENTIFIER_POINTER (dname); | |
978 | ||
a28e3c7f MS |
979 | /* member operators new and delete look like methods at this point. */ |
980 | if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST) | |
981 | { | |
00595019 MS |
982 | if (dname == ansi_opname[(int) DELETE_EXPR]) |
983 | return get_identifier ("__builtin_delete"); | |
984 | else if (dname == ansi_opname[(int) VEC_DELETE_EXPR]) | |
985 | return get_identifier ("__builtin_vec_delete"); | |
986 | else if (TREE_CHAIN (parms) == void_list_node) | |
a28e3c7f MS |
987 | { |
988 | if (dname == ansi_opname[(int) NEW_EXPR]) | |
989 | return get_identifier ("__builtin_new"); | |
990 | else if (dname == ansi_opname[(int) VEC_NEW_EXPR]) | |
991 | return get_identifier ("__builtin_vec_new"); | |
992 | } | |
a28e3c7f | 993 | } |
8d08fdba MS |
994 | |
995 | OB_INIT (); | |
996 | if (for_method != 2) | |
997 | OB_PUTCP (name); | |
998 | /* Otherwise, we can divine that this is a constructor, | |
999 | and figure out its name without any extra encoding. */ | |
1000 | ||
1001 | OB_PUTC2 ('_', '_'); | |
1002 | if (for_method) | |
1003 | { | |
1004 | #if 0 | |
1005 | /* We can get away without doing this. */ | |
1006 | OB_PUTC ('M'); | |
1007 | #endif | |
1008 | { | |
1009 | tree this_type = TREE_VALUE (parms); | |
1010 | ||
1011 | if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */ | |
1012 | parms = temp_tree_cons (NULL_TREE, SIGNATURE_TYPE (this_type), | |
1013 | TREE_CHAIN (parms)); | |
1014 | else | |
1015 | parms = temp_tree_cons (NULL_TREE, TREE_TYPE (this_type), | |
1016 | TREE_CHAIN (parms)); | |
1017 | } | |
1018 | } | |
1019 | else | |
1020 | OB_PUTC ('F'); | |
1021 | ||
1022 | if (parms == NULL_TREE) | |
1023 | OB_PUTC2 ('e', '\0'); | |
1024 | else if (parms == void_list_node) | |
1025 | OB_PUTC2 ('v', '\0'); | |
1026 | else | |
1027 | { | |
1028 | ALLOCATE_TYPEVEC (parms); | |
1029 | nofold = 0; | |
1030 | if (for_method) | |
1031 | { | |
1032 | build_overload_name (TREE_VALUE (parms), 0, 0); | |
1033 | ||
1034 | typevec[maxtype++] = TREE_VALUE (parms); | |
1035 | TREE_USED (TREE_VALUE (parms)) = 1; | |
1036 | ||
1037 | if (TREE_CHAIN (parms)) | |
1038 | build_overload_name (TREE_CHAIN (parms), 0, 1); | |
1039 | else | |
1040 | OB_PUTC2 ('e', '\0'); | |
1041 | } | |
1042 | else | |
1043 | build_overload_name (parms, 0, 1); | |
1044 | DEALLOCATE_TYPEVEC (parms); | |
1045 | } | |
1046 | { | |
1047 | tree n = get_identifier (obstack_base (&scratch_obstack)); | |
1048 | if (IDENTIFIER_OPNAME_P (dname)) | |
1049 | IDENTIFIER_OPNAME_P (n) = 1; | |
1050 | return n; | |
1051 | } | |
1052 | } | |
1053 | ||
1054 | /* Build an overload name for the type expression TYPE. */ | |
1055 | tree | |
1056 | build_typename_overload (type) | |
1057 | tree type; | |
1058 | { | |
1059 | tree id; | |
1060 | ||
1061 | OB_INIT (); | |
1062 | OB_PUTID (ansi_opname[(int) TYPE_EXPR]); | |
1063 | nofold = 1; | |
1064 | build_overload_name (type, 0, 1); | |
1065 | id = get_identifier (obstack_base (&scratch_obstack)); | |
1066 | IDENTIFIER_OPNAME_P (id) = 1; | |
a0a33927 | 1067 | #if 0 |
51c184be | 1068 | IDENTIFIER_GLOBAL_VALUE (id) = TYPE_NAME (type); |
a0a33927 | 1069 | #endif |
51c184be | 1070 | TREE_TYPE (id) = type; |
8d08fdba MS |
1071 | return id; |
1072 | } | |
1073 | ||
1074 | #ifndef NO_DOLLAR_IN_LABEL | |
1075 | #define T_DESC_FORMAT "TD$" | |
1076 | #define I_DESC_FORMAT "ID$" | |
1077 | #define M_DESC_FORMAT "MD$" | |
1078 | #else | |
1079 | #if !defined(NO_DOT_IN_LABEL) | |
1080 | #define T_DESC_FORMAT "TD." | |
1081 | #define I_DESC_FORMAT "ID." | |
1082 | #define M_DESC_FORMAT "MD." | |
1083 | #else | |
1084 | #define T_DESC_FORMAT "__t_desc_" | |
1085 | #define I_DESC_FORMAT "__i_desc_" | |
1086 | #define M_DESC_FORMAT "__m_desc_" | |
1087 | #endif | |
1088 | #endif | |
1089 | ||
1090 | /* Build an overload name for the type expression TYPE. */ | |
1091 | tree | |
1092 | build_t_desc_overload (type) | |
1093 | tree type; | |
1094 | { | |
1095 | OB_INIT (); | |
1096 | OB_PUTS (T_DESC_FORMAT); | |
1097 | nofold = 1; | |
1098 | ||
1099 | #if 0 | |
1100 | /* Use a different format if the type isn't defined yet. */ | |
1101 | if (TYPE_SIZE (type) == NULL_TREE) | |
1102 | { | |
1103 | char *p; | |
1104 | int changed; | |
1105 | ||
1106 | for (p = tname; *p; p++) | |
1107 | if (isupper (*p)) | |
1108 | { | |
1109 | changed = 1; | |
1110 | *p = tolower (*p); | |
1111 | } | |
1112 | /* If there's no change, we have an inappropriate T_DESC_FORMAT. */ | |
1113 | my_friendly_assert (changed != 0, 249); | |
1114 | } | |
1115 | #endif | |
1116 | ||
1117 | build_overload_name (type, 0, 1); | |
1118 | return get_identifier (obstack_base (&scratch_obstack)); | |
1119 | } | |
1120 | ||
1121 | /* Top-level interface to explicit overload requests. Allow NAME | |
1122 | to be overloaded. Error if NAME is already declared for the current | |
1123 | scope. Warning if function is redundantly overloaded. */ | |
1124 | ||
1125 | void | |
1126 | declare_overloaded (name) | |
1127 | tree name; | |
1128 | { | |
1129 | #ifdef NO_AUTO_OVERLOAD | |
1130 | if (is_overloaded (name)) | |
1131 | warning ("function `%s' already declared overloaded", | |
1132 | IDENTIFIER_POINTER (name)); | |
1133 | else if (IDENTIFIER_GLOBAL_VALUE (name)) | |
1134 | error ("overloading function `%s' that is already defined", | |
1135 | IDENTIFIER_POINTER (name)); | |
1136 | else | |
1137 | { | |
1138 | TREE_OVERLOADED (name) = 1; | |
1139 | IDENTIFIER_GLOBAL_VALUE (name) = build_tree_list (name, NULL_TREE); | |
1140 | TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)) = unknown_type_node; | |
1141 | } | |
1142 | #else | |
1143 | if (current_lang_name == lang_name_cplusplus) | |
1144 | { | |
1145 | if (0) | |
1146 | warning ("functions are implicitly overloaded in C++"); | |
1147 | } | |
1148 | else if (current_lang_name == lang_name_c) | |
1149 | error ("overloading function `%s' cannot be done in C language context"); | |
1150 | else | |
1151 | my_friendly_abort (76); | |
1152 | #endif | |
1153 | } | |
1154 | ||
1155 | #ifdef NO_AUTO_OVERLOAD | |
1156 | /* Check to see if NAME is overloaded. For first approximation, | |
1157 | check to see if its TREE_OVERLOADED is set. This is used on | |
1158 | IDENTIFIER nodes. */ | |
1159 | int | |
1160 | is_overloaded (name) | |
1161 | tree name; | |
1162 | { | |
1163 | /* @@ */ | |
1164 | return (TREE_OVERLOADED (name) | |
1165 | && (! IDENTIFIER_CLASS_VALUE (name) || current_class_type == 0) | |
1166 | && ! IDENTIFIER_LOCAL_VALUE (name)); | |
1167 | } | |
1168 | #endif | |
1169 | \f | |
1170 | /* Given a tree_code CODE, and some arguments (at least one), | |
1171 | attempt to use an overloaded operator on the arguments. | |
1172 | ||
1173 | For unary operators, only the first argument need be checked. | |
1174 | For binary operators, both arguments may need to be checked. | |
1175 | ||
1176 | Member functions can convert class references to class pointers, | |
1177 | for one-level deep indirection. More than that is not supported. | |
1178 | Operators [](), ()(), and ->() must be member functions. | |
1179 | ||
1180 | We call function call building calls with LOOKUP_COMPLAIN if they | |
1181 | are our only hope. This is true when we see a vanilla operator | |
1182 | applied to something of aggregate type. If this fails, we are free | |
1183 | to return `error_mark_node', because we will have reported the | |
1184 | error. | |
1185 | ||
1186 | Operators NEW and DELETE overload in funny ways: operator new takes | |
1187 | a single `size' parameter, and operator delete takes a pointer to the | |
1188 | storage being deleted. When overloading these operators, success is | |
1189 | assumed. If there is a failure, report an error message and return | |
1190 | `error_mark_node'. */ | |
1191 | ||
1192 | /* NOSTRICT */ | |
1193 | tree | |
1194 | build_opfncall (code, flags, xarg1, xarg2, arg3) | |
1195 | enum tree_code code; | |
1196 | int flags; | |
1197 | tree xarg1, xarg2, arg3; | |
1198 | { | |
1199 | tree rval = 0; | |
1200 | tree arg1, arg2; | |
1201 | tree type1, type2, fnname; | |
1202 | tree fields1 = 0, parms = 0; | |
1203 | tree global_fn; | |
1204 | int try_second; | |
1205 | int binary_is_unary; | |
1206 | ||
1207 | if (xarg1 == error_mark_node) | |
1208 | return error_mark_node; | |
1209 | ||
1210 | if (code == COND_EXPR) | |
1211 | { | |
1212 | if (TREE_CODE (xarg2) == ERROR_MARK | |
1213 | || TREE_CODE (arg3) == ERROR_MARK) | |
1214 | return error_mark_node; | |
1215 | } | |
1216 | if (code == COMPONENT_REF) | |
1217 | if (TREE_CODE (TREE_TYPE (xarg1)) == POINTER_TYPE) | |
1218 | return rval; | |
1219 | ||
1220 | /* First, see if we can work with the first argument */ | |
1221 | type1 = TREE_TYPE (xarg1); | |
1222 | ||
1223 | /* Some tree codes have length > 1, but we really only want to | |
1224 | overload them if their first argument has a user defined type. */ | |
1225 | switch (code) | |
1226 | { | |
1227 | case PREINCREMENT_EXPR: | |
1228 | case PREDECREMENT_EXPR: | |
1229 | case POSTINCREMENT_EXPR: | |
1230 | case POSTDECREMENT_EXPR: | |
1231 | case COMPONENT_REF: | |
1232 | binary_is_unary = 1; | |
1233 | try_second = 0; | |
1234 | break; | |
1235 | ||
1236 | /* ARRAY_REFs and CALL_EXPRs must overload successfully. | |
1237 | If they do not, return error_mark_node instead of NULL_TREE. */ | |
1238 | case ARRAY_REF: | |
1239 | if (xarg2 == error_mark_node) | |
1240 | return error_mark_node; | |
1241 | case CALL_EXPR: | |
1242 | rval = error_mark_node; | |
1243 | binary_is_unary = 0; | |
1244 | try_second = 0; | |
1245 | break; | |
1246 | ||
a28e3c7f | 1247 | case VEC_NEW_EXPR: |
8d08fdba MS |
1248 | case NEW_EXPR: |
1249 | { | |
a28e3c7f MS |
1250 | tree args = tree_cons (NULL_TREE, xarg2, arg3); |
1251 | fnname = ansi_opname[(int) code]; | |
8d08fdba | 1252 | if (flags & LOOKUP_GLOBAL) |
a28e3c7f | 1253 | return build_overload_call (fnname, args, flags & LOOKUP_COMPLAIN, |
8d08fdba MS |
1254 | (struct candidate *)0); |
1255 | ||
1256 | rval = build_method_call | |
1257 | (build_indirect_ref (build1 (NOP_EXPR, xarg1, error_mark_node), | |
1258 | "new"), | |
a28e3c7f | 1259 | fnname, args, NULL_TREE, flags); |
8d08fdba MS |
1260 | if (rval == error_mark_node) |
1261 | /* User might declare fancy operator new, but invoke it | |
1262 | like standard one. */ | |
1263 | return rval; | |
1264 | ||
1265 | TREE_TYPE (rval) = xarg1; | |
1266 | TREE_CALLS_NEW (rval) = 1; | |
1267 | return rval; | |
1268 | } | |
1269 | break; | |
1270 | ||
a28e3c7f | 1271 | case VEC_DELETE_EXPR: |
8d08fdba MS |
1272 | case DELETE_EXPR: |
1273 | { | |
a28e3c7f | 1274 | fnname = ansi_opname[(int) code]; |
8d08fdba MS |
1275 | if (flags & LOOKUP_GLOBAL) |
1276 | return build_overload_call (fnname, | |
a28e3c7f | 1277 | build_tree_list (NULL_TREE, xarg1), |
8d08fdba MS |
1278 | flags & LOOKUP_COMPLAIN, |
1279 | (struct candidate *)0); | |
1280 | ||
1281 | rval = build_method_call | |
1282 | (build_indirect_ref (build1 (NOP_EXPR, TREE_TYPE (xarg1), | |
1283 | error_mark_node), | |
1284 | NULL_PTR), | |
1285 | fnname, tree_cons (NULL_TREE, xarg1, | |
a28e3c7f | 1286 | build_tree_list (NULL_TREE, xarg2)), |
8d08fdba | 1287 | NULL_TREE, flags); |
d18c083e MS |
1288 | #if 0 |
1289 | /* This can happen when operator delete is protected. */ | |
8d08fdba MS |
1290 | my_friendly_assert (rval != error_mark_node, 250); |
1291 | TREE_TYPE (rval) = void_type_node; | |
d18c083e | 1292 | #endif |
8d08fdba MS |
1293 | return rval; |
1294 | } | |
1295 | break; | |
1296 | ||
1297 | default: | |
1298 | binary_is_unary = 0; | |
1299 | try_second = tree_code_length [(int) code] == 2; | |
1300 | if (try_second && xarg2 == error_mark_node) | |
1301 | return error_mark_node; | |
1302 | break; | |
1303 | } | |
1304 | ||
1305 | if (try_second && xarg2 == error_mark_node) | |
1306 | return error_mark_node; | |
1307 | ||
1308 | /* What ever it was, we do not know how to deal with it. */ | |
1309 | if (type1 == NULL_TREE) | |
1310 | return rval; | |
1311 | ||
1312 | if (TREE_CODE (type1) == OFFSET_TYPE) | |
1313 | type1 = TREE_TYPE (type1); | |
1314 | ||
1315 | if (TREE_CODE (type1) == REFERENCE_TYPE) | |
1316 | { | |
1317 | arg1 = convert_from_reference (xarg1); | |
1318 | type1 = TREE_TYPE (arg1); | |
1319 | } | |
1320 | else | |
1321 | { | |
1322 | arg1 = xarg1; | |
1323 | } | |
1324 | ||
1325 | if (!IS_AGGR_TYPE (type1) || TYPE_PTRMEMFUNC_P (type1)) | |
1326 | { | |
1327 | /* Try to fail. First, fail if unary */ | |
1328 | if (! try_second) | |
1329 | return rval; | |
1330 | /* Second, see if second argument is non-aggregate. */ | |
1331 | type2 = TREE_TYPE (xarg2); | |
1332 | if (TREE_CODE (type2) == OFFSET_TYPE) | |
1333 | type2 = TREE_TYPE (type2); | |
1334 | if (TREE_CODE (type2) == REFERENCE_TYPE) | |
1335 | { | |
1336 | arg2 = convert_from_reference (xarg2); | |
1337 | type2 = TREE_TYPE (arg2); | |
1338 | } | |
1339 | else | |
1340 | { | |
1341 | arg2 = xarg2; | |
1342 | } | |
1343 | ||
1344 | if (!IS_AGGR_TYPE (type2)) | |
1345 | return rval; | |
1346 | try_second = 0; | |
1347 | } | |
1348 | ||
1349 | if (try_second) | |
1350 | { | |
1351 | /* First arg may succeed; see whether second should. */ | |
1352 | type2 = TREE_TYPE (xarg2); | |
1353 | if (TREE_CODE (type2) == OFFSET_TYPE) | |
1354 | type2 = TREE_TYPE (type2); | |
1355 | if (TREE_CODE (type2) == REFERENCE_TYPE) | |
1356 | { | |
1357 | arg2 = convert_from_reference (xarg2); | |
1358 | type2 = TREE_TYPE (arg2); | |
1359 | } | |
1360 | else | |
1361 | { | |
1362 | arg2 = xarg2; | |
1363 | } | |
1364 | ||
1365 | if (! IS_AGGR_TYPE (type2)) | |
1366 | try_second = 0; | |
1367 | } | |
1368 | ||
1369 | if (type1 == unknown_type_node | |
1370 | || (try_second && TREE_TYPE (xarg2) == unknown_type_node)) | |
1371 | { | |
1372 | /* This will not be implemented in the foreseeable future. */ | |
1373 | return rval; | |
1374 | } | |
1375 | ||
1376 | if (code == MODIFY_EXPR) | |
1377 | fnname = ansi_assopname[(int) TREE_CODE (arg3)]; | |
1378 | else | |
1379 | fnname = ansi_opname[(int) code]; | |
1380 | ||
700f8a87 | 1381 | global_fn = lookup_name_nonclass (fnname); |
8d08fdba MS |
1382 | |
1383 | /* This is the last point where we will accept failure. This | |
1384 | may be too eager if we wish an overloaded operator not to match, | |
1385 | but would rather a normal operator be called on a type-converted | |
1386 | argument. */ | |
1387 | ||
1388 | if (IS_AGGR_TYPE (type1)) | |
1389 | { | |
1390 | fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0); | |
1391 | /* ARM $13.4.7, prefix/postfix ++/--. */ | |
1392 | if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR) | |
1393 | { | |
1394 | xarg2 = integer_zero_node; | |
1395 | binary_is_unary = 0; | |
1396 | ||
1397 | if (fields1) | |
1398 | { | |
1399 | tree t, t2; | |
1400 | int have_postfix = 0; | |
1401 | ||
1402 | /* Look for an `operator++ (int)'. If they didn't have | |
1403 | one, then we fall back to the old way of doing things. */ | |
e1b7b0cb | 1404 | for (t = TREE_VALUE (fields1); t ; t = DECL_CHAIN (t)) |
8d08fdba MS |
1405 | { |
1406 | t2 = TYPE_ARG_TYPES (TREE_TYPE (t)); | |
1407 | if (TREE_CHAIN (t2) != NULL_TREE | |
1408 | && TREE_VALUE (TREE_CHAIN (t2)) == integer_type_node) | |
1409 | { | |
1410 | have_postfix = 1; | |
1411 | break; | |
1412 | } | |
1413 | } | |
1414 | ||
1415 | if (! have_postfix) | |
1416 | { | |
1417 | char *op = POSTINCREMENT_EXPR ? "++" : "--"; | |
1418 | ||
1419 | /* There's probably a LOT of code in the world that | |
e1b7b0cb RK |
1420 | relies upon this old behavior. */ |
1421 | if (! flag_traditional) | |
1422 | pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead", | |
8d08fdba MS |
1423 | op, op); |
1424 | xarg2 = NULL_TREE; | |
1425 | binary_is_unary = 1; | |
1426 | } | |
1427 | } | |
1428 | } | |
1429 | } | |
1430 | ||
1431 | if (fields1 == NULL_TREE && global_fn == NULL_TREE) | |
1432 | return rval; | |
1433 | ||
1434 | /* If RVAL winds up being `error_mark_node', we will return | |
1435 | that... There is no way that normal semantics of these | |
1436 | operators will succeed. */ | |
1437 | ||
1438 | /* This argument may be an uncommitted OFFSET_REF. This is | |
1439 | the case for example when dealing with static class members | |
1440 | which are referenced from their class name rather than | |
1441 | from a class instance. */ | |
1442 | if (TREE_CODE (xarg1) == OFFSET_REF | |
1443 | && TREE_CODE (TREE_OPERAND (xarg1, 1)) == VAR_DECL) | |
1444 | xarg1 = TREE_OPERAND (xarg1, 1); | |
1445 | if (try_second && xarg2 && TREE_CODE (xarg2) == OFFSET_REF | |
1446 | && TREE_CODE (TREE_OPERAND (xarg2, 1)) == VAR_DECL) | |
1447 | xarg2 = TREE_OPERAND (xarg2, 1); | |
1448 | ||
1449 | if (global_fn) | |
1450 | flags |= LOOKUP_GLOBAL; | |
1451 | ||
1452 | if (code == CALL_EXPR) | |
1453 | { | |
1454 | /* This can only be a member function. */ | |
1455 | return build_method_call (xarg1, fnname, xarg2, | |
1456 | NULL_TREE, LOOKUP_NORMAL); | |
1457 | } | |
1458 | else if (tree_code_length[(int) code] == 1 || binary_is_unary) | |
1459 | { | |
1460 | parms = NULL_TREE; | |
1461 | rval = build_method_call (xarg1, fnname, NULL_TREE, NULL_TREE, flags); | |
1462 | } | |
1463 | else if (code == COND_EXPR) | |
1464 | { | |
1465 | parms = tree_cons (0, xarg2, build_tree_list (NULL_TREE, arg3)); | |
1466 | rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags); | |
1467 | } | |
1468 | else if (code == METHOD_CALL_EXPR) | |
1469 | { | |
1470 | /* must be a member function. */ | |
1471 | parms = tree_cons (NULL_TREE, xarg2, arg3); | |
1472 | return build_method_call (xarg1, fnname, parms, NULL_TREE, | |
1473 | LOOKUP_NORMAL); | |
1474 | } | |
1475 | else if (fields1) | |
1476 | { | |
1477 | parms = build_tree_list (NULL_TREE, xarg2); | |
1478 | rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags); | |
1479 | } | |
1480 | else | |
1481 | { | |
1482 | parms = tree_cons (NULL_TREE, xarg1, | |
1483 | build_tree_list (NULL_TREE, xarg2)); | |
1484 | rval = build_overload_call (fnname, parms, flags, | |
1485 | (struct candidate *)0); | |
1486 | } | |
1487 | ||
1488 | return rval; | |
1489 | } | |
1490 | \f | |
1491 | /* This function takes an identifier, ID, and attempts to figure out what | |
1492 | it means. There are a number of possible scenarios, presented in increasing | |
1493 | order of hair: | |
1494 | ||
1495 | 1) not in a class's scope | |
1496 | 2) in class's scope, member name of the class's method | |
1497 | 3) in class's scope, but not a member name of the class | |
1498 | 4) in class's scope, member name of a class's variable | |
1499 | ||
1500 | NAME is $1 from the bison rule. It is an IDENTIFIER_NODE. | |
1501 | VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1) | |
8d08fdba MS |
1502 | |
1503 | As a last ditch, try to look up the name as a label and return that | |
1504 | address. | |
1505 | ||
1506 | Values which are declared as being of REFERENCE_TYPE are | |
1507 | automatically dereferenced here (as a hack to make the | |
1508 | compiler faster). */ | |
1509 | ||
1510 | tree | |
5566b478 | 1511 | hack_identifier (value, name) |
8d08fdba | 1512 | tree value, name; |
8d08fdba | 1513 | { |
5566b478 | 1514 | tree type, context; |
8d08fdba MS |
1515 | |
1516 | if (TREE_CODE (value) == ERROR_MARK) | |
1517 | { | |
1518 | if (current_class_name) | |
1519 | { | |
1520 | tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1); | |
1521 | if (fields == error_mark_node) | |
1522 | return error_mark_node; | |
1523 | if (fields) | |
1524 | { | |
1525 | tree fndecl; | |
1526 | ||
1527 | fndecl = TREE_VALUE (fields); | |
1528 | my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251); | |
1529 | if (DECL_CHAIN (fndecl) == NULL_TREE) | |
1530 | { | |
1531 | warning ("methods cannot be converted to function pointers"); | |
1532 | return fndecl; | |
1533 | } | |
1534 | else | |
1535 | { | |
1536 | error ("ambiguous request for method pointer `%s'", | |
1537 | IDENTIFIER_POINTER (name)); | |
1538 | return error_mark_node; | |
1539 | } | |
1540 | } | |
1541 | } | |
1542 | if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name)) | |
1543 | { | |
1544 | return IDENTIFIER_LABEL_VALUE (name); | |
1545 | } | |
1546 | return error_mark_node; | |
1547 | } | |
1548 | ||
1549 | type = TREE_TYPE (value); | |
1550 | if (TREE_CODE (value) == FIELD_DECL) | |
1551 | { | |
1552 | if (current_class_decl == NULL_TREE) | |
1553 | { | |
1554 | error ("request for member `%s' in static member function", | |
1555 | IDENTIFIER_POINTER (DECL_NAME (value))); | |
1556 | return error_mark_node; | |
1557 | } | |
1558 | TREE_USED (current_class_decl) = 1; | |
a5894242 | 1559 | |
8d08fdba MS |
1560 | /* Mark so that if we are in a constructor, and then find that |
1561 | this field was initialized by a base initializer, | |
1562 | we can emit an error message. */ | |
1563 | TREE_USED (value) = 1; | |
1564 | return build_component_ref (C_C_D, name, 0, 1); | |
1565 | } | |
1566 | ||
a5ef9010 | 1567 | if (really_overloaded_fn (value)) |
8d08fdba | 1568 | { |
72b7eeff | 1569 | #if 0 |
5b605f68 | 1570 | tree t = get_first_fn (value); |
eac293a1 | 1571 | for (; t; t = DECL_CHAIN (t)) |
8d08fdba | 1572 | { |
eac293a1 MS |
1573 | if (TREE_CODE (t) == TEMPLATE_DECL) |
1574 | continue; | |
1575 | ||
5b605f68 | 1576 | assemble_external (t); |
8d08fdba | 1577 | TREE_USED (t) = 1; |
8d08fdba | 1578 | } |
72b7eeff | 1579 | #endif |
8d08fdba | 1580 | } |
a5ef9010 JM |
1581 | else if (TREE_CODE (value) == TREE_LIST) |
1582 | { | |
72b7eeff | 1583 | /* Ambiguous reference to base members, possibly other cases?. */ |
a5ef9010 JM |
1584 | tree t = value; |
1585 | while (t && TREE_CODE (t) == TREE_LIST) | |
1586 | { | |
72b7eeff | 1587 | mark_used (TREE_VALUE (t)); |
a5ef9010 JM |
1588 | t = TREE_CHAIN (t); |
1589 | } | |
1590 | } | |
8d08fdba | 1591 | else |
72b7eeff | 1592 | mark_used (value); |
8d08fdba | 1593 | |
e76a2646 | 1594 | if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL) |
5566b478 MS |
1595 | { |
1596 | tree context = decl_function_context (value); | |
1597 | if (context != NULL_TREE && context != current_function_decl | |
1598 | && ! TREE_STATIC (value)) | |
1599 | { | |
e76a2646 | 1600 | cp_error ("use of %s from containing function", |
5566b478 MS |
1601 | (TREE_CODE (value) == VAR_DECL |
1602 | ? "`auto' variable" : "parameter")); | |
e76a2646 MS |
1603 | cp_error_at (" `%#D' declared here", value); |
1604 | value = error_mark_node; | |
5566b478 MS |
1605 | } |
1606 | } | |
1607 | ||
8d08fdba MS |
1608 | if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value)) |
1609 | { | |
1610 | if (DECL_LANG_SPECIFIC (value) | |
1611 | && DECL_CLASS_CONTEXT (value) != current_class_type) | |
1612 | { | |
be99da77 | 1613 | tree path, access; |
8d08fdba MS |
1614 | register tree context |
1615 | = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value)) | |
1616 | ? DECL_CLASS_CONTEXT (value) | |
1617 | : DECL_CONTEXT (value); | |
1618 | ||
1619 | get_base_distance (context, current_class_type, 0, &path); | |
1620 | if (path) | |
1621 | { | |
1622 | access = compute_access (path, value); | |
be99da77 | 1623 | if (access != access_public_node) |
8d08fdba MS |
1624 | { |
1625 | if (TREE_CODE (value) == VAR_DECL) | |
1626 | error ("static member `%s' is %s", | |
1627 | IDENTIFIER_POINTER (name), | |
1628 | TREE_PRIVATE (value) ? "private" : | |
1629 | "from a private base class"); | |
1630 | else | |
1631 | error ("enum `%s' is from private base class", | |
1632 | IDENTIFIER_POINTER (name)); | |
1633 | return error_mark_node; | |
1634 | } | |
1635 | } | |
1636 | } | |
1637 | return value; | |
1638 | } | |
1639 | if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value)) | |
1640 | { | |
1641 | if (type == 0) | |
1642 | { | |
1643 | error ("request for member `%s' is ambiguous in multiple inheritance lattice", | |
1644 | IDENTIFIER_POINTER (name)); | |
1645 | return error_mark_node; | |
1646 | } | |
1647 | ||
1648 | return value; | |
1649 | } | |
1650 | ||
5566b478 | 1651 | if (TREE_CODE (type) == REFERENCE_TYPE && ! current_template_parms) |
8d08fdba MS |
1652 | { |
1653 | my_friendly_assert (TREE_CODE (value) == VAR_DECL | |
1654 | || TREE_CODE (value) == PARM_DECL | |
1655 | || TREE_CODE (value) == RESULT_DECL, 252); | |
878cd289 | 1656 | return convert_from_reference (value); |
8d08fdba MS |
1657 | } |
1658 | return value; | |
1659 | } | |
1660 | ||
1661 | \f | |
39211cd5 | 1662 | #if 0 |
8d08fdba MS |
1663 | /* Given an object OF, and a type conversion operator COMPONENT |
1664 | build a call to the conversion operator, if a call is requested, | |
1665 | or return the address (as a pointer to member function) if one is not. | |
1666 | ||
1667 | OF can be a TYPE_DECL or any kind of datum that would normally | |
1668 | be passed to `build_component_ref'. It may also be NULL_TREE, | |
1669 | in which case `current_class_type' and `current_class_decl' | |
1670 | provide default values. | |
1671 | ||
1672 | BASETYPE_PATH, if non-null, is the path of basetypes | |
1673 | to go through before we get the the instance of interest. | |
1674 | ||
1675 | PROTECT says whether we apply C++ scoping rules or not. */ | |
1676 | tree | |
1677 | build_component_type_expr (of, component, basetype_path, protect) | |
1678 | tree of, component, basetype_path; | |
1679 | int protect; | |
1680 | { | |
1681 | tree cname = NULL_TREE; | |
1682 | tree tmp, last; | |
1683 | tree name; | |
1684 | int flags = protect ? LOOKUP_NORMAL : LOOKUP_COMPLAIN; | |
1685 | ||
1686 | if (of) | |
1687 | my_friendly_assert (IS_AGGR_TYPE (TREE_TYPE (of)), 253); | |
1688 | my_friendly_assert (TREE_CODE (component) == TYPE_EXPR, 254); | |
1689 | ||
1690 | tmp = TREE_OPERAND (component, 0); | |
1691 | last = NULL_TREE; | |
1692 | ||
1693 | while (tmp) | |
1694 | { | |
1695 | switch (TREE_CODE (tmp)) | |
1696 | { | |
1697 | case CALL_EXPR: | |
1698 | if (last) | |
1699 | TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0); | |
1700 | else | |
1701 | TREE_OPERAND (component, 0) = TREE_OPERAND (tmp, 0); | |
1702 | ||
1703 | last = groktypename (build_tree_list (TREE_TYPE (component), | |
1704 | TREE_OPERAND (component, 0))); | |
1705 | name = build_typename_overload (last); | |
1706 | TREE_TYPE (name) = last; | |
1707 | ||
1708 | if (TREE_OPERAND (tmp, 0) | |
1709 | && TREE_OPERAND (tmp, 0) != void_list_node) | |
1710 | { | |
1711 | cp_error ("`operator %T' requires empty parameter list", last); | |
1712 | TREE_OPERAND (tmp, 0) = NULL_TREE; | |
1713 | } | |
1714 | ||
1715 | if (of && TREE_CODE (of) != TYPE_DECL) | |
1716 | return build_method_call (of, name, NULL_TREE, NULL_TREE, flags); | |
1717 | else if (of) | |
1718 | { | |
1719 | tree this_this; | |
1720 | ||
1721 | if (current_class_decl == NULL_TREE) | |
1722 | { | |
1723 | cp_error ("object required for `operator %T' call", | |
1724 | TREE_TYPE (name)); | |
1725 | return error_mark_node; | |
1726 | } | |
1727 | ||
1728 | this_this = convert_pointer_to (TREE_TYPE (of), | |
1729 | current_class_decl); | |
1730 | this_this = build_indirect_ref (this_this, NULL_PTR); | |
1731 | return build_method_call (this_this, name, NULL_TREE, | |
1732 | NULL_TREE, flags | LOOKUP_NONVIRTUAL); | |
1733 | } | |
1734 | else if (current_class_decl) | |
1735 | return build_method_call (tmp, name, NULL_TREE, NULL_TREE, flags); | |
1736 | ||
1737 | cp_error ("object required for `operator %T' call", | |
1738 | TREE_TYPE (name)); | |
1739 | return error_mark_node; | |
1740 | ||
1741 | case INDIRECT_REF: | |
1742 | case ADDR_EXPR: | |
1743 | case ARRAY_REF: | |
1744 | break; | |
1745 | ||
1746 | case SCOPE_REF: | |
1747 | my_friendly_assert (cname == 0, 255); | |
1748 | cname = TREE_OPERAND (tmp, 0); | |
1749 | tmp = TREE_OPERAND (tmp, 1); | |
1750 | break; | |
1751 | ||
1752 | default: | |
1753 | my_friendly_abort (77); | |
1754 | } | |
1755 | last = tmp; | |
1756 | tmp = TREE_OPERAND (tmp, 0); | |
1757 | } | |
1758 | ||
1759 | last = groktypename (build_tree_list (TREE_TYPE (component), TREE_OPERAND (component, 0))); | |
1760 | name = build_typename_overload (last); | |
1761 | TREE_TYPE (name) = last; | |
1762 | if (of && TREE_CODE (of) == TYPE_DECL) | |
1763 | { | |
1764 | if (cname == NULL_TREE) | |
1765 | { | |
1766 | cname = DECL_NAME (of); | |
1767 | of = NULL_TREE; | |
1768 | } | |
1769 | else my_friendly_assert (cname == DECL_NAME (of), 256); | |
1770 | } | |
1771 | ||
1772 | if (of) | |
1773 | { | |
1774 | tree this_this; | |
1775 | ||
1776 | if (current_class_decl == NULL_TREE) | |
1777 | { | |
1778 | cp_error ("object required for `operator %T' call", | |
1779 | TREE_TYPE (name)); | |
1780 | return error_mark_node; | |
1781 | } | |
1782 | ||
1783 | this_this = convert_pointer_to (TREE_TYPE (of), current_class_decl); | |
1784 | return build_component_ref (this_this, name, 0, protect); | |
1785 | } | |
1786 | else if (cname) | |
1787 | return build_offset_ref (cname, name); | |
1788 | else if (current_class_name) | |
1789 | return build_offset_ref (current_class_name, name); | |
1790 | ||
1791 | cp_error ("object required for `operator %T' member reference", | |
1792 | TREE_TYPE (name)); | |
1793 | return error_mark_node; | |
1794 | } | |
39211cd5 | 1795 | #endif |
8926095f MS |
1796 | \f |
1797 | static char * | |
1798 | thunk_printable_name (decl) | |
1799 | tree decl; | |
1800 | { | |
1801 | return "<thunk function>"; | |
1802 | } | |
1803 | ||
1804 | tree | |
1805 | make_thunk (function, delta) | |
1806 | tree function; | |
1807 | int delta; | |
1808 | { | |
1809 | char buffer[250]; | |
a0a33927 | 1810 | tree thunk_fndecl, thunk_id; |
8926095f | 1811 | tree thunk; |
a0a33927 | 1812 | char *func_name; |
8926095f MS |
1813 | static int thunk_number = 0; |
1814 | tree func_decl; | |
1815 | if (TREE_CODE (function) != ADDR_EXPR) | |
1816 | abort (); | |
1817 | func_decl = TREE_OPERAND (function, 0); | |
1818 | if (TREE_CODE (func_decl) != FUNCTION_DECL) | |
1819 | abort (); | |
a0a33927 | 1820 | func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl)); |
5edb8b93 MS |
1821 | if (delta<=0) |
1822 | sprintf (buffer, "__thunk_%d_%s", -delta, func_name); | |
1823 | else | |
1824 | sprintf (buffer, "__thunk_n%d_%s", delta, func_name); | |
a0a33927 MS |
1825 | thunk_id = get_identifier (buffer); |
1826 | thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id); | |
1827 | if (thunk && TREE_CODE (thunk) != THUNK_DECL) | |
1828 | { | |
1829 | error_with_decl ("implementation-reserved name `%s' used"); | |
1830 | IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE; | |
1831 | } | |
1832 | if (thunk == NULL_TREE) | |
1833 | { | |
72b7eeff | 1834 | thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl)); |
a0a33927 | 1835 | DECL_RESULT (thunk) |
f30432d7 MS |
1836 | = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (vtable_entry_type))); |
1837 | TREE_READONLY (thunk) = TYPE_READONLY (TREE_TYPE (vtable_entry_type)); | |
1838 | TREE_THIS_VOLATILE (thunk) = TYPE_VOLATILE (TREE_TYPE (vtable_entry_type)); | |
a0a33927 | 1839 | make_function_rtl (thunk); |
72b7eeff | 1840 | TREE_SET_CODE (thunk, THUNK_DECL); |
a0a33927 MS |
1841 | DECL_INITIAL (thunk) = function; |
1842 | THUNK_DELTA (thunk) = delta; | |
72b7eeff MS |
1843 | DECL_EXTERNAL (thunk) = 1; |
1844 | TREE_PUBLIC (thunk) = 1; | |
a0a33927 MS |
1845 | /* So that finish_file can write out any thunks that need to be: */ |
1846 | pushdecl_top_level (thunk); | |
1847 | } | |
8926095f MS |
1848 | return thunk; |
1849 | } | |
1850 | ||
1851 | void | |
1852 | emit_thunk (thunk_fndecl) | |
1853 | tree thunk_fndecl; | |
1854 | { | |
1855 | rtx insns; | |
1856 | char *fnname; | |
1857 | char buffer[250]; | |
1858 | tree argp; | |
1859 | struct args_size stack_args_size; | |
1860 | tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0); | |
1861 | int delta = THUNK_DELTA (thunk_fndecl); | |
1862 | int tem; | |
1863 | int failure = 0; | |
2986ae00 | 1864 | int current_call_is_indirect = 0; /* needed for HPPA FUNCTION_ARG */ |
8926095f MS |
1865 | |
1866 | /* Used to remember which regs we need to emit a USE rtx for. */ | |
1867 | rtx need_use[FIRST_PSEUDO_REGISTER]; | |
1868 | int need_use_count = 0; | |
1869 | ||
1870 | /* rtx for the 'this' parameter. */ | |
1871 | rtx this_rtx = 0, this_reg_rtx = 0, fixed_this_rtx; | |
1872 | ||
1873 | char *(*save_decl_printable_name) () = decl_printable_name; | |
1874 | /* Data on reg parms scanned so far. */ | |
1875 | CUMULATIVE_ARGS args_so_far; | |
1876 | ||
1877 | if (TREE_ASM_WRITTEN (thunk_fndecl)) | |
1878 | return; | |
1879 | ||
a0a33927 MS |
1880 | TREE_ASM_WRITTEN (thunk_fndecl) = 1; |
1881 | ||
72b7eeff MS |
1882 | if (! TREE_PUBLIC (function)) |
1883 | TREE_PUBLIC (thunk_fndecl) = 0; | |
1884 | if (DECL_EXTERNAL (function)) | |
1885 | return; | |
1886 | DECL_EXTERNAL (thunk_fndecl) = 0; | |
a0a33927 | 1887 | |
8926095f MS |
1888 | decl_printable_name = thunk_printable_name; |
1889 | if (current_function_decl) | |
1890 | abort (); | |
1891 | current_function_decl = thunk_fndecl; | |
1892 | init_function_start (thunk_fndecl, input_filename, lineno); | |
1893 | pushlevel (0); | |
1894 | expand_start_bindings (1); | |
1895 | ||
1896 | /* Start updating where the next arg would go. */ | |
1897 | INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (function), NULL_RTX); | |
1898 | stack_args_size.constant = 0; | |
1899 | stack_args_size.var = 0; | |
1900 | /* SETUP for possible structure return address FIXME */ | |
1901 | ||
1902 | /* Now look through all the parameters, make sure that we | |
1903 | don't clobber any registers used for parameters. | |
1904 | Also, pick up an rtx for the first "this" parameter. */ | |
1905 | for (argp = TYPE_ARG_TYPES (TREE_TYPE (function)); | |
1906 | argp != NULL_TREE; | |
1907 | argp = TREE_CHAIN (argp)) | |
1908 | ||
1909 | { | |
1910 | tree passed_type = TREE_VALUE (argp); | |
1911 | register rtx entry_parm; | |
1912 | int named = 1; /* FIXME */ | |
1913 | struct args_size stack_offset; | |
1914 | struct args_size arg_size; | |
1915 | ||
1916 | if (passed_type == void_type_node) | |
1917 | break; | |
1918 | ||
1919 | if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST | |
1920 | && contains_placeholder_p (TYPE_SIZE (passed_type))) | |
1921 | #ifdef FUNCTION_ARG_PASS_BY_REFERENCE | |
1922 | || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, | |
1923 | TYPE_MODE (passed_type), | |
1924 | passed_type, named) | |
1925 | #endif | |
1926 | ) | |
1927 | passed_type = build_pointer_type (passed_type); | |
1928 | ||
1929 | entry_parm = FUNCTION_ARG (args_so_far, | |
1930 | TYPE_MODE (passed_type), | |
1931 | passed_type, | |
1932 | named); | |
1933 | if (entry_parm != 0) | |
1934 | need_use[need_use_count++] = entry_parm; | |
1935 | ||
1936 | locate_and_pad_parm (TYPE_MODE (passed_type), passed_type, | |
1937 | #ifdef STACK_PARMS_IN_REG_PARM_AREA | |
1938 | 1, | |
1939 | #else | |
1940 | entry_parm != 0, | |
1941 | #endif | |
1942 | thunk_fndecl, | |
1943 | &stack_args_size, &stack_offset, &arg_size); | |
1944 | ||
1945 | /* REGNO (entry_parm);*/ | |
1946 | if (this_rtx == 0) | |
1947 | { | |
1948 | this_reg_rtx = entry_parm; | |
1949 | if (!entry_parm) | |
1950 | { | |
1951 | rtx offset_rtx = ARGS_SIZE_RTX (stack_offset); | |
1952 | ||
1953 | rtx internal_arg_pointer, stack_parm; | |
1954 | ||
1955 | if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM | |
1956 | || ! (fixed_regs[ARG_POINTER_REGNUM] | |
1957 | || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))) | |
1958 | internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx); | |
1959 | else | |
1960 | internal_arg_pointer = virtual_incoming_args_rtx; | |
1961 | ||
1962 | if (offset_rtx == const0_rtx) | |
1963 | entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type), | |
1964 | internal_arg_pointer); | |
1965 | else | |
1966 | entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type), | |
1967 | gen_rtx (PLUS, Pmode, | |
1968 | internal_arg_pointer, | |
1969 | offset_rtx)); | |
1970 | } | |
1971 | ||
1972 | this_rtx = entry_parm; | |
1973 | } | |
1974 | ||
1975 | FUNCTION_ARG_ADVANCE (args_so_far, | |
1976 | TYPE_MODE (passed_type), | |
1977 | passed_type, | |
1978 | named); | |
1979 | } | |
1980 | ||
1981 | fixed_this_rtx = plus_constant (this_rtx, delta); | |
1982 | if (this_rtx != fixed_this_rtx) | |
1983 | emit_move_insn (this_rtx, fixed_this_rtx); | |
1984 | ||
1985 | if (this_reg_rtx) | |
1986 | emit_insn (gen_rtx (USE, VOIDmode, this_reg_rtx)); | |
1987 | ||
1988 | emit_indirect_jump (XEXP (DECL_RTL (function), 0)); | |
1989 | ||
1990 | while (need_use_count > 0) | |
1991 | emit_insn (gen_rtx (USE, VOIDmode, need_use[--need_use_count])); | |
1992 | ||
1993 | expand_end_bindings (NULL, 1, 0); | |
faae18ab | 1994 | poplevel (0, 0, 1); |
8926095f | 1995 | |
8926095f MS |
1996 | /* From now on, allocate rtl in current_obstack, not in saveable_obstack. |
1997 | Note that that may have been done above, in save_for_inline_copying. | |
1998 | The call to resume_temporary_allocation near the end of this function | |
1999 | goes back to the usual state of affairs. */ | |
2000 | ||
2001 | rtl_in_current_obstack (); | |
2002 | ||
2003 | insns = get_insns (); | |
2004 | ||
2005 | /* Copy any shared structure that should not be shared. */ | |
2006 | ||
2007 | unshare_all_rtl (insns); | |
2008 | ||
db5ae43f MS |
2009 | /* Instantiate all virtual registers. */ |
2010 | ||
2011 | instantiate_virtual_regs (current_function_decl, get_insns ()); | |
2012 | ||
8926095f MS |
2013 | /* We are no longer anticipating cse in this function, at least. */ |
2014 | ||
2015 | cse_not_expected = 1; | |
2016 | ||
2017 | /* Now we choose between stupid (pcc-like) register allocation | |
2018 | (if we got the -noreg switch and not -opt) | |
2019 | and smart register allocation. */ | |
2020 | ||
2021 | if (optimize > 0) /* Stupid allocation probably won't work */ | |
2022 | obey_regdecls = 0; /* if optimizations being done. */ | |
2023 | ||
2024 | regclass_init (); | |
2025 | ||
2026 | regclass (insns, max_reg_num ()); | |
2027 | if (obey_regdecls) | |
2028 | { | |
2029 | stupid_life_analysis (insns, max_reg_num (), NULL); | |
2030 | failure = reload (insns, 0, NULL); | |
2031 | } | |
2032 | else | |
2033 | { | |
2034 | /* Do control and data flow analysis, | |
2035 | and write some of the results to dump file. */ | |
2036 | ||
2037 | flow_analysis (insns, max_reg_num (), NULL); | |
2038 | local_alloc (); | |
2039 | failure = global_alloc (NULL); | |
2040 | } | |
2041 | ||
2042 | reload_completed = 1; | |
2043 | ||
2044 | #ifdef LEAF_REGISTERS | |
2045 | leaf_function = 0; | |
2046 | if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ()) | |
2047 | leaf_function = 1; | |
2048 | #endif | |
2049 | ||
2050 | /* If a machine dependent reorganization is needed, call it. */ | |
2051 | #ifdef MACHINE_DEPENDENT_REORG | |
2052 | MACHINE_DEPENDENT_REORG (insns); | |
2053 | #endif | |
2054 | ||
2055 | /* Now turn the rtl into assembler code. */ | |
2056 | ||
2057 | { | |
2058 | char *fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0); | |
2059 | assemble_start_function (thunk_fndecl, fnname); | |
2060 | final (insns, asm_out_file, optimize, 0); | |
2061 | assemble_end_function (thunk_fndecl, fnname); | |
2062 | }; | |
2063 | ||
2064 | exit_rest_of_compilation: | |
2065 | ||
2066 | reload_completed = 0; | |
2067 | ||
2068 | /* Cancel the effect of rtl_in_current_obstack. */ | |
2069 | ||
2070 | resume_temporary_allocation (); | |
2071 | ||
2072 | decl_printable_name = save_decl_printable_name; | |
2073 | current_function_decl = 0; | |
2074 | } | |
f376e137 MS |
2075 | \f |
2076 | /* Code for synthesizing methods which have default semantics defined. */ | |
2077 | ||
0171aeab JM |
2078 | /* For the anonymous union in TYPE, return the member that is at least as |
2079 | large as the rest of the members, so we can copy it. */ | |
2080 | static tree | |
2081 | largest_union_member (type) | |
2082 | tree type; | |
2083 | { | |
2084 | tree f, type_size = TYPE_SIZE (type); | |
2085 | ||
2086 | for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f)) | |
14ac3bfe | 2087 | if (simple_cst_equal (DECL_SIZE (f), type_size) == 1) |
0171aeab JM |
2088 | return f; |
2089 | ||
2090 | /* We should always find one. */ | |
2091 | my_friendly_abort (323); | |
2092 | return NULL_TREE; | |
2093 | } | |
2094 | ||
f376e137 MS |
2095 | /* Generate code for default X(X&) constructor. */ |
2096 | void | |
db5ae43f | 2097 | do_build_copy_constructor (fndecl) |
f376e137 MS |
2098 | tree fndecl; |
2099 | { | |
2100 | tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); | |
2101 | tree t; | |
2102 | ||
f376e137 MS |
2103 | clear_last_expr (); |
2104 | push_momentary (); | |
2105 | ||
2106 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) | |
2107 | parm = TREE_CHAIN (parm); | |
2108 | parm = convert_from_reference (parm); | |
2109 | ||
e8abc66f | 2110 | if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)) |
f376e137 MS |
2111 | { |
2112 | t = build (INIT_EXPR, void_type_node, C_C_D, parm); | |
2113 | TREE_SIDE_EFFECTS (t) = 1; | |
2114 | cplus_expand_expr_stmt (t); | |
2115 | } | |
2116 | else | |
2117 | { | |
2118 | tree fields = TYPE_FIELDS (current_class_type); | |
2119 | int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type); | |
2120 | tree binfos = TYPE_BINFO_BASETYPES (current_class_type); | |
2121 | int i; | |
2122 | ||
2123 | for (t = CLASSTYPE_VBASECLASSES (current_class_type); t; | |
2124 | t = TREE_CHAIN (t)) | |
2125 | { | |
2126 | tree basetype = BINFO_TYPE (t); | |
8ccc31eb MS |
2127 | tree p = convert_to_reference |
2128 | (build_reference_type (basetype), parm, | |
2129 | CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE); | |
f376e137 | 2130 | p = convert_from_reference (p); |
be99da77 | 2131 | current_base_init_list = tree_cons (basetype, |
f376e137 MS |
2132 | p, current_base_init_list); |
2133 | } | |
2134 | ||
2135 | for (i = 0; i < n_bases; ++i) | |
2136 | { | |
2137 | tree p, basetype = TREE_VEC_ELT (binfos, i); | |
2138 | if (TREE_VIA_VIRTUAL (basetype)) | |
8ccc31eb | 2139 | continue; |
f376e137 MS |
2140 | |
2141 | basetype = BINFO_TYPE (basetype); | |
8ccc31eb MS |
2142 | p = convert_to_reference |
2143 | (build_reference_type (basetype), parm, | |
2144 | CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE); | |
f376e137 | 2145 | p = convert_from_reference (p); |
be99da77 | 2146 | current_base_init_list = tree_cons (basetype, |
f376e137 MS |
2147 | p, current_base_init_list); |
2148 | } | |
2149 | for (; fields; fields = TREE_CHAIN (fields)) | |
2150 | { | |
0171aeab | 2151 | tree name, init, t; |
a5894242 MS |
2152 | tree field = fields; |
2153 | ||
2154 | if (TREE_CODE (field) != FIELD_DECL) | |
f376e137 | 2155 | continue; |
a5894242 | 2156 | if (DECL_NAME (field)) |
f376e137 | 2157 | { |
a5894242 | 2158 | if (VFIELD_NAME_P (DECL_NAME (field))) |
f376e137 | 2159 | continue; |
a5894242 | 2160 | if (VBASE_NAME_P (DECL_NAME (field))) |
f376e137 MS |
2161 | continue; |
2162 | ||
2163 | /* True for duplicate members. */ | |
a5894242 | 2164 | if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field) |
f376e137 MS |
2165 | continue; |
2166 | } | |
a5894242 | 2167 | else if ((t = TREE_TYPE (field)) != NULL_TREE |
0171aeab JM |
2168 | && TREE_CODE (t) == UNION_TYPE |
2169 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)) | |
2170 | && TYPE_FIELDS (t) != NULL_TREE) | |
a5894242 | 2171 | field = largest_union_member (t); |
0171aeab JM |
2172 | else |
2173 | continue; | |
f376e137 | 2174 | |
a5894242 | 2175 | init = build (COMPONENT_REF, TREE_TYPE (field), parm, field); |
f376e137 MS |
2176 | init = build_tree_list (NULL_TREE, init); |
2177 | ||
2178 | current_member_init_list | |
a5894242 | 2179 | = tree_cons (DECL_NAME (field), init, current_member_init_list); |
f376e137 MS |
2180 | } |
2181 | current_member_init_list = nreverse (current_member_init_list); | |
faae18ab | 2182 | current_base_init_list = nreverse (current_base_init_list); |
f376e137 MS |
2183 | setup_vtbl_ptr (); |
2184 | } | |
2185 | ||
2186 | pop_momentary (); | |
f376e137 MS |
2187 | } |
2188 | ||
2189 | void | |
db5ae43f | 2190 | do_build_assign_ref (fndecl) |
f376e137 MS |
2191 | tree fndecl; |
2192 | { | |
2193 | tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); | |
2194 | ||
db5ae43f | 2195 | clear_last_expr (); |
f376e137 MS |
2196 | push_momentary (); |
2197 | ||
2198 | parm = convert_from_reference (parm); | |
2199 | ||
e8abc66f | 2200 | if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)) |
f376e137 MS |
2201 | { |
2202 | tree t = build (MODIFY_EXPR, void_type_node, C_C_D, parm); | |
2203 | TREE_SIDE_EFFECTS (t) = 1; | |
2204 | cplus_expand_expr_stmt (t); | |
2205 | } | |
2206 | else | |
2207 | { | |
2208 | tree fields = TYPE_FIELDS (current_class_type); | |
2209 | int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type); | |
2210 | tree binfos = TYPE_BINFO_BASETYPES (current_class_type); | |
2211 | int i; | |
2212 | ||
2213 | for (i = 0; i < n_bases; ++i) | |
2214 | { | |
2215 | tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i)); | |
2216 | if (TYPE_HAS_ASSIGN_REF (basetype)) | |
2217 | { | |
8ccc31eb MS |
2218 | tree p = convert_to_reference |
2219 | (build_reference_type (basetype), parm, | |
2220 | CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE); | |
f376e137 | 2221 | p = convert_from_reference (p); |
be99da77 | 2222 | p = build_member_call (basetype, ansi_opname [MODIFY_EXPR], |
f376e137 MS |
2223 | build_tree_list (NULL_TREE, p)); |
2224 | expand_expr_stmt (p); | |
2225 | } | |
2226 | } | |
2227 | for (; fields; fields = TREE_CHAIN (fields)) | |
2228 | { | |
0171aeab | 2229 | tree comp, init, t; |
a5894242 MS |
2230 | tree field = fields; |
2231 | ||
2232 | if (TREE_CODE (field) != FIELD_DECL) | |
f376e137 | 2233 | continue; |
a5894242 | 2234 | if (DECL_NAME (field)) |
f376e137 | 2235 | { |
a5894242 | 2236 | if (VFIELD_NAME_P (DECL_NAME (field))) |
f376e137 | 2237 | continue; |
a5894242 | 2238 | if (VBASE_NAME_P (DECL_NAME (field))) |
f376e137 MS |
2239 | continue; |
2240 | ||
2241 | /* True for duplicate members. */ | |
a5894242 | 2242 | if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field) |
f376e137 MS |
2243 | continue; |
2244 | } | |
a5894242 | 2245 | else if ((t = TREE_TYPE (field)) != NULL_TREE |
0171aeab JM |
2246 | && TREE_CODE (t) == UNION_TYPE |
2247 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)) | |
2248 | && TYPE_FIELDS (t) != NULL_TREE) | |
a5894242 | 2249 | field = largest_union_member (t); |
0171aeab JM |
2250 | else |
2251 | continue; | |
f376e137 | 2252 | |
a5894242 MS |
2253 | comp = build (COMPONENT_REF, TREE_TYPE (field), C_C_D, field); |
2254 | init = build (COMPONENT_REF, TREE_TYPE (field), parm, field); | |
f376e137 MS |
2255 | |
2256 | expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init)); | |
2257 | } | |
2258 | } | |
2259 | c_expand_return (C_C_D); | |
2260 | pop_momentary (); | |
f376e137 MS |
2261 | } |
2262 | ||
2263 | void | |
db5ae43f | 2264 | synthesize_method (fndecl) |
f376e137 MS |
2265 | tree fndecl; |
2266 | { | |
db5ae43f | 2267 | int nested = (current_function_decl != NULL_TREE); |
e76a2646 | 2268 | tree context = hack_decl_function_context (fndecl); |
b7484fbe | 2269 | tree base = DECL_CLASS_CONTEXT (fndecl); |
db5ae43f MS |
2270 | |
2271 | if (nested) | |
28cbf42c | 2272 | push_cp_function_context (context); |
db5ae43f | 2273 | |
e76a2646 | 2274 | interface_unknown = 1; |
f30432d7 | 2275 | start_function (NULL_TREE, fndecl, NULL_TREE, NULL_TREE, 1); |
f376e137 | 2276 | store_parm_decls (); |
db5ae43f MS |
2277 | |
2278 | if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR]) | |
2279 | do_build_assign_ref (fndecl); | |
2280 | else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) | |
2281 | ; | |
2282 | else | |
2283 | { | |
2284 | tree arg_chain = FUNCTION_ARG_CHAIN (fndecl); | |
2285 | if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl)) | |
2286 | arg_chain = TREE_CHAIN (arg_chain); | |
2287 | if (arg_chain != void_list_node) | |
2288 | do_build_copy_constructor (fndecl); | |
2289 | else if (TYPE_NEEDS_CONSTRUCTING (current_class_type)) | |
2290 | setup_vtbl_ptr (); | |
2291 | } | |
2292 | ||
2293 | finish_function (lineno, 0, nested); | |
28cbf42c MS |
2294 | |
2295 | /* Do we really *want* to inline this function? */ | |
2296 | if (DECL_INLINE (fndecl)) | |
2297 | { | |
2298 | /* Turn off DECL_INLINE for the moment so function_cannot_inline_p | |
2299 | will check our size. */ | |
2300 | DECL_INLINE (fndecl) = 0; | |
2301 | if (function_cannot_inline_p (fndecl) == 0) | |
2302 | DECL_INLINE (fndecl) = 1; | |
2303 | } | |
2304 | ||
db5ae43f MS |
2305 | extract_interface_info (); |
2306 | if (nested) | |
28cbf42c | 2307 | pop_cp_function_context (context); |
f376e137 | 2308 | } |