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

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

Issue 2965663002: Mojo C++ bindings: support setting default value for fields whose types are typemapped enums. (Closed)
Patch Set: . Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/interfaces/bindings/tests/struct_with_traits.mojom ('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 a60389f6a217ba916c89bc2de11fc1402c01f563..4679f089aa3fa6b59fe88d7283a5a1d7757d0fe6 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -400,16 +400,22 @@ class Generator(generator.Generator):
def _ConstantValue(self, constant):
return self._ExpressionToText(constant.value, kind=constant.kind)
- # TODO(yzshen): Revisit the default value feature. It was designed prior to
- # custom type mapping.
def _DefaultValue(self, field):
- if field.default:
- if mojom.IsStructKind(field.kind):
- assert field.default == "default"
- if not self._IsTypemappedKind(field.kind):
- return "%s::New()" % self._GetNameForKind(field.kind)
- return self._ExpressionToText(field.default, kind=field.kind)
- return ""
+ if not field.default:
+ return ""
+
+ if mojom.IsStructKind(field.kind):
+ assert field.default == "default"
+ if self._IsTypemappedKind(field.kind):
+ return ""
+ return "%s::New()" % self._GetNameForKind(field.kind)
+
+ expression = self._ExpressionToText(field.default, kind=field.kind)
+ if mojom.IsEnumKind(field.kind) and self._IsTypemappedKind(field.kind):
+ expression = "mojo::internal::ConvertEnumValue<%s, %s>(%s)" % (
+ self._GetNameForKind(field.kind), self._GetCppWrapperType(field.kind),
+ expression)
+ return expression
def _GetNameForKind(self, kind, internal=False, flatten_nested_kind=False,
add_same_module_namespaces=False):
« no previous file with comments | « mojo/public/interfaces/bindings/tests/struct_with_traits.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698