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

Unified Diff: tools/json_schema_compiler/cc_generator.py

Issue 10824002: JSON Schema Compiler supports functions as PropertyTypes. (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..021dce154c25756272d18485d3c5fe4cd0bebd21 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -152,6 +152,7 @@ class CCGenerator(object):
t == PropertyType.CHOICES or
t == PropertyType.ENUM or
t == PropertyType.OBJECT or
+ t == PropertyType.FUNCTION or
t == PropertyType.REF or
t == PropertyType.STRING):
# TODO(miket): It would be nice to initialize CHOICES and ENUM, but we
@@ -316,6 +317,12 @@ class CCGenerator(object):
return '%s.DeepCopy()' % self._any_helper.GetValue(prop, var)
elif prop.type_ == PropertyType.ADDITIONAL_PROPERTIES:
return '%s.DeepCopy()' % var
+ elif prop.type_ == PropertyType.FUNCTION:
+ if prop.optional:
+ vardot = var + '->'
+ else:
+ vardot = var + '.'
+ return '%sDeepCopy()' % vardot
elif prop.type_ == PropertyType.ENUM:
return 'CreateEnumValue(%s).release()' % var
elif prop.type_ == PropertyType.BINARY:
@@ -469,6 +476,9 @@ class CCGenerator(object):
'if (!%(ctype)s::Populate(*dictionary, &%(dst)s->%(name)s))')
.Append(' return %(failure_value)s;')
)
+ elif prop.type_ == PropertyType.FUNCTION:
+ if prop.optional:
+ c.Append('%(dst)s->%(name)s.reset(new base::DictionaryValue());')
elif prop.type_ == PropertyType.ANY:
if prop.optional:
c.Append('%(dst)s->%(name)s.reset(new ' + any_helper.ANY_CLASS + '());')

Powered by Google App Engine
This is Rietveld 408576698