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

Unified Diff: tools/json_schema_compiler/cc_generator.py

Issue 197873009: Support scoped types in PPAPI IDL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed compiling. Created 6 years, 9 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
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.
'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.
+ 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(

Powered by Google App Engine
This is Rietveld 408576698