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

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

Issue 2064903002: Mojo: Report bindings validation errors via MojoNotifyBadMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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 {#--- 1 {#---
2 Macro for enum definition, and the declaration of associated functions. 2 Macro for enum definition, and the declaration of associated functions.
3 ---#} 3 ---#}
4 {%- macro enum_decl(enum) %} 4 {%- macro enum_decl(enum) %}
5 enum class {{enum.name}} : int32_t { 5 enum class {{enum.name}} : int32_t {
6 {%- for field in enum.fields %} 6 {%- for field in enum.fields %}
7 {%- if field.value %} 7 {%- if field.value %}
8 {{field.name}} = {{field.value|expression_to_text}}, 8 {{field.name}} = {{field.value|expression_to_text}},
9 {%- else %} 9 {%- else %}
10 {{field.name}}, 10 {{field.name}},
(...skipping 12 matching lines...) Expand all
23 switch (value) { 23 switch (value) {
24 {%- for enum_field in enum.fields|groupby('numeric_value') %} 24 {%- for enum_field in enum.fields|groupby('numeric_value') %}
25 case {{enum_field[0]}}: 25 case {{enum_field[0]}}:
26 {%- endfor %} 26 {%- endfor %}
27 return true; 27 return true;
28 } 28 }
29 {%- endif %} 29 {%- endif %}
30 return false; 30 return false;
31 } 31 }
32 32
33 static bool Validate(int32_t value) { 33 static bool Validate(int32_t value,
34 mojo::internal::ValidationContext* validation_context) {
34 if (kIsExtensible || IsKnownValue(value)) 35 if (kIsExtensible || IsKnownValue(value))
35 return true; 36 return true;
36 37
37 ReportValidationError(mojo::internal::VALIDATION_ERROR_UNKNOWN_ENUM_VALUE); 38 ReportValidationError(validation_context,
39 mojo::internal::VALIDATION_ERROR_UNKNOWN_ENUM_VALUE);
38 return false; 40 return false;
39 } 41 }
40 }; 42 };
41 {%- endmacro %} 43 {%- endmacro %}
42 44
43 {#--- macros for enum-associated functions. Namely: 45 {#--- macros for enum-associated functions. Namely:
44 * operator<<(): outputs the given enum value. 46 * operator<<(): outputs the given enum value.
45 * IsKnownEnumValue(): returns true if the given enum value exists in this 47 * IsKnownEnumValue(): returns true if the given enum value exists in this
46 generated version of enum. 48 generated version of enum.
47 ---#} 49 ---#}
(...skipping 18 matching lines...) Expand all
66 } 68 }
67 } 69 }
68 {%- endmacro %} 70 {%- endmacro %}
69 71
70 {%- macro is_known_enum_value(enum) %} 72 {%- macro is_known_enum_value(enum) %}
71 inline bool IsKnownEnumValue({{enum|get_name_for_kind}} value) { 73 inline bool IsKnownEnumValue({{enum|get_name_for_kind}} value) {
72 return {{enum|get_qualified_name_for_kind(internal=True)}}::IsKnownValue( 74 return {{enum|get_qualified_name_for_kind(internal=True)}}::IsKnownValue(
73 static_cast<int32_t>(value)); 75 static_cast<int32_t>(value));
74 } 76 }
75 {%- endmacro %} 77 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698