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

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl

Issue 917333003: Mojo C++ bindings templates: use the same templates for user-defined structs and method params. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl
index ee8934e2f40d039757c94840effa20fd712e0ee1..839636b82d57061edb989c1404eacf0942819f14 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl
@@ -1,4 +1,3 @@
-{%- import "struct_macros.tmpl" as struct_macros %}
{%- set class_name = struct.name ~ "_Data" -%}
class {{class_name}} {
@@ -8,12 +7,39 @@ class {{class_name}} {
static bool Validate(const void* data,
mojo::internal::BoundsChecker* bounds_checker);
- mojo::internal::StructHeader header_;
-{{struct_macros.fields(struct)}}
-
void EncodePointersAndHandles(std::vector<mojo::Handle>* handles);
void DecodePointersAndHandles(std::vector<mojo::Handle>* handles);
+ mojo::internal::StructHeader header_;
+{%- for packed_field in struct.packed.packed_fields %}
+{%- set name = packed_field.field.name -%}
+{%- set kind = packed_field.field.kind -%}
+{%- if kind.spec == 'b' -%}
+ uint8_t {{name}} : 1;
+{%- elif kind|is_enum_kind -%}
+ int32_t {{name}};
+{%- else -%}
+ {{kind|cpp_field_type}} {{name}};
+{%- endif %}
+{%- if not loop.last %}
+{%- set next_pf = struct.packed.packed_fields[loop.index0 + 1] %}
+{%- set pad = next_pf.offset - (packed_field.offset + packed_field.size) %}
+{%- if pad > 0 %}
+ uint8_t pad{{loop.index0}}_[{{pad}}];
+{%- endif %}
+{%- endif %}
+{%- endfor -%}
+
+{%- set num_fields = struct.versions[-1].num_fields %}
+{%- if num_fields > 0 %}
+{%- set last_field = struct.packed.packed_fields[num_fields - 1] %}
+{%- set offset = last_field.offset + last_field.size %}
+{%- set pad = offset|get_pad(8) -%}
+{%- if pad > 0 %}
+ uint8_t padfinal_[{{pad}}];
+{%- endif %}
+{%- endif %}
+
private:
{{class_name}}();
~{{class_name}}() = delete;

Powered by Google App Engine
This is Rietveld 408576698