| 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 | 10 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 elif type_.property_type == PropertyType.ENUM: | 139 elif type_.property_type == PropertyType.ENUM: |
| 140 (c.Cblock(self._GenerateEnumToString(cpp_namespace, type_)) | 140 (c.Cblock(self._GenerateEnumToString(cpp_namespace, type_)) |
| 141 .Cblock(self._GenerateEnumFromString(cpp_namespace, type_)) | 141 .Cblock(self._GenerateEnumFromString(cpp_namespace, type_)) |
| 142 ) | 142 ) |
| 143 | 143 |
| 144 return c | 144 return c |
| 145 | 145 |
| 146 def _GenerateInitializersAndBody(self, type_): | 146 def _GenerateInitializersAndBody(self, type_): |
| 147 items = [] | 147 items = [] |
| 148 for prop in type_.properties.values(): | 148 for prop in type_.properties.values(): |
| 149 if prop.optional: | 149 t = prop.type_ |
| 150 |
| 151 real_t = self._type_helper.FollowRef(t) |
| 152 if real_t.property_type == PropertyType.ENUM: |
| 153 items.append('%s(%s)' % ( |
| 154 prop.unix_name, |
| 155 self._type_helper.GetEnumNoneValue(t))) |
| 156 elif prop.optional: |
| 150 continue | 157 continue |
| 151 | 158 elif t.property_type == PropertyType.INTEGER: |
| 152 t = prop.type_ | |
| 153 if t.property_type == PropertyType.INTEGER: | |
| 154 items.append('%s(0)' % prop.unix_name) | 159 items.append('%s(0)' % prop.unix_name) |
| 155 elif t.property_type == PropertyType.DOUBLE: | 160 elif t.property_type == PropertyType.DOUBLE: |
| 156 items.append('%s(0.0)' % prop.unix_name) | 161 items.append('%s(0.0)' % prop.unix_name) |
| 157 elif t.property_type == PropertyType.BOOLEAN: | 162 elif t.property_type == PropertyType.BOOLEAN: |
| 158 items.append('%s(false)' % prop.unix_name) | 163 items.append('%s(false)' % prop.unix_name) |
| 159 elif (t.property_type == PropertyType.ANY or | 164 elif (t.property_type == PropertyType.ANY or |
| 160 t.property_type == PropertyType.ARRAY or | 165 t.property_type == PropertyType.ARRAY or |
| 161 t.property_type == PropertyType.BINARY or # mapped to std::string | 166 t.property_type == PropertyType.BINARY or # mapped to std::string |
| 162 t.property_type == PropertyType.CHOICES or | 167 t.property_type == PropertyType.CHOICES or |
| 163 t.property_type == PropertyType.ENUM or | |
| 164 t.property_type == PropertyType.OBJECT or | 168 t.property_type == PropertyType.OBJECT or |
| 165 t.property_type == PropertyType.FUNCTION or | 169 t.property_type == PropertyType.FUNCTION or |
| 166 t.property_type == PropertyType.REF or | 170 t.property_type == PropertyType.REF or |
| 167 t.property_type == PropertyType.STRING): | 171 t.property_type == PropertyType.STRING): |
| 168 # TODO(miket): It would be nice to initialize CHOICES and ENUM, but we | 172 # TODO(miket): It would be nice to initialize CHOICES, but we |
| 169 # don't presently have the semantics to indicate which one of a set | 173 # don't presently have the semantics to indicate which one of a set |
| 170 # should be the default. | 174 # should be the default. |
| 171 continue | 175 continue |
| 172 else: | 176 else: |
| 173 raise TypeError(t) | 177 raise TypeError(t) |
| 174 | 178 |
| 175 if items: | 179 if items: |
| 176 s = ': %s' % (', '.join(items)) | 180 s = ': %s' % (', '.join(items)) |
| 177 else: | 181 else: |
| 178 s = '' | 182 s = '' |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 if self._generate_error_messages: | 1064 if self._generate_error_messages: |
| 1061 params = list(params) + ['base::string16* error'] | 1065 params = list(params) + ['base::string16* error'] |
| 1062 return ', '.join(str(p) for p in params) | 1066 return ', '.join(str(p) for p in params) |
| 1063 | 1067 |
| 1064 def _GenerateArgs(self, args): | 1068 def _GenerateArgs(self, args): |
| 1065 """Builds the argument list for a function, given an array of arguments. | 1069 """Builds the argument list for a function, given an array of arguments. |
| 1066 """ | 1070 """ |
| 1067 if self._generate_error_messages: | 1071 if self._generate_error_messages: |
| 1068 args = list(args) + ['error'] | 1072 args = list(args) + ['error'] |
| 1069 return ', '.join(str(a) for a in args) | 1073 return ', '.join(str(a) for a in args) |
| OLD | NEW |