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

Unified Diff: tools/json_schema_compiler/h_generator.py

Issue 10790040: JSON Schema Compiler now supports conversion from Choice to base::Value. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: added comments/style 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/h_generator.py
diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py
index 5f59ffbe04603f83e730b78cf7bbec8c94698bb7..85ad37102f803da1fade85e7886204601fdab548 100644
--- a/tools/json_schema_compiler/h_generator.py
+++ b/tools/json_schema_compiler/h_generator.py
@@ -253,7 +253,8 @@ class HGenerator(object):
if function.params:
(c.Sblock('struct Params {')
- .Concat(self._GeneratePropertyStructures(function.params))
+ .Concat(self._GeneratePropertyStructures(function.params,
+ from_function=True))
.Concat(self._GenerateFields(function.params))
.Append('~Params();')
.Append()
@@ -269,9 +270,10 @@ class HGenerator(object):
return c
- def _GeneratePropertyStructures(self, props):
+ def _GeneratePropertyStructures(self, props, from_function=False):
"""Generate the structures required by a property such as OBJECT classes
and enums.
+ If from_function is True if these properties belong to an API Function.
not at google - send to devlin 2012/07/18 01:21:35 You'll want to use from_client not from_function h
chebert 2012/07/19 00:56:01 Done.
"""
c = Code()
for prop in props:
@@ -287,6 +289,11 @@ class HGenerator(object):
prop,
[choice.type_.name for choice in prop.choices.values()]))
c.Concat(self._GeneratePropertyStructures(prop.choices.values()))
+ # We only need GetChoiceValue() if there is a ToValue() method.
+ if prop.from_json and not from_function:
not at google - send to devlin 2012/07/18 01:21:35 I think this should all be "prop.from_client"?
chebert 2012/07/19 00:56:01 Done.
+ c.Append('scoped_ptr<base::Value> GetChoiceValue(%s) const;' %
not at google - send to devlin 2012/07/18 01:21:35 Btw this should be generated under private; should
chebert 2012/07/19 00:56:01 Turns out the CreateEnumValue move to private is n
not at google - send to devlin 2012/07/19 01:48:22 sure thing
+ cpp_util.GetParameterDeclaration(prop,
+ self._cpp_type_generator.GetChoicesEnumType(prop)))
not at google - send to devlin 2012/07/18 01:21:35 There is some unfortunate whitespace thing going o
chebert 2012/07/19 00:56:01 Done.
elif prop.type_ == PropertyType.ENUM:
enum_name = self._cpp_type_generator.GetType(prop)
c.Concat(self._GenerateEnumDeclaration(
@@ -308,7 +315,7 @@ class HGenerator(object):
"""
c = Code()
params = function.params
- c.Concat(self._GeneratePropertyStructures(params))
+ c.Concat(self._GeneratePropertyStructures(params, from_function=True))
param_lists = self._cpp_type_generator.GetAllPossibleParameterLists(params)
for param_list in param_lists:

Powered by Google App Engine
This is Rietveld 408576698