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

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

Issue 1618963006: Mojo C++ bindings: support enum validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl
index 6a8254949795698009140db45bd03393bedcc70c..ecb64800289dcf1521b8e9b83f028657faea74b9 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl
@@ -91,6 +91,15 @@
return false;
{%- endmacro %}
+{#- Validates the specified struct field, which is supposed to be an enum.
+ This macro is expanded by the Validate() method. #}
+{%- macro _validate_enum(struct, packed_field) %}
+{%- set name = packed_field.field.name %}
+{%- set kind = packed_field.field.kind %}
+ if (!mojo::internal::ValidateEnum(object->{{name}}))
+ return false;
+{%- endmacro %}
+
// static
{{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) {
return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}();
@@ -146,7 +155,8 @@ bool {{class_name}}::Validate(const void* data,
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %}
{%- set kind = packed_field.field.kind %}
{%- if kind|is_object_kind or kind|is_any_handle_kind or
- kind|is_interface_kind or kind|is_associated_kind %}
+ kind|is_interface_kind or kind|is_associated_kind or
+ kind|is_enum_kind %}
{%- if packed_field.min_version > last_checked_version %}
{%- set last_checked_version = packed_field.min_version %}
if (object->header_.version < {{packed_field.min_version}})
@@ -156,8 +166,10 @@ bool {{class_name}}::Validate(const void* data,
{{_validate_object(struct, packed_field)}}
{%- elif kind|is_any_handle_kind or kind|is_interface_kind %}
{{_validate_handle(struct, packed_field)}}
-{%- else %}
+{%- elif kind|is_associated_kind %}
{{_validate_associated(struct, packed_field)}}
+{%- else %}
+{{_validate_enum(struct, packed_field)}}
{%- endif %}
{%- endif %}
{%- endfor %}

Powered by Google App Engine
This is Rietveld 408576698