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

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

Issue 1682113003: Mojo C++ bindings: Generate InterfaceHandle<> instead of InterfacePtr<>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebase ontop of master, address trung's comments Created 4 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 This macro is expanded to compute seriailized size for both: 8 This macro is expanded to compute seriailized size for both:
9 - user-defined structs: the input is an instance of the corresponding struct 9 - user-defined structs: the input is an instance of the corresponding struct
10 wrapper class. 10 wrapper class.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 {%- set condition = "!%s->%s.ptr" | format(output,name) %} 174 {%- set condition = "!%s->%s.ptr" | format(output,name) %}
175 {%- endif %} 175 {%- endif %}
176 {{_validation_check_macro( 176 {{_validation_check_macro(
177 condition = condition, 177 condition = condition,
178 error_code = "mojo::internal::ValidationError::UNEXPECTED_NULL_POINTER", 178 error_code = "mojo::internal::ValidationError::UNEXPECTED_NULL_POINTER",
179 error_msg = "null %s in %s" | format(name, struct_display_name), 179 error_msg = "null %s in %s" | format(name, struct_display_name),
180 should_return_errors = should_return_errors)}} 180 should_return_errors = should_return_errors)}}
181 {%- endif %} 181 {%- endif %}
182 {%- elif kind|is_any_handle_kind or kind|is_interface_kind %} 182 {%- elif kind|is_any_handle_kind or kind|is_interface_kind %}
183 {%- if kind|is_interface_kind %} 183 {%- if kind|is_interface_kind %}
184 mojo::internal::InterfacePointerToData({{input_field}}.Pass(), &{{output}}->{{ name}}); 184 mojo::internal::InterfaceHandleToData({{input_field}}.Pass(),
185 &{{output}}->{{name}});
185 {%- elif kind|is_interface_request_kind %} 186 {%- elif kind|is_interface_request_kind %}
186 {{output}}->{{name}} = {{input_field}}.PassMessagePipe().release(); 187 {{output}}->{{name}} = {{input_field}}.PassMessagePipe().release();
187 {%- else %} 188 {%- else %}
188 {{output}}->{{name}} = {{input_field}}.release(); 189 {{output}}->{{name}} = {{input_field}}.release();
189 {%- endif %} 190 {%- endif %}
190 {%- if not kind|is_nullable_kind %} 191 {%- if not kind|is_nullable_kind %}
191 {%- if kind|is_interface_kind %} 192 {%- if kind|is_interface_kind %}
192 {%- set condition = "!%s->%s.handle.is_valid()" | format(output, name) % } 193 {%- set condition = "!%s->%s.handle.is_valid()" | format(output, name) % }
193 {%- else %} 194 {%- else %}
194 {%- set condition = "!%s->%s.is_valid()" | format(output,name) %} 195 {%- set condition = "!%s->%s.is_valid()" | format(output,name) %}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 {%- elif kind|is_struct_kind %} 247 {%- elif kind|is_struct_kind %}
247 if ({{input}}->{{name}}.ptr) { 248 if ({{input}}->{{name}}.ptr) {
248 {{output_field}} = {{kind|get_name_for_kind}}::New(); 249 {{output_field}} = {{kind|get_name_for_kind}}::New();
249 Deserialize_({{input}}->{{name}}.ptr, {{output_field}}.get()); 250 Deserialize_({{input}}->{{name}}.ptr, {{output_field}}.get());
250 } 251 }
251 {%- else %} 252 {%- else %}
252 {#- Arrays and Maps #} 253 {#- Arrays and Maps #}
253 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}); 254 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}});
254 {%- endif %} 255 {%- endif %}
255 {%- elif kind|is_interface_kind %} 256 {%- elif kind|is_interface_kind %}
256 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field }}); 257 mojo::internal::InterfaceDataToHandle(&{{input}}->{{name}}, &{{output_field} });
257 {%- elif kind|is_interface_request_kind %} 258 {%- elif kind|is_interface_request_kind %}
258 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}}))); 259 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}})));
259 {%- elif kind|is_any_handle_kind %} 260 {%- elif kind|is_any_handle_kind %}
260 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); 261 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}}));
261 {%- elif kind|is_enum_kind %} 262 {%- elif kind|is_enum_kind %}
262 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} }); 263 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} });
263 {%- else %} 264 {%- else %}
264 {{output_field}} = {{input}}->{{name}}; 265 {{output_field}} = {{input}}->{{name}};
265 {%- endif %} 266 {%- endif %}
266 {%- endfor %} 267 {%- endfor %}
267 } while (false); 268 } while (false);
268 {%- endmacro %} 269 {%- endmacro %}
269 270
270 {# Forward declares |struct|, and typedefs the appropriate Ptr wrapper 271 {# Forward declares |struct|, and typedefs the appropriate Ptr wrapper
271 (|mojo::StructPtr| or |mojo::InlinedStructPtr|). This macro is expanded for 272 (|mojo::StructPtr| or |mojo::InlinedStructPtr|). This macro is expanded for
272 all generated structs: 273 all generated structs:
273 - user-defined mojo structs 274 - user-defined mojo structs
274 - interface method params/response params #} 275 - interface method params/response params #}
275 {%- macro structptr_forward_decl(struct) -%} 276 {%- macro structptr_forward_decl(struct) -%}
276 class {{struct.name}}; 277 class {{struct.name}};
277 {% if struct|should_inline %} 278 {% if struct|should_inline %}
278 using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>; 279 using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>;
279 {% else %} 280 {% else %}
280 using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>; 281 using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>;
281 {% endif %} 282 {% endif %}
282 {% endmacro %} 283 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698