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

Unified Diff: tools/json_schema_compiler/cc_generator.py

Issue 10825029: Added JSON schema compiler support for serialized types (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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 8cea17b588af55ed93f5df205ca5076d9bf6080d..d7cb65434bac1af48543bb1500d16b7149d00997 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -434,23 +434,55 @@ class CCGenerator(object):
if self._IsFundamentalOrFundamentalRef(prop):
if prop.optional:
- (c.Append('%(ctype)s temp;')
- .Append('if (!%s)' %
- cpp_util.GetAsFundamentalValue(
- self._cpp_type_generator.GetReferencedProperty(prop),
- value_var,
- '&temp'))
- .Append(' return %(failure_value)s;')
- .Append('%(dst)s->%(name)s.reset(new %(ctype)s(temp));')
- )
+ if prop.serialized_type is None:
+ (c.Append('%(ctype)s temp;')
+ .Append('if (!%s)' %
+ cpp_util.GetAsFundamentalValue(
+ self._cpp_type_generator.GetReferencedProperty(prop),
+ value_var,
+ '&temp'))
+ .Append(' return %(failure_value)s;')
+ .Append('%(dst)s->%(name)s.reset(new %(ctype)s(temp));')
+ )
+ else:
+ (c.Append('%(ctype)s temp1;')
+ .Append('%(serialized_ctype)s temp2;')
+ .Append('if (!%s || !%s)' %
+ (cpp_util.GetAsFundamentalValue(
+ self._cpp_type_generator.GetReferencedProperty(prop),
+ value_var,
+ '&temp1'),
+ cpp_util.DoConversion(
+ self._cpp_type_generator.GetReferencedProperty(prop),
+ 'temp1',
+ '&temp2')))
+ .Append(' return %(failure_value)s;')
+ .Append('%(dst)s->%(name)s.reset(new %(serialized_ctype)s(temp2));')
+ )
+
else:
- (c.Append('if (!%s)' %
- cpp_util.GetAsFundamentalValue(
- self._cpp_type_generator.GetReferencedProperty(prop),
- value_var,
- '&%s->%s' % (dst, prop.unix_name)))
- .Append(' return %(failure_value)s;')
- )
+ if prop.serialized_type is None:
+ (c.Append('if (!%s)' %
+ cpp_util.GetAsFundamentalValue(
+ self._cpp_type_generator.GetReferencedProperty(prop),
+ value_var,
+ '&%s->%s' % (dst, prop.unix_name)))
+ .Append(' return %(failure_value)s;')
+ )
+ else:
+ (c.Append('%(ctype)s temp;')
+ .Append('if (!%s || !%s)' %
+ (cpp_util.GetAsFundamentalValue(
+ self._cpp_type_generator.GetReferencedProperty(prop),
+ value_var,
+ '&temp'),
+ cpp_util.DoConversion(
+ 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;')
@@ -536,6 +568,8 @@ class CCGenerator(object):
}
if prop.type_ not in (PropertyType.CHOICES, PropertyType.ANY):
sub['ctype'] = self._cpp_type_generator.GetType(prop)
+ sub['serialized_ctype'] = self._cpp_type_generator.GetType(
+ prop, serialized=True)
sub['value_type'] = cpp_util.GetValueType(self._cpp_type_generator
.GetReferencedProperty(prop).type_)
c.Substitute(sub)
« no previous file with comments | « no previous file | tools/json_schema_compiler/cpp_type_generator.py » ('j') | tools/json_schema_compiler/cpp_type_generator.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698