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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/validation_macros.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, 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 unified diff | Download patch
OLDNEW
1 {%- macro validate_not_null_ptr(field_expr, field, object_name) %} 1 {%- macro validate_not_null_ptr(field_expr, field, object_name) %}
2 if (!{{field_expr}}->offset) { 2 if (!{{field_expr}}->offset) {
3 ReportValidationError( 3 ReportValidationError(
4 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, 4 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
5 "null {{field.name}} field in {{object_name}}"); 5 "null {{field.name}} field in {{object_name}}");
6 return false; 6 return false;
7 } 7 }
8 {%- endmacro %} 8 {%- endmacro %}
9 9
10 {%- macro validate_encoded_ptr(field_expr) %} 10 {%- macro validate_encoded_ptr(field_expr) %}
(...skipping 23 matching lines...) Expand all
34 "invalid {{field.name}} field in {{object_name}}"); 34 "invalid {{field.name}} field in {{object_name}}");
35 return false; 35 return false;
36 } 36 }
37 {%- endif %} 37 {%- endif %}
38 if (!bounds_checker->ClaimHandle({{field.name}}_handle)) { 38 if (!bounds_checker->ClaimHandle({{field.name}}_handle)) {
39 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_HANDLE); 39 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_HANDLE);
40 return false; 40 return false;
41 } 41 }
42 {%- endmacro -%} 42 {%- endmacro -%}
43 43
44 {%- macro validate_enum(field_expr, field) -%}
45 if (!mojo::internal::ValidateEnum(*{{field_expr}}))
46 return false;
47 {%- endmacro -%}
48
44 {%- macro validate_union_field(field, union) %} 49 {%- macro validate_union_field(field, union) %}
45 {%- set field_expr = "(reinterpret_cast<const " 50 {%- set field_expr = "(reinterpret_cast<const "
46 ~ field.kind|cpp_union_field_type 51 ~ field.kind|cpp_union_field_type
47 ~ "*>(&object->data.f_" 52 ~ "*>(&object->data.f_"
48 ~ field.name 53 ~ field.name
49 ~ "))" -%} 54 ~ "))" -%}
50 {%- if field.kind|is_object_kind -%} 55 {%- if field.kind|is_object_kind -%}
51 {%- if not field.kind|is_nullable_kind -%} 56 {%- if not field.kind|is_nullable_kind -%}
52 {{ validate_not_null_ptr(field_expr, field, union.name) }} 57 {{ validate_not_null_ptr(field_expr, field, union.name) }}
53 {%- endif %} 58 {%- endif %}
54 {{ validate_encoded_ptr(field_expr) }} 59 {{ validate_encoded_ptr(field_expr) }}
55 {%- endif %} 60 {%- endif %}
56 61
57 {%- if field.kind|is_array_kind or field.kind|is_string_kind -%} 62 {%- if field.kind|is_array_kind or field.kind|is_string_kind -%}
58 {{ validate_array_or_string(field_expr, field) }} 63 {{ validate_array_or_string(field_expr, field) }}
59 {%- endif %} 64 {%- endif %}
60 65
61 {%- if field.kind|is_any_handle_kind -%} 66 {%- if field.kind|is_any_handle_kind -%}
62 {{ validate_handle(field_expr, field, union.name) }} 67 {{ validate_handle(field_expr, field, union.name) }}
63 {%- endif %} 68 {%- endif %}
69
70 {%- if field.kind|is_enum_kind -%}
71 {{ validate_enum(field_expr, field) }}
72 {%- endif %}
64 return true; 73 return true;
65 {%- endmacro %} 74 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698