Lines Matching full:out
3 use crate::gen::out::OutFile;
19 let out = &mut out_file; in gen() localVariable
21 pick_includes_and_builtins(out, apis); in gen()
22 out.include.extend(&opt.include); in gen()
24 write_forward_declarations(out, apis); in gen()
25 write_data_structures(out, apis); in gen()
26 write_functions(out, apis); in gen()
27 write_generic_instantiations(out); in gen()
29 builtin::write(out); in gen()
30 include::write(out); in gen()
35 fn write_forward_declarations(out: &mut OutFile, apis: &[Api]) { in write_forward_declarations()
38 Api::Enum(enm) => !out.types.cxx.contains(&enm.name.rust), in write_forward_declarations()
45 write(out, &apis_by_namespace, 0); in write_forward_declarations()
47 fn write(out: &mut OutFile, ns_entries: &NamespaceEntries, indent: usize) { in write_forward_declarations()
51 write!(out, "{:1$}", "", indent); in write_forward_declarations()
53 Api::Struct(strct) => write_struct_decl(out, &strct.name), in write_forward_declarations()
54 Api::Enum(enm) => write_enum_decl(out, enm), in write_forward_declarations()
55 Api::CxxType(ety) => write_struct_using(out, &ety.name), in write_forward_declarations()
56 Api::RustType(ety) => write_struct_decl(out, &ety.name), in write_forward_declarations()
62 writeln!(out, "{:2$}namespace {} {{", "", namespace, indent); in write_forward_declarations()
63 write(out, nested_ns_entries, indent + 2); in write_forward_declarations()
64 writeln!(out, "{:1$}}}", "", indent); in write_forward_declarations()
69 fn write_data_structures<'a>(out: &mut OutFile<'a>, apis: &'a [Api]) { in write_data_structures()
83 let mut toposorted_structs = out.types.toposorted_structs.iter(); in write_data_structures()
88 if !out.types.cxx.contains(&strct.name.rust) { in write_data_structures()
89 out.next_section(); in write_data_structures()
94 write_struct(out, next, methods); in write_data_structures()
103 out.next_section(); in write_data_structures()
104 if out.types.cxx.contains(&enm.name.rust) { in write_data_structures()
105 check_enum(out, enm); in write_data_structures()
107 write_enum(out, enm); in write_data_structures()
111 out.next_section(); in write_data_structures()
116 write_opaque_type(out, ety, methods); in write_data_structures()
122 if out.header { in write_data_structures()
126 out.set_namespace(Default::default()); in write_data_structures()
128 out.next_section(); in write_data_structures()
131 if let Some(reasons) = out.types.required_trivial.get(&ety.name.rust) { in write_data_structures()
132 check_trivial_extern_type(out, ety, reasons) in write_data_structures()
138 fn write_functions<'a>(out: &mut OutFile<'a>, apis: &'a [Api]) { in write_functions()
139 if !out.header { in write_functions()
142 Api::Struct(strct) => write_struct_operator_decls(out, strct), in write_functions()
143 Api::RustType(ety) => write_opaque_type_layout_decls(out, ety), in write_functions()
144 Api::CxxFunction(efn) => write_cxx_function_shim(out, efn), in write_functions()
145 Api::RustFunction(efn) => write_rust_function_decl(out, efn), in write_functions()
150 write_std_specializations(out, apis); in write_functions()
155 Api::Struct(strct) => write_struct_operators(out, strct), in write_functions()
156 Api::RustType(ety) => write_opaque_type_layout(out, ety), in write_functions()
158 out.next_section(); in write_functions()
159 write_rust_function_shim(out, efn); in write_functions()
166 fn write_std_specializations(out: &mut OutFile, apis: &[Api]) { in write_std_specializations()
167 out.set_namespace(Default::default()); in write_std_specializations()
168 out.begin_block(Block::Namespace("std")); in write_std_specializations()
173 out.next_section(); in write_std_specializations()
174 out.include.cstddef = true; in write_std_specializations()
175 out.include.functional = true; in write_std_specializations()
177 writeln!(out, "template <> struct hash<{}> {{", qualified); in write_std_specializations()
179 out, in write_std_specializations()
184 write!(out, " return ::"); in write_std_specializations()
186 write!(out, "{}::", name); in write_std_specializations()
188 writeln!(out, "{}(self);", link_name); in write_std_specializations()
189 writeln!(out, " }}"); in write_std_specializations()
190 writeln!(out, "}};"); in write_std_specializations()
195 out.end_block(Block::Namespace("std")); in write_std_specializations()
198 fn pick_includes_and_builtins(out: &mut OutFile, apis: &[Api]) { in pick_includes_and_builtins()
201 out.include.insert(include); in pick_includes_and_builtins()
205 for ty in out.types { in pick_includes_and_builtins()
209 | Some(I64) => out.include.cstdint = true, in pick_includes_and_builtins()
210 Some(Usize) => out.include.cstddef = true, in pick_includes_and_builtins()
211 Some(Isize) => out.builtin.rust_isize = true, in pick_includes_and_builtins()
212 Some(CxxString) => out.include.string = true, in pick_includes_and_builtins()
213 Some(RustString) => out.builtin.rust_string = true, in pick_includes_and_builtins()
216 Type::RustBox(_) => out.builtin.rust_box = true, in pick_includes_and_builtins()
217 Type::RustVec(_) => out.builtin.rust_vec = true, in pick_includes_and_builtins()
218 Type::UniquePtr(_) => out.include.memory = true, in pick_includes_and_builtins()
219 Type::SharedPtr(_) | Type::WeakPtr(_) => out.include.memory = true, in pick_includes_and_builtins()
220 Type::Str(_) => out.builtin.rust_str = true, in pick_includes_and_builtins()
221 Type::CxxVector(_) => out.include.vector = true, in pick_includes_and_builtins()
222 Type::Fn(_) => out.builtin.rust_fn = true, in pick_includes_and_builtins()
223 Type::SliceRef(_) => out.builtin.rust_slice = true, in pick_includes_and_builtins()
224 Type::Array(_) => out.include.array = true, in pick_includes_and_builtins()
230 fn write_struct<'a>(out: &mut OutFile<'a>, strct: &'a Struct, methods: &[&ExternFn]) { in write_struct()
234 out.set_namespace(&strct.name.namespace); in write_struct()
236 writeln!(out, "#ifndef {}", guard); in write_struct()
237 writeln!(out, "#define {}", guard); in write_struct()
239 writeln!(out, "//{}", line); in write_struct()
241 writeln!(out, "struct {} final {{", strct.name.cxx); in write_struct()
245 writeln!(out, " //{}", line); in write_struct()
247 write!(out, " "); in write_struct()
248 write_type_space(out, &field.ty); in write_struct()
249 writeln!(out, "{};", field.name.cxx); in write_struct()
252 writeln!(out); in write_struct()
255 write!(out, " "); in write_struct()
258 write_rust_function_shim_decl(out, &local_name, sig, false); in write_struct()
259 writeln!(out, ";"); in write_struct()
264 out, in write_struct()
269 out, in write_struct()
277 out, in write_struct()
282 out, in write_struct()
287 out, in write_struct()
292 out, in write_struct()
298 out.include.type_traits = true; in write_struct()
299 writeln!(out, " using IsRelocatable = ::std::true_type;"); in write_struct()
301 writeln!(out, "}};"); in write_struct()
302 writeln!(out, "#endif // {}", guard); in write_struct()
305 fn write_struct_decl(out: &mut OutFile, ident: &Pair) { in write_struct_decl()
306 writeln!(out, "struct {};", ident.cxx); in write_struct_decl()
309 fn write_enum_decl(out: &mut OutFile, enm: &Enum) { in write_enum_decl()
310 write!(out, "enum class {} : ", enm.name.cxx); in write_enum_decl()
311 write_atom(out, enm.repr); in write_enum_decl()
312 writeln!(out, ";"); in write_enum_decl()
315 fn write_struct_using(out: &mut OutFile, ident: &Pair) { in write_struct_using()
316 writeln!(out, "using {} = {};", ident.cxx, ident.to_fully_qualified()); in write_struct_using()
319 fn write_opaque_type<'a>(out: &mut OutFile<'a>, ety: &'a ExternType, methods: &[&ExternFn]) { in write_opaque_type()
320 out.set_namespace(&ety.name.namespace); in write_opaque_type()
322 writeln!(out, "#ifndef {}", guard); in write_opaque_type()
323 writeln!(out, "#define {}", guard); in write_opaque_type()
325 writeln!(out, "//{}", line); in write_opaque_type()
328 out.builtin.opaque = true; in write_opaque_type()
330 out, in write_opaque_type()
336 write!(out, " "); in write_opaque_type()
339 write_rust_function_shim_decl(out, &local_name, sig, false); in write_opaque_type()
340 writeln!(out, ";"); in write_opaque_type()
343 writeln!(out, " ~{}() = delete;", ety.name.cxx); in write_opaque_type()
344 writeln!(out); in write_opaque_type()
346 out.builtin.layout = true; in write_opaque_type()
347 out.include.cstddef = true; in write_opaque_type()
348 writeln!(out, "private:"); in write_opaque_type()
349 writeln!(out, " friend ::rust::layout;"); in write_opaque_type()
350 writeln!(out, " struct layout {{"); in write_opaque_type()
351 writeln!(out, " static ::std::size_t size() noexcept;"); in write_opaque_type()
352 writeln!(out, " static ::std::size_t align() noexcept;"); in write_opaque_type()
353 writeln!(out, " }};"); in write_opaque_type()
354 writeln!(out, "}};"); in write_opaque_type()
355 writeln!(out, "#endif // {}", guard); in write_opaque_type()
358 fn write_enum<'a>(out: &mut OutFile<'a>, enm: &'a Enum) { in write_enum()
359 out.set_namespace(&enm.name.namespace); in write_enum()
361 writeln!(out, "#ifndef {}", guard); in write_enum()
362 writeln!(out, "#define {}", guard); in write_enum()
364 writeln!(out, "//{}", line); in write_enum()
366 write!(out, "enum class {} : ", enm.name.cxx); in write_enum()
367 write_atom(out, enm.repr); in write_enum()
368 writeln!(out, " {{"); in write_enum()
371 writeln!(out, " //{}", line); in write_enum()
373 writeln!(out, " {} = {},", variant.name.cxx, variant.discriminant); in write_enum()
375 writeln!(out, "}};"); in write_enum()
376 writeln!(out, "#endif // {}", guard); in write_enum()
379 fn check_enum<'a>(out: &mut OutFile<'a>, enm: &'a Enum) { in check_enum()
380 out.set_namespace(&enm.name.namespace); in check_enum()
381 out.include.type_traits = true; in check_enum()
383 out, in check_enum()
387 write!(out, "static_assert(sizeof({}) == sizeof(", enm.name.cxx); in check_enum()
388 write_atom(out, enm.repr); in check_enum()
389 writeln!(out, "), \"incorrect size\");"); in check_enum()
391 write!(out, "static_assert(static_cast<"); in check_enum()
392 write_atom(out, enm.repr); in check_enum()
394 out, in check_enum()
401 fn check_trivial_extern_type(out: &mut OutFile, alias: &TypeAlias, reasons: &[TrivialReason]) { in check_trivial_extern_type()
417 // There may be legitimate reasons to opt out of this assertion for support in check_trivial_extern_type()
420 // or destructor. To opt out of the relocatability check, they need to do in check_trivial_extern_type()
436 out.builtin.relocatable = true; in check_trivial_extern_type()
437 writeln!(out, "static_assert("); in check_trivial_extern_type()
438 writeln!(out, " ::rust::IsRelocatable<{}>::value,", id); in check_trivial_extern_type()
440 out, in check_trivial_extern_type()
447 fn write_struct_operator_decls<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { in write_struct_operator_decls()
448 out.set_namespace(&strct.name.namespace); in write_struct_operator_decls()
449 out.begin_block(Block::ExternC); in write_struct_operator_decls()
454 out, in write_struct_operator_decls()
462 out, in write_struct_operator_decls()
472 out, in write_struct_operator_decls()
479 out, in write_struct_operator_decls()
487 out, in write_struct_operator_decls()
494 out, in write_struct_operator_decls()
502 out.include.cstddef = true; in write_struct_operator_decls()
505 out, in write_struct_operator_decls()
511 out.end_block(Block::ExternC); in write_struct_operator_decls()
514 fn write_struct_operators<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { in write_struct_operators()
515 if out.header { in write_struct_operators()
519 out.set_namespace(&strct.name.namespace); in write_struct_operators()
522 out.next_section(); in write_struct_operators()
524 out, in write_struct_operators()
529 writeln!(out, " return {}(*this, rhs);", link_name); in write_struct_operators()
530 writeln!(out, "}}"); in write_struct_operators()
532 out.next_section(); in write_struct_operators()
534 out, in write_struct_operators()
539 writeln!(out, " return !(*this == rhs);"); in write_struct_operators()
542 writeln!(out, " return {}(*this, rhs);", link_name); in write_struct_operators()
544 writeln!(out, "}}"); in write_struct_operators()
548 out.next_section(); in write_struct_operators()
550 out, in write_struct_operators()
555 writeln!(out, " return {}(*this, rhs);", link_name); in write_struct_operators()
556 writeln!(out, "}}"); in write_struct_operators()
558 out.next_section(); in write_struct_operators()
560 out, in write_struct_operators()
565 writeln!(out, " return {}(*this, rhs);", link_name); in write_struct_operators()
566 writeln!(out, "}}"); in write_struct_operators()
568 out.next_section(); in write_struct_operators()
570 out, in write_struct_operators()
575 writeln!(out, " return !(*this <= rhs);"); in write_struct_operators()
578 writeln!(out, " return {}(*this, rhs);", link_name); in write_struct_operators()
580 writeln!(out, "}}"); in write_struct_operators()
582 out.next_section(); in write_struct_operators()
584 out, in write_struct_operators()
589 writeln!(out, " return !(*this < rhs);"); in write_struct_operators()
592 writeln!(out, " return {}(*this, rhs);", link_name); in write_struct_operators()
594 writeln!(out, "}}"); in write_struct_operators()
598 fn write_opaque_type_layout_decls<'a>(out: &mut OutFile<'a>, ety: &'a ExternType) { in write_opaque_type_layout_decls()
599 out.set_namespace(&ety.name.namespace); in write_opaque_type_layout_decls()
600 out.begin_block(Block::ExternC); in write_opaque_type_layout_decls()
603 writeln!(out, "::std::size_t {}() noexcept;", link_name); in write_opaque_type_layout_decls()
606 writeln!(out, "::std::size_t {}() noexcept;", link_name); in write_opaque_type_layout_decls()
608 out.end_block(Block::ExternC); in write_opaque_type_layout_decls()
611 fn write_opaque_type_layout<'a>(out: &mut OutFile<'a>, ety: &'a ExternType) { in write_opaque_type_layout()
612 if out.header { in write_opaque_type_layout()
616 out.set_namespace(&ety.name.namespace); in write_opaque_type_layout()
618 out.next_section(); in write_opaque_type_layout()
621 out, in write_opaque_type_layout()
625 writeln!(out, " return {}();", link_name); in write_opaque_type_layout()
626 writeln!(out, "}}"); in write_opaque_type_layout()
628 out.next_section(); in write_opaque_type_layout()
631 out, in write_opaque_type_layout()
635 writeln!(out, " return {}();", link_name); in write_opaque_type_layout()
636 writeln!(out, "}}"); in write_opaque_type_layout()
639 fn begin_function_definition(out: &mut OutFile) { in begin_function_definition()
640 if let Some(annotation) = &out.opt.cxx_impl_annotations { in begin_function_definition()
641 write!(out, "{} ", annotation); in begin_function_definition()
645 fn write_cxx_function_shim<'a>(out: &mut OutFile<'a>, efn: &'a ExternFn) { in write_cxx_function_shim()
646 out.next_section(); in write_cxx_function_shim()
647 out.set_namespace(&efn.name.namespace); in write_cxx_function_shim()
648 out.begin_block(Block::ExternC); in write_cxx_function_shim()
649 begin_function_definition(out); in write_cxx_function_shim()
651 out.builtin.ptr_len = true; in write_cxx_function_shim()
652 write!(out, "::rust::repr::PtrLen "); in write_cxx_function_shim()
654 write_extern_return_type_space(out, &efn.ret); in write_cxx_function_shim()
656 let mangled = mangle::extern_fn(efn, out.types); in write_cxx_function_shim()
657 write!(out, "{}(", mangled); in write_cxx_function_shim()
660 write!(out, "const "); in write_cxx_function_shim()
663 out, in write_cxx_function_shim()
665 out.types.resolve(&receiver.ty).name.to_fully_qualified(), in write_cxx_function_shim()
670 write!(out, ", "); in write_cxx_function_shim()
673 write!(out, "const "); in write_cxx_function_shim()
675 write!(out, "const "); in write_cxx_function_shim()
677 write_extern_arg(out, arg); in write_cxx_function_shim()
679 let indirect_return = indirect_return(efn, out.types); in write_cxx_function_shim()
682 write!(out, ", "); in write_cxx_function_shim()
684 write_indirect_return_type_space(out, efn.ret.as_ref().unwrap()); in write_cxx_function_shim()
685 write!(out, "*return$"); in write_cxx_function_shim()
687 writeln!(out, ") noexcept {{"); in write_cxx_function_shim()
688 write!(out, " "); in write_cxx_function_shim()
689 write_return_type(out, &efn.ret); in write_cxx_function_shim()
691 None => write!(out, "(*{}$)(", efn.name.rust), in write_cxx_function_shim()
693 out, in write_cxx_function_shim()
695 out.types.resolve(&receiver.ty).name.to_fully_qualified(), in write_cxx_function_shim()
701 write!(out, ", "); in write_cxx_function_shim()
703 write_type(out, &arg.ty); in write_cxx_function_shim()
705 write!(out, ")"); in write_cxx_function_shim()
708 write!(out, " const"); in write_cxx_function_shim()
711 write!(out, " = "); in write_cxx_function_shim()
713 None => write!(out, "{}", efn.name.to_fully_qualified()), in write_cxx_function_shim()
715 out, in write_cxx_function_shim()
717 out.types.resolve(&receiver.ty).name.to_fully_qualified(), in write_cxx_function_shim()
721 writeln!(out, ";"); in write_cxx_function_shim()
722 write!(out, " "); in write_cxx_function_shim()
724 out.builtin.ptr_len = true; in write_cxx_function_shim()
725 out.builtin.trycatch = true; in write_cxx_function_shim()
726 writeln!(out, "::rust::repr::PtrLen throw$;"); in write_cxx_function_shim()
727 writeln!(out, " ::rust::behavior::trycatch("); in write_cxx_function_shim()
728 writeln!(out, " [&] {{"); in write_cxx_function_shim()
729 write!(out, " "); in write_cxx_function_shim()
732 out.include.new = true; in write_cxx_function_shim()
733 write!(out, "new (return$) "); in write_cxx_function_shim()
734 write_indirect_return_type(out, efn.ret.as_ref().unwrap()); in write_cxx_function_shim()
735 write!(out, "("); in write_cxx_function_shim()
737 write!(out, "return "); in write_cxx_function_shim()
740 Some(Type::Ref(_)) => write!(out, "&"), in write_cxx_function_shim()
742 out.builtin.rust_str_repr = true; in write_cxx_function_shim()
743 write!(out, "::rust::impl<::rust::Str>::repr("); in write_cxx_function_shim()
746 out.builtin.rust_slice_repr = true; in write_cxx_function_shim()
747 write!(out, "::rust::impl<"); in write_cxx_function_shim()
748 write_type(out, ty); in write_cxx_function_shim()
749 write!(out, ">::repr("); in write_cxx_function_shim()
754 None => write!(out, "{}$(", efn.name.rust), in write_cxx_function_shim()
755 Some(_) => write!(out, "(self.*{}$)(", efn.name.rust), in write_cxx_function_shim()
759 write!(out, ", "); in write_cxx_function_shim()
762 write_type(out, &arg.ty); in write_cxx_function_shim()
763 write!(out, "::from_raw({})", arg.name.cxx); in write_cxx_function_shim()
765 write_type(out, &arg.ty); in write_cxx_function_shim()
766 write!(out, "({})", arg.name.cxx); in write_cxx_function_shim()
768 out.builtin.unsafe_bitcopy = true; in write_cxx_function_shim()
770 out, in write_cxx_function_shim()
775 out.builtin.unsafe_bitcopy = true; in write_cxx_function_shim()
776 write_type(out, &arg.ty); in write_cxx_function_shim()
777 write!(out, "(::rust::unsafe_bitcopy, *{})", arg.name.cxx); in write_cxx_function_shim()
778 } else if out.types.needs_indirect_abi(&arg.ty) { in write_cxx_function_shim()
779 out.include.utility = true; in write_cxx_function_shim()
780 write!(out, "::std::move(*{})", arg.name.cxx); in write_cxx_function_shim()
782 write!(out, "{}", arg.name.cxx); in write_cxx_function_shim()
785 write!(out, ")"); in write_cxx_function_shim()
787 Some(Type::RustBox(_)) => write!(out, ".into_raw()"), in write_cxx_function_shim()
788 Some(Type::UniquePtr(_)) => write!(out, ".release()"), in write_cxx_function_shim()
789 Some(Type::Str(_)) | Some(Type::SliceRef(_)) if !indirect_return => write!(out, ")"), in write_cxx_function_shim()
793 write!(out, ")"); in write_cxx_function_shim()
795 writeln!(out, ";"); in write_cxx_function_shim()
797 out.include.cstring = true; in write_cxx_function_shim()
798 out.builtin.exception = true; in write_cxx_function_shim()
799 writeln!(out, " throw$.ptr = nullptr;"); in write_cxx_function_shim()
800 writeln!(out, " }},"); in write_cxx_function_shim()
801 writeln!(out, " [&](const char *catch$) noexcept {{"); in write_cxx_function_shim()
802 writeln!(out, " throw$.len = ::std::strlen(catch$);"); in write_cxx_function_shim()
804 out, in write_cxx_function_shim()
807 writeln!(out, " }});"); in write_cxx_function_shim()
808 writeln!(out, " return throw$;"); in write_cxx_function_shim()
810 writeln!(out, "}}"); in write_cxx_function_shim()
814 write_function_pointer_trampoline(out, efn, var, f); in write_cxx_function_shim()
817 out.end_block(Block::ExternC); in write_cxx_function_shim()
820 fn write_function_pointer_trampoline(out: &mut OutFile, efn: &ExternFn, var: &Pair, f: &Signature) { in write_function_pointer_trampoline()
821 let r_trampoline = mangle::r_trampoline(efn, var, out.types); in write_function_pointer_trampoline()
823 write_rust_function_decl_impl(out, &r_trampoline, f, indirect_call); in write_function_pointer_trampoline()
825 out.next_section(); in write_function_pointer_trampoline()
826 let c_trampoline = mangle::c_trampoline(efn, var, out.types).to_string(); in write_function_pointer_trampoline()
827 write_rust_function_shim_impl(out, &c_trampoline, f, &r_trampoline, indirect_call); in write_function_pointer_trampoline()
830 fn write_rust_function_decl<'a>(out: &mut OutFile<'a>, efn: &'a ExternFn) { in write_rust_function_decl()
831 out.set_namespace(&efn.name.namespace); in write_rust_function_decl()
832 out.begin_block(Block::ExternC); in write_rust_function_decl()
833 let link_name = mangle::extern_fn(efn, out.types); in write_rust_function_decl()
835 write_rust_function_decl_impl(out, &link_name, efn, indirect_call); in write_rust_function_decl()
836 out.end_block(Block::ExternC); in write_rust_function_decl()
840 out: &mut OutFile, in write_rust_function_decl_impl()
845 out.next_section(); in write_rust_function_decl_impl()
847 out.builtin.ptr_len = true; in write_rust_function_decl_impl()
848 write!(out, "::rust::repr::PtrLen "); in write_rust_function_decl_impl()
850 write_extern_return_type_space(out, &sig.ret); in write_rust_function_decl_impl()
852 write!(out, "{}(", link_name); in write_rust_function_decl_impl()
856 write!(out, "const "); in write_rust_function_decl_impl()
859 out, in write_rust_function_decl_impl()
861 out.types.resolve(&receiver.ty).name.to_fully_qualified(), in write_rust_function_decl_impl()
867 write!(out, ", "); in write_rust_function_decl_impl()
869 write_extern_arg(out, arg); in write_rust_function_decl_impl()
872 if indirect_return(sig, out.types) { in write_rust_function_decl_impl()
874 write!(out, ", "); in write_rust_function_decl_impl()
878 write_pointee_type(out, &ret.inner, ret.mutable); in write_rust_function_decl_impl()
879 write!(out, " *"); in write_rust_function_decl_impl()
881 ret => write_type_space(out, ret), in write_rust_function_decl_impl()
883 write!(out, "*return$"); in write_rust_function_decl_impl()
888 write!(out, ", "); in write_rust_function_decl_impl()
890 write!(out, "void *"); in write_rust_function_decl_impl()
892 writeln!(out, ") noexcept;"); in write_rust_function_decl_impl()
895 fn write_rust_function_shim<'a>(out: &mut OutFile<'a>, efn: &'a ExternFn) { in write_rust_function_shim()
896 out.set_namespace(&efn.name.namespace); in write_rust_function_shim()
898 writeln!(out, "//{}", line); in write_rust_function_shim()
904 out.types.resolve(&receiver.ty).name.cxx, in write_rust_function_shim()
908 let invoke = mangle::extern_fn(efn, out.types); in write_rust_function_shim()
910 write_rust_function_shim_impl(out, &local_name, efn, &invoke, indirect_call); in write_rust_function_shim()
914 out: &mut OutFile, in write_rust_function_shim_decl()
919 begin_function_definition(out); in write_rust_function_shim_decl()
920 write_return_type(out, &sig.ret); in write_rust_function_shim_decl()
921 write!(out, "{}(", local_name); in write_rust_function_shim_decl()
924 write!(out, ", "); in write_rust_function_shim_decl()
926 write_type_space(out, &arg.ty); in write_rust_function_shim_decl()
927 write!(out, "{}", arg.name.cxx); in write_rust_function_shim_decl()
931 write!(out, ", "); in write_rust_function_shim_decl()
933 write!(out, "void *extern$"); in write_rust_function_shim_decl()
935 write!(out, ")"); in write_rust_function_shim_decl()
938 write!(out, " const"); in write_rust_function_shim_decl()
942 write!(out, " noexcept"); in write_rust_function_shim_decl()
947 out: &mut OutFile, in write_rust_function_shim_impl()
953 if out.header && sig.receiver.is_some() { in write_rust_function_shim_impl()
957 write_rust_function_shim_decl(out, local_name, sig, indirect_call); in write_rust_function_shim_impl()
958 if out.header { in write_rust_function_shim_impl()
959 writeln!(out, ";"); in write_rust_function_shim_impl()
962 writeln!(out, " {{"); in write_rust_function_shim_impl()
964 if arg.ty != RustString && out.types.needs_indirect_abi(&arg.ty) { in write_rust_function_shim_impl()
965 out.include.utility = true; in write_rust_function_shim_impl()
966 out.builtin.manually_drop = true; in write_rust_function_shim_impl()
967 write!(out, " ::rust::ManuallyDrop<"); in write_rust_function_shim_impl()
968 write_type(out, &arg.ty); in write_rust_function_shim_impl()
969 writeln!(out, "> {}$(::std::move({0}));", arg.name.cxx); in write_rust_function_shim_impl()
972 write!(out, " "); in write_rust_function_shim_impl()
973 let indirect_return = indirect_return(sig, out.types); in write_rust_function_shim_impl()
975 out.builtin.maybe_uninit = true; in write_rust_function_shim_impl()
976 write!(out, "::rust::MaybeUninit<"); in write_rust_function_shim_impl()
979 write_pointee_type(out, &ret.inner, ret.mutable); in write_rust_function_shim_impl()
980 write!(out, " *"); in write_rust_function_shim_impl()
982 ret => write_type(out, ret), in write_rust_function_shim_impl()
984 writeln!(out, "> return$;"); in write_rust_function_shim_impl()
985 write!(out, " "); in write_rust_function_shim_impl()
987 write!(out, "return "); in write_rust_function_shim_impl()
990 write_type(out, ret); in write_rust_function_shim_impl()
991 write!(out, "::from_raw("); in write_rust_function_shim_impl()
994 write_type(out, ret); in write_rust_function_shim_impl()
995 write!(out, "("); in write_rust_function_shim_impl()
997 Type::Ref(_) => write!(out, "*"), in write_rust_function_shim_impl()
999 out.builtin.rust_str_new_unchecked = true; in write_rust_function_shim_impl()
1000 write!(out, "::rust::impl<::rust::Str>::new_unchecked("); in write_rust_function_shim_impl()
1003 out.builtin.rust_slice_new = true; in write_rust_function_shim_impl()
1004 write!(out, "::rust::impl<"); in write_rust_function_shim_impl()
1005 write_type(out, ret); in write_rust_function_shim_impl()
1006 write!(out, ">::slice("); in write_rust_function_shim_impl()
1012 out.builtin.ptr_len = true; in write_rust_function_shim_impl()
1013 write!(out, "::rust::repr::PtrLen error$ = "); in write_rust_function_shim_impl()
1015 write!(out, "{}(", invoke); in write_rust_function_shim_impl()
1018 write!(out, "*this"); in write_rust_function_shim_impl()
1023 write!(out, ", "); in write_rust_function_shim_impl()
1025 if out.types.needs_indirect_abi(&arg.ty) { in write_rust_function_shim_impl()
1026 write!(out, "&"); in write_rust_function_shim_impl()
1028 write!(out, "{}", arg.name.cxx); in write_rust_function_shim_impl()
1030 Type::RustBox(_) => write!(out, ".into_raw()"), in write_rust_function_shim_impl()
1031 Type::UniquePtr(_) => write!(out, ".release()"), in write_rust_function_shim_impl()
1032 ty if ty != RustString && out.types.needs_indirect_abi(ty) => write!(out, "$.value"), in write_rust_function_shim_impl()
1039 write!(out, ", "); in write_rust_function_shim_impl()
1041 write!(out, "&return$.value"); in write_rust_function_shim_impl()
1046 write!(out, ", "); in write_rust_function_shim_impl()
1048 write!(out, "extern$"); in write_rust_function_shim_impl()
1050 write!(out, ")"); in write_rust_function_shim_impl()
1054 write!(out, ")"); in write_rust_function_shim_impl()
1058 writeln!(out, ";"); in write_rust_function_shim_impl()
1060 out.builtin.rust_error = true; in write_rust_function_shim_impl()
1061 writeln!(out, " if (error$.ptr) {{"); in write_rust_function_shim_impl()
1062 writeln!(out, " throw ::rust::impl<::rust::Error>::error(error$);"); in write_rust_function_shim_impl()
1063 writeln!(out, " }}"); in write_rust_function_shim_impl()
1066 write!(out, " return "); in write_rust_function_shim_impl()
1068 Type::Ref(_) => write!(out, "*return$.value"), in write_rust_function_shim_impl()
1070 out.include.utility = true; in write_rust_function_shim_impl()
1071 write!(out, "::std::move(return$.value)"); in write_rust_function_shim_impl()
1074 writeln!(out, ";"); in write_rust_function_shim_impl()
1076 writeln!(out, "}}"); in write_rust_function_shim_impl()
1079 fn write_return_type(out: &mut OutFile, ty: &Option<Type>) { in write_return_type()
1081 None => write!(out, "void "), in write_return_type()
1082 Some(ty) => write_type_space(out, ty), in write_return_type()
1092 fn write_indirect_return_type(out: &mut OutFile, ty: &Type) { in write_indirect_return_type()
1095 write_type_space(out, &ty.inner); in write_indirect_return_type()
1096 write!(out, "*"); in write_indirect_return_type()
1100 write!(out, "const "); in write_indirect_return_type()
1102 write_type(out, &ty.inner); in write_indirect_return_type()
1103 write!(out, " *"); in write_indirect_return_type()
1105 _ => write_type(out, ty), in write_indirect_return_type()
1109 fn write_indirect_return_type_space(out: &mut OutFile, ty: &Type) { in write_indirect_return_type_space()
1110 write_indirect_return_type(out, ty); in write_indirect_return_type_space()
1113 Type::Str(_) | Type::SliceRef(_) => write!(out, " "), in write_indirect_return_type_space()
1114 _ => write_space_after_type(out, ty), in write_indirect_return_type_space()
1118 fn write_extern_return_type_space(out: &mut OutFile, ty: &Option<Type>) { in write_extern_return_type_space()
1121 write_type_space(out, &ty.inner); in write_extern_return_type_space()
1122 write!(out, "*"); in write_extern_return_type_space()
1126 write!(out, "const "); in write_extern_return_type_space()
1128 write_type(out, &ty.inner); in write_extern_return_type_space()
1129 write!(out, " *"); in write_extern_return_type_space()
1132 out.builtin.repr_fat = true; in write_extern_return_type_space()
1133 write!(out, "::rust::repr::Fat "); in write_extern_return_type_space()
1135 Some(ty) if out.types.needs_indirect_abi(ty) => write!(out, "void "), in write_extern_return_type_space()
1136 _ => write_return_type(out, ty), in write_extern_return_type_space()
1140 fn write_extern_arg(out: &mut OutFile, arg: &Var) { in write_extern_arg()
1143 write_type_space(out, &ty.inner); in write_extern_arg()
1144 write!(out, "*"); in write_extern_arg()
1146 _ => write_type_space(out, &arg.ty), in write_extern_arg()
1148 if out.types.needs_indirect_abi(&arg.ty) { in write_extern_arg()
1149 write!(out, "*"); in write_extern_arg()
1151 write!(out, "{}", arg.name.cxx); in write_extern_arg()
1154 fn write_type(out: &mut OutFile, ty: &Type) { in write_type()
1157 Some(atom) => write_atom(out, atom), in write_type()
1159 out, in write_type()
1161 out.types.resolve(ident).name.to_fully_qualified(), in write_type()
1165 write!(out, "::rust::Box<"); in write_type()
1166 write_type(out, &ty.inner); in write_type()
1167 write!(out, ">"); in write_type()
1170 write!(out, "::rust::Vec<"); in write_type()
1171 write_type(out, &ty.inner); in write_type()
1172 write!(out, ">"); in write_type()
1175 write!(out, "::std::unique_ptr<"); in write_type()
1176 write_type(out, &ptr.inner); in write_type()
1177 write!(out, ">"); in write_type()
1180 write!(out, "::std::shared_ptr<"); in write_type()
1181 write_type(out, &ptr.inner); in write_type()
1182 write!(out, ">"); in write_type()
1185 write!(out, "::std::weak_ptr<"); in write_type()
1186 write_type(out, &ptr.inner); in write_type()
1187 write!(out, ">"); in write_type()
1190 write!(out, "::std::vector<"); in write_type()
1191 write_type(out, &ty.inner); in write_type()
1192 write!(out, ">"); in write_type()
1195 write_pointee_type(out, &r.inner, r.mutable); in write_type()
1196 write!(out, " &"); in write_type()
1199 write_pointee_type(out, &p.inner, p.mutable); in write_type()
1200 write!(out, " *"); in write_type()
1203 write!(out, "::rust::Str"); in write_type()
1206 write!(out, "::rust::Slice<"); in write_type()
1208 write!(out, "const "); in write_type()
1210 write_type(out, &slice.inner); in write_type()
1211 write!(out, ">"); in write_type()
1214 write!(out, "::rust::Fn<"); in write_type()
1216 Some(ret) => write_type(out, ret), in write_type()
1217 None => write!(out, "void"), in write_type()
1219 write!(out, "("); in write_type()
1222 write!(out, ", "); in write_type()
1224 write_type(out, &arg.ty); in write_type()
1226 write!(out, ")>"); in write_type()
1229 write!(out, "::std::array<"); in write_type()
1230 write_type(out, &a.inner); in write_type()
1231 write!(out, ", {}>", &a.len); in write_type()
1238 fn write_pointee_type(out: &mut OutFile, inner: &Type, mutable: bool) { in write_pointee_type()
1240 write_type_space(out, inner); in write_pointee_type()
1242 write!(out, "const"); in write_pointee_type()
1246 write!(out, "const "); in write_pointee_type()
1248 write_type(out, inner); in write_pointee_type()
1252 fn write_atom(out: &mut OutFile, atom: Atom) { in write_atom()
1254 Bool => write!(out, "bool"), in write_atom()
1255 Char => write!(out, "char"), in write_atom()
1256 U8 => write!(out, "::std::uint8_t"), in write_atom()
1257 U16 => write!(out, "::std::uint16_t"), in write_atom()
1258 U32 => write!(out, "::std::uint32_t"), in write_atom()
1259 U64 => write!(out, "::std::uint64_t"), in write_atom()
1260 Usize => write!(out, "::std::size_t"), in write_atom()
1261 I8 => write!(out, "::std::int8_t"), in write_atom()
1262 I16 => write!(out, "::std::int16_t"), in write_atom()
1263 I32 => write!(out, "::std::int32_t"), in write_atom()
1264 I64 => write!(out, "::std::int64_t"), in write_atom()
1265 Isize => write!(out, "::rust::isize"), in write_atom()
1266 F32 => write!(out, "float"), in write_atom()
1267 F64 => write!(out, "double"), in write_atom()
1268 CxxString => write!(out, "::std::string"), in write_atom()
1269 RustString => write!(out, "::rust::String"), in write_atom()
1273 fn write_type_space(out: &mut OutFile, ty: &Type) { in write_type_space()
1274 write_type(out, ty); in write_type_space()
1275 write_space_after_type(out, ty); in write_type_space()
1278 fn write_space_after_type(out: &mut OutFile, ty: &Type) { in write_space_after_type()
1290 | Type::Array(_) => write!(out, " "), in write_space_after_type()
1342 fn write_generic_instantiations(out: &mut OutFile) { in write_generic_instantiations()
1343 if out.header { in write_generic_instantiations()
1347 out.next_section(); in write_generic_instantiations()
1348 out.set_namespace(Default::default()); in write_generic_instantiations()
1349 out.begin_block(Block::ExternC); in write_generic_instantiations()
1350 for impl_key in out.types.impls.keys() { in write_generic_instantiations()
1351 out.next_section(); in write_generic_instantiations()
1353 ImplKey::RustBox(ident) => write_rust_box_extern(out, ident), in write_generic_instantiations()
1354 ImplKey::RustVec(ident) => write_rust_vec_extern(out, ident), in write_generic_instantiations()
1355 ImplKey::UniquePtr(ident) => write_unique_ptr(out, ident), in write_generic_instantiations()
1356 ImplKey::SharedPtr(ident) => write_shared_ptr(out, ident), in write_generic_instantiations()
1357 ImplKey::WeakPtr(ident) => write_weak_ptr(out, ident), in write_generic_instantiations()
1358 ImplKey::CxxVector(ident) => write_cxx_vector(out, ident), in write_generic_instantiations()
1361 out.end_block(Block::ExternC); in write_generic_instantiations()
1363 out.begin_block(Block::Namespace("rust")); in write_generic_instantiations()
1364 out.begin_block(Block::InlineNamespace("cxxbridge1")); in write_generic_instantiations()
1365 for impl_key in out.types.impls.keys() { in write_generic_instantiations()
1367 ImplKey::RustBox(ident) => write_rust_box_impl(out, ident), in write_generic_instantiations()
1368 ImplKey::RustVec(ident) => write_rust_vec_impl(out, ident), in write_generic_instantiations()
1372 out.end_block(Block::InlineNamespace("cxxbridge1")); in write_generic_instantiations()
1373 out.end_block(Block::Namespace("rust")); in write_generic_instantiations()
1376 fn write_rust_box_extern(out: &mut OutFile, key: NamedImplKey) { in write_rust_box_extern()
1377 let resolve = out.types.resolve(&key); in write_rust_box_extern()
1382 out, in write_rust_box_extern()
1387 out, in write_rust_box_extern()
1392 out, in write_rust_box_extern()
1398 fn write_rust_vec_extern(out: &mut OutFile, key: NamedImplKey) { in write_rust_vec_extern()
1400 let inner = element.to_typename(out.types); in write_rust_vec_extern()
1401 let instance = element.to_mangled(out.types); in write_rust_vec_extern()
1403 out.include.cstddef = true; in write_rust_vec_extern()
1406 out, in write_rust_vec_extern()
1411 out, in write_rust_vec_extern()
1416 out, in write_rust_vec_extern()
1421 out, in write_rust_vec_extern()
1426 out, in write_rust_vec_extern()
1431 out, in write_rust_vec_extern()
1436 out, in write_rust_vec_extern()
1442 fn write_rust_box_impl(out: &mut OutFile, key: NamedImplKey) { in write_rust_box_impl()
1443 let resolve = out.types.resolve(&key); in write_rust_box_impl()
1447 writeln!(out, "template <>"); in write_rust_box_impl()
1448 begin_function_definition(out); in write_rust_box_impl()
1450 out, in write_rust_box_impl()
1454 writeln!(out, " return cxxbridge1$box${}$alloc();", instance); in write_rust_box_impl()
1455 writeln!(out, "}}"); in write_rust_box_impl()
1457 writeln!(out, "template <>"); in write_rust_box_impl()
1458 begin_function_definition(out); in write_rust_box_impl()
1460 out, in write_rust_box_impl()
1464 writeln!(out, " cxxbridge1$box${}$dealloc(ptr);", instance); in write_rust_box_impl()
1465 writeln!(out, "}}"); in write_rust_box_impl()
1467 writeln!(out, "template <>"); in write_rust_box_impl()
1468 begin_function_definition(out); in write_rust_box_impl()
1469 writeln!(out, "void Box<{}>::drop() noexcept {{", inner); in write_rust_box_impl()
1470 writeln!(out, " cxxbridge1$box${}$drop(this);", instance); in write_rust_box_impl()
1471 writeln!(out, "}}"); in write_rust_box_impl()
1474 fn write_rust_vec_impl(out: &mut OutFile, key: NamedImplKey) { in write_rust_vec_impl()
1476 let inner = element.to_typename(out.types); in write_rust_vec_impl()
1477 let instance = element.to_mangled(out.types); in write_rust_vec_impl()
1479 out.include.cstddef = true; in write_rust_vec_impl()
1481 writeln!(out, "template <>"); in write_rust_vec_impl()
1482 begin_function_definition(out); in write_rust_vec_impl()
1483 writeln!(out, "Vec<{}>::Vec() noexcept {{", inner); in write_rust_vec_impl()
1484 writeln!(out, " cxxbridge1$rust_vec${}$new(this);", instance); in write_rust_vec_impl()
1485 writeln!(out, "}}"); in write_rust_vec_impl()
1487 writeln!(out, "template <>"); in write_rust_vec_impl()
1488 begin_function_definition(out); in write_rust_vec_impl()
1489 writeln!(out, "void Vec<{}>::drop() noexcept {{", inner); in write_rust_vec_impl()
1490 writeln!(out, " return cxxbridge1$rust_vec${}$drop(this);", instance); in write_rust_vec_impl()
1491 writeln!(out, "}}"); in write_rust_vec_impl()
1493 writeln!(out, "template <>"); in write_rust_vec_impl()
1494 begin_function_definition(out); in write_rust_vec_impl()
1496 out, in write_rust_vec_impl()
1500 writeln!(out, " return cxxbridge1$rust_vec${}$len(this);", instance); in write_rust_vec_impl()
1501 writeln!(out, "}}"); in write_rust_vec_impl()
1503 writeln!(out, "template <>"); in write_rust_vec_impl()
1504 begin_function_definition(out); in write_rust_vec_impl()
1506 out, in write_rust_vec_impl()
1511 out, in write_rust_vec_impl()
1515 writeln!(out, "}}"); in write_rust_vec_impl()
1517 writeln!(out, "template <>"); in write_rust_vec_impl()
1518 begin_function_definition(out); in write_rust_vec_impl()
1519 writeln!(out, "const {} *Vec<{0}>::data() const noexcept {{", inner); in write_rust_vec_impl()
1520 writeln!(out, " return cxxbridge1$rust_vec${}$data(this);", instance); in write_rust_vec_impl()
1521 writeln!(out, "}}"); in write_rust_vec_impl()
1523 writeln!(out, "template <>"); in write_rust_vec_impl()
1524 begin_function_definition(out); in write_rust_vec_impl()
1526 out, in write_rust_vec_impl()
1531 out, in write_rust_vec_impl()
1535 writeln!(out, "}}"); in write_rust_vec_impl()
1537 writeln!(out, "template <>"); in write_rust_vec_impl()
1538 begin_function_definition(out); in write_rust_vec_impl()
1540 out, in write_rust_vec_impl()
1545 out, in write_rust_vec_impl()
1549 writeln!(out, "}}"); in write_rust_vec_impl()
1552 fn write_unique_ptr(out: &mut OutFile, key: NamedImplKey) { in write_unique_ptr()
1554 write_unique_ptr_common(out, ty); in write_unique_ptr()
1558 fn write_unique_ptr_common(out: &mut OutFile, ty: UniquePtr) { in write_unique_ptr_common()
1559 out.include.new = true; in write_unique_ptr_common()
1560 out.include.utility = true; in write_unique_ptr_common()
1561 let inner = ty.to_typename(out.types); in write_unique_ptr_common()
1562 let instance = ty.to_mangled(out.types); in write_unique_ptr_common()
1570 out.types.structs.contains_key(ident) in write_unique_ptr_common()
1571 || out.types.enums.contains_key(ident) in write_unique_ptr_common()
1572 || out.types.aliases.contains_key(ident) in write_unique_ptr_common()
1579 !out.types.structs.contains_key(ident) && !out.types.enums.contains_key(ident) in write_unique_ptr_common()
1585 out.builtin.is_complete = true; in write_unique_ptr_common()
1587 UniquePtr::Ident(ty) => &out.types.resolve(ty).name.cxx, in write_unique_ptr_common()
1591 out, in write_unique_ptr_common()
1597 out, in write_unique_ptr_common()
1602 out, in write_unique_ptr_common()
1607 out, in write_unique_ptr_common()
1611 writeln!(out, " ::new (ptr) ::std::unique_ptr<{}>();", inner); in write_unique_ptr_common()
1612 writeln!(out, "}}"); in write_unique_ptr_common()
1614 out.builtin.maybe_uninit = true; in write_unique_ptr_common()
1616 out, in write_unique_ptr_common()
1621 out, in write_unique_ptr_common()
1625 writeln!(out, " ::new (ptr) ::std::unique_ptr<{}>(uninit);", inner); in write_unique_ptr_common()
1626 writeln!(out, " return uninit;"); in write_unique_ptr_common()
1627 writeln!(out, "}}"); in write_unique_ptr_common()
1630 out, in write_unique_ptr_common()
1634 writeln!(out, " ::new (ptr) ::std::unique_ptr<{}>(raw);", inner); in write_unique_ptr_common()
1635 writeln!(out, "}}"); in write_unique_ptr_common()
1637 out, in write_unique_ptr_common()
1641 writeln!(out, " return ptr.get();"); in write_unique_ptr_common()
1642 writeln!(out, "}}"); in write_unique_ptr_common()
1644 out, in write_unique_ptr_common()
1648 writeln!(out, " return ptr.release();"); in write_unique_ptr_common()
1649 writeln!(out, "}}"); in write_unique_ptr_common()
1651 out, in write_unique_ptr_common()
1656 out.builtin.deleter_if = true; in write_unique_ptr_common()
1658 out, in write_unique_ptr_common()
1663 writeln!(out, " ptr->~unique_ptr();"); in write_unique_ptr_common()
1665 writeln!(out, "}}"); in write_unique_ptr_common()
1668 fn write_shared_ptr(out: &mut OutFile, key: NamedImplKey) { in write_shared_ptr()
1670 let resolve = out.types.resolve(ident); in write_shared_ptr()
1674 out.include.new = true; in write_shared_ptr()
1675 out.include.utility = true; in write_shared_ptr()
1681 let can_construct_from_value = out.types.structs.contains_key(ident) in write_shared_ptr()
1682 || out.types.enums.contains_key(ident) in write_shared_ptr()
1683 || out.types.aliases.contains_key(ident); in write_shared_ptr()
1686 out, in write_shared_ptr()
1691 out, in write_shared_ptr()
1696 out, in write_shared_ptr()
1700 writeln!(out, " ::new (ptr) ::std::shared_ptr<{}>();", inner); in write_shared_ptr()
1701 writeln!(out, "}}"); in write_shared_ptr()
1703 out.builtin.maybe_uninit = true; in write_shared_ptr()
1705 out, in write_shared_ptr()
1710 out, in write_shared_ptr()
1714 writeln!(out, " ::new (ptr) ::std::shared_ptr<{}>(uninit);", inner); in write_shared_ptr()
1715 writeln!(out, " return uninit;"); in write_shared_ptr()
1716 writeln!(out, "}}"); in write_shared_ptr()
1719 out, in write_shared_ptr()
1723 writeln!(out, " ::new (ptr) ::std::shared_ptr<{}>(self);", inner); in write_shared_ptr()
1724 writeln!(out, "}}"); in write_shared_ptr()
1726 out, in write_shared_ptr()
1730 writeln!(out, " return self.get();"); in write_shared_ptr()
1731 writeln!(out, "}}"); in write_shared_ptr()
1733 out, in write_shared_ptr()
1737 writeln!(out, " self->~shared_ptr();"); in write_shared_ptr()
1738 writeln!(out, "}}"); in write_shared_ptr()
1741 fn write_weak_ptr(out: &mut OutFile, key: NamedImplKey) { in write_weak_ptr()
1742 let resolve = out.types.resolve(&key); in write_weak_ptr()
1746 out.include.new = true; in write_weak_ptr()
1747 out.include.utility = true; in write_weak_ptr()
1750 out, in write_weak_ptr()
1755 out, in write_weak_ptr()
1760 out, in write_weak_ptr()
1764 writeln!(out, " ::new (ptr) ::std::weak_ptr<{}>();", inner); in write_weak_ptr()
1765 writeln!(out, "}}"); in write_weak_ptr()
1767 out, in write_weak_ptr()
1771 writeln!(out, " ::new (ptr) ::std::weak_ptr<{}>(self);", inner); in write_weak_ptr()
1772 writeln!(out, "}}"); in write_weak_ptr()
1774 out, in write_weak_ptr()
1778 writeln!(out, " ::new (weak) ::std::weak_ptr<{}>(shared);", inner); in write_weak_ptr()
1779 writeln!(out, "}}"); in write_weak_ptr()
1781 out, in write_weak_ptr()
1786 out, in write_weak_ptr()
1790 writeln!(out, "}}"); in write_weak_ptr()
1792 out, in write_weak_ptr()
1796 writeln!(out, " self->~weak_ptr();"); in write_weak_ptr()
1797 writeln!(out, "}}"); in write_weak_ptr()
1800 fn write_cxx_vector(out: &mut OutFile, key: NamedImplKey) { in write_cxx_vector()
1802 let inner = element.to_typename(out.types); in write_cxx_vector()
1803 let instance = element.to_mangled(out.types); in write_cxx_vector()
1805 out.include.cstddef = true; in write_cxx_vector()
1808 out, in write_cxx_vector()
1812 writeln!(out, " return s.size();"); in write_cxx_vector()
1813 writeln!(out, "}}"); in write_cxx_vector()
1815 out, in write_cxx_vector()
1819 writeln!(out, " return &(*s)[pos];"); in write_cxx_vector()
1820 writeln!(out, "}}"); in write_cxx_vector()
1822 out.include.memory = true; in write_cxx_vector()
1823 write_unique_ptr_common(out, UniquePtr::CxxVector(element)); in write_cxx_vector()