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

Unified Diff: mojo/public/tools/bindings/generators/mojom_cpp_generator.py

Issue 466613002: Add validation logic for non-nullable types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/tools/bindings/generators/mojom_cpp_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
index 8f90c419d57c1dc1377f79806d743a5723290856..27c1b2bf5f8712f3c02d04a0483603ca001c634e 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -243,6 +243,24 @@ def ShouldInlineStruct(struct):
return False
return True
+def GetArrayValidateParams(kind):
+ if not mojom.IsAnyArrayKind(kind) and not mojom.IsStringKind(kind):
+ return "mojo::internal::NoValidateParams"
+
+ if mojom.IsStringKind(kind):
+ expected_num_elements = 0
+ element_nullable = False
+ element_validate_params = "mojo::internal::NoValidateParams"
+ else:
+ expected_num_elements = generator.ExpectedArraySize(kind)
+ element_nullable = mojom.IsNullableKind(kind.kind)
+ element_validate_params = GetArrayValidateParams(kind.kind)
+
+ return "mojo::internal::ArrayValidateParams<%d, %s,\n%s> " % (
+ expected_num_elements,
+ 'true' if element_nullable else 'false',
+ element_validate_params)
+
_HEADER_SIZE = 8
class Generator(generator.Generator):
@@ -258,6 +276,7 @@ class Generator(generator.Generator):
"default_value": DefaultValue,
"expected_array_size": generator.ExpectedArraySize,
"expression_to_text": ExpressionToText,
+ "get_array_validate_params": GetArrayValidateParams,
"get_name_for_kind": GetNameForKind,
"get_pad": pack.GetPad,
"has_callbacks": HasCallbacks,
@@ -268,6 +287,7 @@ class Generator(generator.Generator):
"is_any_handle_kind": mojom.IsAnyHandleKind,
"is_interface_kind": mojom.IsInterfaceKind,
"is_interface_request_kind": mojom.IsInterfaceRequestKind,
+ "is_nullable_kind": mojom.IsNullableKind,
"is_object_kind": mojom.IsObjectKind,
"is_string_kind": mojom.IsStringKind,
"is_struct_with_handles": IsStructWithHandles,
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698