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

Unified 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, 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_macros.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
index 623ebb441c69938da26e8489662eb65641f82f5d..e457e61620658d3f00fd241d39a3fc2c21acb918 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
@@ -14,7 +14,21 @@
{%- for packed_field in struct.packed.packed_fields %}
{%- set name = packed_field.field.name %}
{%- set kind = packed_field.field.kind %}
-{%- if kind|is_object_kind %}
+{%- if kind|is_union_kind %}
+{%- if not kind|is_nullable_kind %}
yzshen1 2015/02/17 19:34:35 (Please note that this part has been under signifi
azani 2015/02/18 00:27:57 Done.
+ if (object->{{name}}.is_null()) {
+ ReportValidationError(
+ mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
+ "null {{name}} field in {{struct.name}} struct");
+ return false;
+ }
+{%- endif %}
+ // We already claimed the union's memory as part of the struct, so we don't
+ // try to claim the union's memory when validating the union.
+ if (!{{kind.name}}::Data_::Validate(&object->{{name}}, bounds_checker, false)) {
yzshen1 2015/02/17 19:34:35 Do you think it make sense to make |false| a templ
azani 2015/02/18 00:27:57 It seems like we would just shift the inconsistenc
+ return false;
+ }
+{%- elif kind|is_object_kind %}
{%- set wrapper_type = kind|cpp_wrapper_type %}
{%- if not kind|is_nullable_kind %}
if (!object->{{name}}.offset) {
@@ -105,7 +119,9 @@
{%- macro encodes(struct) -%}
{%- for pf in struct.packed.packed_fields %}
-{%- if pf.field.kind|is_object_kind %}
+{%- if pf.field.kind|is_union_kind %}
+// TODO(azani): Encode pointers and handles.
+{%- elif pf.field.kind|is_object_kind %}
mojo::internal::Encode(&{{pf.field.name}}, handles);
{%- elif pf.field.kind|is_any_handle_kind %}
mojo::internal::EncodeHandle(&{{pf.field.name}}, handles);
@@ -115,7 +131,9 @@ mojo::internal::EncodeHandle(&{{pf.field.name}}, handles);
{%- macro decodes(struct) -%}
{%- for pf in struct.packed.packed_fields %}
-{%- if pf.field.kind|is_object_kind %}
+{%- if pf.field.kind|is_union_kind %}
+// TODO(azani): Decode pointers and handles.
+{%- elif pf.field.kind|is_object_kind %}
mojo::internal::Decode(&{{pf.field.name}}, handles);
{%- elif pf.field.kind|is_any_handle_kind %}
mojo::internal::DecodeHandle(&{{pf.field.name}}, handles);

Powered by Google App Engine
This is Rietveld 408576698