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

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: Synced. 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 1a7f80c8bc4afbf0e0f76c015b3ae5667ac82137..5225700c10fdad5a06c4b1f9999f5e03817cf81c 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
not at google - send to devlin 2012/07/03 14:21:39 hooray!
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(
not at google - send to devlin 2012/07/03 14:21:39 Some of the function names in json_schema_compiler
Matt Tytel 2012/07/11 02:08:50 Done.
+ "%s::Result" % cpp_namespace, function.callback))
c.Substitute({'cpp_namespace': cpp_namespace})
@@ -623,24 +634,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):
not at google - send to devlin 2012/07/03 14:21:39 the name "function_scope" keeps tripping me up. ju
Matt Tytel 2012/07/11 02:08:50 In this meaning, for a function A::B::C(), A::B is
+ """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
not at google - send to devlin 2012/07/03 14:21:39 ITYM "Baz".
Matt Tytel 2012/07/11 02:08:50 ITYR Done.
"""
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
@@ -654,12 +665,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) {')
not at google - send to devlin 2012/07/03 14:21:39 possible cleanup: make this return scoped_ptr<Valu
Matt Tytel 2012/07/11 02:08:50 I really like this, I'll file a separate issue if
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