]>
Commit | Line | Data |
---|---|---|
8d08fdba MS |
1 | /* Handle the hair of processing (but not expanding) inline functions. |
2 | Also manage function and variable name overloading. | |
8be64d09 | 3 | Copyright (C) 1987, 89, 92-97, 1998, 1999 Free Software Foundation, Inc. |
8d08fdba MS |
4 | Contributed by Michael Tiemann (tiemann@cygnus.com) |
5 | ||
e5e809f4 | 6 | This file is part of GNU CC. |
8d08fdba MS |
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 | ||
ed22c95e AM |
24 | #ifndef __GNUC__ |
25 | #define __inline | |
26 | #endif | |
27 | ||
8d08fdba MS |
28 | #ifndef PARM_CAN_BE_ARRAY_TYPE |
29 | #define PARM_CAN_BE_ARRAY_TYPE 1 | |
30 | #endif | |
31 | ||
32 | /* Handle method declarations. */ | |
8d08fdba | 33 | #include "config.h" |
e817b5e3 | 34 | #include "system.h" |
8d08fdba MS |
35 | #include "tree.h" |
36 | #include "cp-tree.h" | |
8d08fdba | 37 | #include "obstack.h" |
8926095f MS |
38 | #include "rtl.h" |
39 | #include "expr.h" | |
40 | #include "output.h" | |
41 | #include "hard-reg-set.h" | |
42 | #include "flags.h" | |
54f92bfb | 43 | #include "toplev.h" |
9cd64686 | 44 | #include "ggc.h" |
8d08fdba MS |
45 | |
46 | /* TREE_LIST of the current inline functions that need to be | |
47 | processed. */ | |
48 | struct pending_inline *pending_inlines; | |
49 | ||
50 | #define obstack_chunk_alloc xmalloc | |
51 | #define obstack_chunk_free free | |
52 | ||
53 | /* Obstack where we build text strings for overloading, etc. */ | |
54 | static struct obstack scratch_obstack; | |
55 | static char *scratch_firstobj; | |
56 | ||
49c249e1 JM |
57 | static void icat PROTO((HOST_WIDE_INT)); |
58 | static void dicat PROTO((HOST_WIDE_INT, HOST_WIDE_INT)); | |
f921acee JM |
59 | static int old_backref_index PROTO((tree)); |
60 | static int flush_repeats PROTO((int, tree)); | |
49c249e1 JM |
61 | static void build_overload_identifier PROTO((tree)); |
62 | static void build_overload_nested_name PROTO((tree)); | |
37dac039 | 63 | static void build_overload_int PROTO((tree, int)); |
49c249e1 JM |
64 | static void build_overload_identifier PROTO((tree)); |
65 | static void build_qualified_name PROTO((tree)); | |
37dac039 | 66 | static void build_overload_value PROTO((tree, tree, int)); |
59e621fc | 67 | static void issue_nrepeats PROTO((int, tree)); |
ed22c95e AM |
68 | static char *build_mangled_name PROTO((tree,int,int)); |
69 | static void process_modifiers PROTO((tree)); | |
70 | static void process_overload_item PROTO((tree,int)); | |
49c249e1 JM |
71 | static void do_build_assign_ref PROTO((tree)); |
72 | static void do_build_copy_constructor PROTO((tree)); | |
73b0fce8 | 73 | static void build_template_template_parm_names PROTO((tree)); |
386b8a85 JM |
74 | static void build_template_parm_names PROTO((tree, tree)); |
75 | static void build_underscore_int PROTO((int)); | |
47c78a3f JL |
76 | static void start_squangling PROTO((void)); |
77 | static void end_squangling PROTO((void)); | |
69ac77ce JL |
78 | static int check_ktype PROTO((tree, int)); |
79 | static int issue_ktype PROTO((tree)); | |
47c78a3f | 80 | static void build_overload_scope_ref PROTO((tree)); |
9c0758dd | 81 | static void build_mangled_template_parm_index PROTO((const char *, tree)); |
e833cb11 | 82 | #if HOST_BITS_PER_WIDE_INT >= 64 |
25f3d2f4 | 83 | static void build_mangled_C9x_name PROTO((int)); |
e833cb11 | 84 | #endif |
59e621fc | 85 | static int is_back_referenceable_type PROTO((tree)); |
69ac77ce | 86 | static int check_btype PROTO((tree)); |
59e621fc MM |
87 | static void build_mangled_name_for_type PROTO((tree)); |
88 | static void build_mangled_name_for_type_with_Gcode PROTO((tree, int)); | |
49c249e1 | 89 | |
8d08fdba MS |
90 | # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0) |
91 | # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C))) | |
92 | # define OB_PUTC2(C1,C2) \ | |
93 | (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2))) | |
94 | # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1)) | |
95 | # define OB_PUTID(ID) \ | |
96 | (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \ | |
97 | IDENTIFIER_LENGTH (ID))) | |
98 | # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S))) | |
99 | # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0')) | |
db5ae43f | 100 | # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1]) |
8d08fdba | 101 | |
9cd64686 MM |
102 | /* type tables for K and B type compression */ |
103 | static varray_type btypelist; | |
104 | static varray_type ktypelist; | |
105 | ||
106 | /* number of each type seen */ | |
107 | static size_t maxbtype; | |
108 | static size_t maxktype; | |
109 | ||
110 | /* Array of types seen so far in top-level call to `build_mangled_name'. | |
111 | Allocated and deallocated by caller. */ | |
112 | static varray_type typevec; | |
113 | ||
114 | /* Number of types interned by `build_mangled_name' so far. */ | |
115 | static size_t maxtype; | |
116 | ||
117 | /* Called once to initialize method.c. */ | |
118 | ||
8d08fdba MS |
119 | void |
120 | init_method () | |
121 | { | |
122 | gcc_obstack_init (&scratch_obstack); | |
123 | scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0); | |
9cd64686 MM |
124 | ggc_add_tree_varray_root (&btypelist, 1); |
125 | ggc_add_tree_varray_root (&ktypelist, 1); | |
126 | ggc_add_tree_varray_root (&typevec, 1); | |
8d08fdba MS |
127 | } |
128 | ||
129 | /* This must be large enough to hold any printed integer or floating-point | |
130 | value. */ | |
131 | static char digit_buffer[128]; | |
132 | ||
133 | /* Move inline function definitions out of structure so that they | |
134 | can be processed normally. CNAME is the name of the class | |
135 | we are working from, METHOD_LIST is the list of method lists | |
136 | of the structure. We delete friend methods here, after | |
137 | saving away their inline function definitions (if any). */ | |
138 | ||
139 | void | |
140 | do_inline_function_hair (type, friend_list) | |
141 | tree type, friend_list; | |
142 | { | |
143 | tree method = TYPE_METHODS (type); | |
144 | ||
145 | if (method && TREE_CODE (method) == TREE_VEC) | |
146 | { | |
fc378698 MS |
147 | if (TREE_VEC_ELT (method, 1)) |
148 | method = TREE_VEC_ELT (method, 1); | |
149 | else if (TREE_VEC_ELT (method, 0)) | |
8d08fdba MS |
150 | method = TREE_VEC_ELT (method, 0); |
151 | else | |
fc378698 | 152 | method = TREE_VEC_ELT (method, 2); |
8d08fdba MS |
153 | } |
154 | ||
155 | while (method) | |
156 | { | |
157 | /* Do inline member functions. */ | |
158 | struct pending_inline *info = DECL_PENDING_INLINE_INFO (method); | |
159 | if (info) | |
160 | { | |
161 | tree args; | |
162 | ||
163 | my_friendly_assert (info->fndecl == method, 238); | |
164 | args = DECL_ARGUMENTS (method); | |
165 | while (args) | |
166 | { | |
167 | DECL_CONTEXT (args) = method; | |
168 | args = TREE_CHAIN (args); | |
169 | } | |
8d08fdba MS |
170 | } |
171 | method = TREE_CHAIN (method); | |
172 | } | |
173 | while (friend_list) | |
174 | { | |
175 | tree fndecl = TREE_VALUE (friend_list); | |
176 | struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl); | |
177 | if (info) | |
178 | { | |
179 | tree args; | |
180 | ||
181 | my_friendly_assert (info->fndecl == fndecl, 239); | |
182 | args = DECL_ARGUMENTS (fndecl); | |
183 | while (args) | |
184 | { | |
185 | DECL_CONTEXT (args) = fndecl; | |
186 | args = TREE_CHAIN (args); | |
187 | } | |
8d08fdba MS |
188 | } |
189 | ||
190 | friend_list = TREE_CHAIN (friend_list); | |
191 | } | |
192 | } | |
193 | \f | |
8d08fdba MS |
194 | /* Here is where overload code starts. */ |
195 | ||
8d08fdba MS |
196 | /* Nonzero if we should not try folding parameter types. */ |
197 | static int nofold; | |
198 | ||
ed22c95e AM |
199 | /* This appears to be set to true if an underscore is required to be |
200 | comcatenated before another number can be outputed. */ | |
201 | static int numeric_output_need_bar; | |
8d08fdba | 202 | |
ed22c95e AM |
203 | static __inline void |
204 | start_squangling () | |
205 | { | |
206 | if (flag_do_squangling) | |
207 | { | |
ed22c95e | 208 | nofold = 0; |
ed22c95e AM |
209 | maxbtype = 0; |
210 | maxktype = 0; | |
9cd64686 MM |
211 | VARRAY_TREE_INIT (btypelist, 50, "btypelist"); |
212 | VARRAY_TREE_INIT (ktypelist, 50, "ktypelist"); | |
ed22c95e AM |
213 | } |
214 | } | |
215 | ||
216 | static __inline void | |
217 | end_squangling () | |
218 | { | |
219 | if (flag_do_squangling) | |
220 | { | |
9cd64686 MM |
221 | VARRAY_FREE (ktypelist); |
222 | VARRAY_FREE (btypelist); | |
ed22c95e AM |
223 | maxbtype = 0; |
224 | maxktype = 0; | |
ed22c95e AM |
225 | } |
226 | } | |
8d08fdba MS |
227 | |
228 | /* Code to concatenate an asciified integer to a string. */ | |
e92cc029 | 229 | |
ed22c95e | 230 | static __inline void |
8d08fdba | 231 | icat (i) |
bd6dd845 | 232 | HOST_WIDE_INT i; |
8d08fdba | 233 | { |
bd6dd845 MS |
234 | unsigned HOST_WIDE_INT ui; |
235 | ||
8d08fdba | 236 | /* Handle this case first, to go really quickly. For many common values, |
bd6dd845 | 237 | the result of ui/10 below is 1. */ |
8d08fdba MS |
238 | if (i == 1) |
239 | { | |
240 | OB_PUTC ('1'); | |
241 | return; | |
242 | } | |
243 | ||
bd6dd845 MS |
244 | if (i >= 0) |
245 | ui = i; | |
246 | else | |
8d08fdba MS |
247 | { |
248 | OB_PUTC ('m'); | |
bd6dd845 MS |
249 | ui = -i; |
250 | } | |
251 | ||
252 | if (ui >= 10) | |
253 | icat (ui / 10); | |
254 | ||
255 | OB_PUTC ('0' + (ui % 10)); | |
256 | } | |
257 | ||
258 | static void | |
259 | dicat (lo, hi) | |
260 | HOST_WIDE_INT lo, hi; | |
261 | { | |
262 | unsigned HOST_WIDE_INT ulo, uhi, qlo, qhi; | |
263 | ||
264 | if (hi >= 0) | |
265 | { | |
266 | uhi = hi; | |
267 | ulo = lo; | |
8d08fdba | 268 | } |
8d08fdba MS |
269 | else |
270 | { | |
bd6dd845 MS |
271 | uhi = (lo == 0 ? -hi : -hi-1); |
272 | ulo = -lo; | |
273 | } | |
274 | if (uhi == 0 | |
275 | && ulo < ((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1))) | |
276 | { | |
277 | icat (ulo); | |
278 | return; | |
8d08fdba | 279 | } |
bd6dd845 MS |
280 | /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */ |
281 | qhi = uhi / 10; | |
282 | uhi = uhi % 10; | |
283 | qlo = uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) / 5); | |
284 | qlo += ulo / 10; | |
285 | ulo = ulo % 10; | |
286 | ulo += uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) % 5) | |
287 | * 2; | |
288 | qlo += ulo / 10; | |
289 | ulo = ulo % 10; | |
290 | /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */ | |
291 | dicat (qlo, qhi); | |
292 | OB_PUTC ('0' + ulo); | |
8d08fdba MS |
293 | } |
294 | ||
f921acee | 295 | /* Returns the index of TYPE in the typevec, or -1 if it's not there. */ |
407f03b8 JM |
296 | |
297 | static __inline int | |
f921acee | 298 | old_backref_index (type) |
8d08fdba MS |
299 | tree type; |
300 | { | |
9cd64686 | 301 | size_t tindex; |
8d08fdba | 302 | |
407f03b8 | 303 | if (! is_back_referenceable_type (type)) |
f921acee | 304 | return -1; |
8d08fdba | 305 | |
407f03b8 JM |
306 | /* The entry for this parm is at maxtype-1, so don't look there for |
307 | something to repeat. */ | |
308 | for (tindex = 0; tindex < maxtype - 1; ++tindex) | |
9cd64686 | 309 | if (same_type_p (VARRAY_TREE (typevec, tindex), type)) |
407f03b8 JM |
310 | break; |
311 | ||
312 | if (tindex == maxtype - 1) | |
f921acee JM |
313 | return -1; |
314 | ||
315 | return tindex; | |
316 | } | |
317 | ||
318 | /* Old mangling style: If TYPE has already been used in the parameter list, | |
319 | emit a backward reference and return non-zero; otherwise, return 0. | |
320 | ||
321 | NREPEATS is the number of repeats we've recorded of this type, or 0 if | |
322 | this is the first time we've seen it and we're just looking to see if | |
323 | it had been used before. */ | |
324 | ||
325 | static __inline int | |
326 | flush_repeats (nrepeats, type) | |
327 | int nrepeats; | |
328 | tree type; | |
329 | { | |
330 | int tindex = old_backref_index (type); | |
331 | ||
332 | if (tindex == -1) | |
333 | { | |
334 | my_friendly_assert (nrepeats == 0, 990316); | |
335 | return 0; | |
336 | } | |
407f03b8 | 337 | |
f921acee JM |
338 | if (nrepeats > 1) |
339 | { | |
340 | OB_PUTC ('N'); | |
341 | icat (nrepeats); | |
342 | if (nrepeats > 9) | |
343 | OB_PUTC ('_'); | |
344 | } | |
345 | else | |
346 | OB_PUTC ('T'); | |
8d08fdba MS |
347 | icat (tindex); |
348 | if (tindex > 9) | |
349 | OB_PUTC ('_'); | |
407f03b8 JM |
350 | |
351 | return 1; | |
8d08fdba MS |
352 | } |
353 | ||
59e621fc MM |
354 | /* Returns nonzero iff this is a type to which we will want to make |
355 | back-references (using the `B' code). */ | |
ed22c95e | 356 | |
e9659ab0 | 357 | static int |
59e621fc MM |
358 | is_back_referenceable_type (type) |
359 | tree type; | |
ed22c95e | 360 | { |
407f03b8 JM |
361 | /* For some reason, the Java folks don't want back refs on these. */ |
362 | if (TYPE_FOR_JAVA (type)) | |
59e621fc MM |
363 | return 0; |
364 | ||
365 | switch (TREE_CODE (type)) | |
ed22c95e | 366 | { |
9223feaa MM |
367 | case BOOLEAN_TYPE: |
368 | if (!flag_do_squangling) | |
369 | /* Even though the mangling of this is just `b', we did | |
370 | historically generate back-references for it. */ | |
371 | return 1; | |
372 | /* Fall through. */ | |
373 | ||
59e621fc MM |
374 | case INTEGER_TYPE: |
375 | case REAL_TYPE: | |
376 | case VOID_TYPE: | |
59e621fc MM |
377 | /* These types have single-character manglings, so there's no |
378 | point in generating back-references. */ | |
379 | return 0; | |
380 | ||
381 | case TEMPLATE_TYPE_PARM: | |
382 | /* It would be a bit complex to demangle signatures correctly if | |
383 | we generated back-references to these, and the manglings of | |
384 | type parameters are short. */ | |
385 | return 0; | |
386 | ||
387 | default: | |
388 | return 1; | |
ed22c95e | 389 | } |
ed22c95e AM |
390 | } |
391 | ||
59e621fc MM |
392 | /* Issue the squangling code indicating NREPEATS repetitions of TYPE, |
393 | which was the last parameter type output. */ | |
394 | ||
395 | static void | |
396 | issue_nrepeats (nrepeats, type) | |
397 | int nrepeats; | |
398 | tree type; | |
399 | { | |
400 | if (nrepeats == 1 && !is_back_referenceable_type (type)) | |
401 | /* For types whose manglings are short, don't bother using the | |
402 | repetition code if there's only one repetition, since the | |
403 | repetition code will be about as long as the ordinary mangling. */ | |
404 | build_mangled_name_for_type (type); | |
405 | else | |
406 | { | |
407 | OB_PUTC ('n'); | |
408 | icat (nrepeats); | |
409 | if (nrepeats > 9) | |
410 | OB_PUTC ('_'); | |
411 | } | |
412 | } | |
ed22c95e | 413 | |
407f03b8 JM |
414 | /* Check to see if a tree node has been entered into the Kcode typelist. |
415 | If not, add it. Returns -1 if it isn't found, otherwise returns the | |
416 | index. */ | |
417 | ||
ed22c95e AM |
418 | static int |
419 | check_ktype (node, add) | |
420 | tree node; | |
421 | int add; | |
422 | { | |
9cd64686 | 423 | size_t x; |
ed22c95e AM |
424 | tree localnode = node; |
425 | ||
426 | if (ktypelist == NULL) | |
427 | return -1; | |
428 | ||
429 | if (TREE_CODE (node) == TYPE_DECL) | |
430 | localnode = TREE_TYPE (node); | |
431 | ||
9cd64686 | 432 | for (x = 0; x < maxktype; x++) |
ed22c95e | 433 | { |
9cd64686 | 434 | if (same_type_p (localnode, VARRAY_TREE (ktypelist, x))) |
407f03b8 | 435 | return x; |
ed22c95e | 436 | } |
407f03b8 | 437 | /* Didn't find it, so add it here. */ |
ed22c95e AM |
438 | if (add) |
439 | { | |
9cd64686 MM |
440 | if (VARRAY_SIZE (ktypelist) <= maxktype) |
441 | VARRAY_GROW (ktypelist, | |
442 | VARRAY_SIZE (ktypelist) * 3 / 2); | |
443 | VARRAY_TREE (ktypelist, maxktype) = localnode; | |
444 | maxktype++; | |
ed22c95e AM |
445 | } |
446 | return -1; | |
447 | } | |
448 | ||
449 | ||
450 | static __inline int | |
451 | issue_ktype (decl) | |
452 | tree decl; | |
453 | { | |
454 | int kindex; | |
455 | kindex = check_ktype (decl, FALSE); | |
456 | if (kindex != -1) | |
457 | { | |
458 | OB_PUTC ('K'); | |
459 | icat (kindex); | |
460 | if (kindex > 9) | |
461 | OB_PUTC ('_'); | |
462 | return TRUE; | |
463 | } | |
464 | return FALSE; | |
465 | } | |
59e621fc MM |
466 | |
467 | /* Build a representation for DECL, which may be an entity not at | |
468 | global scope. If so, a marker indicating that the name is | |
469 | qualified has already been output, but the qualifying context has | |
470 | not. */ | |
8d08fdba MS |
471 | |
472 | static void | |
db5ae43f MS |
473 | build_overload_nested_name (decl) |
474 | tree decl; | |
8d08fdba | 475 | { |
cb0dbb9a JM |
476 | tree context; |
477 | ||
ed22c95e AM |
478 | if (ktypelist && issue_ktype (decl)) |
479 | return; | |
480 | ||
2c73f9f5 ML |
481 | if (decl == global_namespace) |
482 | return; | |
483 | ||
cb0dbb9a JM |
484 | context = CP_DECL_CONTEXT (decl); |
485 | ||
486 | /* try to issue a K type, and if we can't continue the normal path */ | |
487 | if (!(ktypelist && issue_ktype (context))) | |
488 | { | |
489 | /* For a template type parameter, we want to output an 'Xn' | |
490 | rather than 'T' or some such. */ | |
491 | if (TREE_CODE (context) == TEMPLATE_TYPE_PARM | |
492 | || TREE_CODE (context) == TEMPLATE_TEMPLATE_PARM) | |
59e621fc | 493 | build_mangled_name_for_type (context); |
cb0dbb9a | 494 | else |
8d08fdba | 495 | { |
cb0dbb9a JM |
496 | if (TREE_CODE_CLASS (TREE_CODE (context)) == 't') |
497 | context = TYPE_NAME (context); | |
498 | build_overload_nested_name (context); | |
8d08fdba | 499 | } |
cb0dbb9a | 500 | } |
ed22c95e | 501 | |
db5ae43f MS |
502 | if (TREE_CODE (decl) == FUNCTION_DECL) |
503 | { | |
504 | tree name = DECL_ASSEMBLER_NAME (decl); | |
505 | char *label; | |
db5ae43f | 506 | |
42976354 BK |
507 | ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), static_labelno); |
508 | static_labelno++; | |
db5ae43f | 509 | |
8cb9cd5d | 510 | if (numeric_output_need_bar) |
42976354 | 511 | OB_PUTC ('_'); |
db5ae43f MS |
512 | icat (strlen (label)); |
513 | OB_PUTCP (label); | |
42976354 | 514 | numeric_output_need_bar = 1; |
db5ae43f | 515 | } |
30394414 JM |
516 | else if (TREE_CODE (decl) == NAMESPACE_DECL) |
517 | build_overload_identifier (DECL_NAME (decl)); | |
db5ae43f | 518 | else /* TYPE_DECL */ |
5566b478 | 519 | build_overload_identifier (decl); |
8d08fdba MS |
520 | } |
521 | ||
59e621fc MM |
522 | /* Output the decimal representation of I. If I > 9, the decimal |
523 | representation is preceeded and followed by an underscore. */ | |
524 | ||
386b8a85 | 525 | static void |
c8907853 JL |
526 | build_underscore_int (i) |
527 | int i; | |
386b8a85 JM |
528 | { |
529 | if (i > 9) | |
530 | OB_PUTC ('_'); | |
531 | icat (i); | |
532 | if (i > 9) | |
c32381b1 | 533 | OB_PUTC ('_'); |
386b8a85 JM |
534 | } |
535 | ||
050367a3 MM |
536 | static void |
537 | build_overload_scope_ref (value) | |
538 | tree value; | |
539 | { | |
540 | OB_PUTC2 ('Q', '2'); | |
541 | numeric_output_need_bar = 0; | |
59e621fc | 542 | build_mangled_name_for_type (TREE_OPERAND (value, 0)); |
050367a3 MM |
543 | build_overload_identifier (TREE_OPERAND (value, 1)); |
544 | } | |
545 | ||
e92cc029 MS |
546 | /* Encoding for an INTEGER_CST value. */ |
547 | ||
e1b7b0cb | 548 | static void |
37dac039 | 549 | build_overload_int (value, in_template) |
e1b7b0cb | 550 | tree value; |
37dac039 | 551 | int in_template; |
e1b7b0cb | 552 | { |
2636fde4 | 553 | if (in_template && TREE_CODE (value) != INTEGER_CST) |
5566b478 | 554 | { |
050367a3 MM |
555 | if (TREE_CODE (value) == SCOPE_REF) |
556 | { | |
557 | build_overload_scope_ref (value); | |
558 | return; | |
559 | } | |
560 | ||
561 | OB_PUTC ('E'); | |
562 | numeric_output_need_bar = 0; | |
563 | ||
564 | if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value)))) | |
565 | { | |
566 | int i; | |
567 | int operands = tree_code_length[(int) TREE_CODE (value)]; | |
568 | tree id; | |
9c0758dd | 569 | const char *name; |
050367a3 MM |
570 | |
571 | id = ansi_opname [(int) TREE_CODE (value)]; | |
572 | my_friendly_assert (id != NULL_TREE, 0); | |
573 | name = IDENTIFIER_POINTER (id); | |
67ffc812 MM |
574 | if (name[0] != '_' || name[1] != '_') |
575 | /* On some erroneous inputs, we can get here with VALUE a | |
576 | LOOKUP_EXPR. In that case, the NAME will be the | |
577 | identifier for "<invalid operator>". We must survive | |
578 | this routine in order to issue a sensible error | |
579 | message, so we fall through to the case below. */ | |
580 | goto bad_value; | |
050367a3 MM |
581 | |
582 | for (i = 0; i < operands; ++i) | |
583 | { | |
584 | tree operand; | |
585 | enum tree_code tc; | |
586 | ||
587 | /* We just outputted either the `E' or the name of the | |
588 | operator. */ | |
589 | numeric_output_need_bar = 0; | |
590 | ||
591 | if (i != 0) | |
592 | /* Skip the leading underscores. */ | |
593 | OB_PUTCP (name + 2); | |
594 | ||
595 | operand = TREE_OPERAND (value, i); | |
596 | tc = TREE_CODE (operand); | |
597 | ||
598 | if (TREE_CODE_CLASS (tc) == 't') | |
599 | /* We can get here with sizeof, e.g.: | |
600 | ||
601 | template <class T> void f(A<sizeof(T)>); */ | |
59e621fc | 602 | build_mangled_name_for_type (operand); |
050367a3 MM |
603 | else if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (tc))) |
604 | build_overload_int (operand, in_template); | |
605 | else | |
606 | build_overload_value (TREE_TYPE (operand), | |
607 | operand, | |
608 | in_template); | |
609 | } | |
610 | } | |
611 | else | |
612 | { | |
613 | /* We don't ever want this output, but it's | |
614 | inconvenient not to be able to build the string. | |
615 | This should cause assembler errors we'll notice. */ | |
616 | ||
617 | static int n; | |
67ffc812 | 618 | bad_value: |
050367a3 MM |
619 | sprintf (digit_buffer, " *%d", n++); |
620 | OB_PUTCP (digit_buffer); | |
621 | } | |
622 | ||
623 | OB_PUTC ('W'); | |
624 | numeric_output_need_bar = 0; | |
5566b478 MS |
625 | return; |
626 | } | |
627 | ||
e1b7b0cb | 628 | my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243); |
5156628f | 629 | if (TYPE_PRECISION (TREE_TYPE (value)) == 2 * HOST_BITS_PER_WIDE_INT) |
e1b7b0cb | 630 | { |
e1b7b0cb RK |
631 | if (TREE_INT_CST_HIGH (value) |
632 | != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1))) | |
633 | { | |
634 | /* need to print a DImode value in decimal */ | |
bd6dd845 | 635 | dicat (TREE_INT_CST_LOW (value), TREE_INT_CST_HIGH (value)); |
050367a3 | 636 | numeric_output_need_bar = 1; |
bd6dd845 | 637 | return; |
e1b7b0cb RK |
638 | } |
639 | /* else fall through to print in smaller mode */ | |
640 | } | |
641 | /* Wordsize or smaller */ | |
642 | icat (TREE_INT_CST_LOW (value)); | |
050367a3 | 643 | numeric_output_need_bar = 1; |
e1b7b0cb RK |
644 | } |
645 | ||
f84b4be9 JM |
646 | |
647 | /* Output S followed by a representation of the TEMPLATE_PARM_INDEX | |
648 | supplied in INDEX. */ | |
649 | ||
650 | static void | |
651 | build_mangled_template_parm_index (s, index) | |
9c0758dd | 652 | const char *s; |
f84b4be9 JM |
653 | tree index; |
654 | { | |
655 | OB_PUTCP (s); | |
656 | build_underscore_int (TEMPLATE_PARM_IDX (index)); | |
657 | /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a | |
658 | representation of the function from the point of view of its | |
659 | type. */ | |
660 | build_underscore_int (TEMPLATE_PARM_LEVEL (index)); | |
661 | } | |
662 | ||
663 | ||
25f3d2f4 BK |
664 | /* Mangling for C9X integer types (and Cygnus extensions for 128-bit |
665 | and other types) is based on the letter "I" followed by the hex | |
666 | representations of the bitsize for the type in question. For | |
667 | encodings that result in larger than two digits, a leading and | |
668 | trailing underscore is added. | |
669 | ||
670 | Thus: | |
671 | int1_t = 001 = I01 | |
672 | int8_t = 008 = I08 | |
673 | int16_t = 010 = I10 | |
674 | int24_t = 018 = I18 | |
675 | int32_t = 020 = I20 | |
676 | int64_t = 040 = I40 | |
677 | int80_t = 050 = I50 | |
678 | int128_t = 080 = I80 | |
679 | int256_t = 100 = I_100_ | |
680 | int512_t = 200 = I_200_ | |
681 | ||
682 | Given an integer in decimal format, mangle according to this scheme. */ | |
683 | ||
e833cb11 | 684 | #if HOST_BITS_PER_WIDE_INT >= 64 |
25f3d2f4 BK |
685 | static void |
686 | build_mangled_C9x_name (bits) | |
687 | int bits; | |
688 | { | |
689 | char mangled[10] = ""; | |
690 | ||
691 | if (bits > 255) | |
692 | sprintf (mangled, "I_%x_", bits); | |
693 | else | |
694 | sprintf (mangled, "I%.2x", bits); | |
695 | ||
696 | OB_PUTCP (mangled); | |
697 | } | |
e833cb11 | 698 | #endif |
25f3d2f4 | 699 | |
8d08fdba | 700 | static void |
37dac039 | 701 | build_overload_value (type, value, in_template) |
8d08fdba | 702 | tree type, value; |
37dac039 | 703 | int in_template; |
8d08fdba | 704 | { |
61a127b3 MM |
705 | my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type)) == 't', 0); |
706 | ||
8d08fdba MS |
707 | while (TREE_CODE (value) == NON_LVALUE_EXPR |
708 | || TREE_CODE (value) == NOP_EXPR) | |
709 | value = TREE_OPERAND (value, 0); | |
050367a3 | 710 | |
e1b7b0cb RK |
711 | if (numeric_output_need_bar) |
712 | { | |
713 | OB_PUTC ('_'); | |
714 | numeric_output_need_bar = 0; | |
715 | } | |
716 | ||
f84b4be9 | 717 | if (TREE_CODE (value) == TEMPLATE_PARM_INDEX) |
2636fde4 | 718 | { |
f84b4be9 | 719 | build_mangled_template_parm_index ("Y", value); |
2636fde4 JM |
720 | return; |
721 | } | |
722 | ||
61a127b3 | 723 | if (TYPE_PTRMEM_P (type)) |
8145f082 | 724 | { |
61a127b3 MM |
725 | if (TREE_CODE (value) != PTRMEM_CST) |
726 | /* We should have already rejected this pointer to member, | |
727 | since it is not a constant. */ | |
728 | my_friendly_abort (0); | |
729 | ||
730 | /* Get the actual FIELD_DECL. */ | |
731 | value = PTRMEM_CST_MEMBER (value); | |
732 | my_friendly_assert (TREE_CODE (value) == FIELD_DECL, 0); | |
733 | ||
734 | /* Output the name of the field. */ | |
735 | build_overload_identifier (DECL_NAME (value)); | |
736 | return; | |
8145f082 MS |
737 | } |
738 | ||
8d08fdba MS |
739 | switch (TREE_CODE (type)) |
740 | { | |
741 | case INTEGER_TYPE: | |
742 | case ENUMERAL_TYPE: | |
2986ae00 MS |
743 | case BOOLEAN_TYPE: |
744 | { | |
37dac039 | 745 | build_overload_int (value, in_template); |
2986ae00 MS |
746 | return; |
747 | } | |
8d08fdba MS |
748 | case REAL_TYPE: |
749 | { | |
750 | REAL_VALUE_TYPE val; | |
751 | char *bufp = digit_buffer; | |
8d08fdba | 752 | |
8251199e | 753 | pedwarn ("ANSI C++ forbids floating-point template arguments"); |
bd6dd845 | 754 | |
8d08fdba MS |
755 | my_friendly_assert (TREE_CODE (value) == REAL_CST, 244); |
756 | val = TREE_REAL_CST (value); | |
bd6dd845 | 757 | if (REAL_VALUE_ISNAN (val)) |
8d08fdba | 758 | { |
bd6dd845 | 759 | sprintf (bufp, "NaN"); |
8d08fdba | 760 | } |
8d08fdba MS |
761 | else |
762 | { | |
bd6dd845 | 763 | if (REAL_VALUE_NEGATIVE (val)) |
8d08fdba | 764 | { |
bd6dd845 | 765 | val = REAL_VALUE_NEGATE (val); |
8d08fdba MS |
766 | *bufp++ = 'm'; |
767 | } | |
bd6dd845 | 768 | if (REAL_VALUE_ISINF (val)) |
8d08fdba | 769 | { |
bd6dd845 | 770 | sprintf (bufp, "Infinity"); |
8d08fdba | 771 | } |
bd6dd845 | 772 | else |
8d08fdba | 773 | { |
3d015f46 | 774 | REAL_VALUE_TO_DECIMAL (val, "%.20e", bufp); |
bd6dd845 MS |
775 | bufp = (char *) index (bufp, 'e'); |
776 | if (!bufp) | |
777 | strcat (digit_buffer, "e0"); | |
778 | else | |
779 | { | |
780 | char *p; | |
781 | bufp++; | |
782 | if (*bufp == '-') | |
783 | { | |
784 | *bufp++ = 'm'; | |
785 | } | |
786 | p = bufp; | |
787 | if (*p == '+') | |
788 | p++; | |
789 | while (*p == '0') | |
790 | p++; | |
791 | if (*p == 0) | |
792 | { | |
793 | *bufp++ = '0'; | |
794 | *bufp = 0; | |
795 | } | |
796 | else if (p != bufp) | |
797 | { | |
798 | while (*p) | |
799 | *bufp++ = *p++; | |
800 | *bufp = 0; | |
801 | } | |
802 | } | |
803 | #ifdef NO_DOT_IN_LABEL | |
804 | bufp = (char *) index (bufp, '.'); | |
805 | if (bufp) | |
806 | *bufp = '_'; | |
807 | #endif | |
8d08fdba MS |
808 | } |
809 | } | |
810 | OB_PUTCP (digit_buffer); | |
e1b7b0cb | 811 | numeric_output_need_bar = 1; |
8d08fdba MS |
812 | return; |
813 | } | |
8d08fdba | 814 | case POINTER_TYPE: |
f84b4be9 | 815 | if (TREE_CODE (value) == INTEGER_CST) |
f30432d7 | 816 | { |
37dac039 | 817 | build_overload_int (value, in_template); |
f30432d7 MS |
818 | return; |
819 | } | |
f84b4be9 JM |
820 | else if (TREE_CODE (value) == TEMPLATE_PARM_INDEX) |
821 | { | |
822 | build_mangled_template_parm_index ("", value); | |
823 | numeric_output_need_bar = 1; | |
824 | return; | |
825 | } | |
826 | ||
8d08fdba | 827 | value = TREE_OPERAND (value, 0); |
5c0aa6d0 MM |
828 | |
829 | /* Fall through. */ | |
830 | ||
831 | case REFERENCE_TYPE: | |
8d08fdba MS |
832 | if (TREE_CODE (value) == VAR_DECL) |
833 | { | |
834 | my_friendly_assert (DECL_NAME (value) != 0, 245); | |
e76a2646 | 835 | build_overload_identifier (DECL_ASSEMBLER_NAME (value)); |
8d08fdba MS |
836 | return; |
837 | } | |
838 | else if (TREE_CODE (value) == FUNCTION_DECL) | |
839 | { | |
840 | my_friendly_assert (DECL_NAME (value) != 0, 246); | |
e76a2646 | 841 | build_overload_identifier (DECL_ASSEMBLER_NAME (value)); |
8d08fdba MS |
842 | return; |
843 | } | |
aa36c081 | 844 | else if (TREE_CODE (value) == SCOPE_REF) |
050367a3 | 845 | build_overload_scope_ref (value); |
8d08fdba MS |
846 | else |
847 | my_friendly_abort (71); | |
848 | break; /* not really needed */ | |
849 | ||
e08a8f45 MM |
850 | case RECORD_TYPE: |
851 | { | |
852 | tree delta; | |
853 | tree idx; | |
854 | tree pfn; | |
855 | tree delta2; | |
856 | ||
857 | my_friendly_assert (TYPE_PTRMEMFUNC_P (type), 0); | |
82bed870 MM |
858 | |
859 | /* We'll get a ADDR_EXPR of a SCOPE_REF here if we're | |
860 | mangling, an instantiation of something like: | |
861 | ||
862 | template <class T, void (T::*fp)()> class C {}; | |
863 | template <class T> C<T, &T::f> x(); | |
864 | ||
865 | We mangle the return type of the function, and that | |
866 | contains template parameters. */ | |
867 | if (TREE_CODE (value) == ADDR_EXPR | |
868 | && TREE_CODE (TREE_OPERAND (value, 0)) == SCOPE_REF) | |
869 | { | |
870 | build_overload_scope_ref (TREE_OPERAND (value, 0)); | |
871 | break; | |
872 | } | |
873 | ||
e08a8f45 MM |
874 | my_friendly_assert (TREE_CODE (value) == PTRMEM_CST, 0); |
875 | ||
876 | expand_ptrmemfunc_cst (value, &delta, &idx, &pfn, &delta2); | |
877 | build_overload_int (delta, in_template); | |
878 | OB_PUTC ('_'); | |
879 | build_overload_int (idx, in_template); | |
880 | OB_PUTC ('_'); | |
881 | if (pfn) | |
882 | { | |
883 | numeric_output_need_bar = 0; | |
884 | build_overload_identifier (DECL_ASSEMBLER_NAME | |
885 | (PTRMEM_CST_MEMBER (value))); | |
886 | } | |
887 | else | |
888 | { | |
889 | OB_PUTC ('i'); | |
890 | build_overload_int (delta2, in_template); | |
891 | } | |
892 | } | |
893 | break; | |
894 | ||
8d08fdba MS |
895 | default: |
896 | sorry ("conversion of %s as template parameter", | |
897 | tree_code_name [(int) TREE_CODE (type)]); | |
898 | my_friendly_abort (72); | |
899 | } | |
900 | } | |
901 | ||
386b8a85 | 902 | |
73b0fce8 | 903 | /* Add encodings for the declaration of template template parameters. |
407f03b8 | 904 | PARMLIST must be a TREE_VEC. */ |
73b0fce8 KL |
905 | |
906 | static void | |
907 | build_template_template_parm_names (parmlist) | |
908 | tree parmlist; | |
909 | { | |
910 | int i, nparms; | |
911 | ||
912 | my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 246.5); | |
913 | nparms = TREE_VEC_LENGTH (parmlist); | |
914 | icat (nparms); | |
915 | for (i = 0; i < nparms; i++) | |
916 | { | |
917 | tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i)); | |
918 | if (TREE_CODE (parm) == TYPE_DECL) | |
919 | { | |
920 | /* This parameter is a type. */ | |
921 | OB_PUTC ('Z'); | |
922 | } | |
923 | else if (TREE_CODE (parm) == TEMPLATE_DECL) | |
924 | { | |
925 | /* This parameter is a template. */ | |
926 | OB_PUTC ('z'); | |
927 | build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm)); | |
928 | } | |
929 | else | |
59e621fc MM |
930 | /* It's a PARM_DECL. */ |
931 | build_mangled_name_for_type (TREE_TYPE (parm)); | |
73b0fce8 KL |
932 | } |
933 | } | |
934 | ||
935 | ||
386b8a85 JM |
936 | /* Add encodings for the vector of template parameters in PARMLIST, |
937 | given the vector of arguments to be substituted in ARGLIST. */ | |
938 | ||
4966381a | 939 | static void |
386b8a85 JM |
940 | build_template_parm_names (parmlist, arglist) |
941 | tree parmlist; | |
942 | tree arglist; | |
943 | { | |
944 | int i, nparms; | |
e4a84209 MM |
945 | tree inner_args = innermost_args (arglist); |
946 | ||
386b8a85 JM |
947 | nparms = TREE_VEC_LENGTH (parmlist); |
948 | icat (nparms); | |
949 | for (i = 0; i < nparms; i++) | |
950 | { | |
951 | tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i)); | |
e4a84209 | 952 | tree arg = TREE_VEC_ELT (inner_args, i); |
386b8a85 JM |
953 | if (TREE_CODE (parm) == TYPE_DECL) |
954 | { | |
955 | /* This parameter is a type. */ | |
956 | OB_PUTC ('Z'); | |
59e621fc | 957 | build_mangled_name_for_type (arg); |
386b8a85 | 958 | } |
73b0fce8 KL |
959 | else if (TREE_CODE (parm) == TEMPLATE_DECL) |
960 | { | |
407f03b8 | 961 | /* This parameter is a template. */ |
73b0fce8 | 962 | if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM) |
407f03b8 | 963 | /* Output parameter declaration, argument index and level. */ |
59e621fc | 964 | build_mangled_name_for_type (arg); |
73b0fce8 KL |
965 | else |
966 | { | |
967 | /* A TEMPLATE_DECL node, output the parameter declaration | |
968 | and template name */ | |
969 | ||
970 | OB_PUTC ('z'); | |
407f03b8 JM |
971 | build_template_template_parm_names |
972 | (DECL_INNERMOST_TEMPLATE_PARMS (parm)); | |
73b0fce8 KL |
973 | icat (IDENTIFIER_LENGTH (DECL_NAME (arg))); |
974 | OB_PUTID (DECL_NAME (arg)); | |
975 | } | |
976 | } | |
386b8a85 JM |
977 | else |
978 | { | |
4393e105 | 979 | parm = tsubst (parm, arglist, /*complain=*/1, NULL_TREE); |
386b8a85 | 980 | /* It's a PARM_DECL. */ |
59e621fc | 981 | build_mangled_name_for_type (TREE_TYPE (parm)); |
61a127b3 MM |
982 | build_overload_value (TREE_TYPE (parm), arg, |
983 | uses_template_parms (arglist)); | |
386b8a85 JM |
984 | } |
985 | } | |
986 | } | |
987 | ||
59e621fc MM |
988 | /* Output the representation for NAME, which is either a TYPE_DECL or |
989 | an IDENTIFIER. */ | |
386b8a85 | 990 | |
8d08fdba MS |
991 | static void |
992 | build_overload_identifier (name) | |
993 | tree name; | |
994 | { | |
5566b478 | 995 | if (TREE_CODE (name) == TYPE_DECL |
7ddedda4 | 996 | && CLASS_TYPE_P (TREE_TYPE (name)) |
5566b478 | 997 | && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name)) |
e1467ff2 | 998 | && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name))) |
3ebc5c52 MM |
999 | || (TREE_CODE (CP_DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE |
1000 | (TREE_TYPE (name)))) | |
e1467ff2 | 1001 | == FUNCTION_DECL))) |
8d08fdba | 1002 | { |
59e621fc | 1003 | /* NAME is the TYPE_DECL for a template specialization. */ |
8d08fdba | 1004 | tree template, parmlist, arglist, tname; |
e4a84209 MM |
1005 | template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name)); |
1006 | arglist = CLASSTYPE_TI_ARGS (TREE_TYPE (name)); | |
8d08fdba | 1007 | tname = DECL_NAME (template); |
98c1c668 | 1008 | parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template); |
8d08fdba MS |
1009 | OB_PUTC ('t'); |
1010 | icat (IDENTIFIER_LENGTH (tname)); | |
1011 | OB_PUTID (tname); | |
386b8a85 | 1012 | build_template_parm_names (parmlist, arglist); |
8d08fdba MS |
1013 | } |
1014 | else | |
1015 | { | |
5566b478 MS |
1016 | if (TREE_CODE (name) == TYPE_DECL) |
1017 | name = DECL_NAME (name); | |
8cb9cd5d | 1018 | if (numeric_output_need_bar) |
f376e137 MS |
1019 | { |
1020 | OB_PUTC ('_'); | |
8cb9cd5d | 1021 | numeric_output_need_bar = 0; |
f376e137 | 1022 | } |
8d08fdba MS |
1023 | icat (IDENTIFIER_LENGTH (name)); |
1024 | OB_PUTID (name); | |
1025 | } | |
1026 | } | |
1027 | ||
42976354 | 1028 | /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce |
ed22c95e | 1029 | the mangling for it. Used by build_mangled_name and build_static_name. */ |
42976354 BK |
1030 | |
1031 | static void | |
1032 | build_qualified_name (decl) | |
1033 | tree decl; | |
1034 | { | |
1035 | tree context; | |
1036 | int i = 1; | |
1037 | ||
1038 | if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't') | |
1039 | decl = TYPE_NAME (decl); | |
1040 | ||
1041 | /* If DECL_ASSEMBLER_NAME has been set properly, use it. */ | |
1042 | if (TREE_CODE (decl) == TYPE_DECL | |
ed22c95e | 1043 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) && !flag_do_squangling) |
42976354 | 1044 | { |
050367a3 MM |
1045 | tree id = DECL_ASSEMBLER_NAME (decl); |
1046 | OB_PUTID (id); | |
faa25e97 | 1047 | if (ISDIGIT (IDENTIFIER_POINTER (id) [IDENTIFIER_LENGTH (id) - 1])) |
050367a3 | 1048 | numeric_output_need_bar = 1; |
42976354 BK |
1049 | return; |
1050 | } | |
1051 | ||
1052 | context = decl; | |
407f03b8 | 1053 | /* If we can't find a Ktype, do it the hard way. */ |
ed22c95e | 1054 | if (check_ktype (context, FALSE) == -1) |
30394414 | 1055 | { |
407f03b8 JM |
1056 | /* Count type and namespace scopes. */ |
1057 | while (1) | |
30394414 | 1058 | { |
407f03b8 JM |
1059 | context = CP_DECL_CONTEXT (context); |
1060 | if (context == global_namespace) | |
1061 | break; | |
30394414 | 1062 | i += 1; |
407f03b8 JM |
1063 | if (check_ktype (context, FALSE) != -1) |
1064 | /* Found one! */ | |
30394414 JM |
1065 | break; |
1066 | if (TREE_CODE_CLASS (TREE_CODE (context)) == 't') | |
1067 | context = TYPE_NAME (context); | |
1068 | } | |
30394414 | 1069 | } |
42976354 BK |
1070 | |
1071 | if (i > 1) | |
1072 | { | |
1073 | OB_PUTC ('Q'); | |
050367a3 | 1074 | build_underscore_int (i); |
42976354 BK |
1075 | numeric_output_need_bar = 0; |
1076 | } | |
1077 | build_overload_nested_name (decl); | |
1078 | } | |
1079 | ||
59e621fc MM |
1080 | /* Output the mangled representation for TYPE. If EXTRA_GCODE is |
1081 | non-zero, mangled names for structure/union types are intentionally | |
1082 | mangled differently from the method described in the ARM. */ | |
1083 | ||
e9659ab0 | 1084 | static void |
59e621fc MM |
1085 | build_mangled_name_for_type_with_Gcode (type, extra_Gcode) |
1086 | tree type; | |
1087 | int extra_Gcode; | |
1088 | { | |
1089 | if (TYPE_PTRMEMFUNC_P (type)) | |
1090 | type = TYPE_PTRMEMFUNC_FN_TYPE (type); | |
59e621fc MM |
1091 | process_modifiers (type); |
1092 | process_overload_item (type, extra_Gcode); | |
1093 | } | |
1094 | ||
1095 | /* Like build_mangled_name_for_type_with_Gcode, but never outputs the | |
1096 | `G'. */ | |
1097 | ||
e9659ab0 | 1098 | static void |
59e621fc MM |
1099 | build_mangled_name_for_type (type) |
1100 | tree type; | |
1101 | { | |
1102 | build_mangled_name_for_type_with_Gcode (type, 0); | |
1103 | } | |
1104 | ||
8d08fdba MS |
1105 | /* Given a list of parameters in PARMTYPES, create an unambiguous |
1106 | overload string. Should distinguish any type that C (or C++) can | |
1107 | distinguish. I.e., pointers to functions are treated correctly. | |
1108 | ||
1109 | Caller must deal with whether a final `e' goes on the end or not. | |
1110 | ||
1111 | Any default conversions must take place before this function | |
1112 | is called. | |
1113 | ||
1114 | BEGIN and END control initialization and finalization of the | |
1115 | obstack where we build the string. */ | |
1116 | ||
1117 | char * | |
1118 | build_overload_name (parmtypes, begin, end) | |
1119 | tree parmtypes; | |
1120 | int begin, end; | |
1121 | { | |
ed22c95e AM |
1122 | char *ret; |
1123 | start_squangling (); | |
1124 | ret = build_mangled_name (parmtypes, begin, end); | |
1125 | end_squangling (); | |
1126 | return ret ; | |
1127 | } | |
1128 | ||
59e621fc MM |
1129 | /* Output the mangled representation for PARMTYPES. If PARMTYPES is a |
1130 | TREE_LIST, then it is a list of parameter types. Otherwise, | |
1131 | PARMTYPES must be a single type. */ | |
1132 | ||
ed22c95e AM |
1133 | static char * |
1134 | build_mangled_name (parmtypes, begin, end) | |
1135 | tree parmtypes; | |
1136 | int begin, end; | |
1137 | { | |
ed22c95e AM |
1138 | if (begin) |
1139 | OB_INIT (); | |
8d08fdba | 1140 | |
59e621fc MM |
1141 | if (TREE_CODE (parmtypes) != TREE_LIST) |
1142 | /* There is only one type. */ | |
1143 | build_mangled_name_for_type (parmtypes); | |
1144 | else | |
8d08fdba | 1145 | { |
59e621fc MM |
1146 | /* There are several types in a parameter list. */ |
1147 | int nrepeats = 0; | |
1148 | int old_style_repeats = !flag_do_squangling && !nofold && typevec; | |
1149 | tree last_type = NULL_TREE; | |
1150 | ||
1151 | for (; parmtypes && parmtypes != void_list_node; | |
1152 | parmtypes = TREE_CHAIN (parmtypes)) | |
1153 | { | |
407f03b8 JM |
1154 | /* We used to call canonical_type_variant here, but that isn't |
1155 | good enough; it doesn't handle pointers to typedef types. So | |
1156 | we can't just set TREE_USED to say we've seen a type already; | |
1157 | we have to check each of the earlier types with same_type_p. */ | |
1158 | tree parmtype = TREE_VALUE (parmtypes); | |
59e621fc MM |
1159 | |
1160 | if (old_style_repeats) | |
1161 | { | |
1162 | /* Every argument gets counted. */ | |
9cd64686 MM |
1163 | my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387); |
1164 | VARRAY_TREE (typevec, maxtype) = parmtype; | |
1165 | maxtype++; | |
59e621fc | 1166 | } |
f921acee JM |
1167 | |
1168 | if (last_type && same_type_p (parmtype, last_type)) | |
59e621fc | 1169 | { |
f921acee JM |
1170 | if (flag_do_squangling |
1171 | || (old_style_repeats | |
1172 | && is_back_referenceable_type (parmtype))) | |
59e621fc MM |
1173 | { |
1174 | /* The next type is the same as this one. Keep | |
1175 | track of the repetition, and output the repeat | |
1176 | count later. */ | |
1177 | nrepeats++; | |
1178 | continue; | |
1179 | } | |
f921acee JM |
1180 | } |
1181 | else if (nrepeats != 0) | |
1182 | { | |
1183 | /* Indicate how many times the previous parameter was | |
1184 | repeated. */ | |
1185 | if (old_style_repeats) | |
1186 | flush_repeats (nrepeats, last_type); | |
1187 | else | |
1188 | issue_nrepeats (nrepeats, last_type); | |
1189 | nrepeats = 0; | |
59e621fc | 1190 | } |
407f03b8 JM |
1191 | |
1192 | last_type = parmtype; | |
1193 | ||
f921acee JM |
1194 | /* Note that for bug-compatibility with 2.7.2, we can't build up |
1195 | repeats of types other than the most recent one. So we call | |
1196 | flush_repeats every round, if we get this far. */ | |
1197 | if (old_style_repeats && flush_repeats (0, parmtype)) | |
407f03b8 | 1198 | continue; |
59e621fc MM |
1199 | |
1200 | /* Output the PARMTYPE. */ | |
1201 | build_mangled_name_for_type_with_Gcode (parmtype, 1); | |
1202 | } | |
1203 | ||
1204 | /* Output the repeat count for the last parameter, if | |
1205 | necessary. */ | |
1206 | if (nrepeats != 0) | |
1207 | { | |
f921acee JM |
1208 | if (old_style_repeats) |
1209 | flush_repeats (nrepeats, last_type); | |
1210 | else | |
1211 | issue_nrepeats (nrepeats, last_type); | |
59e621fc MM |
1212 | nrepeats = 0; |
1213 | } | |
1214 | ||
1215 | if (!parmtypes) | |
1216 | /* The parameter list ends in an ellipsis. */ | |
1217 | OB_PUTC ('e'); | |
1218 | } | |
8d08fdba | 1219 | |
ed22c95e AM |
1220 | if (end) |
1221 | OB_FINISH (); | |
1222 | return (char *)obstack_base (&scratch_obstack); | |
1223 | } | |
8d08fdba | 1224 | |
8be64d09 JM |
1225 | /* Emit modifiers such as constant, read-only, and volatile. */ |
1226 | ||
e9659ab0 | 1227 | static void |
ed22c95e AM |
1228 | process_modifiers (parmtype) |
1229 | tree parmtype; | |
1230 | { | |
91063b51 MM |
1231 | /* Note that here we do not use CP_TYPE_CONST_P and friends because |
1232 | we describe types recursively; we will get the `const' in | |
1233 | `const int ()[10]' when processing the `const int' part. */ | |
1234 | if (TYPE_READONLY (parmtype)) | |
ed22c95e | 1235 | OB_PUTC ('C'); |
a1774733 | 1236 | if (TREE_CODE (parmtype) == INTEGER_TYPE |
8be64d09 JM |
1237 | && parmtype != char_type_node |
1238 | && parmtype != wchar_type_node | |
a1774733 BK |
1239 | && (TYPE_MAIN_VARIANT (parmtype) |
1240 | == unsigned_type (TYPE_MAIN_VARIANT (parmtype))) | |
ea419909 | 1241 | && ! TYPE_FOR_JAVA (parmtype)) |
59e621fc | 1242 | OB_PUTC ('U'); |
ed22c95e AM |
1243 | if (TYPE_VOLATILE (parmtype)) |
1244 | OB_PUTC ('V'); | |
91063b51 MM |
1245 | /* It would be better to use `R' for `restrict', but that's already |
1246 | used for reference types. And `r' is used for `long double'. */ | |
1247 | if (TYPE_RESTRICT (parmtype)) | |
1248 | OB_PUTC ('u'); | |
ed22c95e | 1249 | } |
a5894242 | 1250 | |
59e621fc MM |
1251 | /* Check to see if TYPE has been entered into the Bcode typelist. If |
1252 | so, return 1 and emit a backreference to TYPE. Otherwise, add TYPE | |
1253 | to the list of back-referenceable types and return 0. */ | |
1254 | ||
e9659ab0 | 1255 | static int |
59e621fc MM |
1256 | check_btype (type) |
1257 | tree type; | |
ed22c95e | 1258 | { |
9cd64686 | 1259 | size_t x; |
a5894242 | 1260 | |
ed22c95e AM |
1261 | if (btypelist == NULL) |
1262 | return 0; | |
8d08fdba | 1263 | |
59e621fc MM |
1264 | if (!is_back_referenceable_type (type)) |
1265 | return 0; | |
31bebb60 | 1266 | |
ed22c95e | 1267 | for (x = 0; x < maxbtype; x++) |
9cd64686 | 1268 | if (same_type_p (type, VARRAY_TREE (btypelist, x))) |
59e621fc MM |
1269 | { |
1270 | OB_PUTC ('B'); | |
1271 | icat (x); | |
1272 | if (x > 9) | |
1273 | OB_PUTC ('_'); | |
1274 | return 1 ; | |
1275 | } | |
1276 | ||
9cd64686 MM |
1277 | if (VARRAY_SIZE (btypelist) <= maxbtype) |
1278 | /* Enlarge the table. */ | |
1279 | VARRAY_GROW (btypelist, | |
1280 | VARRAY_SIZE (btypelist) * 3 / 2); | |
1281 | ||
59e621fc | 1282 | /* Register the TYPE. */ |
9cd64686 MM |
1283 | VARRAY_TREE (btypelist, maxbtype) = type; |
1284 | maxbtype++; | |
59e621fc | 1285 | |
ed22c95e AM |
1286 | return 0; |
1287 | } | |
8d08fdba | 1288 | |
8be64d09 JM |
1289 | /* Emit the correct code for various node types. */ |
1290 | ||
ed22c95e AM |
1291 | static void |
1292 | process_overload_item (parmtype, extra_Gcode) | |
1293 | tree parmtype; | |
1294 | int extra_Gcode; | |
1295 | { | |
59e621fc | 1296 | numeric_output_need_bar = 0; |
8d08fdba | 1297 | |
407f03b8 JM |
1298 | /* Our caller should have already handed any qualifiers, so pull out the |
1299 | TYPE_MAIN_VARIANT to avoid typedef confusion. Except we can't do that | |
1300 | for arrays, because they are transparent to qualifiers. Sigh. */ | |
1301 | if (TREE_CODE (parmtype) == ARRAY_TYPE) | |
1302 | parmtype = canonical_type_variant (parmtype); | |
1303 | else | |
1304 | parmtype = TYPE_MAIN_VARIANT (parmtype); | |
1305 | ||
8be64d09 JM |
1306 | /* These tree types are considered modifiers for B code squangling, |
1307 | and therefore should not get entries in the Btypelist. They are, | |
1308 | however, repeatable types. */ | |
8d08fdba | 1309 | |
ed22c95e AM |
1310 | switch (TREE_CODE (parmtype)) |
1311 | { | |
1312 | case REFERENCE_TYPE: | |
1313 | OB_PUTC ('R'); | |
1314 | goto more; | |
8d08fdba | 1315 | |
ed22c95e AM |
1316 | case ARRAY_TYPE: |
1317 | #if PARM_CAN_BE_ARRAY_TYPE | |
1318 | { | |
ed22c95e AM |
1319 | OB_PUTC ('A'); |
1320 | if (TYPE_DOMAIN (parmtype) == NULL_TREE) | |
2d914461 | 1321 | OB_PUTC ('_'); |
ed22c95e | 1322 | else |
53929c47 JM |
1323 | { |
1324 | tree length = array_type_nelts (parmtype); | |
1325 | if (TREE_CODE (length) != INTEGER_CST || flag_do_squangling) | |
1326 | { | |
1327 | length = fold (build (PLUS_EXPR, TREE_TYPE (length), | |
1328 | length, integer_one_node)); | |
1329 | STRIP_NOPS (length); | |
1330 | } | |
1331 | build_overload_value (sizetype, length, 1); | |
1332 | } | |
1333 | if (numeric_output_need_bar && ! flag_do_squangling) | |
1334 | OB_PUTC ('_'); | |
ed22c95e AM |
1335 | goto more; |
1336 | } | |
8d08fdba | 1337 | #else |
ed22c95e AM |
1338 | OB_PUTC ('P'); |
1339 | goto more; | |
8d08fdba MS |
1340 | #endif |
1341 | ||
ed22c95e AM |
1342 | case POINTER_TYPE: |
1343 | OB_PUTC ('P'); | |
1344 | more: | |
59e621fc | 1345 | build_mangled_name_for_type (TREE_TYPE (parmtype)); |
ed22c95e AM |
1346 | return; |
1347 | break; | |
31bebb60 KG |
1348 | |
1349 | default: | |
1350 | break; | |
ed22c95e AM |
1351 | } |
1352 | ||
59e621fc MM |
1353 | if (flag_do_squangling && check_btype (parmtype)) |
1354 | /* If PARMTYPE is already in the list of back-referenceable types, | |
1355 | then check_btype will output the appropriate reference, and | |
1356 | there's nothing more to do. */ | |
1357 | return; | |
8d08fdba | 1358 | |
ed22c95e AM |
1359 | switch (TREE_CODE (parmtype)) |
1360 | { | |
1361 | case OFFSET_TYPE: | |
1362 | OB_PUTC ('O'); | |
59e621fc | 1363 | build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype)); |
ed22c95e | 1364 | OB_PUTC ('_'); |
59e621fc | 1365 | build_mangled_name_for_type (TREE_TYPE (parmtype)); |
ed22c95e | 1366 | break; |
8d08fdba | 1367 | |
ed22c95e AM |
1368 | case FUNCTION_TYPE: |
1369 | case METHOD_TYPE: | |
1370 | { | |
59e621fc | 1371 | tree parms = TYPE_ARG_TYPES (parmtype); |
ed22c95e | 1372 | |
59e621fc MM |
1373 | /* Rather than implementing a reentrant TYPEVEC, we turn off |
1374 | repeat codes here, unless we're squangling. Squangling | |
1375 | doesn't make use of the TYPEVEC, so there's no reentrancy | |
1376 | problem. */ | |
1377 | int old_nofold = nofold; | |
1378 | if (!flag_do_squangling) | |
1379 | nofold = 1; | |
1380 | ||
1381 | if (TREE_CODE (parmtype) == METHOD_TYPE) | |
1382 | { | |
1383 | /* Mark this as a method. */ | |
ed22c95e | 1384 | OB_PUTC ('M'); |
59e621fc MM |
1385 | /* Output the class of which this method is a member. */ |
1386 | build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype)); | |
1387 | /* Output any qualifiers for the `this' parameter. */ | |
1388 | process_modifiers (TREE_TYPE (TREE_VALUE (parms))); | |
1389 | } | |
ed22c95e | 1390 | |
59e621fc MM |
1391 | /* Output the parameter types. */ |
1392 | OB_PUTC ('F'); | |
1393 | if (parms == NULL_TREE) | |
1394 | OB_PUTC ('e'); | |
1395 | else if (parms == void_list_node) | |
1396 | OB_PUTC ('v'); | |
1397 | else | |
1398 | build_mangled_name (parms, 0, 0); | |
1399 | ||
1400 | /* Output the return type. */ | |
ed22c95e | 1401 | OB_PUTC ('_'); |
59e621fc MM |
1402 | build_mangled_name_for_type (TREE_TYPE (parmtype)); |
1403 | ||
ed22c95e AM |
1404 | nofold = old_nofold; |
1405 | break; | |
1406 | } | |
8d08fdba | 1407 | |
ed22c95e | 1408 | case INTEGER_TYPE: |
ed22c95e | 1409 | if (parmtype == integer_type_node |
ea419909 PB |
1410 | || parmtype == unsigned_type_node |
1411 | || parmtype == java_int_type_node) | |
ed22c95e AM |
1412 | OB_PUTC ('i'); |
1413 | else if (parmtype == long_integer_type_node | |
1414 | || parmtype == long_unsigned_type_node) | |
1415 | OB_PUTC ('l'); | |
1416 | else if (parmtype == short_integer_type_node | |
ea419909 PB |
1417 | || parmtype == short_unsigned_type_node |
1418 | || parmtype == java_short_type_node) | |
ed22c95e AM |
1419 | OB_PUTC ('s'); |
1420 | else if (parmtype == signed_char_type_node) | |
1421 | { | |
1422 | OB_PUTC ('S'); | |
1423 | OB_PUTC ('c'); | |
1424 | } | |
1425 | else if (parmtype == char_type_node | |
ea419909 PB |
1426 | || parmtype == unsigned_char_type_node |
1427 | || parmtype == java_byte_type_node) | |
ed22c95e | 1428 | OB_PUTC ('c'); |
ea419909 PB |
1429 | else if (parmtype == wchar_type_node |
1430 | || parmtype == java_char_type_node) | |
ed22c95e AM |
1431 | OB_PUTC ('w'); |
1432 | else if (parmtype == long_long_integer_type_node | |
ea419909 PB |
1433 | || parmtype == long_long_unsigned_type_node |
1434 | || parmtype == java_long_type_node) | |
ed22c95e | 1435 | OB_PUTC ('x'); |
ea419909 PB |
1436 | else if (parmtype == java_boolean_type_node) |
1437 | OB_PUTC ('b'); | |
25f3d2f4 | 1438 | #if HOST_BITS_PER_WIDE_INT >= 64 |
f2655b99 | 1439 | else |
25f3d2f4 | 1440 | { |
25f3d2f4 BK |
1441 | int bits = TREE_INT_CST_LOW (TYPE_SIZE (parmtype)); |
1442 | build_mangled_C9x_name (bits); | |
1443 | } | |
f2655b99 | 1444 | #else |
ed22c95e | 1445 | else |
f2655b99 AH |
1446 | my_friendly_abort (73); |
1447 | #endif | |
ed22c95e | 1448 | break; |
42976354 | 1449 | |
ed22c95e AM |
1450 | case BOOLEAN_TYPE: |
1451 | OB_PUTC ('b'); | |
1452 | break; | |
8d08fdba | 1453 | |
ed22c95e | 1454 | case REAL_TYPE: |
ed22c95e AM |
1455 | if (parmtype == long_double_type_node) |
1456 | OB_PUTC ('r'); | |
ea419909 PB |
1457 | else if (parmtype == double_type_node |
1458 | || parmtype == java_double_type_node) | |
ed22c95e | 1459 | OB_PUTC ('d'); |
ea419909 PB |
1460 | else if (parmtype == float_type_node |
1461 | || parmtype == java_float_type_node) | |
ed22c95e AM |
1462 | OB_PUTC ('f'); |
1463 | else my_friendly_abort (74); | |
1464 | break; | |
1465 | ||
1466 | case COMPLEX_TYPE: | |
1467 | OB_PUTC ('J'); | |
59e621fc | 1468 | build_mangled_name_for_type (TREE_TYPE (parmtype)); |
ed22c95e AM |
1469 | break; |
1470 | ||
1471 | case VOID_TYPE: | |
1472 | OB_PUTC ('v'); | |
1473 | break; | |
1474 | ||
1475 | case ERROR_MARK: /* not right, but nothing is anyway */ | |
1476 | break; | |
1477 | ||
1478 | /* have to do these */ | |
1479 | case UNION_TYPE: | |
1480 | case RECORD_TYPE: | |
1481 | { | |
1482 | if (extra_Gcode) | |
1483 | OB_PUTC ('G'); /* make it look incompatible with AT&T */ | |
1484 | /* drop through into next case */ | |
1485 | } | |
1486 | case ENUMERAL_TYPE: | |
1487 | { | |
1488 | tree name = TYPE_NAME (parmtype); | |
73b0fce8 | 1489 | |
ed22c95e | 1490 | my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 248); |
73b0fce8 | 1491 | |
ed22c95e AM |
1492 | build_qualified_name (name); |
1493 | break; | |
1494 | } | |
8d08fdba | 1495 | |
ed22c95e AM |
1496 | case UNKNOWN_TYPE: |
1497 | /* This will take some work. */ | |
1498 | OB_PUTC ('?'); | |
1499 | break; | |
1500 | ||
1501 | case TEMPLATE_TEMPLATE_PARM: | |
1502 | /* Find and output the original template parameter | |
1503 | declaration. */ | |
7ddedda4 | 1504 | if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parmtype)) |
ed22c95e | 1505 | { |
f84b4be9 JM |
1506 | build_mangled_template_parm_index ("tzX", |
1507 | TEMPLATE_TYPE_PARM_INDEX | |
1508 | (parmtype)); | |
1509 | build_template_parm_names | |
7ddedda4 MM |
1510 | (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (parmtype)), |
1511 | TYPE_TI_ARGS (parmtype)); | |
ed22c95e AM |
1512 | } |
1513 | else | |
1514 | { | |
f84b4be9 JM |
1515 | build_mangled_template_parm_index ("ZzX", |
1516 | TEMPLATE_TYPE_PARM_INDEX | |
1517 | (parmtype)); | |
1518 | build_template_template_parm_names | |
1519 | (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype))); | |
ed22c95e AM |
1520 | } |
1521 | break; | |
1522 | ||
1523 | case TEMPLATE_TYPE_PARM: | |
f84b4be9 JM |
1524 | build_mangled_template_parm_index ("X", |
1525 | TEMPLATE_TYPE_PARM_INDEX | |
1526 | (parmtype)); | |
ed22c95e AM |
1527 | break; |
1528 | ||
1529 | case TYPENAME_TYPE: | |
1530 | /* When mangling the type of a function template whose | |
1531 | declaration looks like: | |
1532 | ||
1533 | template <class T> void foo(typename T::U) | |
1534 | ||
1535 | we have to mangle these. */ | |
1536 | build_qualified_name (parmtype); | |
1537 | break; | |
8d08fdba | 1538 | |
ed22c95e AM |
1539 | default: |
1540 | my_friendly_abort (75); | |
8d08fdba MS |
1541 | } |
1542 | ||
8d08fdba | 1543 | } |
f376e137 | 1544 | |
42976354 BK |
1545 | /* Produce the mangling for a variable named NAME in CONTEXT, which can |
1546 | be either a class TYPE or a FUNCTION_DECL. */ | |
1547 | ||
f376e137 | 1548 | tree |
42976354 BK |
1549 | build_static_name (context, name) |
1550 | tree context, name; | |
f376e137 | 1551 | { |
42976354 BK |
1552 | OB_INIT (); |
1553 | numeric_output_need_bar = 0; | |
ed22c95e | 1554 | start_squangling (); |
42976354 BK |
1555 | #ifdef JOINER |
1556 | OB_PUTC ('_'); | |
1557 | build_qualified_name (context); | |
1558 | OB_PUTC (JOINER); | |
1559 | #else | |
1560 | OB_PUTS ("__static_"); | |
1561 | build_qualified_name (context); | |
a6f02587 | 1562 | OB_PUTC ('_'); |
42976354 BK |
1563 | #endif |
1564 | OB_PUTID (name); | |
1565 | OB_FINISH (); | |
ed22c95e | 1566 | end_squangling (); |
42976354 BK |
1567 | |
1568 | return get_identifier ((char *)obstack_base (&scratch_obstack)); | |
1569 | } | |
8d08fdba | 1570 | \f |
36a117a5 MM |
1571 | /* FOR_METHOD should be 1 if the declaration in question is for a member |
1572 | of a class (including a static member) and 2 if the declaration is | |
1573 | for a constructor. */ | |
1574 | tree | |
386b8a85 JM |
1575 | build_decl_overload_real (dname, parms, ret_type, tparms, targs, |
1576 | for_method) | |
8d08fdba MS |
1577 | tree dname; |
1578 | tree parms; | |
386b8a85 JM |
1579 | tree ret_type; |
1580 | tree tparms; | |
1581 | tree targs; | |
8d08fdba MS |
1582 | int for_method; |
1583 | { | |
9c0758dd | 1584 | const char *name = IDENTIFIER_POINTER (dname); |
8d08fdba | 1585 | |
a28e3c7f | 1586 | /* member operators new and delete look like methods at this point. */ |
047f64a3 JM |
1587 | if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST |
1588 | && TREE_CHAIN (parms) == void_list_node) | |
a28e3c7f | 1589 | { |
00595019 MS |
1590 | if (dname == ansi_opname[(int) DELETE_EXPR]) |
1591 | return get_identifier ("__builtin_delete"); | |
1592 | else if (dname == ansi_opname[(int) VEC_DELETE_EXPR]) | |
1593 | return get_identifier ("__builtin_vec_delete"); | |
047f64a3 JM |
1594 | if (dname == ansi_opname[(int) NEW_EXPR]) |
1595 | return get_identifier ("__builtin_new"); | |
1596 | else if (dname == ansi_opname[(int) VEC_NEW_EXPR]) | |
1597 | return get_identifier ("__builtin_vec_new"); | |
a28e3c7f | 1598 | } |
8d08fdba | 1599 | |
ed22c95e | 1600 | start_squangling (); |
8d08fdba MS |
1601 | OB_INIT (); |
1602 | if (for_method != 2) | |
1603 | OB_PUTCP (name); | |
1604 | /* Otherwise, we can divine that this is a constructor, | |
1605 | and figure out its name without any extra encoding. */ | |
1606 | ||
1607 | OB_PUTC2 ('_', '_'); | |
c27be9b9 | 1608 | numeric_output_need_bar = 0; |
386b8a85 JM |
1609 | |
1610 | if (tparms) | |
1611 | { | |
59e621fc | 1612 | OB_PUTC ('H'); |
386b8a85 JM |
1613 | build_template_parm_names (tparms, targs); |
1614 | OB_PUTC ('_'); | |
1615 | } | |
59e621fc MM |
1616 | else if (!for_method && current_namespace == global_namespace) |
1617 | /* XXX this works only if we call this in the same namespace | |
1618 | as the declaration. Unfortunately, we don't have the _DECL, | |
1619 | only its name */ | |
1620 | OB_PUTC ('F'); | |
26877584 JM |
1621 | |
1622 | if (!for_method && current_namespace != global_namespace) | |
59e621fc | 1623 | /* qualify with namespace */ |
30394414 JM |
1624 | build_qualified_name (current_namespace); |
1625 | ||
8d08fdba | 1626 | if (parms == NULL_TREE) |
386b8a85 | 1627 | OB_PUTC ('e'); |
8d08fdba | 1628 | else if (parms == void_list_node) |
386b8a85 | 1629 | OB_PUTC ('v'); |
8d08fdba MS |
1630 | else |
1631 | { | |
407f03b8 | 1632 | if (!flag_do_squangling) |
ed22c95e | 1633 | { |
407f03b8 | 1634 | /* Allocate typevec array. */ |
9cd64686 | 1635 | size_t typevec_size = list_length (parms); |
ed22c95e | 1636 | maxtype = 0; |
2c73f9f5 | 1637 | if (!for_method && current_namespace != global_namespace) |
407f03b8 | 1638 | /* The namespace of a global function needs one slot. */ |
2c73f9f5 | 1639 | typevec_size++; |
9cd64686 | 1640 | VARRAY_TREE_INIT (typevec, typevec_size, "typevec"); |
ed22c95e | 1641 | } |
8d08fdba | 1642 | nofold = 0; |
59e621fc | 1643 | |
8d08fdba MS |
1644 | if (for_method) |
1645 | { | |
6eabb241 | 1646 | tree this_type = TREE_TYPE (TREE_VALUE (parms)); |
59e621fc MM |
1647 | |
1648 | build_mangled_name_for_type (this_type); | |
1649 | ||
1650 | if (!flag_do_squangling) | |
1651 | { | |
9cd64686 MM |
1652 | my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387); |
1653 | VARRAY_TREE (typevec, maxtype) = this_type; | |
1654 | maxtype++; | |
59e621fc | 1655 | } |
8d08fdba MS |
1656 | |
1657 | if (TREE_CHAIN (parms)) | |
ed22c95e | 1658 | build_mangled_name (TREE_CHAIN (parms), 0, 0); |
8d08fdba | 1659 | else |
386b8a85 | 1660 | OB_PUTC ('e'); |
8d08fdba MS |
1661 | } |
1662 | else | |
30394414 JM |
1663 | { |
1664 | /* the namespace qualifier for a global function | |
1665 | will count as type */ | |
1666 | if (current_namespace != global_namespace | |
1667 | && !flag_do_squangling) | |
2c73f9f5 | 1668 | { |
9cd64686 MM |
1669 | my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387); |
1670 | VARRAY_TREE (typevec, maxtype) = current_namespace; | |
1671 | maxtype++; | |
2c73f9f5 | 1672 | } |
30394414 JM |
1673 | build_mangled_name (parms, 0, 0); |
1674 | } | |
ed22c95e | 1675 | |
407f03b8 JM |
1676 | if (!flag_do_squangling) |
1677 | /* Deallocate typevec array. */ | |
9cd64686 | 1678 | VARRAY_FREE (typevec); |
8d08fdba | 1679 | } |
386b8a85 | 1680 | |
1f06b267 | 1681 | if (ret_type != NULL_TREE && for_method != 2) |
386b8a85 JM |
1682 | { |
1683 | /* Add the return type. */ | |
1684 | OB_PUTC ('_'); | |
59e621fc | 1685 | build_mangled_name_for_type (ret_type); |
386b8a85 JM |
1686 | } |
1687 | ||
1688 | OB_FINISH (); | |
ed22c95e | 1689 | end_squangling (); |
8d08fdba MS |
1690 | { |
1691 | tree n = get_identifier (obstack_base (&scratch_obstack)); | |
1692 | if (IDENTIFIER_OPNAME_P (dname)) | |
1693 | IDENTIFIER_OPNAME_P (n) = 1; | |
1694 | return n; | |
1695 | } | |
1696 | } | |
1697 | ||
386b8a85 JM |
1698 | /* Change the name of a function definition so that it may be |
1699 | overloaded. NAME is the name of the function to overload, | |
1700 | PARMS is the parameter list (which determines what name the | |
1701 | final function obtains). | |
1702 | ||
1703 | FOR_METHOD is 1 if this overload is being performed | |
1704 | for a method, rather than a function type. It is 2 if | |
1705 | this overload is being performed for a constructor. */ | |
1706 | ||
1707 | tree | |
1708 | build_decl_overload (dname, parms, for_method) | |
1709 | tree dname; | |
1710 | tree parms; | |
1711 | int for_method; | |
1712 | { | |
1713 | return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE, | |
1714 | NULL_TREE, for_method); | |
1715 | } | |
1716 | ||
36a117a5 | 1717 | /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */ |
386b8a85 | 1718 | |
c1def683 | 1719 | void |
36a117a5 | 1720 | set_mangled_name_for_decl (decl) |
9a68c51f | 1721 | tree decl; |
386b8a85 | 1722 | { |
6b4b3deb MM |
1723 | tree parm_types; |
1724 | ||
1725 | if (processing_template_decl) | |
1726 | /* There's no need to mangle the name of a template function. */ | |
1727 | return; | |
1728 | ||
1729 | parm_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
9a68c51f | 1730 | |
36a117a5 MM |
1731 | if (DECL_STATIC_FUNCTION_P (decl)) |
1732 | parm_types = | |
1733 | hash_tree_chain (build_pointer_type (DECL_CLASS_CONTEXT (decl)), | |
1734 | parm_types); | |
1735 | else | |
1736 | /* The only member functions whose type is a FUNCTION_TYPE, rather | |
1737 | than a METHOD_TYPE, should be static members. */ | |
1738 | my_friendly_assert (!DECL_CONTEXT (decl) | |
1739 | || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl))) | |
1740 | || TREE_CODE (TREE_TYPE (decl)) != FUNCTION_TYPE, | |
1741 | 0); | |
1742 | ||
1743 | DECL_ASSEMBLER_NAME (decl) | |
1744 | = build_decl_overload (DECL_NAME (decl), parm_types, | |
1745 | DECL_FUNCTION_MEMBER_P (decl) | |
1746 | + DECL_CONSTRUCTOR_P (decl)); | |
386b8a85 JM |
1747 | } |
1748 | ||
8d08fdba | 1749 | /* Build an overload name for the type expression TYPE. */ |
e92cc029 | 1750 | |
8d08fdba MS |
1751 | tree |
1752 | build_typename_overload (type) | |
1753 | tree type; | |
1754 | { | |
1755 | tree id; | |
1756 | ||
1757 | OB_INIT (); | |
1758 | OB_PUTID (ansi_opname[(int) TYPE_EXPR]); | |
1759 | nofold = 1; | |
ed22c95e AM |
1760 | start_squangling (); |
1761 | build_mangled_name (type, 0, 1); | |
8d08fdba MS |
1762 | id = get_identifier (obstack_base (&scratch_obstack)); |
1763 | IDENTIFIER_OPNAME_P (id) = 1; | |
a0a33927 | 1764 | #if 0 |
d2e5ee5c | 1765 | IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type); |
a0a33927 | 1766 | #endif |
51c184be | 1767 | TREE_TYPE (id) = type; |
ed22c95e | 1768 | end_squangling (); |
8d08fdba MS |
1769 | return id; |
1770 | } | |
1771 | ||
8d08fdba | 1772 | tree |
6b5fbb55 MS |
1773 | build_overload_with_type (name, type) |
1774 | tree name, type; | |
8d08fdba MS |
1775 | { |
1776 | OB_INIT (); | |
6b5fbb55 | 1777 | OB_PUTID (name); |
8d08fdba MS |
1778 | nofold = 1; |
1779 | ||
ed22c95e AM |
1780 | start_squangling (); |
1781 | build_mangled_name (type, 0, 1); | |
1782 | end_squangling (); | |
8d08fdba MS |
1783 | return get_identifier (obstack_base (&scratch_obstack)); |
1784 | } | |
1785 | ||
67d743fe MS |
1786 | tree |
1787 | get_id_2 (name, name2) | |
9c0758dd | 1788 | const char *name; |
67d743fe MS |
1789 | tree name2; |
1790 | { | |
1791 | OB_INIT (); | |
1792 | OB_PUTCP (name); | |
1793 | OB_PUTID (name2); | |
1794 | OB_FINISH (); | |
1795 | return get_identifier (obstack_base (&scratch_obstack)); | |
1796 | } | |
711734a9 JM |
1797 | |
1798 | /* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */ | |
1799 | ||
1800 | tree | |
1801 | build_destructor_name (type) | |
1802 | tree type; | |
1803 | { | |
1804 | return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX), | |
1805 | type); | |
1806 | } | |
8d08fdba MS |
1807 | \f |
1808 | /* Given a tree_code CODE, and some arguments (at least one), | |
1809 | attempt to use an overloaded operator on the arguments. | |
1810 | ||
1811 | For unary operators, only the first argument need be checked. | |
1812 | For binary operators, both arguments may need to be checked. | |
1813 | ||
1814 | Member functions can convert class references to class pointers, | |
1815 | for one-level deep indirection. More than that is not supported. | |
1816 | Operators [](), ()(), and ->() must be member functions. | |
1817 | ||
1818 | We call function call building calls with LOOKUP_COMPLAIN if they | |
1819 | are our only hope. This is true when we see a vanilla operator | |
1820 | applied to something of aggregate type. If this fails, we are free | |
1821 | to return `error_mark_node', because we will have reported the | |
1822 | error. | |
1823 | ||
1824 | Operators NEW and DELETE overload in funny ways: operator new takes | |
1825 | a single `size' parameter, and operator delete takes a pointer to the | |
1826 | storage being deleted. When overloading these operators, success is | |
1827 | assumed. If there is a failure, report an error message and return | |
1828 | `error_mark_node'. */ | |
1829 | ||
1830 | /* NOSTRICT */ | |
1831 | tree | |
1832 | build_opfncall (code, flags, xarg1, xarg2, arg3) | |
1833 | enum tree_code code; | |
1834 | int flags; | |
1835 | tree xarg1, xarg2, arg3; | |
1836 | { | |
277294d7 | 1837 | return build_new_op (code, flags, xarg1, xarg2, arg3); |
8d08fdba MS |
1838 | } |
1839 | \f | |
1840 | /* This function takes an identifier, ID, and attempts to figure out what | |
1841 | it means. There are a number of possible scenarios, presented in increasing | |
1842 | order of hair: | |
1843 | ||
1844 | 1) not in a class's scope | |
1845 | 2) in class's scope, member name of the class's method | |
1846 | 3) in class's scope, but not a member name of the class | |
1847 | 4) in class's scope, member name of a class's variable | |
1848 | ||
1849 | NAME is $1 from the bison rule. It is an IDENTIFIER_NODE. | |
1850 | VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1) | |
8d08fdba MS |
1851 | |
1852 | As a last ditch, try to look up the name as a label and return that | |
1853 | address. | |
1854 | ||
1855 | Values which are declared as being of REFERENCE_TYPE are | |
1856 | automatically dereferenced here (as a hack to make the | |
1857 | compiler faster). */ | |
1858 | ||
1859 | tree | |
5566b478 | 1860 | hack_identifier (value, name) |
8d08fdba | 1861 | tree value, name; |
8d08fdba | 1862 | { |
de22184b | 1863 | tree type; |
8d08fdba | 1864 | |
bd6dd845 | 1865 | if (value == error_mark_node) |
8d08fdba MS |
1866 | { |
1867 | if (current_class_name) | |
1868 | { | |
1869 | tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1); | |
1870 | if (fields == error_mark_node) | |
1871 | return error_mark_node; | |
1872 | if (fields) | |
1873 | { | |
1874 | tree fndecl; | |
1875 | ||
1876 | fndecl = TREE_VALUE (fields); | |
1877 | my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251); | |
2c73f9f5 ML |
1878 | /* I could not trigger this code. MvL */ |
1879 | my_friendly_abort (980325); | |
1880 | #ifdef DEAD | |
8d08fdba MS |
1881 | if (DECL_CHAIN (fndecl) == NULL_TREE) |
1882 | { | |
8251199e | 1883 | warning ("methods cannot be converted to function pointers"); |
8d08fdba MS |
1884 | return fndecl; |
1885 | } | |
1886 | else | |
1887 | { | |
8251199e | 1888 | error ("ambiguous request for method pointer `%s'", |
8d08fdba MS |
1889 | IDENTIFIER_POINTER (name)); |
1890 | return error_mark_node; | |
1891 | } | |
2c73f9f5 | 1892 | #endif |
8d08fdba MS |
1893 | } |
1894 | } | |
1895 | if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name)) | |
1896 | { | |
1897 | return IDENTIFIER_LABEL_VALUE (name); | |
1898 | } | |
1899 | return error_mark_node; | |
1900 | } | |
1901 | ||
1902 | type = TREE_TYPE (value); | |
1903 | if (TREE_CODE (value) == FIELD_DECL) | |
1904 | { | |
4ac14744 | 1905 | if (current_class_ptr == NULL_TREE) |
8d08fdba | 1906 | { |
672476cb MM |
1907 | if (current_function_decl |
1908 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
8251199e | 1909 | cp_error ("invalid use of member `%D' in static member function", |
672476cb MM |
1910 | value); |
1911 | else | |
1912 | /* We can get here when processing a bad default | |
1913 | argument, like: | |
1914 | struct S { int a; void f(int i = a); } */ | |
8251199e | 1915 | cp_error ("invalid use of member `%D'", value); |
672476cb | 1916 | |
8d08fdba MS |
1917 | return error_mark_node; |
1918 | } | |
4ac14744 | 1919 | TREE_USED (current_class_ptr) = 1; |
a5894242 | 1920 | |
8d08fdba MS |
1921 | /* Mark so that if we are in a constructor, and then find that |
1922 | this field was initialized by a base initializer, | |
1923 | we can emit an error message. */ | |
1924 | TREE_USED (value) = 1; | |
4ac14744 | 1925 | value = build_component_ref (current_class_ref, name, NULL_TREE, 1); |
8d08fdba | 1926 | } |
8f032717 MM |
1927 | else if ((TREE_CODE (value) == FUNCTION_DECL |
1928 | && DECL_FUNCTION_MEMBER_P (value)) | |
1929 | || (TREE_CODE (value) == OVERLOAD | |
1930 | && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value)))) | |
51924768 JM |
1931 | { |
1932 | tree decl; | |
1933 | ||
8f032717 MM |
1934 | if (TREE_CODE (value) == OVERLOAD) |
1935 | value = OVL_CURRENT (value); | |
1936 | ||
51924768 JM |
1937 | decl = maybe_dummy_object (DECL_CLASS_CONTEXT (value), 0); |
1938 | value = build_component_ref (decl, name, NULL_TREE, 1); | |
1939 | } | |
6b5fbb55 | 1940 | else if (really_overloaded_fn (value)) |
8f032717 | 1941 | ; |
2c73f9f5 ML |
1942 | else if (TREE_CODE (value) == OVERLOAD) |
1943 | /* not really overloaded function */ | |
1944 | mark_used (OVL_FUNCTION (value)); | |
a5ef9010 JM |
1945 | else if (TREE_CODE (value) == TREE_LIST) |
1946 | { | |
72b7eeff | 1947 | /* Ambiguous reference to base members, possibly other cases?. */ |
a5ef9010 JM |
1948 | tree t = value; |
1949 | while (t && TREE_CODE (t) == TREE_LIST) | |
1950 | { | |
72b7eeff | 1951 | mark_used (TREE_VALUE (t)); |
a5ef9010 JM |
1952 | t = TREE_CHAIN (t); |
1953 | } | |
1954 | } | |
2c73f9f5 | 1955 | else if (TREE_CODE (value) == NAMESPACE_DECL) |
0e607f34 | 1956 | { |
8251199e | 1957 | cp_error ("use of namespace `%D' as expression", value); |
0e607f34 JM |
1958 | return error_mark_node; |
1959 | } | |
1960 | else if (DECL_CLASS_TEMPLATE_P (value)) | |
1961 | { | |
8251199e | 1962 | cp_error ("use of class template `%T' as expression", value); |
0e607f34 JM |
1963 | return error_mark_node; |
1964 | } | |
8d08fdba | 1965 | else |
72b7eeff | 1966 | mark_used (value); |
8d08fdba | 1967 | |
c6882a35 JM |
1968 | if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL |
1969 | || TREE_CODE (value) == RESULT_DECL) | |
5566b478 MS |
1970 | { |
1971 | tree context = decl_function_context (value); | |
1972 | if (context != NULL_TREE && context != current_function_decl | |
1973 | && ! TREE_STATIC (value)) | |
1974 | { | |
8251199e | 1975 | cp_error ("use of %s from containing function", |
5566b478 MS |
1976 | (TREE_CODE (value) == VAR_DECL |
1977 | ? "`auto' variable" : "parameter")); | |
8251199e | 1978 | cp_error_at (" `%#D' declared here", value); |
e76a2646 | 1979 | value = error_mark_node; |
5566b478 MS |
1980 | } |
1981 | } | |
1982 | ||
8d08fdba MS |
1983 | if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value)) |
1984 | { | |
1985 | if (DECL_LANG_SPECIFIC (value) | |
1986 | && DECL_CLASS_CONTEXT (value) != current_class_type) | |
1987 | { | |
d6479fe7 | 1988 | tree path; |
8d08fdba MS |
1989 | register tree context |
1990 | = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value)) | |
1991 | ? DECL_CLASS_CONTEXT (value) | |
1992 | : DECL_CONTEXT (value); | |
1993 | ||
1994 | get_base_distance (context, current_class_type, 0, &path); | |
d6479fe7 MM |
1995 | if (path && !enforce_access (current_class_type, value)) |
1996 | return error_mark_node; | |
8d08fdba | 1997 | } |
8d08fdba | 1998 | } |
280f9385 MM |
1999 | else if (TREE_CODE (value) == TREE_LIST |
2000 | && TREE_TYPE (value) == error_mark_node) | |
8d08fdba | 2001 | { |
0cfdd854 ML |
2002 | error ("request for member `%s' is ambiguous in multiple inheritance lattice", |
2003 | IDENTIFIER_POINTER (name)); | |
66543169 | 2004 | print_candidates (value); |
0cfdd854 | 2005 | return error_mark_node; |
8d08fdba MS |
2006 | } |
2007 | ||
75d587eb | 2008 | if (! processing_template_decl) |
6b5fbb55 | 2009 | value = convert_from_reference (value); |
8d08fdba MS |
2010 | return value; |
2011 | } | |
2012 | ||
8926095f | 2013 | \f |
8926095f MS |
2014 | tree |
2015 | make_thunk (function, delta) | |
2016 | tree function; | |
2017 | int delta; | |
2018 | { | |
b87692e5 | 2019 | tree thunk_id; |
8926095f | 2020 | tree thunk; |
8926095f | 2021 | tree func_decl; |
cc600f33 | 2022 | |
8926095f MS |
2023 | if (TREE_CODE (function) != ADDR_EXPR) |
2024 | abort (); | |
2025 | func_decl = TREE_OPERAND (function, 0); | |
2026 | if (TREE_CODE (func_decl) != FUNCTION_DECL) | |
2027 | abort (); | |
cc600f33 JM |
2028 | |
2029 | OB_INIT (); | |
2030 | OB_PUTS ("__thunk_"); | |
2031 | if (delta > 0) | |
2032 | { | |
2033 | OB_PUTC ('n'); | |
2034 | icat (delta); | |
2035 | } | |
5edb8b93 | 2036 | else |
cc600f33 JM |
2037 | icat (-delta); |
2038 | OB_PUTC ('_'); | |
2039 | OB_PUTID (DECL_ASSEMBLER_NAME (func_decl)); | |
2040 | OB_FINISH (); | |
2041 | thunk_id = get_identifier (obstack_base (&scratch_obstack)); | |
2042 | ||
a0a33927 MS |
2043 | thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id); |
2044 | if (thunk && TREE_CODE (thunk) != THUNK_DECL) | |
2045 | { | |
8251199e | 2046 | cp_error ("implementation-reserved name `%D' used", thunk_id); |
2c73f9f5 ML |
2047 | thunk = NULL_TREE; |
2048 | SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk); | |
a0a33927 MS |
2049 | } |
2050 | if (thunk == NULL_TREE) | |
2051 | { | |
eb448459 MS |
2052 | thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl)); |
2053 | TREE_READONLY (thunk) = TREE_READONLY (func_decl); | |
2054 | TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl); | |
7fcdf4c2 | 2055 | comdat_linkage (thunk); |
72b7eeff | 2056 | TREE_SET_CODE (thunk, THUNK_DECL); |
a0a33927 MS |
2057 | DECL_INITIAL (thunk) = function; |
2058 | THUNK_DELTA (thunk) = delta; | |
72b7eeff | 2059 | DECL_EXTERNAL (thunk) = 1; |
eb448459 | 2060 | DECL_ARTIFICIAL (thunk) = 1; |
a0a33927 MS |
2061 | /* So that finish_file can write out any thunks that need to be: */ |
2062 | pushdecl_top_level (thunk); | |
2063 | } | |
8926095f MS |
2064 | return thunk; |
2065 | } | |
2066 | ||
eb448459 MS |
2067 | /* Emit the definition of a C++ multiple inheritance vtable thunk. */ |
2068 | ||
8926095f MS |
2069 | void |
2070 | emit_thunk (thunk_fndecl) | |
824b9a4c | 2071 | tree thunk_fndecl; |
8926095f | 2072 | { |
8926095f MS |
2073 | tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0); |
2074 | int delta = THUNK_DELTA (thunk_fndecl); | |
8926095f MS |
2075 | |
2076 | if (TREE_ASM_WRITTEN (thunk_fndecl)) | |
2077 | return; | |
2078 | ||
a0a33927 MS |
2079 | TREE_ASM_WRITTEN (thunk_fndecl) = 1; |
2080 | ||
809c8c30 JM |
2081 | TREE_ADDRESSABLE (function) = 1; |
2082 | mark_used (function); | |
2083 | ||
8926095f MS |
2084 | if (current_function_decl) |
2085 | abort (); | |
a0128b67 MS |
2086 | |
2087 | TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL); | |
eb66be0e | 2088 | |
eb448459 | 2089 | { |
a80e4195 | 2090 | #ifdef ASM_OUTPUT_MI_THUNK |
eb448459 MS |
2091 | char *fnname; |
2092 | current_function_decl = thunk_fndecl; | |
b87692e5 MS |
2093 | /* Make sure we build up its RTL before we go onto the |
2094 | temporary obstack. */ | |
2095 | make_function_rtl (thunk_fndecl); | |
eb448459 MS |
2096 | temporary_allocation (); |
2097 | DECL_RESULT (thunk_fndecl) | |
2098 | = build_decl (RESULT_DECL, 0, integer_type_node); | |
eb448459 | 2099 | fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0); |
da20811c | 2100 | init_function_start (thunk_fndecl, input_filename, lineno); |
ed48174c | 2101 | current_function_is_thunk = 1; |
eb448459 MS |
2102 | assemble_start_function (thunk_fndecl, fnname); |
2103 | ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function); | |
2104 | assemble_end_function (thunk_fndecl, fnname); | |
2105 | permanent_allocation (1); | |
2106 | current_function_decl = 0; | |
eb66be0e | 2107 | #else /* ASM_OUTPUT_MI_THUNK */ |
eb448459 MS |
2108 | /* If we don't have the necessary macro for efficient thunks, generate a |
2109 | thunk function that just makes a call to the real function. | |
2110 | Unfortunately, this doesn't work for varargs. */ | |
2111 | ||
eb66be0e | 2112 | tree a, t; |
8926095f | 2113 | |
eb448459 | 2114 | if (varargs_function_p (function)) |
8251199e | 2115 | cp_error ("generic thunk code fails for method `%#D' which uses `...'", |
eb448459 MS |
2116 | function); |
2117 | ||
eb66be0e MS |
2118 | /* Set up clone argument trees for the thunk. */ |
2119 | t = NULL_TREE; | |
2120 | for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a)) | |
2121 | { | |
2122 | tree x = copy_node (a); | |
2123 | TREE_CHAIN (x) = t; | |
2124 | DECL_CONTEXT (x) = thunk_fndecl; | |
2125 | t = x; | |
2126 | } | |
2127 | a = nreverse (t); | |
2128 | DECL_ARGUMENTS (thunk_fndecl) = a; | |
2129 | DECL_RESULT (thunk_fndecl) = NULL_TREE; | |
eb448459 MS |
2130 | DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function); |
2131 | copy_lang_decl (thunk_fndecl); | |
2132 | DECL_INTERFACE_KNOWN (thunk_fndecl) = 1; | |
2133 | DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1; | |
eb66be0e MS |
2134 | |
2135 | start_function (NULL_TREE, thunk_fndecl, NULL_TREE, 1); | |
2136 | store_parm_decls (); | |
eb448459 | 2137 | current_function_is_thunk = 1; |
eb66be0e MS |
2138 | |
2139 | /* Build up the call to the real function. */ | |
2140 | t = build_int_2 (delta, -1 * (delta < 0)); | |
2141 | TREE_TYPE (t) = signed_type (sizetype); | |
2142 | t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t)); | |
e1b3e07d | 2143 | t = tree_cons (NULL_TREE, t, NULL_TREE); |
eb66be0e | 2144 | for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a)) |
e1b3e07d | 2145 | t = tree_cons (NULL_TREE, a, t); |
eb66be0e MS |
2146 | t = nreverse (t); |
2147 | t = build_call (function, TREE_TYPE (TREE_TYPE (function)), t); | |
2148 | c_expand_return (t); | |
2149 | ||
fdfcc44c | 2150 | finish_function (lineno, 0); |
4d6efa25 JM |
2151 | |
2152 | /* Don't let the backend defer this function. */ | |
2153 | if (DECL_DEFER_OUTPUT (thunk_fndecl)) | |
2154 | { | |
2155 | output_inline_function (thunk_fndecl); | |
2156 | permanent_allocation (1); | |
2157 | } | |
809c8c30 | 2158 | #endif /* ASM_OUTPUT_MI_THUNK */ |
eb448459 | 2159 | } |
8926095f | 2160 | |
eb66be0e | 2161 | TREE_SET_CODE (thunk_fndecl, THUNK_DECL); |
8926095f | 2162 | } |
f376e137 MS |
2163 | \f |
2164 | /* Code for synthesizing methods which have default semantics defined. */ | |
2165 | ||
f376e137 | 2166 | /* Generate code for default X(X&) constructor. */ |
e92cc029 | 2167 | |
824b9a4c | 2168 | static void |
db5ae43f | 2169 | do_build_copy_constructor (fndecl) |
f376e137 MS |
2170 | tree fndecl; |
2171 | { | |
2172 | tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); | |
f1dedc31 | 2173 | tree compound_stmt; |
f376e137 MS |
2174 | tree t; |
2175 | ||
f376e137 MS |
2176 | if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) |
2177 | parm = TREE_CHAIN (parm); | |
2178 | parm = convert_from_reference (parm); | |
2179 | ||
a59ca936 JM |
2180 | if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type) |
2181 | && is_empty_class (current_class_type)) | |
2182 | /* Don't copy the padding byte; it might not have been allocated | |
2183 | if *this is a base subobject. */; | |
2184 | else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)) | |
f376e137 | 2185 | { |
4ac14744 | 2186 | t = build (INIT_EXPR, void_type_node, current_class_ref, parm); |
f376e137 | 2187 | TREE_SIDE_EFFECTS (t) = 1; |
f1dedc31 | 2188 | finish_expr_stmt (t); |
f376e137 MS |
2189 | } |
2190 | else | |
2191 | { | |
2192 | tree fields = TYPE_FIELDS (current_class_type); | |
2193 | int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type); | |
2194 | tree binfos = TYPE_BINFO_BASETYPES (current_class_type); | |
2195 | int i; | |
2196 | ||
1b5f5f76 | 2197 | /* Initialize all the base-classes. */ |
f376e137 MS |
2198 | for (t = CLASSTYPE_VBASECLASSES (current_class_type); t; |
2199 | t = TREE_CHAIN (t)) | |
1b5f5f76 MM |
2200 | current_base_init_list |
2201 | = tree_cons (BINFO_TYPE (t), parm, current_base_init_list); | |
f376e137 MS |
2202 | for (i = 0; i < n_bases; ++i) |
2203 | { | |
1b5f5f76 MM |
2204 | t = TREE_VEC_ELT (binfos, i); |
2205 | if (TREE_VIA_VIRTUAL (t)) | |
8ccc31eb | 2206 | continue; |
f376e137 | 2207 | |
1b5f5f76 MM |
2208 | current_base_init_list |
2209 | = tree_cons (BINFO_TYPE (t), parm, current_base_init_list); | |
f376e137 | 2210 | } |
1b5f5f76 | 2211 | |
f376e137 MS |
2212 | for (; fields; fields = TREE_CHAIN (fields)) |
2213 | { | |
de22184b | 2214 | tree init, t; |
a5894242 MS |
2215 | tree field = fields; |
2216 | ||
2217 | if (TREE_CODE (field) != FIELD_DECL) | |
f376e137 | 2218 | continue; |
8dff1027 MS |
2219 | |
2220 | init = parm; | |
a5894242 | 2221 | if (DECL_NAME (field)) |
f376e137 | 2222 | { |
a5894242 | 2223 | if (VFIELD_NAME_P (DECL_NAME (field))) |
f376e137 | 2224 | continue; |
a5894242 | 2225 | if (VBASE_NAME_P (DECL_NAME (field))) |
f376e137 MS |
2226 | continue; |
2227 | ||
2228 | /* True for duplicate members. */ | |
a5894242 | 2229 | if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field) |
f376e137 MS |
2230 | continue; |
2231 | } | |
a5894242 | 2232 | else if ((t = TREE_TYPE (field)) != NULL_TREE |
6bdb8141 | 2233 | && ANON_AGGR_TYPE_P (t) |
0171aeab | 2234 | && TYPE_FIELDS (t) != NULL_TREE) |
6bdb8141 JM |
2235 | /* Just use the field; anonymous types can't have |
2236 | nontrivial copy ctors or assignment ops. */; | |
0171aeab JM |
2237 | else |
2238 | continue; | |
f376e137 | 2239 | |
8dff1027 | 2240 | init = build (COMPONENT_REF, TREE_TYPE (field), init, field); |
f376e137 MS |
2241 | init = build_tree_list (NULL_TREE, init); |
2242 | ||
2243 | current_member_init_list | |
6bdb8141 | 2244 | = tree_cons (field, init, current_member_init_list); |
f376e137 MS |
2245 | } |
2246 | current_member_init_list = nreverse (current_member_init_list); | |
faae18ab | 2247 | current_base_init_list = nreverse (current_base_init_list); |
f376e137 MS |
2248 | setup_vtbl_ptr (); |
2249 | } | |
2250 | ||
f1dedc31 MM |
2251 | compound_stmt = begin_compound_stmt (/*has_no_scope=*/0); |
2252 | finish_compound_stmt (/*has_no_scope=*/0, compound_stmt); | |
f376e137 MS |
2253 | } |
2254 | ||
824b9a4c | 2255 | static void |
db5ae43f | 2256 | do_build_assign_ref (fndecl) |
f376e137 MS |
2257 | tree fndecl; |
2258 | { | |
2259 | tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); | |
f1dedc31 | 2260 | tree compound_stmt; |
f376e137 | 2261 | |
f1dedc31 | 2262 | compound_stmt = begin_compound_stmt (/*has_no_scope=*/0); |
f376e137 MS |
2263 | parm = convert_from_reference (parm); |
2264 | ||
a59ca936 JM |
2265 | if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type) |
2266 | && is_empty_class (current_class_type)) | |
2267 | /* Don't copy the padding byte; it might not have been allocated | |
2268 | if *this is a base subobject. */; | |
2269 | else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)) | |
f376e137 | 2270 | { |
4ac14744 | 2271 | tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm); |
f376e137 | 2272 | TREE_SIDE_EFFECTS (t) = 1; |
f1dedc31 | 2273 | finish_expr_stmt (t); |
f376e137 MS |
2274 | } |
2275 | else | |
2276 | { | |
2277 | tree fields = TYPE_FIELDS (current_class_type); | |
2278 | int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type); | |
2279 | tree binfos = TYPE_BINFO_BASETYPES (current_class_type); | |
2280 | int i; | |
2281 | ||
2282 | for (i = 0; i < n_bases; ++i) | |
2283 | { | |
2284 | tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i)); | |
e349ee73 MS |
2285 | tree p = convert_to_reference |
2286 | (build_reference_type (basetype), parm, | |
2287 | CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE); | |
2288 | p = convert_from_reference (p); | |
2289 | p = build_member_call (basetype, ansi_opname [MODIFY_EXPR], | |
e66d884e | 2290 | build_expr_list (NULL_TREE, p)); |
e349ee73 | 2291 | expand_expr_stmt (p); |
f376e137 MS |
2292 | } |
2293 | for (; fields; fields = TREE_CHAIN (fields)) | |
2294 | { | |
0171aeab | 2295 | tree comp, init, t; |
a5894242 MS |
2296 | tree field = fields; |
2297 | ||
2298 | if (TREE_CODE (field) != FIELD_DECL) | |
f376e137 | 2299 | continue; |
e349ee73 | 2300 | |
1b8899d1 | 2301 | if (CP_TYPE_CONST_P (TREE_TYPE (field))) |
e349ee73 MS |
2302 | { |
2303 | if (DECL_NAME (field)) | |
8251199e | 2304 | cp_error ("non-static const member `%#D', can't use default assignment operator", field); |
e349ee73 | 2305 | else |
8251199e | 2306 | cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type); |
e349ee73 MS |
2307 | continue; |
2308 | } | |
2309 | else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE) | |
2310 | { | |
2311 | if (DECL_NAME (field)) | |
8251199e | 2312 | cp_error ("non-static reference member `%#D', can't use default assignment operator", field); |
e349ee73 | 2313 | else |
8251199e | 2314 | cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type); |
e349ee73 MS |
2315 | continue; |
2316 | } | |
2317 | ||
8dff1027 MS |
2318 | comp = current_class_ref; |
2319 | init = parm; | |
2320 | ||
a5894242 | 2321 | if (DECL_NAME (field)) |
f376e137 | 2322 | { |
a5894242 | 2323 | if (VFIELD_NAME_P (DECL_NAME (field))) |
f376e137 | 2324 | continue; |
a5894242 | 2325 | if (VBASE_NAME_P (DECL_NAME (field))) |
f376e137 MS |
2326 | continue; |
2327 | ||
2328 | /* True for duplicate members. */ | |
a5894242 | 2329 | if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field) |
f376e137 MS |
2330 | continue; |
2331 | } | |
a5894242 | 2332 | else if ((t = TREE_TYPE (field)) != NULL_TREE |
6bdb8141 | 2333 | && ANON_AGGR_TYPE_P (t) |
0171aeab | 2334 | && TYPE_FIELDS (t) != NULL_TREE) |
6bdb8141 JM |
2335 | /* Just use the field; anonymous types can't have |
2336 | nontrivial copy ctors or assignment ops. */; | |
0171aeab JM |
2337 | else |
2338 | continue; | |
f376e137 | 2339 | |
8dff1027 MS |
2340 | comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field); |
2341 | init = build (COMPONENT_REF, TREE_TYPE (field), init, field); | |
f376e137 MS |
2342 | |
2343 | expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init)); | |
2344 | } | |
2345 | } | |
4ac14744 | 2346 | c_expand_return (current_class_ref); |
f1dedc31 | 2347 | finish_compound_stmt (/*has_no_scope=*/0, compound_stmt); |
f376e137 MS |
2348 | } |
2349 | ||
2350 | void | |
db5ae43f | 2351 | synthesize_method (fndecl) |
f376e137 MS |
2352 | tree fndecl; |
2353 | { | |
db5ae43f | 2354 | int nested = (current_function_decl != NULL_TREE); |
e76a2646 | 2355 | tree context = hack_decl_function_context (fndecl); |
db5ae43f | 2356 | |
b7067a12 JM |
2357 | if (at_eof) |
2358 | import_export_decl (fndecl); | |
2359 | ||
9a3b49ac MS |
2360 | if (! context) |
2361 | push_to_top_level (); | |
2362 | else if (nested) | |
99dccabc | 2363 | push_function_context_to (context); |
db5ae43f | 2364 | |
e76a2646 | 2365 | interface_unknown = 1; |
c11b6f21 | 2366 | start_function (NULL_TREE, fndecl, NULL_TREE, 1); |
f376e137 | 2367 | store_parm_decls (); |
f1dedc31 | 2368 | clear_last_expr (); |
db5ae43f MS |
2369 | |
2370 | if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR]) | |
2371 | do_build_assign_ref (fndecl); | |
2372 | else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) | |
2373 | ; | |
2374 | else | |
2375 | { | |
2376 | tree arg_chain = FUNCTION_ARG_CHAIN (fndecl); | |
2377 | if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl)) | |
2378 | arg_chain = TREE_CHAIN (arg_chain); | |
2379 | if (arg_chain != void_list_node) | |
2380 | do_build_copy_constructor (fndecl); | |
2381 | else if (TYPE_NEEDS_CONSTRUCTING (current_class_type)) | |
f18a14bc MM |
2382 | { |
2383 | tree compound_stmt; | |
2384 | ||
2385 | setup_vtbl_ptr (); | |
2386 | compound_stmt = begin_compound_stmt (/*has_no_scope=*/0); | |
2387 | finish_compound_stmt (/*has_no_scope=*/0, compound_stmt); | |
2388 | } | |
db5ae43f MS |
2389 | } |
2390 | ||
fdfcc44c | 2391 | finish_function (lineno, 0); |
28cbf42c | 2392 | |
db5ae43f | 2393 | extract_interface_info (); |
9a3b49ac MS |
2394 | if (! context) |
2395 | pop_from_top_level (); | |
2396 | else if (nested) | |
99dccabc | 2397 | pop_function_context_from (context); |
f376e137 | 2398 | } |