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): |