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

Unified Diff: tools/json_schema_compiler/cpp_type_generator.py

Issue 9456007: Add wider support to json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rework, add nocompile to extension.json Created 8 years, 10 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/cpp_type_generator.py
diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py
index 186a6167b754281b81325e84428e97992967d755..b4735dde647fc225726056913c0ecbb0aadde446 100644
--- a/tools/json_schema_compiler/cpp_type_generator.py
+++ b/tools/json_schema_compiler/cpp_type_generator.py
@@ -21,6 +21,34 @@ class CppTypeGenerator(object):
self._cpp_namespaces = {}
self.AddNamespace(namespace, cpp_namespace)
+ def CreateValueFromProperty(self, util_cc_helper, prop, var):
not at google - send to devlin 2012/02/26 23:51:53 Why did you move this method into cpp_type_generat
calamity 2012/02/27 04:57:30 Mismove. Moved into cc_generator.
+ """Creates a Value given a single property. Generated code passes ownership
+ to caller. Does not support CHOICES.
not at google - send to devlin 2012/02/26 23:51:53 Rather than this little comment, could you add an
calamity 2012/02/27 04:57:30 Just raised an error for now. If we want to do fau
+
+ var: variable or variable*
+ """
+ if prop.type_ in (PropertyType.REF, PropertyType.OBJECT):
+ if prop.optional:
+ return '%s->ToValue().release()' % var
+ else:
+ return '%s.ToValue().release()' % var
+ elif prop.type_ == PropertyType.ENUM:
+ return 'CreateEnumValue(%s).release()' % var
+ elif prop.type_ == PropertyType.ARRAY:
+ return '%s.release()' % util_cc_helper.CreateValueFromArray(prop, var)
+ elif prop.type_.is_fundamental:
+ if prop.optional:
+ var = '*' + var
+ return {
+ PropertyType.STRING: 'Value::CreateStringValue(%s)',
+ PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)',
+ PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)',
+ PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)',
+ }[prop.type_] % var
+ else:
+ raise NotImplementedError('Conversion of single %s to Value not '
+ 'implemented' % repr(prop.type_))
+
def AddNamespace(self, namespace, cpp_namespace):
"""Maps a model.Namespace to its C++ namespace name. All mappings are
beneath the root namespace.
@@ -189,8 +217,9 @@ class CppTypeGenerator(object):
for function in self._namespace.functions.values():
for param in function.params:
dependencies |= self._PropertyTypeDependencies(param)
- for param in function.callback.params:
- dependencies |= self._PropertyTypeDependencies(param)
+ if function.callback:
+ for param in function.callback.params:
+ dependencies |= self._PropertyTypeDependencies(param)
for type_ in self._namespace.types.values():
for prop in type_.properties.values():
dependencies |= self._PropertyTypeDependencies(prop)

Powered by Google App Engine
This is Rietveld 408576698