| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 for prop in type_.properties.values(): | 155 for prop in type_.properties.values(): |
| 156 t = prop.type_ | 156 t = prop.type_ |
| 157 | 157 |
| 158 real_t = self._type_helper.FollowRef(t) | 158 real_t = self._type_helper.FollowRef(t) |
| 159 if real_t.property_type == PropertyType.ENUM: | 159 if real_t.property_type == PropertyType.ENUM: |
| 160 namespace_prefix = ('%s::' % real_t.namespace.unix_name | 160 namespace_prefix = ('%s::' % real_t.namespace.unix_name |
| 161 if real_t.namespace != self._namespace | 161 if real_t.namespace != self._namespace |
| 162 else '') | 162 else '') |
| 163 items.append('%s(%s%s)' % (prop.unix_name, | 163 items.append('%s(%s%s)' % (prop.unix_name, |
| 164 namespace_prefix, | 164 namespace_prefix, |
| 165 self._type_helper.GetEnumNoneValue(t))) | 165 self._type_helper.GetEnumNoneValue(real_t))) |
| 166 elif prop.optional: | 166 elif prop.optional: |
| 167 continue | 167 continue |
| 168 elif t.property_type == PropertyType.INTEGER: | 168 elif t.property_type == PropertyType.INTEGER: |
| 169 items.append('%s(0)' % prop.unix_name) | 169 items.append('%s(0)' % prop.unix_name) |
| 170 elif t.property_type == PropertyType.DOUBLE: | 170 elif t.property_type == PropertyType.DOUBLE: |
| 171 items.append('%s(0.0)' % prop.unix_name) | 171 items.append('%s(0.0)' % prop.unix_name) |
| 172 elif t.property_type == PropertyType.BOOLEAN: | 172 elif t.property_type == PropertyType.BOOLEAN: |
| 173 items.append('%s(false)' % prop.unix_name) | 173 items.append('%s(false)' % prop.unix_name) |
| 174 elif (t.property_type == PropertyType.ANY or | 174 elif (t.property_type == PropertyType.ANY or |
| 175 t.property_type == PropertyType.ARRAY or | 175 t.property_type == PropertyType.ARRAY or |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 .Concat(self._GeneratePopulatePropertyFromValue( | 380 .Concat(self._GeneratePopulatePropertyFromValue( |
| 381 prop, value_var, dst, 'false'))) | 381 prop, value_var, dst, 'false'))) |
| 382 underlying_type = self._type_helper.FollowRef(prop.type_) | 382 underlying_type = self._type_helper.FollowRef(prop.type_) |
| 383 if underlying_type.property_type == PropertyType.ENUM: | 383 if underlying_type.property_type == PropertyType.ENUM: |
| 384 namespace_prefix = ('%s::' % underlying_type.namespace.unix_name | 384 namespace_prefix = ('%s::' % underlying_type.namespace.unix_name |
| 385 if underlying_type.namespace != self._namespace | 385 if underlying_type.namespace != self._namespace |
| 386 else '') | 386 else '') |
| 387 (c.Append('} else {') | 387 (c.Append('} else {') |
| 388 .Append('%%(dst)s->%%(name)s = %s%s;' % | 388 .Append('%%(dst)s->%%(name)s = %s%s;' % |
| 389 (namespace_prefix, | 389 (namespace_prefix, |
| 390 self._type_helper.GetEnumNoneValue(prop.type_)))) | 390 self._type_helper.GetEnumNoneValue(underlying_type)))) |
| 391 c.Eblock('}') | 391 c.Eblock('}') |
| 392 else: | 392 else: |
| 393 (c.Sblock( | 393 (c.Sblock( |
| 394 'if (!%(src)s->GetWithoutPathExpansion("%(key)s", &%(value_var)s)) {') | 394 'if (!%(src)s->GetWithoutPathExpansion("%(key)s", &%(value_var)s)) {') |
| 395 .Concat(self._GenerateError('"\'%%(key)s\' is required"')) | 395 .Concat(self._GenerateError('"\'%%(key)s\' is required"')) |
| 396 .Append('return false;') | 396 .Append('return false;') |
| 397 .Eblock('}') | 397 .Eblock('}') |
| 398 .Concat(self._GeneratePopulatePropertyFromValue( | 398 .Concat(self._GeneratePopulatePropertyFromValue( |
| 399 prop, value_var, dst, 'false')) | 399 prop, value_var, dst, 'false')) |
| 400 ) | 400 ) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 underlying_type = self._type_helper.FollowRef(prop.type_) | 455 underlying_type = self._type_helper.FollowRef(prop.type_) |
| 456 if underlying_type.property_type == PropertyType.ENUM: | 456 if underlying_type.property_type == PropertyType.ENUM: |
| 457 # Optional enum values are generated with a NONE enum value, | 457 # Optional enum values are generated with a NONE enum value, |
| 458 # potentially from another namespace. | 458 # potentially from another namespace. |
| 459 maybe_namespace = '' | 459 maybe_namespace = '' |
| 460 if underlying_type.namespace != self._namespace: | 460 if underlying_type.namespace != self._namespace: |
| 461 maybe_namespace = '%s::' % underlying_type.namespace.unix_name | 461 maybe_namespace = '%s::' % underlying_type.namespace.unix_name |
| 462 c.Sblock('if (%s != %s%s) {' % | 462 c.Sblock('if (%s != %s%s) {' % |
| 463 (prop_var, | 463 (prop_var, |
| 464 maybe_namespace, | 464 maybe_namespace, |
| 465 self._type_helper.GetEnumNoneValue(prop.type_))) | 465 self._type_helper.GetEnumNoneValue(underlying_type))) |
| 466 else: | 466 else: |
| 467 c.Sblock('if (%s.get()) {' % prop_var) | 467 c.Sblock('if (%s.get()) {' % prop_var) |
| 468 | 468 |
| 469 # ANY is a base::Value which is abstract and cannot be a direct member, so | 469 # ANY is a base::Value which is abstract and cannot be a direct member, so |
| 470 # it will always be a pointer. | 470 # it will always be a pointer. |
| 471 is_ptr = prop.optional or prop.type_.property_type == PropertyType.ANY | 471 is_ptr = prop.optional or prop.type_.property_type == PropertyType.ANY |
| 472 c.Cblock(self._CreateValueFromType( | 472 c.Cblock(self._CreateValueFromType( |
| 473 'value->SetWithoutPathExpansion("%s", %%s);' % prop.name, | 473 'value->SetWithoutPathExpansion("%s", %%s);' % prop.name, |
| 474 prop.name, | 474 prop.name, |
| 475 prop.type_, | 475 prop.type_, |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 underlying_type = self._type_helper.FollowRef(prop.type_) | 1121 underlying_type = self._type_helper.FollowRef(prop.type_) |
| 1122 if (underlying_type.property_type == PropertyType.ENUM and | 1122 if (underlying_type.property_type == PropertyType.ENUM and |
| 1123 prop.optional): | 1123 prop.optional): |
| 1124 namespace_prefix = ('%s::' % underlying_type.namespace.unix_name | 1124 namespace_prefix = ('%s::' % underlying_type.namespace.unix_name |
| 1125 if underlying_type.namespace != self._namespace | 1125 if underlying_type.namespace != self._namespace |
| 1126 else '') | 1126 else '') |
| 1127 c.Append('%s->%s = %s%s;' % ( | 1127 c.Append('%s->%s = %s%s;' % ( |
| 1128 dst, | 1128 dst, |
| 1129 prop.unix_name, | 1129 prop.unix_name, |
| 1130 namespace_prefix, | 1130 namespace_prefix, |
| 1131 self._type_helper.GetEnumNoneValue(prop.type_))) | 1131 self._type_helper.GetEnumNoneValue(underlying_type))) |
| 1132 return c | 1132 return c |
| 1133 | 1133 |
| 1134 def _GenerateError(self, body): | 1134 def _GenerateError(self, body): |
| 1135 """Generates an error message pertaining to population failure. | 1135 """Generates an error message pertaining to population failure. |
| 1136 | 1136 |
| 1137 E.g 'expected bool, got int' | 1137 E.g 'expected bool, got int' |
| 1138 """ | 1138 """ |
| 1139 c = Code() | 1139 c = Code() |
| 1140 if not self._generate_error_messages: | 1140 if not self._generate_error_messages: |
| 1141 return c | 1141 return c |
| 1142 (c.Append('if (error->length())') | 1142 (c.Append('if (error->length())') |
| 1143 .Append(' error->append(UTF8ToUTF16("; "));') | 1143 .Append(' error->append(UTF8ToUTF16("; "));') |
| 1144 .Append('error->append(UTF8ToUTF16(%s));' % body)) | 1144 .Append('error->append(UTF8ToUTF16(%s));' % body)) |
| 1145 return c | 1145 return c |
| 1146 | 1146 |
| 1147 def _GenerateParams(self, params): | 1147 def _GenerateParams(self, params): |
| 1148 """Builds the parameter list for a function, given an array of parameters. | 1148 """Builds the parameter list for a function, given an array of parameters. |
| 1149 """ | 1149 """ |
| 1150 if self._generate_error_messages: | 1150 if self._generate_error_messages: |
| 1151 params = list(params) + ['base::string16* error'] | 1151 params = list(params) + ['base::string16* error'] |
| 1152 return ', '.join(str(p) for p in params) | 1152 return ', '.join(str(p) for p in params) |
| 1153 | 1153 |
| 1154 def _GenerateArgs(self, args): | 1154 def _GenerateArgs(self, args): |
| 1155 """Builds the argument list for a function, given an array of arguments. | 1155 """Builds the argument list for a function, given an array of arguments. |
| 1156 """ | 1156 """ |
| 1157 if self._generate_error_messages: | 1157 if self._generate_error_messages: |
| 1158 args = list(args) + ['error'] | 1158 args = list(args) + ['error'] |
| 1159 return ', '.join(str(a) for a in args) | 1159 return ', '.join(str(a) for a in args) |
| OLD | NEW |