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

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

Issue 2247083003: Mojo C++ bindings: extract code shared by different variants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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 {#- Validates the specified field, which is supposed to be an object 1 {#- Validates the specified field, which is supposed to be an object
2 (struct/array/string/map/union). If it is a union, |union_is_inlined| 2 (struct/array/string/map/union). If it is a union, |union_is_inlined|
3 indicates whether the union is inlined. (Nested unions are not inlined.) 3 indicates whether the union is inlined. (Nested unions are not inlined.)
4 This macro is expanded by the Validate() method. #} 4 This macro is expanded by the Validate() method. #}
5 {%- macro validate_object(field, field_expr, object_name, union_is_inlined) %} 5 {%- macro validate_object(field, field_expr, object_name, union_is_inlined) %}
6 {%- set name = field.name %} 6 {%- set name = field.name %}
7 {%- set kind = field.kind %} 7 {%- set kind = field.kind %}
8 {%- if not kind|is_nullable_kind %} 8 {%- if not kind|is_nullable_kind %}
9 {%- if kind|is_union_kind and union_is_inlined %} 9 {%- if kind|is_union_kind and union_is_inlined %}
10 if (!mojo::internal::ValidateInlinedUnionNonNullable( 10 if (!mojo::internal::ValidateInlinedUnionNonNullable(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 {%- endif %} 59 {%- endif %}
60 if (!mojo::internal::ValidateHandleOrInterface({{field_expr}}, 60 if (!mojo::internal::ValidateHandleOrInterface({{field_expr}},
61 validation_context)) { 61 validation_context)) {
62 return false; 62 return false;
63 } 63 }
64 {%- endmacro %} 64 {%- endmacro %}
65 65
66 {#- Validates the specified field, which is supposed to be an enum. 66 {#- Validates the specified field, which is supposed to be an enum.
67 This macro is expanded by the Validate() method. #} 67 This macro is expanded by the Validate() method. #}
68 {%- macro validate_enum(field, field_expr) %} 68 {%- macro validate_enum(field, field_expr) %}
69 if (!{{field.kind|get_qualified_name_for_kind(internal=True)}} 69 if (!{{field.kind|get_qualified_name_for_kind(internal=True,flatten_nested_kin d=True)}}
70 ::Validate({{field_expr}}, validation_context)) 70 ::Validate({{field_expr}}, validation_context))
71 return false; 71 return false;
72 {%- endmacro %} 72 {%- endmacro %}
73 73
74 {%- macro validate_field(field, field_expr, object_name, union_is_inlined) %} 74 {%- macro validate_field(field, field_expr, object_name, union_is_inlined) %}
75 {%- if field.kind|is_object_kind -%} 75 {%- if field.kind|is_object_kind -%}
76 {{validate_object(field, field_expr, object_name, union_is_inlined)}} 76 {{validate_object(field, field_expr, object_name, union_is_inlined)}}
77 {%- elif field.kind|is_any_handle_or_interface_kind -%} 77 {%- elif field.kind|is_any_handle_or_interface_kind -%}
78 {{validate_handle_or_interface(field, field_expr, object_name)}} 78 {{validate_handle_or_interface(field, field_expr, object_name)}}
79 {%- elif field.kind|is_enum_kind %} 79 {%- elif field.kind|is_enum_kind %}
80 {{validate_enum(field, field_expr)}} 80 {{validate_enum(field, field_expr)}}
81 {%- endif %} 81 {%- endif %}
82 {%- endmacro %} 82 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698