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

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

Issue 923033003: Implement unions as members of structs. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 28 matching lines...) Expand all
39 {%- set input_field = input_field_pattern|format(pf.field.name) %} 39 {%- set input_field = input_field_pattern|format(pf.field.name) %}
40 {%- set name = pf.field.name %} 40 {%- set name = pf.field.name %}
41 {%- set kind = pf.field.kind %} 41 {%- set kind = pf.field.kind %}
42 {%- if kind|is_object_kind %} 42 {%- if kind|is_object_kind %}
43 {%- if kind|is_array_kind %} 43 {%- if kind|is_array_kind %}
44 mojo::SerializeArray_<{{kind|get_array_validate_params|indent(24)}}>( 44 mojo::SerializeArray_<{{kind|get_array_validate_params|indent(24)}}>(
45 mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name} }.ptr); 45 mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name} }.ptr);
46 {%- elif kind|is_map_kind %} 46 {%- elif kind|is_map_kind %}
47 mojo::SerializeMap_<{{kind.value_kind|get_map_validate_params|indent(24)}}>( 47 mojo::SerializeMap_<{{kind.value_kind|get_map_validate_params|indent(24)}}>(
48 mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name} }.ptr); 48 mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name} }.ptr);
49 {%- elif kind|is_union_kind %}
50 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}};
51 SerializeUnion_(mojo::internal::Forward({{input_field}}), {{buffer}}, &{{name} }_ptr, true);
49 {%- else %} 52 {%- else %}
50 Serialize_(mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}-> {{name}}.ptr); 53 Serialize_(mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}-> {{name}}.ptr);
51 {%- endif %} 54 {%- endif %}
52 {%- if not kind|is_nullable_kind %} 55 {%- if not kind|is_nullable_kind %}
53 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( 56 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
57 {%- if kind|is_union_kind %}
58 {{output}}->{{name}}.is_null(),
59 {%- else %}
54 !{{output}}->{{name}}.ptr, 60 !{{output}}->{{name}}.ptr,
61 {%- endif %}
55 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, 62 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
56 "null {{name}} in {{struct_display_name}}"); 63 "null {{name}} in {{struct_display_name}}");
57 {%- endif %} 64 {%- endif %}
58 {%- elif kind|is_any_handle_kind %} 65 {%- elif kind|is_any_handle_kind %}
59 {%- if kind|is_interface_kind or kind|is_interface_request_kind %} 66 {%- if kind|is_interface_kind or kind|is_interface_request_kind %}
60 {{output}}->{{name}} = {{input_field}}.PassMessagePipe().release(); 67 {{output}}->{{name}} = {{input_field}}.PassMessagePipe().release();
61 {%- else %} 68 {%- else %}
62 {{output}}->{{name}} = {{input_field}}.release(); 69 {{output}}->{{name}} = {{input_field}}.release();
63 {%- endif %} 70 {%- endif %}
64 {%- if not kind|is_nullable_kind %} 71 {%- if not kind|is_nullable_kind %}
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} 103 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
97 {%- set output_field = output_field_pattern|format(pf.field.name) %} 104 {%- set output_field = output_field_pattern|format(pf.field.name) %}
98 {%- set name = pf.field.name %} 105 {%- set name = pf.field.name %}
99 {%- set kind = pf.field.kind %} 106 {%- set kind = pf.field.kind %}
100 {%- if pf.min_version > last_checked_version %} 107 {%- if pf.min_version > last_checked_version %}
101 {%- set last_checked_version = pf.min_version %} 108 {%- set last_checked_version = pf.min_version %}
102 if ({{input}}->header_.version < {{pf.min_version}}) 109 if ({{input}}->header_.version < {{pf.min_version}})
103 break; 110 break;
104 {%- endif %} 111 {%- endif %}
105 {%- if kind|is_object_kind %} 112 {%- if kind|is_object_kind %}
113 {%- if kind|is_union_kind %}
114 Deserialize_(&{{input}}->{{name}}, &{{output_field}});
115 {%- else %}
106 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}); 116 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}});
117 {%- endif %}
107 {%- elif kind|is_interface_kind or kind|is_interface_request_kind %} 118 {%- elif kind|is_interface_kind or kind|is_interface_request_kind %}
108 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}}))); 119 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}})));
109 {%- elif kind|is_any_handle_kind %} 120 {%- elif kind|is_any_handle_kind %}
110 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); 121 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}}));
111 {%- elif kind|is_enum_kind %} 122 {%- elif kind|is_enum_kind %}
112 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} }); 123 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} });
113 {%- else %} 124 {%- else %}
114 {{output_field}} = {{input}}->{{name}}; 125 {{output_field}} = {{input}}->{{name}};
115 {%- endif %} 126 {%- endif %}
116 {%- endfor %} 127 {%- endfor %}
117 } while (false); 128 } while (false);
118 {%- endmacro %} 129 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698