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

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

Issue 1833033003: C++ Bindings: Remove 'inline' arg from generated union serialization functions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 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.
11 - method parameters/response parameters: the input is a list of 11 - method parameters/response parameters: the input is a list of
12 arguments. 12 arguments.
13 It declares |size| of type size_t to store the resulting size. #} 13 It declares |size| of type size_t to store the resulting size. #}
14 {%- macro get_serialized_size(struct, input_field_pattern) -%} 14 {%- macro get_serialized_size(struct, input_field_pattern) -%}
15 size_t size = sizeof(internal::{{struct.name}}_Data); 15 size_t size = sizeof(internal::{{struct.name}}_Data);
16 {%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is _object_kind %} 16 {%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is _object_kind %}
17 {%- if pf.field.kind|is_union_kind %} 17 {%- if pf.field.kind|is_union_kind %}
18 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}, true ); 18 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}});
19 {%- elif pf.field.kind|is_struct_kind %} 19 {%- elif pf.field.kind|is_struct_kind %}
20 size += {{input_field_pattern|format(pf.field.name)}}.is_null() 20 size += {{input_field_pattern|format(pf.field.name)}}.is_null()
21 ? 0 21 ? 0
22 : GetSerializedSize_(*{{input_field_pattern|format(pf.field.name)} }); 22 : GetSerializedSize_(*{{input_field_pattern|format(pf.field.name)} });
23 {%- else %} 23 {%- else %}
24 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}); 24 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}});
25 {%- endif %} 25 {%- endif %}
26 {%- endfor %} 26 {%- endfor %}
27 {%- endmacro -%} 27 {%- endmacro -%}
28 28
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 mojo::SerializeMap_( 69 mojo::SerializeMap_(
70 {{input}}, {{buffer}}, {{output}}, 70 {{input}}, {{buffer}}, {{output}},
71 &{{name}}_validate_params); 71 &{{name}}_validate_params);
72 {%- if should_return_errors %} 72 {%- if should_return_errors %}
73 if (retval != mojo::internal::ValidationError::NONE) 73 if (retval != mojo::internal::ValidationError::NONE)
74 return retval; 74 return retval;
75 {%- endif %} 75 {%- endif %}
76 } 76 }
77 {%- endmacro -%} 77 {%- endmacro -%}
78 78
79 {%- macro call_serialize_union(input, buffer, output, inlined, 79 {%- macro call_serialize_union(input, buffer, output, should_return_errors) -%}
80 should_return_errors) -%}
81 { 80 {
82 {%- if should_return_errors %} 81 {%- if should_return_errors %}
83 auto retval = 82 auto retval =
84 {%- endif %} 83 {%- endif %}
85 SerializeUnion_({{input}}, 84 SerializeUnion_({{input}},
86 {{buffer}}, 85 {{buffer}},
87 {{output}}, 86 {{output}});
88 {{inlined}});
89 {%- if should_return_errors %} 87 {%- if should_return_errors %}
90 if (retval != mojo::internal::ValidationError::NONE) 88 if (retval != mojo::internal::ValidationError::NONE)
91 return retval; 89 return retval;
92 {%- endif %} 90 {%- endif %}
93 } 91 }
94 {%- endmacro -%} 92 {%- endmacro -%}
95 93
96 {%- macro call_serialize_struct(input, buffer, output, should_return_errors) -%} 94 {%- macro call_serialize_struct(input, buffer, output, should_return_errors) -%}
97 { 95 {
98 {%- if should_return_errors -%} 96 {%- if should_return_errors -%}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 input = '&' ~ input_field, 148 input = '&' ~ input_field,
151 buffer = buffer, 149 buffer = buffer,
152 output = '&%s->%s.ptr'|format(output,name), 150 output = '&%s->%s.ptr'|format(output,name),
153 should_return_errors = should_return_errors, 151 should_return_errors = should_return_errors,
154 indent_size = 10)}} 152 indent_size = 10)}}
155 {%- elif kind|is_union_kind %} 153 {%- elif kind|is_union_kind %}
156 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}}; 154 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}};
157 {{call_serialize_union(input = input_field ~ ".get()", 155 {{call_serialize_union(input = input_field ~ ".get()",
158 buffer = buffer, 156 buffer = buffer,
159 output = "&%s_ptr"|format(name), 157 output = "&%s_ptr"|format(name),
160 inlined = "true",
161 should_return_errors = should_return_errors)}} 158 should_return_errors = should_return_errors)}}
162 {%- elif kind|is_string_kind %} 159 {%- elif kind|is_string_kind %}
163 SerializeString_({{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr); 160 SerializeString_({{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr);
164 {%- else %} 161 {%- else %}
165 {{call_serialize_struct(input = input_field ~ ".get()", 162 {{call_serialize_struct(input = input_field ~ ".get()",
166 buffer = buffer, 163 buffer = buffer,
167 output = "&%s->%s.ptr"|format(output,name), 164 output = "&%s->%s.ptr"|format(output,name),
168 should_return_errors = should_return_errors)}} 165 should_return_errors = should_return_errors)}}
169 {%- endif %} 166 {%- endif %}
170 {%- if not kind|is_nullable_kind %} 167 {%- if not kind|is_nullable_kind %}
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 - user-defined mojo structs 271 - user-defined mojo structs
275 - interface method params/response params #} 272 - interface method params/response params #}
276 {%- macro structptr_forward_decl(struct) -%} 273 {%- macro structptr_forward_decl(struct) -%}
277 class {{struct.name}}; 274 class {{struct.name}};
278 {% if struct|should_inline %} 275 {% if struct|should_inline %}
279 using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>; 276 using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>;
280 {% else %} 277 {% else %}
281 using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>; 278 using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>;
282 {% endif %} 279 {% endif %}
283 {% endmacro %} 280 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698