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

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: bool function; becomes bool has_function; 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..6cb2b5f87afb8469631e0e42a3fad967295d0774 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
@@ -215,13 +216,21 @@ class CCGenerator(object):
value_var = prop.unix_name + '_value'
c.Append('base::Value* %(value_var)s = NULL;')
if prop.optional:
- (c.Sblock(
- 'if (%(src)s->GetWithoutPathExpansion("%(key)s", &%(value_var)s)) {'
+ if prop.type_ == PropertyType.FUNCTION:
not at google - send to devlin 2012/07/25 01:32:33 Comment why you're only generating for optional.
chebert 2012/07/25 18:38:30 the empty dict solved a lot of problems, so a lot
+ # For functions, we only want to check the presence, we are not actually
+ # getting a value
not at google - send to devlin 2012/07/25 01:32:33 nit: fullstop
chebert 2012/07/25 18:38:30 Done.
+ (c.Sblock('%s->has_%s = '
+ '%s->GetWithoutPathExpansion("%s", &%s);' %
not at google - send to devlin 2012/07/25 01:32:33 just use HasKey, don't need to Get it too.
+ (dst, prop.unix_name, src, prop.name, value_var))
+ )
+ else:
+ (c.Sblock(
+ 'if (%(src)s->GetWithoutPathExpansion("%(key)s", &%(value_var)s)) {'
+ )
+ .Concat(self._GeneratePopulatePropertyFromValue(
+ prop, value_var, dst, 'false'))
+ .Eblock('}')
)
- .Concat(self._GeneratePopulatePropertyFromValue(
- prop, value_var, dst, 'false'))
- .Eblock('}')
- )
else:
(c.Append(
'if (!%(src)s->GetWithoutPathExpansion("%(key)s", &%(value_var)s))')
@@ -250,7 +259,7 @@ class CCGenerator(object):
if prop.type_ == PropertyType.ADDITIONAL_PROPERTIES:
c.Append('value->MergeDictionary(&%s);' % prop.unix_name)
else:
- if prop.optional:
+ if prop.optional and not prop.type_ == PropertyType.FUNCTION:
not at google - send to devlin 2012/07/25 01:32:33 nit: assign this condition to a local variable and
chebert 2012/07/25 18:38:30 Done.
if prop.type_ == PropertyType.ENUM:
c.Sblock('if (%s != %s)' %
(prop.unix_name,
@@ -264,7 +273,7 @@ class CCGenerator(object):
c.Append('value->SetWithoutPathExpansion("%s", %s);' % (
prop.name,
self._CreateValueFromProperty(prop, 'this->' + prop.unix_name)))
- if prop.optional:
+ if prop.optional and not prop.type_ == PropertyType.FUNCTION:
c.Eblock();
(c.Append()
.Append('return value.Pass();')
@@ -318,6 +327,8 @@ class CCGenerator(object):
return '%s.DeepCopy()' % var
elif prop.type_ == PropertyType.ENUM:
return 'CreateEnumValue(%s).release()' % var
+ elif prop.type_ == PropertyType.FUNCTION:
not at google - send to devlin 2012/07/25 01:32:33 Hm, well, for consistency with the way that functi
chebert 2012/07/25 18:38:30 Done.
+ return 'base::Value::CreateBooleanValue(this->has_%s)' % prop.unix_name
elif prop.type_ == PropertyType.BINARY:
if prop.optional:
vardot = var + '->'
@@ -469,6 +480,8 @@ class CCGenerator(object):
'if (!%(ctype)s::Populate(*dictionary, &%(dst)s->%(name)s))')
.Append(' return %(failure_value)s;')
)
+ elif prop.type_ == PropertyType.FUNCTION:
+ c.Append('%s->has_%s = true;' % (dst, prop.unix_name))
not at google - send to devlin 2012/07/25 01:32:33 comment plz, the stuff about the renderer I said i
chebert 2012/07/25 18:38:30 Done.
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