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 2c47b5ed00b192ba9a38c2f53058f0253d31e6f8..17b6026e2cf76236daaf0ae6b2fc7c9ac38d3b65 100644 |
| --- a/tools/json_schema_compiler/cc_generator.py |
| +++ b/tools/json_schema_compiler/cc_generator.py |
| @@ -686,7 +686,7 @@ class _Generator(object): |
| item_type = self._type_helper.FollowRef(underlying_type.item_type) |
| if item_type.property_type == PropertyType.ENUM: |
| c.Concat(self._GenerateListValueToEnumArrayConversion( |
| - item_type, |
| + underlying_type.item_type, # Pass ref. |
|
not at google - send to devlin
2014/03/28 18:42:25
what does "Pass ref" mean?
mtomasz
2014/03/31 01:39:20
PropertyType of the passed type is equal to REF. R
|
| 'list', |
| dst_var, |
| failure_value, |
| @@ -779,7 +779,7 @@ class _Generator(object): |
| (c.Sblock('for (base::ListValue::const_iterator it = %s->begin(); ' |
| 'it != %s->end(); ++it) {' % (src_var, src_var)) |
| .Append('%s tmp;' % self._type_helper.GetCppType(item_type)) |
| - .Concat(self._GenerateStringToEnumConversion(item_type, |
| + .Concat(self._GenerateStringToEnumConversion(item_type, # Pass ref. |
| '(*it)', |
| 'tmp', |
| failure_value)) |
| @@ -799,6 +799,22 @@ class _Generator(object): |
| """ |
| c = Code() |
| enum_as_string = '%s_as_string' % type_.unix_name |
| + # The passed type may be either of REF type, or directly ENUM. Note, that |
| + # the second case is used only by JSON and it is always in the default |
| + # namespace. |
|
not at google - send to devlin
2014/03/28 18:42:25
It surprises me that enums need special treatment
mtomasz
2014/03/29 04:22:53
For enums we need to generate C++ code like this:
mtomasz
2014/03/31 01:39:20
I simplified the code. That's correct, that we don
|
| + cpp_type_fullname = self._type_helper.GetCppType(type_) |
| + cpp_type_namespace = None |
| + cpp_type_name = None |
| + # Eg. for other_namespace::EnumType: |
| + # cpp_type_fullname = other_namespace::EnumType |
| + # cpp_type_namespace = other_namespace |
| + # cpp_type_name = EnumType |
| + if type_.property_type == PropertyType.REF: |
| + enum_type = self._type_helper.FollowRef(type_) |
| + cpp_type_namespace = enum_type.namespace.unix_name |
| + cpp_type_name = self._type_helper.GetCppType(enum_type) |
| + else: |
| + cpp_type_name = cpp_type_fullname |
| (c.Append('std::string %s;' % enum_as_string) |
| .Sblock('if (!%s->GetAsString(&%s)) {' % (src_var, enum_as_string)) |
| .Concat(self._GenerateError( |
| @@ -806,11 +822,15 @@ class _Generator(object): |
| self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) |
| .Append('return %s;' % failure_value) |
| .Eblock('}') |
| - .Append('%s = Parse%s(%s);' % (dst_var, |
| - self._type_helper.GetCppType(type_), |
| - enum_as_string)) |
| - .Sblock('if (%s == %s) {' % (dst_var, |
| - self._type_helper.GetEnumNoneValue(type_))) |
| + .Append('%s = %sParse%s(%s);' % ( |
| + dst_var, |
| + cpp_type_namespace + '::' if cpp_type_namespace else '', |
| + cpp_type_name, |
| + enum_as_string)) |
| + .Sblock('if (%s == %s%s) {' % ( |
| + dst_var, |
| + cpp_type_namespace + '::' if cpp_type_namespace else '', |
| + self._type_helper.GetEnumNoneValue(type_))) |
| .Concat(self._GenerateError( |
| '\"\'%%(key)s\': expected \\"' + |
| '\\" or \\"'.join( |