| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from code import Code | 5 from code import Code |
| 6 from model import PropertyType | 6 from model import PropertyType |
| 7 import cpp_util | 7 import cpp_util |
| 8 import schema_util | 8 import schema_util |
| 9 import util_cc_helper | 9 import util_cc_helper |
| 10 from cpp_namespace_environment import CppNamespaceEnvironment | 10 from cpp_namespace_environment import CppNamespaceEnvironment |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 elif prop.optional: | 153 elif prop.optional: |
| 154 continue | 154 continue |
| 155 elif t.property_type == PropertyType.INTEGER: | 155 elif t.property_type == PropertyType.INTEGER: |
| 156 items.append('%s(0)' % prop.unix_name) | 156 items.append('%s(0)' % prop.unix_name) |
| 157 elif t.property_type == PropertyType.DOUBLE: | 157 elif t.property_type == PropertyType.DOUBLE: |
| 158 items.append('%s(0.0)' % prop.unix_name) | 158 items.append('%s(0.0)' % prop.unix_name) |
| 159 elif t.property_type == PropertyType.BOOLEAN: | 159 elif t.property_type == PropertyType.BOOLEAN: |
| 160 items.append('%s(false)' % prop.unix_name) | 160 items.append('%s(false)' % prop.unix_name) |
| 161 elif (t.property_type == PropertyType.ANY or | 161 elif (t.property_type == PropertyType.ANY or |
| 162 t.property_type == PropertyType.ARRAY or | 162 t.property_type == PropertyType.ARRAY or |
| 163 t.property_type == PropertyType.BINARY or # mapped to std::string | 163 t.property_type == PropertyType.BINARY or |
| 164 t.property_type == PropertyType.CHOICES or | 164 t.property_type == PropertyType.CHOICES or |
| 165 t.property_type == PropertyType.OBJECT or | 165 t.property_type == PropertyType.OBJECT or |
| 166 t.property_type == PropertyType.FUNCTION or | 166 t.property_type == PropertyType.FUNCTION or |
| 167 t.property_type == PropertyType.REF or | 167 t.property_type == PropertyType.REF or |
| 168 t.property_type == PropertyType.STRING): | 168 t.property_type == PropertyType.STRING): |
| 169 # TODO(miket): It would be nice to initialize CHOICES, but we | 169 # TODO(miket): It would be nice to initialize CHOICES, but we |
| 170 # don't presently have the semantics to indicate which one of a set | 170 # don't presently have the semantics to indicate which one of a set |
| 171 # should be the default. | 171 # should be the default. |
| 172 continue | 172 continue |
| 173 else: | 173 else: |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) | 810 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) |
| 811 ) | 811 ) |
| 812 if not self._generate_error_messages: | 812 if not self._generate_error_messages: |
| 813 c.Append('return %(failure_value)s;') | 813 c.Append('return %(failure_value)s;') |
| 814 (c.Eblock('}') | 814 (c.Eblock('}') |
| 815 .Sblock('else {') | 815 .Sblock('else {') |
| 816 .Append(' binary_value =') | 816 .Append(' binary_value =') |
| 817 .Append(' static_cast<const base::BinaryValue*>(%(src_var)s);') | 817 .Append(' static_cast<const base::BinaryValue*>(%(src_var)s);') |
| 818 ) | 818 ) |
| 819 if is_ptr: | 819 if is_ptr: |
| 820 (c.Append('%(dst_var)s.reset(') | 820 (c.Append('%(dst_var)s.reset(new std::vector<char>(') |
| 821 .Append(' new std::string(binary_value->GetBuffer(),') | 821 .Append(' binary_value->GetBuffer(),') |
| 822 .Append(' binary_value->GetSize()));') | 822 .Append(' binary_value->GetBuffer() + binary_value->GetSize()));') |
| 823 ) | 823 ) |
| 824 else: | 824 else: |
| 825 (c.Append('%(dst_var)s.assign(binary_value->GetBuffer(),') | 825 (c.Append('%(dst_var)s.assign(') |
| 826 .Append(' binary_value->GetSize());') | 826 .Append(' binary_value->GetBuffer(),') |
| 827 .Append(' binary_value->GetBuffer() + binary_value->GetSize());') |
| 827 ) | 828 ) |
| 828 c.Eblock('}') | 829 c.Eblock('}') |
| 829 else: | 830 else: |
| 830 raise NotImplementedError(type_) | 831 raise NotImplementedError(type_) |
| 831 if c.IsEmpty(): | 832 if c.IsEmpty(): |
| 832 return c | 833 return c |
| 833 return Code().Sblock('{').Concat(c.Substitute({ | 834 return Code().Sblock('{').Concat(c.Substitute({ |
| 834 'cpp_type': self._type_helper.GetCppType(type_), | 835 'cpp_type': self._type_helper.GetCppType(type_), |
| 835 'src_var': src_var, | 836 'src_var': src_var, |
| 836 'dst_var': dst_var, | 837 'dst_var': dst_var, |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 if self._generate_error_messages: | 1062 if self._generate_error_messages: |
| 1062 params = list(params) + ['base::string16* error'] | 1063 params = list(params) + ['base::string16* error'] |
| 1063 return ', '.join(str(p) for p in params) | 1064 return ', '.join(str(p) for p in params) |
| 1064 | 1065 |
| 1065 def _GenerateArgs(self, args): | 1066 def _GenerateArgs(self, args): |
| 1066 """Builds the argument list for a function, given an array of arguments. | 1067 """Builds the argument list for a function, given an array of arguments. |
| 1067 """ | 1068 """ |
| 1068 if self._generate_error_messages: | 1069 if self._generate_error_messages: |
| 1069 args = list(args) + ['error'] | 1070 args = list(args) + ['error'] |
| 1070 return ', '.join(str(a) for a in args) | 1071 return ', '.join(str(a) for a in args) |
| OLD | NEW |