Chromium Code Reviews| Index: tools/json_schema_compiler/cc_generator.py |
| diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py |
| index 021dce154c25756272d18485d3c5fe4cd0bebd21..ceb1370fc3ef0b5df937a2aa76cecf061f23ecc1 100644 |
| --- a/tools/json_schema_compiler/cc_generator.py |
| +++ b/tools/json_schema_compiler/cc_generator.py |
| @@ -448,16 +448,39 @@ class CCGenerator(object): |
| value_var, |
| '&temp')) |
| .Append(' return %(failure_value)s;') |
| - .Append('%(dst)s->%(name)s.reset(new %(ctype)s(temp));') |
| ) |
| + if prop.type_ != prop.compiled_type: |
| + (c.Append('%(compiled_ctype)s temp2;') |
| + .Append('if (!%s)' % |
| + cpp_util.GenerateTypeConversionCall( |
| + self._cpp_type_generator.GetReferencedProperty(prop), |
| + 'temp', |
| + '&temp2')) |
| + .Append(' return %(failure_value)s;') |
| + .Append('%(dst)s->%(name)s.reset(new %(compiled_ctype)s(temp2));') |
| + ) |
| + else: |
| + c.Append('%(dst)s->%(name)s.reset(new %(ctype)s(temp));') |
| + |
| else: |
| + if prop.type_ != prop.compiled_type: |
| + c.Append('%(ctype)s temp;') |
| (c.Append('if (!%s)' % |
| cpp_util.GetAsFundamentalValue( |
| self._cpp_type_generator.GetReferencedProperty(prop), |
| value_var, |
| - '&%s->%s' % (dst, prop.unix_name))) |
| + '%(fundamental_value_dst)s')) |
|
not at google - send to devlin
2012/07/27 04:14:28
can you inline this value? It's only used once so
mitchellwrosen
2012/07/30 20:52:45
Done.
|
| .Append(' return %(failure_value)s;') |
| ) |
| + if prop.type_ != prop.compiled_type: |
| + (c.Append('if (!%s)' % |
| + cpp_util.GenerateTypeConversionCall( |
| + self._cpp_type_generator.GetReferencedProperty(prop), |
| + 'temp', |
| + '&%s->%s' % (dst, prop.unix_name))) |
| + .Append(' return %(failure_value)s;') |
| + ) |
| + |
| elif self._IsObjectOrObjectRef(prop): |
| if prop.optional: |
| (c.Append('base::DictionaryValue* dictionary = NULL;') |
| @@ -543,9 +566,15 @@ class CCGenerator(object): |
| 'name': prop.unix_name, |
| 'dst': dst, |
| 'failure_value': failure_value, |
| + 'fundamental_value_dst': ( |
| + '&%s->%s' % (dst, prop.unix_name) |
| + if prop.type_ == prop.compiled_type |
| + else '&temp') |
| } |
| if prop.type_ not in (PropertyType.CHOICES, PropertyType.ANY): |
| sub['ctype'] = self._cpp_type_generator.GetType(prop) |
| + sub['compiled_ctype'] = self._cpp_type_generator.GetType( |
| + prop, convert_type=True) |
| sub['value_type'] = cpp_util.GetValueType(self._cpp_type_generator |
| .GetReferencedProperty(prop).type_) |
| c.Substitute(sub) |