method.c (52284) | method.c (60967) |
---|---|
1/* Handle the hair of processing (but not expanding) inline functions. 2 Also manage function and variable name overloading. 3 Copyright (C) 1987, 89, 92-97, 1998, 1999 Free Software Foundation, Inc. 4 Contributed by Michael Tiemann (tiemann@cygnus.com) 5 6This file is part of GNU CC. 7 8GNU CC is free software; you can redistribute it and/or modify --- 27 unchanged lines hidden (view full) --- 36#include "cp-tree.h" 37#include "obstack.h" 38#include "rtl.h" 39#include "expr.h" 40#include "output.h" 41#include "hard-reg-set.h" 42#include "flags.h" 43#include "toplev.h" | 1/* Handle the hair of processing (but not expanding) inline functions. 2 Also manage function and variable name overloading. 3 Copyright (C) 1987, 89, 92-97, 1998, 1999 Free Software Foundation, Inc. 4 Contributed by Michael Tiemann (tiemann@cygnus.com) 5 6This file is part of GNU CC. 7 8GNU CC is free software; you can redistribute it and/or modify --- 27 unchanged lines hidden (view full) --- 36#include "cp-tree.h" 37#include "obstack.h" 38#include "rtl.h" 39#include "expr.h" 40#include "output.h" 41#include "hard-reg-set.h" 42#include "flags.h" 43#include "toplev.h" |
44#include "decl.h" |
|
44 45/* TREE_LIST of the current inline functions that need to be 46 processed. */ 47struct pending_inline *pending_inlines; 48 49int static_labelno; 50 51#define obstack_chunk_alloc xmalloc --- 31 unchanged lines hidden (view full) --- 83static void build_mangled_template_parm_index PROTO((char *, tree)); 84#if HOST_BITS_PER_WIDE_INT >= 64 85static void build_mangled_C9x_name PROTO((int)); 86#endif 87static int is_back_referenceable_type PROTO((tree)); 88static int check_btype PROTO((tree)); 89static void build_mangled_name_for_type PROTO((tree)); 90static void build_mangled_name_for_type_with_Gcode PROTO((tree, int)); | 45 46/* TREE_LIST of the current inline functions that need to be 47 processed. */ 48struct pending_inline *pending_inlines; 49 50int static_labelno; 51 52#define obstack_chunk_alloc xmalloc --- 31 unchanged lines hidden (view full) --- 84static void build_mangled_template_parm_index PROTO((char *, tree)); 85#if HOST_BITS_PER_WIDE_INT >= 64 86static void build_mangled_C9x_name PROTO((int)); 87#endif 88static int is_back_referenceable_type PROTO((tree)); 89static int check_btype PROTO((tree)); 90static void build_mangled_name_for_type PROTO((tree)); 91static void build_mangled_name_for_type_with_Gcode PROTO((tree, int)); |
92static tree build_base_path PROTO((tree, int)); |
|
91 | 93 |
94 |
|
92# define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0) 93# define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C))) 94# define OB_PUTC2(C1,C2) \ 95 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2))) 96# define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1)) 97# define OB_PUTID(ID) \ 98 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \ 99 IDENTIFIER_LENGTH (ID))) --- 1244 unchanged lines hidden (view full) --- 1344 goto more; 1345 } 1346#else 1347 OB_PUTC ('P'); 1348 goto more; 1349#endif 1350 1351 case POINTER_TYPE: | 95# define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0) 96# define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C))) 97# define OB_PUTC2(C1,C2) \ 98 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2))) 99# define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1)) 100# define OB_PUTID(ID) \ 101 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \ 102 IDENTIFIER_LENGTH (ID))) --- 1244 unchanged lines hidden (view full) --- 1347 goto more; 1348 } 1349#else 1350 OB_PUTC ('P'); 1351 goto more; 1352#endif 1353 1354 case POINTER_TYPE: |
1355 /* Even though the vlist_type_node is PPPFe (i.e. `int 1356 (***)(...)'), it is different from the any other occurence of 1357 the pointer type, because the underlying function type is 1358 different. */ 1359 if (parmtype == vlist_type_node) 1360 { 1361 OB_PUTS (VLIST_TYPE_NAME); 1362 return; 1363 } |
|
1352 OB_PUTC ('P'); 1353 more: 1354 build_mangled_name_for_type (TREE_TYPE (parmtype)); 1355 return; 1356 break; 1357 1358 default: 1359 break; --- 444 unchanged lines hidden (view full) --- 1804{ 1805 OB_INIT (); 1806 OB_PUTCP (name); 1807 OB_PUTID (name2); 1808 OB_FINISH (); 1809 return get_identifier (obstack_base (&scratch_obstack)); 1810} 1811 | 1364 OB_PUTC ('P'); 1365 more: 1366 build_mangled_name_for_type (TREE_TYPE (parmtype)); 1367 return; 1368 break; 1369 1370 default: 1371 break; --- 444 unchanged lines hidden (view full) --- 1816{ 1817 OB_INIT (); 1818 OB_PUTCP (name); 1819 OB_PUTID (name2); 1820 OB_FINISH (); 1821 return get_identifier (obstack_base (&scratch_obstack)); 1822} 1823 |
1812/* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */ | 1824/* Print a binfo path T, starting with the most derived class. If 1825 OMIT_LAST is set, drop and return the most derived class. */ |
1813 | 1826 |
1827static tree 1828build_base_path (t, omit_last) 1829 tree t; 1830 int omit_last; 1831{ 1832 tree ret = NULL_TREE; 1833 if (BINFO_INHERITANCE_CHAIN (t)) 1834 ret = build_base_path (BINFO_INHERITANCE_CHAIN (t), omit_last); 1835 else if (omit_last) 1836 return t; 1837 process_overload_item (BINFO_TYPE (t), 0); 1838 return ret; 1839} 1840 1841/* Return a mangled name for a vlist vtable, using the path of both 1842 BASE and VBASE. */ 1843 |
|
1814tree | 1844tree |
1815build_destructor_name (type) | 1845get_vlist_vtable_id (base, vbase) 1846 tree base, vbase; 1847{ 1848 tree last; 1849 OB_INIT (); 1850 OB_PUTS (VCTABLE_NAME); 1851 build_base_path (base, 0); 1852 OB_PUTC ('_'); 1853 /* Since the base path should end where the vbase path starts, we 1854 can omit the most-derived class in the vbase path. Check below 1855 that this really happens. */ 1856 last = build_base_path (vbase, 1); 1857 my_friendly_assert (BINFO_TYPE (last) == BINFO_TYPE (base), 990402); 1858 OB_FINISH (); 1859 return get_identifier (obstack_base (&scratch_obstack)); 1860} 1861 1862/* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. If 1863 HAS_VLIST is set, also add the vlist argument. */ 1864 1865tree 1866build_destructor_name (type, has_vlist) |
1816 tree type; | 1867 tree type; |
1868 int has_vlist; |
|
1817{ | 1869{ |
1818 return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX), 1819 type); | 1870 OB_INIT (); 1871 OB_PUTS (DESTRUCTOR_DECL_PREFIX); 1872 start_squangling (); 1873 build_mangled_name_for_type (type); 1874 /* If we need backwards compatibility, we can get aways by 1875 not linking type-safely, as the dtor will check whether 1876 the argument was provided. */ 1877 if (has_vlist && !flag_vtable_thunks_compat) 1878 OB_PUTS (VLIST_TYPE_NAME); 1879 OB_FINISH (); 1880 end_squangling (); 1881 return get_identifier (obstack_base (&scratch_obstack)); |
1820} 1821 1822/* Given a tree_code CODE, and some arguments (at least one), 1823 attempt to use an overloaded operator on the arguments. 1824 1825 For unary operators, only the first argument need be checked. 1826 For binary operators, both arguments may need to be checked. 1827 --- 345 unchanged lines hidden (view full) --- 2173 permanent_allocation (1); 2174 } 2175#endif /* ASM_OUTPUT_MI_THUNK */ 2176 } 2177 2178 TREE_SET_CODE (thunk_fndecl, THUNK_DECL); 2179} 2180 | 1882} 1883 1884/* Given a tree_code CODE, and some arguments (at least one), 1885 attempt to use an overloaded operator on the arguments. 1886 1887 For unary operators, only the first argument need be checked. 1888 For binary operators, both arguments may need to be checked. 1889 --- 345 unchanged lines hidden (view full) --- 2235 permanent_allocation (1); 2236 } 2237#endif /* ASM_OUTPUT_MI_THUNK */ 2238 } 2239 2240 TREE_SET_CODE (thunk_fndecl, THUNK_DECL); 2241} 2242 |
2243void 2244make_vlist_ctor_wrapper (fn) 2245 tree fn; 2246{ 2247 tree fntype, decl; 2248 tree arg_types, parms, parm, basetype, pbasetype; 2249 tree t, ctors; 2250 2251 arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn)); 2252 pbasetype = TREE_VALUE (arg_types); 2253 basetype = TREE_TYPE (pbasetype); 2254 parms = DECL_ARGUMENTS (fn); 2255 2256 /* Skip this, __in_chrg, and _vlist */ 2257 arg_types = TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arg_types))); 2258 2259 2260 /* Add __in_charge. */ 2261 arg_types = hash_tree_chain (integer_type_node, arg_types); 2262 2263 /* Don't add this to arg_types, as build_cplus_method_type does so. */ 2264 2265 fntype = build_cplus_method_type (basetype, TREE_TYPE (TREE_TYPE (fn)), 2266 arg_types); 2267 2268 decl = build_lang_decl (FUNCTION_DECL, DECL_NAME (fn), fntype); 2269 DECL_LANG_SPECIFIC (decl)->decl_flags = DECL_LANG_SPECIFIC (fn)->decl_flags; 2270 DECL_EXTERNAL (decl) = 0; 2271 TREE_PUBLIC (decl) = 1; 2272 DECL_ARTIFICIAL (decl) = 1; 2273 DECL_CONSTRUCTOR_P (decl) = 1; 2274 DECL_CONSTRUCTOR_FOR_VBASE (decl) = CONSTRUCTOR_FOR_VBASE; 2275 /* Claim that this is never a template instantiation. */ 2276 DECL_USE_TEMPLATE (decl) = 0; 2277 DECL_TEMPLATE_INFO (decl) = NULL_TREE; 2278 2279 /* Set up clone argument trees for the thunk. */ 2280 parms = TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (parms))); 2281 /* Add this */ 2282 t = build_decl (PARM_DECL, this_identifier, pbasetype); 2283 SET_DECL_ARTIFICIAL (t); 2284 DECL_ARG_TYPE (t) = pbasetype; 2285 DECL_REGISTER (t) = 1; 2286 /* Add __in_charge. */ 2287 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node); 2288 SET_DECL_ARTIFICIAL (parm); 2289 DECL_ARG_TYPE (parm) = integer_type_node; 2290 TREE_CHAIN (parm) = t; 2291 t = parm; 2292 2293 while (parms) 2294 { 2295 tree x = copy_node (parms); 2296 TREE_CHAIN (x) = t; 2297 DECL_CONTEXT (x) = decl; 2298 t = x; 2299 parms = TREE_CHAIN (parms); 2300 } 2301 parms = nreverse (t); 2302 DECL_ARGUMENTS (decl) = parms; 2303 2304 DECL_ASSEMBLER_NAME (decl) 2305 = build_decl_overload (DECL_NAME (decl), 2306 TYPE_ARG_TYPES (TREE_TYPE (decl)), 2); 2307 2308 ctors = CLASSTYPE_METHOD_VEC (basetype); 2309 if (ctors) 2310 ctors = TREE_VEC_ELT (ctors, 0); 2311 for ( ; ctors; ctors = OVL_NEXT (ctors)) 2312 if (DECL_ASSEMBLER_NAME (OVL_CURRENT (ctors)) 2313 == DECL_ASSEMBLER_NAME (decl)) 2314 break; 2315 2316 if (!ctors) 2317 { 2318 add_method (basetype, 0, decl); 2319 cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0, 0); 2320 } 2321 else 2322 decl = OVL_CURRENT (ctors); 2323 2324 /* Remember the original function. */ 2325 DECL_VLIST_CTOR_WRAPPED (decl) = fn; 2326 2327 /* When fn is declared, DECL_INITIAL is null. When it is defined, 2328 DECL_INITIAL will be error_mark_node. */ 2329 if (DECL_INITIAL (fn) == error_mark_node) 2330 { 2331 /* Record that the ctor is being defined, so we also emit the 2332 wrapper later. */ 2333 TREE_USED (decl) = 1; 2334 DECL_NOT_REALLY_EXTERN (decl) = 1; 2335 DECL_INITIAL (decl) = NULL_TREE; 2336 mark_inline_for_output (decl); 2337 } 2338} 2339 2340static void 2341emit_vlist_ctor_wrapper (decl) 2342 tree decl; 2343{ 2344 tree t, parms, fn; 2345 2346 current_function_is_thunk = 1; 2347 2348 parms = DECL_ARGUMENTS (decl); 2349 fn = DECL_VLIST_CTOR_WRAPPED (decl); 2350 mark_used (fn); 2351 2352 /* Build up the call to the real function. */ 2353 t = NULL_TREE; 2354 /* Push this, __in_charge. */ 2355 t = expr_tree_cons (NULL_TREE, parms, t); 2356 parms = TREE_CHAIN (parms); 2357 t = expr_tree_cons (NULL_TREE, parms, t); 2358 parms = TREE_CHAIN (parms); 2359 /* Push 0 as __vlist. */ 2360 t = expr_tree_cons (NULL_TREE, vlist_zero_node, t); 2361 /* Push rest of arguments. */ 2362 while (parms) 2363 { 2364 t = expr_tree_cons (NULL_TREE, parms, t); 2365 parms = TREE_CHAIN (parms); 2366 } 2367 t = nreverse (t); 2368 t = build_call (fn, TREE_TYPE (TREE_TYPE (fn)), t); 2369 expand_expr_stmt (t); 2370} 2371 2372 |
|
2181/* Code for synthesizing methods which have default semantics defined. */ 2182 2183/* For the anonymous union in TYPE, return the member that is at least as 2184 large as the rest of the members, so we can copy it. */ 2185 2186static tree 2187largest_union_member (type) 2188 tree type; --- 18 unchanged lines hidden (view full) --- 2207 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); 2208 tree t; 2209 2210 clear_last_expr (); 2211 push_momentary (); 2212 2213 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) 2214 parm = TREE_CHAIN (parm); | 2373/* Code for synthesizing methods which have default semantics defined. */ 2374 2375/* For the anonymous union in TYPE, return the member that is at least as 2376 large as the rest of the members, so we can copy it. */ 2377 2378static tree 2379largest_union_member (type) 2380 tree type; --- 18 unchanged lines hidden (view full) --- 2399 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); 2400 tree t; 2401 2402 clear_last_expr (); 2403 push_momentary (); 2404 2405 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) 2406 parm = TREE_CHAIN (parm); |
2407 if (TYPE_USES_PVBASES (current_class_type)) 2408 parm = TREE_CHAIN (parm); |
|
2215 parm = convert_from_reference (parm); 2216 2217 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type) 2218 && is_empty_class (current_class_type)) 2219 /* Don't copy the padding byte; it might not have been allocated 2220 if *this is a base subobject. */; 2221 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)) 2222 { --- 180 unchanged lines hidden (view full) --- 2403 2404void 2405synthesize_method (fndecl) 2406 tree fndecl; 2407{ 2408 int nested = (current_function_decl != NULL_TREE); 2409 tree context = hack_decl_function_context (fndecl); 2410 | 2409 parm = convert_from_reference (parm); 2410 2411 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type) 2412 && is_empty_class (current_class_type)) 2413 /* Don't copy the padding byte; it might not have been allocated 2414 if *this is a base subobject. */; 2415 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)) 2416 { --- 180 unchanged lines hidden (view full) --- 2597 2598void 2599synthesize_method (fndecl) 2600 tree fndecl; 2601{ 2602 int nested = (current_function_decl != NULL_TREE); 2603 tree context = hack_decl_function_context (fndecl); 2604 |
2605 /* If this is a wrapper around a undefined vlist ctor, don't emit it 2606 even if it is used. */ 2607 if (DECL_VLIST_CTOR_WRAPPER_P (fndecl)) 2608 { 2609 tree orig_fn = DECL_VLIST_CTOR_WRAPPED (fndecl); 2610 mark_used (orig_fn); 2611 if (DECL_INITIAL (orig_fn) == NULL_TREE) 2612 return; 2613 } 2614 |
|
2411 if (at_eof) 2412 import_export_decl (fndecl); 2413 2414 if (! context) 2415 push_to_top_level (); 2416 else if (nested) 2417 push_cp_function_context (context); 2418 --- 5 unchanged lines hidden (view full) --- 2424 do_build_assign_ref (fndecl); 2425 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) 2426 ; 2427 else 2428 { 2429 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl); 2430 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl)) 2431 arg_chain = TREE_CHAIN (arg_chain); | 2615 if (at_eof) 2616 import_export_decl (fndecl); 2617 2618 if (! context) 2619 push_to_top_level (); 2620 else if (nested) 2621 push_cp_function_context (context); 2622 --- 5 unchanged lines hidden (view full) --- 2628 do_build_assign_ref (fndecl); 2629 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) 2630 ; 2631 else 2632 { 2633 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl); 2634 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl)) 2635 arg_chain = TREE_CHAIN (arg_chain); |
2432 if (arg_chain != void_list_node) | 2636 else if (DECL_CONSTRUCTOR_FOR_PVBASE_P (fndecl)) 2637 arg_chain = TREE_CHAIN (TREE_CHAIN (arg_chain)); 2638 if (DECL_VLIST_CTOR_WRAPPER_P (fndecl)) 2639 emit_vlist_ctor_wrapper (fndecl); 2640 else if (arg_chain != void_list_node) |
2433 do_build_copy_constructor (fndecl); 2434 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type)) 2435 setup_vtbl_ptr (); 2436 } 2437 2438 finish_function (lineno, 0, nested); 2439 2440 extract_interface_info (); 2441 if (! context) 2442 pop_from_top_level (); 2443 else if (nested) 2444 pop_cp_function_context (context); 2445} | 2641 do_build_copy_constructor (fndecl); 2642 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type)) 2643 setup_vtbl_ptr (); 2644 } 2645 2646 finish_function (lineno, 0, nested); 2647 2648 extract_interface_info (); 2649 if (! context) 2650 pop_from_top_level (); 2651 else if (nested) 2652 pop_cp_function_context (context); 2653} |
2654 2655 2656 |
|