| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 is_ptr=True)) | 300 is_ptr=True)) |
| 301 .Append('return true;') | 301 .Append('return true;') |
| 302 .Eblock('}') | 302 .Eblock('}') |
| 303 ) | 303 ) |
| 304 (c.Concat(self._GenerateError( | 304 (c.Concat(self._GenerateError( |
| 305 '"expected %s, got " + %s' % | 305 '"expected %s, got " + %s' % |
| 306 (" or ".join(choice.name for choice in type_.choices), | 306 (" or ".join(choice.name for choice in type_.choices), |
| 307 self._util_cc_helper.GetValueTypeString('value')))) | 307 self._util_cc_helper.GetValueTypeString('value')))) |
| 308 .Append('return false;')) | 308 .Append('return false;')) |
| 309 elif type_.property_type == PropertyType.OBJECT: | 309 elif type_.property_type == PropertyType.OBJECT: |
| 310 (c.Sblock('if (!value.IsType(base::Value::TYPE_DICTIONARY)) {') | 310 (c.Sblock('if (!value.IsType(base::Value::Type::DICTIONARY)) {') |
| 311 .Concat(self._GenerateError( | 311 .Concat(self._GenerateError( |
| 312 '"expected dictionary, got " + ' + | 312 '"expected dictionary, got " + ' + |
| 313 self._util_cc_helper.GetValueTypeString('value'))) | 313 self._util_cc_helper.GetValueTypeString('value'))) |
| 314 .Append('return false;') | 314 .Append('return false;') |
| 315 .Eblock('}')) | 315 .Eblock('}')) |
| 316 | 316 |
| 317 if type_.properties or type_.additional_properties is not None: | 317 if type_.properties or type_.additional_properties is not None: |
| 318 c.Append('const base::DictionaryValue* dict = ' | 318 c.Append('const base::DictionaryValue* dict = ' |
| 319 'static_cast<const base::DictionaryValue*>(&value);') | 319 'static_cast<const base::DictionaryValue*>(&value);') |
| 320 if self._generate_error_messages: | 320 if self._generate_error_messages: |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 for i, param in enumerate(function.params): | 706 for i, param in enumerate(function.params): |
| 707 # Any failure will cause this function to return. If any argument is | 707 # Any failure will cause this function to return. If any argument is |
| 708 # incorrect or missing, those following it are not processed. Note that | 708 # incorrect or missing, those following it are not processed. Note that |
| 709 # for optional arguments, we allow missing arguments and proceed because | 709 # for optional arguments, we allow missing arguments and proceed because |
| 710 # there may be other arguments following it. | 710 # there may be other arguments following it. |
| 711 failure_value = 'std::unique_ptr<Params>()' | 711 failure_value = 'std::unique_ptr<Params>()' |
| 712 c.Append() | 712 c.Append() |
| 713 value_var = param.unix_name + '_value' | 713 value_var = param.unix_name + '_value' |
| 714 (c.Append('const base::Value* %(value_var)s = NULL;') | 714 (c.Append('const base::Value* %(value_var)s = NULL;') |
| 715 .Append('if (args.Get(%(i)s, &%(value_var)s) &&') | 715 .Append('if (args.Get(%(i)s, &%(value_var)s) &&') |
| 716 .Sblock(' !%(value_var)s->IsType(base::Value::TYPE_NULL)) {') | 716 .Sblock(' !%(value_var)s->IsType(base::Value::Type::NONE)) {') |
| 717 .Concat(self._GeneratePopulatePropertyFromValue( | 717 .Concat(self._GeneratePopulatePropertyFromValue( |
| 718 param, value_var, 'params', failure_value)) | 718 param, value_var, 'params', failure_value)) |
| 719 .Eblock('}') | 719 .Eblock('}') |
| 720 ) | 720 ) |
| 721 if not param.optional: | 721 if not param.optional: |
| 722 (c.Sblock('else {') | 722 (c.Sblock('else {') |
| 723 .Concat(self._GenerateError('"\'%%(key)s\' is required"')) | 723 .Concat(self._GenerateError('"\'%%(key)s\' is required"')) |
| 724 .Append('return %s;' % failure_value) | 724 .Append('return %s;' % failure_value) |
| 725 .Eblock('}')) | 725 .Eblock('}')) |
| 726 c.Substitute({'value_var': value_var, 'i': i, 'key': param.name}) | 726 c.Substitute({'value_var': value_var, 'i': i, 'key': param.name}) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 (c.Append('if (!%%(cpp_type)s::Populate(%s))' % self._GenerateArgs( | 881 (c.Append('if (!%%(cpp_type)s::Populate(%s))' % self._GenerateArgs( |
| 882 ('*%(src_var)s', '&%(dst_var)s'))) | 882 ('*%(src_var)s', '&%(dst_var)s'))) |
| 883 .Append(' return %(failure_value)s;')) | 883 .Append(' return %(failure_value)s;')) |
| 884 elif underlying_type.property_type == PropertyType.ENUM: | 884 elif underlying_type.property_type == PropertyType.ENUM: |
| 885 c.Concat(self._GenerateStringToEnumConversion(underlying_type, | 885 c.Concat(self._GenerateStringToEnumConversion(underlying_type, |
| 886 src_var, | 886 src_var, |
| 887 dst_var, | 887 dst_var, |
| 888 failure_value)) | 888 failure_value)) |
| 889 elif underlying_type.property_type == PropertyType.BINARY: | 889 elif underlying_type.property_type == PropertyType.BINARY: |
| 890 (c.Append('const base::BinaryValue* binary_value = NULL;') | 890 (c.Append('const base::BinaryValue* binary_value = NULL;') |
| 891 .Sblock('if (!%(src_var)s->IsType(base::Value::TYPE_BINARY)) {') | 891 .Sblock('if (!%(src_var)s->IsType(base::Value::Type::BINARY)) {') |
| 892 .Concat(self._GenerateError( | 892 .Concat(self._GenerateError( |
| 893 '"\'%%(key)s\': expected binary, got " + ' + | 893 '"\'%%(key)s\': expected binary, got " + ' + |
| 894 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) | 894 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) |
| 895 ) | 895 ) |
| 896 if not self._generate_error_messages: | 896 if not self._generate_error_messages: |
| 897 c.Append('return %(failure_value)s;') | 897 c.Append('return %(failure_value)s;') |
| 898 (c.Eblock('}') | 898 (c.Eblock('}') |
| 899 .Sblock('else {') | 899 .Sblock('else {') |
| 900 .Append(' binary_value =') | 900 .Append(' binary_value =') |
| 901 .Append(' static_cast<const base::BinaryValue*>(%(src_var)s);') | 901 .Append(' static_cast<const base::BinaryValue*>(%(src_var)s);') |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |