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