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

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

Issue 2130463002: Mojo C++ bindings: allow StructTraits to return handle or interface types as value. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 {%- macro serialize(struct, struct_display_name, input_field_pattern, output, 59 {%- macro serialize(struct, struct_display_name, input_field_pattern, output,
60 buffer, context, input_may_be_temp=False) -%} 60 buffer, context, input_may_be_temp=False) -%}
61 auto {{output}} = 61 auto {{output}} =
62 {{struct|get_qualified_name_for_kind(internal=True)}}::New({{buffer}}); 62 {{struct|get_qualified_name_for_kind(internal=True)}}::New({{buffer}});
63 ALLOW_UNUSED_LOCAL({{output}}); 63 ALLOW_UNUSED_LOCAL({{output}});
64 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} 64 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
65 {%- set input_field = input_field_pattern|format(pf.field.name) %} 65 {%- set input_field = input_field_pattern|format(pf.field.name) %}
66 {%- set name = pf.field.name %} 66 {%- set name = pf.field.name %}
67 {%- set kind = pf.field.kind %} 67 {%- set kind = pf.field.kind %}
68 {%- set serializer_type = kind|unmapped_type_for_serializer %} 68 {%- set serializer_type = kind|unmapped_type_for_serializer %}
69 {%- if kind|is_object_kind %} 69
70 {%- if kind|is_object_kind or kind|is_any_handle_or_interface_kind %}
70 {%- set original_input_field = input_field_pattern|format(name) %} 71 {%- set original_input_field = input_field_pattern|format(name) %}
71 {%- set input_field = "in_%s"|format(name) if input_may_be_temp 72 {%- set input_field = "in_%s"|format(name) if input_may_be_temp
72 else original_input_field %} 73 else original_input_field %}
73 {%- if input_may_be_temp %} 74 {%- if input_may_be_temp %}
74 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}}; 75 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}};
75 {%- endif %} 76 {%- endif %}
77 {%- endif %}
78
79 {%- if kind|is_object_kind %}
76 {%- if kind|is_array_kind or kind|is_map_kind %} 80 {%- if kind|is_array_kind or kind|is_map_kind %}
Peng 2016/07/06 18:05:26 This code is totally unreadable to me. Maybe ask o
yzshen1 2016/07/06 18:07:25 I am the author of most of the code in this folder
77 typename decltype({{output}}->{{name}})::BaseType* {{name}}_ptr; 81 typename decltype({{output}}->{{name}})::BaseType* {{name}}_ptr;
78 const mojo::internal::ContainerValidateParams {{name}}_validate_params( 82 const mojo::internal::ContainerValidateParams {{name}}_validate_params(
79 {{kind|get_container_validate_params_ctor_args|indent(10)}}); 83 {{kind|get_container_validate_params_ctor_args|indent(10)}});
80 mojo::internal::Serialize<{{serializer_type}}>( 84 mojo::internal::Serialize<{{serializer_type}}>(
81 {{input_field}}, {{buffer}}, &{{name}}_ptr, &{{name}}_validate_params, 85 {{input_field}}, {{buffer}}, &{{name}}_ptr, &{{name}}_validate_params,
82 {{context}}); 86 {{context}});
83 {{output}}->{{name}}.Set({{name}}_ptr); 87 {{output}}->{{name}}.Set({{name}}_ptr);
84 {%- elif kind|is_union_kind %} 88 {%- elif kind|is_union_kind %}
85 auto {{name}}_ptr = &{{output}}->{{name}}; 89 auto {{name}}_ptr = &{{output}}->{{name}};
86 mojo::internal::Serialize<{{serializer_type}}>( 90 mojo::internal::Serialize<{{serializer_type}}>(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 {%- if kind|is_object_kind or kind|is_enum_kind %} 148 {%- if kind|is_object_kind or kind|is_enum_kind %}
145 if (!{{input}}.Read{{name|under_to_camel}}(&{{output_field}})) 149 if (!{{input}}.Read{{name|under_to_camel}}(&{{output_field}}))
146 {{success}} = false; 150 {{success}} = false;
147 {%- elif kind|is_any_handle_or_interface_kind %} 151 {%- elif kind|is_any_handle_or_interface_kind %}
148 {{output_field}} = {{input}}.Take{{name|under_to_camel}}(); 152 {{output_field}} = {{input}}.Take{{name|under_to_camel}}();
149 {%- else %} 153 {%- else %}
150 {{output_field}} = {{input}}.{{name}}(); 154 {{output_field}} = {{input}}.{{name}}();
151 {%- endif %} 155 {%- endif %}
152 {%- endfor %} 156 {%- endfor %}
153 {%- endmacro %} 157 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698