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

Unified Diff: tools/json_schema_compiler/h_generator.py

Issue 10701012: JSON Schema Compiler: Added event compilation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/model.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5e7e7003a36629161c365e2d5ed0df237e8ace39..4d8cc60175dd97525864d60187b5ac3cd46fd840 100644
--- a/tools/json_schema_compiler/h_generator.py
+++ b/tools/json_schema_compiler/h_generator.py
@@ -92,6 +92,16 @@ class HGenerator(object):
(c.Concat(self._GenerateFunction(function))
.Append()
)
+ if self._namespace.events:
+ (c.Append('//')
+ .Append('// Events')
+ .Append('//')
+ .Append()
+ )
+ for event in self._namespace.events.values():
+ (c.Concat(self._GenerateEvent(event))
+ .Append()
+ )
(c.Concat(self._cpp_type_generator.GetNamespaceEnd())
.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
.Append()
@@ -212,6 +222,15 @@ class HGenerator(object):
c.Substitute({'classname': classname})
return c
+ def _GenerateEvent(self, event):
+ """Generates the structs for an event.
+ """
+ c = Code()
+ c.Sblock('namespace %s {' % cpp_util.Classname(event.name))
+ c.Concat(self._GenerateClientFunction(event))
+ c.Eblock('};')
+ return c
+
def _GenerateFunction(self, function):
"""Generates the structs for a function.
"""
@@ -221,7 +240,7 @@ class HGenerator(object):
.Append()
)
if function.callback:
- (c.Concat(self._GenerateFunctionResult(function))
+ (c.Concat(self._GenerateFunctionResult(function.callback))
.Append()
)
c.Eblock('};')
@@ -274,17 +293,22 @@ class HGenerator(object):
enum_name,
prop,
prop.enum_values))
- c.Append('static scoped_ptr<Value> CreateEnumValue(%s %s);' %
- (enum_name, prop.unix_name))
+ # If the property is from the UI then we're in a struct so this function
+ # should be static. If it's from the client, then we're just in a
+ # namespace so we don't need the static keyword.
+ if prop.from_json:
Matt Tytel 2012/06/27 23:11:48 This is a bit of a hack. I'm currently looking for
+ c.Append('static scoped_ptr<Value> CreateEnumValue(%s %s);' %
+ (enum_name, prop.unix_name))
+ else:
+ c.Append('scoped_ptr<Value> CreateEnumValue(%s %s);' %
+ (enum_name, prop.unix_name))
return c
- def _GenerateFunctionResult(self, function):
- """Generates functions for passing a function's result back.
+ def _GenerateClientFunction(self, function):
+ """Generates functions for passing paramaters to a callback.
"""
c = Code()
-
- c.Sblock('namespace Result {')
- params = function.callback.params
+ params = function.params
if not params:
c.Append('Value* Create();')
else:
@@ -303,6 +327,15 @@ class HGenerator(object):
continue
c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration(
param, self._cpp_type_generator.GetType(param)))
+
+ return c
+
+ def _GenerateFunctionResult(self, callback):
+ """Generates namespace for passing a function's result back.
+ """
+ c = Code()
+ c.Sblock('namespace Result {')
+ c.Concat(self._GenerateClientFunction(callback))
c.Eblock('};')
return c
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/model.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698