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 10701012: JSON Schema Compiler: Added event compilation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added more testing for event compilation. Created 8 years, 6 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 3bba684b21e9ace38fa7a5385447566504015c7d..224a22b00fc56907553c6e1e5326ff40ef3581d3 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -86,11 +86,21 @@ class CCGenerator(object):
cpp_util.Classname(function.name), function))
.Append()
)
+ if self._namespace.events:
+ (c.Append('//')
+ .Append('// Events')
+ .Append('//')
+ .Append()
+ )
+ for event in self._namespace.events.values():
+ (c.Concat(self._GenerateCallbackCreate(
+ cpp_util.Classname(event.name), event))
+ .Append()
+ )
(c.Concat(self._cpp_type_generator.GetNamespaceEnd())
.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
.Append()
)
- # TODO(calamity): Events
return c
def _GenerateType(self, cpp_namespace, type_):
@@ -280,7 +290,8 @@ class CCGenerator(object):
# Result::Create function
if function.callback:
- c.Concat(self._GenerateFunctionResultCreate(cpp_namespace, function))
+ c.Concat(self._GenerateCallbackCreate(
+ "%s::Result" % cpp_namespace, function.callback))
c.Substitute({'cpp_namespace': cpp_namespace})
@@ -587,24 +598,24 @@ class CCGenerator(object):
c.Append()
return c
- def _GenerateFunctionResultCreate(self, cpp_namespace, function):
- """Generate function to create a Result given the return value.
+ def _GenerateCallbackCreate(self, function_scope, callback):
+ """Generate function to create Value parameters for a callback.
E.g for function "Bar", generate Bar::Result::Create
+ E.g for event "Gar", generate Gar::Create
"""
c = Code()
- params = function.callback.params
+ params = callback.params
if not params:
- (c.Append('Value* %s::Result::Create() {' % cpp_namespace)
+ (c.Append('Value* %s::Create() {' % function_scope)
.Append(' return Value::CreateNullValue();')
.Append('}')
)
else:
expanded_params = self._cpp_type_generator.GetExpandedChoicesInParams(
params)
- c.Concat(self._GeneratePropertyFunctions(
- cpp_namespace + '::Result', expanded_params))
+ c.Concat(self._GeneratePropertyFunctions(function_scope, expanded_params))
# If there is a single parameter, this is straightforward. However, if
# the callback parameter is of 'choices', this generates a Create method
@@ -618,12 +629,12 @@ class CCGenerator(object):
# scoped_ptr if it's optional.
param_copy = param.Copy()
param_copy.optional = False
- c.Sblock('Value* %(cpp_namespace)s::Result::Create(const %(arg)s) {')
+ c.Sblock('Value* %(function_scope)s::Create(const %(arg)s) {')
c.Append('return %s;' %
self._CreateValueFromProperty(param_copy, param_copy.unix_name))
c.Eblock('}')
c.Substitute({
- 'cpp_namespace': cpp_namespace,
+ 'function_scope': function_scope,
'arg': cpp_util.GetParameterDeclaration(
param_copy, self._cpp_type_generator.GetType(param_copy))
})

Powered by Google App Engine
This is Rietveld 408576698