Chromium Code Reviews| 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 45f4d9d195505b2a97ca882e2e4b995fee3ee9da..d1be80539178455b696260bd28e69c5c7ec05c62 100644 |
| --- a/tools/json_schema_compiler/cc_generator.py |
| +++ b/tools/json_schema_compiler/cc_generator.py |
| @@ -3,11 +3,9 @@ |
| # found in the LICENSE file. |
| from code import Code |
| -from model import PropertyType, Type |
| +from model import PropertyType |
| import cpp_util |
| -import model |
| import schema_util |
| -import sys |
| import util_cc_helper |
|
not at google - send to devlin
2013/09/09 23:50:25
now that I know about the Python PEP8 thing, I kno
dhnishi (use Chromium)
2013/09/10 17:21:37
Done.
|
| class CCGenerator(object): |
| @@ -349,7 +347,7 @@ class _Generator(object): |
| is_ptr=is_ptr))) |
| if prop.optional: |
| - c.Eblock('}'); |
| + c.Eblock('}') |
| if type_.additional_properties is not None: |
| if type_.additional_properties.property_type == PropertyType.ANY: |
| @@ -382,7 +380,7 @@ class _Generator(object): |
| """ |
| c = Code() |
| c.Sblock('scoped_ptr<base::Value> %s::ToValue() const {' % cpp_namespace) |
| - c.Append('scoped_ptr<base::Value> result;'); |
| + c.Append('scoped_ptr<base::Value> result;') |
| for choice in type_.choices: |
| choice_var = 'as_%s' % choice.unix_name |
| (c.Sblock('if (%s) {' % choice_var) |
| @@ -406,9 +404,8 @@ class _Generator(object): |
| # TODO(kalman): use function.unix_name not Classname. |
| function_namespace = cpp_util.Classname(function.name) |
| - """Windows has a #define for SendMessage, so to avoid any issues, we need |
| - to not use the name. |
| - """ |
| + # Windows has a #define for SendMessage, so to avoid any issues, we need |
| + # to not use the name. |
| if function_namespace == 'SendMessage': |
| function_namespace = 'PassMessage' |
| (c.Append('namespace %s {' % function_namespace) |
| @@ -738,28 +735,28 @@ class _Generator(object): |
| dst_var, |
| failure_value, |
| is_ptr=False): |
| - """Returns Code that converts a ListValue of string constants from |
| - |src_var| into an array of enums of |type_| in |dst_var|. On failure, |
| - returns |failure_value|. |
| - """ |
| - c = Code() |
| - accessor = '.' |
| - if is_ptr: |
| - accessor = '->' |
| - cpp_type = self._type_helper.GetCppType(item_type, is_in_container=True) |
| - c.Append('%s.reset(new std::vector<%s>);' % |
| - (dst_var, cpp_util.PadForGenerics(cpp_type))) |
| - (c.Sblock('for (base::ListValue::const_iterator it = %s->begin(); ' |
| - 'it != %s->end(); ++it) {' % (src_var, src_var)) |
| - .Append('%s tmp;' % self._type_helper.GetCppType(item_type)) |
| - .Concat(self._GenerateStringToEnumConversion(item_type, |
| - '(*it)', |
| - 'tmp', |
| - failure_value)) |
| - .Append('%s%spush_back(tmp);' % (dst_var, accessor)) |
| - .Eblock('}') |
| - ) |
| - return c |
| + """Returns Code that converts a ListValue of string constants from |
| + |src_var| into an array of enums of |type_| in |dst_var|. On failure, |
| + returns |failure_value|. |
| + """ |
| + c = Code() |
| + accessor = '.' |
| + if is_ptr: |
| + accessor = '->' |
| + cpp_type = self._type_helper.GetCppType(item_type, is_in_container=True) |
| + c.Append('%s.reset(new std::vector<%s>);' % |
| + (dst_var, cpp_util.PadForGenerics(cpp_type))) |
| + (c.Sblock('for (base::ListValue::const_iterator it = %s->begin(); ' |
| + 'it != %s->end(); ++it) {' % (src_var, src_var)) |
| + .Append('%s tmp;' % self._type_helper.GetCppType(item_type)) |
| + .Concat(self._GenerateStringToEnumConversion(item_type, |
| + '(*it)', |
| + 'tmp', |
| + failure_value)) |
| + .Append('%s%spush_back(tmp);' % (dst_var, accessor)) |
| + .Eblock('}') |
| + ) |
| + return c |
| def _GenerateStringToEnumConversion(self, |
| type_, |