Backed out 5 changesets (bug 1890092, bug 1888683) for causing build bustages & crash...
[gecko.git] / third_party / rust / uniffi_bindgen / src / bindings / ruby / templates / macros.rb
blob8dc3e5e613b525d55cb818414b7a6b9f229bb44b
1 {#
2 // Template to call into rust. Used in several places.
3 // Variable names in `arg_list_decl` should match up with arg lists
4 // passed to rust via `_arg_list_ffi_call` (we use  `var_name_rb` in `lower_rb`)
5 #}
7 {%- macro to_ffi_call(func) -%}
8     {%- match func.throws_name() -%}
9     {%- when Some with (e) -%}
10       {{ ci.namespace()|class_name_rb }}.rust_call_with_error({{ e|class_name_rb }},
11     {%- else -%}
12       {{ ci.namespace()|class_name_rb }}.rust_call(
13     {%- endmatch -%}
14     :{{ func.ffi_func().name() }},
15     {%- call _arg_list_ffi_call(func) -%}
17 {%- endmacro -%}
19 {%- macro to_ffi_call_with_prefix(prefix, func) -%}
20     {%- match func.throws_name() -%}
21     {%- when Some with (e) -%}
22       {{ ci.namespace()|class_name_rb }}.rust_call_with_error({{ e|class_name_rb }},
23     {%- else -%}
24       {{ ci.namespace()|class_name_rb }}.rust_call(
25     {%- endmatch -%}
26     :{{ func.ffi_func().name() }},
27     {{- prefix }},
28     {%- call _arg_list_ffi_call(func) -%}
30 {%- endmacro -%}
32 {%- macro _arg_list_ffi_call(func) %}
33     {%- for arg in func.arguments() %}
34         {{- arg.name()|lower_rb(arg.as_type().borrow()) }}
35         {%- if !loop.last %},{% endif %}
36     {%- endfor %}
37 {%- endmacro -%}
39 {#-
40 // Arglist as used in Ruby declarations of methods, functions and constructors.
41 // Note the var_name_rb and type_rb filters.
42 -#}
44 {% macro arg_list_decl(func) %}
45     {%- for arg in func.arguments() -%}
46         {{ arg.name()|var_name_rb }}
47         {%- match arg.default_value() %}
48         {%- when Some with(literal) %} = {{ literal|literal_rb }}
49         {%- else %}
50         {%- endmatch %}
51         {%- if !loop.last %}, {% endif -%}
52     {%- endfor %}
53 {%- endmacro %}
55 {#-
56 // Arglist as used in the UniFFILib function declarations.
57 // Note unfiltered name but type_ffi filters.
58 -#}
59 {%- macro arg_list_ffi_decl(func) %}
60     [{%- for arg in func.arguments() -%}{{ arg.type_().borrow()|type_ffi }}, {% endfor -%} RustCallStatus.by_ref]
61 {%- endmacro -%}
63 {%- macro coerce_args(func) %}
64     {%- for arg in func.arguments() %}
65     {{ arg.name() }} = {{ arg.name()|coerce_rb(ci.namespace()|class_name_rb, arg.as_type().borrow()) -}}
66     {% endfor -%}
67 {%- endmacro -%}
69 {%- macro coerce_args_extra_indent(func) %}
70         {%- for arg in func.arguments() %}
71         {{ arg.name() }} = {{ arg.name()|coerce_rb(ci.namespace()|class_name_rb, arg.as_type().borrow()) }}
72         {%- endfor %}
73 {%- endmacro -%}