Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl

Issue 2660733002: Mojo C++ bindings: introduce an optional array to store transferred interface IDs in messages. (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 {# TODO(yzshen): Make these templates more readable. #} 1 {# TODO(yzshen): Make these templates more readable. #}
2 2
3 {# Computes the serialized size for the specified struct. 3 {# Computes the serialized size for the specified struct.
4 |struct| is the struct definition. 4 |struct| is the struct definition.
5 |input_field_pattern| should be a pattern that contains one string 5 |input_field_pattern| should be a pattern that contains one string
6 placeholder, for example, "input->%s", "p_%s". The placeholder will be 6 placeholder, for example, "input->%s", "p_%s". The placeholder will be
7 substituted with struct field names to refer to the input fields. 7 substituted with struct field names to refer to the input fields.
8 |context| is the name of the serialization context. 8 |context| is the name of the serialization context.
9 |input_may_be_temp| indicates whether any input may be temporary obejcts. 9 |input_may_be_temp| indicates whether any input may be temporary obejcts.
10 We need to assign temporary objects to local variables before passing it to 10 We need to assign temporary objects to local variables before passing it to
11 Serializer, because it is illegal to pass temporary objects as non-const 11 Serializer, because it is illegal to pass temporary objects as non-const
12 references. 12 references.
13 This macro is expanded to compute seriailized size for both: 13 This macro is expanded to compute seriailized size for both:
14 - user-defined structs: the input is an instance of the corresponding struct 14 - user-defined structs: the input is an instance of the corresponding struct
15 wrapper class. 15 wrapper class.
16 - method parameters/response parameters: the input is a list of 16 - method parameters/response parameters: the input is a list of
17 arguments. 17 arguments.
18 It declares |size| of type size_t to store the resulting size. #} 18 It declares |size| of type size_t to store the resulting size. #}
19 {%- macro get_serialized_size(struct, input_field_pattern, context, 19 {%- macro get_serialized_size(struct, input_field_pattern, context,
20 input_may_be_temp=False) -%} 20 input_may_be_temp=False) -%}
21 size_t size = sizeof({{struct|get_qualified_name_for_kind(internal=True)}}); 21 size_t size = sizeof({{struct|get_qualified_name_for_kind(internal=True)}});
22 {%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is _object_kind %} 22 {%- for pf in struct.packed.packed_fields_in_ordinal_order
23 if pf.field.kind|is_object_kind or pf.field.kind|is_associated_kind %}
23 {%- set name = pf.field.name -%} 24 {%- set name = pf.field.name -%}
24 {%- set kind = pf.field.kind -%} 25 {%- set kind = pf.field.kind -%}
25 {%- set original_input_field = input_field_pattern|format(name) %} 26 {%- set original_input_field = input_field_pattern|format(name) %}
26 {%- set input_field = "in_%s"|format(name) if input_may_be_temp 27 {%- set input_field = "in_%s"|format(name) if input_may_be_temp
27 else original_input_field %} 28 else original_input_field %}
28 {%- if input_may_be_temp %} 29 {%- if input_may_be_temp %}
29 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}}; 30 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}};
30 {%- endif %} 31 {%- endif %}
31 32
32 {%- set serializer_type = kind|unmapped_type_for_serializer %} 33 {%- set serializer_type = kind|unmapped_type_for_serializer %}
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 {%- elif kind|is_any_handle_kind %} 152 {%- elif kind|is_any_handle_kind %}
152 {{output_field}} = {{input}}.Take{{name|under_to_camel}}(); 153 {{output_field}} = {{input}}.Take{{name|under_to_camel}}();
153 {%- elif kind|is_any_interface_kind %} 154 {%- elif kind|is_any_interface_kind %}
154 {{output_field}} = 155 {{output_field}} =
155 {{input}}.Take{{name|under_to_camel}}<decltype({{output_field}})>(); 156 {{input}}.Take{{name|under_to_camel}}<decltype({{output_field}})>();
156 {%- else %} 157 {%- else %}
157 {{output_field}} = {{input}}.{{name}}(); 158 {{output_field}} = {{input}}.{{name}}();
158 {%- endif %} 159 {%- endif %}
159 {%- endfor %} 160 {%- endfor %}
160 {%- endmacro %} 161 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698