Chromium Code Reviews| 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) |